Re: [PATCH v7 1/6] sched: Annotate rq->rd with __rcu and update lockless readers

From: Aaron Tomlin

Date: Thu Aug 27 2026 - 05:55:18 EST


On Thu, Aug 27, 2026 at 11:39:35AM +0200, Peter Zijlstra wrote:
> On Thu, Aug 27, 2026 at 05:35:44AM -0400, Aaron Tomlin wrote:
>
> > To solve this cleanly, I propose introducing a concise helper, for the root
> > domain in kernel/sched/sched.h mirroring rcu_dereference_sched_domain(p):
> >
> > #define rcu_dereference_root_domain(p) \
> > rcu_dereference_all_check((p), lockdep_is_held(&sched_domains_mutex))
> >
> > This covers both the update side (under sched_domains_mutex) and read-side
> > contexts (under rq_lock(), preemption-disabled, or RCU read locks) via
> > rcu_read_lock_any_held(), while keeping the call sites clean and
> > eliminating Sparse warnings.
> >
> > Would you prefer rcu_dereference_root_domain(p)?
>
> Yeah, but I'm not sure I see the point of adding it, as it is exactly
> the same as rcu_dereference_sched_domain(). The root domains are part of
> the sched domains, so it doesn't seem wrong to me to use that existing
> one.

Indeed. However, the motivation is purely code clarity. Defining
rcu_dereference_root_domain() preserves the natural symmetry of rq->rd and
rq->sd in struct rq, while keeping grep-ability straightforward.

That said, should you still prefer reusing rcu_dereference_sched_domain(),
I am quite happy to convert them over.

Kind regards,
--
Aaron Tomlin