Skip to content

Commit 8b1fac2

Browse files
committed
tracing: Wait for preempt irq delay thread to execute
A bug report was posted that running the preempt irq delay module on a slow machine, and removing it quickly could lead to the thread created by the modlue to execute after the module is removed, and this could cause the kernel to crash. The fix for this was to call kthread_stop() after creating the thread to make sure it finishes before allowing the module to be removed. Now this caused the opposite problem on fast machines. What now happens is the kthread_stop() can cause the kthread never to execute and the test never to run. To fix this, add a completion and wait for the kthread to execute, then wait for it to end. This issue caused the ftracetest selftests to fail on the preemptirq tests. Link: https://lore.kernel.org/r/[email protected] Cc: [email protected] Fixes: d16a8c3 ("tracing: Wait for preempt irq delay thread to finish") Reviewed-by: Joel Fernandes (Google) <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 9d82ccd commit 8b1fac2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

kernel/trace/preemptirq_delay_test.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/printk.h>
1717
#include <linux/string.h>
1818
#include <linux/sysfs.h>
19+
#include <linux/completion.h>
1920

2021
static ulong delay = 100;
2122
static char test_mode[12] = "irq";
@@ -28,6 +29,8 @@ MODULE_PARM_DESC(delay, "Period in microseconds (100 us default)");
2829
MODULE_PARM_DESC(test_mode, "Mode of the test such as preempt, irq, or alternate (default irq)");
2930
MODULE_PARM_DESC(burst_size, "The size of a burst (default 1)");
3031

32+
static struct completion done;
33+
3134
#define MIN(x, y) ((x) < (y) ? (x) : (y))
3235

3336
static void busy_wait(ulong time)
@@ -114,6 +117,8 @@ static int preemptirq_delay_run(void *data)
114117
for (i = 0; i < s; i++)
115118
(testfuncs[i])(i);
116119

120+
complete(&done);
121+
117122
set_current_state(TASK_INTERRUPTIBLE);
118123
while (!kthread_should_stop()) {
119124
schedule();
@@ -128,15 +133,18 @@ static int preemptirq_delay_run(void *data)
128133
static int preemptirq_run_test(void)
129134
{
130135
struct task_struct *task;
131-
132136
char task_name[50];
133137

138+
init_completion(&done);
139+
134140
snprintf(task_name, sizeof(task_name), "%s_test", test_mode);
135141
task = kthread_run(preemptirq_delay_run, NULL, task_name);
136142
if (IS_ERR(task))
137143
return PTR_ERR(task);
138-
if (task)
144+
if (task) {
145+
wait_for_completion(&done);
139146
kthread_stop(task);
147+
}
140148
return 0;
141149
}
142150

0 commit comments

Comments
 (0)