[PATCH 2/3] KVM: arm64: Reject KVM_RUN on a vCPU that's no longer initialized

Fuad Tabba fuad.tabba at linux.dev
Mon Nov 30 06:44:37 PST 2026


KVM_RUN returns -ENOEXEC on a vCPU that isn't initialized. The check was
there in kvm_arch_vcpu_ioctl_run() until commit b5aa368abfbf4 ("KVM: arm64:
Merge kvm_arch_vcpu_run_pid_change() and kvm_vcpu_first_run_init()")
moved it to kvm_arch_vcpu_run_pid_change(), which is called only when
the thread issuing KVM_RUN changes. However, KVM clears VCPU_INITIALIZED
on a vCPU that enters a disallowed AArch32 mode, and still runs it on
the next KVM_RUN from the same thread.

Restore the check in kvm_arch_vcpu_ioctl_run(). Keep the one in
kvm_arch_vcpu_run_pid_change(), which also prepares a vCPU for its
first run.

Fixes: b5aa368abfbf4 ("KVM: arm64: Merge kvm_arch_vcpu_run_pid_change() and kvm_vcpu_first_run_init()")
Signed-off-by: Fuad Tabba <fuad.tabba at linux.dev>
---
 arch/arm64/kvm/arm.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index cfaaadd97233f..6c2d3811f2814 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -1417,6 +1417,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 	struct kvm_run *run = vcpu->run;
 	int ret;
 
+	if (unlikely(!kvm_vcpu_initialized(vcpu)))
+		return -ENOEXEC;
+
 	if (run->exit_reason == KVM_EXIT_MMIO) {
 		ret = kvm_handle_mmio_return(vcpu);
 		if (ret <= 0)
-- 
2.47.3




More information about the linux-arm-kernel mailing list