Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1887233pxv; Fri, 2 Jul 2021 15:11:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDDwgp7C0FHYKRwGiER0aJoW790whdLWkw5/9TPkzJH2LnEGQmUYblsmUsIuRye57FJdk7 X-Received: by 2002:a17:907:3e17:: with SMTP id hp23mr1851740ejc.259.1625263897891; Fri, 02 Jul 2021 15:11:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625263897; cv=none; d=google.com; s=arc-20160816; b=XloXWT3H8OMZUebgAcY071OkT20I6TEJmvIaGhi6nNj9CksZ/UqJufG4kL/sOxbHgU tOSLgWxT/Oh78C9dOGgF9raXRhlIEGUv08EfrNlEJjpe/qz+quVaENQsel3KGpTsucNC ClOvEyNrV3WdNw3zhzuyf8EVJEMTfnxFaEdRxBa2xTHLZwZVpR0xWiuRAA111vDNM/nn drIFG4/nHF4MxXVnkYkv95cYYchYUWDOS5Skf9W7PyykXYGr6wElCJv1F/di/i+YvLH3 sijCAvYA95HDsraZBOlUAZBuTLQbb0OryrbsU0Kgfxe3C9/lI7G+mSR2cwHpbJEnwN+S YURQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=reFX3SacQP793degMgtbdenk1v1gklOBiuWtOMAs8d4=; b=ySGEXJtFteE8Gu+4Tbp+wfgA9bEikgDHW9dHD3bePeImHbG0YKh9SthHwQBquCmZdL FKaH1vdHwBif8ueNaBi1yus/kMNKuwtAZXoIe//JkcRQTtOS8a4awCphcoYk7zhL5E22 hRzvBtSyJ0EjUBjGfEFMikt/86GwLizXGiRVtwdDTlE3mj36ZH1nDjKmwTLs95r/8H8B I3zc7MyPHh2ICv/CLHh5MTEBiHZtpO3miABrWaBi6ImeF8QPNjUhJ1p8nRJ3j24YOPLx NFKmfwzMMlH8ClRV1HCI8gX5hP2W9K2JTQQIveR5OOtpNX70S5mW7TxzM/T4Uy5PWkOL pZjA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d13si147444edz.545.2021.07.02.15.11.14; Fri, 02 Jul 2021 15:11:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234206AbhGBWKc (ORCPT + 99 others); Fri, 2 Jul 2021 18:10:32 -0400 Received: from mga02.intel.com ([134.134.136.20]:51169 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233018AbhGBWHz (ORCPT ); Fri, 2 Jul 2021 18:07:55 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10033"; a="195951893" X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="195951893" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 15:05:21 -0700 X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="642814710" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 15:05:21 -0700 From: isaku.yamahata@intel.com To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , erdemaktas@google.com, Connor Kuehl , Sean Christopherson , x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Sean Christopherson Subject: [RFC PATCH v2 13/69] KVM: Enable hardware before doing arch VM initialization Date: Fri, 2 Jul 2021 15:04:19 -0700 Message-Id: <66062b64b2b61cd985e280418a7c4318104bc541.1625186503.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson 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 Signed-off-by: Isaku Yamahata --- virt/kvm/kvm_main.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 9e52fe999c92..751d1f6890b0 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -923,7 +923,7 @@ static struct kvm *kvm_create_vm(unsigned long type) struct kvm_memslots *slots = kvm_alloc_memslots(); if (!slots) - goto out_err_no_arch_destroy_vm; + goto out_err_no_disable; /* Generations must be different for each address space. */ slots->generation = i; rcu_assign_pointer(kvm->memslots[i], slots); @@ -933,19 +933,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 @@ -972,10 +972,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)); -- 2.25.1