Skip to content

Commit c0095ce

Browse files
Yosry Ahmedgregkh
authored andcommitted
KVM: nSVM: Clear EVENTINJ fields in vmcb12 on nested #VMEXIT
commit 69b721a upstream. According to the APM, from the reference of the VMRUN instruction: Upon #VMEXIT, the processor performs the following actions in order to return to the host execution context: ... clear EVENTINJ field in VMCB KVM already syncs EVENTINJ fields from vmcb02 to cached vmcb12 on every L2->L0 #VMEXIT. Since these fields are zeroed by the CPU on #VMEXIT, they will mostly be zeroed in vmcb12 on nested #VMEXIT by nested_svm_vmexit(). However, this is not the case when: 1. Consistency checks fail, as nested_svm_vmexit() is not called. 2. Entering guest mode fails before L2 runs (e.g. due to failed load of CR3). (2) was broken by commit 2d8a42b ("KVM: nSVM: synchronize VMCB controls updated by the processor on every vmexit"), as prior to that nested_svm_vmexit() always zeroed EVENTINJ fields. Explicitly clear the fields in all nested #VMEXIT code paths. Fixes: 3d6368e ("KVM: SVM: Add VMRUN handler") Fixes: 2d8a42b ("KVM: nSVM: synchronize VMCB controls updated by the processor on every vmexit") Cc: stable@vger.kernel.org Signed-off-by: Yosry Ahmed <yosry@kernel.org> Link: https://patch.msgid.link/20260303003421.2185681-12-yosry@kernel.org [sean: massage changelog formatting] Signed-off-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 83754e4 commit c0095ce

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

arch/x86/kvm/svm/nested.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,8 @@ int nested_svm_vmrun(struct kvm_vcpu *vcpu)
884884
vmcb12->control.exit_code_hi = -1u;
885885
vmcb12->control.exit_info_1 = 0;
886886
vmcb12->control.exit_info_2 = 0;
887+
vmcb12->control.event_inj = 0;
888+
vmcb12->control.event_inj_err = 0;
887889
svm_set_gif(svm, false);
888890
goto out;
889891
}
@@ -1025,9 +1027,9 @@ int nested_svm_vmexit(struct vcpu_svm *svm)
10251027
if (guest_can_use(vcpu, X86_FEATURE_NRIPS))
10261028
vmcb12->control.next_rip = vmcb02->control.next_rip;
10271029

1030+
vmcb12->control.event_inj = 0;
1031+
vmcb12->control.event_inj_err = 0;
10281032
vmcb12->control.int_ctl = svm->nested.ctl.int_ctl;
1029-
vmcb12->control.event_inj = svm->nested.ctl.event_inj;
1030-
vmcb12->control.event_inj_err = svm->nested.ctl.event_inj_err;
10311033

10321034
if (!kvm_pause_in_guest(vcpu->kvm)) {
10331035
vmcb01->control.pause_filter_count = vmcb02->control.pause_filter_count;

0 commit comments

Comments
 (0)