Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp982974pxp; Wed, 16 Mar 2022 23:26:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxNz1g3w+5dtvov2U6n8fK41GGmICwiDH3xv6UZTdx3e2drpyw1HULz0JoVQNeb7uESriY X-Received: by 2002:a17:903:206:b0:153:ebab:a52f with SMTP id r6-20020a170903020600b00153ebaba52fmr1766550plh.118.1647498367538; Wed, 16 Mar 2022 23:26:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647498367; cv=none; d=google.com; s=arc-20160816; b=I5AfYrswcoobi7V9Kkqnm0fdAhG749C/aPhK66R69F6cm6yA4SfAXWgfKnciiaTHva lxy157Cq6eq+sthpoYKsBYcdzQCuIViQkWvnfdB4QI29DJ01ZlhysI36vXrQlkjEzldR OwneF7Dfoagf5/wh8p8qex8p3TBwVXhsLLAlohqi3XnYmRK2Ea+ks1yzCwsJaqZ4kWOo 2U47g0mXQkpNX+CSQqiQVRjOgLMoKdF0omhyDVaLoJRs7F1o2k5wTIvMlbuVw5nv3fbR Syx06Tvo6tx7Kw7J2uNjpDhAgEgOcOb5UrtTjGMV7vYnOpgk7oBTquM7AOnwilMp/GER Ttrg== 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=Khxe0uzFUBaZsEXn3sidP7P3H6fzreCHdzo4FPa7gjk=; b=gmIUgTRUbiaNaUCweW4dV7KakrNFuh7SXLr9Za29NRjhGD12FZuQpXr7C3fdY9JQi5 GxN6OMefz9CiXvIWEc998EhMBikj/jz8U2/Tdc9/AGAkxvcUrcXr3JYghTWgxaJsrVEc Hy5Fdl3tjKYtuFMota83sZBUkaf3doS3a5gksV908lywSbDm/SsDbLf09vhGFg9PDk/a UhTLiWnmhx/DGxovEWyIswZdqrskYU390d/jjLx+HZI0me+YBlBj8ClpshDJ0WCAYVgY a98lJtlDoaFj3CUrMgHNl6VWRpaFLiE8Hhpy99DJkaLjCBAqGoJDLDVyocibR4Cm+YJm nuog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GZYoKuvz; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id k197-20020a633dce000000b003816043f02dsi1264289pga.546.2022.03.16.23.26.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 23:26:07 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GZYoKuvz; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2EEC1285694; Wed, 16 Mar 2022 22:11:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352372AbiCOWva (ORCPT + 99 others); Tue, 15 Mar 2022 18:51:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242937AbiCOWv1 (ORCPT ); Tue, 15 Mar 2022 18:51:27 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30A905D1A8; Tue, 15 Mar 2022 15:50:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1647384613; x=1678920613; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7cHtBavUZQpj+upBdcXGP4IKZQedaVsnZ7sJicl2SlE=; b=GZYoKuvzDMmRa3+NqihARUENjeKPlSIJq41lUn7vgyuD7VISExoC0RKN R0Xi07XsI7DqK4aL5pdMh9gciudoWzJz2Em9T/TFYsbyDEu3NxkZf2OZ7 7N3c0yVMEZf5zwNpwC5cnjYeH6myng4sa65aCvOlGE1yWat/z4nIhA+Pd z6O/SBlh3M/rA+2+3avWl8uxKxdOYHVP0tbHnrXPS9d7/g221GZmNQzE6 Puc8bePfwwQpXpu51H9WrZrmwT3b68gTJiwdL7VfjYKhYRWcH4fD4Gp61 53vIJAme+XqMgrN+CvsfrKJKBC7veDL6rCpTnG2Q0JbNiTQ0mCXnzjyYJ w==; X-IronPort-AV: E=McAfee;i="6200,9189,10286"; a="256390615" X-IronPort-AV: E=Sophos;i="5.90,185,1643702400"; d="scan'208";a="256390615" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2022 15:50:12 -0700 X-IronPort-AV: E=Sophos;i="5.90,185,1643702400"; d="scan'208";a="690368455" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2022 15:50:12 -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 , Jim Mattson , erdemaktas@google.com, Connor Kuehl , Sean Christopherson Subject: [PATCH 1/6] KVM: Enable hardware before doing arch VM initialization Date: Tue, 15 Mar 2022 15:50:05 -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=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 --- 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)); -- 2.25.1