Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3434398imm; Sun, 1 Jul 2018 21:53:00 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf1ORUcjgssJ9SZ1uqQnHocrFvuphZyalMie1PzCe9IFYHzGNm/V2TZUoekyFS9oXZmquuj X-Received: by 2002:aa7:810c:: with SMTP id b12-v6mr23596515pfi.79.1530507180728; Sun, 01 Jul 2018 21:53:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530507180; cv=none; d=google.com; s=arc-20160816; b=oh7wN2VL2GyIQqj2MXxbTGkwcWJrDWk1LuBuf5xhA2UYCAq67pgGGMSE3NMN+Lhw5Y 3NE79eL6eht8GgqP00bLa828MVBvFW3tBYdS2iO2TDUZIJFaLSqvz82y28MgzKzJka7i t1ReP/f3Rsi7d2PLwJpwjVML3Pv4ypUyi3MuFbkIzRqgiBAQyPMRxmjfd/B8qkw4qC1l SdErMcmOU+3JF5kG8YLfgQ9yWLpgdRYbp2fz/o2Hxduwy4VUzx6ZShbgzwX/O97oZcVM WjhcNVIkfGnSsjkRFefVeHD2FpXQwfXpWekPV6BTsN1TJGDLa2bPd9jHBi4/Uk9yLP4T NXRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=EXMxsteHUQRc1ZwS6UFknpn28OWF1aOMpEOBAnd2E/4=; b=EfGpYzsOuao6WIvhPWMVISnCCRmJFIbgiFbrLyuer3vypQB0fKdR4JvNKoe3l3U3IF MJ+aOsXc02WXI8iVEJQLYjHWC90S/Rl0BLyQk6E6f89KBouLXzUpQu7AHD9nq/OIwWzY rHBQAlVYxPnhR8whq80u72Mwj04Jj3r7zJbJWVhycqwYgAL0MsDeSU6lwDRKUCzYKvGK nR6puXDbYwGqXvpXC83XCkSvCSPQiweI+gyTylWzbcmJnSQxNneDws57CblS+6AMCXvd FesuNv/z6w84ahHGyNWURazdFGNFh3TFI1PIyfll6bHHm1W0u8yZYZVgIqvJqXT8C8wS 2gjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=iZSQkKbK; dkim=pass header.i=@codeaurora.org header.s=default header.b=XRjRS9M7; 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 74-v6si15587254pfp.161.2018.07.01.21.52.46; Sun, 01 Jul 2018 21:53:00 -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=iZSQkKbK; dkim=pass header.i=@codeaurora.org header.s=default header.b=XRjRS9M7; 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 S1752831AbeGBEfX (ORCPT + 99 others); Mon, 2 Jul 2018 00:35:23 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:57688 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752211AbeGBEfW (ORCPT ); Mon, 2 Jul 2018 00:35:22 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 38C9F601CF; Mon, 2 Jul 2018 04:35:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1530506122; bh=Ezbyat8gPD6MPFZZhoNzZYdeMwnYW77nEBk22fHtDp8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=iZSQkKbKc3Lpmxj/IgQKj04q4UWCyNYkJivX5Bmp7fOHSukjWQnDqiEBNwTqbHHQ6 BzKBVs3MoFTyJYtVN1oP3YUEldv8U6yOizWTqS5JBmXL54X6CRldWAU/Lok/VbJD+O JTqK0NaXHhRZbnjgAXC5ogvN41qe0/jHqdRYn4XU= 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 codeaurora.org (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: pkondeti@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id E86B0601CF; Mon, 2 Jul 2018 04:35:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1530506121; bh=Ezbyat8gPD6MPFZZhoNzZYdeMwnYW77nEBk22fHtDp8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XRjRS9M77k8Tme9XgngCvcp4HpEAdnRRAfFyrX70cVTw/0p23/0YW5cJ6w3P9iVGG H/zNdwI439Mbfmx4835GrMr6yRYpact8cwo27vI/ONh9uYFGJGhbMsywMWxuBP4OKn kxjJNhcfQ/kZNStgJcejZbfjlrDQ1Yf99SniUHpo= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org E86B0601CF 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=pkondeti@codeaurora.org Date: Mon, 2 Jul 2018 10:05:15 +0530 From: Pavan Kondeti To: "Isaac J. Manjarres" Cc: peterz@infradead.org, matt@codeblueprint.co.uk, mingo@kernel.org, tglx@linutronix.de, bigeasy@linutronix.de, linux-kernel@vger.kernel.org, psodagud@codeaurora.org Subject: Re: [PATCH v2] stop_machine: Disable preemption when waking two stopper threads Message-ID: <20180702043515.GH9208@codeaurora.org> References: <1530305712-16416-1-git-send-email-isaacm@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1530305712-16416-1-git-send-email-isaacm@codeaurora.org> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Issac, On Fri, Jun 29, 2018 at 01:55:12PM -0700, Isaac J. Manjarres wrote: > 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() to ensure that the worker thread > that is waking up the stopper threads isn't preempted > by the source CPU's stopper thread, and permanently > scheduled out, leaving the remaining stopper thread asleep > in the wake queue. > > Co-developed-by: Pavankumar Kondeti > Signed-off-by: Prasad Sodagudi > Signed-off-by: Pavankumar Kondeti > Signed-off-by: Isaac J. Manjarres > --- You might want to add the below Fixes tag and CC stable. Fixes: 0b26351b910f ("stop_machine, sched: Fix migrate_swap() vs. active_balance() deadlock") > 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; > } -- Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.