KVM: arm64: Acquire mp_state_lock in kvm_arch_vcpu_ioctl_vcpu_init()
authorReiji Watanabe <reijiw@google.com>
Wed, 19 Apr 2023 02:18:51 +0000 (19:18 -0700)
committerMarc Zyngier <maz@kernel.org>
Thu, 20 Apr 2023 08:06:02 +0000 (09:06 +0100)
kvm_arch_vcpu_ioctl_vcpu_init() doesn't acquire mp_state_lock
when setting the mp_state to KVM_MP_STATE_RUNNABLE. Fix the
code to acquire the lock.

Signed-off-by: Reiji Watanabe <reijiw@google.com>
[maz: minor refactor]
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20230419021852.2981107-2-reijiw@google.com
arch/arm64/kvm/arm.c

index fd8d355..ad3655a 100644 (file)
@@ -1241,11 +1241,15 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu,
        /*
         * Handle the "start in power-off" case.
         */
+       spin_lock(&vcpu->arch.mp_state_lock);
+
        if (test_bit(KVM_ARM_VCPU_POWER_OFF, vcpu->arch.features))
-               kvm_arm_vcpu_power_off(vcpu);
+               __kvm_arm_vcpu_power_off(vcpu);
        else
                WRITE_ONCE(vcpu->arch.mp_state.mp_state, KVM_MP_STATE_RUNNABLE);
 
+       spin_unlock(&vcpu->arch.mp_state_lock);
+
        return 0;
 }