[PATCH v7 02/17] KVM: nSVM: Bail early out of VMRUN emulation if advancing RIP fails
From: Yosry Ahmed
Date: Wed May 27 2026 - 19:48:06 EST
If svm_skip_emulation_instruction() fails, then RIP could not be
advanced correctly (e.g. decode failure when NextRIP is not available).
KVM will exit to userspace to handle the emulation failure, but only
after stuffing the wrong RIP into vmcb01 and entering guest mode.
Bail early and exit to userspace before committing any side-effects of
emulating the VMRUN (e.g. entering guest mode).
Fixes: c8e16b78c614 ("x86: KVM: svm: eliminate hardcoded RIP advancement from vmrun_interception()")
Signed-off-by: Yosry Ahmed <yosry@xxxxxxxxxx>
---
arch/x86/kvm/svm/nested.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
index 01e3e6fa8bbb1..ddf18a6daf823 100644
--- a/arch/x86/kvm/svm/nested.c
+++ b/arch/x86/kvm/svm/nested.c
@@ -1159,9 +1159,10 @@ int nested_svm_vmrun(struct kvm_vcpu *vcpu)
* FIXME: If TF is set on VMRUN should inject a #DB (or handle guest
* debugging) right after #VMEXIT, right now it's just ignored.
*/
- ret = svm_skip_emulated_instruction(vcpu);
- if (ret)
- kvm_pmu_instruction_retired(vcpu);
+ if (!svm_skip_emulated_instruction(vcpu))
+ return 0;
+
+ kvm_pmu_instruction_retired(vcpu);
/*
* Since vmcb01 is not in use, we can use it to store some of the L1
@@ -1191,7 +1192,7 @@ int nested_svm_vmrun(struct kvm_vcpu *vcpu)
nested_svm_vmexit(svm);
}
- return ret;
+ return 1;
}
/* Copy state save area fields which are handled by VMRUN */
--
2.54.0.794.g4f17f83d09-goog