Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177887284
D60561.1795519704.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
D60561.1795519704.diff
View Options
diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c
--- a/sys/dev/hwpmc/hwpmc_mod.c
+++ b/sys/dev/hwpmc/hwpmc_mod.c
@@ -5941,12 +5941,14 @@
PMCDBG0(MOD,INI,0, "cleanup");
+ /* The caller holds pmc_sx from the owner check through unhooking. */
+ sx_assert(&pmc_sx, SX_XLOCKED);
+
/* switch off sampling */
CPU_FOREACH(cpu)
DPCPU_ID_SET(cpu, pmc_sampled, 0);
pmc_intr = NULL;
- sx_xlock(&pmc_sx);
if (pmc_hook == NULL) { /* being unloaded already */
sx_xunlock(&pmc_sx);
return;
@@ -6101,6 +6103,33 @@
sx_xunlock(&pmc_sx); /* we are done */
}
+/*
+ * Do not unhook sampling while owners can still hold queued samples.
+ * MOD_UNLOAD runs under kld_sx. A blocking acquisition of pmc_sx would
+ * invert the sampling path's pmc_sx -> kld_sx order, so refuse on lock
+ * contention. Keep the successful try-lock through cleanup to exclude
+ * new owners between checking the hash and disabling the hooks.
+ */
+static int
+pmc_unload(void)
+{
+ struct pmc_ownerhash *ph;
+
+ if (!sx_try_xlock(&pmc_sx))
+ return (EXTERROR(EBUSY, "PMC state lock is busy"));
+ if (pmc_ownerhash != NULL) {
+ for (ph = pmc_ownerhash;
+ ph <= &pmc_ownerhash[pmc_ownerhashmask]; ph++) {
+ if (!LIST_EMPTY(ph)) {
+ sx_xunlock(&pmc_sx);
+ return (EXTERROR(EBUSY, "PMC owners still exist"));
+ }
+ }
+ }
+ pmc_cleanup();
+ return (0);
+}
+
/*
* The function called at load/unload.
*/
@@ -6121,7 +6150,13 @@
pmc_cpu_max());
break;
case MOD_UNLOAD:
+ error = pmc_unload();
+ if (error == 0)
+ PMCDBG0(MOD,INI,1, "unloaded");
+ break;
case MOD_SHUTDOWN:
+ /* Shutdown cannot be vetoed by PMC owners. */
+ sx_xlock(&pmc_sx);
pmc_cleanup();
PMCDBG0(MOD,INI,1, "unloaded");
break;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 24, 11:28 AM (19 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41704616
Default Alt Text
D60561.1795519704.diff (1 KB)
Attached To
Mode
D60561: hwpmc: refuse MOD_UNLOAD while PMC owners exist
Attached
Detach File
Event Timeline