From patchwork Tue May 6 15:55:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun KS X-Patchwork-Id: 4122811 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E72919F1E1 for ; Tue, 6 May 2014 15:59:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 19EE52022A for ; Tue, 6 May 2014 15:59:03 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3072A2012B for ; Tue, 6 May 2014 15:59:02 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Whhja-000475-59; Tue, 06 May 2014 15:56:46 +0000 Received: from mail-pd0-x22c.google.com ([2607:f8b0:400e:c02::22c]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Whhj7-0003QV-D5 for linux-arm-kernel@lists.infradead.org; Tue, 06 May 2014 15:56:17 +0000 Received: by mail-pd0-f172.google.com with SMTP id g10so9563469pdj.31 for ; Tue, 06 May 2014 08:55:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AyacJyyHXLMhKmOb/umECD5Zy4aMsaBIIuXaKVE9vYA=; b=ZkwG8Lg2HchtVunavuzbWhpTDIXzMeALJuDpvER+AUPlWE7DXmQOIsITI2LL2QoAaZ CguhcvW3CiRurKB//lfWJDB8gNibQugmLk6k9f6iNkLsdCFGyNhAKOlyjRGIVXbR4Tpo 72zpNFEzQHy5jByBmtZafj+F3BSQYT9Sbr3Cft9iFBTNcugQVsc+sa7t4c47DlSy9Bwe 3hFJsosAwRsocxqGX8YmLQ4t8DaSRZOluuc0wrvBDvwHlrTE/3rGIURTTh+R17/+XQCB lt9O8PnH+pNJVeg8pYdRaH3NJPnhNUPtU6TQSInSvsOJO1Jqgu+NRJMxN/4+Ai6RyICc ABjA== X-Received: by 10.66.233.72 with SMTP id tu8mr7736741pac.112.1399391755484; Tue, 06 May 2014 08:55:55 -0700 (PDT) Received: from localhost ([122.179.57.79]) by mx.google.com with ESMTPSA id ry10sm101036908pab.38.2014.05.06.08.55.52 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 06 May 2014 08:55:54 -0700 (PDT) From: arunks.linux@gmail.com To: linux-arm-kernel@lists.infradead.org Subject: arm64: Fix deadlock scenario with smp_send_stop() Date: Tue, 6 May 2014 21:25:08 +0530 Message-Id: <1399391708-13442-2-git-send-email-arunks.linux@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1399391708-13442-1-git-send-email-arunks.linux@gmail.com> References: <1399391708-13442-1-git-send-email-arunks.linux@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140506_085617_483094_BC8D931A X-CRM114-Status: GOOD ( 11.80 ) X-Spam-Score: -0.1 (/) Cc: catalin.marinas@arm.com, Arun KS , Arun KS , Stephen Boyd X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Arun KS If one process calls sys_reboot and that process then stops other CPUs while those CPUs are within a spin_lock() region we can potentially encounter a deadlock scenario like below. CPU 0 CPU 1 ----- ----- spin_lock(my_lock) smp_send_stop() handle_IPI() disable_preemption/irqs while(1); spin_lock(my_lock) <--- Waits forever We shouldn't attempt to run any other tasks after we send a stop IPI to a CPU so disable preemption so that this task runs to completion. We use local_irq_disable() here for cross-arch consistency with x86. Signed-off-by: Stephen Boyd Signed-off-by: Arun KS Signed-off-by: Arun KS --- arch/arm64/kernel/process.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index 2d43614..abe57e0 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -134,6 +134,7 @@ void machine_shutdown(void) */ void machine_halt(void) { + local_irq_disable(); smp_send_stop(); while (1); } @@ -146,6 +147,7 @@ void machine_halt(void) */ void machine_power_off(void) { + local_irq_disable(); smp_send_stop(); if (pm_power_off) pm_power_off(); @@ -164,10 +166,9 @@ void machine_power_off(void) */ void machine_restart(char *cmd) { - smp_send_stop(); - /* Disable interrupts first */ local_irq_disable(); + smp_send_stop(); /* Now call the architecture specific reboot code. */ if (arm_pm_restart)