[PATCH v8 7/9] KVM: Move kvm_arch_vcpu_precreate() under kvm->lock
From: Zeng Guang
Date: Mon Apr 11 2022 - 05:38:01 EST
Arch specific KVM common data may require pre-allocation or other
preprocess ready before vCPU creation at runtime. It's safe to
invoke kvm_arch_vcpu_precreate() within the protection of kvm->lock
directly rather than take into account in the implementation for each
architecture.
Suggested-by: Sean Christopherson <seanjc@xxxxxxxxxx>
Signed-off-by: Zeng Guang <guang.zeng@xxxxxxxxx>
---
arch/s390/kvm/kvm-s390.c | 2 --
virt/kvm/kvm_main.c | 2 +-
2 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 156d1c25a3c1..5c795bbcf1ea 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -3042,9 +3042,7 @@ static int sca_can_add_vcpu(struct kvm *kvm, unsigned int id)
if (!sclp.has_esca || !sclp.has_64bscao)
return false;
- mutex_lock(&kvm->lock);
rc = kvm->arch.use_esca ? 0 : sca_switch_to_extended(kvm);
- mutex_unlock(&kvm->lock);
return rc == 0 && id < KVM_S390_ESCA_CPU_SLOTS;
}
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 70e05af5ebea..a452e678a015 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -3732,9 +3732,9 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
}
kvm->created_vcpus++;
+ r = kvm_arch_vcpu_precreate(kvm, id);
mutex_unlock(&kvm->lock);
- r = kvm_arch_vcpu_precreate(kvm, id);
if (r)
goto vcpu_decrement;
--
2.27.0