Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3528504pxf; Mon, 15 Mar 2021 11:34:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzs3nStCA8jNZ1CPxhaj5J1hYCAg6yZg+6VuDEGXfuaqvkwC+2W/uDZ/eWnFZ/0Zwr8tsLd X-Received: by 2002:a17:906:c402:: with SMTP id u2mr25121694ejz.546.1615833245574; Mon, 15 Mar 2021 11:34:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615833245; cv=none; d=google.com; s=arc-20160816; b=O4wcAqAd+2K2owovOoOI+MGxJEB6dR12dW+10gFU4VwtBrwICst1MbXu2zMNroVq7G TVs0IPIYWkRXcSPkzBJXdx5wVy+47qw+8aQMb0Y/F1VNC94rk9+gWK1ps+2K224cY29K MvIDIsGUeQUQvIvIZQY172zf8SvihbOTq+srZyMaReEeGo5CztubeSe+W0/vGV1PiGlO QFj0qP1iP8YpzBhecuD+TMWKMiIxw0NMy2AIfyM0Z8cjTxI65ZWEOuFyhPDGT/pVCGHJ 0HYBzBBv43zo5Syox0FMgJFAXxa6NYZV9E7M+U+kmeVuIEVu2xqgMl8Jicrl3RKZfwbj z/Aw== 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=Yx86GnoE3fgkPv+NXi3gk+rbu5seQqfEnLl5OBg80tw=; b=tRTQVlE0Pe3DLxqkmgXLY6/vjYuDeGwycyQ9Dr8pC3njPBZ1VZKb3kHFuJXJZJ+BZr /4m62Dp2I4rEaVVIG25uD8uOoqGEEfmwgib8A6OHvITzvrzHtEDgPTBXB6npD9xncsH7 57Wvi2op/bFWcW6SK6K9RoiKFURFd3E/qrouPmhmaqZhFg5u3PS0TqkjmwK5ddazIuyc ub4Mf8VuAl2v0bSD+pX50j3dgCvThZzCao2tL+rNvddzdZKpy0p7A5cKbHkxOgBycQ03 cS8wcrPxGL/IwDxYkOv3gRqy3wtalieXBszoj8F7PyHzwRSEfnI6Adg+jG6q4tE/oMEn DEPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=roUPhtKK; 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 u13si11224873ejc.243.2021.03.15.11.33.43; Mon, 15 Mar 2021 11:34:05 -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=roUPhtKK; 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 S238792AbhCOOpg (ORCPT + 99 others); Mon, 15 Mar 2021 10:45:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:51960 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234545AbhCOOER (ORCPT ); Mon, 15 Mar 2021 10:04:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 847D064E89; Mon, 15 Mar 2021 14:04:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615817055; bh=UPEbvgQAMpZ8MPZYPFSzw49Va+WUebUD+ZGbXcx94cE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=roUPhtKKIPDdy5hW+wvuxKCtHKsVMBLN42Vz/fRAbDCtxiZtz+e5xjdNM/J1dcGx9 9wmuraD06Qh8pjMX0ujhS6gOlOMv60mW1KKCoeX8N0wQq6h6I9uuYWtYi+V8fxi0N2 g1xt9QouynKNDsffLLnr/dAZhhURGURHouPOfFVw= 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 278/306] sched: Simplify set_affinity_pending refcounts Date: Mon, 15 Mar 2021 14:55:41 +0100 Message-Id: <20210315135517.065144356@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 50caf9c14b1498c90cf808dbba2ca29bd32ccba4 upstream. Now that we have set_affinity_pending::stop_pending to indicate if a stopper is in progress, and we have the guarantee that if that stopper exists, it will (eventually) complete our @pending we can simplify the refcount scheme by no longer counting the stopper thread. 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.724130207@infradead.org Signed-off-by: Greg Kroah-Hartman --- kernel/sched/core.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1862,6 +1862,10 @@ struct migration_arg { struct set_affinity_pending *pending; }; +/* + * @refs: number of wait_for_completion() + * @stop_pending: is @stop_work in use + */ struct set_affinity_pending { refcount_t refs; unsigned int stop_pending; @@ -1997,10 +2001,6 @@ out: if (complete) complete_all(&pending->done); - /* For pending->{arg,stop_work} */ - if (pending && refcount_dec_and_test(&pending->refs)) - wake_up_var(&pending->refs); - return 0; } @@ -2199,12 +2199,16 @@ static int affine_move_task(struct rq *r push_task = get_task_struct(p); } + /* + * If there are pending waiters, but no pending stop_work, + * then complete now. + */ pending = p->migration_pending; - if (pending) { - refcount_inc(&pending->refs); + if (pending && !pending->stop_pending) { p->migration_pending = NULL; complete = true; } + task_rq_unlock(rq, p, rf); if (push_task) { @@ -2213,7 +2217,7 @@ static int affine_move_task(struct rq *r } if (complete) - goto do_complete; + complete_all(&pending->done); return 0; } @@ -2264,9 +2268,9 @@ static int affine_move_task(struct rq *r 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); if (!stop_pending) { @@ -2282,12 +2286,13 @@ static int affine_move_task(struct rq *r if (task_on_rq_queued(p)) rq = move_queued_task(rq, rf, p, dest_cpu); - p->migration_pending = NULL; - complete = true; + if (!pending->stop_pending) { + p->migration_pending = NULL; + complete = true; + } } task_rq_unlock(rq, p, rf); -do_complete: if (complete) complete_all(&pending->done); } @@ -2295,7 +2300,7 @@ do_complete: wait_for_completion(&pending->done); if (refcount_dec_and_test(&pending->refs)) - wake_up_var(&pending->refs); + wake_up_var(&pending->refs); /* No UaF, just an address */ /* * Block the original owner of &pending until all subsequent callers @@ -2303,6 +2308,9 @@ do_complete: */ wait_var_event(&my_pending.refs, !refcount_read(&my_pending.refs)); + /* ARGH */ + WARN_ON_ONCE(my_pending.stop_pending); + return 0; }