Skip to content

Commit 8312f1b

Browse files
jsmattsonjrsean-jc
authored andcommitted
KVM: SVM: Don't set GIF when clearing EFER.SVME
Clearing EFER.SVME is not architected to set GIF. Don't set GIF when emulating a change to EFER that clears EFER.SVME. However, keep setting GIF if clearing EFER.SVME causes force-leaving the nested guest through svm_leave_nested(), to maintain a sane behavior of not leaving GIF cleared after exiting the guest. In every other path, setting GIF is either correct/desirable, or irrelevant because the caller immediately and unconditionally sets/clears GIF. This is more-or-less KVM defining HW behavior, but leaving GIF cleared would also be defining HW behavior anyway. Note that if force-leaving the nested guest is considered a SHUTDOWN, then this could violate the APM-specified behavior: If the processor enters the shutdown state (due to a triple fault for instance) while GIF is clear, it can only be restarted by means of a RESET. However, a SHUTDOWN leaves the VMCB undefined, so there's not a lot that KVM can do in this case. Also, if vGIF is enabled on SHUTDOWN, KVM has no way of finding out of GIF was cleared. The only way for KVM to handle this without making up HW behavior is to completely terminate the VM, so settle for doing the relatively "sane" thing of setting GIF when force-leaving nested. Fixes: c513f48 ("KVM: nSVM: leave guest mode when clearing EFER.SVME") Signed-off-by: Jim Mattson <jmattson@google.com> Co-developed-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Yosry Ahmed <yosry.ahmed@linux.dev> Link: https://patch.msgid.link/20251121204803.991707-3-yosry.ahmed@linux.dev Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent db5e824 commit 8312f1b

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

arch/x86/kvm/svm/nested.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,8 @@ void svm_leave_nested(struct kvm_vcpu *vcpu)
13991399
nested_svm_uninit_mmu_context(vcpu);
14001400
vmcb_mark_all_dirty(svm->vmcb);
14011401

1402+
svm_set_gif(svm, true);
1403+
14021404
if (kvm_apicv_activated(vcpu->kvm))
14031405
kvm_make_request(KVM_REQ_APICV_UPDATE, vcpu);
14041406
}

arch/x86/kvm/svm/svm.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ int svm_set_efer(struct kvm_vcpu *vcpu, u64 efer)
215215
if ((old_efer & EFER_SVME) != (efer & EFER_SVME)) {
216216
if (!(efer & EFER_SVME)) {
217217
svm_leave_nested(vcpu);
218-
svm_set_gif(svm, true);
219218
/* #GP intercept is still needed for vmware backdoor */
220219
if (!enable_vmware_backdoor)
221220
clr_exception_intercept(svm, GP_VECTOR);

0 commit comments

Comments
 (0)