Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2622637rdg; Mon, 16 Oct 2023 09:39:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHAzFKBy43N7/ceJhG70KEEwB6g/+OFA+PZW+qYjo1d6V8VK5LcqaRq148oLdrHwkGy/Iod X-Received: by 2002:a17:90b:1c02:b0:27d:7f1b:1bf1 with SMTP id oc2-20020a17090b1c0200b0027d7f1b1bf1mr2778614pjb.32.1697474366798; Mon, 16 Oct 2023 09:39:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697474366; cv=none; d=google.com; s=arc-20160816; b=FKhYWiQIPScnOkDbEM/06KA9+bylzedpsRh/uDfmcZ69HY+TOkIs2yJbVVxFKj//hM kszmmYeDt7UxBKU/hu9aqzbQHjd3eGOiak/2RY4uTTTdG8kRjQMnfhM2oNo9AgayZmRY /YnaWZD5gnKmIFmEZefqEHoq6AkKMthlUfv9oVzGmDIebs/FpcFw5CdAZ+O2a+cnbelz 04F0+7szC0jy5HQGfiQtC7c29DD4j+9p9XsTPNkjs/Tswqw+JNOayqfw5S1nlAvOkrsR nGZh4ZrFTudhmrZvfNbs6m4JB6m+l5nkC+BnQJ4AmqCamCNaZ6FL2YSq6Zfbtp4R7JNZ S4gA== 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=lNtxR4NXyTpyORuLQPaX4llL6nFjiNgmRNw60VcGAVc=; fh=lRdU2Q/1zx5DcPdZuWBjshA5VT5Oc9cEhB1tCFiV0Nw=; b=ZuTYr3WTLBhkVcFSBZFxkL86YKn1eAhdt8dCh815qcNQHUn91s8kitGOihESrZ0C0N GFGVY7JwWVFeDChTW34fGP6cs4cxHkh1R74mZ0ik5k53hoyC//wkAiXntsLLxJ7CqF8S NhIJio59IvkjrTp/UXGOLrmRv5p1r8XH2rrekmb9icLhdlUIrhsytKnS+WGpVyE9gPP+ dmiARUB1MyyAAb5R2aXQHS6QwivsMHLeDXhZtOhUEg+WeWOoww8te2eMDqzMJhbWJKCA wlFSaplykisVqeMFZvf15pSsAl+hz0mwoQeaOZlEHb3cMWUjHBlf2bjLofryFERLcrKF kGOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dmogTcr5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id pi15-20020a17090b1e4f00b00276b35bc424si6836511pjb.26.2023.10.16.09.39.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 09:39:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dmogTcr5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 00D93802C7F7; Mon, 16 Oct 2023 09:39:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234085AbjJPQjU (ORCPT + 99 others); Mon, 16 Oct 2023 12:39:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234609AbjJPQhp (ORCPT ); Mon, 16 Oct 2023 12:37:45 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4B391BD7; Mon, 16 Oct 2023 09:19:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697473193; x=1729009193; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2MenNoRfM+kDUQw1mfErociIuakJ6BBFYWLA5yUYfYM=; b=dmogTcr5INXaRQpdufxFcYcctnV9PCSUnp/uFOOgQuwvL+TiOO/CVNzE ZFr9+8is1bwoKRm/trDv8jpJhE5VTZv+SUjh/KQnb7ZqP1baubqPq6JBa K+rpmK7A+F8gH1Bb2ySVDnJKUv2y03xnaVJLzbw0b2WrnNYVUj66GrUcQ HUq3QwO3kcgC3PS4agHv2aQj8E4xflWqklHU+VU5QeKWJcmy7EEQR7Jol qIWp8Ui3hHTIc5xPP2PtDUT6QESAiK/Q9dmGcqYDjJPTu0JeqD5b30eSX HCISFAzRBE8QDJEs8qn1HXjuEr+nYEOUH9V502MdJQyEnoxw8PSWZYnvn A==; X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="365825882" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="365825882" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:15:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="1087125977" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="1087125977" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:15:23 -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, hang.yuan@intel.com, tina.zhang@intel.com Subject: [PATCH v16 006/116] KVM: TDX: Add placeholders for TDX VM/vcpu structure Date: Mon, 16 Oct 2023 09:13:18 -0700 Message-Id: <5ef4e8cdd63c5eff306cd2251192848eca658c89.1697471314.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=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 16 Oct 2023 09:39:26 -0700 (PDT) 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 --- v14 -> v15: - use KVM_X86_TDX_VM --- 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 14ab7d5cdded..1d423abd124b 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 = vmx_init(); if (r) goto err_vmx_init; @@ -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 8a378fb6f1d4..1c9884164566 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..473013265bd8 --- /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_TDX_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