mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v9 0/3] Fix uclamp race against non atomic static key enable
@ 2026-11-29 18:40 Qais Yousef
  2026-11-29 18:40 ` [PATCH v9 1/3] sched/uclamp: Use wrappers instead of open coding UCLAMP_FLAG_IDLE Qais Yousef
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Qais Yousef @ 2026-11-29 18:40 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Vincent Guittot
  Cc: Christian Loehle, Dietmar Eggemann, Steven Rostedt, John Stultz,
	linux-kernel, Kayra Cizmeci, Qais Yousef

More sashiko races addressed..

Changes since v8:
	- Hopefully fix the last race reported by sashiko in
	  uclamp_update_active() for delayed and throttled tasks.

Changes since v7:
	- Reorder the series so the fair bandwidth control fix is before
	  the static key fix.
	- Address Sashiko's comments about potentially missing cpufreq
	  updates and not handling delayed tasks properly.
	- Handle Christian's point about the WARN_ON_ONCE() if
	  uclamp_update_active() is called when a sleeping task has
	  imbalanced .active set due to static key race condition.
	- Re-introduced the Fixes tag.

Changes since v6:
	- Use uclamp_rq_set() in init_uclamp_rq() to preserve
	  WRITE_ONCE() annotation

Changes since v5:
	- Drop patch 3 to partial revert subtracting rq->nr_running for
	  RT throttling.
	- Drop fixes tag from patch 1 as the series now is partially
	  fixed and not suitable for LTS.

Changes since v4:
	- Fix problems in fair/RT throttling logic that were exposed by
	  the original fix.

Changes since v3:
	- Fix Sashiko report about force_idle paths where
	  rq->nr_running is not 0 highlighted by Christian
	- Update patch 1 commit message to reflect jump_label call
	  sites on the same CPU might not be updated atomically too

Changes since v2:
	- Use uclamp_rq_is_idle() instead of scanning buckets to detect
	  imbalance
	- Do some cleanup on accessing the flag as an additional patch

Changes since v1:
	- Fix kernel test robot report due to missing static inline in dummy
	  definition of init_uclamp_rq()

Tested with the patch below to force imbalance via sched_feat. I could see the
warning appearing and frequencies spiking during imbalance. Correct behavior is
restored when sched_feat is disabled where the idle entry reset fixes things
up.

I had a mix of uclamp_max mainly used in the system via schedqosd.

	diff --git a/kernel/sched/core.c b/kernel/sched/core.c
	index a2035d66270b9..14f9f1e419e02 100644
	--- a/kernel/sched/core.c
	+++ b/kernel/sched/core.c
	@@ -1889,6 +1889,11 @@ static inline void uclamp_rq_inc(struct rq *rq, struct task_struct *p, int flags
		for_each_clamp_id(clamp_id)
			uclamp_rq_inc_id(rq, p, clamp_id);

	+       if (sched_feat(UCLAMP_IMBALANCED)) {
	+               for_each_clamp_id(clamp_id)
	+                       uclamp_rq_inc_id(rq, p, clamp_id);
	+       }
	+
		/* Reset clamp idle holding when there is one RUNNABLE task */
		if (uclamp_rq_is_idle(rq))
			uclamp_rq_clear_idle(rq);
	diff --git a/kernel/sched/features.h b/kernel/sched/features.h
	index 8f0dee8fc4755..b59e532500fd9 100644
	--- a/kernel/sched/features.h
	+++ b/kernel/sched/features.h
	@@ -142,3 +142,5 @@ SCHED_FEAT(LATENCY_WARN, false)
	  */
	 SCHED_FEAT(NI_RANDOM, true)
	 SCHED_FEAT(NI_RATE, true)
	+
	+SCHED_FEAT(UCLAMP_IMBALANCED, false)
	diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
	index 84301fc49e699..dbc3f5e1a7e01 100644
	--- a/kernel/sched/idle.c
	+++ b/kernel/sched/idle.c
	@@ -519,7 +519,7 @@ static void set_next_task_idle(struct rq *rq, struct task_struct *next, enum snt
		 * are still queued.
		 */
		if (uclamp_is_used() &&
	-           !rq->nr_running && unlikely(!uclamp_rq_is_idle(rq)))
	+           !rq->nr_running && unlikely(WARN_ON(!uclamp_rq_is_idle(rq))))
			init_uclamp_rq(rq);
	 }

Qais Yousef (3):
  sched/uclamp: Use wrappers instead of open coding UCLAMP_FLAG_IDLE
  sched/uclamp: Move uclamp_rq_{inc, dec}() from core.c
  sched/uclamp: Fix race condition leading to imbalanced uclamp_rq

 kernel/sched/core.c    | 68 ++++++++++++++++++++----------------------
 kernel/sched/ext/ext.c |  6 ++--
 kernel/sched/fair.c    | 16 +++++-----
 kernel/sched/idle.c    | 19 ++++++++++++
 kernel/sched/rt.c      | 10 ++++---
 kernel/sched/sched.h   | 22 +++++++++++---
 6 files changed, 86 insertions(+), 55 deletions(-)

-- 
2.53.0


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

end of thread, other threads:[~2026-11-30  2:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29 18:40 [PATCH v9 0/3] Fix uclamp race against non atomic static key enable Qais Yousef
2026-11-29 18:40 ` [PATCH v9 1/3] sched/uclamp: Use wrappers instead of open coding UCLAMP_FLAG_IDLE Qais Yousef
2026-11-30  0:06   ` Christian Loehle
2026-11-29 18:40 ` [PATCH v9 2/3] sched/uclamp: Move uclamp_rq_{inc, dec}() from core.c Qais Yousef
2026-11-29 18:40 ` [PATCH v9 3/3] sched/uclamp: Fix race condition leading to imbalanced uclamp_rq Qais Yousef
2026-11-29 23:03   ` kernel test robot
2026-11-29 23:42     ` Qais Yousef
2026-11-29 23:24   ` kernel test robot
2026-11-30  2:42   ` kernel test robot

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®