Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 17 Feb 2014 12:12:32 +0000 (UTC)
From:      Andriy Gapon <avg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r262032 - stable/9/sys/kern
Message-ID:  <201402171212.s1HCCWE6029784@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avg
Date: Mon Feb 17 12:12:32 2014
New Revision: 262032
URL: http://svnweb.freebsd.org/changeset/base/262032

Log:
  MFC r254811: call linker_file_lookup_set() with the shared lock held

Modified:
  stable/9/sys/kern/kern_linker.c
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/kern/kern_linker.c
==============================================================================
--- stable/9/sys/kern/kern_linker.c	Mon Feb 17 12:10:08 2014	(r262031)
+++ stable/9/sys/kern/kern_linker.c	Mon Feb 17 12:12:32 2014	(r262032)
@@ -196,6 +196,8 @@ linker_file_sysinit(linker_file_t lf)
 	KLD_DPF(FILE, ("linker_file_sysinit: calling SYSINITs for %s\n",
 	    lf->filename));
 
+	sx_assert(&kld_sx, SA_XLOCKED);
+
 	if (linker_file_lookup_set(lf, "sysinit_set", &start, &stop, NULL) != 0)
 		return;
 	/*
@@ -221,6 +223,7 @@ linker_file_sysinit(linker_file_t lf)
 	 * Traverse the (now) ordered list of system initialization tasks.
 	 * Perform each task, and continue on to the next task.
 	 */
+	sx_xunlock(&kld_sx);
 	mtx_lock(&Giant);
 	for (sipp = start; sipp < stop; sipp++) {
 		if ((*sipp)->subsystem == SI_SUB_DUMMY)
@@ -230,6 +233,7 @@ linker_file_sysinit(linker_file_t lf)
 		(*((*sipp)->func)) ((*sipp)->udata);
 	}
 	mtx_unlock(&Giant);
+	sx_xlock(&kld_sx);
 }
 
 static void
@@ -240,6 +244,8 @@ linker_file_sysuninit(linker_file_t lf)
 	KLD_DPF(FILE, ("linker_file_sysuninit: calling SYSUNINITs for %s\n",
 	    lf->filename));
 
+	sx_assert(&kld_sx, SA_XLOCKED);
+
 	if (linker_file_lookup_set(lf, "sysuninit_set", &start, &stop,
 	    NULL) != 0)
 		return;
@@ -267,6 +273,7 @@ linker_file_sysuninit(linker_file_t lf)
 	 * Traverse the (now) ordered list of system initialization tasks.
 	 * Perform each task, and continue on to the next task.
 	 */
+	sx_xunlock(&kld_sx);
 	mtx_lock(&Giant);
 	for (sipp = start; sipp < stop; sipp++) {
 		if ((*sipp)->subsystem == SI_SUB_DUMMY)
@@ -276,6 +283,7 @@ linker_file_sysuninit(linker_file_t lf)
 		(*((*sipp)->func)) ((*sipp)->udata);
 	}
 	mtx_unlock(&Giant);
+	sx_xlock(&kld_sx);
 }
 
 static void
@@ -287,13 +295,17 @@ linker_file_register_sysctls(linker_file
 	    ("linker_file_register_sysctls: registering SYSCTLs for %s\n",
 	    lf->filename));
 
+	sx_assert(&kld_sx, SA_XLOCKED);
+
 	if (linker_file_lookup_set(lf, "sysctl_set", &start, &stop, NULL) != 0)
 		return;
 
+	sx_xunlock(&kld_sx);
 	sysctl_lock();
 	for (oidp = start; oidp < stop; oidp++)
 		sysctl_register_oid(*oidp);
 	sysctl_unlock();
+	sx_xlock(&kld_sx);
 }
 
 static void
@@ -304,13 +316,17 @@ linker_file_unregister_sysctls(linker_fi
 	KLD_DPF(FILE, ("linker_file_unregister_sysctls: registering SYSCTLs"
 	    " for %s\n", lf->filename));
 
+	sx_assert(&kld_sx, SA_XLOCKED);
+
 	if (linker_file_lookup_set(lf, "sysctl_set", &start, &stop, NULL) != 0)
 		return;
 
+	sx_xunlock(&kld_sx);
 	sysctl_lock();
 	for (oidp = start; oidp < stop; oidp++)
 		sysctl_unregister_oid(*oidp);
 	sysctl_unlock();
+	sx_xlock(&kld_sx);
 }
 
 static int
@@ -323,6 +339,8 @@ linker_file_register_modules(linker_file
 	KLD_DPF(FILE, ("linker_file_register_modules: registering modules"
 	    " in %s\n", lf->filename));
 
+	sx_assert(&kld_sx, SA_XLOCKED);
+
 	if (linker_file_lookup_set(lf, "modmetadata_set", &start,
 	    &stop, NULL) != 0) {
 		/*
@@ -411,10 +429,8 @@ linker_load_file(const char *filename, l
 				return (error);
 			}
 			modules = !TAILQ_EMPTY(&lf->modules);
-			sx_xunlock(&kld_sx);
 			linker_file_register_sysctls(lf);
 			linker_file_sysinit(lf);
-			sx_xlock(&kld_sx);
 			lf->flags |= LINKER_FILE_LINKED;
 
 			/*
@@ -665,10 +681,8 @@ linker_file_unload(linker_file_t file, i
 	 */
 	if (file->flags & LINKER_FILE_LINKED) {
 		file->flags &= ~LINKER_FILE_LINKED;
-		sx_xunlock(&kld_sx);
 		linker_file_sysuninit(file);
 		linker_file_unregister_sysctls(file);
-		sx_xlock(&kld_sx);
 	}
 	TAILQ_REMOVE(&linker_files, file, link);
 
@@ -737,15 +751,9 @@ int
 linker_file_lookup_set(linker_file_t file, const char *name,
     void *firstp, void *lastp, int *countp)
 {
-	int error, locked;
 
-	locked = sx_xlocked(&kld_sx);
-	if (!locked)
-		sx_xlock(&kld_sx);
-	error = LINKER_LOOKUP_SET(file, name, firstp, lastp, countp);
-	if (!locked)
-		sx_xunlock(&kld_sx);
-	return (error);
+	sx_assert(&kld_sx, SA_LOCKED);
+	return (LINKER_LOOKUP_SET(file, name, firstp, lastp, countp));
 }
 
 /*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201402171212.s1HCCWE6029784>