Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4102095rwb; Sun, 7 Aug 2022 15:05:00 -0700 (PDT) X-Google-Smtp-Source: AA6agR5cqhLqMMfVrGBSgQA6CkMGO5h4qKBz8G1z31kPLQQyS7+qy83F2rkx0I/9wTcDjDBrakbr X-Received: by 2002:a17:907:2c6b:b0:730:e952:4140 with SMTP id ib11-20020a1709072c6b00b00730e9524140mr10340123ejc.702.1659909900307; Sun, 07 Aug 2022 15:05:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659909900; cv=none; d=google.com; s=arc-20160816; b=iu0pirjV3MdgEbVoLZrhh3u06RyNVSKMRl6WU73Rk9sDjjbXSYgCWGEzXVAWniQa69 S5IcJkwsfpfpM6fOsaPPSkasgxcUqbcr87WqYaAh9MSIVQl3xhTL+HTYZrB54S6ZLYg2 O3bWX0tb4zQ2V22ylXtFcMfQam3+HlklPPKRrvVcWs4nSxLLU7vQCmeVb4N4Rp6aZfDT /WEeRLDmJWdmGxZ2fhbncow3Oy42YLz10JmYX9YXIcttTkF7XSwGOJvm6YiAcebayC2n FJoM5Uk3vpsD5jSKCfrNLf3wcY3Ca3gJYR6bPgHVmXDWnxAqWIhZQvd/hDCd5X3tyYo/ BJAg== 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=G4LXgbt408qBvrepoVvkIUKcyd7aoWCMpaJLFqgYzxU=; b=VOhc5yxqjhFz3Dej0ViHDZ/4y9QuUXDM1P63+aP0Rv7CMIETZ9tDDY5VfXbQp4HC+c gxvhAfOBXG1dWgSrvGEx2aILRgSUL6GTbxir58avIVvydOqpiKZnVnp5y153ls/Ij3/n hcI5a58Ga5cp41CAiWWjkOte7GJRnSnNdCuI9djrFa+FXjm5Zg3CeObOXSF0nZ6ejDIo UGlLwvzpjJ4j5+7cqs0n7thCog3r/1TiLIxNxEuRHPJTdt4l8mEoNvzg4+YzTK/MkrDN Fo3nD9IcfezQrawLBBOdDDrCZV+vfFTNmBvQJF+ZrGe4vjc4hmAtyq/2I7BfszLlsipN dIeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=AX+xTwkF; 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 a2-20020a509b42000000b0043ae03d2f9bsi5442392edj.459.2022.08.07.15.04.33; Sun, 07 Aug 2022 15:05:00 -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=AX+xTwkF; 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 S234845AbiHGWC4 (ORCPT + 99 others); Sun, 7 Aug 2022 18:02:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230386AbiHGWCd (ORCPT ); Sun, 7 Aug 2022 18:02:33 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44509647E; Sun, 7 Aug 2022 15:02:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1659909753; x=1691445753; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CPctVshAYvBZQeYePQA7/EdHee14GQa4BWG3ivvY6lo=; b=AX+xTwkFQTEjqdHMr+jOLTZm0jPUcfmS6He8Z5jiNVoQNCqkY3p4nuGG tXmvFcIfKPqsSvpqgmvo8TWzlqM003vSs6YnUCm+CBIux8HN84jaKknA3 rlhBNojJBR0G3/RMVET6OOEjmq5dvpcbYpXX25r8GIBobFf+BNmSGr5e/ zGDZkuVah2B7jitZ19DtLHpwayAFU5rFUtUpjAa5MHNC+vUSmlt7bGtko brRPa8a5oLW7JOYp6SKyH6zH+UDu4DeFXDwh4hpQdK546xrvWbPjJ44HZ 0/ym4F6k4Xp2fGFc1Y74mr4xV/S/9ZBv7n/72K0rWXvpMqX0d6w/XHxyn w==; X-IronPort-AV: E=McAfee;i="6400,9594,10432"; a="289224053" X-IronPort-AV: E=Sophos;i="5.93,220,1654585200"; d="scan'208";a="289224053" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2022 15:02:29 -0700 X-IronPort-AV: E=Sophos;i="5.93,220,1654585200"; d="scan'208";a="663682457" 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; 07 Aug 2022 15:02:29 -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 v8 007/103] KVM: TDX: Add placeholders for TDX VM/vcpu structure Date: Sun, 7 Aug 2022 15:00:52 -0700 Message-Id: <435820db6a973d7befc70a75c25c4dd2888256d6.1659854790.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=-5.0 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,T_SCC_BODY_TEXT_LINE 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 381e1ab760de..a0252cc0b48d 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(); vmx_init_early(); 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