From patchwork Sat Feb 4 00:08:51 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: 13128540 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 4603EC05027 for ; Sat, 4 Feb 2023 00:10:40 +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=k7/D3Ho9Mkfq2mY0yAW7VQrdI8pPXQa9qxz3YTkJows=; b=HZKUyYsmgZ+guL w8Ll9OnUnyMNjgn1+SHLDeVwYmph6RtWjhfN82MGyWXR/MW10dWh8EDN60ywN3bpL9vg05TBGBNL2 vnvpcFAsE21v7jnE3o6dD0bTwl1rxmtRnYRVsNwcS5dIU6CObeNy3qQ64/qt49wErExsShYK3QMA7 cF0Lqw2eKN/YI05IM+cJfEnL+13OV/F2yOpOy9xa/+klAQ2u5S2dBUK4M0NrJ9ogJ3Q5vTmITX6O7 bbt+J57d5yzaT3AmOy0YI5e7EH+M5i03eZR8N4aWtpa7+domWH0cM53OQWjBoqIPNsdtqv/ppwf/C g5Lnv2ZrWzUQu/kNDzIg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pO67S-0045Sa-EM; Sat, 04 Feb 2023 00:09:26 +0000 Received: from mail-bn1nam02on20707.outbound.protection.outlook.com ([2a01:111:f400:7eb2::707] helo=NAM02-BN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pO67P-0045S7-AT for linux-arm-kernel@lists.infradead.org; Sat, 04 Feb 2023 00:09:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ucb9Z/GvN5IvecpxUV92EIk64Y2SAFIGWMDrw08dM8p0kznwdsbm9sE/GU2a4Bwmh0VkvuyJ5q2uXayJy5M2SdI+wpKNNJPBxLNvi7JocVM+m75Pjgkvu/IF7ZKI7XhyCGJZVwCwBWUIEtwH91jDLIuWU0geogKfgBvKc95ecogtTxJb2kUy7DfwtbsErKN6VFvzRlHo/HTJ8qeipHnVq7LQL/UsEqlK2zh81I78C5f563D9+dVi/iOcRoSqvBwE/smJTYArarBMeqfjrQdo1ApOTvz6XPgaVsStiU53F3AcKMnrIAfJrIDJajj+uroqZXCN3errTFIRJ/3Ibnfu8Q== 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=fSx4suMbPk3CTNA4L8V1Vn0//gAkdZVUDJmZgq2ZYzM=; b=K7l5v2Cxh4zUuQzwHsIHieG2+HeQ82Jkbg+9ZH5YJNCdlls2Gxvf66/m6d3tA6dVhxYrzBmzqgvzWzsrzOmNvV5gblU6s50WO/1mleu7Lm4S+hkjrBVeXgJ73tLy8eNwM9VjgaeLeqPt8KKc1vFPSVQoSQcopqY4wZLehlZ1wyp5y09AR7+VS6ebpDl8rzcNG0ABcC3bJMzSpkEOtExlx4d3UiAzHJgmvORR7W+UnxeEGqT9AmfpaTJCH8mB0JVcTfDODgwm3HjiMCO7ZSDmQrADkfei8aDYsy8OXQImDgUUHSEVN1TCUD/0iVBb391XdaQHwLeqpl1XkoHStcKhvw== 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=fSx4suMbPk3CTNA4L8V1Vn0//gAkdZVUDJmZgq2ZYzM=; b=SP3xKYrA1jBRWgYmKTZw9UiiKRAN8VlpBR/VTSZ1BUeKFsxxe5RCXatMAEtSqoUoy6ElVR8/m8VP6yDfgU9a/eYs44zty7K1Aw54rmZOBoWuim+zUnLSqVqelC6JyAeusfEqaFVwtu0/hKnt8/BynH8rzo6lhzt2TpvhnnCEk8k= 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 CY4PR01MB2279.prod.exchangelabs.com (2603:10b6:903:23::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.38; Sat, 4 Feb 2023 00:09:15 +0000 Received: from MWHPR0101MB2893.prod.exchangelabs.com ([fe80::f612:13b6:49b7:d81e]) by MWHPR0101MB2893.prod.exchangelabs.com ([fe80::f612:13b6:49b7:d81e%3]) with mapi id 15.20.6043.022; Sat, 4 Feb 2023 00:09:15 +0000 From: D Scott Phillips To: linux-arm-kernel@lists.infradead.org Cc: Catalin Marinas , Will Deacon , James Morse Subject: [PATCH] arm64: abort SDEI handlers during crash Date: Fri, 3 Feb 2023 16:08:51 -0800 Message-Id: <20230204000851.3871-1-scott@os.amperecomputing.com> X-Mailer: git-send-email 2.39.1 X-ClientProxiedBy: CH0PR13CA0023.namprd13.prod.outlook.com (2603:10b6:610:b1::28) To MWHPR0101MB2893.prod.exchangelabs.com (2603:10b6:301:33::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR0101MB2893:EE_|CY4PR01MB2279:EE_ X-MS-Office365-Filtering-Correlation-Id: 8938c74c-4910-4100-b75a-08db06440ce3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fpP5VrFYagDGjizBvA6dIzFm0JoovUmPNmzcTRTDuEg2HIYm+V/eJuZ+HbjY3m8pi7R9R5q/BJxx4RCrBY34N3yEZORaCEkHMpw0hoR9IquM9erWURQstim+8Gj+HJKh1TU1girTx7YyW3fAGCCXesPLrxQFiHXOfWarMOfdG9fDBBEJFIdq41Nn9Q/LqK3FyFCHT8ebVrutL38xIAMTHzF0WN0nJJrQiDiuJOUr7eZzXynbKb5okwHqD/pYIRPdWTK9g/cefFlk10XVagJt83ayR7LncVNzUcyrB7LCO1/TmXWkoNpYrLzzWc9GQUym1t8diTF0UeeQZhWUnYhe4LRvA4E/AIUpJGBV6LGoOqYO4Gz2Q9YAnZqR/kNawfru/9HEkYaCRA+lvAvlOpsQIWP5j1zuGWKPm8sOPLQqCEZTuXsVEob06XPHInMfuY3pHgQJ7k12HhHFpyocFZt3tvBRSIbeZViCFtK05X2IDt6MxqkWXifEYEbHPj7OGmD+qSeH+8fuk3zbYGnsfjrK0UC2/V72oRLek6XnHx5R+lglcfhMrf/4Po0XKXKjXbRVSyh/RYB7PTla+MezJ7wxOMDpdvWnIDhlFjoPvj6CnaRwkYBMQ+9WJSCLaoz09XBcPOs4GeUri82gSG5yqAma0Z56Itjtvx670QjyHyt3MMy0eTZqt7tMaXANRqOEay/2ymKjCW3Ux1+aL9t2fE/y3Q== 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:(13230025)(4636009)(376002)(366004)(39850400004)(136003)(396003)(346002)(451199018)(1076003)(6512007)(83380400001)(186003)(26005)(6506007)(6666004)(5660300002)(38350700002)(38100700002)(2906002)(8676002)(4326008)(6916009)(66476007)(66556008)(66946007)(316002)(54906003)(8936002)(41300700001)(6486002)(52116002)(478600001)(86362001)(2616005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Fs4hL2VBNHFS02/LEmwA4VL3pTyVKgJC7dJt4jlhdUeEIK4iZvY4n5wc8xn+vVV7i4z6ep/Ze3v9g8DigtjYDIzmBoZob08hvnettYAXt8hbVto0qm6gQdpXpJs1xuK3OZjAdVDsKOq1xiD4u/nAdVSIsgYKgfig8jsjzqRei46eEtYzI7/hcvj8/PBPwnQGVpB646cR/r1y+VCjtHT2GSeXX0ecjg3AN3CDnmHBugwvzbMsmjR3Wv/tfBsRAI6Iq9Pitb63zZF0XVjz54fFqWZuBTPjCdBuC7Z74KP8YK6fjIlxEIDUk0NtdBAzJM12wPP/PT3X18E9usvUjUXZ7Th8BpbVH/x01+mCoTjgrPv2W7TCCraLlY5xSSg/oS+GIo8UwdbyJEO9h3rRox4O9pMkBIBDYF4LeE6rlAb2LrOPMygMLpRZDr16lSQBcE+5rwYIMb0L+SaGjs90OtO7OBwcCpzsC5Mbh6yx0IB3SRZPXLJC2bonAW4iQ9T6zUDGt0EjxqVRDZqhAtqJxMvBokBnMXl786X06hDh5iew2AVS0/EUQUBF49qgO8u6Z0HyqWrGOrwmAxDSeHnrobyxTpIkYF8t8MOVY2RQsHrxTGjqdmJUYWk/2euvU6dTQ2LHED0/K6UTsgUfQIzZSg2gLQ02Jxtt+Wl0aT1bpkQEIfaupaufMw6pa1fBGLyonRZ8tU3z/Yxr5QTa5ql9jg62kC/uOgOyzhyhNui4QI4p/E27gsPNxLnk70mrcXzP3cXg1yRbZ/o50fbYPC8o6zUSgxi2OfeZx5nq108YAneb6hEXZCOWe/aRNjAKogeLEHc99YziT9IXeThBF6JDEKLYFOLcFO2Vx39GJy71q1Kh83T7P5b2yMGTCqE1ZD8GVMpNXbmxqX91ZT/wrqtaOn1OZuRj0xJHxqyRzNh0CEVU2WUvRpT/WD27TksQbyV8CeKU6sGKssrKtYKt9FWFCOxqoHeuwgSEXmeHE+t8quhf+mFHngfdUvZICboEDlyZp7ef+HI849TZtGKmTBlJuMZD6VYKvgcRj53lVG1aQkk8SXyQzuSg6ZaTXyJYbWrasuuDBvh7VvS3iWLRYvNAdBNoLCHD8ym3yLxWmJWAwcwySN8SM/MIOF4Y8t3BcLYKV+z789rm8dfRnlX9fYmal/1LhH5Ze7acaskw2q18a/b6VhihvZgSomFDS3aZE3dVjY/Vyzp98DFTO6BCreargCS+QLqz5RF4G1VGaV+KEchcFN5PUllGJENkuHy4TWLlJiWmm7wmSDEjU405tqw/gZqOr/UuVIdg9Ms/fBk8p+IQnKS3svduDF4j0hbMcwMfsk2FEgKIKabUjq9DrST87v0NGcwAR9wqMeYH1N7QFuR0kng9XROCeAnECfW0QMrXfQGCa1C27AvKyrd7H1MUb7x4s+TP89h8JJr5RR1X/yP5ig+Q88fM2QaOByAxM/K+0eZ57nwGhVpdca1Me2R2pjw18C2DarldaTQUxBXs2Niqi8nm3/KydrLvwrTOtDQZ9JB/Hu6oryWU7WLYzHY0Bb643qg/kS6J6nwydNn9QSFYNZxYK53ucMLbH1o1mKG87BNc875hhVnKDqhlBy8AHGZD1HHAZ69U0YSdFkIZVjwjTL0= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8938c74c-4910-4100-b75a-08db06440ce3 X-MS-Exchange-CrossTenant-AuthSource: MWHPR0101MB2893.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2023 00:09:15.0443 (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: fbHrkxFvTAm6aYls/vj0nMq0mL/8C/XpTC7/JmTn1Xecf8OGRX9veeBD4WdAj+13K7HkxpATVd5PO4/cxTNx7Ne8ih47JiD0gFqnt77DoPYQXQovpqMmqsN4ppzwVwov X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR01MB2279 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230203_160923_612768_DE44D303 X-CRM114-Status: GOOD ( 17.81 ) 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. Try two COMPLETE_AND_RESUMEs in case both a normal and critical event were being handled. Fixes: f5df26961853 ("arm64: kernel: Add arch-specific SDEI entry code and CPU masking") Signed-off-by: D Scott Phillips Tested-by: Mihai Carabas --- arch/arm64/include/asm/sdei.h | 3 +++ arch/arm64/kernel/entry.S | 24 +++++++++++++++++++++--- arch/arm64/kernel/smp.c | 14 ++++++++++---- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/sdei.h b/arch/arm64/include/asm/sdei.h index 4292d9bafb9d..1030568db7d3 100644 --- a/arch/arm64/include/asm/sdei.h +++ b/arch/arm64/include/asm/sdei.h @@ -29,6 +29,9 @@ asmlinkage void __sdei_asm_entry_trampoline(unsigned long event_num, unsigned long pc, unsigned long pstate); +/* End a possibly still 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 11cb99c4d298..03dc233bdaa1 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -909,13 +909,18 @@ NOKPROBE(call_on_irq_stack) #include #include -.macro sdei_handler_exit exit_mode - /* On success, this call never returns... */ +.macro sdei_handler_exit_fallthrough exit_mode cmp \exit_mode, #SDEI_EXIT_SMC b.ne 99f smc #0 - b . + b 100f 99: hvc #0 +100: +.endm + +.macro sdei_handler_exit exit_mode + sdei_handler_exit_fallthrough exit_mode=\exit_mode + /* On success, this call never returns... */ b . .endm @@ -1077,4 +1082,17 @@ 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_fallthrough exit_mode=x2 + // either fallthrough if not in handler context, or 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/smp.c b/arch/arm64/kernel/smp.c index ffc5d76cf695..bc1b3000197e 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,15 @@ 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(); + /* + * The crash may have happened in a critical event handler which + * preempted a normal handler. So at most we might have two + * levels of SDEI context to exit. + */ + sdei_handler_abort(); + sdei_handler_abort(); } bool smp_crash_stop_failed(void)