Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3528427pxf; Mon, 15 Mar 2021 11:33:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/a1q5TJpQxctwuytrgjkuZRFH8p0lfRGB5pClYbIizwn2hojQMYMV2t/aZe8iEo3FUw9O X-Received: by 2002:a17:907:d8a:: with SMTP id go10mr25557488ejc.46.1615833239038; Mon, 15 Mar 2021 11:33:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615833239; cv=none; d=google.com; s=arc-20160816; b=rtnergHybjZbHtF4raWOljdY0FilbnZ1MQYOtlb0fDN6IX+SCVFDzvQsXJabFRgzNI EyV4k0BoqL8h4njVB2aWRFmEMwRzV3LHxm2VqI5npgYb+tIDnjhsy0CvSonI3t9YsfbU GA8olwL0SPixWdvD2f2nfOmGmNtog1DibjtdYJpAwM0AQ0HAaklW3brFOld/ywaBOv3o +Av3KHeUouuNrTsfTbhlZMcbZlebeOoEsno0OU31QEgCfLru2tuDeDTo4ADmSHW5rzLH NGeIlH8UIF7/FNFHhE+s/gNUqWnJ4xHXUwFDQwLoX8UMrsUOHDDHrp1in+RakSNpKavv xYlg== 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=orCyVfvXoThJ9Bhnp5KnMfVObG4hJnMhVE/ks38IJmc=; b=W0F/fYqij2IuG56cY2823Jc94L+EyCoV301RZPNVtslw09Hqu3SSGNfg3Yd8PTxawu zkojU09LIFbSydWPkWRP3vxUe6LgJtqG5GEPLpme1NlDILd4y9oqusCR2V6TDaE+3xeM ugr7lGtWbcmdQKpOnpj4pLYrgQCJDiY1dzrao7oE7S+U3ccuU9prkKJrCfJC/ZXA75Ku QhoIwMUVofvmWEsHHh7KMb8M0NsPusUhFNLRNNf1KDyyaFUtLOAKvbeum3mhgYNpz/nU aOVgTWZmeK0tl0w3VEFtFnD9aeqm+YLa5dbkoMWD3rApigAhHcy2bGZ3cFjeeKw6qokf zKJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dfJ4qTEm; 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 k2si11248893ejr.529.2021.03.15.11.33.36; Mon, 15 Mar 2021 11:33:59 -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=dfJ4qTEm; 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 S238921AbhCOOpW (ORCPT + 99 others); Mon, 15 Mar 2021 10:45:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:51810 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234542AbhCOOEO (ORCPT ); Mon, 15 Mar 2021 10:04:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A4A4464EE3; Mon, 15 Mar 2021 14:04:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615817054; bh=Vp34CFmEdB6pIqcX7xV3sokzG4TTobf7lhnf2zX29gE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dfJ4qTEmQJGHAGgBBmHFuiDYtLQQ7eA5xv1Z3zo2GIiE3fLvhBYv+jV4nwTYJMODF BTWRQ99q4o7/6O4aJwI9EEXSL4gLsL3bNBLngED2cabBRFmaOQ9n9Noi35Y5EVOfru iL/GXZFd1STk70/sAiDo3PGl5lT2rhd4vUbyOhU4= 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 277/306] sched: Fix affine_move_task() self-concurrency Date: Mon, 15 Mar 2021 14:55:40 +0100 Message-Id: <20210315135517.027782694@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 9e81889c7648d48dd5fe13f41cbc99f3c362484a upstream. Consider: sched_setaffinity(p, X); sched_setaffinity(p, Y); Then the first will install p->migration_pending = &my_pending; and issue stop_one_cpu_nowait(pending); and the second one will read p->migration_pending and _also_ issue: stop_one_cpu_nowait(pending), the _SAME_ @pending. This causes stopper list corruption. Add set_affinity_pending::stop_pending, to indicate if a stopper is in progress. 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.649146419@infradead.org Signed-off-by: Greg Kroah-Hartman --- kernel/sched/core.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1864,6 +1864,7 @@ struct migration_arg { struct set_affinity_pending { refcount_t refs; + unsigned int stop_pending; struct completion done; struct cpu_stop_work stop_work; struct migration_arg arg; @@ -1982,12 +1983,15 @@ static int migration_cpu_stop(void *data * determine is_migration_disabled() and so have to chase after * it. */ + WARN_ON_ONCE(!pending->stop_pending); task_rq_unlock(rq, p, &rf); stop_one_cpu_nowait(task_cpu(p), migration_cpu_stop, &pending->arg, &pending->stop_work); return 0; } out: + if (pending) + pending->stop_pending = false; task_rq_unlock(rq, p, &rf); if (complete) @@ -2183,7 +2187,7 @@ static int affine_move_task(struct rq *r int dest_cpu, unsigned int flags) { struct set_affinity_pending my_pending = { }, *pending = NULL; - bool complete = false; + bool stop_pending, complete = false; /* Can the task run on the task's current CPU? If so, we're done */ if (cpumask_test_cpu(task_cpu(p), &p->cpus_mask)) { @@ -2256,14 +2260,19 @@ static int affine_move_task(struct rq *r * anything else we cannot do is_migration_disabled(), punt * and have the stopper function handle it all race-free. */ + stop_pending = pending->stop_pending; + if (!stop_pending) + pending->stop_pending = true; refcount_inc(&pending->refs); /* pending->{arg,stop_work} */ if (flags & SCA_MIGRATE_ENABLE) p->migration_flags &= ~MDF_PUSH; task_rq_unlock(rq, p, rf); - stop_one_cpu_nowait(cpu_of(rq), migration_cpu_stop, - &pending->arg, &pending->stop_work); + if (!stop_pending) { + stop_one_cpu_nowait(cpu_of(rq), migration_cpu_stop, + &pending->arg, &pending->stop_work); + } if (flags & SCA_MIGRATE_ENABLE) return 0;