Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3460788rwb; Fri, 30 Sep 2022 04:04:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4WX3SnjUYXw+j4ykv6pqHD4KgSiIJzVypEy4ATpTuqd+3pn2jpuvjpsawOjvJ8DVQC6CQK X-Received: by 2002:a17:902:f64d:b0:178:a963:d400 with SMTP id m13-20020a170902f64d00b00178a963d400mr8515857plg.6.1664535873968; Fri, 30 Sep 2022 04:04:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664535873; cv=none; d=google.com; s=arc-20160816; b=y5WO27OoJ4eO+k2uyhyhqAbL64XO31eRf7sZOSA/zCg5GltsfATNCBi7EwlZyQf5d9 1nPl3Y8YAAMXGw5CKSp1WX2nvKKBTBg5rntRR7sRu6k4smqyTCs8AOXwtf3LrFHcLNoX swRY+giWdbNDTiXIVt6Qt4CEGhzdTFpveAmO+K/iGjwXaeQxbzbaT+JinaCTF0qYRxGp OPPVeTT/jnk9PautBq9OGteLVBmSS+rmK7jeqSZlbQphjir62vr+NPuzIZfR1eTPMmXv h3M2qXilCb0WYRPKUmpNBL0sJxmzYK47FXyY/gi62+lPn8ZHG9Pz4F1YNx+kY8S4kNmC wE0w== 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=5gVFxpKlmWFCZAqbkH2sc5HV90CAqlElazyTVhdHIdA=; b=UYw4TYDEzlfhtVPUMM8fvD7lkOSgbOCK2a6DHerYqcPYaxwdEMoJEIOOVBsOLKf/bP +SqISX3ypY++CLQg583WE7nhlqPwoSSaxCOBySVtRnXQfZ5F1T9YFb/Kr7Foks5wEG3p dc3BMLX1ZzFKK90QEh/lQMrxA60Bfj7fCBgt5SymTwwpCoZnVtEZupwIv5WccK5wYIGV TEas2O1FoVnSTHwPfArM9hcxPbS5lB3NB2toRl+E529D7kITjV0Bc5oPmA+Xxe+gB2tR MsNtLQv3Vksi+s9lQF69807p8TsW7pLI30yn+hcXpThacUf/IafdP5wzJZexkH/FY/sq iDhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RJDUVLOg; 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 h14-20020a056a00170e00b0053836f22d73si2517087pfc.214.2022.09.30.04.04.21; Fri, 30 Sep 2022 04:04:33 -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=RJDUVLOg; 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 S231856AbiI3KUj (ORCPT + 99 others); Fri, 30 Sep 2022 06:20:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231350AbiI3KS6 (ORCPT ); Fri, 30 Sep 2022 06:18:58 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B85BC15ED24; Fri, 30 Sep 2022 03:18:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664533137; x=1696069137; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+ajoNHlOsgUMx9Ru1r7eVLb2wmIljVefH8LEi5z8W90=; b=RJDUVLOg77b00dslKnOEJfRCyX7kIVN54vRgsy8G3FlarkRc0jx9iJZZ ruBpQAdw7ZvjoBz0ZQso/6aESBVqOajJeQE7t4DxMkPohP35h1buS9CMX sSHddKWGNnZ1mT8l487j8fKUmE9yJk0hfBEsZ7OX81sIHAciEZkxFa77f d4dpVGl9YxRjULIPMRdCWnyVZsT1GfRzkbKifls9fO3mwwK5evsNPcjVK u16cGFFd7DpOocl/JXbfOJUk+FeNIhDw+0kN8EX8171eVboVGVvfoL7Zt VH6Nq2p68qQNEB6jyLfRKd9+Eu4rFtw3ajFrUnrWWhobhadsToH5TcWAV w==; X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="366207479" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="366207479" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2022 03:18:52 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="726807524" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="726807524" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2022 03:18:52 -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 Subject: [PATCH v9 007/105] KVM: TDX: Make TDX VM type supported Date: Fri, 30 Sep 2022 03:17:01 -0700 Message-Id: <40488ce068d7c97507489b364613d4ece586abae.1664530907.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=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 | 5 ----- arch/x86/kvm/vmx/x86_ops.h | 3 ++- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c index 03e3bb127837..477c14b64879 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -10,6 +10,12 @@ static bool __read_mostly enable_tdx = IS_ENABLED(CONFIG_INTEL_TDX_HOST); module_param_named(tdx, enable_tdx, bool, 0444); +static bool vt_is_vm_type_supported(unsigned long type) +{ + return type == KVM_X86_DEFAULT_VM || + (enable_tdx && tdx_is_vm_type_supported(type)); +} + static __init int vt_hardware_setup(void) { int ret; @@ -23,6 +29,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); +} + struct kvm_x86_ops vt_x86_ops __initdata = { .name = "kvm_intel", @@ -33,9 +47,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 6f8451ff8980..c4a318efbed5 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -74,6 +74,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; +} + int __init tdx_hardware_setup(struct kvm_x86_ops *x86_ops) { int r; diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index a1d0631d5fa8..fb626adc347d 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7418,11 +7418,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 901b37636080..2a870202fbf6 100644 --- a/arch/x86/kvm/vmx/x86_ops.h +++ b/arch/x86/kvm/vmx/x86_ops.h @@ -27,7 +27,6 @@ void vmx_hardware_unsetup(void); int vmx_check_processor_compatibility(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); @@ -133,8 +132,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 0; } +static inline bool tdx_is_vm_type_supported(unsigned long type) { return false; } #endif #endif /* __KVM_X86_VMX_X86_OPS_H */ -- 2.25.1