From patchwork Tue Apr 18 19:47:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: D Scott Phillips X-Patchwork-Id: 13216126 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 05B50C77B75 for ; Tue, 18 Apr 2023 19:49:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=S6PJZ4y3S75HFGlK9cgIXFLdUdKrCu0NAUYBSNyHRXc=; b=FzcoIeZik0xIWk AkbtwCjbKHlMOULMJGAIqoL+DuVTB63ffdSzQnVbTlMSwO4JUQJGPU4J9w/HySfjs87eeaT5eYTjT e4tT54Fi5q2MBRac2kI3KqdvmfmOgwDwnIi6QqIopEUu+xT7DHElJx9mpkf3vPAuic7E3A6ZIHTmY hO8lsY0DQeIRn1/ROgGMvRMrxJiWKVS/s07/GcJ9VVUOaYbhKJ4rF+mxgZD0G4p85ntUgqrMPtssx QksZvdTIFaf9w7e3fmhWMvzx8Bjrx/OoSn500Ikr2LrMErjbppbIEfVhfsmTGaI16VezMyHTDXIMU V0sns2GozjVmLi1G9vQQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1porJF-003Cxy-08; Tue, 18 Apr 2023 19:48:13 +0000 Received: from mail-mw2nam12on20728.outbound.protection.outlook.com ([2a01:111:f400:fe5a::728] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1porJB-003Cx2-03 for linux-arm-kernel@lists.infradead.org; Tue, 18 Apr 2023 19:48:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O1qC9LtVsi+nY1WI7QhT3StX/GqrzL1auLJk3eV3f8uJTq7fTnYsU+Hoapt/2rd1j7IYfuqAlcuo4qgZV1ySpK++Yp5pIa5E4eUO4leebYhxLE+LIRR6yCcs2uPu1sQEoM4C3E1acM6+MLN1xqUYNalDnIahi8QqBKx8Mz6A+s4nkXL0u5wS4X+aUbdhm29QiE4Arwenwceam3HdE82rg2cgWhDh5r/tybsBbOgbdKdcabMXt2TIaZsuW/o7ILnpHdRh6e3bt+vxqugbwqlqvXtHw7Uw+X7WL9gSeXss5Ja3Pjmu8ZvPjPHxjPCPjJxKg3erCf8ZhHnrnu9CGBUR6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=x1QKyM0ujN8MIg70hN50CWZYNE2zTZ84Lbe11dCVmwU=; b=KFS0FX5Qr4UnRWtryCMntRoN8+2TDNenZZlY0+Yz/36PYZHHblyVkcrRia9lD5r1yVr/KwW2t0bc9VgZ5KHYGvf/tShZJlIp48doKkymd0eDmqoQYuCsx96TcJu/9HbjVXRpUnIoVsP9p5jYsyTZq6xkDJ3+DLm5Myxj5AsXVT66Rq0Xnx9tAYdzLQQtUTnALD92t+kh9AIvhMkbZM8dByVo10uzjKpf3tyFcuuI0rjFcmqto3SW5QCuXelW90e9HYo/8Lx3N7LM0sopepJspmzY5wY+R2ZvcdYZ+F7P8E8eq52X5JhYtQAIXrFVsbcoKyudYK3Z0htumnFWqBoW/w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=x1QKyM0ujN8MIg70hN50CWZYNE2zTZ84Lbe11dCVmwU=; b=gnrXnIuPY2Qd4FVMbdKOeqtslgPu9Qr54V7LKvT9Ff7DlTgvXvOQKaIl3pY0WQYNXYT44L6zr6nHTf41Yc9qy36+t4Cu8NWQILW3/qYV/fqFd5Sb/AHbdpWst3Rnq49/e8xkE0GUOskioX+rRxy8dRdaXYNhONecONdCw+Q3fXg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from MWHPR0101MB2893.prod.exchangelabs.com (2603:10b6:301:33::25) by BL3PR01MB7196.prod.exchangelabs.com (2603:10b6:208:347::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.20; Tue, 18 Apr 2023 19:48:02 +0000 Received: from MWHPR0101MB2893.prod.exchangelabs.com ([fe80::1cda:7642:ae1d:599c]) by MWHPR0101MB2893.prod.exchangelabs.com ([fe80::1cda:7642:ae1d:599c%3]) with mapi id 15.20.6319.019; Tue, 18 Apr 2023 19:48:02 +0000 From: D Scott Phillips To: linux-arm-kernel@lists.infradead.org, James Morse Cc: Catalin Marinas , Will Deacon , linux-kernel@vger.kernel.org Subject: [PATCH v2 RESEND 1/2] arm64: sdei: Use alternative patching to select the conduit in sdei exit Date: Tue, 18 Apr 2023 12:47:45 -0700 Message-Id: <20230418194746.620266-1-scott@os.amperecomputing.com> X-Mailer: git-send-email 2.39.2 X-ClientProxiedBy: CH0PR03CA0418.namprd03.prod.outlook.com (2603:10b6:610:11b::19) To MWHPR0101MB2893.prod.exchangelabs.com (2603:10b6:301:33::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR0101MB2893:EE_|BL3PR01MB7196:EE_ X-MS-Office365-Filtering-Correlation-Id: 0a09d52c-3169-4653-ec20-08db4045d194 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /+/7Hq/tBfy9MNp/2lCX19KiMntq9BIV/hSbeyYDTQSq1/EFk7V2JgT/35D7BupWxTSZZZfSfWhiqOKcT9FxgbSlYwlO4nwF1Fzq0Y7Q1Q8dT9u2e13jFOwheqyY72ad5d1VZWRA94nEGkrTJucfPXeRZgXEmzSFwZbrPJamxR0jGE/WwH47uGUjanpgyb/zGbtiloJ1iMQHuN5aomfh5Z5Dbc1UCwyEq/KBMkLq3Tmibk9V2N1PRN88R1FDRnthrsss3TwpcUw1Dsm3T5XQe/7s+lNYTO2CE7OQAJStVFlElEPR1SAMYl7MhRnSuPYgpeKosp/23EuqmJC4K5ulRgi/fb0Kc1G87OMFjELLyrnL5Dn33Qbx/ZellJ/97yg2aw3bW236DpWms7hLKNJqzSa/WL5FPl6fRYXBvLWmOOTLPdfb2QsSV2PCba8KDw+VtM+cvj8gg2vkoeaQOxi7F3KniCBvO7k5y4mOkgg8Gk9dFFpzllOJVoixuER5z4Bpd7jP7jPjFh/xkONXhQWiCWxX9B4wBMMm20+GulfzeY04jr4t+jhxsHfOJcR7AmJAW0AXzZoZDrb9bEziSoZsBvUleqpOkQOHlyfZG1uWLMh4AdHkrv1lTNGErz9kcUVT X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR0101MB2893.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(136003)(39850400004)(396003)(376002)(366004)(346002)(451199021)(5660300002)(2616005)(26005)(86362001)(83380400001)(6512007)(186003)(1076003)(6506007)(38350700002)(38100700002)(8676002)(8936002)(54906003)(6666004)(6486002)(52116002)(478600001)(41300700001)(316002)(66556008)(66946007)(6916009)(66476007)(4326008)(2906002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: w2BifIuL0fRuESN4Jf1F1lg2TE0XhEwpJbdH8VXjGKGXxg5EOnfdF89MjZTgzAm0booBx7Xd0TXzbMSoLVKtguOVe7ob7osfZCPJaFkyEASoYVP6lBw7b3LTkDEodWFKS6MLiEd5EvI4rX/LzY6X6xwwemLSPCz1iBi868N1mFVNEQ/2Wmo342oqBg/VR0x8MZ77Wb+DmZ89uLsnI9ztE4jdfl321aSZN/FOCVOW9sxYneRMa1LvMajCGFOjFnHuUeYvh+2GC0V2vPL4Q7oi3E26fbApea8Dr0n6S7DIApIuBNRhDoiE3vkF+B7ULHPAqHQK/vb7Ovtru05UnfgNoLlUvQU0qnZJ014NftH4GNXAGxlmT43+/nHjOq3VFs3APWcf3o9A0HP6EM3sXCJXiBtrDK1SoXJ099ZTQVhp2+NUWOujqlLd9ZlDIVgPw5qU211/SNZKMQrHNOFs8Phims4sQJX9CZVQISjwcXCBjBc7w4JE3SqLw1fIPQOS1efUIMdQbdYskSo4DGaVKO6PRB2J4/Etn1p3Ai7MumLvO1A4OjUM1Fow9c3Xqc6L3vaPwr+0hC+1mBs9Rg5/MUl02X/PhEwfwLZe2qqPTGgo4sfW4DLa+Bclng0DvwwDBSSZMHiTd1FMJoUw6SHlfg5zPSZTVmBevnob/30aIfEDQH3BB82nbph9AVh+ALiZK0VtGm74QxJrjtdwloij4eMaF9cIoI2nsZVRyWUYx70KIgeAerLw2mj+fo32jrtEJeA9XsCVMXmJoO+UJNNWIhU1o9aA0fjwHHG4Nwnow/8HGc+S5WhzQVQ3qafuxGIf6ccWHUuCnpoDZV0CsIWpV4Fg02Lc0lpAP7B4MeFWMidGBVTaGLmY16JOk1D4MPGUndFqM4Ds2vHThDeC+J3LNMlh1wZ907otqwm9P7kGkrp9I5nq9eHGd5BMLKHO6++gtxvGLMx70t7A29L1zPDi3me9PcDGl9E1vACiqK28X1P+bxyFxc9NQ8C+0vunRfm2hNaFxkQOMSgWC7eGO/X2bhmRbKOWHqBiSbprxgP+k3tNGub+qX5o8p7sHpVUzZkc3Jl3H5eU+S/M628TOfkeqbzh6YeZYpBs/8f2DC1nWjYkRgqWM3KdFWhiInwWhavmoB8RftZTEYmrmTOfTPffkiFiHwgc+mT2HB/1Z4zeNI287ZSpqleBNUtJNDcGeaih9c/nKKUha6pSqrPOPtZnhAqFda3ZNiwVNNxVwuDYoZx8a8Kojvm4RYisn1+1MrqA3mIAkSzqSMrsdksEUKlsk5zS0GpvbKIaeOgP156CSXk+ADeeJBKZ7HuqGEoID5dIKv0R70qn4dEcbJ168lbgo0T0viz/6ScLFiSwCGVIl7t6GvukA1uKtEa5c5B2vuoiFbAhfoISWJ0D3Ol95IwlmzIz8dLw1GTVnYgavIM94ypHwexYy+CYz4S9CgB7wcyfHPKRJ4uK4okuB1wuiR9oFDfedqONgcZeIpOSs/pFiXSdlnO3Lw1FHs0TetcHtvMmDpofxcSecieSqe84/qYk0aN3bZ4y/7pDvDhqUOfF0R4zXsGaUwGl4jbUGZPVtI/SaRRR9JbzsV2RlVPP1MtSh/fjaQ== X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0a09d52c-3169-4653-ec20-08db4045d194 X-MS-Exchange-CrossTenant-AuthSource: MWHPR0101MB2893.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2023 19:48:01.9338 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: +CduQbcu/VGECtB2wdi2Cw1DtJI01SF9OUAyD03NNgIkxWKmM+oIsyDuuVXEhhGqHah1z3yfOFu+EsgVc/37sflzJATgtor/ITduxKGbfQcSxd2PIL5ZBBUh+b9JgeEe X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR01MB7196 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230418_124809_371486_1542EDAE X-CRM114-Status: GOOD ( 20.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Patch in the conduit instruction for SDEI instead of branching between the possible conduits. The sdei driver's conduit initialization is moved earlier in the initialization flow, into setup_arch(), so that it is ready in time for alternative patching. Suggested-by: James Morse Signed-off-by: D Scott Phillips --- arch/arm64/include/asm/sdei.h | 13 +++---- arch/arm64/kernel/entry.S | 26 ++++++------- arch/arm64/kernel/sdei.c | 30 ++++++++++++--- arch/arm64/kernel/setup.c | 3 ++ drivers/firmware/arm_sdei.c | 71 +++++++++++++++++++---------------- include/linux/arm_sdei.h | 6 ++- 6 files changed, 88 insertions(+), 61 deletions(-) diff --git a/arch/arm64/include/asm/sdei.h b/arch/arm64/include/asm/sdei.h index 4292d9bafb9d..badb39510515 100644 --- a/arch/arm64/include/asm/sdei.h +++ b/arch/arm64/include/asm/sdei.h @@ -3,10 +3,6 @@ #ifndef __ASM_SDEI_H #define __ASM_SDEI_H -/* Values for sdei_exit_mode */ -#define SDEI_EXIT_HVC 0 -#define SDEI_EXIT_SMC 1 - #define SDEI_STACK_SIZE IRQ_STACK_SIZE #ifndef __ASSEMBLY__ @@ -17,8 +13,6 @@ #include -extern unsigned long sdei_exit_mode; - /* Software Delegated Exception entry point from firmware*/ asmlinkage void __sdei_asm_handler(unsigned long event_num, unsigned long arg, unsigned long pc, unsigned long pstate); @@ -40,8 +34,11 @@ asmlinkage unsigned long __sdei_handler(struct pt_regs *regs, unsigned long do_sdei_event(struct pt_regs *regs, struct sdei_registered_event *arg); -unsigned long sdei_arch_get_entry_point(int conduit); -#define sdei_arch_get_entry_point(x) sdei_arch_get_entry_point(x) +unsigned long sdei_arch_get_entry_point(void); +#define sdei_arch_get_entry_point sdei_arch_get_entry_point + +void __init sdei_patch_conduit(struct alt_instr *alt, __le32 *origptr, + __le32 *updptr, int nr_inst); #endif /* __ASSEMBLY__ */ #endif /* __ASM_SDEI_H */ diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index ab2a6e33c052..ae7aa02f0df5 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -914,13 +914,10 @@ NOKPROBE(call_on_irq_stack) #include #include -.macro sdei_handler_exit exit_mode - /* On success, this call never returns... */ - cmp \exit_mode, #SDEI_EXIT_SMC - b.ne 99f - smc #0 - b . -99: hvc #0 +.macro sdei_handler_exit +alternative_cb ARM64_ALWAYS_SYSTEM, sdei_patch_conduit + nop // Patched to SMC/HVC #0 +alternative_cb_end b . .endm @@ -955,7 +952,6 @@ NOKPROBE(__sdei_asm_entry_trampoline) * Make the exit call and restore the original ttbr1_el1 * * x0 & x1: setup for the exit API call - * x2: exit_mode * x4: struct sdei_registered_event argument from registration time. */ SYM_CODE_START(__sdei_asm_exit_trampoline) @@ -964,7 +960,7 @@ SYM_CODE_START(__sdei_asm_exit_trampoline) tramp_unmap_kernel tmp=x4 -1: sdei_handler_exit exit_mode=x2 +1: sdei_handler_exit SYM_CODE_END(__sdei_asm_exit_trampoline) NOKPROBE(__sdei_asm_exit_trampoline) .popsection // .entry.tramp.text @@ -1070,14 +1066,16 @@ SYM_CODE_START(__sdei_asm_handler) mov_q x3, SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME csel x0, x2, x3, ls - ldr_l x2, sdei_exit_mode - -alternative_if_not ARM64_UNMAP_KERNEL_AT_EL0 - sdei_handler_exit exit_mode=x2 +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 +alternative_if ARM64_UNMAP_KERNEL_AT_EL0 + b 1f alternative_else_nop_endif +#endif + + sdei_handler_exit #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 - tramp_alias dst=x5, sym=__sdei_asm_exit_trampoline, tmp=x3 +1: tramp_alias dst=x5, sym=__sdei_asm_exit_trampoline, tmp=x3 br x5 #endif SYM_CODE_END(__sdei_asm_handler) diff --git a/arch/arm64/kernel/sdei.c b/arch/arm64/kernel/sdei.c index 830be01af32d..be7f6ea49956 100644 --- a/arch/arm64/kernel/sdei.c +++ b/arch/arm64/kernel/sdei.c @@ -20,8 +20,6 @@ #include #include -unsigned long sdei_exit_mode; - /* * VMAP'd stacks checking for stack overflow on exception using sp as a scratch * register, meaning SDEI has to switch to its own stack. We need two stacks as @@ -162,7 +160,7 @@ static int init_sdei_scs(void) return err; } -unsigned long sdei_arch_get_entry_point(int conduit) +unsigned long sdei_arch_get_entry_point(void) { /* * SDEI works between adjacent exception levels. If we booted at EL1 we @@ -181,8 +179,6 @@ unsigned long sdei_arch_get_entry_point(int conduit) if (init_sdei_scs()) goto out_err_free_stacks; - sdei_exit_mode = (conduit == SMCCC_CONDUIT_HVC) ? SDEI_EXIT_HVC : SDEI_EXIT_SMC; - #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 if (arm64_kernel_unmapped_at_el0()) { unsigned long offset; @@ -262,3 +258,27 @@ unsigned long __kprobes do_sdei_event(struct pt_regs *regs, return vbar + 0x480; } + +/* + * Patch in the sdei conduit instruction. + */ +void __init sdei_patch_conduit(struct alt_instr *alt, __le32 *origptr, + __le32 *updptr, int nr_inst) +{ + u32 insn; + + BUG_ON(nr_inst != 1); /* NOP -> HVC/SMC */ + + switch (sdei_get_conduit()) { + case SMCCC_CONDUIT_HVC: + insn = aarch64_insn_get_hvc_value(); + break; + case SMCCC_CONDUIT_SMC: + insn = aarch64_insn_get_smc_value(); + break; + default: + return; + } + + *updptr = cpu_to_le32(insn); +} diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index b8ec7b3ac9cb..6286c4c59074 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -365,6 +366,8 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p) else psci_acpi_init(); + sdei_conduit_init(); + init_bootcpu_ops(); smp_init_cpus(); smp_build_mpidr_hash(); diff --git a/drivers/firmware/arm_sdei.c b/drivers/firmware/arm_sdei.c index 1e1a51510e83..0dbb88bcc9a2 100644 --- a/drivers/firmware/arm_sdei.c +++ b/drivers/firmware/arm_sdei.c @@ -919,37 +919,12 @@ int sdei_unregister_ghes(struct ghes *ghes) return err; } -static int sdei_get_conduit(struct platform_device *pdev) +enum arm_smccc_conduit sdei_get_conduit(void) { - const char *method; - struct device_node *np = pdev->dev.of_node; - - sdei_firmware_call = NULL; - if (np) { - if (of_property_read_string(np, "method", &method)) { - pr_warn("missing \"method\" property\n"); - return SMCCC_CONDUIT_NONE; - } - - if (!strcmp("hvc", method)) { - sdei_firmware_call = &sdei_smccc_hvc; - return SMCCC_CONDUIT_HVC; - } else if (!strcmp("smc", method)) { - sdei_firmware_call = &sdei_smccc_smc; - return SMCCC_CONDUIT_SMC; - } - - pr_warn("invalid \"method\" property: %s\n", method); - } else if (!acpi_disabled) { - if (acpi_psci_use_hvc()) { - sdei_firmware_call = &sdei_smccc_hvc; - return SMCCC_CONDUIT_HVC; - } else { - sdei_firmware_call = &sdei_smccc_smc; - return SMCCC_CONDUIT_SMC; - } - } - + if (sdei_firmware_call == sdei_smccc_hvc) + return SMCCC_CONDUIT_HVC; + if (sdei_firmware_call == sdei_smccc_smc) + return SMCCC_CONDUIT_SMC; return SMCCC_CONDUIT_NONE; } @@ -957,9 +932,7 @@ static int sdei_probe(struct platform_device *pdev) { int err; u64 ver = 0; - int conduit; - conduit = sdei_get_conduit(pdev); if (!sdei_firmware_call) return 0; @@ -984,7 +957,7 @@ static int sdei_probe(struct platform_device *pdev) if (err) return err; - sdei_entry_point = sdei_arch_get_entry_point(conduit); + sdei_entry_point = sdei_arch_get_entry_point(); if (!sdei_entry_point) { /* Not supported due to hardware or boot configuration */ sdei_mark_interface_broken(); @@ -1059,6 +1032,38 @@ static bool __init sdei_present_acpi(void) return true; } +void __init sdei_conduit_init(void) +{ + const char *method; + struct device_node *np; + + if (acpi_disabled) { + np = of_find_matching_node_and_match(NULL, sdei_of_match, NULL); + if (!np || !of_device_is_available(np)) + return; + + if (of_property_read_string(np, "method", &method)) { + pr_warn("missing \"method\" property\n"); + return; + } + + if (!strcmp("hvc", method)) + sdei_firmware_call = &sdei_smccc_hvc; + else if (!strcmp("smc", method)) + sdei_firmware_call = &sdei_smccc_smc; + else + pr_warn("invalid \"method\" property: %s\n", method); + } else { + if (!sdei_present_acpi()) + return; + + if (acpi_psci_use_hvc()) + sdei_firmware_call = &sdei_smccc_hvc; + else + sdei_firmware_call = &sdei_smccc_smc; + } +} + void __init sdei_init(void) { struct platform_device *pdev; diff --git a/include/linux/arm_sdei.h b/include/linux/arm_sdei.h index 14dc461b0e82..de9aafd87c48 100644 --- a/include/linux/arm_sdei.h +++ b/include/linux/arm_sdei.h @@ -13,7 +13,7 @@ /* Arch code should override this to set the entry point from firmware... */ #ifndef sdei_arch_get_entry_point -#define sdei_arch_get_entry_point(conduit) (0) +#define sdei_arch_get_entry_point() (0) #endif /* @@ -22,6 +22,8 @@ */ typedef int (sdei_event_callback)(u32 event, struct pt_regs *regs, void *arg); +enum arm_smccc_conduit sdei_get_conduit(void); + /* * Register your callback to claim an event. The event must be described * by firmware. @@ -47,10 +49,12 @@ int sdei_unregister_ghes(struct ghes *ghes); int sdei_mask_local_cpu(void); int sdei_unmask_local_cpu(void); void __init sdei_init(void); +void __init sdei_conduit_init(void); #else static inline int sdei_mask_local_cpu(void) { return 0; } static inline int sdei_unmask_local_cpu(void) { return 0; } static inline void sdei_init(void) { } +static inline void sdei_conduit_init(void) { } #endif /* CONFIG_ARM_SDE_INTERFACE */ From patchwork Tue Apr 18 19:47:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: D Scott Phillips X-Patchwork-Id: 13216127 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4AA26C77B7E for ; Tue, 18 Apr 2023 19:49:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xXywYLMUsyTYBkvXL5EwnXZKLgzamuhm8Zsbb8FJSx8=; b=bQdd/d80iLcmkG z0vw1yHr1vqn6zTuNvVRqxBCCmprMfdJ6ROwAR/JabOR6394Ch+punpe8i9d66a0ORhYX5ACP9Pbj gyXtQUFFRfCEjo7DT5K9lkh2lT1LaINaHS0rsaIBr5JClDha0wyS9uImhfPjrkmBI6ZrLlsIjS4rb cEdnnDAQ3KFznWAcrbT3iMAM6VMWi0+jAbtB2rFzZxZJ8C/Rz7HmWMXn+cOeqVpTQUyngI2d+S0gX Bft4mCCEVf8ZV8lEHxGVeiHu5egzH7cXzfq7s0D0UlOF8X5P4Ex3+alBNaPwdHcIAua967t7f/jwG pUROXTP6eZt9B2ODyWhQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1porJL-003CzB-0U; Tue, 18 Apr 2023 19:48:19 +0000 Received: from mail-mw2nam12on20728.outbound.protection.outlook.com ([2a01:111:f400:fe5a::728] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1porJD-003Cx2-1B for linux-arm-kernel@lists.infradead.org; Tue, 18 Apr 2023 19:48:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nJHEbIrS+c4cnXxyYjkbB62KW8IbBxkbGJgHvQX8jgURE3u1Fb8U0q8kUQf7ZBZW8HaWpb60fMHPvwJ8R/dbBnrBH4Jo0RgqOhOAtanhSpLVFFRmbzwo5NYOuJ5ZjDeXe3LAu6ly1GND10GWWv1FaqpmvjPwWTezewBwl9Ob8mOkajo96Z7hUVN98seJec2b3mWiO8oOQbfyxTNa52RYqcuLKgA83L8DGVwtOgdjlDFmTQrowhwmhjgu+EgPcIAwEjgb5tKThgqcdvso0zMG7VMyQhsjlehKx9vz5SvOxgorZsfKhQrUMTpyl7l00/glXCseTK27bmch/jNQHBfYhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=gBqPvPs4q2Jt1uOdvG3vZxgyMi7/bDMueON4hFS2uo0=; b=El9jfer1eYjKLLh3RkKBaJufCaC3GQNFOyWaDmhG+gkcx2hkKj7eW4Rish2D3QjkFau/qVH6ONZoTOBCWuGPzzMDRfKk5/mu4zlRhCM7CVpvi8aQplD4U3BIG6kgXNOaxU5DhiHd3Y1YrQ0Da//4lIySQRB3Xgy7qEVLYxgIoyDe1lAhWWRzSgvu6EFPqw0DixUz1b7GbE+j/5ciTMTwp/sSqVfJQk25ntN6wEkspdScop9qR49NhSrJwkC4bck7y6NSTsh5KSGW1HfEFteV6pBf2lUhYx1kYo6Jrz5u6exZYqqlydEeLZ2cuqLlx3bZtne8MAy4hoVd89+wHiEUeQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gBqPvPs4q2Jt1uOdvG3vZxgyMi7/bDMueON4hFS2uo0=; b=c//FSstinSV/R3qiB7pF//ZoNLuM3DBd++rCV96O7DWIUEQsN7fg1A5CBldsYrdUHCLsjHCTqVxm6OiF6/H/WX/LjdrU+Xg/KxcxlTrrWIr1fHYpHF3bHT09b+0wYof6KahvSgCCaQdvT0vpHswB7viErXEDsk2CDPzH4sjfBi4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from MWHPR0101MB2893.prod.exchangelabs.com (2603:10b6:301:33::25) by BL3PR01MB7196.prod.exchangelabs.com (2603:10b6:208:347::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.20; Tue, 18 Apr 2023 19:48:03 +0000 Received: from MWHPR0101MB2893.prod.exchangelabs.com ([fe80::1cda:7642:ae1d:599c]) by MWHPR0101MB2893.prod.exchangelabs.com ([fe80::1cda:7642:ae1d:599c%3]) with mapi id 15.20.6319.019; Tue, 18 Apr 2023 19:48:03 +0000 From: D Scott Phillips To: linux-arm-kernel@lists.infradead.org, James Morse Cc: Catalin Marinas , Will Deacon , linux-kernel@vger.kernel.org Subject: [PATCH v2 RESEND 2/2] arm64: sdei: abort running SDEI handlers during crash Date: Tue, 18 Apr 2023 12:47:46 -0700 Message-Id: <20230418194746.620266-2-scott@os.amperecomputing.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230418194746.620266-1-scott@os.amperecomputing.com> References: <20230418194746.620266-1-scott@os.amperecomputing.com> X-ClientProxiedBy: CH0PR03CA0418.namprd03.prod.outlook.com (2603:10b6:610:11b::19) To MWHPR0101MB2893.prod.exchangelabs.com (2603:10b6:301:33::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR0101MB2893:EE_|BL3PR01MB7196:EE_ X-MS-Office365-Filtering-Correlation-Id: 19b5fb34-4ff5-4ad4-a49a-08db4045d253 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LVIxC4eRsLv6Z//JFLkDhdCeHaGdjuP3Tn7THAzqPlrRg5RDCMFk3YhFWWPRRfhjn80ZwCH83Z/K3cuKK1zGaZOydR6Eyt4ajKYNZXHNopd45prqhjrbH8osYy/PTiUpqFg14gm1wE9y0RuF4LGi8E7Lyku9uNFFcZ4fJgoNw53mh4gvjkaRsR8/GX9R2QHMXB/gRygsJnEisUn21yuRDC3JndIwz6SGOemjLkNxlei3+Pj5c/sv/n07oD8+vOl1sO5RggAyorjmJoNta5cnMFhA7LmwIjPRABt/ewQfVkkhzf5+TB15jncSdSDevxsBAHUhO9Lvr9FmwRACD8aIeWdV3mfK6SDyFBN49nG5DPNk1rIKdFxRu59Uu7epB7zS9avZbC6NnmuWbWKoeI4EviTjrykoqpn8umW/q5V4Q8UusARf5B/z7J0XUEXBUXq5dpm8bQVvOa8uN8YfTBNdr5Efnl5AUgGG/ygcwHu0l4sB/YYMxHPhXkHaaQunDmCuiHcDpBevHKX+VOLpW1Hj4mwXCOS8APLCPKsCyP/D/Xp+CMnUjfPGzTcauarc64tCgkb/d3/zzx/RAyrLh1exefhKsLpY6qeF8/HCutg3w81EkJadSpN6QUEwzHvrM3SF X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR0101MB2893.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(136003)(39850400004)(396003)(376002)(366004)(346002)(451199021)(5660300002)(2616005)(26005)(86362001)(83380400001)(6512007)(186003)(1076003)(6506007)(38350700002)(38100700002)(8676002)(8936002)(54906003)(6666004)(6486002)(52116002)(478600001)(41300700001)(316002)(66556008)(66946007)(6916009)(66476007)(4326008)(2906002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FMeKC+PgUtkf8yCihkEhxFbDwl5nZzAWN4LHBksdN2INRuMw3V1KxLNIGXkY6wODv8DVqpq1w9N2TCoF0nSWOVWz48LJDHcvT2darf55VZ7GCGmIHUHT9eojr1SOLPM2AB8NNjz1/TM6L4gm5XBS0dr/kVS8qFNn3LvmuaEQb0bzJjnXUJv0ATKJEiWDy+YuTP3zg3WlJxq31Jtay2nmBwzQ5P3NdLLeht/CI5icIdCSN2gDcAPk9ygwyER3IUn+oXeICeJlckNLS2VN7nEpQcjo2uGWcRcvz2wb0xyjVptHkM0P3v8tSMNQzBiqg6ZNz1MhxsPX/vcmn5uNoAae3rx9zP0qGPg6rfW/rAk4dvMMZP+MwRWstcR46WPau2FV0lGrbevbIjkY6T9fLDptmqBSgkvv9RD4/14yH0O5Y3tdZk+L3yj9PKRbKgSY9OqzfX6+3wrRukNx0L892AvXIgAaiKAR3PHZzIHbmkN27AtAoKHpVb9Us0owzru80l4Y5jxyoqtddK+OjXk4DU2rKacbEK2I8Wg6TtLKcU4zSF8f3QvanHet+GdxuFuFB58QMYTp441IHiZ6zZe15uzIOtXD/LAs3Jy2y+ScJe8OsocGmyHVkchBt3rfdfpReeh7acjLmP20947FtJe+paDM9U8sZ+2a1Jh3Obgz1k6B4EtkM5mlRSRyiYrcz3gZZr7VWaz99Z/BpN9B2Rv62N+DdkKlOE5W7yDOmhvFSP5SNmiq2DDaM+78K5EOkbDYuY8yvQhVH+TBPzyhJDZqExKAsAXyTVpuqrOWWJbhkTIAwDgvVlWaKDIwCOZbKRvuH4EgLB5HEGbGZbP3eIoSZPHHt9m8sOSwssJE0dpjO1QznNzec0QZFu6pasDzdbaCbZIq90To5FL6wmMTc3zcurvOeGA+fg5tJnbyzY5s0RUtTkumfhs7ORdCsD0aXMuOnsFjdgz6ASarZkfqN3Sh4L/HfS7WujqgERazjR5/t+r6oNjeQP3XdqRTNvqI9j0lfUIztaHwVDW26Eo7Q8nYIoVbUKU5WHWeqPdQDJQhJiHEbp4Md/YwuO2JAkwM3HDs70ZrrTnfBkrCyDpBtJJgnfm38WYo20eTwPXmymg6Ei7mY9q/mpo8SFyxfQRkhZIHJYoyBLM1C90ppADL2jYylOBEtLGKd6NEsUt9EspX1PezQmQuAw0UBK67AEeaTjOOf8CUG11wx5JnFhNalEHx2RsvUB8Gd2+Pjk+06IVex6OyK5z0TakWv/Ca45uku3bL+ixsL7bhIhveS0bkiUQH/MiZ923N/XRqC8+4OSh5pOgzDa/r9YoT5mDcbDzXSWcwzpWY+Y4DGNtbmvqZ+h8qLIw4NFiyOVqjj1lUqJas39ufHCH5dpxdV/jKixbnBzxN536mS2Vds4Pha2IRHahxQqhwXnso7xGxu+rBLTtvAG4NqMISelvEaB0rUNaJUowiOHcXJdmb0mMK6fR1rq8BaxdXU6Nziz1jrlFbvNy+5CZCXfU1NMe10cii1kQ0gzXijkYCxpg7pkfzjaHg1KhIQw7EM+6ifHj7H3/dyJB5NCfv8MCs6lBlwL5bm37oCP1xVXJNAbFDInq+75TcE6EEHkUBtg== X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 19b5fb34-4ff5-4ad4-a49a-08db4045d253 X-MS-Exchange-CrossTenant-AuthSource: MWHPR0101MB2893.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2023 19:48:03.2021 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: kd8za+g9YCedsf82ZRo0yC4cZFAht0GpzL9zie9Jhnv1HMWoBDaF3GdLRSgQo5IhMDObzrQwZPwYH9LtmQnhkADhDq2juMNQ6Y5nvF/w/YHP8NODs5ZBXPpAjzQ5/Cub X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR01MB7196 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230418_124811_410576_251446BE X-CRM114-Status: GOOD ( 19.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Interrupts are blocked in SDEI context, per the SDEI spec: "The client interrupts cannot preempt the event handler." If we crashed in the SDEI handler-running context (as with ACPI's AGDI) then we need to clean up the SDEI state before proceeding to the crash kernel so that the crash kernel can have working interrupts. Track the active SDEI handler per-cpu so that we can COMPLETE_AND_RESUME the handler, discarding the interrupted context. Fixes: f5df26961853 ("arm64: kernel: Add arch-specific SDEI entry code and CPU masking") Signed-off-by: D Scott Phillips --- arch/arm64/include/asm/sdei.h | 8 ++++++++ arch/arm64/kernel/entry.S | 24 ++++++++++++++++++++++++ arch/arm64/kernel/sdei.c | 3 +++ arch/arm64/kernel/smp.c | 27 +++++++++++++++++++++++---- 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/sdei.h b/arch/arm64/include/asm/sdei.h index badb39510515..58bc9ebe4a6d 100644 --- a/arch/arm64/include/asm/sdei.h +++ b/arch/arm64/include/asm/sdei.h @@ -13,6 +13,11 @@ #include +#ifdef CONFIG_ARM_SDE_INTERFACE +DECLARE_PER_CPU(struct sdei_registered_event *, sdei_active_normal_event); +DECLARE_PER_CPU(struct sdei_registered_event *, sdei_active_critical_event); +#endif + /* Software Delegated Exception entry point from firmware*/ asmlinkage void __sdei_asm_handler(unsigned long event_num, unsigned long arg, unsigned long pc, unsigned long pstate); @@ -23,6 +28,9 @@ asmlinkage void __sdei_asm_entry_trampoline(unsigned long event_num, unsigned long pc, unsigned long pstate); +/* Abort a running handler. Context is discarded. */ +void sdei_handler_abort(void); + /* * The above entry point does the minimum to call C code. This function does * anything else, before calling the driver. diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index ae7aa02f0df5..6d5694dfcb7b 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -1003,6 +1003,12 @@ SYM_CODE_START(__sdei_asm_handler) ldrb w4, [x19, #SDEI_EVENT_PRIORITY] #endif + cbnz w4, 1f + adr_this_cpu dst=x5, sym=sdei_active_normal_event, tmp=x6 + b 2f +1: adr_this_cpu dst=x5, sym=sdei_active_critical_event, tmp=x6 +2: str x19, [x5] + #ifdef CONFIG_VMAP_STACK /* * entry.S may have been using sp as a scratch register, find whether @@ -1066,6 +1072,13 @@ SYM_CODE_START(__sdei_asm_handler) mov_q x3, SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME csel x0, x2, x3, ls + ldrb w3, [x4, #SDEI_EVENT_PRIORITY] + cbnz w3, 1f + adr_this_cpu dst=x5, sym=sdei_active_normal_event, tmp=x6 + b 2f +1: adr_this_cpu dst=x5, sym=sdei_active_critical_event, tmp=x6 +2: str xzr, [x5] + #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 alternative_if ARM64_UNMAP_KERNEL_AT_EL0 b 1f @@ -1080,4 +1093,15 @@ alternative_else_nop_endif #endif SYM_CODE_END(__sdei_asm_handler) NOKPROBE(__sdei_asm_handler) + +SYM_CODE_START(sdei_handler_abort) + mov_q x0, SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME + adr x1, 1f + sdei_handler_exit + // exit the handler and jump to the next instruction. + // Exit will stomp x0-x17, PSTATE, ELR_ELx, and SPSR_ELx. +1: ret +SYM_CODE_END(sdei_handler_abort) +NOKPROBE(sdei_handler_abort) + #endif /* CONFIG_ARM_SDE_INTERFACE */ diff --git a/arch/arm64/kernel/sdei.c b/arch/arm64/kernel/sdei.c index be7f6ea49956..07fa9630f0ce 100644 --- a/arch/arm64/kernel/sdei.c +++ b/arch/arm64/kernel/sdei.c @@ -45,6 +45,9 @@ DEFINE_PER_CPU(unsigned long *, sdei_shadow_call_stack_normal_ptr); DEFINE_PER_CPU(unsigned long *, sdei_shadow_call_stack_critical_ptr); #endif +DEFINE_PER_CPU(struct sdei_registered_event *, sdei_active_normal_event); +DEFINE_PER_CPU(struct sdei_registered_event *, sdei_active_critical_event); + static void _free_sdei_stack(unsigned long * __percpu *ptr, int cpu) { unsigned long *p; diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index 4e8327264255..ea221b1ee9ac 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -1047,10 +1047,8 @@ void crash_smp_send_stop(void) * If this cpu is the only one alive at this point in time, online or * not, there are no stop messages to be sent around, so just back out. */ - if (num_other_online_cpus() == 0) { - sdei_mask_local_cpu(); - return; - } + if (num_other_online_cpus() == 0) + goto skip_ipi; cpumask_copy(&mask, cpu_online_mask); cpumask_clear_cpu(smp_processor_id(), &mask); @@ -1069,7 +1067,28 @@ void crash_smp_send_stop(void) pr_warn("SMP: failed to stop secondary CPUs %*pbl\n", cpumask_pr_args(&mask)); +skip_ipi: sdei_mask_local_cpu(); + +#ifdef CONFIG_ARM_SDE_INTERFACE + /* + * If the crash happened in an SDEI event handler then we need to + * finish the handler with the firmware so that we can have working + * interrupts in the crash kernel. + */ + if (__this_cpu_read(sdei_active_critical_event)) { + pr_warn("SMP: stopped CPUS from SDEI critical event handler " + "context, attempting to finish handler.\n"); + sdei_handler_abort(); + __this_cpu_write(sdei_active_critical_event, NULL); + } + if (__this_cpu_read(sdei_active_normal_event)) { + pr_warn("SMP: stopped CPUS from SDEI normal event handler " + "context, attempting to finish handler.\n"); + sdei_handler_abort(); + __this_cpu_write(sdei_active_normal_event, NULL); + } +#endif } bool smp_crash_stop_failed(void)