Skip to content

Commit e35d78e

Browse files
Hou Taovijay-suman
authored andcommitted
bpf: Use preempt_count() directly in bpf_send_signal_common()
[ Upstream commit b4a8b5bba712a711d8ca1f7d04646db63f9c88f5 ] bpf_send_signal_common() uses preemptible() to check whether or not the current context is preemptible. If it is preemptible, it will use irq_work to send the signal asynchronously instead of trying to hold a spin-lock, because spin-lock is sleepable under PREEMPT_RT. However, preemptible() depends on CONFIG_PREEMPT_COUNT. When CONFIG_PREEMPT_COUNT is turned off (e.g., CONFIG_PREEMPT_VOLUNTARY=y), !preemptible() will be evaluated as 1 and bpf_send_signal_common() will use irq_work unconditionally. Fix it by unfolding "!preemptible()" and using "preempt_count() != 0 || irqs_disabled()" instead. Fixes: 87c5441 ("bpf: Send signals asynchronously if !preemptible") Signed-off-by: Hou Tao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit eba7778cf9b977329bec485337aa56599f911ebf) FOF: 0525 Signed-off-by: Vijayendra Suman <[email protected]>
1 parent d206aa8 commit e35d78e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/trace/bpf_trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ static int bpf_send_signal_common(u32 sig, enum pid_type type)
799799
if (unlikely(is_global_init(current)))
800800
return -EPERM;
801801

802-
if (!preemptible()) {
802+
if (preempt_count() != 0 || irqs_disabled()) {
803803
/* Do an early check on signal validity. Otherwise,
804804
* the error is lost in deferred irq_work.
805805
*/

0 commit comments

Comments
 (0)