Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3376682iog; Mon, 27 Jun 2022 14:56:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ssjuMjkRSXEbkNAtFnFrjiRjn6nwmPhz7KGi0WROq5rLaB9ujH6gwp/6jTBzvrjIWFS/tI X-Received: by 2002:a17:907:8d1b:b0:726:31ec:36aa with SMTP id tc27-20020a1709078d1b00b0072631ec36aamr14708493ejc.310.1656366978549; Mon, 27 Jun 2022 14:56:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656366978; cv=none; d=google.com; s=arc-20160816; b=FmxrJBighlvCP2nsUKozTmokrtU3MViIC/K4Ws2Mi5w/fiqifoQmAObb4lBFIugpAm yEUYJ/IWJLaIV0erHASr1Dg5+vco0ZsR9/QMCo/KHvlpk6+jclAgHuWNbkqVq8eFz87Y qp6vhT+v6ubsV5IB70U53RyhvdM6UEA7k/q93m2FPugIKxAxPSI1rgX160ys4uyuNPOp GHykwWoflWJC7RJBXr6bLjdXBB8RiIh7eJ+4NuibQUxyaeHtwq7qfJDkSM8MUA4l0WDd aQESZ10QbZCHdQr2wXybD3ZOqU/69jyZwvjDyE+6rcq2rQJk+xiVocJ9EVer43sCKdq9 lETg== 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 :dkim-signature; bh=+jThlaGAE0n90Y5bRSbXUDMk3MPPhHXUTcf2Brci0zk=; b=xEziSyM0dkGsQnZyhPQadBVCOZvsxQiDSvGsj+v4Es5w1gTqaEdvPi74hkGcb51MV3 hGlaQciRx+oDDOrYXfqxbyZ2581KSA4Ac9EGa0cJhWBEDGzoYFg5vfrZqWTVZhKG8azU D3dIQjHkci7DCioKkviu9HkvBwnrFQJqdb31rjg7pLZ5wZfygL8ruOdqqibR8/izTF2g lzcRv+JNV9HJT4fIk57EcgyShqstGufaqUuK+sD5mfY0+eyTcftKPzbfZIjA+5tXQqF+ 1hEleUhWKBJ8ZLPqFggrDx08Bl30rRQTEFRJsVfysaIV/1NaFfzb7dva/5dJE/XYUXmz zhNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MGWLBb5h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dy7-20020a05640231e700b00435be992059si13462005edb.125.2022.06.27.14.55.52; Mon, 27 Jun 2022 14:56:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MGWLBb5h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241275AbiF0Vyw (ORCPT + 99 others); Mon, 27 Jun 2022 17:54:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240041AbiF0Vyt (ORCPT ); Mon, 27 Jun 2022 17:54:49 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 935DA625E; Mon, 27 Jun 2022 14:54:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656366888; x=1687902888; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=v5BqaMvNZqMpHCHM9lfZC+yP1raq0KNki8VQ/Pk5gbs=; b=MGWLBb5hN57HzYJ1EJKM4FqLJS6pw6DEO3/TxzpvFqcq3QXG3qvqtpvj yi5R/S5Q0dcjYjuEDnYs0N/NvUdpIpT4tVJSULqoDhPAkmTBpuYdgVRLO WYJwy/3Sz9mRWikmJv1qtr7bHyp2EbNw3PCaD3Z/R1TJkpn2SZcVm6PJW 9I9i454xaxaHvJcRSQzuw6wWZHtT/GcvqYxlI+uNRdRzlSGFID2o8+xs9 Ptwta3R6dYeegC34lITEObuHhEV+8N+bo6jGfXOvdBhFFL7omeBWx1yAa jc5poJLw78dD2tnvd9wLaX7PhTzNIAFqHs+HAcSlU0AJqnKPIM0CEuKzo g==; X-IronPort-AV: E=McAfee;i="6400,9594,10391"; a="261983018" X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="261983018" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 14:54:48 -0700 X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="657863449" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 14:54:48 -0700 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , Sean Christopherson Subject: [PATCH v7 007/102] KVM: Enable hardware before doing arch VM initialization Date: Mon, 27 Jun 2022 14:52:59 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 Reviewed-by: Paolo Bonzini --- 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 cee799265ce6..0acb0b6d1f82 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1138,19 +1138,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 @@ -1188,10 +1188,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