Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1255517imm; Sun, 15 Jul 2018 03:16:54 -0700 (PDT) X-Google-Smtp-Source: AAOMgpccVP9w7e2j83+RP9sBw+boSrN0KbyB2RM7yiqqetBcjoJnQof9ViVJiBAszev8lSGfNYlW X-Received: by 2002:a17:902:a9:: with SMTP id a38-v6mr12892477pla.102.1531649814542; Sun, 15 Jul 2018 03:16:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531649814; cv=none; d=google.com; s=arc-20160816; b=Bojh9STqc5ob0mUP763XROcqZ2hDOttb4iLh+ggr4RBAXsVVagkhLzoMTVo/UDgvB0 /1y3kMx8etuLkovB9WyvsFdPR1ibycr32GctYf+diYk+9jFsDxA6ob+uVUhRhNSkw+Vr b5D7IQuqD+HqjtIpUBvT9fCQ7jG4Soota04UKalaS+irdCXk5M3vzGBX4X9gBJukuaRy 20zB1i1W7KY5J7IdAtew2DyNNqdggU/FH1F7K/El8ZCSX85vzw9c/+242wM0Zc/cVNYX FAYNf8Nk/bwdHXV4Q7lXctvh/fZUnZZf5CEdfxSaNKVxSZC2gcn2Se9tfffLsw/+5o7G 8r3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=mTiIjctogNWoupgcGgOXiWXy+4La7tPKmGNqTVIqr3s=; b=MUowerXxYKRm722aZuUgl0f1E+ufANpQvFr9XFg405W0vsqSUMlR1Y7sOEJzpAGrZl oYw/cDd88OuRqkcpkKZv0HU2cIB7tkn80vENblBHKsIi/+ikkQbIKgDREnVpEW272Gvw s1QJIQ3+4RS5BkwMqB9UBVpfo1Bwf7+X0PhdKHv7L65kMDBVuu8aGwfr506mgP1dWxnY a4lFIGyacGkYIXwxtGIC/NDyaRS2SbWnM4NH0860jqQl1B7AkS9J5MFDPI3VuoeDHILG BrfidVojRxPg1LWRfo6COKgVCG8bufxem4aEMYInTLWhV/ZNL3o8i8G72LA2hOrLrgth tqLw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h16-v6si28238339pgb.39.2018.07.15.03.16.39; Sun, 15 Jul 2018 03:16:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726141AbeGOKic (ORCPT + 99 others); Sun, 15 Jul 2018 06:38:32 -0400 Received: from terminus.zytor.com ([198.137.202.136]:59053 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726030AbeGOKic (ORCPT ); Sun, 15 Jul 2018 06:38:32 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w6FAFt8j738816 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sun, 15 Jul 2018 03:15:55 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w6FAFoFP738776; Sun, 15 Jul 2018 03:15:50 -0700 Date: Sun, 15 Jul 2018 03:15:50 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: "tip-bot for Isaac J. Manjarres" Message-ID: Cc: mingo@kernel.org, pkondeti@codeaurora.org, psodagud@codeaurora.org, tglx@linutronix.de, hpa@zytor.com, linux-kernel@vger.kernel.org, isaacm@codeaurora.org Reply-To: isaacm@codeaurora.org, hpa@zytor.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@kernel.org, psodagud@codeaurora.org, pkondeti@codeaurora.org In-Reply-To: <1530655334-4601-1-git-send-email-isaacm@codeaurora.org> References: <1530655334-4601-1-git-send-email-isaacm@codeaurora.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:sched/urgent] stop_machine: Disable preemption when waking two stopper threads Git-Commit-ID: 9fb8d5dc4b649dd190e1af4ead670753e71bf907 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 9fb8d5dc4b649dd190e1af4ead670753e71bf907 Gitweb: https://git.kernel.org/tip/9fb8d5dc4b649dd190e1af4ead670753e71bf907 Author: Isaac J. Manjarres AuthorDate: Tue, 3 Jul 2018 15:02:14 -0700 Committer: Thomas Gleixner CommitDate: Sun, 15 Jul 2018 12:12:45 +0200 stop_machine: Disable preemption when waking two stopper threads When cpu_stop_queue_two_works() begins to wake the stopper threads, it does so without preemption disabled, which leads to the following race condition: The source CPU calls cpu_stop_queue_two_works(), with cpu1 as the source CPU, and cpu2 as the destination CPU. When adding the stopper threads to the wake queue used in this function, the source CPU stopper thread is added first, and the destination CPU stopper thread is added last. When wake_up_q() is invoked to wake the stopper threads, the threads are woken up in the order that they are queued in, so the source CPU's stopper thread is woken up first, and it preempts the thread running on the source CPU. The stopper thread will then execute on the source CPU, disable preemption, and begin executing multi_cpu_stop(), and wait for an ack from the destination CPU's stopper thread, with preemption still disabled. Since the worker thread that woke up the stopper thread on the source CPU is affine to the source CPU, and preemption is disabled on the source CPU, that thread will never run to dequeue the destination CPU's stopper thread from the wake queue, and thus, the destination CPU's stopper thread will never run, causing the source CPU's stopper thread to wait forever, and stall. Disable preemption when waking the stopper threads in cpu_stop_queue_two_works(). Fixes: 0b26351b910f ("stop_machine, sched: Fix migrate_swap() vs. active_balance() deadlock") Co-Developed-by: Prasad Sodagudi Signed-off-by: Prasad Sodagudi Co-Developed-by: Pavankumar Kondeti Signed-off-by: Pavankumar Kondeti Signed-off-by: Isaac J. Manjarres Signed-off-by: Thomas Gleixner Cc: peterz@infradead.org Cc: matt@codeblueprint.co.uk Cc: bigeasy@linutronix.de Cc: gregkh@linuxfoundation.org Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/1530655334-4601-1-git-send-email-isaacm@codeaurora.org --- kernel/stop_machine.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c index f89014a2c238..1ff523dae6e2 100644 --- a/kernel/stop_machine.c +++ b/kernel/stop_machine.c @@ -270,7 +270,11 @@ unlock: goto retry; } - wake_up_q(&wakeq); + if (!err) { + preempt_disable(); + wake_up_q(&wakeq); + preempt_enable(); + } return err; }