diff mbox series

[RFC,v5,004/104] KVM: Enable hardware before doing arch VM initialization

Message ID 9fa862520b817bf7d029ce0d030ad17b799f1472.1646422845.git.isaku.yamahata@intel.com (mailing list archive)
State New, archived
Headers show
Series KVM TDX basic feature support | expand

Commit Message

Isaku Yamahata March 4, 2022, 7:48 p.m. UTC
From: Sean Christopherson <sean.j.christopherson@intel.com>

Swap the order of hardware_enable_all() and kvm_arch_init_vm() to
accommodate Intel's TDX, which needs VMX to be enabled during VM init in
order to make SEAMCALLs.

This also provides consistent ordering between kvm_create_vm() and
kvm_destroy_vm() with respect to calling kvm_arch_destroy_vm() and
hardware_disable_all().

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
---
 virt/kvm/kvm_main.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Comments

Paolo Bonzini March 13, 2022, 2 p.m. UTC | #1
On 3/4/22 20:48, isaku.yamahata@intel.com wrote:
> From: Sean Christopherson <sean.j.christopherson@intel.com>
> 
> Swap the order of hardware_enable_all() and kvm_arch_init_vm() to
> accommodate Intel's TDX, which needs VMX to be enabled during VM init in
> order to make SEAMCALLs.
> 
> This also provides consistent ordering between kvm_create_vm() and
> kvm_destroy_vm() with respect to calling kvm_arch_destroy_vm() and
> hardware_disable_all().
> 
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

and please submit this as a preparation patch that can be committed 
separately.

Paolo

> ---
>   virt/kvm/kvm_main.c | 14 +++++++-------
>   1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 0afc016cc54d..52f72a366beb 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -1105,19 +1105,19 @@ static struct kvm *kvm_create_vm(unsigned long type)
>   		rcu_assign_pointer(kvm->buses[i],
>   			kzalloc(sizeof(struct kvm_io_bus), GFP_KERNEL_ACCOUNT));
>   		if (!kvm->buses[i])
> -			goto out_err_no_arch_destroy_vm;
> +			goto out_err_no_disable;
>   	}
>   
>   	kvm->max_halt_poll_ns = halt_poll_ns;
>   
> -	r = kvm_arch_init_vm(kvm, type);
> -	if (r)
> -		goto out_err_no_arch_destroy_vm;
> -
>   	r = hardware_enable_all();
>   	if (r)
>   		goto out_err_no_disable;
>   
> +	r = kvm_arch_init_vm(kvm, type);
> +	if (r)
> +		goto out_err_no_arch_destroy_vm;
> +
>   #ifdef CONFIG_HAVE_KVM_IRQFD
>   	INIT_HLIST_HEAD(&kvm->irq_ack_notifier_list);
>   #endif
> @@ -1145,10 +1145,10 @@ static struct kvm *kvm_create_vm(unsigned long type)
>   		mmu_notifier_unregister(&kvm->mmu_notifier, current->mm);
>   #endif
>   out_err_no_mmu_notifier:
> -	hardware_disable_all();
> -out_err_no_disable:
>   	kvm_arch_destroy_vm(kvm);
>   out_err_no_arch_destroy_vm:
> +	hardware_disable_all();
> +out_err_no_disable:
>   	WARN_ON_ONCE(!refcount_dec_and_test(&kvm->users_count));
>   	for (i = 0; i < KVM_NR_BUSES; i++)
>   		kfree(kvm_get_bus(kvm, i));
diff mbox series

Patch

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 0afc016cc54d..52f72a366beb 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1105,19 +1105,19 @@  static struct kvm *kvm_create_vm(unsigned long type)
 		rcu_assign_pointer(kvm->buses[i],
 			kzalloc(sizeof(struct kvm_io_bus), GFP_KERNEL_ACCOUNT));
 		if (!kvm->buses[i])
-			goto out_err_no_arch_destroy_vm;
+			goto out_err_no_disable;
 	}
 
 	kvm->max_halt_poll_ns = halt_poll_ns;
 
-	r = kvm_arch_init_vm(kvm, type);
-	if (r)
-		goto out_err_no_arch_destroy_vm;
-
 	r = hardware_enable_all();
 	if (r)
 		goto out_err_no_disable;
 
+	r = kvm_arch_init_vm(kvm, type);
+	if (r)
+		goto out_err_no_arch_destroy_vm;
+
 #ifdef CONFIG_HAVE_KVM_IRQFD
 	INIT_HLIST_HEAD(&kvm->irq_ack_notifier_list);
 #endif
@@ -1145,10 +1145,10 @@  static struct kvm *kvm_create_vm(unsigned long type)
 		mmu_notifier_unregister(&kvm->mmu_notifier, current->mm);
 #endif
 out_err_no_mmu_notifier:
-	hardware_disable_all();
-out_err_no_disable:
 	kvm_arch_destroy_vm(kvm);
 out_err_no_arch_destroy_vm:
+	hardware_disable_all();
+out_err_no_disable:
 	WARN_ON_ONCE(!refcount_dec_and_test(&kvm->users_count));
 	for (i = 0; i < KVM_NR_BUSES; i++)
 		kfree(kvm_get_bus(kvm, i));