Received: by 2002:a05:6520:1682:b0:147:d1a0:b502 with SMTP id ck2csp5595448lkb; Mon, 11 Oct 2021 09:37:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyU4s2wHIrKrANVpq1ZaeNfm0OZB9z56F33YdkEoqT1OfS0JUqBx65SXzOcU3vMZlDpVyd5 X-Received: by 2002:a05:6402:2684:: with SMTP id w4mr42545515edd.108.1633970261287; Mon, 11 Oct 2021 09:37:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633970261; cv=none; d=google.com; s=arc-20160816; b=ty+iayKsIz7jp4VHA7Xt/VpalmIK2QQPIveLT10WTJIbr8B26FJbY0VRcwzFiky9Io +lYw8pt8EUjB0QbGCqyMQebl3LNr0S4k4bxhAiQVOUWKZ1DcEJ2AIPgI7jWMnj/jBp5M tMminikBg55xvgOKAcSKM64Tqdn1yDGJKYR6PMkKNSOniWrMhFLd0qpVXIySbTYIjau9 c0Qjo376yY2W6k4VHoZGJJj72ZhfC1GQY5Ul14SSIjKGHlAaoQNKroPlyDER93uFprCC t2ob+5fSL1yY8Tbh13nPc/VmklOIAyqTpI0W5FckHkL0Xxx3S4oOnI8QAh/i3WV7Dahc x/Qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pnByttl3AAOSuGXCGQxq0EYf1RNJAWUrxAnfviBnctE=; b=zlIGe2xcNiG1cV8NqGxmZqFRaQIR89SsL/zxr65C75gC/YRTUTerSNIdsIo45bMQW8 ZGxQMQHe4CYR0HW8k9hc7TYZRzuQqXjLi4llEUHJOV9GBQZf7bP5sojnLOotsahOTVMw fR7IwR6IYXiCajaYjen9ROgnYC1VqPzY8rJP1yWS4xvBgDE82SrTUj35P6k/eX52B2ac 8EAz4uDJVuX9xW1EyfsXHWAyfTqjfSpRlyA9W4uPcbq29PNfkUeb343LGQvwylvrHqpQ 5Euz52FVEgeUrrsvaqlqsVZaBbCovPVL0k8Qkipy93uJyua5oF+MBbnC6T16zUlI3+ba O5dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=E2us64Jl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v5si16190306edi.595.2021.10.11.09.37.17; Mon, 11 Oct 2021 09:37:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=E2us64Jl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243315AbhJKOOu (ORCPT + 99 others); Mon, 11 Oct 2021 10:14:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:34548 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241398AbhJKOMX (ORCPT ); Mon, 11 Oct 2021 10:12:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D134D611C3; Mon, 11 Oct 2021 14:03:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633961017; bh=NOGSNji1o8kG1g3XIXYxkdGf31q50X9+8naDMWaz/Zc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E2us64Jl5/O18W0/NlVJeSlHXlrKh6jc/yEnNuTPpQEA4orA9zjm52qE6G88xoMBd lN2Pv4a5lK6M6HMmhiykOGXligtwVCzA/RfXY4V7vuas/wnNXKH1ZUm+HiTvxNERTF RU9yr0mrugI1aQQBhZwHs/LnHXK+aoKiZ/dS0Ke0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nicholas Piggin , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Michael Ellerman , Sasha Levin Subject: [PATCH 5.14 141/151] powerpc/64s: Fix unrecoverable MCE calling async handler from NMI Date: Mon, 11 Oct 2021 15:46:53 +0200 Message-Id: <20211011134522.371374641@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211011134517.833565002@linuxfoundation.org> References: <20211011134517.833565002@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nicholas Piggin [ Upstream commit f08fb25bc66986b0952724530a640d9970fa52c1 ] The machine check handler is not considered NMI on 64s. The early handler is the true NMI handler, and then it schedules the machine_check_exception handler to run when interrupts are enabled. This works fine except the case of an unrecoverable MCE, where the true NMI is taken when MSR[RI] is clear, it can not recover, so it calls machine_check_exception directly so something might be done about it. Calling an async handler from NMI context can result in irq state and other things getting corrupted. This can also trigger the BUG at arch/powerpc/include/asm/interrupt.h:168 BUG_ON(!arch_irq_disabled_regs(regs) && !(regs->msr & MSR_EE)); Fix this by making an _async version of the handler which is called in the normal case, and a NMI version that is called for unrecoverable interrupts. Fixes: 2b43dd7653cc ("powerpc/64: enable MSR[EE] in irq replay pt_regs") Signed-off-by: Nicholas Piggin Tested-by: Cédric Le Goater Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20211004145642.1331214-6-npiggin@gmail.com Signed-off-by: Sasha Levin --- arch/powerpc/include/asm/interrupt.h | 5 ++--- arch/powerpc/kernel/exceptions-64s.S | 8 +++++-- arch/powerpc/kernel/traps.c | 31 ++++++++++++++++------------ 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/arch/powerpc/include/asm/interrupt.h b/arch/powerpc/include/asm/interrupt.h index 6b800d3e2681..a925dbc5833c 100644 --- a/arch/powerpc/include/asm/interrupt.h +++ b/arch/powerpc/include/asm/interrupt.h @@ -525,10 +525,9 @@ static __always_inline long ____##func(struct pt_regs *regs) /* kernel/traps.c */ DECLARE_INTERRUPT_HANDLER_NMI(system_reset_exception); #ifdef CONFIG_PPC_BOOK3S_64 -DECLARE_INTERRUPT_HANDLER_ASYNC(machine_check_exception); -#else -DECLARE_INTERRUPT_HANDLER_NMI(machine_check_exception); +DECLARE_INTERRUPT_HANDLER_ASYNC(machine_check_exception_async); #endif +DECLARE_INTERRUPT_HANDLER_NMI(machine_check_exception); DECLARE_INTERRUPT_HANDLER(SMIException); DECLARE_INTERRUPT_HANDLER(handle_hmi_exception); DECLARE_INTERRUPT_HANDLER(unknown_exception); diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S index 024d9231f88c..eaf1f72131a1 100644 --- a/arch/powerpc/kernel/exceptions-64s.S +++ b/arch/powerpc/kernel/exceptions-64s.S @@ -1243,7 +1243,7 @@ EXC_COMMON_BEGIN(machine_check_common) li r10,MSR_RI mtmsrd r10,1 addi r3,r1,STACK_FRAME_OVERHEAD - bl machine_check_exception + bl machine_check_exception_async b interrupt_return_srr @@ -1303,7 +1303,11 @@ END_FTR_SECTION_IFSET(CPU_FTR_HVMODE) subi r12,r12,1 sth r12,PACA_IN_MCE(r13) - /* Invoke machine_check_exception to print MCE event and panic. */ + /* + * Invoke machine_check_exception to print MCE event and panic. + * This is the NMI version of the handler because we are called from + * the early handler which is a true NMI. + */ addi r3,r1,STACK_FRAME_OVERHEAD bl machine_check_exception diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c index 4ac85ab15ad7..08356ec9bfed 100644 --- a/arch/powerpc/kernel/traps.c +++ b/arch/powerpc/kernel/traps.c @@ -797,24 +797,22 @@ void die_mce(const char *str, struct pt_regs *regs, long err) * do_exit() checks for in_interrupt() and panics in that case, so * exit the irq/nmi before calling die. */ - if (IS_ENABLED(CONFIG_PPC_BOOK3S_64)) - irq_exit(); - else + if (in_nmi()) nmi_exit(); + else + irq_exit(); die(str, regs, err); } /* - * BOOK3S_64 does not call this handler as a non-maskable interrupt + * BOOK3S_64 does not usually call this handler as a non-maskable interrupt * (it uses its own early real-mode handler to handle the MCE proper * and then raises irq_work to call this handler when interrupts are - * enabled). + * enabled). The only time when this is not true is if the early handler + * is unrecoverable, then it does call this directly to try to get a + * message out. */ -#ifdef CONFIG_PPC_BOOK3S_64 -DEFINE_INTERRUPT_HANDLER_ASYNC(machine_check_exception) -#else -DEFINE_INTERRUPT_HANDLER_NMI(machine_check_exception) -#endif +static void __machine_check_exception(struct pt_regs *regs) { int recover = 0; @@ -848,12 +846,19 @@ DEFINE_INTERRUPT_HANDLER_NMI(machine_check_exception) /* Must die if the interrupt is not recoverable */ if (!(regs->msr & MSR_RI)) die_mce("Unrecoverable Machine check", regs, SIGBUS); +} #ifdef CONFIG_PPC_BOOK3S_64 - return; -#else - return 0; +DEFINE_INTERRUPT_HANDLER_ASYNC(machine_check_exception_async) +{ + __machine_check_exception(regs); +} #endif +DEFINE_INTERRUPT_HANDLER_NMI(machine_check_exception) +{ + __machine_check_exception(regs); + + return 0; } DEFINE_INTERRUPT_HANDLER(SMIException) /* async? */ -- 2.33.0