[PATCHSET sched_ext/for-7.4-fixes] sched_ext: Fix and tighten RCU usage in kfuncs
From: Kuba Piecuch
Date: Mon Nov 23 2026 - 10:00:48 EST
Several sched_ext kfuncs dereference RCU-protected state without taking
rcu_read_lock() themselves. They depend on the caller's context instead,
but that context does not always satisfy rcu_read_lock_held().
The verifier treats every non-sleepable program as being inside an RCU
read-side section, and KF_RCU_PROTECTED only checks that. bpf_timer
callbacks are non-sleepable, but bpf_timer_cb() calls them directly
from hrtimer softirq, with no trampoline and so no rcu_read_lock():
hrtimer softirq
bpf_timer_cb()
timer callback (BPF)
scx_bpf_dsq_peek()
rcu_dereference(dsq->first_task) <- rcu_read_lock_held() == 0
With CONFIG_PROVE_RCU=y this triggers:
WARNING: suspicious RCU usage
kernel/sched/ext/ext.c:11170 suspicious rcu_dereference_check() usage!
...
Call Trace:
lockdep_rcu_suspicious+0x11a/0x160
scx_bpf_dsq_peek+0x7d/0xd0
bpf_timer_cb+0xf9/0x130
WARNING: suspicious RCU usage
kernel/sched/ext/ext.c:11961 suspicious rcu_dereference_check() usage!
...
Call Trace:
lockdep_rcu_suspicious+0x11a/0x160
scx_bpf_tid_to_task+0x2ae/0x2e0
bpf_timer_cb+0xf9/0x130
A sleepable program inside bpf_preempt_disable() hits the same check.
Both contexts are RCU readers, so these are lockdep false positives, not
use-after-frees, but they make PROVE_RCU kernels noisy for any scheduler
that peeks a DSQ or resolves a tid from a timer.
The sub-cap kfuncs (scx_bpf_sub_grant(), scx_bpf_sub_revoke() and
scx_bpf_sub_caps()) are reachable from the same contexts. They avoid
the warning only because they disable IRQs and every RCU check on their
paths (rcu_dereference_all(), bpf_rcu_lock_held(),
rcu_read_lock_any_held()) accepts that. In scx_qmap, for example, the
round-robin bpf_timer callback calls scx_bpf_sub_revoke() and
scx_bpf_sub_grant(), which look up the child sched in scx_sched_hash
with rcu_read_lock_held() == 0.
Patch 1 adds guard(rcu)() to scx_bpf_dsq_peek() and
scx_bpf_tid_to_task(), matching scx_bpf_cpu_curr() and
scx_bpf_cid_curr(). This fixes both warnings.
Patch 2 adds guard(rcu)() to the three sub-cap kfuncs, matching
scx_bpf_sub_dispatch() and scx_bpf_sub_kill_bstr(). This makes their
RCU section explicit, so a future plain rcu_dereference() on those paths
does not reintroduce the warning. No functional change.
The patches were written with the help of an AI coding assistant.
Kuba Piecuch (2):
sched_ext: Fix suspicious RCU usage in KF_RCU_PROTECTED kfuncs
sched_ext: Take rcu_read_lock() explicitly in sub-cap kfuncs
kernel/sched/ext/ext.c | 4 ++++
kernel/sched/ext/sub.c | 3 +++
2 files changed, 7 insertions(+)
base-commit: 2f7928516314f37d7cb334675656b4412edc8be3
--
2.56.1.750.gf70dc682cf-goog