Skip to content

Commit 22c6a0e

Browse files
committed
KVM: x86: check validity of argument to KVM_SET_MP_STATE
An invalid argument to KVM_SET_MP_STATE has no effect other than making the vCPU fail to run at the next KVM_RUN. Since it is extremely unlikely that any userspace is relying on it, fail with -EINVAL just like for other architectures. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 8769364 commit 22c6a0e

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

arch/x86/kvm/x86.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10669,7 +10669,8 @@ static inline int vcpu_block(struct kvm_vcpu *vcpu)
1066910669
case KVM_MP_STATE_INIT_RECEIVED:
1067010670
break;
1067110671
default:
10672-
return -EINTR;
10672+
WARN_ON_ONCE(1);
10673+
break;
1067310674
}
1067410675
return 1;
1067510676
}
@@ -11110,9 +11111,22 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
1111011111

1111111112
vcpu_load(vcpu);
1111211113

11113-
if (!lapic_in_kernel(vcpu) &&
11114-
mp_state->mp_state != KVM_MP_STATE_RUNNABLE)
11114+
switch (mp_state->mp_state) {
11115+
case KVM_MP_STATE_UNINITIALIZED:
11116+
case KVM_MP_STATE_HALTED:
11117+
case KVM_MP_STATE_AP_RESET_HOLD:
11118+
case KVM_MP_STATE_INIT_RECEIVED:
11119+
case KVM_MP_STATE_SIPI_RECEIVED:
11120+
if (!lapic_in_kernel(vcpu))
11121+
goto out;
11122+
break;
11123+
11124+
case KVM_MP_STATE_RUNNABLE:
11125+
break;
11126+
11127+
default:
1111511128
goto out;
11129+
}
1111611130

1111711131
/*
1111811132
* KVM_MP_STATE_INIT_RECEIVED means the processor is in

0 commit comments

Comments
 (0)