Skip to content

Commit 2ced994

Browse files
Kefeng Wanggregkh
authored andcommitted
sample-trace-array: Fix sleeping function called from invalid context
commit e9b7b1c upstream. BUG: sleeping function called from invalid context at kernel/locking/mutex.c:935 in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 0, name: swapper/5 1 lock held by swapper/5/0: #0: ffff80001002bd90 (samples/ftrace/sample-trace-array.c:38){+.-.}-{0:0}, at: call_timer_fn+0x8/0x3e0 CPU: 5 PID: 0 Comm: swapper/5 Not tainted 5.7.0+ raspberrypi#8 Hardware name: QEMU QEMU Virtual Machine, BIOS 0.0.0 02/06/2015 Call trace: dump_backtrace+0x0/0x1a0 show_stack+0x20/0x30 dump_stack+0xe4/0x150 ___might_sleep+0x160/0x200 __might_sleep+0x58/0x90 __mutex_lock+0x64/0x948 mutex_lock_nested+0x3c/0x58 __ftrace_set_clr_event+0x44/0x88 trace_array_set_clr_event+0x24/0x38 mytimer_handler+0x34/0x40 [sample_trace_array] mutex_lock() will be called in interrupt context, using workqueue to fix it. Link: https://lkml.kernel.org/r/20200610011244.2209486-1-wangkefeng.wang@huawei.com Cc: stable@vger.kernel.org Fixes: 89ed424 ("tracing: Sample module to demonstrate kernel access to Ftrace instances.") Reviewed-by: Divya Indi <divya.indi@oracle.com> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 11afc0d commit 2ced994

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

‎samples/ftrace/sample-trace-array.c‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/timer.h>
77
#include <linux/err.h>
88
#include <linux/jiffies.h>
9+
#include <linux/workqueue.h>
910

1011
/*
1112
* Any file that uses trace points, must include the header.
@@ -20,6 +21,16 @@ struct trace_array *tr;
2021
static void mytimer_handler(struct timer_list *unused);
2122
static struct task_struct *simple_tsk;
2223

24+
static void trace_work_fn(struct work_struct *work)
25+
{
26+
/*
27+
* Disable tracing for event "sample_event".
28+
*/
29+
trace_array_set_clr_event(tr, "sample-subsystem", "sample_event",
30+
false);
31+
}
32+
static DECLARE_WORK(trace_work, trace_work_fn);
33+
2334
/*
2435
* mytimer: Timer setup to disable tracing for event "sample_event". This
2536
* timer is only for the purposes of the sample module to demonstrate access of
@@ -29,11 +40,7 @@ static DEFINE_TIMER(mytimer, mytimer_handler);
2940

3041
static void mytimer_handler(struct timer_list *unused)
3142
{
32-
/*
33-
* Disable tracing for event "sample_event".
34-
*/
35-
trace_array_set_clr_event(tr, "sample-subsystem", "sample_event",
36-
false);
43+
schedule_work(&trace_work);
3744
}
3845

3946
static void simple_thread_func(int count)
@@ -76,6 +83,7 @@ static int simple_thread(void *arg)
7683
simple_thread_func(count++);
7784

7885
del_timer(&mytimer);
86+
cancel_work_sync(&trace_work);
7987

8088
/*
8189
* trace_array_put() decrements the reference counter associated with

0 commit comments

Comments
 (0)