bpf: trace: send signals asynchronously if !preemptible
Subsystems (4)
PATCH 1/1 bpf: trace: send signals asynchronously if !preemptible
BPF programs can execute in all kinds of contexts and when a program running in a non-preemptible context uses the bpf_send_signal() kfunc, it will cause issues because this kfunc can sleep.
So change irqs_disabled() to !preemptible() that covers all edge
cases: preempt_count() == 0 and irqs_disabled()
--- kernel/trace/bpf_trace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/bpf_trace.c +1 -1
@@ -853,7 +853,7 @@ static int bpf_send_signal_common(u32 sig, enum pid_type type, struct task_strucif (unlikely (is_global_init (task)))return -EPERM ; -if (irqs_disabled ()) { +if (!preemptible ()) {/* Do an early check on signal validity. Otherwise, * the error is lost in deferred irq_work. */
Signature · 1 line
2.40.1
Quoted 11 lines · Puranjay Mohan
BPF programs can execute in all kinds of contexts and when a program running in a non-preemptible context uses the
bpf_send_signal()kfunc, it will cause issues because this kfunc can sleep.So change
irqs_disabled()to!preemptible()that covers all edge
cases:preempt_count()== 0 andirqs_disabled()Reported-by [email protected]Fixes 1bc7896e9ef4 ("bpf: Fix deadlock with rq_lock in bpf_send_signal()")Signed-off-by Puranjay Mohan <[email protected]>
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 8 lines · On Wed, 15 Jan 2025 10:36:47 +0000 you wrote:
BPF programs can execute in all kinds of contexts and when a program running in a non-preemptible context uses the
bpf_send_signal()kfunc, it will cause issues because this kfunc can sleep.So change
irqs_disabled()to!preemptible()that covers all edge
cases:preempt_count()== 0 andirqs_disabled()[...]
Here is the summary with links:
- [bpf] bpf: trace: send signals asynchronously if !preemptible
https://git.kernel.org/bpf/bpf-next/c/87c544108b61
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Hi,
Quoted 20 lines · Puranjay Mohan
BPF programs can execute in all kinds of contexts and when a program running in a non-preemptible context uses the
bpf_send_signal()kfunc, it will cause issues because this kfunc can sleep.So change
irqs_disabled()to!preemptible()that covers all edge
cases:preempt_count()== 0 andirqs_disabled()Reported-by [email protected]Fixes 1bc7896e9ef4 ("bpf: Fix deadlock with rq_lock in bpf_send_signal()")Signed-off-by Puranjay Mohan <[email protected]>--- kernel/trace/bpf_trace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/trace/bpf_trace.c +0
-0
kernel/trace/bpf_trace.c static int bpf_send_signal_common(u32 sig, enum pid_type type, struct task_struc · line 856
Quoted 5 lines
kernel/trace/bpf_trace.c +1
-1@@ -853,7 +853,7 @@ static int bpf_send_signal_common(u32 sig, enum pid_type type, struct task_strucif (unlikely (is_global_init (task)))return -EPERM ; -if (irqs_disabled ()) { +if (!preemptible ()) {
Should we unfold preemptible() to "preempt_count() == 0 && !irqs_disabled()" instead, because when preemption is disabled, preemptible() will evaluate as 0 and the irq_disabled() case will be skipped ?
Quoted 3 lines
kernel/trace/bpf_trace.c +0
-0/* Do an early check on signal validity. Otherwise, * the error is lost in deferred irq_work. */