Commit e83dff5e authored by Christoffer Dall's avatar Christoffer Dall Committed by Paolo Bonzini

KVM: Move vcpu_load to arch-specific kvm_arch_vcpu_ioctl_set_mpstate

Move vcpu_load() and vcpu_put() into the architecture specific
implementations of kvm_arch_vcpu_ioctl_set_mpstate().
Reviewed-by: default avatarDavid Hildenbrand <david@redhat.com>
Signed-off-by: default avatarChristoffer Dall <christoffer.dall@linaro.org>
Reviewed-by: default avatarCornelia Huck <cohuck@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent fd232561
...@@ -2850,6 +2850,8 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, ...@@ -2850,6 +2850,8 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
{ {
int rc = 0; int rc = 0;
vcpu_load(vcpu);
/* user space knows about this interface - let it control the state */ /* user space knows about this interface - let it control the state */
vcpu->kvm->arch.user_cpu_state_ctrl = 1; vcpu->kvm->arch.user_cpu_state_ctrl = 1;
...@@ -2867,6 +2869,7 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, ...@@ -2867,6 +2869,7 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
rc = -ENXIO; rc = -ENXIO;
} }
vcpu_put(vcpu);
return rc; return rc;
} }
......
...@@ -7481,15 +7481,19 @@ int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu, ...@@ -7481,15 +7481,19 @@ int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
struct kvm_mp_state *mp_state) struct kvm_mp_state *mp_state)
{ {
int ret = -EINVAL;
vcpu_load(vcpu);
if (!lapic_in_kernel(vcpu) && if (!lapic_in_kernel(vcpu) &&
mp_state->mp_state != KVM_MP_STATE_RUNNABLE) mp_state->mp_state != KVM_MP_STATE_RUNNABLE)
return -EINVAL; goto out;
/* INITs are latched while in SMM */ /* INITs are latched while in SMM */
if ((is_smm(vcpu) || vcpu->arch.smi_pending) && if ((is_smm(vcpu) || vcpu->arch.smi_pending) &&
(mp_state->mp_state == KVM_MP_STATE_SIPI_RECEIVED || (mp_state->mp_state == KVM_MP_STATE_SIPI_RECEIVED ||
mp_state->mp_state == KVM_MP_STATE_INIT_RECEIVED)) mp_state->mp_state == KVM_MP_STATE_INIT_RECEIVED))
return -EINVAL; goto out;
if (mp_state->mp_state == KVM_MP_STATE_SIPI_RECEIVED) { if (mp_state->mp_state == KVM_MP_STATE_SIPI_RECEIVED) {
vcpu->arch.mp_state = KVM_MP_STATE_INIT_RECEIVED; vcpu->arch.mp_state = KVM_MP_STATE_INIT_RECEIVED;
...@@ -7497,7 +7501,11 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, ...@@ -7497,7 +7501,11 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
} else } else
vcpu->arch.mp_state = mp_state->mp_state; vcpu->arch.mp_state = mp_state->mp_state;
kvm_make_request(KVM_REQ_EVENT, vcpu); kvm_make_request(KVM_REQ_EVENT, vcpu);
return 0;
ret = 0;
out:
vcpu_put(vcpu);
return ret;
} }
int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int idt_index, int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int idt_index,
......
...@@ -395,6 +395,10 @@ int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu, ...@@ -395,6 +395,10 @@ int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
struct kvm_mp_state *mp_state) struct kvm_mp_state *mp_state)
{ {
int ret = 0;
vcpu_load(vcpu);
switch (mp_state->mp_state) { switch (mp_state->mp_state) {
case KVM_MP_STATE_RUNNABLE: case KVM_MP_STATE_RUNNABLE:
vcpu->arch.power_off = false; vcpu->arch.power_off = false;
...@@ -403,10 +407,11 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, ...@@ -403,10 +407,11 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
vcpu_power_off(vcpu); vcpu_power_off(vcpu);
break; break;
default: default:
return -EINVAL; ret = -EINVAL;
} }
return 0; vcpu_put(vcpu);
return ret;
} }
/** /**
......
...@@ -2649,9 +2649,7 @@ static long kvm_vcpu_ioctl(struct file *filp, ...@@ -2649,9 +2649,7 @@ static long kvm_vcpu_ioctl(struct file *filp,
r = -EFAULT; r = -EFAULT;
if (copy_from_user(&mp_state, argp, sizeof(mp_state))) if (copy_from_user(&mp_state, argp, sizeof(mp_state)))
goto out; goto out;
vcpu_load(vcpu);
r = kvm_arch_vcpu_ioctl_set_mpstate(vcpu, &mp_state); r = kvm_arch_vcpu_ioctl_set_mpstate(vcpu, &mp_state);
vcpu_put(vcpu);
break; break;
} }
case KVM_TRANSLATE: { case KVM_TRANSLATE: {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment