Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2277982pxm; Fri, 4 Mar 2022 12:58:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJyAAyKnwK/LSHysIGXAF2bY/Rw+JewMmuWpOmGGKbGhlHrcrHcIJ4i0vkaS40HnoS+Dqu43 X-Received: by 2002:a17:902:c412:b0:151:a5f3:f5f6 with SMTP id k18-20020a170902c41200b00151a5f3f5f6mr193236plk.7.1646427506211; Fri, 04 Mar 2022 12:58:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646427506; cv=none; d=google.com; s=arc-20160816; b=q+g6GPpIPgz5oDxeUiBoILXvDRvSISNmQ+mcPsWxpPTMH7uLamtyuyraULOoQaskh0 NL8IcWwHO96EzhwWcWBDeu3v1OY9xKoDEMJjDrnJd91HCWCii5vDtQ/ZdXJPU9iLRUD8 Q+ybomBsVPi+kCCkwAv1/WQU2srDIwhvGv8tudIKGwQwLWe+YOBpb5yHnazeItehlxY6 2SGpOCCGzCTpQiN/0sWCHqjkXs2NkTqsjy+ZUgEuBKoUUaZcmzenIqbOA/XGUXxonH/v 5mP7osl2ThH1x7lq8/Nv5NGjS+l/2bzSd1BDHbtDU+X72KY7n7OMDlPKFvUoPAJs/zun SxUw== 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=iZK2xw+tIKzAY6Xh7vlbDp9pXWdm0m5BhwOHLfZ6zFQ=; b=G8Ym7cmS0ictRcuwUT/4gX/S4DwrehycQW1uCBPMjZZxLYxf1ExBfqvvBxMkISZzX2 Oj26UW6FRSWrNGsZYLmAWyCHpSyrfY17gcB5GwOGIi5FLhFJjVtV9xc3W+aRIhujk+LO 8FGrRxYlP1igk5ncr1dbRF6JKSWlbwrXf5x8pdxb7RmmMFQUgwDOSDErUkbSz3psI14j OC8zluEXkSYCUYGfJ9XFOsmpbF3WLx86H1nxobha34Sra2M0VhSBbcFWeW9tA11h65y1 iLTB62y3jpWi3CHs9XDYL8uvp8LhbVQK8RY0oM4TzBe8jcOjeAed4f0Wo5On9zyMBjWf d5FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="AI/551Of"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x62-20020a638641000000b0037d108fc745si1990813pgd.250.2022.03.04.12.58.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 12:58:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="AI/551Of"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 0D32124A13B; Fri, 4 Mar 2022 12:05:58 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230165AbiCDUGX (ORCPT + 99 others); Fri, 4 Mar 2022 15:06:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230176AbiCDUGD (ORCPT ); Fri, 4 Mar 2022 15:06:03 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58087673E7; Fri, 4 Mar 2022 12:01:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646424062; x=1677960062; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5JNuowlQDCbpp0wHYAqtnMb6w2fOXVXxSPQJpPL0icg=; b=AI/551OfF6XPrQu3TDcYsiCd4eXdJUtgKirO0MWRV/XBrITeTi/GbB8o cKnQOJJlAI/pRQwhewXi7u9kpan2RgZzy0WqZgc22NTX9xZN8ifMoRGEG 9OTiRyazODLEiVBiYoV6IZMmMtHV7Ni8himi3L+5P+k4Icpbw8CyjLD+U DZEvHr5ZQQQ2XX1otH0tGhmHuSJXLb12MWs3K5yU1PVFhnI72UB5hjbYv OFzB9CdcTBYHyHYtvlfHbUfeVQ623Q0D9/948UDi9sUwI2OijBxy7jkD2 /cct48hrvgwLezhEPSvO91KmJA7XqFGS/hTwr2NP5jsIm2DhaugmSccit Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10276"; a="253983317" X-IronPort-AV: E=Sophos;i="5.90,156,1643702400"; d="scan'208";a="253983317" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2022 11:50:06 -0800 X-IronPort-AV: E=Sophos;i="5.90,156,1643702400"; d="scan'208";a="552344123" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2022 11:50:05 -0800 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: [RFC PATCH v5 010/104] KVM: TDX: Make TDX VM type supported Date: Fri, 4 Mar 2022 11:48:26 -0800 Message-Id: <0596db2913da40660e87d5005167c623cee14765.1646422845.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 X-Spam-Status: No, score=-2.3 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: Isaku Yamahata As first step TDX VM support, return that TDX VM type supported to device model, e.g. qemu. The callback to create guest TD is vm_init callback for KVM_CREATE_VM. Add a place holder function and call a function to initialize TDX module on demand because in that callback VMX is enabled by hardware_enable callback (vmx_hardware_enable). Signed-off-by: Isaku Yamahata --- arch/x86/kvm/vmx/main.c | 24 ++++++++++++++++++++++-- arch/x86/kvm/vmx/tdx.c | 5 +++++ arch/x86/kvm/vmx/vmx.c | 5 ----- arch/x86/kvm/vmx/x86_ops.h | 3 ++- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c index 77da926ee505..8103d1c32cc9 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -5,6 +5,12 @@ #include "vmx.h" #include "nested.h" #include "pmu.h" +#include "tdx.h" + +static bool vt_is_vm_type_supported(unsigned long type) +{ + return type == KVM_X86_DEFAULT_VM || tdx_is_vm_type_supported(type); +} static __init int vt_hardware_setup(void) { @@ -19,6 +25,20 @@ static __init int vt_hardware_setup(void) return 0; } +static int vt_vm_init(struct kvm *kvm) +{ + int ret; + + if (is_td(kvm)) { + ret = tdx_module_setup(); + if (ret) + return ret; + return -EOPNOTSUPP; /* Not ready to create guest TD yet. */ + } + + return vmx_vm_init(kvm); +} + struct kvm_x86_ops vt_x86_ops __initdata = { .name = "kvm_intel", @@ -29,9 +49,9 @@ struct kvm_x86_ops vt_x86_ops __initdata = { .cpu_has_accelerated_tpr = report_flexpriority, .has_emulated_msr = vmx_has_emulated_msr, - .is_vm_type_supported = vmx_is_vm_type_supported, + .is_vm_type_supported = vt_is_vm_type_supported, .vm_size = sizeof(struct kvm_vmx), - .vm_init = vmx_vm_init, + .vm_init = vt_vm_init, .vcpu_create = vmx_vcpu_create, .vcpu_free = vmx_vcpu_free, diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 8adc87ad1807..e8d293a3c11c 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -105,6 +105,11 @@ int tdx_module_setup(void) return ret; } +bool tdx_is_vm_type_supported(unsigned long type) +{ + return type == KVM_X86_TDX_VM && READ_ONCE(enable_tdx); +} + static int __init __tdx_hardware_setup(struct kvm_x86_ops *x86_ops) { u32 max_pa; diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 3c7b3f245fee..7838cd177f0e 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7079,11 +7079,6 @@ int vmx_vcpu_create(struct kvm_vcpu *vcpu) return err; } -bool vmx_is_vm_type_supported(unsigned long type) -{ - return type == KVM_X86_DEFAULT_VM; -} - #define L1TF_MSG_SMT "L1TF CPU bug present and SMT on, data leak possible. See CVE-2018-3646 and https://www.kernel.org/doc/html/latest/admin-guide/hw-vuln/l1tf.html for details.\n" #define L1TF_MSG_L1D "L1TF CPU bug present and virtualization mitigation disabled, data leak possible. See CVE-2018-3646 and https://www.kernel.org/doc/html/latest/admin-guide/hw-vuln/l1tf.html for details.\n" diff --git a/arch/x86/kvm/vmx/x86_ops.h b/arch/x86/kvm/vmx/x86_ops.h index f7327bc73be0..78331dbc29f7 100644 --- a/arch/x86/kvm/vmx/x86_ops.h +++ b/arch/x86/kvm/vmx/x86_ops.h @@ -25,7 +25,6 @@ void vmx_hardware_unsetup(void); int vmx_hardware_enable(void); void vmx_hardware_disable(void); bool report_flexpriority(void); -bool vmx_is_vm_type_supported(unsigned long type); int vmx_vm_init(struct kvm *kvm); int vmx_vcpu_create(struct kvm_vcpu *vcpu); int vmx_vcpu_pre_run(struct kvm_vcpu *vcpu); @@ -130,10 +129,12 @@ void vmx_setup_mce(struct kvm_vcpu *vcpu); #ifdef CONFIG_INTEL_TDX_HOST void __init tdx_pre_kvm_init(unsigned int *vcpu_size, unsigned int *vcpu_align, unsigned int *vm_size); +bool tdx_is_vm_type_supported(unsigned long type); void __init tdx_hardware_setup(struct kvm_x86_ops *x86_ops); #else static inline void tdx_pre_kvm_init( unsigned int *vcpu_size, unsigned int *vcpu_align, unsigned int *vm_size) {} +static inline bool tdx_is_vm_type_supported(unsigned long type) { return false; } static inline void tdx_hardware_setup(struct kvm_x86_ops *x86_ops) {} #endif -- 2.25.1