Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3529466pxf; Mon, 15 Mar 2021 11:35:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlk520wDDttdpqg3L+OhknTXkFSRH0ojyO3ELN4BnhI8UGCtJ5JWEhdQWqL3P0EhFYvCmi X-Received: by 2002:a17:907:f97:: with SMTP id kb23mr24976598ejc.33.1615833327604; Mon, 15 Mar 2021 11:35:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615833327; cv=none; d=google.com; s=arc-20160816; b=jcSRnfoyw3DhL4anrmf0tx30R8F0+zOdfrw+t9qxdBXu0/COb0f2bViR2FjEpNUsMV sgJEiiuJoiBkjQKPAjIrw5ab0DSBqkQqHwwU+6m0JgXR8ktWyPZ5tWUylDi5an3eHXor WDZONqmTzI2s67aY46PCIVq5ff52OF21LTPNpU8IKPPVYDaG60Bcn1K+yiNrtDsouy1x kRN2ukwo1e0Bid/a+5ok/VWhJY1Wb5Kj9yGgLzrUURUFZxY0NVTxqRPV9BcvTzt3H817 fgFWWH924NwZRdhxlSE/prKnl9EMnou+WWVao0DMxcKROmO+4pwF8v90Z5G/5UdGEXrV /Xvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uFK5FiRvQsroplPX6ieHFM+49YlId21OGATPFDCqTQQ=; b=u6/2L1iFQNBjpouSNw7vV19LEOeTHwLXfHqIO0d2TqsEMhmSCA5N+RRSHGjIaN8lsJ 3Y5T2NLFrkkiEXyoHtbOnmvH/dB6lCQ+dZ3cfUVY+/Q2hI1dl+iZoLLlM9xpT93urzZb GsnJH+Yi0wSMv531SRINjdB2+Znsp8Dot5NmXauEnMyp0v0YHcUmRWheI/pUoXhtCVwJ v6RjfZv7QRzoTJ5aCg1XnATB3g5bLDswnT3/FZniVn2P2s6SzqOmyGZtP1Pjj3PmVHHd b4vsTnoasFBGtyhx5vxJ15bROoIVJ9Mtk7e0Z/6wU1e7qI7V5mx3VWIMs+JLz3fDhRs6 rM0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Po3S2V0z; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id si28si12215498ejb.106.2021.03.15.11.35.05; Mon, 15 Mar 2021 11:35:27 -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=@linuxfoundation.org header.s=korg header.b=Po3S2V0z; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238893AbhCOOpS (ORCPT + 99 others); Mon, 15 Mar 2021 10:45:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:51696 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234532AbhCOOEM (ORCPT ); Mon, 15 Mar 2021 10:04:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DA0DB64E83; Mon, 15 Mar 2021 14:04:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615817052; bh=WPjeWVA1ttw7p/Rkyh3FafAywGgPmhm9Sf7XLwNoQCM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Po3S2V0zf3Al2m16NlaF5ngr9RpO/kaaVXJDecGojJ0LBKai1YW8j2tL4OEBx5xlp 6iYktc/HdJeSrgjpNMNjNS/QMzb7w9uAKcBQR7m07aninMF261WL2PWMkabWPq8WYf iK75YkBdflbYHwHOTfusSuO9mH+brEE1pdPbFMOQ= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, "Peter Zijlstra (Intel)" , Ingo Molnar , Valentin Schneider Subject: [PATCH 5.11 276/306] sched: Optimize migration_cpu_stop() Date: Mon, 15 Mar 2021 14:55:39 +0100 Message-Id: <20210315135516.995722029@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Peter Zijlstra commit 3f1bc119cd7fc987c8ed25ffb717f99403bb308c upstream. When the purpose of migration_cpu_stop() is to migrate the task to 'any' valid CPU, don't migrate the task when it's already running on a valid CPU. Fixes: 6d337eab041d ("sched: Fix migrate_disable() vs set_cpus_allowed_ptr()") Cc: stable@kernel.org Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar Reviewed-by: Valentin Schneider Link: https://lkml.kernel.org/r/20210224131355.569238629@infradead.org Signed-off-by: Greg Kroah-Hartman --- kernel/sched/core.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1936,14 +1936,25 @@ static int migration_cpu_stop(void *data complete = true; } - if (dest_cpu < 0) + if (dest_cpu < 0) { + if (cpumask_test_cpu(task_cpu(p), &p->cpus_mask)) + goto out; + dest_cpu = cpumask_any_distribute(&p->cpus_mask); + } if (task_on_rq_queued(p)) rq = __migrate_task(rq, &rf, p, dest_cpu); else p->wake_cpu = dest_cpu; + /* + * XXX __migrate_task() can fail, at which point we might end + * up running on a dodgy CPU, AFAICT this can only happen + * during CPU hotplug, at which point we'll get pushed out + * anyway, so it's probably not a big deal. + */ + } else if (pending) { /* * This happens when we get migrated between migrate_enable()'s