Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1885095pxv; Fri, 2 Jul 2021 15:08:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7Fy6KGW6fVh/vIyLE0L8EqTi1yZdWjizA1zh6/tYGgTrqbKT5xhDVGHtG29h0PVtqXdlq X-Received: by 2002:a17:907:3da3:: with SMTP id he35mr1958805ejc.490.1625263707350; Fri, 02 Jul 2021 15:08:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625263707; cv=none; d=google.com; s=arc-20160816; b=Yz49/qDRvQwz5RtGumITrT4iJXDyFECHnHqRJr1BOiqQgPBx/8N2R3EnHXmxfyMizd afw9fIwVZGFa/x2v3wqBfIMjAayNmGu9CS6K7mW9sQcYuEPGYUp0rcu4wFPRAOj5yR9n Uahl5H582xqgAZjmgyK0pfXrxLXFAkw5KKeJTjGZW5aoCWYPu9vPb9hg52IxdI/kbXc3 s9NQLP5sAyYCd/n2lSkIZHfukzUguji8nYffmkjbkyXHqfOQaccn5abGwy6/9LWxHSWT zCPsghnsKfOaQpT0MIVjpIkhb9GHtjvg9TGeiWZvdzXo21DJBzDg1KE46dq35uKPAJfo 918Q== 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=Gdfusm6bkzYCGiZEz6UhLIyLoq8Bqzoe6hBq8KY5uS0=; b=soUKDFmkNSi8BSuIlb3UM5YSn2HkEqNAFJVX++1mOU4ZSVAuCWZ5zhVpBCSe5Hzt5t dai9yGWFs2G0f8cAtb97XpzrEgjOydg+YogJkMM6jPpBn0u1JZf7+1BxXyJDm5m0tROR N/DykSDNbXbMTXzxRb/L3T9bqLiMMbbPN89SZ7K3/nbIR/KyCC2jAXl9V/aAVqFD9r3l g07xoRTfvCCy/RdcgGCIe7v2xY43MidhRE3wESTJUQ0clwj4XcQQ1ca4JkUraoVq5dhR uMHhkH1u8pQIVuaniuPZ0xbzdUf0ux4yat+afcQNqW+4iPfSBSEiFR9UUDkO3z3ci3mw regg== 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 b31si4181606edf.385.2021.07.02.15.08.04; Fri, 02 Jul 2021 15:08:27 -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 S233984AbhGBWIo (ORCPT + 99 others); Fri, 2 Jul 2021 18:08:44 -0400 Received: from mga12.intel.com ([192.55.52.136]:50200 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233176AbhGBWH7 (ORCPT ); Fri, 2 Jul 2021 18:07:59 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10033"; a="188472742" X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="188472742" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 15:05:25 -0700 X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="642814788" 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:25 -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 35/69] KVM: x86: Introduce vm_teardown() hook in kvm_arch_vm_destroy() Date: Fri, 2 Jul 2021 15:04:41 -0700 Message-Id: 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 Add a second kvm_x86_ops hook in kvm_arch_vm_destroy() to support TDX's destruction path, which needs to first put the VM into a teardown state, then free per-vCPU resource, and finally free per-VM resources. Note, this knowingly creates a discrepancy in nomenclature for SVM as svm_vm_teardown() invokes avic_vm_destroy() and sev_vm_destroy(). Moving the now-misnamed functions or renaming them is left to a future patch so as not to introduce a functional change for SVM. Signed-off-by: Sean Christopherson Signed-off-by: Isaku Yamahata --- arch/x86/include/asm/kvm-x86-ops.h | 1 + arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/svm/svm.c | 8 +++++++- arch/x86/kvm/vmx/vmx.c | 12 ++++++++++++ arch/x86/kvm/x86.c | 3 ++- 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h index 01457da0162b..95ae4a71cfbc 100644 --- a/arch/x86/include/asm/kvm-x86-ops.h +++ b/arch/x86/include/asm/kvm-x86-ops.h @@ -20,6 +20,7 @@ KVM_X86_OP(has_emulated_msr) KVM_X86_OP(vcpu_after_set_cpuid) KVM_X86_OP(is_vm_type_supported) KVM_X86_OP(vm_init) +KVM_X86_OP(vm_teardown) KVM_X86_OP_NULL(vm_destroy) KVM_X86_OP(vcpu_create) KVM_X86_OP(vcpu_free) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index e3abf077f328..96e6cd95d884 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1217,6 +1217,7 @@ struct kvm_x86_ops { bool (*is_vm_type_supported)(unsigned long vm_type); unsigned int vm_size; int (*vm_init)(struct kvm *kvm); + void (*vm_teardown)(struct kvm *kvm); void (*vm_destroy)(struct kvm *kvm); /* Create, but do not attach this VCPU */ diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 286a49b09269..bcc3fc4872a3 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4416,12 +4416,17 @@ static void svm_vcpu_deliver_sipi_vector(struct kvm_vcpu *vcpu, u8 vector) sev_vcpu_deliver_sipi_vector(vcpu, vector); } -static void svm_vm_destroy(struct kvm *kvm) +static void svm_vm_teardown(struct kvm *kvm) { avic_vm_destroy(kvm); sev_vm_destroy(kvm); } +static void svm_vm_destroy(struct kvm *kvm) +{ + +} + static bool svm_is_vm_type_supported(unsigned long type) { return type == KVM_X86_LEGACY_VM; @@ -4456,6 +4461,7 @@ static struct kvm_x86_ops svm_x86_ops __initdata = { .is_vm_type_supported = svm_is_vm_type_supported, .vm_size = sizeof(struct kvm_svm), .vm_init = svm_vm_init, + .vm_teardown = svm_vm_teardown, .vm_destroy = svm_vm_destroy, .prepare_guest_switch = svm_prepare_guest_switch, diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 84c2df824ecc..36756a356704 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6995,6 +6995,16 @@ static int vmx_vm_init(struct kvm *kvm) return 0; } +static void vmx_vm_teardown(struct kvm *kvm) +{ + +} + +static void vmx_vm_destroy(struct kvm *kvm) +{ + +} + static int __init vmx_check_processor_compat(void) { struct vmcs_config vmcs_conf; @@ -7613,6 +7623,8 @@ static struct kvm_x86_ops vmx_x86_ops __initdata = { .is_vm_type_supported = vmx_is_vm_type_supported, .vm_size = sizeof(struct kvm_vmx), .vm_init = vmx_vm_init, + .vm_teardown = vmx_vm_teardown, + .vm_destroy = vmx_vm_destroy, .vcpu_create = vmx_create_vcpu, .vcpu_free = vmx_free_vcpu, diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index da9f1081cb03..4b436cae1732 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -11043,7 +11043,7 @@ void kvm_arch_destroy_vm(struct kvm *kvm) __x86_set_memory_region(kvm, TSS_PRIVATE_MEMSLOT, 0, 0); mutex_unlock(&kvm->slots_lock); } - static_call_cond(kvm_x86_vm_destroy)(kvm); + static_call(kvm_x86_vm_teardown)(kvm); kvm_free_msr_filter(srcu_dereference_check(kvm->arch.msr_filter, &kvm->srcu, 1)); kvm_pic_destroy(kvm); kvm_ioapic_destroy(kvm); @@ -11054,6 +11054,7 @@ void kvm_arch_destroy_vm(struct kvm *kvm) kvm_page_track_cleanup(kvm); kvm_xen_destroy_vm(kvm); kvm_hv_destroy_vm(kvm); + static_call_cond(kvm_x86_vm_destroy)(kvm); } void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *slot) -- 2.25.1