mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ada Couprie Diaz <ada.coupriediaz@arm.com>
To: linux-arm-kernel@lists.infradead.org,
	Will Deacon <will@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Catalin Marinas <catalin.marinas@arm.com>
Cc: Vladimir Murzin <vladimir.murzin@arm.com>,
	Marc Zyngier <maz@kernel.org>, Kiryl Shutsemau <kas@kernel.org>,
	Breno Leitao <leitao@debian.org>,
	Jinjie Ruan <ruanjinjie@huawei.com>,
	Doug Anderson <dianders@chromium.org>,
	Linus Walleij <linusw@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Huth <thuth@redhat.com>, Dawei Li <dawei.li@linux.dev>,
	mrigendrachaubey <mrigendra.chaubey@gmail.com>,
	kernel-team@meta.com, linux-kernel@vger.kernel.org,
	Ada Couprie Diaz <ada.coupriediaz@arm.com>,
	stable@vger.kernel.org
Subject: [PATCH 1/3] arm64: entry: sdei: always set VBAR_EL1 on SDEI entry
Date: Tue, 17 Nov 2026 17:48:12 +0000	[thread overview]
Message-ID: <20261117174814.95936-2-ada.coupriediaz@arm.com> (raw)
In-Reply-To: <20261117174814.95936-1-ada.coupriediaz@arm.com>

SDEI can interrupt at any time, so we cannot guarantee that VBAR_EL1
points to the kernel vectors.
Unconditionally set VBAR_EL1 to the kernel vectors on SDEI entry so
the SDEI handler always runs on the correct vectors.

Commit 9bf6ee7952c7 ("arm64: sdei: Run the event handler on the kernel
vectors") sets VBAR_EL1 to the kernel vectors when KPTI is on
and it still points to the trampoline vectors.

This is only covers the KPTI case, as any other VBAR_EL1 value would
not be changed, while pointing to the wrong exception vectors.
KVM in VHE mode would be such a case as, in VHE, VBAR_EL1 is an alias for
VBAR_EL2, which KVM uses for the hypervisor vectors when running guests.

Fixes: 79e9aa59dc29 ("arm64: sdei: Add trampoline code for remapping the kernel")
Cc: stable@vger.kernel.org
Cc: Kiryl Shutsemau (Meta) <kas@kernel.org>
Cc: Breno Leitao <leitao@debian.org>
Signed-off-by: Ada Couprie Diaz <ada.coupriediaz@arm.com>
---
 arch/arm64/kernel/entry-common.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c
index beb56891fc4f..cb122163a68d 100644
--- a/arch/arm64/kernel/entry-common.c
+++ b/arch/arm64/kernel/entry-common.c
@@ -1079,19 +1079,22 @@ __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg)
 	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
-	 * handle exceptions from EL0: an exception taken here would run their
-	 * empty current-EL half and never come back. Switch to the kernel
-	 * vectors. The IRQ-like resume keeps using the interrupted VBAR, so it
-	 * still goes through the trampoline.
+	 * As an SDEI event can take over at any point, VBAR_EL1 might not allow
+	 * us to take an exception safely :
+	 * - With KPTI, VBAR_EL1 holds the trampoline vectors from the return to
+	 *   EL0 until the next exception from EL0 maps the kernel. They only
+	 *   handle exceptions from EL0: an exception taken here would run their
+	 *   empty current-EL half and never come back ;
+	 * - With VHE, the kernel runs at EL2 and VBAR_EL1 accesses VBAR_EL2.
+	 *   KVM might be running a guest and switched VBAR_EL2 to the
+	 *   hypervisor vectors.
+	 *
+	 * Switch to the kernel vectors unconditionally and restore
+	 * the interrupted VBAR_EL1 before returning.
 	 */
 	vbar = read_sysreg(vbar_el1);
-	if (arm64_kernel_unmapped_at_el0() &&
-	    vbar == (unsigned long)raw_cpu_read(this_cpu_vector)) {
-		write_sysreg((unsigned long)vectors, vbar_el1);
-		isb();
-	}
+	write_sysreg((unsigned long)vectors, vbar_el1);
+	isb();
 
 	state = irqentry_nmi_enter(regs);
 	ret = do_sdei_event(regs, arg, vbar);
-- 
2.43.0


  reply	other threads:[~2026-11-17 17:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 17:48 [PATCH 0/3] arm64: sdei: fix entry edge cases, pseudo-NMI Ada Couprie Diaz
2026-11-17 17:48 ` Ada Couprie Diaz [this message]
2026-11-17 17:48 ` [PATCH 2/3] arm64: entry: sdei: save and restore PMR for pseudo-NMI Ada Couprie Diaz
2026-11-18  9:58   ` Vladimir Murzin
2026-11-17 17:48 ` [PATCH 3/3] arm64: head: set __entry_task along with task setup Ada Couprie Diaz
2026-11-18 11:01   ` Vladimir Murzin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261117174814.95936-2-ada.coupriediaz@arm.com \
    --to=ada.coupriediaz@arm.com \
    --cc=catalin.marinas@arm.com \
    --cc=dawei.li@linux.dev \
    --cc=dianders@chromium.org \
    --cc=kas@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=leitao@debian.org \
    --cc=linusw@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=mrigendra.chaubey@gmail.com \
    --cc=peterz@infradead.org \
    --cc=ruanjinjie@huawei.com \
    --cc=stable@vger.kernel.org \
    --cc=thuth@redhat.com \
    --cc=vladimir.murzin@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®