From patchwork Fri Mar 22 15:44:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 10866135 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 549B0139A for ; Fri, 22 Mar 2019 15:47:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F62B28E48 for ; Fri, 22 Mar 2019 15:47:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2383129182; Fri, 22 Mar 2019 15:47:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AA1B52A8BD for ; Fri, 22 Mar 2019 15:47:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=r8x8TAVCPrPV4h/+5QiXTnw/0L5QC4+hOC/F7G9pfPk=; b=hnJXSviQB5739B vXT5yqe5UCqwfnVlc/N9s2vnSPT/hb2i2594/Rca4JCOV8yl3OhSqZYtiXcO+jKph0uCesMywmjgC 6GuLuCdUbLboJWe5+l9LAr1BJ+nuQegmHqUgIuBpnsO4WldBtK/YcqUSmPlfNKGE0bmUfK/MGsBv3 S5Sgjp9FQEQESjlwia9flnU43Ts7RBX58EcGVYlZ6QEA/Z0OocIQi6eqw+qTiXAq2WinVjERayIIA qSpbYjC8v7kZyysMcO8JXYcWnwsMP28q1mjIw6E8FPmQN9d3qOei6C+HAWlGFESfgzHipY9vE1Joh 8E74kzeyYgQ3nDASE+NQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h7MOF-0003lv-3L; Fri, 22 Mar 2019 15:47:27 +0000 Received: from mout.kundenserver.de ([212.227.17.10]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h7MOA-0003Z0-SY for linux-arm-kernel@lists.infradead.org; Fri, 22 Mar 2019 15:47:24 +0000 Received: from wuerfel.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1Mz9hF-1glrBT0Dlz-00wEbJ; Fri, 22 Mar 2019 16:46:56 +0100 From: Arnd Bergmann To: stable@vger.kernel.org, Catalin Marinas , Will Deacon , "Eric W. Biederman" , Mark Rutland , "Rafael J. Wysocki" , Anshuman Khandual , James Morse , Peter Maydell , Andrey Konovalov Subject: [BACKPORT 4.4.y 10/25] arm64: mm: Add trace_irqflags annotations to do_debug_exception() Date: Fri, 22 Mar 2019 16:44:01 +0100 Message-Id: <20190322154425.3852517-11-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20190322154425.3852517-1-arnd@arndb.de> References: <20190322154425.3852517-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:ZFpF8CAe8AmBwG8PGJWPFop0PRfjbeBIlad56HwVq67hsFHJ0tt /vTMl2X1z7FjJcfBD0yN8KM2IpfFg+j50kqftvc8+oe9L9ijCZIB96BSaGpzYkwAB3tKm5x QsQSsWeUgJ4gewKBKXcbAFOG+noCIE8Jlpu1KFR853UTVguO/qJWsuPHpuFMH4tfXZccPsR OKODfg19h+O9i3y9U71xQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:vhym0IdyrDA=:IagoDTjJ/AZm8MOUQihw/h lfjIfsiKuAjcr0YkJUa3nKwnT87irDoj13onxU3W5TDW0hf4b9zn9hX/tbM+y3Kd3QZY9nW4P ENXHg/s6eOeXdL/57nJ3gRv4nWemwtl58VGfkAJ/9GQRdeb4RZO3oaMPLSBP6XDcsIdZ+Idp4 jXvlvemWe6/NVlMZMALxF3//wuKh9mj0yT0WuAeKNOJ0BYycfiAxtLPnnJr8rJnw58QvCZ0ZF MK26TbIvudgq7V25j37GDFSAUKSfLEhsaFJEPlHPH0eO+OeycXf2dsU4DhLSVSXw59ibyHzwU SEni14uvrS8VhclQLU6h69oKllWXhaY2F+GpDcxxdxPb+KglXhXgMOFZO/IrrjUlZPzx0nDud cf6sj3qJA69QviQTQgygrApzKDiROW/IS1pABbOvyJoMLmyfP4b7ykMmYlWnorrgqwdh0+KSH OU3zPAxbKIWvkr2g+XuRnAa9d9lC005SfdyTJjBwS2PuBjfWJpNBRgISiNe82vigjFLRYl0gP m736lhhI/A7M2uTQBr/PhBhc+UsBteTXBV5ZG+7u/fx7jIRqNVOChl+BElMvlbSrgkbbVKIGq y86Da3naDGq/+sZryHTJZ143Z1/7CHhrrG7g00LrJ7pJoIu7jiyjVVUPIdQVv5LEgAW6HE20B Bjs4+SlMn0PTY8zvXnTC7v+YAPGsRnOWEKL1Y0kMjEc/X2G1vOMH91h1y3J+fc2lVvvHsiFT9 ccvN6lPlR10SMbWu8ROHz45cwbajO7eTSOlrjw== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190322_084723_229545_8BFE3CAA X-CRM114-Status: GOOD ( 15.80 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Arnd Bergmann , linux-kernel@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: James Morse With CONFIG_PROVE_LOCKING, CONFIG_DEBUG_LOCKDEP and CONFIG_TRACE_IRQFLAGS enabled, lockdep will compare current->hardirqs_enabled with the flags from local_irq_save(). When a debug exception occurs, interrupts are disabled in entry.S, but lockdep isn't told, resulting in: DEBUG_LOCKS_WARN_ON(current->hardirqs_enabled) ------------[ cut here ]------------ WARNING: at ../kernel/locking/lockdep.c:3523 Modules linked in: CPU: 3 PID: 1752 Comm: perf Not tainted 4.5.0-rc4+ #2204 Hardware name: ARM Juno development board (r1) (DT) task: ffffffc974868000 ti: ffffffc975f40000 task.ti: ffffffc975f40000 PC is at check_flags.part.35+0x17c/0x184 LR is at check_flags.part.35+0x17c/0x184 pc : [] lr : [] pstate: 600003c5 [...] ---[ end trace 74631f9305ef5020 ]--- Call trace: [] check_flags.part.35+0x17c/0x184 [] lock_acquire+0xa8/0xc4 [] breakpoint_handler+0x118/0x288 [] do_debug_exception+0x3c/0xa8 [] el1_dbg+0x18/0x6c [] do_filp_open+0x64/0xdc [] do_sys_open+0x140/0x204 [] SyS_openat+0x10/0x18 [] el0_svc_naked+0x24/0x28 possible reason: unannotated irqs-off. irq event stamp: 65857 hardirqs last enabled at (65857): [] lookup_mnt+0xf4/0x1b4 hardirqs last disabled at (65856): [] lookup_mnt+0xbc/0x1b4 softirqs last enabled at (65790): [] __do_softirq+0x1f8/0x290 softirqs last disabled at (65757): [] irq_exit+0x9c/0xd0 This patch adds the annotations to do_debug_exception(), while trying not to call trace_hardirqs_off() if el1_dbg() interrupted a task that already had irqs disabled. Signed-off-by: James Morse Signed-off-by: Will Deacon (cherry picked from commit 6afedcd23cfd7ac56c011069e4a8db37b46e4623) Signed-off-by: Arnd Bergmann --- arch/arm64/mm/fault.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index be7f8416809f..04c4b88706d8 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -595,20 +595,33 @@ asmlinkage int __exception do_debug_exception(unsigned long addr, { const struct fault_info *inf = debug_fault_info + DBG_ESR_EVT(esr); struct siginfo info; + int rv; - if (!inf->fn(addr, esr, regs)) - return 1; + /* + * Tell lockdep we disabled irqs in entry.S. Do nothing if they were + * already disabled to preserve the last enabled/disabled addresses. + */ + if (interrupts_enabled(regs)) + trace_hardirqs_off(); - pr_alert("Unhandled debug exception: %s (0x%08x) at 0x%016lx\n", - inf->name, esr, addr); + if (!inf->fn(addr, esr, regs)) { + rv = 1; + } else { + pr_alert("Unhandled debug exception: %s (0x%08x) at 0x%016lx\n", + inf->name, esr, addr); + + info.si_signo = inf->sig; + info.si_errno = 0; + info.si_code = inf->code; + info.si_addr = (void __user *)addr; + arm64_notify_die("", regs, &info, 0); + rv = 0; + } - info.si_signo = inf->sig; - info.si_errno = 0; - info.si_code = inf->code; - info.si_addr = (void __user *)addr; - arm64_notify_die("", regs, &info, 0); + if (interrupts_enabled(regs)) + trace_hardirqs_on(); - return 0; + return rv; } #ifdef CONFIG_ARM64_PAN From patchwork Fri Mar 22 15:44:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 10866155 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BB76315AC for ; Fri, 22 Mar 2019 15:49:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 936C22A8BE for ; Fri, 22 Mar 2019 15:49:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 863412A8C4; Fri, 22 Mar 2019 15:49:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DA0B92A8BE for ; Fri, 22 Mar 2019 15:49:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=unEpz8ZVHowpTJMFGY/sipxLFx31zmNchUdI7U2K1s4=; b=qlz8R/VDpvkVln As3D5tlT+5E3qIcFTbDp3nq1OO5HYxiuHW5/tInk0oizVhlOOsFr2ebTZErVMZNgsDkNpsJi1bgM9 BXyueHcBDRi5ESqhZNnlfkdI1CwKXQ1GNaY0mlgbUVlXFgmXDi3khv//yYlu47aQkx/hsjn2DbA1t tqKvkDj908ndGSl5DNa6jkPF1Dmw6RWKv1qBgJuqKGf30ICGlFf+oHwQ6hZ2YQ6etnc6pEo4y/YJI 0g4cfApw/cgPPymaGbtc+2ou5MoBJmW7wdfDEGncWXV9u5CWhlpxl0OY/UQ0XHd41oMf8usndff5L 9xeYPF7jLhQHmjs6QOLA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h7MQd-0004m3-KK; Fri, 22 Mar 2019 15:49:55 +0000 Received: from mout.kundenserver.de ([212.227.17.13]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h7MQZ-0004lh-HW for linux-arm-kernel@lists.infradead.org; Fri, 22 Mar 2019 15:49:54 +0000 Received: from wuerfel.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MUXh8-1hXrXA13M8-00QWTC; Fri, 22 Mar 2019 16:49:24 +0100 From: Arnd Bergmann To: stable@vger.kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , "Eric W. Biederman" , Marc Zyngier , Anshuman Khandual , Andrey Konovalov Subject: [BACKPORT 4.4.y 21/25] arm64: traps: disable irq in die() Date: Fri, 22 Mar 2019 16:44:12 +0100 Message-Id: <20190322154425.3852517-22-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20190322154425.3852517-1-arnd@arndb.de> References: <20190322154425.3852517-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:3h0I8WSBNcOUW2oBof6q4Zhu/MkBQ6JfTTEKDc7C3t0ARWbsWDW LpKGcnzl45jHUFU9EP6rpjw/bhSVoXTjFVkix+HREzEV0D6h29XjIBciuqjvbl5ioglPyhZ o09rVRymoVQv97+wPo7JbUcvIqc+YXMps+5gOFwSUMbgnrjZ60/CJxMhUelO3jFDPtnRZnA qwT+QalE3JUyoRCgW6ApA== X-UI-Out-Filterresults: notjunk:1;V03:K0:OyNCwkcqWVk=:fnMCXM6qGiqalwHEgD8Iu2 pdyteGzjvepTLU+a3gAQMbqAZA+7QMp2r6Duc6ZGbHyBsvLRqjmRyEa8RPuMCpy4zJg8nSt2q 9NZRKRPGRykTQCCVwky0x4qJZ6zhOJXjP+z9dlHqcxrywdgoAcMOPrGibkrMEQhxCNC+/Xwvl S1TJ3gfoefECcdTdnEtUg8CUVdGEPTa5eaaOiUlneggP0hVD6RYYE/fPg9OVCpBICv0YqxfRb TshicGNuaCMyxlndntEGftdpt/cQCLNbKzlyNxSnwIXGST2AxFEn2+e4Koi+zrLAgx3yq8tEK AXigKZZr7JElicNSnXOAAq9uDVWMk9EV6l0wN5zZmOMqYPkDAbBZ+LscXN4B8UGUQRrNOHsjZ ZAt+2niyO+5EWFq4Zs+Ui5zONBpbxw4MiDOchKYerKvLuyr6RPMOIt+vyPbxzA9JNCr28IZrC S7b82gW4MQE359l+cI5RidYzYbMaDt4GteSbccTGYgIW5xa5PLYMY98/4thvelGEzNYBjbnRy VxQ0q1+sN/sRtpHEfx9YEte8Fjhs5Vx8cL1ThvWJf7PxnmXWqin//WwhlYAscLw+ZT1OQ5SIF FmC0A1Fxrzjdbofrt1Bo74vw8VdKyD7g4xMjxXlMPjjB5cHJoqAyI2uxcZzbjth40ZfxtY08X HVNXqZ3TNYDPmIFPcUo81haz7hCLWZR3/DWLQinW4+VRyS9nWS0sb7mK9yZ2ntWlrLZjByeCf GYKkMLUnW8IRzldjnvyioNNCGZVG2KYUfaCl3w== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190322_084951_927593_86DABEB8 X-CRM114-Status: GOOD ( 12.50 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Qiao Zhou , linux-arm-kernel@lists.infradead.org, Arnd Bergmann , linux-kernel@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Qiao Zhou In current die(), the irq is disabled for __die() handle, not including the possible panic() handling. Since the log in __die() can take several hundreds ms, new irq might come and interrupt current die(). If the process calling die() holds some critical resource, and some other process scheduled later also needs it, then it would deadlock. The first panic will not be executed. So here disable irq for the whole flow of die(). Signed-off-by: Qiao Zhou Signed-off-by: Will Deacon (cherry picked from commit 6f44a0bacb79a03972c83759711832b382b1b8ac) Signed-off-by: Arnd Bergmann --- arch/arm64/kernel/traps.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index 5d270ca76aec..6b4579e07aa2 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -239,10 +239,12 @@ void die(const char *str, struct pt_regs *regs, int err) { struct thread_info *thread = current_thread_info(); int ret; + unsigned long flags; + + raw_spin_lock_irqsave(&die_lock, flags); oops_enter(); - raw_spin_lock_irq(&die_lock); console_verbose(); bust_spinlocks(1); ret = __die(str, err, thread, regs); @@ -252,13 +254,15 @@ void die(const char *str, struct pt_regs *regs, int err) bust_spinlocks(0); add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE); - raw_spin_unlock_irq(&die_lock); oops_exit(); if (in_interrupt()) panic("Fatal exception in interrupt"); if (panic_on_oops) panic("Fatal exception"); + + raw_spin_unlock_irqrestore(&die_lock, flags); + if (ret != NOTIFY_STOP) do_exit(SIGSEGV); }