Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2688143rwd; Sun, 28 May 2023 22:14:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4K5OVYikDPtNZbloY50mh3fvd2vv7XkGkzjWmhSQaHwJz34uKucXLs8KIULrsouOzE3tqa X-Received: by 2002:a05:6a21:6d8b:b0:103:946d:8a4c with SMTP id wl11-20020a056a216d8b00b00103946d8a4cmr6413211pzb.5.1685337290768; Sun, 28 May 2023 22:14:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685337290; cv=none; d=google.com; s=arc-20160816; b=Y3TYTZJnNKk2RmTU2oRLHUD7sv9KPoEJD6DXWvWJ/2xhmFv2AUzNSYGSdX5pg78Wjc WtpxZI7raRnxLxNYguhcVNsaBlt9bITMbMrpKlGPw/mPc0WUk2BzClOz0NJIXH746DSL Z3ncUUjFK8TOPPz3CQPCZPD7QpCUaTcg8bkRzXzW1+bbOq81ZjMha3quHgg4SqO2vv5N GuOixCQRpPhHmxten2LoAdNlIdSlTX5GpZn25n9HfVbLZqVoiT2bNFCECkMODf6hqB0A QDFYVvAWEtynpdWSna+Y4UGM7rR14JNF0lYJBjmgdct8Jt1rpFACQ017wCF+DepYb9aP jbiw== 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=1FtGj3rPLVBZ8OD5xcWOi5Pg4NiUy8yqN+CrlGKjDZo=; b=tRas/+F4U0NzlYCkDxKlyJ3+y/TPKQ9bG4C9xcLL7aUyriOURmnwvtAIXXa01ipcaN yCfMtG3A+Jl7BLcqd+LdVEPc5V3mI5A3X0Y8uEF1JiK118HL1uu4UC29nvedp/m6UtK1 8Y9TL/m5DvDWU0b89NCkUFYe7MG9fW4WakCokJ2Hj1N6xXQ9xGfOcNg84WiPUk0Rb8H8 D73l7smBqNZ0W838xO3UfRlHDw/Qj+pudqBJexdz+QwVfP35pAbipT7GBq4B3eMbPUHC InzAbxEdyr3qlvcPlJkKKcyNe01ERp1HUd5HmdBpRm1duIaHesFpWal5oCdV+wS8jXzn U59Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=a4yySRZR; 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 f91-20020a17090a28e400b00256917c7851si378764pjd.107.2023.05.28.22.14.38; Sun, 28 May 2023 22:14:50 -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=a4yySRZR; 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 S229505AbjE2EVP (ORCPT + 99 others); Mon, 29 May 2023 00:21:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231277AbjE2EUt (ORCPT ); Mon, 29 May 2023 00:20:49 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A664C2; Sun, 28 May 2023 21:20:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685334048; x=1716870048; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XMMeU5wfJIPJamHp+eMovarqPh3KgG79l1E9z1OOVks=; b=a4yySRZRVqMqa7FlAydhHqnIt7A1lSc+l4YdKwKadqg5DvwMaO0wem42 EUqVFPA94lwPsoh7/T7N4fATDbM3dXgwYeO6tIzw3+OdRlCfHGJ5FWVEK h3MbaDWHd3q5HOE+6n7JlQmQhD0QHgSZbgGjuOi7IOYYkFJoco7gqNxoQ SINLegf6ZsCcO8m/Zb9JZ9kAfRODBRtfplbh7SBeX/lH2G8mgvU5hISAf UFMaPf/3v+yN9mj3UPE5228AuncX2a2+haJdn/sSd0MBz4Td512j7onHm xoRgYLy9U64I9+O49QozyHq7rXBEHvg79yL8VY6CgO/elZpJnhASGpbNp g==; X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="418094252" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="418094252" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 21:20:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="683419298" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="683419298" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 21:20:44 -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 , David Matlack , Kai Huang , Zhi Wang , chen.bo@intel.com Subject: [PATCH v14 005/113] KVM: TDX: Add placeholders for TDX VM/vcpu structure Date: Sun, 28 May 2023 21:18:47 -0700 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.6 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 | 18 +++++++++++++-- arch/x86/kvm/vmx/tdx.c | 1 + arch/x86/kvm/vmx/tdx.h | 50 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 2 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 2638b344864c..72c6a78eaed4 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" static bool enable_tdx __ro_after_init; module_param_named(tdx, enable_tdx, bool, 0444); @@ -210,6 +211,21 @@ static int __init vt_init(void) */ hv_init_evmcs(); + /* + * kvm_x86_ops is updated with vt_x86_ops. vt_x86_ops.vm_size must + * be set before kvm_x86_vendor_init(). + */ + vcpu_size = sizeof(struct vcpu_vmx); + vcpu_align = __alignof__(struct vcpu_vmx); + if (enable_tdx) { + vt_x86_ops.vm_size = max_t(unsigned int, vt_x86_ops.vm_size, + sizeof(struct kvm_tdx)); + vcpu_size = max_t(unsigned int, vcpu_size, + sizeof(struct vcpu_tdx)); + vcpu_align = max_t(unsigned int, vcpu_align, + __alignof__(struct vcpu_tdx)); + } + r = kvm_x86_vendor_init(&vt_init_ops); if (r) return r; @@ -222,8 +238,6 @@ static int __init vt_init(void) * Common KVM initialization _must_ come last, after this, /dev/kvm is * exposed to userspace! */ - vcpu_size = sizeof(struct vcpu_vmx); - vcpu_align = __alignof__(struct vcpu_vmx); r = kvm_init(vcpu_size, vcpu_align, THIS_MODULE); if (r) goto err_kvm_init; diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 965545a308ad..19d5656b9cb0 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -6,6 +6,7 @@ #include "capabilities.h" #include "x86_ops.h" #include "x86.h" +#include "tdx.h" #undef pr_fmt #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt diff --git a/arch/x86/kvm/vmx/tdx.h b/arch/x86/kvm/vmx/tdx.h new file mode 100644 index 000000000000..2210c8c1e893 --- /dev/null +++ b/arch/x86/kvm/vmx/tdx.h @@ -0,0 +1,50 @@ +/* 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) +{ + return kvm->arch.vm_type == KVM_X86_PROTECTED_VM; +} + +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