Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1173993rbb; Mon, 26 Feb 2024 00:36:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV7/eKkeXY2PwEoikL7Do/HCyuAGNN3L3/3cHivasEIGE+A0QbBancI17mRJ8XARZqslryKxoKC8Gn0Y/Fn4dS1A8eNphJ1pUJ7lZOjjw== X-Google-Smtp-Source: AGHT+IGGcr8cUnXz8RjaSXCbQN0/BTXg8Hp3JHwd5EUHvUIsc7iXBPB/DncmBoR3SaKbe6p6n3tS X-Received: by 2002:a17:90a:ea17:b0:29a:2146:70ed with SMTP id w23-20020a17090aea1700b0029a214670edmr3647787pjy.22.1708936586769; Mon, 26 Feb 2024 00:36:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708936586; cv=pass; d=google.com; s=arc-20160816; b=xTxdYgY46zvSjC9jwqg+i4/YwxE8ikvFwmovlgxO5CgHczB0sAdO7Vt6RmX24NP2DZ +Rti9aCiYcPNfVbw0dQdOnHMjp36VVoIdQrnaT41ZGUniVSTZvVORoLmpyrigjBajklu uVWWsApwvvmlfWPhwcoQZ4bTxeyaHCyhTzCzkdpKF6dS95lsz3O6VwWzW/xLSIKgShf1 zeRbn7pJeHi4SwnP+deWiC910hYNVeoJuUnihPbsjXkDYmjBV4vjbsXcVSZFlypir0z+ ANkem4tBQINF+lDlLR4W3Dp2is6woVYEl05KcD9BDxpM7pgrO0AR2yqCtMsrz3OJO0zY zu+g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=w2kpTuks/ZrV1ZoOsYo0W27tYFlSZ9SAWtn/Fa2fbi0=; fh=Itbyk7CEvizIrzGEESCqq3I2tZgG1kc/GkVOa3S7Hsg=; b=cDMJZ3RiqmqcaCAOKwyF5gqu03csYHoygCVyCo3E2+Z3RXYnZb4CsrKudoQU8Ogrty GHBHOsYH/vptQFI17T92kPMF2UCyLlv5pakij0wpVf/W6JRiWTpyHQjEd3+koQtdP/PT /DYAcI3suQ6jy2BvvrWV+ELAkYgSFZr8MDQD4DsANl3i6qBka3x2XJkvvLxeI/Ah5/ZC eFLs+v13o3WospZ/Iyno50VL/u31P7G6PI0/pEF1XhZ24fswRKJIr2Era6qjOVphQvvl wkG6IdAOsJ814iYho0durzabZmB6A8nAUoIGlFO6cnrbh5MW2wW1O45+ETIbDF1hzT1f UudQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WC0e7zAt; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-80785-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80785-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id p16-20020a17090ad31000b0029a64380aefsi5240974pju.114.2024.02.26.00.36.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 00:36:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80785-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WC0e7zAt; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-80785-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80785-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D1C9F283EAE for ; Mon, 26 Feb 2024 08:35:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AFD5C56470; Mon, 26 Feb 2024 08:27:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WC0e7zAt" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B3F854FB0; Mon, 26 Feb 2024 08:27:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936075; cv=none; b=qxu6Wn0FRrHDAzyqugHYK91UN33euYL0OzqmpeU+08sJEqL0Rad62248IX/3NZceuUNbP8gbn7d8b4YcKvctLKqnNv5AxJ9hH66hR2b86GiXiw5xKBfhcreJOVJlrDNhgW6YDkGY6ZegRYg01yzdcPsFYjaSkdQzKNEKANQ/MiE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936075; c=relaxed/simple; bh=t8ZVY21QvgWkqCaFflB5Ky+24TTmKzW3GvfNfpp1CgI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cXAhaZxf+PLqiz8v2NulK7WOuUaJKNMpg+RBSwO7lG9I3RQvS6A1oyn1tAq8m8wviLE6NqfGElCuvmpP0fTiNzQU4odndlOH6YV4AwJS/LKpyMvXtAzD7ktjiSMz7/qs/c/FRMCZXlV/ZDFupCyj10oGnCN7QkN9dESEfZPEfC8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=WC0e7zAt; arc=none smtp.client-ip=192.198.163.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708936073; x=1740472073; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=t8ZVY21QvgWkqCaFflB5Ky+24TTmKzW3GvfNfpp1CgI=; b=WC0e7zAtCJC0BzdkTeCrcqmVEQpLEw0reBZ//ZZVZqHzn2JE6KMzHY9r E57vixUr4CbFcem13VbJqGzdtnyZM9NkO1LlQd1fIN9jZbbhEvM/Y/y+J JOlIghoTFh8Vhp4tbOuYoiQ9nbkRV6NXnro8s81v+PryHlYD7SMuDvoYR mGjm55NxZ/v04dkypIbQkcYAmDEJFJ6TYOJVTLSxDbYscqkxsebPjdm7v zGs8wrO4qvF1Mx1+ormZWDzwvZjp4UEiWaLPEADyGjozkw8bxaiCOlbaR C462iROSAB05aU5xX14HNvNzsM7bDt5b8zTrFKi0/eI1y7mpzQHsW/tFF A==; X-IronPort-AV: E=McAfee;i="6600,9927,10995"; a="6155242" X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="6155242" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:27:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="6615452" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:27:51 -0800 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 , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com Subject: [PATCH v19 024/130] KVM: TDX: Add placeholders for TDX VM/vcpu structure Date: Mon, 26 Feb 2024 00:25:26 -0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- v19: - correctly update ops.vm_size, vcpu_size and, vcpu_align by Xiaoyao v14 -> v15: - use KVM_X86_TDX_VM Signed-off-by: Isaku Yamahata --- arch/x86/kvm/vmx/main.c | 14 ++++++++++++ arch/x86/kvm/vmx/tdx.c | 1 + arch/x86/kvm/vmx/tdx.h | 50 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) 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 18aef6e23aab..e11edbd19e7c 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); @@ -18,6 +19,9 @@ static __init int vt_hardware_setup(void) return ret; enable_tdx = enable_tdx && !tdx_hardware_setup(&vt_x86_ops); + if (enable_tdx) + vt_x86_ops.vm_size = max_t(unsigned int, vt_x86_ops.vm_size, + sizeof(struct kvm_tdx)); return 0; } @@ -215,8 +219,18 @@ static int __init vt_init(void) * Common KVM initialization _must_ come last, after this, /dev/kvm is * exposed to userspace! */ + /* + * 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) { + 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_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 43c504fb4fed..14ef0ccd8f1a 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