Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C7AA606A32C for ; Mon, 30 Nov 2026 15:57:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=YTdtrfBU; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=bCFbD4KZ DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=nbvcPzJpdQ3i3lwnp1nmcAIKuxLWFW9dgQEmp9PZVI8=; b=YTdtrfBUpXd6Wb w+sCuVjNzPVdfw4cCkgJWZiU5g8/tdM6wUxG3YU7PElihHfN+o3mnqCXo/FIXZi4+lP7n01kfxqOh ij9QM7lmdWPfo+2+yt18dFqacGviOBxuyS5fUSW8HcwSClYRjq2qWQh/kkoP9XfG0T5/VHX+kjwL3 jfH9HqQIxXTFrc1sv6CoSBs55YAbm+IguGtgyFDnx0JEk1phZD7LmHAN8DJBlkuUxltWu2JSpUUcF QaTgBBXhOFVMLNamPbbxcjmKpbzvvMwTPh1cQgmPWX5QUNIgqlxgWkLY6A2w4e70RFF2LNkPx1N5/ VGVsf0omuZ+wznU9qrig==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY3ku-000000057GG-3cEO; Mon, 30 Nov 2026 15:57:28 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY3kC-000000056e8-2fAo for linux-arm-kernel@lists.infradead.org; Mon, 30 Nov 2026 15:56:49 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 648121655; Mon, 30 Nov 2026 07:56:41 -0800 (PST) Received: from login2.euhpc2.arm.com (login2.euhpc2.arm.com [10.58.100.22]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7D6093F86F; Mon, 30 Nov 2026 07:56:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796054204; bh=/M3Oy6LgnWdsv07z+3saosdua8JxuWJuT6u8kX5oYSg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bCFbD4KZURy2N2vbTle9pn6NKlbD9FRAM/fK6J2pSvsvCSKz7YLxxLV+Eu15AIYum dkyv612tKfFpR0CWHEuWUe1f2yIGU+RiON+7P4yyK2jzVG1BJ3/dd9FZUsmJxMjCYr 7f8w6gpDQlKW4bhf6lfKVtfNclrjKuwcsRi3j82U= From: Vladimir Murzin To: linux-arm-kernel@lists.infradead.org Cc: catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, lpieralisi@kernel.org, ruanjinjie@huawei.com, liaochang1@huawei.com, ashok.raj@oss.qualcomm.com, maz@kernel.org, kas@kernel.org Subject: [PATCH v3 31/44] arm64: nmi: Add handling of superpriority interrupts as NMIs Date: Mon, 30 Nov 2026 15:54:53 +0000 Message-Id: <20261130155506.118408-32-vladimir.murzin@arm.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20261130155506.118408-1-vladimir.murzin@arm.com> References: <20261130155506.118408-1-vladimir.murzin@arm.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261130_075644_766696_46A413E3 X-CRM114-Status: GOOD ( 19.89 ) X-Spam-Score: -4.4 (----) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 From: Mark Brown Our goal with superpriority interrupts is to use them as NMIs, taking advantage of the much smaller regions where they are masked to allow prompt handling of the most time-critical interrupts. When an interrupt is configured with superpriority, we enter EL1 as we do for any other interrupt. The presence of a superpriority interrupt is indicated by a status bit in ISR_EL1. We check this bit before unmasking interrupts in elX_interrupt(), and if a superpriority interrupt is pending, we handle it as an NMI. Otherwise, normal interrupts are handled as usual. Since superpriority interrupts are always handled as NMIs, the interrupt controller can rely on in_nmi() to distinguish them from ordinary interrupts. Enable IPIs to use superpriority interrupts as NMIs, matching the existing pseudo-NMI behaviour. Signed-off-by: Mark Brown Signed-off-by: Ada Couprie Diaz Signed-off-by: Vladimir Murzin Reviewed-by: Jinjie Ruan Tested-by: Jinjie Ruan --- arch/arm64/include/asm/entry-common.h | 7 +++ arch/arm64/kernel/entry-common.c | 83 +++++++++++++++++++++++---- arch/arm64/kernel/smp.c | 2 +- 3 files changed, 79 insertions(+), 13 deletions(-) diff --git a/arch/arm64/include/asm/entry-common.h b/arch/arm64/include/asm/entry-common.h index 73d82a8d8e95..078b9a6456d0 100644 --- a/arch/arm64/include/asm/entry-common.h +++ b/arch/arm64/include/asm/entry-common.h @@ -37,6 +37,13 @@ static inline bool arch_irqentry_exit_need_resched(void) if (system_uses_irq_prio_masking() && read_sysreg(daif)) return false; + /* + * If AllInt is set then we must have handled an NMI, so skip + * preemption + */ + if (system_uses_nmi() && (read_sysreg_s(SYS_ALLINT) & ALLINT_ALLINT)) + return false; + /* * Preempting a task from an IRQ means we leave copies of PSTATE * on the stack. cpufeature's enable calls may modify PSTATE, but diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c index ec7edb8790d5..1a2119f8ac11 100644 --- a/arch/arm64/kernel/entry-common.c +++ b/arch/arm64/kernel/entry-common.c @@ -33,6 +33,14 @@ #include #include +static __always_inline bool is_nmi(void) +{ + if (!system_uses_nmi()) + return false; + + return !!(read_sysreg(isr_el1) & ISR_EL1_IS); +} + /* * Where the context being returned to had an active percpu GPR critical * section, ensure that the offset and address GPRs are updated to match the @@ -564,8 +572,8 @@ asmlinkage void noinstr el1h_64_sync_handler(struct pt_regs *regs) arm64_debug_exc_context(CRITICAL_CONTEXT); } -static __always_inline void __el1_pnmi(struct pt_regs *regs, - void (*handler)(struct pt_regs *)) +static __always_inline void __el1_nmi(struct pt_regs *regs, + void (*handler)(struct pt_regs *)) { arm64_exc_hwstate_t hwstate; irqentry_state_t state; @@ -584,7 +592,23 @@ static __always_inline void __el1_irq(struct pt_regs *regs, state = arm64_enter_from_kernel_mode(regs); - arm64_unmask_exc_context(NONMI_CONTEXT); + /* + * For non-NMI systems, we can switch to NOIRQ context since + * NMIs cannot occur. + * + * For pseudo-NMI, we must keep NONMI context until we can + * determine the interrupt priority, which is done by the IRQ + * handler. + * + * For FEAT_NMI, we already know the interrupt is an IRQ, so we + * can switch to NOIRQ context immediately. NMIs do not + * interfere because they follow a separate handling path and do + * not share the IRQ handling state. + */ + if (system_uses_irq_prio_masking()) + arm64_unmask_exc_context(NONMI_CONTEXT); + else + arm64_unmask_exc_context(NOIRQ_CONTEXT); irq_enter_rcu(); do_interrupt_handler(regs, handler); @@ -604,8 +628,9 @@ static __always_inline void __el1_irq(struct pt_regs *regs, static void noinstr el1_interrupt(struct pt_regs *regs, void (*handler)(struct pt_regs *)) { - if (IS_ENABLED(CONFIG_ARM64_PSEUDO_NMI) && regs_irqs_disabled(regs)) - __el1_pnmi(regs, handler); + /* Is there a NMI to handle? */ + if (regs_irqs_disabled(regs) || is_nmi()) + __el1_nmi(regs, handler); else __el1_irq(regs, handler); @@ -619,6 +644,8 @@ asmlinkage void noinstr el1h_64_irq_handler(struct pt_regs *regs) asmlinkage void noinstr el1h_64_fiq_handler(struct pt_regs *regs) { + WARN_ON_ONCE(system_uses_nmi() && (read_sysreg(isr_el1) & ISR_EL1_FS)); + el1_interrupt(regs, handle_arch_fiq); } @@ -942,20 +969,36 @@ asmlinkage void noinstr el0t_64_sync_handler(struct pt_regs *regs) arm64_debug_exc_context(CRITICAL_CONTEXT); } -static void noinstr el0_interrupt(struct pt_regs *regs, - void (*handler)(struct pt_regs *)) +static __always_inline void __el0_nmi(struct pt_regs *regs, + void (*handler)(struct pt_regs *)) { - arm64_enter_from_user_mode(regs); + irqentry_state_t state; + arm64_exc_hwstate_t hwstate; - arm64_unmask_exc_context(NONMI_CONTEXT); + state = irqentry_nmi_enter(regs); + hwstate = arm64_unmask_exc_context(NONMI_CONTEXT); + do_interrupt_handler(regs, handler); + arm64_mask_exc_context(hwstate); + irqentry_nmi_exit(regs, state); +} - if (regs->pc & BIT(55)) - arm64_apply_bp_hardening(); +static __always_inline void __el0_irq(struct pt_regs *regs, + void (*handler)(struct pt_regs *)) +{ + arm64_enter_from_user_mode(regs); + /* + * For the same reason as in el1_irq() keep NONMI + * context for pesudo-NMI, and switch to NOIRQ + * otherwise + */ + if (system_uses_irq_prio_masking()) + arm64_unmask_exc_context(NONMI_CONTEXT); + else + arm64_unmask_exc_context(NOIRQ_CONTEXT); irq_enter_rcu(); do_interrupt_handler(regs, handler); irq_exit_rcu(); - /* * For the same reason as in el1_irq() we effectivly * have NOIRQ_CONTEXT on return from handler - keep @@ -963,6 +1006,20 @@ static void noinstr el0_interrupt(struct pt_regs *regs, */ arm64_debug_exc_context(NOIRQ_CONTEXT); arm64_exit_to_user_mode(regs, arm64_exc_hwstate_of_context(NOIRQ_CONTEXT)); +} + +static void noinstr el0_interrupt(struct pt_regs *regs, + void (*handler)(struct pt_regs *)) +{ + if (regs->pc & BIT(55)) + arm64_apply_bp_hardening(); + + /* Is there a NMI to handle? */ + if (is_nmi()) + __el0_nmi(regs, handler); + else + __el0_irq(regs, handler); + arm64_debug_exc_context(CRITICAL_CONTEXT); } @@ -978,6 +1035,8 @@ asmlinkage void noinstr el0t_64_irq_handler(struct pt_regs *regs) static void noinstr __el0_fiq_handler_common(struct pt_regs *regs) { + WARN_ON_ONCE(system_uses_nmi() && (read_sysreg(isr_el1) & ISR_EL1_FS)); + el0_interrupt(regs, handle_arch_fiq); } diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index 2606e382f464..d78a441dcb5f 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -1081,7 +1081,7 @@ static void smp_cross_call(const struct cpumask *target, unsigned int ipinr) static bool ipi_should_be_nmi(enum ipi_msg_type ipi) { - if (!system_uses_irq_prio_masking()) + if (!system_uses_nmi() && !system_uses_irq_prio_masking()) return false; switch (ipi) { -- 2.34.1