Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp959134pxp; Wed, 16 Mar 2022 22:40:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUINOSMufp7y8aw75cLJ7sKySbbfJ1DNNSVhYOPr2iFFp24k5f4a36SGq22c8ABI2P6iwK X-Received: by 2002:a63:fd01:0:b0:381:31b7:8bc5 with SMTP id d1-20020a63fd01000000b0038131b78bc5mr2401428pgh.206.1647495612936; Wed, 16 Mar 2022 22:40:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647495612; cv=none; d=google.com; s=arc-20160816; b=iBnjsyqiH6u1snB67tZ/z5zFw2Ezo6NA4h5KlQpl/QuUecGVOxjFFOXQFTq/8CFIFC /YdJwMRjVy42SnQNHo3loOouIy60Ru73lykIbvQz+HSCcJTs+IAjOVCb8TZ3yGhLeloU +EwXW0CXYav3SZz2ufal15cbruksc9Y6S2JQpESKQ0f40g8RR1s1eUhWXOW8FZ1NKvIe z45k/PIyq31Pnw4CIXWVabcm+GlxgghUH4aBAA2Dxfo0GA2pUXYn0FZG7sBOpb2Xjk2V 5OQFXAh8j/pOrb0dqJMDRGXko217xyPAeuifFYBZ93TvY3JFEd1LXU5zz7IEoGYciRlC rsCA== 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=S7/ODdg+GzQRh4nPjyercOT3yyEn80anDiM+C9BDGY8=; b=Wykge2hGBCUoFsAeHyoTJxVz3n8iUB2HHsKvIeoofzeKTdIZw7FgHLVOAreyv2VBeM H8RvPCzlVV8UTqFb7gMTe767UuRYUT/JPbGzLvV8FNtvPR9jFR4n+99MvoHj9tCb8McM jJeTgBgUOPnpgN21lDV6ebMaviGo6K0zJlBlJyVvXI82Eqe6AlRlXE8BKQMhmDKY0H6i KGdeMzadvUt7ExCn8Rbrk0O1LvEjSngmAxmtJf6Hi9RhXY+BTYutctbYHmpFzcHPyEFC a3On1EkU6pKl6pltE5xGsAdfVCrwSjvo3jrGnjieMplnmJ+p0ArQhi2SJITuPI4UC/Ao 1Ehw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HPKxEcz+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id y8-20020a17090aca8800b001bd4e7011d2si1265111pjt.157.2022.03.16.22.40.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 22:40:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HPKxEcz+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 86D1D147527; Wed, 16 Mar 2022 21:45:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352419AbiCOWvh (ORCPT + 99 others); Tue, 15 Mar 2022 18:51:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352349AbiCOWva (ORCPT ); Tue, 15 Mar 2022 18:51:30 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17EC05D1A8; Tue, 15 Mar 2022 15:50:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1647384617; x=1678920617; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=G6wU/34ck5dJazez1GHKSlKvkf4t7Zi1Bj8Q+6SFQoU=; b=HPKxEcz+0U1ekqEJstP25LQJd4yNUy0+JrbilK3jfFrymXny6fugTQHU Bh1R2T7++2J6PRHnUa0zi/51+/ip0LlVChCpx/0etacYpJIDvQxvVj3r+ VPILEG0qItGsLOKiCSyMOUH6DqOc10Qdejz0J8CobaH3e19/pYkzuGH8E FYKKoFVJLjYeBLaQwuoMxZfrvc7mCNt3kct6PYRrkMZdVN2ij/m7gn6PQ umqvx2BwEQ+tkqry57T/ubQncySxKjaB117/p3VbYcGgwVIzxxLscap7I UB1bez1/43j+gh68P2ZnMKCDUV6fE45aPnOk5kSwRSdz65vBdR143eKKa g==; X-IronPort-AV: E=McAfee;i="6200,9189,10286"; a="256390618" X-IronPort-AV: E=Sophos;i="5.90,185,1643702400"; d="scan'208";a="256390618" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2022 15:50:13 -0700 X-IronPort-AV: E=Sophos;i="5.90,185,1643702400"; d="scan'208";a="690368465" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2022 15:50:12 -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 , Jim Mattson , erdemaktas@google.com, Connor Kuehl , Sean Christopherson Subject: [PATCH 4/6] KVM: TDX: Add placeholders for TDX VM/vcpu structure Date: Tue, 15 Mar 2022 15:50:08 -0700 Message-Id: <64b2878c69db959ea3b4f9e01e59a9af716d81f2.1647384148.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=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 8b50427f404b..7acbb317caa8 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", @@ -158,9 +159,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