Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp300594rwb; Tue, 25 Jul 2023 16:19:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlEzBOBRE+6AFTnZgBSWTwdTdrkUJqn83UH22HvLOiFttnIsiFXCnulaGFNpMPVOh1xhRmU5 X-Received: by 2002:a17:906:cc0c:b0:970:1b2d:45cc with SMTP id ml12-20020a170906cc0c00b009701b2d45ccmr204105ejb.57.1690327151749; Tue, 25 Jul 2023 16:19:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690327151; cv=none; d=google.com; s=arc-20160816; b=R9pti/nLubyhVqOI70Q73XnFIIPSMmVSHhk6dQRtKgN6nQn+ZIXQXuZyLtD7k7HRCj mHKvCg/SuOgaAHpSYVLwLzkPZf43QBPutO1Cd6Dfoz7Zfcqr/CimCd0EFNNeUOeyoL3L JKpVMTagfQCXK3mzvJrP2g1f4g3MjiUr2Bt0Qh1UOdRsR8A2MruA/AVCbQPWIg4JA8Tk oph+ovSxouOVCf/6KgRivzgHT0H0lpMjGH8wfxDvbsctrX1UEpvW8euz8WBJsxZ9Msi0 6ZiTJcgzmfDKdH+ovkZNJ7mf6JDn9NBBv0I/az+KfaKmgXehQSjq2ER50DZT4CLBXnWs Exxg== 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=VYI/LZh3BiI08WB3jLJ7pq+Ruq9aH6hdWZ2tovaFL3s=; fh=juxwNcA6iKwLISFgUCNwdoIYC0NKLUseq3xZdq25RR4=; b=HB9WLZdgtR3qT0kcxBTZ2Ot5NePJxaO6e2oOrtM4rjiNvWaUShNRhwsdZCUN7YKkFc mvmP+KEINbgTv/aygIpTc18q8qRN0hoB1tim2uNhHDZFcmvj6y11hn/933+A7J2+GJms opUE6cO+KpHRnizWrTmuONV9pa+1cyxuSmcaRMXt7NAajHknqBa12qzkumkQLCro+pZh 7wLPiueKb0lTqkLC3tUzVVQa08xXgwMNo/kSEMuhc61xjemMrLy6W5jxSc79obcAqjdO rMF15x+84ORdwiWNKuD8EdBJO6Hy/2eEylZvSdnE4J8PcUh41IlE9KjrxaLgFdapPqNk 638A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MLhW9l8b; 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 ga4-20020a170906b84400b00977e0843714si8309395ejb.1002.2023.07.25.16.18.47; Tue, 25 Jul 2023 16:19:11 -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=MLhW9l8b; 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 S231955AbjGYWQd (ORCPT + 99 others); Tue, 25 Jul 2023 18:16:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230461AbjGYWPk (ORCPT ); Tue, 25 Jul 2023 18:15:40 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F78EE0; Tue, 25 Jul 2023 15:15:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690323339; x=1721859339; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iYKlzEZfVdp6EBGW2nCCTrJYsg848Ln6Mn5S9XVlZdg=; b=MLhW9l8bK+gefx1chxg6jQG34Qpg1jZGFBoK/gHMwajuPD0h208DQlW9 ICLYB9a4OOVRNKtb4C2bWqUy8I3GnbT/jtZ1hZxh6TwHRPKbrPrb4YyEB N7tc/+oYmEJ+UkGoKoYTc5amO80fxr7SdNptpinOzNfsG0Rdu3W0gvcpa HNwq9Z2bn8frqXGMdHxSqbMtz9pKG9khj+q5D/o7AIteJaONUOwWmqaJM //U3N4/qn2oEF+OYWOELPjCMx2IqQ68xLj+eWK6GWeQPkTTIP0kdN4NVR vCIsodhTLTdN7OglYBnU1fdNGz4hfS1jGUpz1bDq+t84xpQ/SJ3nODg9M g==; X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="357863055" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="357863055" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:15:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="1056938785" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="1056938785" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:15:17 -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 , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , David Matlack , Kai Huang , Zhi Wang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com Subject: [PATCH v15 007/115] KVM: TDX: Make TDX VM type supported Date: Tue, 25 Jul 2023 15:13:18 -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.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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: Isaku Yamahata NOTE: This patch is in position of the patch series for developers to be able to test codes during the middle of the patch series although this patch series doesn't provide functional features until the all the patches of this patch series. When merging this patch series, this patch can be moved to the end. 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. Signed-off-by: Isaku Yamahata --- arch/x86/kvm/vmx/main.c | 18 ++++++++++++++++-- arch/x86/kvm/vmx/tdx.c | 6 ++++++ arch/x86/kvm/vmx/vmx.c | 6 ------ arch/x86/kvm/vmx/x86_ops.h | 3 ++- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c index 11ecc231f9c4..9619473fba01 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -10,6 +10,12 @@ static bool enable_tdx __ro_after_init; module_param_named(tdx, enable_tdx, bool, 0444); +static bool vt_is_vm_type_supported(unsigned long type) +{ + return __kvm_is_vm_type_supported(type) || + (enable_tdx && tdx_is_vm_type_supported(type)); +} + static int vt_hardware_enable(void) { int ret; @@ -37,6 +43,14 @@ static __init int vt_hardware_setup(void) return 0; } +static int vt_vm_init(struct kvm *kvm) +{ + if (is_td(kvm)) + return -EOPNOTSUPP; /* Not ready to create guest TD yet. */ + + return vmx_vm_init(kvm); +} + #define VMX_REQUIRED_APICV_INHIBITS \ (BIT(APICV_INHIBIT_REASON_DISABLE)| \ BIT(APICV_INHIBIT_REASON_ABSENT) | \ @@ -57,9 +71,9 @@ struct kvm_x86_ops vt_x86_ops __initdata = { .hardware_disable = vmx_hardware_disable, .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, .vm_destroy = vmx_vm_destroy, .vcpu_precreate = vmx_vcpu_precreate, diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 1c9884164566..9d3f593eacb8 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -24,6 +24,12 @@ static int __init tdx_module_setup(void) return 0; } +bool tdx_is_vm_type_supported(unsigned long type) +{ + /* enable_tdx check is done by the caller. */ + return type == KVM_X86_TDX_VM; +} + struct vmx_tdx_enabled { cpumask_var_t vmx_enabled; atomic_t err; diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 8ff2323181fd..76e444c3e865 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7501,12 +7501,6 @@ int vmx_vcpu_create(struct kvm_vcpu *vcpu) return err; } -bool vmx_is_vm_type_supported(unsigned long type) -{ - /* TODO: Check if TDX is supported. */ - return __kvm_is_vm_type_supported(type); -} - #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 ab1b50dcf178..32a5c2629145 100644 --- a/arch/x86/kvm/vmx/x86_ops.h +++ b/arch/x86/kvm/vmx/x86_ops.h @@ -30,7 +30,6 @@ void vmx_hardware_unsetup(void); int vmx_check_processor_compat(void); int vmx_hardware_enable(void); void vmx_hardware_disable(void); -bool vmx_is_vm_type_supported(unsigned long type); int vmx_vm_init(struct kvm *kvm); void vmx_vm_destroy(struct kvm *kvm); int vmx_vcpu_precreate(struct kvm *kvm); @@ -138,8 +137,10 @@ void vmx_setup_mce(struct kvm_vcpu *vcpu); #ifdef CONFIG_INTEL_TDX_HOST int __init tdx_hardware_setup(struct kvm_x86_ops *x86_ops); +bool tdx_is_vm_type_supported(unsigned long type); #else static inline int tdx_hardware_setup(struct kvm_x86_ops *x86_ops) { return -EOPNOTSUPP; } +static inline bool tdx_is_vm_type_supported(unsigned long type) { return false; } #endif #endif /* __KVM_X86_VMX_X86_OPS_H */ -- 2.25.1