Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp506926rwb; Thu, 12 Jan 2023 08:43:42 -0800 (PST) X-Google-Smtp-Source: AMrXdXszXfhwS7coaUbjn68w8GaA7ddusc6L62Ng2R+0qtHyOQYtbLhVmK54AVvwUVY3p1pwD2Mv X-Received: by 2002:a17:907:2587:b0:7c0:e7ad:fb0f with SMTP id ad7-20020a170907258700b007c0e7adfb0fmr54130517ejc.20.1673541822090; Thu, 12 Jan 2023 08:43:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673541822; cv=none; d=google.com; s=arc-20160816; b=xFHMB0rtNIsHu6RpbB0gxZjW1+CeOzH8guYf26XhgnJ9+jpGoB7ZH3uEjbqsq/s/r1 YGXhAd2tcqpt5nmh6m1jg4ssgMxqc/xglm4ucCd90a2d8aRwR7ZQDUA8JbddLR9oOIAb SZu7X7YWGocG/WLof46JGFAAR4inFjw0jQaWJeevY77+trNO+I7wy7XljlMZmwn5H24K +e7U+AOVFL4l56wQdDvLaRGVLYky6S7JtbRncfGRv8tWuYZxBqKpUfin5AZOVfFnRlgC 1KyHcEakAjshaGOi7uu6oH0+CWvJpNi5vK0ZjL5lD67Pn3okn0SoVtokqylAML0rhsHZ 3uQA== 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=uGuFqtw8DPpQL0wX8QzhdqQ4QBibYYlTYCKmua5vb6w=; b=jVNvSAlEFP+Bf2k0VaGroEwSJZKdq/0KEyM3BF6HQ800PbyYM0engfmfQ7mKOiEaAv RvcK8ni0Dc+BwF8HYHT77p9iibn/st7gLfKJuECj8KY9G01PIx5aPcDR8XEB65jt5cJY 7+WH1a8fItdA6bOqszNzs5ZCYD7CdMD1i6tTYQnfdbyzphOqf7wJWPimYPBUEAAgkg8F mJI0BqFxvWhTDSg+ggwkp6aIzK5T4Ov1pvlObgxU7P01Lw6zUSg0lGhtbmwO7Wh+be0k thkFCCTBsQs0MfqulEdQAgOGqV33XUxHWAKsaUjFx/EtdLJ9L1uVojuYhCGJtmdhKsdv wAkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nAbZv1Do; 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 sb2-20020a1709076d8200b007ae84881ebasi18970959ejc.505.2023.01.12.08.43.30; Thu, 12 Jan 2023 08:43:42 -0800 (PST) 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=nAbZv1Do; 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 S240154AbjALQl3 (ORCPT + 50 others); Thu, 12 Jan 2023 11:41:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229643AbjALQh3 (ORCPT ); Thu, 12 Jan 2023 11:37:29 -0500 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4078310E4; Thu, 12 Jan 2023 08:33:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673541229; x=1705077229; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HvvKYI1Xf9Q8i4IYWiUvx8L3dyljg6f6JJmuQ6ZMQOs=; b=nAbZv1DoSAgjT8tgrOuDu9c52Fz+m//t7lIOcXdR40G8CHOU+0XtqL4h u2HvGeGkiD64OEDV5dMvCBXazIleYWPwQQf2JPu4AnjkCiDgoF7ks4Ct4 oTZy8FyrEj2Lc5v+z1D0Jx168LIknXIk9kr/BH8+x3ELqghwbYvxOX2Tz Hplc/QY2KppyhhDsDEZk6tWVxQNNIiZU0uBKkbr73woXduvrdp0O8ek8p QkVzN/AHsoH8TpH6jaPJk3B4xvisxAMLsyXWw1uMZNwjGzVcYmhH0rgfC AGGoU5AH4vXNotLixPxtu9DIOJvv4rintoQ9N5zP/q0kfNylUYwNDzJi6 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="323811651" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="323811651" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:33:20 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="721151630" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="721151630" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:33:19 -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 , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , David Matlack Subject: [PATCH v11 003/113] KVM: TDX: Add placeholders for TDX VM/vcpu structure Date: Thu, 12 Jan 2023 08:31:11 -0800 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, 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 Add placeholders TDX VM/vcpu structure that overlays with VMX VM/vcpu structures. Initialize VM structure size and vcpu size/align so that x86 KVM common code knows those size irrespective of VMX or TDX. Those structures will be populated as guest creation logic develops. Add helper functions to check if the VM is guest TD and add conversion functions between KVM VM/VCPU and TDX VM/VCPU. Signed-off-by: Isaku Yamahata --- arch/x86/kvm/vmx/main.c | 8 +++--- arch/x86/kvm/vmx/tdx.h | 54 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 arch/x86/kvm/vmx/tdx.h diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c index 58474511a057..18f659d1d456 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -5,6 +5,7 @@ #include "vmx.h" #include "nested.h" #include "pmu.h" +#include "tdx.h" struct kvm_x86_ops vt_x86_ops __initdata = { .name = KBUILD_MODNAME, @@ -181,9 +182,10 @@ static int __init vt_init(void) * Common KVM initialization _must_ come last, after this, /dev/kvm is * exposed to userspace! */ - vt_x86_ops.vm_size = sizeof(struct kvm_vmx); - vcpu_size = sizeof(struct vcpu_vmx); - vcpu_align = __alignof__(struct vcpu_vmx); + vt_x86_ops.vm_size = max(sizeof(struct kvm_vmx), sizeof(struct kvm_tdx)); + vcpu_size = max(sizeof(struct vcpu_vmx), sizeof(struct vcpu_tdx)); + vcpu_align = max(__alignof__(struct vcpu_vmx), + __alignof__(struct vcpu_tdx)); r = kvm_init(vcpu_size, vcpu_align, THIS_MODULE); if (r) goto err_kvm_init; diff --git a/arch/x86/kvm/vmx/tdx.h b/arch/x86/kvm/vmx/tdx.h new file mode 100644 index 000000000000..060bf48ec3d6 --- /dev/null +++ b/arch/x86/kvm/vmx/tdx.h @@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __KVM_X86_TDX_H +#define __KVM_X86_TDX_H + +#ifdef CONFIG_INTEL_TDX_HOST +struct kvm_tdx { + struct kvm kvm; + /* TDX specific members follow. */ +}; + +struct vcpu_tdx { + struct kvm_vcpu vcpu; + /* TDX specific members follow. */ +}; + +static inline bool is_td(struct kvm *kvm) +{ + /* + * TDX VM type isn't defined yet. + * return kvm->arch.vm_type == KVM_X86_TDX_VM; + */ + return false; +} + +static inline bool is_td_vcpu(struct kvm_vcpu *vcpu) +{ + return is_td(vcpu->kvm); +} + +static inline struct kvm_tdx *to_kvm_tdx(struct kvm *kvm) +{ + return container_of(kvm, struct kvm_tdx, kvm); +} + +static inline struct vcpu_tdx *to_tdx(struct kvm_vcpu *vcpu) +{ + return container_of(vcpu, struct vcpu_tdx, vcpu); +} +#else +struct kvm_tdx { + struct kvm kvm; +}; + +struct vcpu_tdx { + struct kvm_vcpu vcpu; +}; + +static inline bool is_td(struct kvm *kvm) { return false; } +static inline bool is_td_vcpu(struct kvm_vcpu *vcpu) { return false; } +static inline struct kvm_tdx *to_kvm_tdx(struct kvm *kvm) { return NULL; } +static inline struct vcpu_tdx *to_tdx(struct kvm_vcpu *vcpu) { return NULL; } +#endif /* CONFIG_INTEL_TDX_HOST */ + +#endif /* __KVM_X86_TDX_H */ -- 2.25.1