From patchwork Wed Jun 7 19:55: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: 104698 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp455731vqr; Wed, 7 Jun 2023 13:17:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ42RlU6dFaQUHNeR4yyjHXuRWYOweJacvLbW2uLUkw/tgRATqINMb6Xv7oZtLD4AuGOR0Mi X-Received: by 2002:a17:902:b689:b0:1b1:9f7d:2aec with SMTP id c9-20020a170902b68900b001b19f7d2aecmr5597354pls.68.1686169040211; Wed, 07 Jun 2023 13:17:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1686169040; cv=pass; d=google.com; s=arc-20160816; b=aOwHD1cPK556BDcpzkAVgGT82pAZxkz+DidgUmSjDcexKm4xpBM0Sc7NOnkaiIFsWu 6WFhlMuYctZ1if7A24O5TcgblVUR5a578K0LYjmChqCKk0e7ZR/lhcGJKW/vPJqXwSUH vdlpv/mTOdc+pdYSAzjpnk0S/bBTacqs+PhmPjfufJD6hE+9L3yNQOEq3DRzmU111cSj wVwuuZ18hb9rNpcY8Tz8Zd4HKfnwNroVO5/9ag5E1mVyxFyEuSwy5tNvEg6zhnujb+sC mMjk112kSGdMulh0L7I33IvAifAaVqpSe2fm5yootB2pLOg+dmc4vQx5XKqhB1zEx3Nd yPYA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=Wu4kQOnP0FzQANrlsb/BAbcZIM1icSlJY+ki7H2dYcg=; b=EfbUF1URHEb0ioS0yjFC5KQsK4r4VbbPPS8cQscSMSdgAJPFq7bI79xNXwfK1LAAgM Ad72tiZtuzodt8FXuwMXMaP68OpD2QMiBIRClsp4VAWWtrzIzcGtl+Hy4u6EcYVKOBwU BB+jSDzYagEjBITYtdbFBDpcsikbTXmMhCm3NdzfbzgCR6el0/w7LO13k74OsBR3Ttpt 8ev6v7ue1pYY0AJJ2pled42aEQF+MX2PwZrSUkoW/MPxXMhbap0Exk4dUpiYeXzS84iJ epa8BHrxK5yZaBQnMEBm3FAiDlbBJrXoyMK9v2qf5wzxysDsvq7BYALeKsC7pwmp8hAL t/Lg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=FCNtNYOa; arc=pass (i=1 spf=pass spfdomain=os.amperecomputing.com dkim=pass dkdomain=os.amperecomputing.com dmarc=pass fromdomain=os.amperecomputing.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amperecomputing.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q2-20020a170902edc200b001b0f727bc35si9149152plk.157.2023.06.07.13.17.03; Wed, 07 Jun 2023 13:17:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=FCNtNYOa; arc=pass (i=1 spf=pass spfdomain=os.amperecomputing.com dkim=pass dkdomain=os.amperecomputing.com dmarc=pass fromdomain=os.amperecomputing.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amperecomputing.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231792AbjFGT4T (ORCPT + 99 others); Wed, 7 Jun 2023 15:56:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229980AbjFGT4R (ORCPT ); Wed, 7 Jun 2023 15:56:17 -0400 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2130.outbound.protection.outlook.com [40.107.95.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2DC52125 for ; Wed, 7 Jun 2023 12:56:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XxaE1o+R50lwHjOGOOwH+AnRXWNyrQR6g6t7MqfVQHFt07zgsQVmElfRH8EIUb3ntICXkFffU4eRszcmB6AuvPKOePDrKv/tFn2Q805RfRh2eKsYdUKQoUwm+TwWIG4nRyRgrnfr7GssrHKxirxbkN+bL8yuTXxEgLS0/2955HGlfSXfL7W+gP62OsBtVLhY8Q5xDum0NfySp+Ew5s8a6lesSpxBP2yYi+L3jFjAQJwycQqSfAZ1vnyR+Zctu1m+tfWwIegqFZk/NXlNMGHybZf61s9nNSBFKnD9fzEl8X7x1cSPSrU1yoVNyUMj/uvhl4qGhsTbbP9qvRzpCka2Ig== 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=Wu4kQOnP0FzQANrlsb/BAbcZIM1icSlJY+ki7H2dYcg=; b=PtPX3XR5jxmRIgCbuWdzW4/+KI7ouvOeNP/IuwNa5sLzCAWaBW1LYE/LwTjWjzFwn/yr+w6rskgL6FEHvTtZ40v8GAqe2OsCtIR7trULRgYRNKdfvHv0Q6GundTXxrm/ZZ7KfZsv/Sf3sDitczcLsR3e01sjo5wgg49896ipf1X1yMDWoq+ucyC2WTfkyWNr5trHYh4XoGb/OINCKaxhKG4+S/wva7DfYcntdCXlmmJR9Fm1pxQFUYbqTG0qFOT+mnBrM5Fjv/JJu0aOUCsKIpJvkzXYe514btlChW3icYkpaPSJLDuG0z/uWe9Pzqwr4Ytek6ITw2M4uYBQgr4YKg== 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=Wu4kQOnP0FzQANrlsb/BAbcZIM1icSlJY+ki7H2dYcg=; b=FCNtNYOaGRhGeyqqzMR3MLlvvV6prbL8qIgpM9j/qmOaXjaAL8iFV/exN2yE9jOfIHYrAmaLoT8JpMiGaBFDT3HZfp8yaGGMhAYIJV2EBTmZUMchq84ipQYJ+LvJ8sbfkfN2313Z/jD3GF3bXaEulvTXaYKJZb0Uj0Uv2hoH/yA= 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 PH0PR01MB6328.prod.exchangelabs.com (2603:10b6:510:1c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.33; Wed, 7 Jun 2023 19:56:05 +0000 Received: from MWHPR0101MB2893.prod.exchangelabs.com ([fe80::c3b4:c7ab:46e:476]) by MWHPR0101MB2893.prod.exchangelabs.com ([fe80::c3b4:c7ab:46e:476%2]) with mapi id 15.20.6455.030; Wed, 7 Jun 2023 19:56:05 +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 v3] arm64: sdei: abort running SDEI handlers during crash Date: Wed, 7 Jun 2023 12:55:46 -0700 Message-Id: <20230607195546.2896-1-scott@os.amperecomputing.com> X-Mailer: git-send-email 2.40.1 X-ClientProxiedBy: CH2PR07CA0010.namprd07.prod.outlook.com (2603:10b6:610:20::23) To MWHPR0101MB2893.prod.exchangelabs.com (2603:10b6:301:33::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR0101MB2893:EE_|PH0PR01MB6328:EE_ X-MS-Office365-Filtering-Correlation-Id: 5c7e3ee4-4981-4dd1-aa6d-08db6791392a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fCa14I4MDwcz2czQ7CY7O92AdxZ2EdpvNakhs0bFgj+pdVgaYDEYKBP3XBWqy06FNzi7lT834jGnXVHalHWA5HAXqJHD0RS85Qe8rR1TTT9w1V/LFbQMR+g0bHDUHwsW8ofHnvEVemM+cZC8EkSo4JI4cGqC5GOtBigN1mmE9Jf23FiuMsSZv4CClA4bqzBuo8t09/JN0ePmOOasqmtv9RZIaJfxbWgoAXU4Si+Lpe3hXtFBGk7/SOxzfClpoo/A7Xfz4hpTiIouw3pO3Sy2GKd7ZSaKfTFI20IjkfeFxFs0vZGevyxqY6+6ijwUbFzUq6sPkOADq5FyklaWeXiCrNkFnC3D17dudo4vdrd3oWLMwEF31Or88WsdU7UDjzAjartW90fi8vquGSJ5cxWpWjAdIEu6c+bBgvLF9AcK34SYpNzihykb97ZA8Wpq8ej/ml9ihgPDMREN+UIxKCWs1p0bT+cGjjDNtbsbSlVWW3M6FnnzD+guMMi+0nlMmXrtz/QH43MC/fkuOwZd67wlSbJrZQDg8QbHD/+NVn8RX8Ov01k/o2Z/NDolD2kLTyRp2foeXqghfmHX8Ljd6xVaMIKsfoEpTjOYuecmORWqN6KTe19pcyWFaO5qj1wS25MQFCgLr4Ex+vwE1ASF5R82FQ== 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)(346002)(39850400004)(376002)(366004)(396003)(136003)(451199021)(8676002)(4326008)(66556008)(6916009)(66476007)(8936002)(66946007)(5660300002)(316002)(54906003)(41300700001)(2906002)(478600001)(38100700002)(6512007)(1076003)(86362001)(186003)(6506007)(26005)(38350700002)(6486002)(52116002)(966005)(83380400001)(2616005)(6666004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Pm3oRWIkOQK36LcI/xqShpDkioHGlBk72tDo5mrGbdpPxTJPbLCzMIg8C84eKQcHUflqKeUkNOkdOb0ifCOZwK/7FFlB5jz3Y8umdHKH254CBTvVmaxZZ8zlTLleC07d3X7BqvRhrYZaVWbHLGue7SDSts44FFq2He7Ez7Gr0el3hy23xVYP4+teY3gIsdUsGcwuiguvxU44r+BM/UB0BA0WGZgi/18GFynB/srQjz/ZDw3KPbDdDOHJaAWfIrHkjWzDD8m/Hn8ktMyHSPnm1w7dhDgh0h5YfwWtPT0C4Fu1RVIkk3PAeSIjEhLXuB4g909jpBXqgsK/OSLJ6YoY1Ag0B54UQJDvJBrvgzbUdJ/SeAccQi79GTb28Zpsn9iJHZnIJpN+t103Z6kNzyP3romBsp1rxOJE91QHATpfxXjkVTCO7qXcLMIH9Mq9lCr6GTl56SGbY8rMXcKu9H8OCeyuj3K0A9m0IHHSb4KcQql+xBJf6LQfH6YQQX6lGbthyLqW9bkyMY3nz599BWBBBRi5YD/CunJkLzPdTipBJZfFazo4rv2b9yYKCDBJAaBOjIZ6cbw3Z2r/MQAttLPR86n2kW6dzPY5rWiU2jnLF93HjOD+LFRE0/33ygV4o85TnAGVlMfJNfXRUoR7fUP2jWEMEDmj+e407UyupXVRkJZ1splbTZ+Ifc2tFmbgP5DlFHrENKmXo6xvMRa4wzJtqx7Hs8prk3YSXpSoSd5X13s0F7gOryloQnp+IV/28N/9sBrPTZTlUmkkIfwJASLRZdtAYlm64vAMGVytiWJtQYPCFczQl7hxQxrDIMsdS1CYGcQQdkaHqcTMtP7jA5cvkLfPIFeNZClQo9sX1tn4Yd2DplxEKJL/oZ4/LHg2G8hti7Rn3rsfUbyRzHiEg8WTzBCBw7ZhGg+h4Qc9US+QhqwgNw39ftbNvvypDtTKvhf3++bTAxfzq+KtMeOg018yE9iBbT69IIO4+eF59+b+3FlISFs6wFF3cN7UhslhU0YdDN9+rxGbZ2/uweS4Qzj64xDtVO/MDS4usqCzhDgm6nRHr2OTOHkoitiRZtqNgqlWmGx/LnKQ4l33MpbslRSX2Jc9lWQlcTwn9SFHeyBZpuIZhU7LTRXFJYLpUmecwFIQGUJFnhJMWScyo0b2XA1GjyHGBLoB7XQtE5wiLtW7gpVJwseTS6ah9L1dtEPApk+lFrBhYDJJFL1W+iZT82q37vhFa/C7ZEhQLCmNkcT864hxKGsURbXtaZqyjYmPbx7rbCNA+3pv7de0N48Ntr1O3NSC72GSR8YeQRuSvbG2y/R29sCZQP37DS3aGKWvUzs2VeAFloxyfJDAQML5bAtv/TfRDh+NZMaVbdShvBlz8VJDpG+Qh1CQiv6FPzJR4mbwIVCrxMPYStvEFuH+P2PLjNuAPHUIXyImhHHOU8KfLHxVhO0+Zc8XDHzS5XhNmOSOn7oMI3tR+OvR8LZWVwK/l5ys/xPAySBWtUBpgluwyxuXvN8flcwl/CBmF69FEdTY8WuVdUYSHAPDRtI10BwWa/qpjM9Z+uxzUBaMUxOcc7hq6Ou08ZKmPGrVBwjL/KoLKVPdHthINuDog9pSHe0iuQ== X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5c7e3ee4-4981-4dd1-aa6d-08db6791392a X-MS-Exchange-CrossTenant-AuthSource: MWHPR0101MB2893.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jun 2023 19:56:04.9064 (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: WzOmXP6psmNyCGkZbmQPKDpWmacnTa05LeCyuJcAY0VK7hM4PQ74FGfL36d/vlLCdDbjo5fZsGEETu0e37c2kyPxYepyeB/Ej31baTYS5sbto2XsfZTkktSfyg7KkcV9 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR01MB6328 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768076387432118361?= X-GMAIL-MSGID: =?utf-8?q?1768076387432118361?= 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 Reviewed-by: James Morse --- Changes since v2: - Dropped the patch fiddling with the sdei conduit. v2 Link: https://lore.kernel.org/linux-arm-kernel/20230329202519.6110-1-scott@os.amperecomputing.com/ Changes since v1: - Store the active SDEI event being handled per-cpu, use the per-cpu active handler information to know when to abort. - Add prints before attempting to abort sdei handlers. v1 Link: https://lore.kernel.org/linux-arm-kernel/20230204000851.3871-1-scott@os.amperecomputing.com/ arch/arm64/include/asm/sdei.h | 8 ++++++++ arch/arm64/kernel/entry.S | 25 +++++++++++++++++++++++++ arch/arm64/kernel/sdei.c | 3 +++ arch/arm64/kernel/smp.c | 27 +++++++++++++++++++++++---- 4 files changed, 59 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/sdei.h b/arch/arm64/include/asm/sdei.h index 4292d9bafb9d..dc2f038a61ef 100644 --- a/arch/arm64/include/asm/sdei.h +++ b/arch/arm64/include/asm/sdei.h @@ -17,6 +17,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 + extern unsigned long sdei_exit_mode; /* Software Delegated Exception entry point from firmware*/ @@ -29,6 +34,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 ab2a6e33c052..e49f72b5fb63 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -1007,6 +1007,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 @@ -1072,6 +1078,13 @@ SYM_CODE_START(__sdei_asm_handler) ldr_l x2, sdei_exit_mode + 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] + alternative_if_not ARM64_UNMAP_KERNEL_AT_EL0 sdei_handler_exit exit_mode=x2 alternative_else_nop_endif @@ -1082,4 +1095,16 @@ 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 + ldr_l x2, sdei_exit_mode + sdei_handler_exit exit_mode=x2 + // 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 830be01af32d..255d12f881c2 100644 --- a/arch/arm64/kernel/sdei.c +++ b/arch/arm64/kernel/sdei.c @@ -47,6 +47,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..ea1595b51590 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)