tracing: Wait for preempt irq delay thread to finish

Running on a slower machine, it is possible that the preempt delay kernel
thread may still be executing if the module was immediately removed after
added, and this can cause the kernel to crash as the kernel thread might be
executing after its code has been removed.

There's no reason that the caller of the code shouldn't just wait for the
delay thread to finish, as the thread can also be created by a trigger in
the sysfs code, which also has the same issues.

Link: http://lore.kernel.org/r/5EA2B0C8.2080706@cn.fujitsu.com

Cc: stable@vger.kernel.org
Fixes: 79393723 ("lib: Add module for testing preemptoff/irqsoff latency tracers")
Reported-by: default avatarXiao Yang <yangx.jy@cn.fujitsu.com>
Reviewed-by: default avatarXiao Yang <yangx.jy@cn.fujitsu.com>
Reviewed-by: default avatarJoel Fernandes <joel@joelfernandes.org>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent 5b4dcd2d
...@@ -113,22 +113,42 @@ static int preemptirq_delay_run(void *data) ...@@ -113,22 +113,42 @@ static int preemptirq_delay_run(void *data)
for (i = 0; i < s; i++) for (i = 0; i < s; i++)
(testfuncs[i])(i); (testfuncs[i])(i);
set_current_state(TASK_INTERRUPTIBLE);
while (!kthread_should_stop()) {
schedule();
set_current_state(TASK_INTERRUPTIBLE);
}
__set_current_state(TASK_RUNNING);
return 0; return 0;
} }
static struct task_struct *preemptirq_start_test(void) static int preemptirq_run_test(void)
{ {
struct task_struct *task;
char task_name[50]; char task_name[50];
snprintf(task_name, sizeof(task_name), "%s_test", test_mode); snprintf(task_name, sizeof(task_name), "%s_test", test_mode);
return kthread_run(preemptirq_delay_run, NULL, task_name); task = kthread_run(preemptirq_delay_run, NULL, task_name);
if (IS_ERR(task))
return PTR_ERR(task);
if (task)
kthread_stop(task);
return 0;
} }
static ssize_t trigger_store(struct kobject *kobj, struct kobj_attribute *attr, static ssize_t trigger_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
preemptirq_start_test(); ssize_t ret;
ret = preemptirq_run_test();
if (ret)
return ret;
return count; return count;
} }
...@@ -148,11 +168,9 @@ static struct kobject *preemptirq_delay_kobj; ...@@ -148,11 +168,9 @@ static struct kobject *preemptirq_delay_kobj;
static int __init preemptirq_delay_init(void) static int __init preemptirq_delay_init(void)
{ {
struct task_struct *test_task;
int retval; int retval;
test_task = preemptirq_start_test(); retval = preemptirq_run_test();
retval = PTR_ERR_OR_ZERO(test_task);
if (retval != 0) if (retval != 0)
return retval; return retval;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment