Skip to content

Commit 503f7e2

Browse files
committed
Merge tag 'trace-v4.14-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull tracing fix from Steven Rostedt: "Testing a new trace event format, I triggered a bug by doing: # modprobe trace-events-sample # echo 1 > /sys/kernel/debug/tracing/events/sample-trace/enable # rmmod trace-events-sample This would cause an oops. The issue is that I added another trace event sample that reused a reg function of another trace event to create a thread to call the tracepoints. The problem was that the reg function couldn't handle nested calls (reg; reg; unreg; unreg;) and created two threads (instead of one) and only removed one on exit. This isn't a critical bug as the bug is only in sample code. But sample code should be free of known bugs to prevent others from copying it. This is why this is also marked for stable" * tag 'trace-v4.14-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: tracing/samples: Fix creation and deletion of simple_thread_fn creation
2 parents ebe6e90 + 6575257 commit 503f7e2

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

samples/trace_events/trace-events-sample.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,37 @@ static int simple_thread_fn(void *arg)
7878
}
7979

8080
static DEFINE_MUTEX(thread_mutex);
81+
static bool simple_thread_cnt;
8182

8283
int foo_bar_reg(void)
8384
{
85+
mutex_lock(&thread_mutex);
86+
if (simple_thread_cnt++)
87+
goto out;
88+
8489
pr_info("Starting thread for foo_bar_fn\n");
8590
/*
8691
* We shouldn't be able to start a trace when the module is
8792
* unloading (there's other locks to prevent that). But
8893
* for consistency sake, we still take the thread_mutex.
8994
*/
90-
mutex_lock(&thread_mutex);
9195
simple_tsk_fn = kthread_run(simple_thread_fn, NULL, "event-sample-fn");
96+
out:
9297
mutex_unlock(&thread_mutex);
9398
return 0;
9499
}
95100

96101
void foo_bar_unreg(void)
97102
{
98-
pr_info("Killing thread for foo_bar_fn\n");
99-
/* protect against module unloading */
100103
mutex_lock(&thread_mutex);
104+
if (--simple_thread_cnt)
105+
goto out;
106+
107+
pr_info("Killing thread for foo_bar_fn\n");
101108
if (simple_tsk_fn)
102109
kthread_stop(simple_tsk_fn);
103110
simple_tsk_fn = NULL;
111+
out:
104112
mutex_unlock(&thread_mutex);
105113
}
106114

0 commit comments

Comments
 (0)