Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp112763imm; Tue, 3 Jul 2018 15:04:10 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcsl4odzaWkR2LAPOIUMtkCA+e+naWxMw7Ryz1d14goEbIQ/rbbpzF/CRLHYyAKn/iMGj0P X-Received: by 2002:a62:2605:: with SMTP id m5-v6mr31508951pfm.223.1530655450274; Tue, 03 Jul 2018 15:04:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530655450; cv=none; d=google.com; s=arc-20160816; b=VmhAq4DeSrWOEPbHRzDNIUzHkpy4u0yAS6jKOJmc5rJar3tatZ26ZLLv2GhxK7FqEs kMWN9mjLrAPQjfzRcsii1NyOFHsJvNVZl2iaOnFfYZ3MjyFVPlOyvYoNjLDgslA3zdhC uReudaL5MlAzx38vVhilhfKCquSqkxLZB+CD017zActWMjtTKUeYTPMyieMhszQlgpKD kLve2XyEx0wn6S5WL86DzGxxMVA2DYPJ+IAI+5WAL6rQ5q9D5I75Z18DOABYB2quCJLH FodzrnU2CejmZA0AjO8iLQjYxoBzfUkCAwj9wK+xVgtdO1E0iauav1znXsqOYEzUhKtc hTVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=zDh9NdX6G2YrmAM0XyyFoGTFtacfvu5OSvDAZA5rJ58=; b=OtHUNurlnEP4vU9nlVFgf91+HqnLT2FGflbSYlsyWWMBgQkwNeL8GGAtN5TqHoyImo QxndYN0VGb8TV/QxSr3y6XKzmlpf+4TluUfkC6Zywdk8ohTfuuYquKX9ZpWYLUDeNgSY +Nwp4dLmmVPuG2TCCOKZCphclsOU4zkFTwRJDM4SaSxAjVo41URqvS6XGXYnVwaTa6OO aKhXHJvjvLmjeA8j6BowJDiz685S3JI0wszBImpmf7iv4nd69m1f7M9SkQC/wkX9lQP/ cSrUuU961pZFhuAswrs8WbWUdv82o3GbTEaPfo7oPUABvl+zQmsLpfeHCAytecpMXPzw it7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=YWGJiYLV; dkim=pass header.i=@codeaurora.org header.s=default header.b=ouQKSYdr; 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 o123-v6si1848334pgo.190.2018.07.03.15.03.55; Tue, 03 Jul 2018 15:04:10 -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; dkim=pass header.i=@codeaurora.org header.s=default header.b=YWGJiYLV; dkim=pass header.i=@codeaurora.org header.s=default header.b=ouQKSYdr; 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 S1753520AbeGCWCw (ORCPT + 99 others); Tue, 3 Jul 2018 18:02:52 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:58548 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753489AbeGCWCu (ORCPT ); Tue, 3 Jul 2018 18:02:50 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 9823F60B19; Tue, 3 Jul 2018 22:02:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1530655369; bh=Mw/64kaifQL/Q2pRx51sUdEM3KqJyG58cb1WWuYz/Hc=; h=From:To:Cc:Subject:Date:From; b=YWGJiYLV+N7a4vzxiNiZagOS6AU/ur9L184RpqztmtJS/LvYrUhjxWrOriLJ1fX7E gjdvheGUDjNUP0p8/68bzY6rl0gAc5yQoJzwps7dim2+DDWww8awgrLn1IqhtJOxw2 X93YonsaBP3zGMTq17FZBOdJHvFqsPTAphFbl2h8= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from isaacm-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: isaacm@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 698426063F; Tue, 3 Jul 2018 22:02:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1530655368; bh=Mw/64kaifQL/Q2pRx51sUdEM3KqJyG58cb1WWuYz/Hc=; h=From:To:Cc:Subject:Date:From; b=ouQKSYdrQ6O3b/pl2AUofg4H4Wq7BGuat4jwu8hDbFuT0n2/ULyXfLOxRAJYT4qm4 8abqyBGnsxTn0tjuyLtY2U/1Q0YpafaGx9krNBK2KTL+Q7FZGN1vRxWdBkR1C2xRig 7r4udiN715qlZV7YEFNzUaDDsOXLiRH0kCA4WxcU= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 698426063F Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=isaacm@codeaurora.org From: "Isaac J. Manjarres" To: peterz@infradead.org, matt@codeblueprint.co.uk, mingo@kernel.org, tglx@linutronix.de, bigeasy@linutronix.de Cc: "Isaac J. Manjarres" , linux-kernel@vger.kernel.org, psodagud@codeaurora.org, gregkh@linuxfoundation.org, pkondeti@codeaurora.org, stable@vger.kernel.org Subject: [PATCH v3] stop_machine: Disable preemption when waking two stopper threads Date: Tue, 3 Jul 2018 15:02:14 -0700 Message-Id: <1530655334-4601-1-git-send-email-isaacm@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Co-Developed-by: Pavankumar Kondeti Signed-off-by: Isaac J. Manjarres Signed-off-by: Prasad Sodagudi Signed-off-by: Pavankumar Kondeti Cc: stable@vger.kernel.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 f89014a..1ff523d 100644 --- a/kernel/stop_machine.c +++ b/kernel/stop_machine.c @@ -270,7 +270,11 @@ static int cpu_stop_queue_two_works(int cpu1, struct cpu_stop_work *work1, goto retry; } - wake_up_q(&wakeq); + if (!err) { + preempt_disable(); + wake_up_q(&wakeq); + preempt_enable(); + } return err; } -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project