Initialize and free the DTrace taskqueue in the dtrace module load/unload

handlers rather than in the dtrace device open/close methods. The current
approach can cause a panic if the device is closed which the taskqueue
thread is active, or if a kernel module containing a provider is unloaded
while retained enablings are present and the dtrace device isn't opened.

Submitted by:	gibbs (original version)
Reviewed by:	gibbs
Approved by:	re (glebius)
MFC after:	2 weeks
This commit is contained in:
Mark Johnston 2013-10-08 12:56:46 +00:00
parent 0a2cefc676
commit cb7320ce7b
3 changed files with 4 additions and 9 deletions

View File

@ -15751,10 +15751,6 @@ dtrace_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
#else
devfs_set_cdevpriv(state, dtrace_dtr);
#endif
/* This code actually belongs in dtrace_attach() */
if (dtrace_opens == 1)
dtrace_taskq = taskq_create("dtrace_taskq", 1, maxclsyspri,
1, INT_MAX, 0);
#endif
mutex_exit(&cpu_lock);
@ -15842,11 +15838,6 @@ dtrace_dtr(void *data)
(void) kdi_dtrace_set(KDI_DTSET_DTRACE_DEACTIVATE);
#else
--dtrace_opens;
/* This code actually belongs in dtrace_detach() */
if ((dtrace_opens == 0) && (dtrace_taskq != NULL)) {
taskq_destroy(dtrace_taskq);
dtrace_taskq = NULL;
}
#endif
mutex_exit(&dtrace_lock);

View File

@ -56,6 +56,8 @@ dtrace_load(void *dummy)
/* Hang our hook for exceptions. */
dtrace_invop_init();
dtrace_taskq = taskq_create("dtrace_taskq", 1, maxclsyspri, 0, 0, 0);
/* Register callbacks for linker file load and unload events. */
dtrace_kld_load_tag = EVENTHANDLER_REGISTER(kld_load,
dtrace_kld_load, NULL, EVENTHANDLER_PRI_ANY);

View File

@ -127,6 +127,8 @@ dtrace_unload()
mutex_destroy(&dtrace_errlock);
#endif
taskq_destroy(dtrace_taskq);
/* Reset our hook for exceptions. */
dtrace_invop_uninit();