Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1228138pxb; Fri, 20 Nov 2020 04:37:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJwpgj6/LIkLyKtd9we6VselPm4W4an5qslPL93vVHfQWl6RvA5RAPws4K6Et7gVPCtNV6// X-Received: by 2002:a17:907:411b:: with SMTP id nw19mr31761269ejb.150.1605875829083; Fri, 20 Nov 2020 04:37:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605875829; cv=none; d=google.com; s=arc-20160816; b=Lj3tm5bUMyK+OUTh3Xn9b1etnqKPz8M13twtwvLxflMd1PuxIo3Lgxq80PSvnwCPYp 1QGmRFvq0VvEzF46u/Z7LAw6Oa83R4DbFcs8R61YyiuWtzzytn1QxB29KkPOo4VS2NKh 8bCuz141h+wa0G0r6PheTtBwUK7vNFeit5/x+whpydVhuY636LnoL1TSYKwVxvxpynL7 6bfEXRnh1f2IPgR23GJf1GCXM/MU6ROm6oQme/dvOuG/FQx2TAOEV4IlT1/4u79Zo6sU n4qdSYicGFJhKnCFtZnK2lNyo2einA0KOZLlf5pgnrmEzdqVCJPsejW2aeTxATMvoblY JZvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=adTR/ZzEE9+Fki0waYDdfgexZDXUHJMWOJkKEONpXEw=; b=Oz70AiQAdW+E4uH4Q/2jXOXA++HUSvJJVAh2VDXzjF1KmDFvvTxlpYFAunXuu2wGRO aEmapEwoOAG+19mbQ5wigjigU+30lxSv81GVgDDiSMEsodqBp0g6pcIy+qke2raWGoNz A02Aa8JMH2Fn8sehSecGd81qsiZwabbVo9cFDtxDbzmMmF0ifGe3ALQ4EEYu5POI5YfE gOaAJAMXtzP2vU4CNjS5QZPP/anapOnzhiyK8bhuoHkDWCAph1v+n6X2GW/OYgNCYoQC bV8G4/JrzgrotwOeMDb6i1YJv6X9ysTf4HwTBEY381Eevz9lFNJ0mMq1ZYM2IWtjXc3y P8iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=nXCt3Amp; dkim=neutral (no key) header.i=@linutronix.de; 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 cc13si1705369edb.104.2020.11.20.04.36.46; Fri, 20 Nov 2020 04:37:09 -0800 (PST) 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=nXCt3Amp; dkim=neutral (no key) header.i=@linutronix.de; 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 S1728161AbgKTMeN (ORCPT + 99 others); Fri, 20 Nov 2020 07:34:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728136AbgKTMeM (ORCPT ); Fri, 20 Nov 2020 07:34:12 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 295CCC0617A7; Fri, 20 Nov 2020 04:34:12 -0800 (PST) Date: Fri, 20 Nov 2020 12:34:09 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1605875650; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=adTR/ZzEE9+Fki0waYDdfgexZDXUHJMWOJkKEONpXEw=; b=nXCt3Amp5jZWylNYZfsbFRVTSAB9WOeUZ96a+kdCN5YlvcH1PyooYOgYUxky5Rqvwzhb1X FfWAuhPQXx0l/G1XwEUFh/IvYUnZRFvaCQK0kS6BsgpOKw9DsNEBh/Sktu9rlUziO47lxv Oowb/gYFwDnso2j/lAdkvlBmo8ssHCaUCYEJgaPrUD6ZOt2ZYXdBZq+WIM1VIsBDUYebNr Jp9HpdV63DoJUr1hIyWDRUeJZ9tq41yw09RksR0wYOasH3u+9GPgyYkM+MY+BrJGilZY9c Co09DBwFWeZsCfNFelyMHPtAlHCpt/xzuGHaXK/+NLYxkJDxfV/IF4zhPvbKAw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1605875650; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=adTR/ZzEE9+Fki0waYDdfgexZDXUHJMWOJkKEONpXEw=; b=aUtusVr1PONTEDgwX+9pB9bf1+Pzi/og5RUXO5eWIO3WOo9N63Pe0NRVVH6HP8aBMTDLW8 OdoCDYkq0I8xDJAg== From: "tip-bot2 for Valentin Schneider" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/core: Add missing completion for affine_move_task() waiters Cc: Qian Cai , Valentin Schneider , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <8b62fd1ad1b18def27f18e2ee2df3ff5b36d0762.camel@redhat.com> References: <8b62fd1ad1b18def27f18e2ee2df3ff5b36d0762.camel@redhat.com> MIME-Version: 1.0 Message-ID: <160587564979.11244.16095006261523066823.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the sched/core branch of tip: Commit-ID: d707faa64d03d26b529cc4aea59dab1b016d4d33 Gitweb: https://git.kernel.org/tip/d707faa64d03d26b529cc4aea59dab1b016d4d33 Author: Valentin Schneider AuthorDate: Fri, 13 Nov 2020 11:24:14 Committer: Peter Zijlstra CommitterDate: Thu, 19 Nov 2020 11:25:45 +01:00 sched/core: Add missing completion for affine_move_task() waiters Qian reported that some fuzzer issuing sched_setaffinity() ends up stuck on a wait_for_completion(). The problematic pattern seems to be: affine_move_task() // task_running() case stop_one_cpu(); wait_for_completion(&pending->done); Combined with, on the stopper side: migration_cpu_stop() // Task moved between unlocks and scheduling the stopper task_rq(p) != rq && // task_running() case dest_cpu >= 0 => no complete_all() This can happen with both PREEMPT and !PREEMPT, although !PREEMPT should be more likely to see this given the targeted task has a much bigger window to block and be woken up elsewhere before the stopper runs. Make migration_cpu_stop() always look at pending affinity requests; signal their completion if the stopper hits a rq mismatch but the task is still within its allowed mask. When Migrate-Disable isn't involved, this matches the previous set_cpus_allowed_ptr() vs migration_cpu_stop() behaviour. Fixes: 6d337eab041d ("sched: Fix migrate_disable() vs set_cpus_allowed_ptr()") Reported-by: Qian Cai Signed-off-by: Valentin Schneider Signed-off-by: Peter Zijlstra (Intel) Link: https://lore.kernel.org/lkml/8b62fd1ad1b18def27f18e2ee2df3ff5b36d0762.camel@redhat.com --- kernel/sched/core.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index a6aaf9f..4d1fd4b 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1923,7 +1923,7 @@ static int migration_cpu_stop(void *data) else p->wake_cpu = dest_cpu; - } else if (dest_cpu < 0) { + } else if (dest_cpu < 0 || pending) { /* * This happens when we get migrated between migrate_enable()'s * preempt_enable() and scheduling the stopper task. At that @@ -1934,6 +1934,17 @@ static int migration_cpu_stop(void *data) */ /* + * The task moved before the stopper got to run. We're holding + * ->pi_lock, so the allowed mask is stable - if it got + * somewhere allowed, we're done. + */ + if (pending && cpumask_test_cpu(task_cpu(p), p->cpus_ptr)) { + p->migration_pending = NULL; + complete = true; + goto out; + } + + /* * When this was migrate_enable() but we no longer have an * @pending, a concurrent SCA 'fixed' things and we should be * valid again. Nothing to do.