Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2818533imm; Sun, 5 Aug 2018 13:02:13 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeT/3/zu77+yG7XY8GnbZ8xVJHdLVeiKvTwWONNkWB/JACZz2X3p9JIZj2h4+49Nl+n+iF/ X-Received: by 2002:a63:5204:: with SMTP id g4-v6mr12108324pgb.274.1533499333209; Sun, 05 Aug 2018 13:02:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533499333; cv=none; d=google.com; s=arc-20160816; b=kEeOtbUAwwDmKt9u11BnnKtvmlKXf5sG8IrDBFnls+Z8WNX2vQ317YJIgzc/ZKnFa2 Qir3v1J01ikqRf89OSUlm4Udioqtwyf4XsFfORSQUZ4ZLMv9udXhZ7MppG8xPdi4unyJ IbomdabkoHbFLtHPwZqFIkJXI10r7zCey7w4gqMK5ejbcVNGgFkDWCvc42M0xixogkJh LtqcqeLj7jCss0gOzt5DQo7peJWNN81hr3yMQmcTcuXAlecEn9XpMJFRoUMGa5Awab8Q MPoLnpglSOgEdsQvD1GkkTND29XlxlvbQmUx0R7vqeme3DDmGZXiAFn09z44tZT015ic pOow== 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=0mV6jBrGeV/nIWDgvN3rM++4Oi/JFy16742ZnW3pMyw=; b=XqbaMJAsJyrLq8FnXFu0j3g374NGRGv53bu60XHsmmR//3pWxINuMGMl8NWufqbHRh 7kWsRA2t2o7wZHxsBM6cDd8OlVrsy89Sw+lBLRPOBXDklnbKDbrCBboO8wa2zckIBjbX WgVnBITiynhev7DYMhe7QIr3skrr+2YptJQygjIg5JxxAtxsNOImdm/oi65EMasV4IYD 9BYhYdXavHRE7nrrezK9e9dkhKjRrle4BDabKVS0hBDa2Wxuj7nqAb1hHWqyHHSTgfoE LgQnE5mBJQkKmalA6V8ZmY+pEGmmaRhQIqpRNjZMKWhih8lpZxUIdpE3XRBH6EdmA6nV vWgQ== 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 g11-v6si9491509pgf.386.2018.08.05.13.01.58; Sun, 05 Aug 2018 13:02:13 -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 S1727009AbeHEWGv (ORCPT + 99 others); Sun, 5 Aug 2018 18:06:51 -0400 Received: from terminus.zytor.com ([198.137.202.136]:42423 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726708AbeHEWGu (ORCPT ); Sun, 5 Aug 2018 18:06:50 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w75K0vkG581001 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sun, 5 Aug 2018 13:00:58 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w75K0vhP580998; Sun, 5 Aug 2018 13:00:57 -0700 Date: Sun, 5 Aug 2018 13:00:57 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Prasad Sodagudi Message-ID: Cc: tglx@linutronix.de, mingo@kernel.org, psodagud@codeaurora.org, hpa@zytor.com, linux-kernel@vger.kernel.org, isaacm@codeaurora.org Reply-To: tglx@linutronix.de, mingo@kernel.org, hpa@zytor.com, psodagud@codeaurora.org, linux-kernel@vger.kernel.org, isaacm@codeaurora.org In-Reply-To: <1533329766-4856-1-git-send-email-isaacm@codeaurora.org> References: <1533329766-4856-1-git-send-email-isaacm@codeaurora.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:sched/urgent] stop_machine: Atomically queue and wake stopper threads Git-Commit-ID: cfd355145c32bb7ccb65fccbe2d67280dc2119e1 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: cfd355145c32bb7ccb65fccbe2d67280dc2119e1 Gitweb: https://git.kernel.org/tip/cfd355145c32bb7ccb65fccbe2d67280dc2119e1 Author: Prasad Sodagudi AuthorDate: Fri, 3 Aug 2018 13:56:06 -0700 Committer: Thomas Gleixner CommitDate: Sun, 5 Aug 2018 21:58:31 +0200 stop_machine: Atomically queue and wake stopper threads When cpu_stop_queue_work() releases the lock for the stopper thread that was queued into its wake queue, preemption is enabled, which leads to the following deadlock: CPU0 CPU1 sched_setaffinity(0, ...) __set_cpus_allowed_ptr() stop_one_cpu(0, ...) stop_two_cpus(0, 1, ...) cpu_stop_queue_work(0, ...) cpu_stop_queue_two_works(0, ..., 1, ...) -grabs lock for migration/0- -spins with preemption disabled, waiting for migration/0's lock to be released- -adds work items for migration/0 and queues migration/0 to its wake_q- -releases lock for migration/0 and preemption is enabled- -current thread is preempted, and __set_cpus_allowed_ptr has changed the thread's cpu allowed mask to CPU1 only- -acquires migration/0 and migration/1's locks- -adds work for migration/0 but does not add migration/0 to wake_q, since it is already in a wake_q- -adds work for migration/1 and adds migration/1 to its wake_q- -releases migration/0 and migration/1's locks, wakes migration/1, and enables preemption- -since migration/1 is requested to run, migration/1 begins to run and waits on migration/0, but migration/0 will never be able to run, since the thread that can wake it is affine to CPU1- Disable preemption in cpu_stop_queue_work() before queueing works for stopper threads, and queueing the stopper thread in the wake queue, to ensure that the operation of queueing the works and waking the stopper threads is atomic. Fixes: 0b26351b910f ("stop_machine, sched: Fix migrate_swap() vs. active_balance() deadlock") Signed-off-by: Prasad Sodagudi 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/1533329766-4856-1-git-send-email-isaacm@codeaurora.org Co-Developed-by: Isaac J. Manjarres --- kernel/stop_machine.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c index e190d1ef3a23..69eb76daed34 100644 --- a/kernel/stop_machine.c +++ b/kernel/stop_machine.c @@ -81,6 +81,7 @@ static bool cpu_stop_queue_work(unsigned int cpu, struct cpu_stop_work *work) unsigned long flags; bool enabled; + preempt_disable(); raw_spin_lock_irqsave(&stopper->lock, flags); enabled = stopper->enabled; if (enabled) @@ -90,6 +91,7 @@ static bool cpu_stop_queue_work(unsigned int cpu, struct cpu_stop_work *work) raw_spin_unlock_irqrestore(&stopper->lock, flags); wake_up_q(&wakeq); + preempt_enable(); return enabled; }