The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Kuba Piecuch <jpiecuch@google.com>
To: Tejun Heo <tj@kernel.org>, David Vernet <void@manifault.com>,
	Andrea Righi <arighi@nvidia.com>,
	 Changwoo Min <changwoo@igalia.com>
Cc: Kuba Piecuch <jpiecuch@google.com>, Ryan Newton <newton@meta.com>,
	sched-ext@lists.linux.dev,  linux-kernel@vger.kernel.org
Subject: [PATCHSET sched_ext/for-7.4-fixes] sched_ext: Fix and tighten RCU usage in kfuncs
Date: Mon, 23 Nov 2026 15:00:36 +0000	[thread overview]
Message-ID: <20261123145927.577162-1-jpiecuch@google.com> (raw)

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


             reply	other threads:[~2026-11-23 15:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 15:00 Kuba Piecuch [this message]
2026-11-23 15:00 ` [PATCH 1/2] sched_ext: Fix suspicious RCU usage in KF_RCU_PROTECTED kfuncs Kuba Piecuch
2026-11-23 15:00 ` [PATCH 2/2] sched_ext: Take rcu_read_lock() explicitly in sub-cap kfuncs Kuba Piecuch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261123145927.577162-1-jpiecuch@google.com \
    --to=jpiecuch@google.com \
    --cc=arighi@nvidia.com \
    --cc=changwoo@igalia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=newton@meta.com \
    --cc=sched-ext@lists.linux.dev \
    --cc=tj@kernel.org \
    --cc=void@manifault.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox