Skip to content

Commit e9e1fe5

Browse files
bpf: Use preempt_count() directly in bpf_send_signal_common()
JIRA: https://issues.redhat.com/browse/RHEL-85486 Conflicts: Context change due to missing commit 6280cf7 ("bpf: Implement bpf_send_signal_task() kfunc"). commit b4a8b5b Author: Hou Tao <houtao1@huawei.com> Date: Thu Feb 20 12:22:59 2025 +0800 bpf: Use preempt_count() directly in bpf_send_signal_common() 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 <houtao1@huawei.com> Link: https://lore.kernel.org/r/20250220042259.1583319-1-houtao@huaweicloud.com Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
1 parent a249a6e commit e9e1fe5

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
@@ -832,7 +832,7 @@ static int bpf_send_signal_common(u32 sig, enum pid_type type)
832832
if (unlikely(is_global_init(current)))
833833
return -EPERM;
834834

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

0 commit comments

Comments
 (0)