linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sched/ext: Suppress warning in __this_cpu_write() by disabling preemption
@ 2025-07-16 12:46 Breno Leitao
  2025-07-16 12:51 ` Peter Zijlstra
  2025-07-16 12:54 ` Steven Rostedt
  0 siblings, 2 replies; 14+ messages in thread
From: Breno Leitao @ 2025-07-16 12:46 UTC (permalink / raw)
  To: Tejun Heo, David Vernet, Andrea Righi, Changwoo Min, Ingo Molnar,
	Peter Zijlstra, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider
  Cc: sched-ext, linux-kernel, kernel-team, jake, Breno Leitao

__this_cpu_write() emits a warning if used with preemption enabled.

Function update_locked_rq() might be called with preemption enabled,
which causes the following warning:

	BUG: using __this_cpu_write() in preemptible [00000000] code: scx_layered_6-9/68770

Disable preemption around the __this_cpu_write() call in
update_locked_rq() to suppress the warning, without affecting behavior.

If preemption triggers a  jump to another CPU during the callback it's
fine, since we would track the rq state on the other CPU with its own
local variable.

Suggested-by: Andrea Righi <arighi@nvidia.com>
Signed-off-by: Breno Leitao <leitao@debian.org>
Fixes: 18853ba782bef ("sched_ext: Track currently locked rq")
Acked-by: Andrea Righi <arighi@nvidia.com>
---
 kernel/sched/ext.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index b498d867ba210..24fcbd7331f73 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -1258,7 +1258,14 @@ static inline void update_locked_rq(struct rq *rq)
 	 */
 	if (rq)
 		lockdep_assert_rq_held(rq);
+	/*
+	 * __this_cpu_write() emits a warning when used with preemption enabled.
+	 * While there's no functional issue if the callback runs on another
+	 * CPU, we disable preemption here solely to suppress that warning.
+	 */
+	preempt_disable();
 	__this_cpu_write(locked_rq, rq);
+	preempt_enable();
 }
 
 /*

---
base-commit: 155a3c003e555a7300d156a5252c004c392ec6b0
change-id: 20250716-scx_warning-5143cf17f806

Best regards,
--  
Breno Leitao <leitao@debian.org>


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

end of thread, other threads:[~2025-07-16 16:13 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-16 12:46 [PATCH] sched/ext: Suppress warning in __this_cpu_write() by disabling preemption Breno Leitao
2025-07-16 12:51 ` Peter Zijlstra
2025-07-16 13:15   ` Andrea Righi
2025-07-16 13:20     ` Breno Leitao
2025-07-16 13:40       ` Peter Zijlstra
2025-07-16 13:36     ` Peter Zijlstra
2025-07-16 14:26       ` Andrea Righi
2025-07-16 15:49         ` Peter Zijlstra
2025-07-16 16:08         ` Breno Leitao
2025-07-16 16:13           ` Andrea Righi
2025-07-16 12:54 ` Steven Rostedt
2025-07-16 13:06   ` Peter Zijlstra
2025-07-16 13:20     ` Andrea Righi
2025-07-16 13:33       ` Peter Zijlstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).