All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched: Prevent balance_push() on remote runqueues
@ 2021-08-27 14:07 Thomas Gleixner
  2021-08-28  7:21 ` Thomas Gleixner
  0 siblings, 1 reply; 6+ messages in thread
From: Thomas Gleixner @ 2021-08-27 14:07 UTC (permalink / raw)
  To: LKML
  Cc: Peter Zijlstra, Valentin Schneider, Daniel Bristot de Oliveira,
	Juri Lelli, Vincent Guittot, Steven Rostedt, Ben Segall,
	Ingo Molnar, Mel Gorman, Dietmar Eggemann

sched_setscheduler() and rt_mutex_setprio() invoke the run-queue balance
callback after changing priorities or the scheduling class of a task. The
run-queue for which the callback is invoked can be local or remote.

That's not a problem for the regular rq::push_work which is serialized with
a busy flag in the run-queue struct, but for the balance_push() work which
is only valid to be invoked on the outgoing CPU that's wrong. It not only
triggers the debug warning, but also leaves the per CPU variable push_work
unprotected, which can result in double enqueues on the stop machine list.

Remove the warning and check that the function is invoked on the
outgoing CPU. If not, just return and do nothing.

Fixes: ae7927023243 ("sched: Optimize finish_lock_switch()")
Reported-by: Sebastian Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
---
 kernel/sched/core.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -8523,7 +8523,6 @@ static void balance_push(struct rq *rq)
 	struct task_struct *push_task = rq->curr;
 
 	lockdep_assert_rq_held(rq);
-	SCHED_WARN_ON(rq->cpu != smp_processor_id());
 
 	/*
 	 * Ensure the thing is persistent until balance_push_set(.on = false);
@@ -8531,9 +8530,10 @@ static void balance_push(struct rq *rq)
 	rq->balance_callback = &balance_push_callback;
 
 	/*
-	 * Only active while going offline.
+	 * Only active while going offline and when invoked on the outgoing
+	 * CPU.
 	 */
-	if (!cpu_dying(rq->cpu))
+	if (!cpu_dying(rq->cpu) && rq == this_rq())
 		return;
 
 	/*

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

end of thread, other threads:[~2021-09-09  9:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-27 14:07 [PATCH] sched: Prevent balance_push() on remote runqueues Thomas Gleixner
2021-08-28  7:21 ` Thomas Gleixner
2021-08-28 13:55   ` [PATCH V2] " Thomas Gleixner
2021-08-28 17:17     ` Tao Zhou
2021-08-30  9:12     ` Peter Zijlstra
2021-09-09  9:38     ` [tip: sched/urgent] " tip-bot2 for Thomas Gleixner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.