mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Uclamp races due to non-atomic static_branch_likely updates
@ 2026-10-20 18:53 John Stultz
  2026-10-20 19:29 ` Steven Rostedt
  0 siblings, 1 reply; 9+ messages in thread
From: John Stultz @ 2026-10-20 18:53 UTC (permalink / raw)
  To: Peter Zijlstra, Vincent Guittot, Christian Loehle, Qais Yousef,
	Steven Rostedt
  Cc: LKML, Hongyan Xia, Ingo Molnar, Wei Wang, Patrick Bellasi,
	Dietmar Eggemann

Hey all,
  So Wei Wang raised an interesting issue recently: He was seeing a
race where when uclamp is enabled (from calling
sched_uclamp_enable()), the static_branch_enable() call will go
through updating the static_branch_likely(&sched_uclamp_used) sites
where the inlined uclamp_is_used() is checked.

The problem being, while the jump label sites are being modified on
one cpu, another cpu might be executing some of these functions and
get inconsistent results.

Specifically in the case where uclamp_rq_inc() on a task is called
followed by uclamp_rq_dec(), its possible that a
static_branch_enable() call modifies the inlined uclamp_is_used()
check in uclamp_rq_inc() first, then on another cpu, uclamp_rq_inc()
is called, sees uclamp_is_used() is true, and increments the buckets.
Then uclamp_rq_dec() is called, but since we're still racing against
the jump table updates, the inlined uclamp_is_used() in that function
returns false and it doesn't do the decrements, leaving things
imbalanced.

Most of the usage I've seen around static_branch/keys treat them as a
magic-compiler global boolean, so to me it seemed this sublte
non-atomic updates could be more widely problematic then just the
uclamp case.

That said, I'm a bit confused, as looking at the jump_label_update()
usage, we already have a key->enabled guard value which can tell us if
the update is in progress. However, despite the logic table in
include/linux/jump_label.h suggesting enabled is used, I don't see it
in the static_branch_[un]likely() -> arch_static_branch[_jump]() logic
(though I recognize the whole point of the static branch logic is to
avoid the conditional, so adding a guard check would undo the benefit
here).

Maybe should the jump_label_update() logic be using something like
stop_machine? Or should there still be a conditional on key->enabled
in the unlikely case to make the behavior consistent? Or is there just
something about the uclamp usage that is off?

Anyway, Wei has proposed dropping the if (!uclamp_is_used()) check in
uclamp_rq_dec() to ensure we always handle the decrement side to
resolve this, but I wanted to see if there were other thoughts on how
we could still preserve the static branch optimization there.

Thoughts?

thanks
-john

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-10-21 14:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-20 18:53 Uclamp races due to non-atomic static_branch_likely updates 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
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

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®