Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1357901pxb; Fri, 27 Aug 2021 07:12:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8TaZA9weP3XZol1SHJWcpVhmUUFk613UvUYdKgbAfCZhPEaQa/Y240vBOxOf8p0ZbGaGh X-Received: by 2002:aa7:c790:: with SMTP id n16mr10052928eds.223.1630073562833; Fri, 27 Aug 2021 07:12:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630073562; cv=none; d=google.com; s=arc-20160816; b=UL45vFSHA3Jm7llbbhPg3thTyU3h4CRrR1ks60IY+Gwjur6H0ETbpBlCozKLi77/QS NlIzAdKVDfe57C3iINbYa40zjDcNZMgERSi0wQWhHq092dcjgFE6jqkxLWRyWnC22Y7v oJ3yQ8yskf8C12HdpCMemR0f1+ZTrkI8UcJyFixz4fCVnNG5V9asXxxT9RiEcL+m7lqO vHKQQ3IWvqA4LcymjyyzP4e96ZZpSyXdR704A3JbpAkPrMplE5R7ee6XFyZZkvNYbGsN MeMgCQ6JO/LBSVmYqAXptqJZ4OlPkX9p9rlGX/PIi77LmKo9ADaq0ybgcqAzz1Jvczzz yHPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to :dkim-signature:dkim-signature:from; bh=11NIC+pr+SwPLcFh+rYzsUwGFwRQn2PPhhrNnoAS/Hk=; b=1CA4K2pSTgjMmLVmhliV/2ognCcFzNkEIA1QZfBW+xQ/6PP2Tbkjxffb3yDZgtXcGA mWkvEk7nzkvxWemh14RZH8HPlONa3dmDXlegOHfMM33bXXL+PJYu5v2pYLSvSDic0GWp 5Ejgsmqepp7zYMi3HWIYw4Jqj7t7NpZgYdgg0rfMtTX3NZOZVrtlJ7+l13OT99bejJqB U0E0tGWq1WHi92xdgbPz3n0mcKELMm0qQFse3Y1R/ST+uPBhy8FzHd6V8EdaYEPbnFjk 5FUnexLzQLVKODCLgWAx4l/xhYgXQc6N+NkVl4QLkJs4cYrSO6cHpTcsQ3JZirsqyTIs DGBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="FA/a8YDH"; dkim=neutral (no key) header.i=@linutronix.de header.b=Tt7ESV8h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k16si6689177edo.475.2021.08.27.07.12.08; Fri, 27 Aug 2021 07:12:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="FA/a8YDH"; dkim=neutral (no key) header.i=@linutronix.de header.b=Tt7ESV8h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232477AbhH0OIW (ORCPT + 99 others); Fri, 27 Aug 2021 10:08:22 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:38472 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231571AbhH0OIV (ORCPT ); Fri, 27 Aug 2021 10:08:21 -0400 From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1630073251; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=11NIC+pr+SwPLcFh+rYzsUwGFwRQn2PPhhrNnoAS/Hk=; b=FA/a8YDH9ZywgSQADqEWqAEC32qDJ1g3ObowrKmhnXpy8W5EgZverx9AHMuh6mqfBVNY0T yg1Pkb2cs3XZrm74KScyzZ83FA5loJXDF3SZ/xA6tYcgAzqZbP9pw/9qFleloyVOy2Fj9+ H1FWQn8pE9MNgDVmlTEZvdWz2mnlGSKcVUf1twKlL2Bkv9rZkF3JuI/MDJt0YOsFLfj9g9 N4tRP5es7MbdSGKOaECjvlauK1625y6SYmo33khDkE+IaMsVQH9YtqD41tB5pGwezcv5su a/B5X6xCNGSso2BVN62Tdq+NWiIq2TUQuFZbTyeSHODD9tZ/8YPEYL9Dqx29yg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1630073251; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=11NIC+pr+SwPLcFh+rYzsUwGFwRQn2PPhhrNnoAS/Hk=; b=Tt7ESV8hwG8E9hl9zdPAzSx+ERfKFDb5RXSUMYOtUjiqVNI00gNOJWevWju1hENZfxXES+ UwFnUzefUSnm21Bw== 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 Subject: [PATCH] sched: Prevent balance_push() on remote runqueues Date: Fri, 27 Aug 2021 16:07:30 +0200 Message-ID: <87tujb0yn1.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Thomas Gleixner 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; /*