[PATCH v2 1/2] KVM: arm64: Don't forward the host's SDEI calls to firmware

Fuad Tabba fuad.tabba at linux.dev
Tue Nov 17 08:37:00 PST 2026


In protected mode, EL2 forwards host SMCs that it doesn't handle to
EL3, where they arrive as calls from EL2. TF-A treats EL2 as the SDEI
client whenever EL2 is implemented, so the host can register an event
handler that runs at EL2.

A pKVM host kernel can't use SDEI, since sdei_arch_get_entry_point()
fails when the kernel is booted at EL2 but runs at EL1. Return
NOT_SUPPORTED for SDEI calls instead of forwarding them.

Fixes: b93c17c4185bf ("KVM: arm64: Trap host SMCs in protected mode")
Signed-off-by: Fuad Tabba <fuad.tabba at linux.dev>
---
 arch/arm64/kvm/hyp/nvhe/hyp-main.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
index 179d7c8277b88..37fb9896ba3ad 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
@@ -10,6 +10,7 @@
 #include <hyp/switch.h>
 
 #include <linux/irqchip/arm-gic-v3.h>
+#include <uapi/linux/arm_sdei.h>
 #include <uapi/linux/psci.h>
 
 #include <asm/pgtable-types.h>
@@ -1647,8 +1648,14 @@ static void handle_host_hcall(struct kvm_cpu_context *host_ctxt)
 	cpu_reg(host_ctxt, 0) = SMCCC_RET_NOT_SUPPORTED;
 }
 
-static void default_host_smc_handler(struct kvm_cpu_context *host_ctxt)
+static void default_host_smc_handler(struct kvm_cpu_context *host_ctxt, u64 func_id)
 {
+	/* Firmware would enter the host's SDEI event handlers at EL2. */
+	if ((func_id & SDEI_1_0_MASK) == SDEI_1_0_FN_BASE) {
+		cpu_reg(host_ctxt, 0) = SMCCC_RET_NOT_SUPPORTED;
+		return;
+	}
+
 	trace_hyp_exit(host_ctxt, HYP_REASON_SMC);
 	__kvm_hyp_host_forward_smc(host_ctxt);
 	trace_hyp_enter(host_ctxt, HYP_REASON_SMC);
@@ -1675,7 +1682,7 @@ static void handle_host_smc(struct kvm_cpu_context *host_ctxt)
 	if (!handled)
 		handled = kvm_host_ffa_handler(host_ctxt, func_id);
 	if (!handled)
-		default_host_smc_handler(host_ctxt);
+		default_host_smc_handler(host_ctxt, func_id);
 
 exit_skip_instr:
 	/* SMC was trapped, move ELR past the current PC. */

base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
-- 
2.47.3




More information about the linux-arm-kernel mailing list