Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3469036rwb; Fri, 30 Sep 2022 04:11:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4PE/A0MohWU3g3lKZgrcqPpr9BHxRVT4yZsmpuPDMy7z450uan969DXqkSfYgzXznLzn7K X-Received: by 2002:a17:903:244e:b0:178:4f50:1ca0 with SMTP id l14-20020a170903244e00b001784f501ca0mr8337852pls.104.1664536263914; Fri, 30 Sep 2022 04:11:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664536263; cv=none; d=google.com; s=arc-20160816; b=mcbs9OjTgNX4u9Bn5nhzZMkzBiNsy+5GbphL0hLX26sqRq5oR6iM6Ixi1eIU3bc20V 1SfoSx+X2+yi4hMvXFuu+izr/qo8AKkkNK4VgUqXSpD9ip/SXjmX1AhIp/7EXhGuaCz0 eYsCW4xA/rEfjqrOmE8F1JvuAxNLVmW+h46Snnx5zmhYXVVTWfzLMgdAO9c03H8/+zvn 6KfTX+BD4yetMN8O+2brIAxde4zj0+3DOgtxMwWUrkRnJhRGiiCNertvOsUr7cZlL9EH YD30bNbpxqsUmWgaCNVuvMmVP8LD1gGgycVyRPKq9Rps0jBRB8EZ/73jRRbaoS5gHKTO rDCw== 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=NNy8F66HSzMUL5jjCOUqdi/qDv4FS7D4Gn+YJKChC5Y=; b=ZCgmkTscHbGDj3MCnqsjZzgrHfTVE43BW3gHb0TIrVm1lzxXmHBvmKkOjXZU7oxTLl KXU0PqUFKs9+geCaa4JLDpyWFRCso6iqAfGpBTxaQOqPMaZttUtJmGItcEpikjBPZFLF JBjUdFOoY+93qtN+qCw9tyofvtjo5nM/XhoCpYxQ7dm+Z0gX3m4XXQOdfnfGHB3qzWVd 28JHtkNx0Q3ekwNx/ArAGNkle64ZSkFwn1aGUvoV0lOTHr3NHNR6+Ep9Jan+40Z1A41K VNn1ZcachgnN+w8KTmzEJ4wWkdtAPvb3xW8vTAl+qYr2yDiy15usF5uCqJCnW1UYCO0n Edjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="BFlk0Ey/"; 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 n1-20020a170902d2c100b001783ee34c7csi2863548plc.222.2022.09.30.04.10.49; Fri, 30 Sep 2022 04:11:03 -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="BFlk0Ey/"; 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 S231660AbiI3KTV (ORCPT + 99 others); Fri, 30 Sep 2022 06:19:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231293AbiI3KS4 (ORCPT ); Fri, 30 Sep 2022 06:18:56 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22DAF15ED32; Fri, 30 Sep 2022 03:18:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664533135; x=1696069135; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ykbD6skEMkTMVQqZNywDYvJqulhVuR9nM0nBEyHFShc=; b=BFlk0Ey/8Fe1P/D2FwiB8aon5QJJqpY+yCrL3cGR3/q3l6eRoSCAIaNQ OKSRREHysBQ+/ljkSNlGzinG8B0W1AFqxsydWvB7U+OvOCcsUPpMEgjGv hmyN2mPG3RWUYcIBUNQInjhOHsU/TBMZ1B7cps4YyjGi59sSnK9bJtjfZ 2DX6sq0e5JZwXNgC1D4ZS2mgojRVBX2DpEN1Eb/GsmXvFN47oNQR9I5SA C+qCO25kAzyZy25DSFdCVXPWGtty21cSL6EEvAUy7ezrXwYcamKhFmIGu 9rO65oo2YeFdN1rmtAPQtfcwkwxpxWc3YxSkIGBilcE5DEA66Dqg1wRNB A==; X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="366207471" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="366207471" 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:51 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="726807512" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="726807512" 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:51 -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 003/105] KVM: TDX: Add placeholders for TDX VM/vcpu structure Date: Fri, 30 Sep 2022 03:16:57 -0700 Message-Id: <89c43c69e4b84889faff9db18eed2e760b3720c0.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 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 5b4aff7a31b6..c8e8b0212a2a 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 = "kvm_intel", @@ -159,9 +160,10 @@ static int __init vt_init(void) unsigned int vcpu_size, vcpu_align; int r; - 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)); hv_vp_assist_page_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