public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] KVM: arm64: Inject UNDEF when host is executing an smc with imm16 != 0
@ 2026-03-24 13:57 Sebastian Ene
  2026-03-24 14:06 ` Vincent Donnefort
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Sebastian Ene @ 2026-03-24 13:57 UTC (permalink / raw)
  To: kvmarm, linux-arm-kernel, linux-kernel, android-kvm
  Cc: catalin.marinas, joey.gouly, mark.rutland, maz, oupton,
	sebastianene, suzuki.poulose, tabba, vdonnefort, will, yuzenghui

The ARM Service Calling Convention (SMCCC) specifies that the function
identifier and parameters should be passed in registers, leaving the
16-bit immediate field of the SMC instruction un-handled.
Currently, our pKVM handler ignores the immediate value, which could lead
to non-compliant software relying on implementation-defined behavior.
Enforce the host kernel running under pKVM to use an immediate value
of 0 by decoding the ISS from the ESR_EL2 and inject an undefined
instruction exception back to the caller.

Signed-off-by: Sebastian Ene <sebastianene@google.com>
---
 arch/arm64/kvm/hyp/nvhe/hyp-main.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
index e7790097db93..ff6a90a4a4c7 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
@@ -756,13 +756,18 @@ static bool handle_host_mte(u64 esr)
 void handle_trap(struct kvm_cpu_context *host_ctxt)
 {
 	u64 esr = read_sysreg_el2(SYS_ESR);
+	u16 imm16;
 
 	switch (ESR_ELx_EC(esr)) {
 	case ESR_ELx_EC_HVC64:
 		handle_host_hcall(host_ctxt);
 		break;
 	case ESR_ELx_EC_SMC64:
-		handle_host_smc(host_ctxt);
+		imm16 = esr & U16_MAX;
+		if (!imm16)
+			handle_host_smc(host_ctxt);
+		else
+			inject_undef64();
 		break;
 	case ESR_ELx_EC_IABT_LOW:
 	case ESR_ELx_EC_DABT_LOW:
-- 
2.53.0.983.g0bb29b3bc5-goog



^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-03-25 10:01 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-24 13:57 [PATCH] KVM: arm64: Inject UNDEF when host is executing an smc with imm16 != 0 Sebastian Ene
2026-03-24 14:06 ` Vincent Donnefort
2026-03-24 14:09   ` Vincent Donnefort
2026-03-24 14:18     ` Vincent Donnefort
2026-03-24 15:05       ` Sebastian Ene
2026-03-24 14:41   ` Sebastian Ene
2026-03-24 14:43 ` Marc Zyngier
2026-03-24 15:04   ` Sebastian Ene
2026-03-24 15:13 ` Fuad Tabba
2026-03-25 10:01   ` Sebastian Ene

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox