[PATCH 3/3] KVM: arm64: Don't run a protected vCPU that was caught in AArch32
From: Fuad Tabba
Date: Mon Nov 30 2026 - 09:45:08 EST
When a protected vCPU exits to EL2 in AArch32, EL2 fails the run and
clears VCPU_INITIALIZED on its copy of the vCPU to make the vCPU
invalid, but EL2 never reads that flag. The host's copy of the flag
remains set, so the next KVM_RUN runs the vCPU again.
Don't run a vCPU whose flag EL2 has cleared. pkvm_filter_vcpu_ioctl()
rejects KVM_ARM_VCPU_INIT for a protected vCPU that has run, so reword
the comment in fixup_guest_exit().
Fixes: be66e67f17509 ("KVM: arm64: Use the pKVM hyp vCPU structure in handle___kvm_vcpu_run()")
Signed-off-by: Fuad Tabba <fuad.tabba@xxxxxxxxx>
---
arch/arm64/kvm/hyp/nvhe/hyp-main.c | 4 ++++
arch/arm64/kvm/hyp/nvhe/switch.c | 7 +++----
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
index 179d7c8277b88..19509d460e06e 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
@@ -924,6 +924,10 @@ DEFINE_KVM_HOST_HCALL(int, __kvm_vcpu_run, struct kvm_vcpu __kern *, vcpu)
if (unlikely(system_supports_sme() && read_sysreg_s(SYS_SVCR)))
return ret;
+ /* Cleared by fixup_guest_exit() for a protected vCPU caught in AArch32. */
+ if (unlikely(!kvm_vcpu_initialized(&hyp_vcpu->vcpu)))
+ return ret;
+
/*
* ON has a single writer, pkvm_reset_vcpu() on this CPU, so
* READ_ONCE suffices. ON_PENDING takes the reset; -ECANCELED
diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c
index 89fb9dd351ad5..b69295f8c122d 100644
--- a/arch/arm64/kvm/hyp/nvhe/switch.c
+++ b/arch/arm64/kvm/hyp/nvhe/switch.c
@@ -262,10 +262,9 @@ static inline bool fixup_guest_exit(struct kvm_vcpu *vcpu, u64 *exit_code)
if (unlikely(vcpu_is_protected(vcpu) && vcpu_mode_is_32bit(vcpu))) {
/*
* As we have caught the guest red-handed, decide that it isn't
- * fit for purpose anymore by making the vcpu invalid. The VMM
- * can try and fix it by re-initializing the vcpu with
- * KVM_ARM_VCPU_INIT, however, this is likely not possible for
- * protected VMs.
+ * fit for purpose anymore by making the vcpu invalid. EL2
+ * can't run it again, and a protected vcpu that has run
+ * can't be re-initialized with KVM_ARM_VCPU_INIT.
*/
vcpu_clear_flag(vcpu, VCPU_INITIALIZED);
*exit_code &= BIT(ARM_EXIT_WITH_SERROR_BIT);
--
2.47.3