mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Qais Yousef <qyousef@layalina.io>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	John Stultz <jstultz@google.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Christian Loehle <christian.loehle@arm.com>,
	Qais Yousef <qyousef@google.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Hongyan Xia <hongyan.xia2@arm.com>,
	Ingo Molnar <mingo@kernel.org>, Wei Wang <wvw@google.com>,
	Patrick Bellasi <patrick.bellasi@arm.com>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>
Subject: Re: Uclamp races due to non-atomic static_branch_likely updates
Date: Wed, 21 Oct 2026 15:29:56 +0200	[thread overview]
Message-ID: <20261021132956.GO2823843@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20261021132058.kxzyumgxzir4jzi2@airbuntu>

On Wed, Oct 21, 2026 at 02:20:58PM +0100, Qais Yousef wrote:

> > Also note that a simple global boolean has the exact same problem.
> > Adding runtime conditionals isn't going to fix this.
> 
> I have something in my memory that could be complete garbage that tells me all
> cpus should see the new update after a grace period, did my brain invent this?

This is true; rcu_sync() implies a memory barrier on all CPUs, and
therefore all CPUs must observe the prior state upon completion.

The thing is that a grace period is of 'arbitrary length' and during
that you can still have some CPUs seeing your variable set while others
will not and you get into the very same problem.

> If not invented, can we do synchronize_rcu() once on any cpu seeing the code
> enabled for the first time to ensure the rest of the cpus has seen the newly
> enabled path?
> 
> eg (not even compile tested):
> 
> 	diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> 	index 7d2ec527b8a2..a6093ec88103 100644
> 	--- a/kernel/sched/sched.h
> 	+++ b/kernel/sched/sched.h
> 	@@ -3715,7 +3715,16 @@ unsigned long uclamp_eff_value(struct task_struct *p, enum uclamp_id clamp_id);
> 	  */
> 	 static inline bool uclamp_is_used(void)
> 	 {
> 	-       return static_branch_likely(&sched_uclamp_used);
> 	+       if (static_branch_likely(&sched_uclamp_used)) {
> 	+               static bool do_once = true;
> 	+               if (unlikely(do_once)) {
> 	+                       do_once = false;
> 	+                       synchronize_rcu();
> 	+               }
> 	+               return true;
> 	+       }
> 	+
> 	+       return false;
> 	 }
> 
> 	 /*

This cannot work; two immediate problems:

 - the do_once needs re-evaluating for every switch
 - you cannot do rcu_sync while holding rq->lock ;-)

> The other alternative is to just accept this race can happen and do some sanity
> check and reset/cleanup on going to idle - which should be pretty cheap and
> straightforward.

This seems the sanest option.

  reply	other threads:[~2026-10-21 13:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-20 18:53 John Stultz
2026-10-20 19:29 ` Steven Rostedt
2026-10-21 11:38   ` Peter Zijlstra
2026-10-21 13:20     ` Qais Yousef
2026-10-21 13:29       ` Peter Zijlstra [this message]
2026-10-21 14:02         ` Qais Yousef
2026-10-21 13:21     ` Steven Rostedt
2026-10-21 13:34       ` Peter Zijlstra
2026-10-21 13:59         ` Steven Rostedt

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=20261021132956.GO2823843@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=christian.loehle@arm.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=hongyan.xia2@arm.com \
    --cc=jstultz@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=patrick.bellasi@arm.com \
    --cc=qyousef@google.com \
    --cc=qyousef@layalina.io \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=wvw@google.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

all inboxes | Powered by JetHome®