From patchwork Wed Sep 23 18:57:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 11795531 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AC948618 for ; Wed, 23 Sep 2020 18:58:27 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 52BBA206FB for ; Wed, 23 Sep 2020 18:58:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="nYQ9O99x" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 52BBA206FB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=Qvyo4i5E8YZPy0Qa1Jh1mRdbgO+npONUFmRwy82OANA=; b=nYQ9O99x+AuVT9qdB0znaaqBYd S0tEiEhkBKwgmqO34a7CQp45KnfvV5fF47tWCKiMeOZ20OgN12C9UJJSKaWnEY6Aes6xpFqw/vMeG tmMcD9TQBB9FbIrAdZu4bgsvjpL20KSAsYgreFGgruSn/xAwROdULc7lxnVhdr48oinKtEjbono09 9B89Qm36omadokTDhLXzoLVoGWh+DcV/vCHO93HqJw5xUOBLaWqRWDNKT/6Z7mA7XTbblfbn6JuXa fekmgSkHBrjxo99SeCCDddzwGPZC5Fb0ZbrISChV4tSq56+zbH7y/ASFjOexOGSU7R+oVpTIn64k0 9zlNj51w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kL9y3-0004II-SI; Wed, 23 Sep 2020 18:58:15 +0000 Received: from mga05.intel.com ([192.55.52.43]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kL9y1-0004HP-Uh for linux-arm-kernel@lists.infradead.org; Wed, 23 Sep 2020 18:58:14 +0000 IronPort-SDR: Omr5HBb86yTHdgEhcIRq0K4viPERt/qphI6jSBEeUjPsGSuFZd0at3FpQLE7PWB6mvyoAoL1h2 zOR2eigckJ2A== X-IronPort-AV: E=McAfee;i="6000,8403,9753"; a="245818993" X-IronPort-AV: E=Sophos;i="5.77,293,1596524400"; d="scan'208";a="245818993" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Sep 2020 11:58:02 -0700 IronPort-SDR: kz7/UhdqfQR7kPq/UutKfm67dCkSO0dRSAPU6xHrzv6Gh4iZ9RoV4ILoENHljI/FS+ll6XOVeH kxkn4Ig0AyyQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,293,1596524400"; d="scan'208";a="338759550" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.160]) by orsmga008.jf.intel.com with ESMTP; 23 Sep 2020 11:58:02 -0700 From: Sean Christopherson To: Paolo Bonzini Subject: [PATCH] KVM: Enable hardware before doing arch VM initialization Date: Wed, 23 Sep 2020 11:57:57 -0700 Message-Id: <20200923185757.1806-1-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200923_145814_121088_631B4001 X-CRM114-Status: GOOD ( 16.24 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [192.55.52.43 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Wanpeng Li , kvm@vger.kernel.org, David Hildenbrand , linux-mips@vger.kernel.org, Paul Mackerras , Huacai Chen , Claudio Imbrenda , Janosch Frank , Marc Zyngier , Joerg Roedel , Christian Borntraeger , Aleksandar Markovic , Julien Thierry , Suzuki K Poulose , kvm-ppc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Jim Mattson , Cornelia Huck , linux-kernel@vger.kernel.org, Sean Christopherson , James Morse , Vitaly Kuznetsov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Swap the order of hardware_enable_all() and kvm_arch_init_vm() to accommodate Intel's Trust Domain Extension (TDX), which needs VMX to be fully 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(). Cc: Marc Zyngier Cc: James Morse Cc: Julien Thierry Cc: Suzuki K Poulose Cc: linux-arm-kernel@lists.infradead.org Cc: Huacai Chen Cc: Aleksandar Markovic Cc: linux-mips@vger.kernel.org Cc: Paul Mackerras Cc: kvm-ppc@vger.kernel.org Cc: Christian Borntraeger Cc: Janosch Frank Cc: David Hildenbrand Cc: Cornelia Huck Cc: Claudio Imbrenda Cc: Vitaly Kuznetsov Cc: Wanpeng Li Cc: Jim Mattson Cc: Joerg Roedel Signed-off-by: Sean Christopherson Reviewed-by: Christian Borntraeger Reviewed-by: Huacai Chen --- Obviously not required until the TDX series comes along, but IMO KVM should be consistent with respect to enabling and disabling virt support in hardware. Tested only on Intel hardware. Unless I missed something, this only affects x86, Arm and MIPS as hardware enabling is a nop for s390 and PPC. Arm looks safe (based on my mostly clueless reading of the code), but I have no idea if this will cause problem for MIPS, which is doing all kinds of things in hardware_enable() that I don't pretend to fully understand. 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 cf88233b819a..58fa19bcfc90 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -766,7 +766,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); @@ -776,19 +776,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 @@ -815,10 +815,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));