Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1833995imm; Mon, 3 Sep 2018 10:37:30 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdbl8HhHvbidsXnTd7zGRplt7/mAaEiFDKo3Mmbu9hO5/Ym304UIs8/u3/dJynxpKooc7lMh X-Received: by 2002:a63:d150:: with SMTP id c16-v6mr27486399pgj.188.1535996250012; Mon, 03 Sep 2018 10:37:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535996249; cv=none; d=google.com; s=arc-20160816; b=HcZpMzEZjr5lUtRuOFOel0rrk+7mGrC6Zq7Y1ujF4+xrCwJ/k8G85OU4qJAUPMLly7 FGmGCgm20gxN+jpB7KYHxwyAaXHaRVbwfolZ0cWvZNkGwPWYbWPVRQhC7Xpp4vg+XAA2 2m30tDGCr7DpBQuZyJTEABRXK2afd0ctB2wxWzvHSRB5D14kTE94lAtTRDyTCEaxMAOv Jc7dJHuWPjTTYnN/21oRKWy/8dl4d6qBlSEyphqVEjiOAU91xnPfAVR7UqEhyHFnxJyf Oigrkxm4A6rXMbgIfxeS1brY+pEJA+0MugKTTg4ILwirdXVqv4OFdw/BrGQP2NwWXtXD VXCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=xpuGX/dLVPJAZsGiIm7yvLs6iGQL0LORduEC2IXTPUY=; b=QN4F/y9ibFPk5LXnQH+LwdPTb24zzI0PXd+rCTR5RwvuCAOtKC6E5Je+ZR42G6cmWK UiPkR+xjrNVdUiqDuPQeVbFHW/40wOIEHCQC8FhLFEaXCmcqDSr162PPt7EXJe0toomI pouEeyxXk+ffy2ZpXpl8GSbeffRgPZ/9l/wD9yOVY8uhH5+Vio8cmeXssXxSuQpuTOPe WG88Xdx/mBQUCY4TfHz7MZYpC1C2C1f3YDflOV8nHWK2daTgog9XcesDviY2HfGdOsu7 3BpL1YqFjr1ClopMNYYvfDjPPFTskV4Wq6v1y77brVAyl7RAZVo0zLH8GPajkEaASQIl LIZA== 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 q8-v6si18128430pli.355.2018.09.03.10.37.15; Mon, 03 Sep 2018 10:37:29 -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 S1731608AbeICV5U (ORCPT + 99 others); Mon, 3 Sep 2018 17:57:20 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:48096 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726196AbeICV5U (ORCPT ); Mon, 3 Sep 2018 17:57:20 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 825ECD1B; Mon, 3 Sep 2018 17:36:09 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Prasad Sodagudi , "Isaac J. Manjarres" , Thomas Gleixner , peterz@infradead.org, matt@codeblueprint.co.uk, bigeasy@linutronix.de Subject: [PATCH 4.18 040/123] stop_machine: Atomically queue and wake stopper threads Date: Mon, 3 Sep 2018 18:56:24 +0200 Message-Id: <20180903165721.172550206@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165719.499675257@linuxfoundation.org> References: <20180903165719.499675257@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Prasad Sodagudi commit cfd355145c32bb7ccb65fccbe2d67280dc2119e1 upstream. 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 Signed-off-by: Greg Kroah-Hartman Co-Developed-by: Isaac J. Manjarres --- kernel/stop_machine.c | 2 ++ 1 file changed, 2 insertions(+) --- a/kernel/stop_machine.c +++ b/kernel/stop_machine.c @@ -81,6 +81,7 @@ static bool cpu_stop_queue_work(unsigned 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 raw_spin_unlock_irqrestore(&stopper->lock, flags); wake_up_q(&wakeq); + preempt_enable(); return enabled; }