Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1827576imm; Mon, 3 Sep 2018 10:27:54 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY9kUEMW9/yYtmPNE29R4NtX8p2gOXIpxYecoYIfs/6bZ6hN9aO1ytgtAAdMsZE2iV6o+fB X-Received: by 2002:a17:902:74ca:: with SMTP id f10-v6mr29799400plt.260.1535995674087; Mon, 03 Sep 2018 10:27:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535995674; cv=none; d=google.com; s=arc-20160816; b=n3L0ug1QajueLXNwOPf+kD51ERCSZunt1VgNUvvQjsCYpwbeRMvRHQyhnLQUoZWXY+ d9eGy409huBmskGQ7q1CRZRfoW3IhC+7JF0M2RW1VZeIp5HUVYROnlLmag04e2NiGbMg hGYL+VmCsioUCyYNBh94PvtTokW8cFEsV+Msce2ZIBgSmS0IfIURtNcl6s3nZMG0PxpR QQMBdwNPPTq3ql3XIT+X9sJn1/mBCNq/B0hS1R6hH0wq0Pt8y3Gi90KLKjWlntMbUult pExN478BnVKbPBp/uQqdkiPKk7DXNoiwcc4RCNJsN0t9/wjcySUhM75WCv9XMVLsBgBt ab2A== 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=p7rkKZthQ9EF20qqdh00OkHvb7ZZGWbKab1nmtVOeq8=; b=x9ByyLrSWySh1yEYDJ4cgejqOl4H2MXlWEN54zHMegtEeUmu0bfbtGyxcD/B05DcTv G5OSUOf9+yudZDUzevDVYYJ0dVUNc3MgjK0cCKcFaV/ssFPPiWcLIo+GGkp0na+25Otx M1HzJGP1vSdE3BqNR4yHkbMr4Rj0NbcjGCNkMIDJT2AcJFD6QD0s5QkEeFaWF3r/guwy tN74jbpnAh6crNao71Yt1Igte6LbvvPD6LSDnccYBqurS/hDxZDouQldjZ8QhPreXCMT wVzbSm1AJKnrv9OWLyzbDekaZ/oT6+MizyQtzgLPmzPERqqOUqGuDloBBdcOv2EKqS1L X/Xw== 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 b10-v6si20213899plk.302.2018.09.03.10.27.39; Mon, 03 Sep 2018 10:27: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 S1730845AbeICVrn (ORCPT + 99 others); Mon, 3 Sep 2018 17:47:43 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45910 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728628AbeICVrm (ORCPT ); Mon, 3 Sep 2018 17:47:42 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 227EDD24; Mon, 3 Sep 2018 17:26:34 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , "Peter Zijlstra (Intel)" , Sebastian Andrzej Siewior , isaacm@codeaurora.org, matt@codeblueprint.co.uk, psodagud@codeaurora.org, pkondeti@codeaurora.org Subject: [PATCH 4.14 103/165] stop_machine: Reflow cpu_stop_queue_two_works() Date: Mon, 3 Sep 2018 18:56:29 +0200 Message-Id: <20180903165700.683519185@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165655.003605184@linuxfoundation.org> References: <20180903165655.003605184@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.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Peter Zijlstra commit b80a2bfce85e1051056d98d04ecb2d0b55cbbc1c upstream. The code flow in cpu_stop_queue_two_works() is a little arcane; fix this by lifting the preempt_disable() to the top to create more natural nesting wrt the spinlocks and make the wake_up_q() and preempt_enable() unconditional at the end. Furthermore, enable preemption in the -EDEADLK case, such that we spin-wait with preemption enabled. Suggested-by: Thomas Gleixner Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Thomas Gleixner Cc: Sebastian Andrzej Siewior Cc: isaacm@codeaurora.org Cc: matt@codeblueprint.co.uk Cc: psodagud@codeaurora.org Cc: gregkh@linuxfoundation.org Cc: pkondeti@codeaurora.org Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20180730112140.GH2494@hirez.programming.kicks-ass.net Signed-off-by: Greg Kroah-Hartman --- kernel/stop_machine.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) --- a/kernel/stop_machine.c +++ b/kernel/stop_machine.c @@ -236,13 +236,24 @@ static int cpu_stop_queue_two_works(int struct cpu_stopper *stopper2 = per_cpu_ptr(&cpu_stopper, cpu2); DEFINE_WAKE_Q(wakeq); int err; + retry: + /* + * The waking up of stopper threads has to happen in the same + * scheduling context as the queueing. Otherwise, there is a + * possibility of one of the above stoppers being woken up by another + * CPU, and preempting us. This will cause us to not wake up the other + * stopper forever. + */ + preempt_disable(); raw_spin_lock_irq(&stopper1->lock); raw_spin_lock_nested(&stopper2->lock, SINGLE_DEPTH_NESTING); - err = -ENOENT; - if (!stopper1->enabled || !stopper2->enabled) + if (!stopper1->enabled || !stopper2->enabled) { + err = -ENOENT; goto unlock; + } + /* * Ensure that if we race with __stop_cpus() the stoppers won't get * queued up in reverse order leading to system deadlock. @@ -253,36 +264,30 @@ retry: * It can be falsely true but it is safe to spin until it is cleared, * queue_stop_cpus_work() does everything under preempt_disable(). */ - err = -EDEADLK; - if (unlikely(stop_cpus_in_progress)) - goto unlock; + if (unlikely(stop_cpus_in_progress)) { + err = -EDEADLK; + goto unlock; + } err = 0; __cpu_stop_queue_work(stopper1, work1, &wakeq); __cpu_stop_queue_work(stopper2, work2, &wakeq); - /* - * The waking up of stopper threads has to happen - * in the same scheduling context as the queueing. - * Otherwise, there is a possibility of one of the - * above stoppers being woken up by another CPU, - * and preempting us. This will cause us to n ot - * wake up the other stopper forever. - */ - preempt_disable(); + unlock: raw_spin_unlock(&stopper2->lock); raw_spin_unlock_irq(&stopper1->lock); if (unlikely(err == -EDEADLK)) { + preempt_enable(); + while (stop_cpus_in_progress) cpu_relax(); + goto retry; } - if (!err) { - wake_up_q(&wakeq); - preempt_enable(); - } + wake_up_q(&wakeq); + preempt_enable(); return err; }