Skip to content

Commit 4580f4e

Browse files
Alexei Starovoitovanakryiko
authored andcommitted
bpf: Fix deadlock between rcu_tasks_trace and event_mutex.
Fix the following deadlock: CPU A _free_event() perf_kprobe_destroy() mutex_lock(&event_mutex) perf_trace_event_unreg() synchronize_rcu_tasks_trace() There are several paths where _free_event() grabs event_mutex and calls sync_rcu_tasks_trace. Above is one such case. CPU B bpf_prog_test_run_syscall() rcu_read_lock_trace() bpf_prog_run_pin_on_cpu() bpf_prog_load() bpf_tracing_func_proto() trace_set_clr_event() mutex_lock(&event_mutex) Delegate trace_set_clr_event() to workqueue to avoid such lock dependency. Signed-off-by: Alexei Starovoitov <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent b123480 commit 4580f4e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

kernel/trace/bpf_trace.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ static const struct bpf_func_proto bpf_trace_printk_proto = {
392392
.arg2_type = ARG_CONST_SIZE,
393393
};
394394

395-
static void __set_printk_clr_event(void)
395+
static void __set_printk_clr_event(struct work_struct *work)
396396
{
397397
/*
398398
* This program might be calling bpf_trace_printk,
@@ -405,10 +405,11 @@ static void __set_printk_clr_event(void)
405405
if (trace_set_clr_event("bpf_trace", "bpf_trace_printk", 1))
406406
pr_warn_ratelimited("could not enable bpf_trace_printk events");
407407
}
408+
static DECLARE_WORK(set_printk_work, __set_printk_clr_event);
408409

409410
const struct bpf_func_proto *bpf_get_trace_printk_proto(void)
410411
{
411-
__set_printk_clr_event();
412+
schedule_work(&set_printk_work);
412413
return &bpf_trace_printk_proto;
413414
}
414415

@@ -451,7 +452,7 @@ static const struct bpf_func_proto bpf_trace_vprintk_proto = {
451452

452453
const struct bpf_func_proto *bpf_get_trace_vprintk_proto(void)
453454
{
454-
__set_printk_clr_event();
455+
schedule_work(&set_printk_work);
455456
return &bpf_trace_vprintk_proto;
456457
}
457458

0 commit comments

Comments
 (0)