Skip to content

Commit 6f4d3eb

Browse files
jsmattsonjrsean-jc
authored andcommitted
KVM: SVM: Allow KVM_SET_NESTED_STATE to clear GIF when SVME==0
GIF==0 together with EFER.SVME==0 is a valid architectural state. Don't return -EINVAL for KVM_SET_NESTED_STATE when this combination is specified. Fixes: cc440cd ("KVM: nSVM: implement KVM_GET_NESTED_STATE and KVM_SET_NESTED_STATE") Signed-off-by: Jim Mattson <jmattson@google.com> Reviewed-by: Yosry Ahmed <yosry.ahmed@linux.dev> Signed-off-by: Yosry Ahmed <yosry.ahmed@linux.dev> Link: https://patch.msgid.link/20251121204803.991707-2-yosry.ahmed@linux.dev [sean: disallow KVM_STATE_NESTED_RUN_PENDING with SVME=0] Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 8312f1b commit 6f4d3eb

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

arch/x86/kvm/svm/nested.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,12 +1821,12 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,
18211821
/*
18221822
* If in guest mode, vcpu->arch.efer actually refers to the L2 guest's
18231823
* EFER.SVME, but EFER.SVME still has to be 1 for VMRUN to succeed.
1824+
* If SVME is disabled, the only valid states are "none" and GIF=1
1825+
* (clearing SVME does NOT set GIF, i.e. GIF=0 is allowed).
18241826
*/
1825-
if (!(vcpu->arch.efer & EFER_SVME)) {
1826-
/* GIF=1 and no guest mode are required if SVME=0. */
1827-
if (kvm_state->flags != KVM_STATE_NESTED_GIF_SET)
1828-
return -EINVAL;
1829-
}
1827+
if (!(vcpu->arch.efer & EFER_SVME) && kvm_state->flags &&
1828+
kvm_state->flags != KVM_STATE_NESTED_GIF_SET)
1829+
return -EINVAL;
18301830

18311831
/* SMM temporarily disables SVM, so we cannot be in guest mode. */
18321832
if (is_smm(vcpu) && (kvm_state->flags & KVM_STATE_NESTED_GUEST_MODE))

0 commit comments

Comments
 (0)