From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794274169; b=5aYt+277wveljJtFeKHu1PegOkhF+NWE85zqzxe28SVBakcCPJgrLCt3lRDmBLkdf0G8 qf1V2agMyAZ5V1JjMxZEwu1U12c46lmDuaqXhTdXD/I7tdLGne5bL9kao2ReisoaknqeS PU++E/3FiMj13tuT404Oxyj9cXt71TZOgfGB/BREB00kY45WKre5A76+DU8fEaTJYKulb ved/JZiUV5D9IbgwvezJ33aWyYdomvJeV6gvTwDvrcGz2nf+EklIb5es8VH+8Q5ivYLG6 TP7XWEivWDb5koFvB7cfx7zPUgHJ+4fRvNr7wgkQibH7UtASXYPXIyUs2LVP1yYcvzA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794274169; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=rR71C1xh+sDMOFt4y+MbtDLZ3qc2ruKpESlxjZ4hHMU=; b=lWMUGM0TVGfuGNurEoVNRkEtxnifff0j7KKGHsWSnxNbKXUbnVy2IkB2xy9IOySLjMd6 JPTd4kOK/PYRER01acZfo1gCw65teMpxj41qi01/kTMO77dEFACewhaO6y3SLBgxmIRu3 gRlz710NkO2F7aqx9SvWtomOjaA0ZblGwcAyBKfjU2plETgCjDmMx/9EU58R0J1//3IhH WBVmV5JAwZfKkcQgNd03ArVPgDM+Nj5vmU/Um9NLD2w/tRaPZUdGZkTQYjabBwz2lZeSO EsHGMIfME1nrN5nLSur5HEyR6cZxP81rwoVPVIhC0rgsjhhWv/IFddKIqHZKZOhFwpQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ggJ7G6OX; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BFF50606A31C for ; Tue, 10 Nov 2026 01:29:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ggJ7G6OX Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DEDD1F0089F; Tue, 10 Nov 2026 01:29:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794274168; bh=rR71C1xh+sDMOFt4y+MbtDLZ3qc2ruKpESlxjZ4hHMU=; h=From:To:Cc:Subject:Date; b=ggJ7G6OX5yLVv6qNr6zuSVPEwc09dT9bBMwr5uhYL1FBba0FDMaI9wFpW65ERfQ+C 4YoHZ+MP9rmGs5P7gkfB3GJW84eX9+bXDowQGXnkNIp/yq0MY7XSHwsL3TWHQw5zQK wcpKOiiXDOlDH0Yoldvrer9ulfejxD6W+UTHq+rUf7bRVtMUQaTqb7lWTMH77by/YM 1oWtrX5eCtMdNmEK5eGROPY4h3dzYR3wzqtFAJ6ifNLBMVp2SgfWoH5S6d4lxNoTnI k1JKu9WgVHJDgKE9SyrYBW+Xa4Xn2Bq65YAop0tfZO+MeehDEFzJXlGLnDaYkCcaMQ VcNKYE+uFbGWw== From: Sasha Levin To: kas@kernel.org, leitao@debian.org, catalin.marinas@arm.com Cc: stable@vger.kernel.org Subject: FAILED: patch "[PATCH] arm64: sdei: Preserve the interrupted context's exception registers" failed to apply to 5.10-stable tree Date: Mon, 9 Nov 2026 20:29:26 -0500 Message-ID: <20261109202926-failed-5.10-58c1eb84e977@kernel.org> X-Mailer: git-send-email 2.53.0 X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The patch below does not apply to the 5.10-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y git checkout FETCH_HEAD git cherry-pick -x 58c1eb84e97701c583605ba2fd553b69afba2245 # git commit -s git send-email --to '' --in-reply-to '20261109202926-failed-5.10-58c1eb84e977@kernel.org' --subject-prefix 'PATCH 5.10.y' 'HEAD^..' Thanks, Sasha ------------------ original commit in Linus's tree ------------------ >From 58c1eb84e97701c583605ba2fd553b69afba2245 Mon Sep 17 00:00:00 2001 From: "Kiryl Shutsemau (Meta)" Date: Thu, 5 Nov 2026 12:08:34 +0000 Subject: [PATCH] arm64: sdei: Preserve the interrupted context's exception registers An SDEI event is dispatched by firmware regardless of PSTATE.DAIF, so it can interrupt the kernel where the exception registers are live: - exception entry, before kernel_entry has saved ELR_EL1/SPSR_EL1 and before the C handler has read ESR_EL1/FAR_EL1; - exception return, after kernel_exit has loaded ELR_EL1/SPSR_EL1 and before the ERET. An IRQ or pseudo-NMI cannot arrive there with PSTATE.I set. Firmware saves only x0-x17, PC and PSTATE around an SDEI event, so a synchronous exception taken by the handler overwrites the interrupted context's ELR, SPSR, ESR and FAR. do_sdei_event() only notices that ELR changed, and warns. The interrupted context then carries on with the handler's state. A task interrupted on its way into the kernel can be sent SIGILL for the handler's kernel data abort. A task interrupted on its way back to user space ERETs to EL1, at the handler's fixup address, with user registers loaded. With SDEI delivering NMI backtraces, this happens in normal operation. The handler runs show_regs(), which reads through possibly-NULL pointers with the _nofault() accessors. print_worker_info() faults this way for a kworker that is not running a work item, and a single sysrq-l warned once per such kworker. Save ELR, SPSR, ESR and FAR in __sdei_handler() before irqentry_nmi_enter(), which can take an exception too, and restore them after irqentry_nmi_exit(). Once they are restored, a nested exception is harmless if its handler is safe in NMI context. That holds for EL1 data aborts on translation, permission and access-flag faults, which never take the mmap lock in NMI context, and for BRK. Warn once, with the syndrome, about any other exception class. Fixes: f5df26961853 ("arm64: kernel: Add arch-specific SDEI entry code and CPU masking") Cc: stable@vger.kernel.org Signed-off-by: Kiryl Shutsemau (Meta) Tested-by: Breno Leitao Signed-off-by: Catalin Marinas --- arch/arm64/kernel/entry-common.c | 21 ++++++++++++- arch/arm64/kernel/sdei.c | 53 ++++++++++++++++++++++++++------ 2 files changed, 64 insertions(+), 10 deletions(-) diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c index 36b85b9e1575d..beb56891fc4fa 100644 --- a/arch/arm64/kernel/entry-common.c +++ b/arch/arm64/kernel/entry-common.c @@ -1041,7 +1041,7 @@ asmlinkage void noinstr __noreturn handle_bad_stack(struct pt_regs *regs) asmlinkage noinstr unsigned long __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg) { - unsigned long vbar; + unsigned long elr, spsr, esr, far, vbar; irqentry_state_t state; unsigned long ret; @@ -1067,6 +1067,17 @@ __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg) else if (cpu_has_pan()) set_pstate_pan(0); + /* + * Nothing saved the interrupted context's exception registers on the + * way in, and it may be in the middle of exception entry or return + * (SDEI ignores DAIF). Save them before anything can take an exception + * and overwrite them. + */ + elr = read_sysreg(elr_el1); + spsr = read_sysreg(spsr_el1); + esr = read_sysreg(esr_el1); + far = read_sysreg(far_el1); + /* * With KPTI, VBAR_EL1 holds the trampoline vectors from the return to * EL0 until the next exception from EL0 maps the kernel. They only @@ -1086,6 +1097,14 @@ __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg) ret = do_sdei_event(regs, arg, vbar); irqentry_nmi_exit(regs, state); + /* + * Put them back unconditionally. An unchanged ELR does not rule out a + * nested exception: one may have returned to the same address. + */ + write_sysreg(elr, elr_el1); + write_sysreg(spsr, spsr_el1); + write_sysreg(esr, esr_el1); + write_sysreg(far, far_el1); write_sysreg(vbar, vbar_el1); return ret; diff --git a/arch/arm64/kernel/sdei.c b/arch/arm64/kernel/sdei.c index 260c13106009c..1b902da8ba43c 100644 --- a/arch/arm64/kernel/sdei.c +++ b/arch/arm64/kernel/sdei.c @@ -195,6 +195,31 @@ unsigned long sdei_arch_get_entry_point(int conduit) return 0; } +/* + * Exceptions an SDEI handler may take without harm once __sdei_handler() has + * restored the interrupted context's exception registers. Their handlers are + * safe in NMI context: + * - EL1 data aborts on translation, permission and access-flag faults: + * faulthandler_disabled() is true in NMI context, so do_page_fault() never + * takes the mmap lock. This covers the _nofault() accessors used by the + * generic dump_stack()/show_regs() code (e.g. print_worker_info()). + * - BRK: kprobes, WARN/BUG, kCFI and UBSAN traps, all NMI-capable. + * Anything else taken at EL1 is fatal on its own, or unexpected here. + */ +static bool sdei_nested_exception_ok(unsigned long esr) +{ + switch (ESR_ELx_EC(esr)) { + case ESR_ELx_EC_DABT_CUR: + return esr_fsc_is_translation_fault(esr) || + esr_fsc_is_permission_fault(esr) || + esr_fsc_is_access_flag_fault(esr); + case ESR_ELx_EC_BRK64: + return true; + default: + return false; + } +} + /* * do_sdei_event() returns one of: * SDEI_EV_HANDLED - success, return to the interrupted context. @@ -211,6 +236,7 @@ unsigned long __kprobes do_sdei_event(struct pt_regs *regs, int i, err = 0; int clobbered_registers = 4; u64 elr = read_sysreg(elr_el1); + u64 nested_elr, nested_esr, nested_far; u32 kernel_mode = read_sysreg(CurrentEL) | 1; /* +SPSel */ if (arm64_kernel_unmapped_at_el0()) @@ -223,18 +249,27 @@ unsigned long __kprobes do_sdei_event(struct pt_regs *regs, } err = sdei_event_handler(regs, arg); - if (err) - return SDEI_EV_FAILED; - if (elr != read_sysreg(elr_el1)) { - /* - * We took a synchronous exception from the SDEI handler. - * This could deadlock, and if you interrupt KVM it will - * hyp-panic instead. - */ - pr_warn("unsafe: exception during handler\n"); + /* + * A synchronous exception taken by the handler has overwritten the + * exception registers; __sdei_handler() puts them back. Only the last + * one's syndrome survives; report it if it is not one known to be + * harmless. + * + * If the event interrupted a KVM world switch, VBAR points at the KVM + * hyp vectors and any such exception is a hyp panic instead. + */ + nested_elr = read_sysreg(elr_el1); + nested_esr = read_sysreg(esr_el1); + nested_far = read_sysreg(far_el1); + if (nested_elr != elr && !sdei_nested_exception_ok(nested_esr)) { + pr_warn_once("unexpected exception during handler: ESR %#llx FAR %#llx near %pS\n", + nested_esr, nested_far, (void *)nested_elr); } + if (err) + return SDEI_EV_FAILED; + mode = regs->pstate & (PSR_MODE32_BIT | PSR_MODE_MASK); /* -- 2.53.0