From: Aaron Tomlin <atomlin@atomlin.com>
To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com,
vincent.guittot@linaro.org
Cc: paulmck@kernel.org, dietmar.eggemann@arm.com,
rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
vschneid@redhat.com, kprateek.nayak@amd.com,
zhanxusheng1024@gmail.com, neelx@suse.com, atomlin@atomlin.com,
chjohnst@mail.com, mproche@mail.com, sean@ashe.io,
steve@abita.co, rishil1999@outlook.com,
linux-kernel@vger.kernel.org
Subject: [PATCH v11 tip/sched/core 2/6] sched/debug: Protect lockless rq->rd access in print_dl_rq()
Date: Fri, 30 Oct 2026 11:13:03 -0400 [thread overview]
Message-ID: <20261030151307.768523-3-atomlin@atomlin.com> (raw)
In-Reply-To: <20261030151307.768523-1-atomlin@atomlin.com>
In print_dl_rq(), cpu_rq(cpu)->rd is dereferenced locklessly to display
deadline bandwidth statistics.
During CPU hot-unplug or cgroup cpuset repartitioning events,
partition_sched_domains() calls cpu_attach_domain(), which executes
rq_attach_root() to detach the CPU from its root_domain. When the
reference count of the detached root_domain drops to zero,
rq_attach_root() calls call_rcu(&old_rd->rcu, free_rootdomain) to
schedule memory teardown after an RCU grace period.
However, rq_attach_root() previously updated rq->rd using a plain C store
without an RCU publication barrier (i.e., rcu_assign_pointer()). Without a
release memory barrier on the writer side, CPU or compiler reordering could
allow the new rq->rd pointer store to become visible to other CPUs before
the initialization writes to rd->dl_bw are committed.
Furthermore, because print_dl_rq() did not hold an RCU read lock while
dereferencing cpu_rq(cpu)->rd, an RCU grace period could elapse
concurrently while debugfs is reading the file, allowing
free_rootdomain() to execute kfree(old_rd) and causing a use-after-free
race condition when print_dl_rq() reads dl_bw->bw.
Resolve this by using rcu_assign_pointer(rq->rd, rd) in rq_attach_root() to
guarantee a release memory barrier when publishing a root_domain.
Finally, fetch rq->rd using guard(rcu)() and rcu_dereference() in print_dl_rq().
Fixes: 02968ccf7b80 ("sched: add /proc/sched_debug file")
Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Signed-off-by: Aaron Tomlin <atomlin@atomlin.com>
---
kernel/sched/debug.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index e6a3b516c703..439e59bc1fe4 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -1166,7 +1166,8 @@ void print_dl_rq(struct seq_file *m, int cpu, struct dl_rq *dl_rq)
SEQ_printf(m, " .%-30s: %lu\n", #x, (unsigned long)(dl_rq->x))
PU(dl_nr_running);
- dl_bw = &cpu_rq(cpu)->rd->dl_bw;
+ guard(rcu)();
+ dl_bw = &rcu_dereference_root_domain(cpu_rq(cpu)->rd)->dl_bw;
SEQ_printf(m, " .%-30s: %lld\n", "dl_bw->bw", dl_bw->bw);
SEQ_printf(m, " .%-30s: %lld\n", "dl_bw->total_bw", dl_bw->total_bw);
--
2.55.0
next prev parent reply other threads:[~2026-10-30 15:13 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 15:13 [PATCH v11 tip/sched/core 0/6] Introduce per-CPU debugfs files Aaron Tomlin
2026-10-30 15:13 ` [PATCH v11 tip/sched/core 1/6] sched: Annotate rq->rd with __rcu and update lockless readers Aaron Tomlin
2026-11-09 8:44 ` [tip: sched/core] " tip-bot2 for Aaron Tomlin
2026-11-09 9:28 ` [tip: sched/core] sched/core: " tip-bot2 for Aaron Tomlin
2026-11-09 11:51 ` tip-bot2 for Aaron Tomlin
2026-10-30 15:13 ` Aaron Tomlin [this message]
2026-11-09 8:44 ` [tip: sched/core] sched/debug: Protect lockless rq->rd access in print_dl_rq() tip-bot2 for Aaron Tomlin
2026-11-09 9:28 ` tip-bot2 for Aaron Tomlin
2026-11-09 11:51 ` tip-bot2 for Aaron Tomlin
2026-10-30 15:13 ` [PATCH v11 tip/sched/core 3/6] sched/debug: Protect lockless rq->curr access in print_cpu() Aaron Tomlin
2026-11-09 8:43 ` [tip: sched/core] " tip-bot2 for Aaron Tomlin
2026-11-09 9:28 ` tip-bot2 for Aaron Tomlin
2026-11-09 10:02 ` tip-bot2 for Aaron Tomlin
2026-10-30 15:13 ` [PATCH v11 tip/sched/core 4/6] sched/debug: Protect p->mm access in sched_show_numa() Aaron Tomlin
2026-11-09 8:43 ` [tip: sched/core] " tip-bot2 for Aaron Tomlin
2026-11-09 9:28 ` tip-bot2 for Aaron Tomlin
2026-11-09 10:02 ` tip-bot2 for Aaron Tomlin
2026-10-30 15:13 ` [PATCH v11 tip/sched/core 5/6] sched/fair: Use list_for_each_entry_rcu() in print_cfs_stats() Aaron Tomlin
2026-11-09 8:43 ` [tip: sched/core] " tip-bot2 for Aaron Tomlin
2026-11-09 9:28 ` tip-bot2 for Aaron Tomlin
2026-11-09 10:02 ` tip-bot2 for Aaron Tomlin
2026-10-30 15:13 ` [PATCH v11 tip/sched/core 6/6] sched/debug: Introduce per-CPU debugfs files Aaron Tomlin
2026-11-09 8:43 ` [tip: sched/core] " tip-bot2 for Aaron Tomlin
2026-11-09 9:28 ` tip-bot2 for Aaron Tomlin
2026-11-09 10:02 ` tip-bot2 for Aaron Tomlin
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=20261030151307.768523-3-atomlin@atomlin.com \
--to=atomlin@atomlin.com \
--cc=bsegall@google.com \
--cc=chjohnst@mail.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=mproche@mail.com \
--cc=neelx@suse.com \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=rishil1999@outlook.com \
--cc=rostedt@goodmis.org \
--cc=sean@ashe.io \
--cc=steve@abita.co \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=zhanxusheng1024@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.