[PATCH v3 17/27] KVM: nSVM: Always switch VMCB before leaving guest mode
From: Yosry Ahmed
Date: Mon Oct 12 2026 - 19:43:05 EST
Move svm_switch_vmcb() calls ahead of leave_guest_mode(), as nothing
between the calls depends on svm->vmcb being set to vmcb01. This makes
the nested VM-Exit path consistent with the nested VM-Enter path, and
having the calls to svm_switch_vmcb() and leave_guest_mode() close makes
it easier to reason about incoming changes that depend on both VMCB and
guest_mode context.
No functional change intended.
Signed-off-by: Yosry Ahmed <yosry@xxxxxxxxxx>
---
arch/x86/kvm/svm/nested.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
index 75ada771026b2..27f78228a42d5 100644
--- a/arch/x86/kvm/svm/nested.c
+++ b/arch/x86/kvm/svm/nested.c
@@ -1329,7 +1329,7 @@ void nested_svm_vmexit(struct vcpu_svm *svm)
if (nested_svm_vmexit_update_vmcb12(vcpu))
kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu);
- /* Exit Guest-Mode */
+ svm_switch_vmcb(svm, &svm->vmcb01);
leave_guest_mode(vcpu);
svm_pmu_handle_nested_transition(svm);
@@ -1356,8 +1356,6 @@ void nested_svm_vmexit(struct vcpu_svm *svm)
if (guest_cpu_cap_has(vcpu, X86_FEATURE_ERAPS))
vmcb01->control.erap_ctl |= ERAP_CONTROL_CLEAR_RAP;
- svm_switch_vmcb(svm, &svm->vmcb01);
-
/*
* Rules for synchronizing int_ctl bits from vmcb02 to vmcb01:
*
@@ -1543,6 +1541,7 @@ void svm_leave_nested(struct kvm_vcpu *vcpu)
vcpu->arch.nested_run_pending = 0;
svm->nested.vmcb12_gpa = INVALID_GPA;
+ svm_switch_vmcb(svm, &svm->vmcb01);
leave_guest_mode(vcpu);
/*
@@ -1554,8 +1553,6 @@ void svm_leave_nested(struct kvm_vcpu *vcpu)
*/
__svm_pmu_handle_nested_transition(svm, true);
- svm_switch_vmcb(svm, &svm->vmcb01);
-
nested_svm_transition_tlb_flush(vcpu);
nested_svm_uninit_mmu_context(vcpu);
--
2.56.0.385.gd3acb90ef8-goog