From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730788680; cv=none; d=zohomail.com; s=zohoarc; b=JTW+yUSIu3g50DgGSxaQO0PQyzPjFs9wZ2AZqEQYjhWJHoeLPYwPvCxDfjwJ3RFKpJvnskQ6LalzgJB+GdkKiNqgjNppizjVvrwiJ0xdS6ZSLLB5LJjV97BgKlRTzaGckUJEwJqBW0eT4avfYdSpZXxWVk/04ZQXGjR4TP+p4RA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730788680; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1r0DiLFqDSP5s6zSoM03y0FIbGd5F9giS7fVT1h/Nnk=; b=Gxe7fc149WaZRW5/yjTiHFy32tNMv1OjCqwdAe7WEy1MD8Ouw35k+GW2OeDnMJbSSaCeFaRo6omo4rvizEPDjdGJB5cdybq7r0E9TPAfRdrZdNHXjHuZR51qn2uv9+aELfuVsj4PdmRy0PcBXlQsgMcX4aPXA3mNv1Vq5xEG25M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730788680064621.4140689742901; Mon, 4 Nov 2024 22:38:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DB0-0004Oc-QY; Tue, 05 Nov 2024 01:36:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DAy-0004O9-To for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:36:28 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DAx-0001nl-6J for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:36:28 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:36:26 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:36:22 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788587; x=1762324587; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=g+h4bo1XqzDmMZ0LZa6Xv9bp3PCsN0+TI6VIrKIylhs=; b=KKDcGj22k2NUx0kQFfqCUrQiDrOFvg22DEVzDEMovgv7P0NIqxbh/oNg fC5E3NCBElKOVou5/3MXKcAm2HClJExOdLwKcEO/Y1ZxWtbR2T+dI1dDd wN+I+1ufbB9MJQcTYRfnvRaocdRxLt+gpkacj4//NKWzHH5zYWBKTKP1x ZxBXYhCAqHSOULfd1U6Z7OxaXseTQk2fWHO6Az5oGq6sBF95LHzfDkSXh p5cvn9objqh5WMf/c5dwVVRBOipTbu7GvIGrCEhQp84Nxkqp7du3dDgPa 8RFUjQiiZt94lMeEYDe9xL6FiFnjReVChGs+9L5ymSqWqLEYwy+C7bv5Y Q==; X-CSE-ConnectionGUID: /uCogON6SlWdl8Pcex5UaA== X-CSE-MsgGUID: ShDe38bUSfm5NDOhJNGRBQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689213" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689213" X-CSE-ConnectionGUID: dzGKxjZRRju1K3R3NN9uKw== X-CSE-MsgGUID: B+woiuUfTM68IGRpM3+trQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83988551" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 01/60] *** HACK *** linux-headers: Update headers to pull in TDX API changes Date: Tue, 5 Nov 2024 01:23:09 -0500 Message-Id: <20241105062408.3533704-2-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730788681451116600 Content-Type: text/plain; charset="utf-8" Pull in recent TDX updates, which are not backwards compatible. It's just to make this series runnable. It will be updated by script scripts/update-linux-headers.sh once TDX support is upstreamed in linux kernel Signed-off-by: Xiaoyao Li --- linux-headers/asm-x86/kvm.h | 70 +++++++++++++++++++++++++++++++++++++ linux-headers/linux/kvm.h | 1 + 2 files changed, 71 insertions(+) diff --git a/linux-headers/asm-x86/kvm.h b/linux-headers/asm-x86/kvm.h index 4711ef2c3d01..719b9d121dbe 100644 --- a/linux-headers/asm-x86/kvm.h +++ b/linux-headers/asm-x86/kvm.h @@ -922,5 +922,75 @@ struct kvm_hyperv_eventfd { #define KVM_X86_SEV_VM 2 #define KVM_X86_SEV_ES_VM 3 #define KVM_X86_SNP_VM 4 +#define KVM_X86_TDX_VM 5 + +/* Trust Domain eXtension sub-ioctl() commands. */ +enum kvm_tdx_cmd_id { + KVM_TDX_CAPABILITIES =3D 0, + KVM_TDX_INIT_VM, + KVM_TDX_INIT_VCPU, + KVM_TDX_INIT_MEM_REGION, + KVM_TDX_FINALIZE_VM, + KVM_TDX_GET_CPUID, + + KVM_TDX_CMD_NR_MAX, +}; + +struct kvm_tdx_cmd { + /* enum kvm_tdx_cmd_id */ + __u32 id; + /* flags for sub-commend. If sub-command doesn't use this, set zero. */ + __u32 flags; + /* + * data for each sub-command. An immediate or a pointer to the actual + * data in process virtual address. If sub-command doesn't use it, + * set zero. + */ + __u64 data; + /* + * Auxiliary error code. The sub-command may return TDX SEAMCALL + * status code in addition to -Exxx. + * Defined for consistency with struct kvm_sev_cmd. + */ + __u64 hw_error; +}; + +struct kvm_tdx_capabilities { + __u64 supported_attrs; + __u64 supported_xfam; + __u64 reserved[254]; + struct kvm_cpuid2 cpuid; +}; + +struct kvm_tdx_init_vm { + __u64 attributes; + __u64 xfam; + __u64 mrconfigid[6]; /* sha384 digest */ + __u64 mrowner[6]; /* sha384 digest */ + __u64 mrownerconfig[6]; /* sha384 digest */ + + /* The total space for TD_PARAMS before the CPUIDs is 256 bytes */ + __u64 reserved[12]; + + /* + * Call KVM_TDX_INIT_VM before vcpu creation, thus before + * KVM_SET_CPUID2. + * This configuration supersedes KVM_SET_CPUID2s for VCPUs because the + * TDX module directly virtualizes those CPUIDs without VMM. The user + * space VMM, e.g. qemu, should make KVM_SET_CPUID2 consistent with + * those values. If it doesn't, KVM may have wrong idea of vCPUIDs of + * the guest, and KVM may wrongly emulate CPUIDs or MSRs that the TDX + * module doesn't virtualize. + */ + struct kvm_cpuid2 cpuid; +}; + +#define KVM_TDX_MEASURE_MEMORY_REGION _BITULL(0) + +struct kvm_tdx_init_mem_region { + __u64 source_addr; + __u64 gpa; + __u64 nr_pages; +}; =20 #endif /* _ASM_X86_KVM_H */ diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index 49dd1b30ce9e..ebad8e0d10c5 100644 --- a/linux-headers/linux/kvm.h +++ b/linux-headers/linux/kvm.h @@ -369,6 +369,7 @@ struct kvm_run { #define KVM_SYSTEM_EVENT_WAKEUP 4 #define KVM_SYSTEM_EVENT_SUSPEND 5 #define KVM_SYSTEM_EVENT_SEV_TERM 6 +#define KVM_SYSTEM_EVENT_TDX_FATAL 7 __u32 type; __u32 ndata; union { --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730788622; cv=none; d=zohomail.com; s=zohoarc; b=R3zGbPqoc9l/FcZqFZM3hRNU6Wuf7mISr5RcQ5HB9UMxOhnjyFY/MOe1FACW+QIK9ymsar7CrP8QRXOgICWQwwOVfaOf6Wq34wgs/xkzeYapZkik3rx46XoHh3zYZ3JQ0cuSTjbSBKMSUwDUGOKnuQyiaZi8WcMCRHNca+AWrwM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730788622; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MOidNYvzEGC8C1YUqXDyQiFs9RfrJFFBGHy6oaKmttg=; b=gdWUruZ/T5mOiVc4Gj1bhwQETyhXi34q+9RjL6I5qnyECM3e2xna9dDtP2+sWi3OpcAnIzAkwZ9LvJdc5e49IAkKT9vp1WcUHe4kId8/Hhcroo5XfxesINvxs+jnH17ndmR7FdPBRdKQK8w4Thfy2I/6CdFiIy44e9L1PCAuCv4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730788622487267.3144910552038; Mon, 4 Nov 2024 22:37:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DB5-0004P8-An; Tue, 05 Nov 2024 01:36:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DB3-0004Oq-GH for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:36:33 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DB1-0001oZ-I9 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:36:33 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:36:30 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:36:26 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788592; x=1762324592; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DWbz/FsnKhNwDGpwgnzLBuoDZpAUd28LILimRe0bFmc=; b=cekHXmx/kF8+L+zLrd3tdikBJb5+3iQmbXpqegcP9N8ovwdLsph/Ll+Z ZlzS3G4YBTAWyG4TjWxvb4Cv9f+7UOORBF5Wb1isXUtrRF+vME2xWJtV4 6xEp0bDqOrBVo9rVI6RnGpGMwJP7vGo+0REjjdNiQTucn7cE1WOPkwOPB L97e2y2qRzQNzH1v0bMM6uWPPD77a1x1TJ0QF9CiTQ1WOyr33I3n52iIk VfH9ZJOAEP6V0uvPH6YAi1jr/yTWEWtCvu0JpHPPUDTGxbZXB6wZuTGV1 A7nTw15OHCfgq6Y6qjvgJkoj+sdIeLjZzX6gI4E+9IpzE2+iKy4eU4YxT A==; X-CSE-ConnectionGUID: RGEz5ysqSDq8VW3SkZDKnw== X-CSE-MsgGUID: fWz5/JrZTqyw9EZ/nHQKJA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689221" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689221" X-CSE-ConnectionGUID: Tt4I96uARDOpGhbeK3+VRQ== X-CSE-MsgGUID: 17l9xoadQhiPBHnWfFfj5A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83988564" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 02/60] i386: Introduce tdx-guest object Date: Tue, 5 Nov 2024 01:23:10 -0500 Message-Id: <20241105062408.3533704-3-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730788624458116600 Content-Type: text/plain; charset="utf-8" Introduce tdx-guest object which inherits X86_CONFIDENTIAL_GUEST, and will be used to create TDX VMs (TDs) by qemu -machine ...,confidential-guest-support=3Dtdx0 \ -object tdx-guest,id=3Dtdx0 It has one QAPI member 'attributes' defined, which allows user to set TD's attributes directly. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann Acked-by: Markus Armbruster --- Chanegs in v6: - Make tdx-guest inherits X86_CONFIDENTIAL_GUEST; - set cgs->require_guest_memfd; - allow attributes settable via QAPI; - update QAPI version to since 9.2; Changes in v4: - update the new qapi `since` filed from 8.2 to 9.0 Changes in v1 - make @attributes not user-settable --- configs/devices/i386-softmmu/default.mak | 1 + hw/i386/Kconfig | 5 +++ qapi/qom.json | 15 ++++++++ target/i386/kvm/meson.build | 2 ++ target/i386/kvm/tdx.c | 45 ++++++++++++++++++++++++ target/i386/kvm/tdx.h | 19 ++++++++++ 6 files changed, 87 insertions(+) create mode 100644 target/i386/kvm/tdx.c create mode 100644 target/i386/kvm/tdx.h diff --git a/configs/devices/i386-softmmu/default.mak b/configs/devices/i38= 6-softmmu/default.mak index 4faf2f0315e2..bc0479a7e0a3 100644 --- a/configs/devices/i386-softmmu/default.mak +++ b/configs/devices/i386-softmmu/default.mak @@ -18,6 +18,7 @@ #CONFIG_QXL=3Dn #CONFIG_SEV=3Dn #CONFIG_SGA=3Dn +#CONFIG_TDX=3Dn #CONFIG_TEST_DEVICES=3Dn #CONFIG_TPM_CRB=3Dn #CONFIG_TPM_TIS_ISA=3Dn diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig index 32818480d263..86bc10377c4f 100644 --- a/hw/i386/Kconfig +++ b/hw/i386/Kconfig @@ -10,6 +10,10 @@ config SGX bool depends on KVM =20 +config TDX + bool + depends on KVM + config PC bool imply APPLESMC @@ -26,6 +30,7 @@ config PC imply QXL imply SEV imply SGX + imply TDX imply TEST_DEVICES imply TPM_CRB imply TPM_TIS_ISA diff --git a/qapi/qom.json b/qapi/qom.json index 321ccd708ad1..129b25edf495 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -1008,6 +1008,19 @@ '*host-data': 'str', '*vcek-disabled': 'bool' } } =20 +## +# @TdxGuestProperties: +# +# Properties for tdx-guest objects. +# +# @attributes: The 'attributes' of a TD guest that is passed to +# KVM_TDX_INIT_VM +# +# Since: 9.2 +## +{ 'struct': 'TdxGuestProperties', + 'data': { '*attributes': 'uint64' } } + ## # @ThreadContextProperties: # @@ -1092,6 +1105,7 @@ 'sev-snp-guest', 'thread-context', 's390-pv-guest', + 'tdx-guest', 'throttle-group', 'tls-creds-anon', 'tls-creds-psk', @@ -1163,6 +1177,7 @@ 'if': 'CONFIG_SECRET_KEYRING' }, 'sev-guest': 'SevGuestProperties', 'sev-snp-guest': 'SevSnpGuestProperties', + 'tdx-guest': 'TdxGuestProperties', 'thread-context': 'ThreadContextProperties', 'throttle-group': 'ThrottleGroupProperties', 'tls-creds-anon': 'TlsCredsAnonProperties', diff --git a/target/i386/kvm/meson.build b/target/i386/kvm/meson.build index 3996cafaf29f..466bccb9cb17 100644 --- a/target/i386/kvm/meson.build +++ b/target/i386/kvm/meson.build @@ -8,6 +8,8 @@ i386_kvm_ss.add(files( =20 i386_kvm_ss.add(when: 'CONFIG_XEN_EMU', if_true: files('xen-emu.c')) =20 +i386_kvm_ss.add(when: 'CONFIG_TDX', if_true: files('tdx.c')) + i386_system_ss.add(when: 'CONFIG_HYPERV', if_true: files('hyperv.c'), if_f= alse: files('hyperv-stub.c')) =20 i386_system_ss.add_all(when: 'CONFIG_KVM', if_true: i386_kvm_ss) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c new file mode 100644 index 000000000000..166f53d2b9e3 --- /dev/null +++ b/target/i386/kvm/tdx.c @@ -0,0 +1,45 @@ +/* + * QEMU TDX support + * + * Copyright Intel + * + * Author: + * Xiaoyao Li + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory + * + */ + +#include "qemu/osdep.h" +#include "qom/object_interfaces.h" + +#include "tdx.h" + +/* tdx guest */ +OBJECT_DEFINE_TYPE_WITH_INTERFACES(TdxGuest, + tdx_guest, + TDX_GUEST, + X86_CONFIDENTIAL_GUEST, + { TYPE_USER_CREATABLE }, + { NULL }) + +static void tdx_guest_init(Object *obj) +{ + ConfidentialGuestSupport *cgs =3D CONFIDENTIAL_GUEST_SUPPORT(obj); + TdxGuest *tdx =3D TDX_GUEST(obj); + + cgs->require_guest_memfd =3D true; + tdx->attributes =3D 0; + + object_property_add_uint64_ptr(obj, "attributes", &tdx->attributes, + OBJ_PROP_FLAG_READWRITE); +} + +static void tdx_guest_finalize(Object *obj) +{ +} + +static void tdx_guest_class_init(ObjectClass *oc, void *data) +{ +} diff --git a/target/i386/kvm/tdx.h b/target/i386/kvm/tdx.h new file mode 100644 index 000000000000..de687457cae6 --- /dev/null +++ b/target/i386/kvm/tdx.h @@ -0,0 +1,19 @@ +#ifndef QEMU_I386_TDX_H +#define QEMU_I386_TDX_H + +#include "confidential-guest.h" + +#define TYPE_TDX_GUEST "tdx-guest" +#define TDX_GUEST(obj) OBJECT_CHECK(TdxGuest, (obj), TYPE_TDX_GUEST) + +typedef struct TdxGuestClass { + X86ConfidentialGuestClass parent_class; +} TdxGuestClass; + +typedef struct TdxGuest { + X86ConfidentialGuest parent_obj; + + uint64_t attributes; /* TD attributes */ +} TdxGuest; + +#endif /* QEMU_I386_TDX_H */ --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730788620; cv=none; d=zohomail.com; s=zohoarc; b=Jov1Kq/g1O4q02BjfKX18lOUoXjBBiuKhNiqFjWRTc9RIp/+H/NunMdp1eNBy5qegMBS8TOvw9uCW61DyJI/xAuYuu1toZxgeWqUkJbVzffCHqVWPjCLrI4fh+m2W7mo00bYDO+08/m5QR6W8Yk1A/kIvI+9tQQuchETd5/DXhw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730788620; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=RlOKdb3AqpOyZuuL08G09cGptl8u0PBmobS6WS9+1Fk=; b=MmSNqRoyT/yV4LwhFQZiBkQxxgT3RQ9olt48b5vWY97XtbO1AgeHT4vPhyObE8hkNVKJWw3v2G+mZYjC9dzGGm46e3fgxs68l4AmmC+9S+hFtohMMbiw7tP+1NoZ3HidWrbwuDetw8yhlM1C7sPQYw1GmxINCAVCeDPW/IQWDM8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730788620801547.1237625619877; Mon, 4 Nov 2024 22:37:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DB9-0004Q2-LG; Tue, 05 Nov 2024 01:36:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DB8-0004Pn-E8 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:36:38 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DB5-0001oZ-6B for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:36:36 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:36:34 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:36:30 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788595; x=1762324595; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OubJ0frbbHV7MSdZrZwfSjPq/m9f7s+BIewp1R/ME4Y=; b=nKEItd8WY9rz/M7avxEAoDoib+5VuQJYaJ6vYJIc+AOely5D6vUaksKo sF04kqa3K4zRFePPhC11DTc5E2gNeZce33eerFEv034J7NQQFmuksZK+o aSKreNXKlAK9PDe7PNMjj3Tq56d7lusWgaD1TwQy/J7NccnmLxwYOoNnf 5yAC1dwSTXpskIf1H16Nn3OWRRRTiy0nxUzAQ6p58dPFS0fnkNlxdGUmR U3jRGfdqQx6KJDPEhUThL4pUf94yoiU9e+fl168qkPEZw+4uuibVDSFeS x2bO0F1RK6l1L34MfTLDSDedkNbZ0cy/x6cY/CQIbLByv+QsQRsmK/Nrf Q==; X-CSE-ConnectionGUID: C4debQkoTpaW178/wEng6w== X-CSE-MsgGUID: gpzjIAbXRP2UN3G67KGInw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689238" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689238" X-CSE-ConnectionGUID: xfz50WFbT2mM6g0uRJBg8A== X-CSE-MsgGUID: 23LnzFrqQVehOjvo+qmMZw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83988589" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 03/60] i386/tdx: Implement tdx_kvm_type() for TDX Date: Tue, 5 Nov 2024 01:23:11 -0500 Message-Id: <20241105062408.3533704-4-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730788622473116600 Content-Type: text/plain; charset="utf-8" TDX VM requires VM type to be KVM_X86_TDX_VM. Implement tdx_kvm_type() as X86ConfidentialGuestClass->kvm_type. Signed-off-by: Xiaoyao Li --- Changes in v6: - new added patch; --- target/i386/kvm/kvm.c | 1 + target/i386/kvm/tdx.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 8e17942c3ba1..ed2e89946c44 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -194,6 +194,7 @@ static const char *vm_type_name[] =3D { [KVM_X86_SEV_VM] =3D "SEV", [KVM_X86_SEV_ES_VM] =3D "SEV-ES", [KVM_X86_SNP_VM] =3D "SEV-SNP", + [KVM_X86_TDX_VM] =3D "TDX", }; =20 bool kvm_is_vm_type_supported(int type) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 166f53d2b9e3..bf8947549a96 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -14,8 +14,17 @@ #include "qemu/osdep.h" #include "qom/object_interfaces.h" =20 +#include "kvm_i386.h" #include "tdx.h" =20 +static int tdx_kvm_type(X86ConfidentialGuest *cg) +{ + /* Do the object check */ + TDX_GUEST(cg); + + return KVM_X86_TDX_VM; +} + /* tdx guest */ OBJECT_DEFINE_TYPE_WITH_INTERFACES(TdxGuest, tdx_guest, @@ -42,4 +51,7 @@ static void tdx_guest_finalize(Object *obj) =20 static void tdx_guest_class_init(ObjectClass *oc, void *data) { + X86ConfidentialGuestClass *x86_klass =3D X86_CONFIDENTIAL_GUEST_CLASS(= oc); + + x86_klass->kvm_type =3D tdx_kvm_type; } --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730788624; cv=none; d=zohomail.com; s=zohoarc; b=EqEiB5O+k//B56sHD0mFJui7PK99mhqPErFE1c87b5LMGwDriPRAJ49rcZedMerfqwrG8EPfUjyJKNmlV5wOxwNcXMrF0pcsKCdel7WwJSX3gWw9DYYl0X1Sm8sCHErPqnK6qEIpDn3i87j0IjggAHMwNFIBbBnN6bvJULe3t3E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730788624; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=bjVUYS3PT38qdj74ngrrHcz9d0w4sSY87Heel0nPmr0=; b=TAte4xZxXZrPB42NeWgyXwbSgkU2wj2l05/8UvbOafq5tUITza2lTPRCcDcjT86rZpcLUDHbrDRgkIc1GiMhId+5Q9/F5P0FSgSIFJjEx948W3cHLgJ63QDKW7gU1nuTdwDQdwl3ZSH+OHEihoGh8iiwKN+27tYbX0tmfcBXLkY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730788624765700.5985473710335; Mon, 4 Nov 2024 22:37:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DBJ-0004Rb-Dn; Tue, 05 Nov 2024 01:36:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBE-0004Qa-5E for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:36:44 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBC-0001oZ-0W for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:36:43 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:36:39 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:36:34 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788602; x=1762324602; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ou+Mdobmm1tQq2ArTm7wdCK4exn2TLAYJgjckbytn0A=; b=Mnc2bvJx6BVs4foH90cXKIfNbZSefP6jMWLqTlNHOb/W474326/BrOoL Pz8VcHIWm4kg8wlVW68Dxz/pTUevBJLViMlIi+Z/vL85F3yM1JdqKldlm gEb0gGwNdGIrATqmVaePunmTDQqCnlEc4u+p8RnjcUaGChUAALuSp6QtZ 9iJrWI6jYHbPIa4Vp7OA/aHZPgSB3jNPIXXf1ODXpurU5UKsb8Qp2V03C Cygle57FeaUW5ISoIUPanLVApqVPpY+29zVhX4drY9kHIRoolC5XBjVx9 nigHFrCRxlbQPbwHkmiwMZtKv0tA0AYW4qTGuTrVeaZd57EiHChlKhAHs g==; X-CSE-ConnectionGUID: Ds17qyEvS7S/cgegM6COBw== X-CSE-MsgGUID: gAvQ3w/7SXywW/kx3Kdh1A== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689257" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689257" X-CSE-ConnectionGUID: r1o3UWJtR+OrzWAUBbZ4Gw== X-CSE-MsgGUID: /2AI0GzRRKefGwjrd6onTg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83988607" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 04/60] i386/tdx: Implement tdx_kvm_init() to initialize TDX VM context Date: Tue, 5 Nov 2024 01:23:12 -0500 Message-Id: <20241105062408.3533704-5-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730788626344116600 Content-Type: text/plain; charset="utf-8" Implement TDX specific ConfidentialGuestSupportClass::kvm_init() callback, tdx_kvm_init(). Mark guest state is proctected for TDX VM. More TDX specific initialization will be added later. Signed-off-by: Xiaoyao Li --- Changes in v6: - remove Acked-by from Gerd since the patch changed due to use ConfidentialGuestSupportClass::kvm_init(); --- target/i386/kvm/kvm.c | 11 +---------- target/i386/kvm/tdx.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index ed2e89946c44..2bbac603da70 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -3204,16 +3204,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s) Error *local_err =3D NULL; =20 /* - * Initialize SEV context, if required - * - * If no memory encryption is requested (ms->cgs =3D=3D NULL) this is - * a no-op. - * - * It's also a no-op if a non-SEV confidential guest support - * mechanism is selected. SEV is the only mechanism available to - * select on x86 at present, so this doesn't arise, but if new - * mechanisms are supported in future (e.g. TDX), they'll need - * their own initialization either here or elsewhere. + * Initialize confidential guest (SEV/TDX) context, if required */ if (ms->cgs) { ret =3D confidential_guest_kvm_init(ms->cgs, &local_err); diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index bf8947549a96..85f006c1d6b4 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -14,9 +14,17 @@ #include "qemu/osdep.h" #include "qom/object_interfaces.h" =20 +#include "hw/i386/x86.h" #include "kvm_i386.h" #include "tdx.h" =20 +static int tdx_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) +{ + kvm_mark_guest_state_protected(); + + return 0; +} + static int tdx_kvm_type(X86ConfidentialGuest *cg) { /* Do the object check */ @@ -51,7 +59,9 @@ static void tdx_guest_finalize(Object *obj) =20 static void tdx_guest_class_init(ObjectClass *oc, void *data) { + ConfidentialGuestSupportClass *klass =3D CONFIDENTIAL_GUEST_SUPPORT_CL= ASS(oc); X86ConfidentialGuestClass *x86_klass =3D X86_CONFIDENTIAL_GUEST_CLASS(= oc); =20 + klass->kvm_init =3D tdx_kvm_init; x86_klass->kvm_type =3D tdx_kvm_type; } --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730788795; cv=none; d=zohomail.com; s=zohoarc; b=d2xfHlaNCOrarzu89RgqHImvHSvs/kUOjNwOLDiu/VFA1tcj6QKelXUBym0P8LQhc7f0GaBU4E9irXyvc8m6XKbJrne1s7G7QZQe6h2Y9m/4xxocPrvudgqXaf+/koFMiybNJFIiWtg3/EWAa0Uxl19piiNgCUkYOx4iR5WV0nk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730788795; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3r9PwJe6YVqZ9EIHM+JUnlYNnJshbuidA+2NbHCIP8c=; b=c0UnuhmYG/61Yqh3CWEpxcjUIwwHaNZiHO+h43SLOnYYGP9gIfWQbl4avohsAzUjxIxwdo4jGzfKnJ696qVkDU1NyG4L+R9WNGCiw3kDXQurLD60ghg0PkSn1GU20qAFUm682hdmWGEYsmqNTIcvytNddDvMSUNaGSRkmcviAfQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17307887957280.6464883419789658; Mon, 4 Nov 2024 22:39:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DBK-0004Rc-Lp; Tue, 05 Nov 2024 01:36:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBH-0004Qp-N1 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:36:47 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBF-0001oZ-PM for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:36:47 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:36:43 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:36:39 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788606; x=1762324606; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0vj+lC4sTbpC830FiXMO0t8VM8X6DjsBEWbC13OZKiM=; b=O2Q2rJ9Vu9ZfD4LI+g2MKQ7JL+uqdTPYq9hCC32jo0Ewx2jc4AS0L3u5 SP2ObJZ37xap/2Pvx2Ty5wp6jc+nk/b1fVUXwk2NaW4pT3xoGbjfIN48q em0mx4ef5zvHcVYqP9LsEzWETG2OE/ILG6mpQgNbSW7VnVxUy/X4cLakb Cn4ftchJlmQwkTk9LLiKEkGXNyBKwHMAxfrZxYuyM+roiHTShOjc7f5nD 3v68ZxYEzWHFGN+CzJJcJsDzKkxujWu0+X1QqG8pjtzKXK9luXRtbHheu bVupumoBcegbPOCF3iHm7tVQ+lXfw10mzyjy+P2mGL/x7gzdVOJV4DtRY Q==; X-CSE-ConnectionGUID: cy6w3+3PQnqzVQH+Mxl0kA== X-CSE-MsgGUID: wO31TQHKSIOAgpLx3nYuDA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689275" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689275" X-CSE-ConnectionGUID: 3W+DpMZgTHWMuO4ZzHvdzA== X-CSE-MsgGUID: 6O5LboUeRWak91gSXFK5fQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83988621" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 05/60] i386/tdx: Get tdx_capabilities via KVM_TDX_CAPABILITIES Date: Tue, 5 Nov 2024 01:23:13 -0500 Message-Id: <20241105062408.3533704-6-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730788797063116600 Content-Type: text/plain; charset="utf-8" KVM provides TDX capabilities via sub command KVM_TDX_CAPABILITIES of IOCTL(KVM_MEMORY_ENCRYPT_OP). Get the capabilities when initializing TDX context. It will be used to validate user's setting later. Since there is no interface reporting how many cpuid configs contains in KVM_TDX_CAPABILITIES, QEMU chooses to try starting with a known number and abort when it exceeds KVM_MAX_CPUID_ENTRIES. Besides, introduce the interfaces to invoke TDX "ioctls" at VCPU scope in preparation. Signed-off-by: Xiaoyao Li --- Changes in v6: - Pass CPUState * to tdx_vcpu_ioctl(); - update commit message to remove platform scope thing; - dump hw_error when it's non-zero to help debug; Changes in v4: - use {} to initialize struct kvm_tdx_cmd, to avoid memset(); - remove tdx_platform_ioctl() because no user; Changes in v3: - rename __tdx_ioctl() to tdx_ioctl_internal() - Pass errp in get_tdx_capabilities(); changes in v2: - Make the error message more clear; changes in v1: - start from nr_cpuid_configs =3D 6 for the loop; - stop the loop when nr_cpuid_configs exceeds KVM_MAX_CPUID_ENTRIES; --- target/i386/kvm/kvm.c | 2 - target/i386/kvm/kvm_i386.h | 2 + target/i386/kvm/tdx.c | 93 +++++++++++++++++++++++++++++++++++++- 3 files changed, 94 insertions(+), 3 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 2bbac603da70..b843de7f2379 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1782,8 +1782,6 @@ static int hyperv_init_vcpu(X86CPU *cpu) =20 static Error *invtsc_mig_blocker; =20 -#define KVM_MAX_CPUID_ENTRIES 100 - static void kvm_init_xsave(CPUX86State *env) { if (has_xsave2) { diff --git a/target/i386/kvm/kvm_i386.h b/target/i386/kvm/kvm_i386.h index 9de9c0d30388..7ac4c3a91171 100644 --- a/target/i386/kvm/kvm_i386.h +++ b/target/i386/kvm/kvm_i386.h @@ -13,6 +13,8 @@ =20 #include "sysemu/kvm.h" =20 +#define KVM_MAX_CPUID_ENTRIES 100 + #ifdef CONFIG_KVM =20 #define kvm_pit_in_kernel() \ diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 85f006c1d6b4..907044910fec 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -12,17 +12,108 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/error-report.h" +#include "qapi/error.h" #include "qom/object_interfaces.h" =20 #include "hw/i386/x86.h" #include "kvm_i386.h" #include "tdx.h" =20 +static struct kvm_tdx_capabilities *tdx_caps; + +enum tdx_ioctl_level { + TDX_VM_IOCTL, + TDX_VCPU_IOCTL, +}; + +static int tdx_ioctl_internal(enum tdx_ioctl_level level, void *state, + int cmd_id, __u32 flags, void *data) +{ + struct kvm_tdx_cmd tdx_cmd =3D {}; + int r; + + tdx_cmd.id =3D cmd_id; + tdx_cmd.flags =3D flags; + tdx_cmd.data =3D (__u64)(unsigned long)data; + + switch (level) { + case TDX_VM_IOCTL: + r =3D kvm_vm_ioctl(kvm_state, KVM_MEMORY_ENCRYPT_OP, &tdx_cmd); + break; + case TDX_VCPU_IOCTL: + r =3D kvm_vcpu_ioctl(state, KVM_MEMORY_ENCRYPT_OP, &tdx_cmd); + break; + default: + error_report("Invalid tdx_ioctl_level %d", level); + exit(1); + } + + if (r && tdx_cmd.hw_error) { + error_report("TDX ioctl %d return with %d, hw_errors: 0x%llx", + cmd_id, r, tdx_cmd.hw_error); + } + return r; +} + +static inline int tdx_vm_ioctl(int cmd_id, __u32 flags, void *data) +{ + return tdx_ioctl_internal(TDX_VM_IOCTL, NULL, cmd_id, flags, data); +} + +static inline int tdx_vcpu_ioctl(CPUState *cpu, int cmd_id, __u32 flags, + void *data) +{ + return tdx_ioctl_internal(TDX_VCPU_IOCTL, cpu, cmd_id, flags, data); +} + +static int get_tdx_capabilities(Error **errp) +{ + struct kvm_tdx_capabilities *caps; + /* 1st generation of TDX reports 6 cpuid configs */ + int nr_cpuid_configs =3D 6; + size_t size; + int r; + + do { + size =3D sizeof(struct kvm_tdx_capabilities) + + nr_cpuid_configs * sizeof(struct kvm_cpuid_entry2); + caps =3D g_malloc0(size); + caps->cpuid.nent =3D nr_cpuid_configs; + + r =3D tdx_vm_ioctl(KVM_TDX_CAPABILITIES, 0, caps); + if (r =3D=3D -E2BIG) { + g_free(caps); + nr_cpuid_configs *=3D 2; + if (nr_cpuid_configs > KVM_MAX_CPUID_ENTRIES) { + error_setg(errp, "%s: KVM TDX seems broken that number of = CPUID" + " entries in kvm_tdx_capabilities exceeds limit= %d", + __func__, KVM_MAX_CPUID_ENTRIES); + return r; + } + } else if (r < 0) { + g_free(caps); + error_setg_errno(errp, -r, "%s: KVM_TDX_CAPABILITIES failed", = __func__); + return r; + } + } while (r =3D=3D -E2BIG); + + tdx_caps =3D caps; + + return 0; +} + static int tdx_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) { + int r =3D 0; + kvm_mark_guest_state_protected(); =20 - return 0; + if (!tdx_caps) { + r =3D get_tdx_capabilities(errp); + } + + return r; } =20 static int tdx_kvm_type(X86ConfidentialGuest *cg) --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789207; cv=none; d=zohomail.com; s=zohoarc; b=JOeAFr+EPWllLj3bZ21viJ4BE6OjFAneyFMFIASvm08iXPunGHnDT83piqtp28wSfy+eIcdlK2jgFZTZL5QzL2TCyOrXTJpZnjgO9J+9A7gtIXFT6PweUFHPHjDqjGOA5KtoM4Mgx2NvUOHO724tpNmxpNj+ca2S5/o3YYHie8I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789207; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+tDJ5RTw0vtERmlSqo3Lcm+7bW8HEqg5oLrjBrjZtNU=; b=UyxYdvMfHXgco0TXiDkVOA3ag70ZL3nD/dynGh2zXxd5feQeZE1UmC2IyBxLOIlfO+jwcIS4FwTugDvTNiLK4vn1AJ3dacYgtBGmSyxnlJFEU8LOr2yLEbA9A2fmw4hcxD9P2jl+58KPaYOP7sB6yy886UFrrLSZVvwxewIdTbk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789207461713.0864035258245; Mon, 4 Nov 2024 22:46:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DBN-0004SR-16; Tue, 05 Nov 2024 01:36:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBJ-0004Re-Rg for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:36:49 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBH-0001pq-Pe for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:36:49 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:36:47 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:36:43 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788608; x=1762324608; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7SB8aGVRHq3cVcRCjG983qVZg5U5xF0U5N0nc3brUHY=; b=KsRWxI/WLyGEs/yj/KDHntMNQirVXImY1qMu525UFreznrWmE9sgvgsG Zh827NPHvc6NWBEfIqZRKTVWvE4NhM8EhMvgUUqN2orhskBOaORVg+H/2 rV6dS67fbwvUUoeTCcAXDjevFZNHKdI7KA4FEDWr5vq7dAOdNlGjQHPH5 Pkt63kmyQV1zepgZc5Lgf2bLUwL6IkuZSYIToW0sE8OaDyp7mskL6NkQb Eqi8wVVqNoI1U9ACXlXYpilxfQlKYYyb2iXswhCL+W8N5bUVICndvonOE /sbW+qoo3yyf2b3xbggbRLB2yt42c9iWK1bYKw9T2so/+jLE+vunkZL+v Q==; X-CSE-ConnectionGUID: xbSja+cSQmKtSdEXwAXiwQ== X-CSE-MsgGUID: AlrywSEwT6aTrnbtt8dzpA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689288" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689288" X-CSE-ConnectionGUID: CGPXOm3fS/i5ivZLDU97xA== X-CSE-MsgGUID: d6NqJKe+RIiI+IpNuhCdLA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83988631" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 06/60] i386/tdx: Introduce is_tdx_vm() helper and cache tdx_guest object Date: Tue, 5 Nov 2024 01:23:14 -0500 Message-Id: <20241105062408.3533704-7-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789208803116600 Content-Type: text/plain; charset="utf-8" It will need special handling for TDX VMs all around the QEMU. Introduce is_tdx_vm() helper to query if it's a TDX VM. Cache tdx_guest object thus no need to cast from ms->cgs every time. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann Reviewed-by: Isaku Yamahata --- changes in v3: - replace object_dynamic_cast with TDX_GUEST(); --- target/i386/kvm/tdx.c | 15 ++++++++++++++- target/i386/kvm/tdx.h | 10 ++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 907044910fec..ff3ef9bd8657 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -20,8 +20,16 @@ #include "kvm_i386.h" #include "tdx.h" =20 +static TdxGuest *tdx_guest; + static struct kvm_tdx_capabilities *tdx_caps; =20 +/* Valid after kvm_arch_init()->confidential_guest_kvm_init()->tdx_kvm_ini= t() */ +bool is_tdx_vm(void) +{ + return !!tdx_guest; +} + enum tdx_ioctl_level { TDX_VM_IOCTL, TDX_VCPU_IOCTL, @@ -105,15 +113,20 @@ static int get_tdx_capabilities(Error **errp) =20 static int tdx_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) { + TdxGuest *tdx =3D TDX_GUEST(cgs); int r =3D 0; =20 kvm_mark_guest_state_protected(); =20 if (!tdx_caps) { r =3D get_tdx_capabilities(errp); + if (r) { + return r; + } } =20 - return r; + tdx_guest =3D tdx; + return 0; } =20 static int tdx_kvm_type(X86ConfidentialGuest *cg) diff --git a/target/i386/kvm/tdx.h b/target/i386/kvm/tdx.h index de687457cae6..bca19c833e18 100644 --- a/target/i386/kvm/tdx.h +++ b/target/i386/kvm/tdx.h @@ -1,6 +1,10 @@ #ifndef QEMU_I386_TDX_H #define QEMU_I386_TDX_H =20 +#ifndef CONFIG_USER_ONLY +#include CONFIG_DEVICES /* CONFIG_TDX */ +#endif + #include "confidential-guest.h" =20 #define TYPE_TDX_GUEST "tdx-guest" @@ -16,4 +20,10 @@ typedef struct TdxGuest { uint64_t attributes; /* TD attributes */ } TdxGuest; =20 +#ifdef CONFIG_TDX +bool is_tdx_vm(void); +#else +#define is_tdx_vm() 0 +#endif /* CONFIG_TDX */ + #endif /* QEMU_I386_TDX_H */ --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730788679; cv=none; d=zohomail.com; s=zohoarc; b=aEvSDpKaHbeCH3fd5HgqL2+91PSaJo7jQh+MLLA8rzsIcOENwk2pwZtFvis2iRXYW+UzF4+4Z1u+RH1nzz1M5YF/xtxBmAtiwSumDDLp9N9SUIS/6XO3Vwc74CS+QGJaE4k/AmgXPHcgC6Agj2wqLOGOULc09ZsXD2rsQB2FTlg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730788679; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+R82oBwXGsUa00QI70KfZxcna2RBmCVUU7BDCB6ecX0=; b=XHYna+Fr0vdY51wMv7FED8yrf0ifG2x+zy7t1NpKYudNyE0PDyW/dmPJD/m5tvA0gimCJxwB9/p0Auz7NMWzNLKDfiumDVqc5T+HnjcEx2QUuiFRKI/fIuYvyB/G3YlZfM/CjieXvMNcLRPcWpXuJ8gt2KoyPoxVmBqPFxUFSPE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730788679173955.2614879963268; Mon, 4 Nov 2024 22:37:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DBP-0004T6-HM; Tue, 05 Nov 2024 01:36:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBO-0004Sk-5i for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:36:54 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBM-0001qk-Jf for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:36:53 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:36:51 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:36:47 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788613; x=1762324613; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=A6C88ZryYnZ5BmBKN8njc0C6s0vxQGqEOftEOyDrLG0=; b=eM5fV5Resi++m5THlBN8K+yJH3DJIR8AY9CanMVhpG4g9wO3BE7kfhT3 IIAX33PaQJqknisSmTonM4KuqzzL50T9maFPkOO4NvXoZ6gkYZQbegV92 ilm6WbLY2jGrO2zMAK86k4H9d6wi87n/B4915nuHFHb/Ax5D2ReQ/bOyV stAi84Yp0UHIPEIY6YBA8KNgzYbAgbScuDWr2MtKOiVdYVQzWcTfUqd9r j8k4ousGLO4GzdzKW99Yxhqv65I0S2gG0MCnXtcNNnvWxAjaa2zJA4zt7 g2jMI1HaBnnou2OD8fn90IHVWIC7nE2HFqGSZAOOgBdZVIoxjXINs2j+D g==; X-CSE-ConnectionGUID: 8gBahJBdQP6rKQEd0veI3w== X-CSE-MsgGUID: ny2wMlY1Q3W1fKAnrKF0bA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689318" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689318" X-CSE-ConnectionGUID: W+heuwoAQZOjmJ+rdV79Pw== X-CSE-MsgGUID: sN9Xd87dRTyBfJlJhz4auA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83988636" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 07/60] kvm: Introduce kvm_arch_pre_create_vcpu() Date: Tue, 5 Nov 2024 01:23:15 -0500 Message-Id: <20241105062408.3533704-8-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730788681353116600 Content-Type: text/plain; charset="utf-8" Introduce kvm_arch_pre_create_vcpu(), to perform arch-dependent work prior to create any vcpu. This is for i386 TDX because it needs call TDX_INIT_VM before creating any vcpu. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- Changes in v3: - pass @errp to kvm_arch_pre_create_vcpu(); (Per Daniel) --- accel/kvm/kvm-all.c | 10 ++++++++++ include/sysemu/kvm.h | 1 + 2 files changed, 11 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 930a5bfed58f..1732fa1adecd 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -523,6 +523,11 @@ void kvm_destroy_vcpu(CPUState *cpu) } } =20 +int __attribute__ ((weak)) kvm_arch_pre_create_vcpu(CPUState *cpu, Error *= *errp) +{ + return 0; +} + int kvm_init_vcpu(CPUState *cpu, Error **errp) { KVMState *s =3D kvm_state; @@ -531,6 +536,11 @@ int kvm_init_vcpu(CPUState *cpu, Error **errp) =20 trace_kvm_init_vcpu(cpu->cpu_index, kvm_arch_vcpu_id(cpu)); =20 + ret =3D kvm_arch_pre_create_vcpu(cpu, errp); + if (ret < 0) { + goto err; + } + ret =3D kvm_create_vcpu(cpu); if (ret < 0) { error_setg_errno(errp, -ret, diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index c3a60b28909a..643ca4950543 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -374,6 +374,7 @@ int kvm_arch_get_default_type(MachineState *ms); =20 int kvm_arch_init(MachineState *ms, KVMState *s); =20 +int kvm_arch_pre_create_vcpu(CPUState *cpu, Error **errp); int kvm_arch_init_vcpu(CPUState *cpu); int kvm_arch_destroy_vcpu(CPUState *cpu); =20 --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789139; cv=none; d=zohomail.com; s=zohoarc; b=CdAoxGPnewOqkf+nKFoxCqG5BYMGvvqzjASLOIOo2sWSxo7ZVg0PTXkZ6BLdiNeLZs59ap2h63ghrpmki0vWBdRSUezmykCRLOjk9BGK8CKaxipqQC3W8NRuYrwYfaNEjQ9wOuUHssH118TQQ3btZBa5eY5qZKja/wYO7nfKM9M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789139; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zJVtHOeEMIrydsPxDYzvmoAy1DkE3j5ui+iBTLs4xJs=; b=PzXk8jWCIi8TGkymsjzqMBRGwnI3W5VjF4osmf0S6qNfvpkKFoTVdi1GublvBD50voxPt3OJmah6kPPdm8Q2pYipkqABbBDaF7dIRb19BL7GTO3dtv0nYyyXIMQo9szxcz+yvuLK1jAXnEB9VbU4J2STqiqdHAMq6ULm1+Okh3g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789139717783.864073866596; Mon, 4 Nov 2024 22:45:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DBT-0004Tt-8p; Tue, 05 Nov 2024 01:36:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBR-0004TS-Ji for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:36:57 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBQ-0001qk-0m for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:36:57 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:36:55 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:36:51 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788616; x=1762324616; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EMCLkioz6PKqWrBweYilnMeVfCok800taR5KSHSziyM=; b=ex7fURO97IP1Mnie9L9kaek2P6LE2N3bBmsgV40PoZ3slT5V0HZobbFk OHT/uGJS8NvuQFleHu9FXitG8Bw/a6y0jdFVjx6JuoLC2WXLKOotPDCnN lCQumcZQzuxSAOqqk/47sLKyTz/Cz1Hw0/mTqlRj4Og7MVrncHH+YKt8d mpjfb+8pkbWH++0KrTo+UhDkmfrmhzrZy6v5ubeQ52aTVXb/Tw/kHfKlc rdJRN0XvqchV00YG+MrEr+EaKBfdYOpFdKIwS/eMQPhwR4Q6rl9S6ah+B DLTOxF0ljV53TqBO6zH+gOKNHtWFuqATETSwgmdGEnLXWjrMRWsEzdP3t A==; X-CSE-ConnectionGUID: EgG+jOotSNqpzsvQeUJ0vA== X-CSE-MsgGUID: GdAGFcRNR9uw+qDFV2sr1Q== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689337" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689337" X-CSE-ConnectionGUID: /mqITyi7TM+2Y+yCpFQ9lQ== X-CSE-MsgGUID: mzsjznpqSTuIPYeKU0/kIQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83988646" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 08/60] i386/kvm: Export cpuid_entry_get_reg() and cpuid_find_entry() Date: Tue, 5 Nov 2024 01:23:16 -0500 Message-Id: <20241105062408.3533704-9-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789140265116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Xiaoyao Li --- target/i386/kvm/kvm.c | 8 ++++---- target/i386/kvm/kvm_i386.h | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index b843de7f2379..afbf67a7fdaa 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -395,7 +395,7 @@ static bool host_tsx_broken(void) =20 /* Returns the value for a specific register on the cpuid entry */ -static uint32_t cpuid_entry_get_reg(struct kvm_cpuid_entry2 *entry, int re= g) +uint32_t cpuid_entry_get_reg(struct kvm_cpuid_entry2 *entry, int reg) { uint32_t ret =3D 0; switch (reg) { @@ -417,9 +417,9 @@ static uint32_t cpuid_entry_get_reg(struct kvm_cpuid_en= try2 *entry, int reg) =20 /* Find matching entry for function/index on kvm_cpuid2 struct */ -static struct kvm_cpuid_entry2 *cpuid_find_entry(struct kvm_cpuid2 *cpuid, - uint32_t function, - uint32_t index) +struct kvm_cpuid_entry2 *cpuid_find_entry(struct kvm_cpuid2 *cpuid, + uint32_t function, + uint32_t index) { int i; for (i =3D 0; i < cpuid->nent; ++i) { diff --git a/target/i386/kvm/kvm_i386.h b/target/i386/kvm/kvm_i386.h index 7ac4c3a91171..efb0883bd968 100644 --- a/target/i386/kvm/kvm_i386.h +++ b/target/i386/kvm/kvm_i386.h @@ -67,6 +67,10 @@ bool kvm_has_waitpkg(void); uint64_t kvm_swizzle_msi_ext_dest_id(uint64_t address); void kvm_update_msi_routes_all(void *private, bool global, uint32_t index, uint32_t mask); +uint32_t cpuid_entry_get_reg(struct kvm_cpuid_entry2 *entry, int reg); +struct kvm_cpuid_entry2 *cpuid_find_entry(struct kvm_cpuid2 *cpuid, + uint32_t function, + uint32_t index); =20 #endif /* CONFIG_KVM */ =20 --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789333; cv=none; d=zohomail.com; s=zohoarc; b=YwdJFt3i8tDaLYq1jACU+pb7LZhvs3ERKcSa++4mfMzQZgQ2bOkcgR2HnQhxy6CnM7RCbTze8j7XJyXhzTdWquQXwEtsqbGWvck1pc9v2DFJ+2P3f72ZzErZg0uuk2IfVadNvBniSCE84hrATexrkA1QE5/dGrHsHHU7a1xiB14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789333; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=J3SRRovuYS/uMTBX0077byl6iYcIeTE5QOBUBYQqeDk=; b=Q+7Pi6J0xhKgBnxYqHmtE3mMIAJ0ZDrCMgmrgqX3UktDC3KDZu54VYWAtnDIdE36xh7PN9b8rzmfijOEOOWbzg8FmJcz1QcdnbMA0ZYOVPHa3nnyYKtyE9guoHIQYCdHhIzvcg1MA9Z0+9bD8krKttoGpgda1/1olWj1icaUwTU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789333064193.4394696106583; Mon, 4 Nov 2024 22:48:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DBd-0004lt-Pm; Tue, 05 Nov 2024 01:37:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBb-0004l4-LJ for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:37:07 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBZ-0001rn-Ir for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:37:07 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:37:04 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:36:55 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788626; x=1762324626; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yQIhC8cfgzUM44TPusIfHMFUJd+lfWQalAFJnpz6Jag=; b=EQOzLnyXVmcJDRTulG4JwKd8CrhmQL8TdN7ro4i6VPm3hd8rZ/7Qa3Q4 SfbZNS7jwPPSLNmmOK7VUx+hwGWHlqki9MCtr4t7su6RL2L2DMVIe16I1 8LvU6k8bD8WPqIqYiYKgP0q8vlA0E7Eo+HeZ7rYX6trAlnAQ7N/TduWnk hDbSdwoxvwrL/AZe6TJyyObsg17hbzyImDWTVqQIkkMkJt2r3awDYiJ8K EAVMGAuRSyKrbHcHPC5NxJhNMs/mmV03RPvyrbVZsbhPjChRul8sG1GaB 06l77xyHlc5eaqyIBM3pDRFwyWVp6tW4WgoS9U6WXVt5sb80LwsVAx+yy Q==; X-CSE-ConnectionGUID: UDLSv9IeQAuMI0h4mcjkPg== X-CSE-MsgGUID: dtcwX9i0RTujKuT1biPwIA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689370" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689370" X-CSE-ConnectionGUID: vvoBuMURRum5DlaKfdWiIg== X-CSE-MsgGUID: nWmSZL4zTd2VmMz+z6IAgA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83988677" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 09/60] i386/tdx: Initialize TDX before creating TD vcpus Date: Tue, 5 Nov 2024 01:23:17 -0500 Message-Id: <20241105062408.3533704-10-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789333545116600 Content-Type: text/plain; charset="utf-8" Invoke KVM_TDX_INIT in kvm_arch_pre_create_vcpu() that KVM_TDX_INIT configures global TD configurations, e.g. the canonical CPUID config, and must be executed prior to creating vCPUs. Use kvm_x86_arch_cpuid() to setup the CPUID settings for TDX VM. Note, this doesn't address the fact that QEMU may change the CPUID configuration when creating vCPUs, i.e. punts on refactoring QEMU to provide a stable CPUID config prior to kvm_arch_init(). Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann Acked-by: Markus Armbruster --- Changes in v6: - setup xfam explicitly to fit with new uapi; - use tdx_caps->cpuid to filter the input of cpuids because now KVM only allows the leafs that reported via KVM_TDX_GET_CAPABILITIES; Changes in v4: - mark init_vm with g_autofree() and use QEMU_LOCK_GUARD() to eliminate the goto labels; (Daniel) Changes in v3: - Pass @errp in tdx_pre_create_vcpu() and pass error info to it. (Daniel) --- accel/kvm/kvm-all.c | 8 ++++ target/i386/kvm/kvm.c | 15 +++++-- target/i386/kvm/kvm_i386.h | 3 ++ target/i386/kvm/meson.build | 2 +- target/i386/kvm/tdx-stub.c | 8 ++++ target/i386/kvm/tdx.c | 87 +++++++++++++++++++++++++++++++++++++ target/i386/kvm/tdx.h | 6 +++ 7 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 target/i386/kvm/tdx-stub.c diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 1732fa1adecd..4a1c9950894c 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -536,8 +536,15 @@ int kvm_init_vcpu(CPUState *cpu, Error **errp) =20 trace_kvm_init_vcpu(cpu->cpu_index, kvm_arch_vcpu_id(cpu)); =20 + /* + * tdx_pre_create_vcpu() may call cpu_x86_cpuid(). It in turn may call + * kvm_vm_ioctl(). Set cpu->kvm_state in advance to avoid NULL pointer + * dereference. + */ + cpu->kvm_state =3D s; ret =3D kvm_arch_pre_create_vcpu(cpu, errp); if (ret < 0) { + cpu->kvm_state =3D NULL; goto err; } =20 @@ -546,6 +553,7 @@ int kvm_init_vcpu(CPUState *cpu, Error **errp) error_setg_errno(errp, -ret, "kvm_init_vcpu: kvm_create_vcpu failed (%lu)", kvm_arch_vcpu_id(cpu)); + cpu->kvm_state =3D NULL; goto err; } =20 diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index afbf67a7fdaa..db676c1336ab 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -38,6 +38,7 @@ #include "kvm_i386.h" #include "../confidential-guest.h" #include "sev.h" +#include "tdx.h" #include "xen-emu.h" #include "hyperv.h" #include "hyperv-proto.h" @@ -1824,9 +1825,8 @@ static void kvm_init_nested_state(CPUX86State *env) } } =20 -static uint32_t kvm_x86_build_cpuid(CPUX86State *env, - struct kvm_cpuid_entry2 *entries, - uint32_t cpuid_i) +uint32_t kvm_x86_build_cpuid(CPUX86State *env, struct kvm_cpuid_entry2 *en= tries, + uint32_t cpuid_i) { uint32_t limit, i, j; uint32_t unused; @@ -2358,6 +2358,15 @@ int kvm_arch_init_vcpu(CPUState *cs) return r; } =20 +int kvm_arch_pre_create_vcpu(CPUState *cpu, Error **errp) +{ + if (is_tdx_vm()) { + return tdx_pre_create_vcpu(cpu, errp); + } + + return 0; +} + int kvm_arch_destroy_vcpu(CPUState *cs) { X86CPU *cpu =3D X86_CPU(cs); diff --git a/target/i386/kvm/kvm_i386.h b/target/i386/kvm/kvm_i386.h index efb0883bd968..b1baf9e7f910 100644 --- a/target/i386/kvm/kvm_i386.h +++ b/target/i386/kvm/kvm_i386.h @@ -24,6 +24,9 @@ #define kvm_ioapic_in_kernel() \ (kvm_irqchip_in_kernel() && !kvm_irqchip_is_split()) =20 +uint32_t kvm_x86_build_cpuid(CPUX86State *env, struct kvm_cpuid_entry2 *en= tries, + uint32_t cpuid_i); + #else =20 #define kvm_pit_in_kernel() 0 diff --git a/target/i386/kvm/meson.build b/target/i386/kvm/meson.build index 466bccb9cb17..3f44cdedb758 100644 --- a/target/i386/kvm/meson.build +++ b/target/i386/kvm/meson.build @@ -8,7 +8,7 @@ i386_kvm_ss.add(files( =20 i386_kvm_ss.add(when: 'CONFIG_XEN_EMU', if_true: files('xen-emu.c')) =20 -i386_kvm_ss.add(when: 'CONFIG_TDX', if_true: files('tdx.c')) +i386_kvm_ss.add(when: 'CONFIG_TDX', if_true: files('tdx.c'), if_false: fil= es('tdx-stub.c')) =20 i386_system_ss.add(when: 'CONFIG_HYPERV', if_true: files('hyperv.c'), if_f= alse: files('hyperv-stub.c')) =20 diff --git a/target/i386/kvm/tdx-stub.c b/target/i386/kvm/tdx-stub.c new file mode 100644 index 000000000000..b614b46d3f4a --- /dev/null +++ b/target/i386/kvm/tdx-stub.c @@ -0,0 +1,8 @@ +#include "qemu/osdep.h" + +#include "tdx.h" + +int tdx_pre_create_vcpu(CPUState *cpu, Error **errp) +{ + return -EINVAL; +} diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index ff3ef9bd8657..1b7894e43c6f 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -137,6 +137,91 @@ static int tdx_kvm_type(X86ConfidentialGuest *cg) return KVM_X86_TDX_VM; } =20 +static int setup_td_xfam(X86CPU *x86cpu, Error **errp) +{ + CPUX86State *env =3D &x86cpu->env; + uint64_t xfam; + + xfam =3D env->features[FEAT_XSAVE_XCR0_LO] | + env->features[FEAT_XSAVE_XCR0_HI] | + env->features[FEAT_XSAVE_XSS_LO] | + env->features[FEAT_XSAVE_XSS_HI]; + + if (xfam & ~tdx_caps->supported_xfam) { + error_setg(errp, "Invalid XFAM 0x%lx for TDX VM (supported: 0x%llx= ))", + xfam, tdx_caps->supported_xfam); + return -1; + } + + tdx_guest->xfam =3D xfam; + return 0; +} + +static void tdx_filter_cpuid(struct kvm_cpuid2 *cpuids) +{ + int i, dest_cnt =3D 0; + struct kvm_cpuid_entry2 *src, *dest, *conf; + + for (i =3D 0; i < cpuids->nent; i++) { + src =3D cpuids->entries + i; + conf =3D cpuid_find_entry(&tdx_caps->cpuid, src->function, src->in= dex); + if (!conf) { + continue; + } + dest =3D cpuids->entries + dest_cnt; + + dest->function =3D src->function; + dest->index =3D src->index; + dest->flags =3D src->flags; + dest->eax =3D src->eax & conf->eax; + dest->ebx =3D src->ebx & conf->ebx; + dest->ecx =3D src->ecx & conf->ecx; + dest->edx =3D src->edx & conf->edx; + + dest_cnt++; + } + cpuids->nent =3D dest_cnt++; +} + +int tdx_pre_create_vcpu(CPUState *cpu, Error **errp) +{ + X86CPU *x86cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86cpu->env; + g_autofree struct kvm_tdx_init_vm *init_vm =3D NULL; + int r =3D 0; + + QEMU_LOCK_GUARD(&tdx_guest->lock); + if (tdx_guest->initialized) { + return r; + } + + init_vm =3D g_malloc0(sizeof(struct kvm_tdx_init_vm) + + sizeof(struct kvm_cpuid_entry2) * KVM_MAX_CPUID_EN= TRIES); + + r =3D setup_td_xfam(x86cpu, errp); + if (r) { + return r; + } + + init_vm->cpuid.nent =3D kvm_x86_build_cpuid(env, init_vm->cpuid.entrie= s, 0); + tdx_filter_cpuid(&init_vm->cpuid); + + init_vm->attributes =3D tdx_guest->attributes; + init_vm->xfam =3D tdx_guest->xfam; + + do { + r =3D tdx_vm_ioctl(KVM_TDX_INIT_VM, 0, init_vm); + } while (r =3D=3D -EAGAIN); + if (r < 0) { + error_setg_errno(errp, -r, "KVM_TDX_INIT_VM failed"); + return r; + } + + tdx_guest->initialized =3D true; + + return 0; +} + /* tdx guest */ OBJECT_DEFINE_TYPE_WITH_INTERFACES(TdxGuest, tdx_guest, @@ -150,6 +235,8 @@ static void tdx_guest_init(Object *obj) ConfidentialGuestSupport *cgs =3D CONFIDENTIAL_GUEST_SUPPORT(obj); TdxGuest *tdx =3D TDX_GUEST(obj); =20 + qemu_mutex_init(&tdx->lock); + cgs->require_guest_memfd =3D true; tdx->attributes =3D 0; =20 diff --git a/target/i386/kvm/tdx.h b/target/i386/kvm/tdx.h index bca19c833e18..e077fd7d1653 100644 --- a/target/i386/kvm/tdx.h +++ b/target/i386/kvm/tdx.h @@ -17,7 +17,11 @@ typedef struct TdxGuestClass { typedef struct TdxGuest { X86ConfidentialGuest parent_obj; =20 + QemuMutex lock; + + bool initialized; uint64_t attributes; /* TD attributes */ + uint64_t xfam; } TdxGuest; =20 #ifdef CONFIG_TDX @@ -26,4 +30,6 @@ bool is_tdx_vm(void); #define is_tdx_vm() 0 #endif /* CONFIG_TDX */ =20 +int tdx_pre_create_vcpu(CPUState *cpu, Error **errp); + #endif /* QEMU_I386_TDX_H */ --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730788969; cv=none; d=zohomail.com; s=zohoarc; b=YT3OyEB+0oZFNErCgAHVNc/2Fv9xUBdM/omk1hQbre2VvxasUFa9Yu9fuZLQkd9pi9+9FpjeVqAh7YqzWLmXtu4H6ikpWT8deko95WzgkHdqyBm661kjEzFgi6IMcGpUlFcj2xQb+0tjK/XajpMUw2Bk68iEC6X6DgtJEZ5hLRM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730788969; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kNWl15H4mG8eb23GFCWjikpgBCGyVkxOtMY5gDmPMOc=; b=cLA8Gxb4bqP8xTITjls5Slo6a1K+wnXLhRc6pSaWYXkSs7aWzOvVSqXpbsRy+Ct7i1jrykAxy+vMvVF3cuxN20r2uQ0fGwHH7txo21KObcTk9RnGbXqRoyoBO0GHPFEWxXG3v9YsLOFsmUBf7oVSpZSV24/k5t0M0fOxgbSQ8tg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17307889696458.288197088381708; Mon, 4 Nov 2024 22:42:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DBf-0004mI-FI; Tue, 05 Nov 2024 01:37:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBd-0004lp-Ke for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:37:09 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBc-0001rn-03 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:37:09 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:37:04 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:37:00 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788628; x=1762324628; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=o/sLK02aQtaM8p5hBGZNXbfp2X2hSnsOmbdz3IT3nfg=; b=UlCNdkdQOK9G8Z1GXCnoVDRuNSObMZ2jXHPvdTKYaDN6e0O8txsbH/a5 nvGSQ9VhQO/vZPBSNiFpReUviXods/iMWiIfHuwUBp0dvVbjB7UKXJi5d FjnnLsmeMW04o5+KNbJ3gYkFOh9Huoy9DKu5f+OLaMe551/L3fH0AcyKm VDNNJjDUWNP8LNWjKExNwUAwYghcbGwtdy+ee/zB4IvHRPHLhCE6femOr hgLSPHK7lUwZdK6COS8AvihCCIscHkPOvrF5siI/mrZRgCG+0EJVoTvxX cucbrjZx7sT6TZlidWxhoDeoqzqOQybM3Cxh4/uoi5xXkhYho3YX+OYhB A==; X-CSE-ConnectionGUID: AjHKPltlTMeWhrJmK+QDrg== X-CSE-MsgGUID: AdOfHdcgQgWwh6O8c3qMVQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689377" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689377" X-CSE-ConnectionGUID: YRSFmewLQMe+eiJQaD2GmQ== X-CSE-MsgGUID: zpxUO4cAQnGtI73ucRqEtw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83988701" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 10/60] i386/tdx: Add property sept-ve-disable for tdx-guest object Date: Tue, 5 Nov 2024 01:23:18 -0500 Message-Id: <20241105062408.3533704-11-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730788971933116600 Content-Type: text/plain; charset="utf-8" Bit 28 of TD attribute, named SEPT_VE_DISABLE. When set to 1, it disables EPT violation conversion to #VE on guest TD access of PENDING pages. Some guest OS (e.g., Linux TD guest) may require this bit as 1. Otherwise refuse to boot. Add sept-ve-disable property for tdx-guest object, for user to configure this bit. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann Acked-by: Markus Armbruster --- Changes in v4: - collect Acked-by from Markus Changes in v3: - update the comment of property @sept-ve-disable to make it more descriptive and use new format. (Daniel and Markus) --- qapi/qom.json | 8 +++++++- target/i386/kvm/tdx.c | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/qapi/qom.json b/qapi/qom.json index 129b25edf495..b3dc0cfa2641 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -1016,10 +1016,16 @@ # @attributes: The 'attributes' of a TD guest that is passed to # KVM_TDX_INIT_VM # +# @sept-ve-disable: toggle bit 28 of TD attributes to control disabling +# of EPT violation conversion to #VE on guest TD access of PENDING +# pages. Some guest OS (e.g., Linux TD guest) may require this to +# be set, otherwise they refuse to boot. +# # Since: 9.2 ## { 'struct': 'TdxGuestProperties', - 'data': { '*attributes': 'uint64' } } + 'data': { '*attributes': 'uint64', + '*sept-ve-disable': 'bool' } } =20 ## # @ThreadContextProperties: diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 1b7894e43c6f..faac05ef630f 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -20,6 +20,8 @@ #include "kvm_i386.h" #include "tdx.h" =20 +#define TDX_TD_ATTRIBUTES_SEPT_VE_DISABLE BIT_ULL(28) + static TdxGuest *tdx_guest; =20 static struct kvm_tdx_capabilities *tdx_caps; @@ -222,6 +224,24 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp) return 0; } =20 +static bool tdx_guest_get_sept_ve_disable(Object *obj, Error **errp) +{ + TdxGuest *tdx =3D TDX_GUEST(obj); + + return !!(tdx->attributes & TDX_TD_ATTRIBUTES_SEPT_VE_DISABLE); +} + +static void tdx_guest_set_sept_ve_disable(Object *obj, bool value, Error *= *errp) +{ + TdxGuest *tdx =3D TDX_GUEST(obj); + + if (value) { + tdx->attributes |=3D TDX_TD_ATTRIBUTES_SEPT_VE_DISABLE; + } else { + tdx->attributes &=3D ~TDX_TD_ATTRIBUTES_SEPT_VE_DISABLE; + } +} + /* tdx guest */ OBJECT_DEFINE_TYPE_WITH_INTERFACES(TdxGuest, tdx_guest, @@ -242,6 +262,9 @@ static void tdx_guest_init(Object *obj) =20 object_property_add_uint64_ptr(obj, "attributes", &tdx->attributes, OBJ_PROP_FLAG_READWRITE); + object_property_add_bool(obj, "sept-ve-disable", + tdx_guest_get_sept_ve_disable, + tdx_guest_set_sept_ve_disable); } =20 static void tdx_guest_finalize(Object *obj) --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730788724; cv=none; d=zohomail.com; s=zohoarc; b=djPSTwX7HQQZk/UClwgNcOX7G/FQVcnR5d4dVLKSXIYGeRj0ykw+UBXOjdP2+nMus6DFaccQCI7ZpWCvzNVRVUWEhJtjYJf7dmt6fPe+GYkXBbj48DDl+TNAtA/wQfF23VokzOSUS+XPcCvjMKB5gpgfBCvqQ3BVVdnCIkXdwyE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730788724; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2dv0+iHyB0meXNwIft3Dt4sz/vn4W18dW/8mjAUDEHc=; b=Cw5N6slyKFgGPyvgmLnV15GEAS9/b3hoj3lwXitETkEwCXIaAYDqZhbYABMsxnoiCUCSdzdK3jTTzQYziqSV4QL538Hyhu8SNxCyItYQIZX5+Wy41SRXEVt1VDCYr3J5mcL3Yy/Nw9sz5ryS4BEGG8nZYm4pJZFMNqwGnMltUcU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730788724557630.3259317972129; Mon, 4 Nov 2024 22:38:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DBm-0004qY-CD; Tue, 05 Nov 2024 01:37:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBg-0004mT-DL for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:37:12 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBe-0001rn-0m for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:37:11 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:37:09 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:37:04 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788630; x=1762324630; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3vrjucC0HxJukGg8dTLCBBUFcd1deUmBY7cHA/rzJ28=; b=fnDTIZgCHldWTxTiLS3W9VW8QbT0q7DLEaPWNsc/yEP/jhIM5W19r6BP Mbxe1m30kqo8N6uffEI1Ix8cSF/HnLU3yeHalkXGPg7xPpX5mKI+adI/w 1ney5Ckn9VCf0x3PJ/yp4sj1WvmpeXuL/7DQQZ4fP4F4Y9+M9i3oo0c0O /vWzybsBkE1UZtv58hHVgtJxlD562rjmID9jJm8IDpvia7TuM0wchrW2b u5nMwcl77fTDaBCNErF+sqecmsjeE5QtwcuyC79MdsFyKbICBU2Cq7s+v 0/wgUAGhLU1/3t307PME3nBmBmr0qsKwmjzAFB6Re1i8RQj2tatGVhzFi w==; X-CSE-ConnectionGUID: TpP6pdLlTiKF0+ChMefqMw== X-CSE-MsgGUID: DnQdGaypTVWNzqRilC2dhg== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689397" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689397" X-CSE-ConnectionGUID: Zm2pPz90SC68qOWzD6MiDQ== X-CSE-MsgGUID: UIm5o8N/TvOypSmczHpCoA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83988743" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 11/60] i386/tdx: Make sept_ve_disable set by default Date: Tue, 5 Nov 2024 01:23:19 -0500 Message-Id: <20241105062408.3533704-12-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730788726665116600 Content-Type: text/plain; charset="utf-8" From: Isaku Yamahata For TDX KVM use case, Linux guest is the most major one. It requires sept_ve_disable set. Make it default for the main use case. For other use case, it can be enabled/disabled via qemu command line. Signed-off-by: Isaku Yamahata --- target/i386/kvm/tdx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index faac05ef630f..e8fd5c7d49e7 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -258,7 +258,7 @@ static void tdx_guest_init(Object *obj) qemu_mutex_init(&tdx->lock); =20 cgs->require_guest_memfd =3D true; - tdx->attributes =3D 0; + tdx->attributes =3D TDX_TD_ATTRIBUTES_SEPT_VE_DISABLE; =20 object_property_add_uint64_ptr(obj, "attributes", &tdx->attributes, OBJ_PROP_FLAG_READWRITE); --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789462; cv=none; d=zohomail.com; s=zohoarc; b=Di/qe3SzoV8en9WhlL40AkKj44wh9Lp66PkfdvB63cqE9XMb5ArhfaEEfPCVHtQ0c3cWQRy+6kWMlcBgdTF+6eSD/N63wFA5CBniJMlK3U8TCghlxz0w74XeEp3aRBuhdx5AM50LetNpGthVQ5Q6AZZFOCSN7Kf16p0GDwu5cp4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789462; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FiFS16E2fb2jOf96SIhWljfTMSK5d6+eBeQWoqFxfhs=; b=VSP1KTRevmpuVxcfSLNIm5ycjASwg2Aqsm+DudeADR99faK8CSbYDOBK3RIjjyo+/Jsrvzt52jrXD7pUx55CfNEQdq7+a8/TxgXIauhK1HHPzBNGIgnqhYznCAwDdrmY8CjSC8Qpd0KOnPmfvIQ4/X+Nncbml+23F8VRPV9Nfyo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789462806315.2699968115239; Mon, 4 Nov 2024 22:51:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DC8-0005J7-RA; Tue, 05 Nov 2024 01:37:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBk-0004qC-Aj for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:37:16 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBi-0001tE-6o for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:37:15 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:37:13 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:37:09 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788634; x=1762324634; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oOcXPFYjwedzTDjXBfJ22esNNNhA5wHUGcb1V46w02g=; b=VV3xb79CzkDt/Rtpf0eay1lb9Vay9tB19a51pHRhxtPWMG/6HGgy0ahs zMxLhJw1OoFPqO+OXk3RNJANpOBvLm03xEeNRVvPZqyS750R6i0UdzKWy CH1LdfUzX6t5MMOA8rdoSTIlJUMM9ZpqkvetbaNbHplbavYde+USKXpph 8Xxr8TyDQU2gxJ8owa0WKzS1EO9+M86li0B07q+AxNN2hfjaq0byg8AYi 3UAJX3HQfglY8cqzpaWCpT+EhcxaRAJ6RO4pczTHlhjpkumtlVPQ1Ype3 LESKIXGWItKyo2vibQRmnxx5AbSMnkBLhzrAfX9le0D15uaHgXkWIU3TS w==; X-CSE-ConnectionGUID: B2Bj6vXeRBi0BRoHFQTq+Q== X-CSE-MsgGUID: ofcSbq+FQI+VD0n1aqUmgg== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689405" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689405" X-CSE-ConnectionGUID: S/SrZVnbRye6tYey39q1gQ== X-CSE-MsgGUID: gPwWQciUSUSPcF3ezm7Hdw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83988765" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 12/60] i386/tdx: Wire CPU features up with attributes of TD guest Date: Tue, 5 Nov 2024 01:23:20 -0500 Message-Id: <20241105062408.3533704-13-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789464152116600 Content-Type: text/plain; charset="utf-8" For QEMU VMs, - PKS is configured via CPUID_7_0_ECX_PKS, e.g., -cpu xxx,+pks and - PMU is configured by x86cpu->enable_pmu, e.g., -cpu xxx,pmu=3Don While the bit 30 (PKS) and bit 63 (PERFMON) of TD's attributes are also used to configure the PKS and PERFMON/PMU of TD, reuse the existing configuration interfaces of 'cpu' for TD's attributes. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- target/i386/kvm/tdx.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index e8fd5c7d49e7..6cf81f788fe0 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -21,6 +21,8 @@ #include "tdx.h" =20 #define TDX_TD_ATTRIBUTES_SEPT_VE_DISABLE BIT_ULL(28) +#define TDX_TD_ATTRIBUTES_PKS BIT_ULL(30) +#define TDX_TD_ATTRIBUTES_PERFMON BIT_ULL(63) =20 static TdxGuest *tdx_guest; =20 @@ -139,6 +141,15 @@ static int tdx_kvm_type(X86ConfidentialGuest *cg) return KVM_X86_TDX_VM; } =20 +static void setup_td_guest_attributes(X86CPU *x86cpu) +{ + CPUX86State *env =3D &x86cpu->env; + + tdx_guest->attributes |=3D (env->features[FEAT_7_0_ECX] & CPUID_7_0_EC= X_PKS) ? + TDX_TD_ATTRIBUTES_PKS : 0; + tdx_guest->attributes |=3D x86cpu->enable_pmu ? TDX_TD_ATTRIBUTES_PERF= MON : 0; +} + static int setup_td_xfam(X86CPU *x86cpu, Error **errp) { CPUX86State *env =3D &x86cpu->env; @@ -200,6 +211,8 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp) init_vm =3D g_malloc0(sizeof(struct kvm_tdx_init_vm) + sizeof(struct kvm_cpuid_entry2) * KVM_MAX_CPUID_EN= TRIES); =20 + setup_td_guest_attributes(x86cpu); + r =3D setup_td_xfam(x86cpu, errp); if (r) { return r; --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789558; cv=none; d=zohomail.com; s=zohoarc; b=dOwHML8hB3plb/Uype3///FWGvoaR/SEVrk8vWNJJQH5Jt4QUAJWqF/f5G71uMAfchJmeScradyoiFzi/ZTau/6F72UWWIEnMw8GT5PClMTwaAZYEztocXFLLPPF7larS+ERO/f9TaUWZgXFWThhali6THcv6TvQZtz44D7WAKQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789558; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rDp54o6bxQP4OFQ/S75LGdsXaddqxZ0borWQjos4ol4=; b=WK4wT+9a6yaT6DNMtlTlCtWhLoCVZKC6X/oDhz/4nKXjrGALYgaXWfgs4zfArbsp7riCqB2I583vpDTvhzTYo5jabvLqljPNKbebd/Dg+w+4fwWxH1t/awgOjIqeh+Tt4/Bea4367OVlqkxQcejxXbPWiS40t4oi9BGdRFTkSp8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789558910400.4528936871974; Mon, 4 Nov 2024 22:52:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DC6-00058Z-3x; Tue, 05 Nov 2024 01:37:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBn-0004x8-Ac for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:37:22 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBl-0001tE-Ln for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:37:19 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:37:17 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:37:13 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788638; x=1762324638; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/c6iKYuArYsGCvrbLnQoYffE/JqYul3IweXytxDmZNY=; b=RldKdVscHrrfupkBzDTvBRpWCPS1jRd7EBSgnFTv5felInNnHZ6/D+yu ynbh/iyrYy3H8btFiJRmrFFG/2I4H2UqNIrIzDwHWIOGH0bKQ9dKmL/wO 9WCzPffMY73Jws7yp45XB3QfIHEs/yDVTK3Vpp2eC3NUGskM+OTMgeS7Q Gj3Uxk50gN742F8SlAKs0hFjv8Z5RIBXZBrVXxvyie4LrVkQnROJEFE5M ktc2mVhoIR3eiNUmcIjhDVVPlvBDoP0C1+EWBdFI6lvo4Zhlk5ZPclMNR hDDKDzovWRufTmY/iKm5enviUKunsrPMb13zGiZBhZrWkfqGRBEERX1lX Q==; X-CSE-ConnectionGUID: Q6JxRguiQ92QoEHlKAy65A== X-CSE-MsgGUID: 0nmEqxVDQGmRX13O1961QA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689423" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689423" X-CSE-ConnectionGUID: L6eSPwevRTCTpTItmtpCDQ== X-CSE-MsgGUID: bP+aULKLSei0fDyQJ6ZDzA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83988794" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 13/60] i386/tdx: Validate TD attributes Date: Tue, 5 Nov 2024 01:23:21 -0500 Message-Id: <20241105062408.3533704-14-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789559292116600 Content-Type: text/plain; charset="utf-8" Validate TD attributes with tdx_caps that fixed-0 bits must be zero and fixed-1 bits must be set. Besides, sanity check the attribute bits that have not been supported by QEMU yet. e.g., debug bit, it will be allowed in the future when debug TD support lands in QEMU. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- Changes in v3: - using error_setg() for error report; (Daniel) --- target/i386/kvm/tdx.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 6cf81f788fe0..5a9ce2ada89d 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -20,6 +20,7 @@ #include "kvm_i386.h" #include "tdx.h" =20 +#define TDX_TD_ATTRIBUTES_DEBUG BIT_ULL(0) #define TDX_TD_ATTRIBUTES_SEPT_VE_DISABLE BIT_ULL(28) #define TDX_TD_ATTRIBUTES_PKS BIT_ULL(30) #define TDX_TD_ATTRIBUTES_PERFMON BIT_ULL(63) @@ -141,13 +142,33 @@ static int tdx_kvm_type(X86ConfidentialGuest *cg) return KVM_X86_TDX_VM; } =20 -static void setup_td_guest_attributes(X86CPU *x86cpu) +static int tdx_validate_attributes(TdxGuest *tdx, Error **errp) +{ + if ((tdx->attributes & ~tdx_caps->supported_attrs)) { + error_setg(errp, "Invalid attributes 0x%lx for TDX VM " + "(supported: 0x%llx)", + tdx->attributes, tdx_caps->supported_attrs); + return -1; + } + + if (tdx->attributes & TDX_TD_ATTRIBUTES_DEBUG) { + error_setg(errp, "Current QEMU doesn't support attributes.debug[bi= t 0] " + "for TDX VM"); + return -1; + } + + return 0; +} + +static int setup_td_guest_attributes(X86CPU *x86cpu, Error **errp) { CPUX86State *env =3D &x86cpu->env; =20 tdx_guest->attributes |=3D (env->features[FEAT_7_0_ECX] & CPUID_7_0_EC= X_PKS) ? TDX_TD_ATTRIBUTES_PKS : 0; tdx_guest->attributes |=3D x86cpu->enable_pmu ? TDX_TD_ATTRIBUTES_PERF= MON : 0; + + return tdx_validate_attributes(tdx_guest, errp); } =20 static int setup_td_xfam(X86CPU *x86cpu, Error **errp) @@ -211,7 +232,10 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp) init_vm =3D g_malloc0(sizeof(struct kvm_tdx_init_vm) + sizeof(struct kvm_cpuid_entry2) * KVM_MAX_CPUID_EN= TRIES); =20 - setup_td_guest_attributes(x86cpu); + r =3D setup_td_guest_attributes(x86cpu, errp); + if (r) { + return r; + } =20 r =3D setup_td_xfam(x86cpu, errp); if (r) { --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730788783; cv=none; d=zohomail.com; s=zohoarc; b=jaPacVKoKuQ8Hi3Gfkg1eZ6btw1ML2K4W9uPXNGIJ9eD9Ep50lG+1l8i79md4B35/6Ti58AcCku9oXoxNhOpZ9c5pEAE5vr3RENcdXnQhm/rd35ouZeQW4zSusVOrMV36j2fL1hmeHnp5desD8sCy5DO7DHzISQ+2yYWlZPFbJ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730788783; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=E3R8Bmka92pXZ5KP1V2j2UGyMApgb2vnnBvoJMy8+kA=; b=j8a/RU9Tk8GaRum5+FDeWb4AioHDiEbbQWczhGNuHxXFrOkX9rkf5m8XxV3k1d7rPw+tdOfQFIc5y1lUyfC/gwT/KuAAMAf2vU/J0k7+DOfkxORTVbwGKnQG6sS5DdUYXmXF6g2aeik2g8rvcFQWr/XYGhHHjX5NLZGvjSQPkyc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730788783537469.2282225553845; Mon, 4 Nov 2024 22:39:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DCB-0005Xe-A9; Tue, 05 Nov 2024 01:37:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBt-00051h-9m for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:37:31 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBq-0001tE-H0 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:37:24 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:37:22 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:37:17 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788642; x=1762324642; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=u2uKohq3DcafzpQYHK3WlKK6kJ5fDktVKOc7Gy0BK4Y=; b=HS/8u9K/BpjiLjcFuJChcMSqn4/O1TQzFO9GiZQFbHM7gXiCDVPRIBEn fzc8UEd4p/jfAfAAHjQYLHDROfmBI7bzSsnl9z97oOsXz+/j9AWLRpYq9 h2vx/OvGrr6OAV6H2h9qkMAEStFnU+tEK6ZU8zv4MBkzPXWu9oH+vnKHy Tkbtqh5giAAGM8gsN+rUvgDTrJU+1MSfAgRXLJYK5hSTl5UfKFuqiesJ7 lOlNv3Zm7l/urCQwMhrA/unjAiNy8prxsgTnyeGtdHM0THrDGXP/3Oqo/ UmaBthw7fG8l6dDjVvbMA8AmXV3C+NR+u9ti06WkZA/JFFZdCOYi8TDGz w==; X-CSE-ConnectionGUID: Vx1qXP/LQ1yvW+LOX0kSWQ== X-CSE-MsgGUID: w32UCxoIT162XzkbacOksA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689431" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689431" X-CSE-ConnectionGUID: 24IZZRMiRmuB5po5TzwMsg== X-CSE-MsgGUID: YO1KTPRyQN+CWj/2JK6wtg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83988820" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 14/60] i386/tdx: Support user configurable mrconfigid/mrowner/mrownerconfig Date: Tue, 5 Nov 2024 01:23:22 -0500 Message-Id: <20241105062408.3533704-15-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730788785071116600 From: Isaku Yamahata Three sha384 hash values, mrconfigid, mrowner and mrownerconfig, of a TD can be provided for TDX attestation. Detailed meaning of them can be found: https://lore.kernel.org/qemu-devel/31d6dbc1-f453-4cef-ab08-4813f4e0f= f92@intel.com/ Allow user to specify those values via property mrconfigid, mrowner and mrownerconfig. They are all in base64 format. example -object tdx-guest, \ mrconfigid=3DASNFZ4mrze8BI0VniavN7wEjRWeJq83vASNFZ4mrze8BI0VniavN7wEjRWeJ= q83v,\ mrowner=3DASNFZ4mrze8BI0VniavN7wEjRWeJq83vASNFZ4mrze8BI0VniavN7wEjRWeJq83= v,\ mrownerconfig=3DASNFZ4mrze8BI0VniavN7wEjRWeJq83vASNFZ4mrze8BI0VniavN7wEjR= WeJq83v Signed-off-by: Isaku Yamahata Co-developed-by: Xiaoyao Li Signed-off-by: Xiaoyao Li --- Changes in v6: - refine the doc comment of QAPI properties; Changes in v5: - refine the description of QAPI properties and add description of default value when not specified; Changes in v4: - describe more of there fields in qom.json - free the old value before set new value to avoid memory leak in _setter(); (Daniel) Changes in v3: - use base64 encoding instread of hex-string; --- qapi/qom.json | 16 +++++++- target/i386/kvm/tdx.c | 86 +++++++++++++++++++++++++++++++++++++++++++ target/i386/kvm/tdx.h | 3 ++ 3 files changed, 104 insertions(+), 1 deletion(-) diff --git a/qapi/qom.json b/qapi/qom.json index b3dc0cfa2641..477bbaa86a68 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -1021,11 +1021,25 @@ # pages. Some guest OS (e.g., Linux TD guest) may require this to # be set, otherwise they refuse to boot. # +# @mrconfigid: ID for non-owner-defined configuration of the guest TD, +# e.g., run-time or OS configuration (base64 encoded SHA384 digest). +# Defaults to all zeros. +# +# @mrowner: ID for the guest TD=E2=80=99s owner (base64 encoded SHA384 dig= est). +# Defaults to all zeros. +# +# @mrownerconfig: ID for owner-defined configuration of the guest TD, +# e.g., specific to the workload rather than the run-time or OS +# (base64 encoded SHA384 digest). Defaults to all zeros. +# # Since: 9.2 ## { 'struct': 'TdxGuestProperties', 'data': { '*attributes': 'uint64', - '*sept-ve-disable': 'bool' } } + '*sept-ve-disable': 'bool', + '*mrconfigid': 'str', + '*mrowner': 'str', + '*mrownerconfig': 'str' } } =20 ## # @ThreadContextProperties: diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 5a9ce2ada89d..887a5324b439 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -13,6 +13,7 @@ =20 #include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qemu/base64.h" #include "qapi/error.h" #include "qom/object_interfaces.h" =20 @@ -222,6 +223,7 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp) X86CPU *x86cpu =3D X86_CPU(cpu); CPUX86State *env =3D &x86cpu->env; g_autofree struct kvm_tdx_init_vm *init_vm =3D NULL; + size_t data_len; int r =3D 0; =20 QEMU_LOCK_GUARD(&tdx_guest->lock); @@ -232,6 +234,37 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp) init_vm =3D g_malloc0(sizeof(struct kvm_tdx_init_vm) + sizeof(struct kvm_cpuid_entry2) * KVM_MAX_CPUID_EN= TRIES); =20 +#define SHA384_DIGEST_SIZE 48 + if (tdx_guest->mrconfigid) { + g_autofree uint8_t *data =3D qbase64_decode(tdx_guest->mrconfigid, + strlen(tdx_guest->mrconfigid), &data_len, er= rp); + if (!data || data_len !=3D SHA384_DIGEST_SIZE) { + error_setg(errp, "TDX: failed to decode mrconfigid"); + return -1; + } + memcpy(init_vm->mrconfigid, data, data_len); + } + + if (tdx_guest->mrowner) { + g_autofree uint8_t *data =3D qbase64_decode(tdx_guest->mrowner, + strlen(tdx_guest->mrowner), &data_len, errp); + if (!data || data_len !=3D SHA384_DIGEST_SIZE) { + error_setg(errp, "TDX: failed to decode mrowner"); + return -1; + } + memcpy(init_vm->mrowner, data, data_len); + } + + if (tdx_guest->mrownerconfig) { + g_autofree uint8_t *data =3D qbase64_decode(tdx_guest->mrownerconf= ig, + strlen(tdx_guest->mrownerconfig), &data_len, e= rrp); + if (!data || data_len !=3D SHA384_DIGEST_SIZE) { + error_setg(errp, "TDX: failed to decode mrownerconfig"); + return -1; + } + memcpy(init_vm->mrownerconfig, data, data_len); + } + r =3D setup_td_guest_attributes(x86cpu, errp); if (r) { return r; @@ -279,6 +312,51 @@ static void tdx_guest_set_sept_ve_disable(Object *obj,= bool value, Error **errp) } } =20 +static char *tdx_guest_get_mrconfigid(Object *obj, Error **errp) +{ + TdxGuest *tdx =3D TDX_GUEST(obj); + + return g_strdup(tdx->mrconfigid); +} + +static void tdx_guest_set_mrconfigid(Object *obj, const char *value, Error= **errp) +{ + TdxGuest *tdx =3D TDX_GUEST(obj); + + g_free(tdx->mrconfigid); + tdx->mrconfigid =3D g_strdup(value); +} + +static char *tdx_guest_get_mrowner(Object *obj, Error **errp) +{ + TdxGuest *tdx =3D TDX_GUEST(obj); + + return g_strdup(tdx->mrowner); +} + +static void tdx_guest_set_mrowner(Object *obj, const char *value, Error **= errp) +{ + TdxGuest *tdx =3D TDX_GUEST(obj); + + g_free(tdx->mrowner); + tdx->mrowner =3D g_strdup(value); +} + +static char *tdx_guest_get_mrownerconfig(Object *obj, Error **errp) +{ + TdxGuest *tdx =3D TDX_GUEST(obj); + + return g_strdup(tdx->mrownerconfig); +} + +static void tdx_guest_set_mrownerconfig(Object *obj, const char *value, Er= ror **errp) +{ + TdxGuest *tdx =3D TDX_GUEST(obj); + + g_free(tdx->mrownerconfig); + tdx->mrownerconfig =3D g_strdup(value); +} + /* tdx guest */ OBJECT_DEFINE_TYPE_WITH_INTERFACES(TdxGuest, tdx_guest, @@ -302,6 +380,14 @@ static void tdx_guest_init(Object *obj) object_property_add_bool(obj, "sept-ve-disable", tdx_guest_get_sept_ve_disable, tdx_guest_set_sept_ve_disable); + object_property_add_str(obj, "mrconfigid", + tdx_guest_get_mrconfigid, + tdx_guest_set_mrconfigid); + object_property_add_str(obj, "mrowner", + tdx_guest_get_mrowner, tdx_guest_set_mrowner); + object_property_add_str(obj, "mrownerconfig", + tdx_guest_get_mrownerconfig, + tdx_guest_set_mrownerconfig); } =20 static void tdx_guest_finalize(Object *obj) diff --git a/target/i386/kvm/tdx.h b/target/i386/kvm/tdx.h index e077fd7d1653..bc26e24eb9ac 100644 --- a/target/i386/kvm/tdx.h +++ b/target/i386/kvm/tdx.h @@ -22,6 +22,9 @@ typedef struct TdxGuest { bool initialized; uint64_t attributes; /* TD attributes */ uint64_t xfam; + char *mrconfigid; /* base64 encoded sha348 digest */ + char *mrowner; /* base64 encoded sha348 digest */ + char *mrownerconfig; /* base64 encoded sha348 digest */ } TdxGuest; =20 #ifdef CONFIG_TDX --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730788694; cv=none; d=zohomail.com; s=zohoarc; b=P2I24sLSrF2twShSfI0xY6sZu/kaUnPnqZvJ4bL0lWbzKnsLQ0s5koL5rLSTMQChjQmzeaMkqIEYZH01ItCZGuLdpGjApCEy+imL5FeJ+sHq6eHG6Ll7k20eRpPq4ntJOF7FlGQbpj0i2Ex/mxykJrLyKhsONsnDdMcnM/S1VRc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730788694; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1fVhnFXnzcgdVWROMJJC6Cy5ObqCKIraGgFczFmVUiM=; b=eb/SeLhnqpYa8nk1ff7x+v2hCXhaYSeAIDMm0jpnjZB4tDKmLKJFRVP9LEPlMnU5mqTGOCeJg05J3nqlF8XuVYc6nDr6xrSJgfY+u/QR0oqjFyoBKCxxVrjGduj9cOU/2KK83A2mDrC0WzaSHX4d1uG1ju1cu2wbX3pRx+2/8sM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730788694540853.0801426102859; Mon, 4 Nov 2024 22:38:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DCA-0005V3-W0; Tue, 05 Nov 2024 01:37:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBw-00051t-FL for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:37:33 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DBu-0001tE-6S for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:37:28 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:37:25 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:37:21 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788646; x=1762324646; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VOjci9p7Zb1n81rBNztaLxcXzrYXbaFL+FZxHq6NkWo=; b=lj4Vic8YfZwfCLstfDxfrsDDPvsPWL3W/kHiude85VQ048Uhgx/0c/GS R0ztmLuQUxTIZ30EMvJ2lK/tfZelvkEFmQKz8owHjmulQi8IeQegZuMnZ Psm19GkGSNMk+8MnEwxRmCZ/syCT6gbeDGhBvmt7gUnbmEv1LumKW503M UjqYEoHMSWuv5eNW8ncfV4U+2tOkP3LBYJA7GS97W7ASIpPduRbT5lYdM fkrgaZTNv3SI/R7aAqFmZbvAnKIeRXVMCMCxwkOGLynVSgOM8HnIuJ1t1 BskYF/VlPktp/RjqOFwC9xA9Bc7K3qx/Dz3Ebnj9LR4TVQfW6+/kECe96 w==; X-CSE-ConnectionGUID: JCbdk3eGSTi4bXJZo4HJJQ== X-CSE-MsgGUID: n5a5QgMEROWbCIs1VKn/5A== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689442" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689442" X-CSE-ConnectionGUID: N4Omogx0ShuO9H1a47PWkQ== X-CSE-MsgGUID: /XLDrWUYQfqYb+xEQj4Gkw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83988843" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 15/60] i386/tdx: Set APIC bus rate to match with what TDX module enforces Date: Tue, 5 Nov 2024 01:23:23 -0500 Message-Id: <20241105062408.3533704-16-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730788696803116600 Content-Type: text/plain; charset="utf-8" TDX advertises core crystal clock with cpuid[0x15] as 25MHz for TD guests and it's unchangeable from VMM. As a result, TDX guest reads the APIC timer as the same frequency, 25MHz. While KVM's default emulated frequency for APIC bus is 1GHz, set the APIC bus rate to match with TDX explicitly to ensure KVM provide correct emulated APIC timer for TD guest. Signed-off-by: Xiaoyao Li --- Changes in v6: - new patch; --- target/i386/kvm/tdx.c | 13 +++++++++++++ target/i386/kvm/tdx.h | 3 +++ 2 files changed, 16 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 887a5324b439..94b9be62c5dd 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -234,6 +234,19 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp) init_vm =3D g_malloc0(sizeof(struct kvm_tdx_init_vm) + sizeof(struct kvm_cpuid_entry2) * KVM_MAX_CPUID_EN= TRIES); =20 + if (!kvm_check_extension(kvm_state, KVM_CAP_X86_APIC_BUS_CYCLES_NS)) { + error_setg(errp, "KVM doesn't support KVM_CAP_X86_APIC_BUS_CYCLES_= NS"); + return -EOPNOTSUPP; + } + + r =3D kvm_vm_enable_cap(kvm_state, KVM_CAP_X86_APIC_BUS_CYCLES_NS, + 0, TDX_APIC_BUS_CYCLES_NS); + if (r < 0) { + error_setg_errno(errp, -r, + "Unable to set core crystal clock frequency to 25= MHz"); + return r; + } + #define SHA384_DIGEST_SIZE 48 if (tdx_guest->mrconfigid) { g_autofree uint8_t *data =3D qbase64_decode(tdx_guest->mrconfigid, diff --git a/target/i386/kvm/tdx.h b/target/i386/kvm/tdx.h index bc26e24eb9ac..0aebc7e3f6c9 100644 --- a/target/i386/kvm/tdx.h +++ b/target/i386/kvm/tdx.h @@ -14,6 +14,9 @@ typedef struct TdxGuestClass { X86ConfidentialGuestClass parent_class; } TdxGuestClass; =20 +/* TDX requires bus frequency 25MHz */ +#define TDX_APIC_BUS_CYCLES_NS 40 + typedef struct TdxGuest { X86ConfidentialGuest parent_obj; =20 --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730788969; cv=none; d=zohomail.com; s=zohoarc; b=TvNjGclA0hyPvfnnSgy4L7l/vMRges3Llep9EE/GWso8n/ZnzUd7CtscOt/8GgPiCKAbQemeyiFcSV8xgvX1dNiH7fohWlsCh7QOuCgmYkCN3IjsqjJwHPPrO21ai3FcJ9pg/0FM6spYA6hV+wTLwc10wZycFJ5h6mLFRUGsQnY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730788969; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=W3+qbwASOQ/xaiATcQ0vGU3IDXNXwFuyQCOQV5TbcZ0=; b=Ejo0CS2jW0C4K1Sr++evUaVHtDcjC/QkF3FOSO223mXbBDYuU7wgQ+rKVFnnxg4i3e7g+LfjV2piTCzuERtxMaJmSVVRGrQu5ClFvYdWeuUSRcNrAsOudQp/F2onWggrEP1+7e/x5ikprKiDn+vRRNrF1VGPXL07FbaWQrEalc4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 173078896956583.7973799524658; Mon, 4 Nov 2024 22:42:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DCK-0005su-KS; Tue, 05 Nov 2024 01:37:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DCA-0005T2-En for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:37:42 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DC8-0001tE-H4 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:37:42 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:37:30 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:37:25 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788661; x=1762324661; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pMLKK6RqyOLgwiaGzV9tdw+bbfVlPoHbIbNhAVqpC40=; b=JY8HbVOBhKgU1E3zOysuYTxWZ52r0CRYQl4B1IUPL8iq11vzZt7/fXOZ yLQQthat8O+wscoKwH4sbRvWYZvNVOpM8Z1wKqpE16dYsU7W10bfPRWRr wRNpqnUFLmc4thuglesnHTVeCaLM7LAZrZ/aohgn4a3YxXBx1xg3VcNkL tihkuSIp2kD4tmUXHjaJncQZhEUENQS7vVi/3O0gxx4wyOEoLTpHj/NhL LxKBS6GWYCb4KIL6MQCTBoI2qDXrrTY+CnmJM8CLM/3n8PrJrLAkSwMSH AdnhRhRCZilc0YlCl0cmOVQBlSrSzQwPFDVNT8ilzG7Rtt+HC3n8iu5gD g==; X-CSE-ConnectionGUID: efRsVcBQQkK0EBbAJc7qgQ== X-CSE-MsgGUID: +Fi6QumxQhGt+mvepgVRyQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689467" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689467" X-CSE-ConnectionGUID: LmwtOO5fT8i33Nqv7yvPQw== X-CSE-MsgGUID: 2V+gOx61QkK0Zyv5GT/b3g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83988865" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 16/60] i386/tdx: Implement user specified tsc frequency Date: Tue, 5 Nov 2024 01:23:24 -0500 Message-Id: <20241105062408.3533704-17-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730788971925116600 Content-Type: text/plain; charset="utf-8" Reuse "-cpu,tsc-frequency=3D" to get user wanted tsc frequency and call VM scope VM_SET_TSC_KHZ to set the tsc frequency of TD before KVM_TDX_INIT_VM. Besides, sanity check the tsc frequency to be in the legal range and legal granularity (required by TDX module). Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- Changes in v3: - use @errp to report error info; (Daniel) Changes in v1: - Use VM scope VM_SET_TSC_KHZ to set the TSC frequency of TD since KVM side drop the @tsc_khz field in struct kvm_tdx_init_vm --- target/i386/kvm/kvm.c | 9 +++++++++ target/i386/kvm/tdx.c | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index db676c1336ab..4fafc003e9a7 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -872,6 +872,15 @@ static int kvm_arch_set_tsc_khz(CPUState *cs) int r, cur_freq; bool set_ioctl =3D false; =20 + /* + * TSC of TD vcpu is immutable, it cannot be set/changed via vcpu scope + * VM_SET_TSC_KHZ, but only be initialized via VM scope VM_SET_TSC_KHZ + * before ioctl KVM_TDX_INIT_VM in tdx_pre_create_vcpu() + */ + if (is_tdx_vm()) { + return 0; + } + if (!env->tsc_khz) { return 0; } diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 94b9be62c5dd..4193211c3190 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -21,6 +21,9 @@ #include "kvm_i386.h" #include "tdx.h" =20 +#define TDX_MIN_TSC_FREQUENCY_KHZ (100 * 1000) +#define TDX_MAX_TSC_FREQUENCY_KHZ (10 * 1000 * 1000) + #define TDX_TD_ATTRIBUTES_DEBUG BIT_ULL(0) #define TDX_TD_ATTRIBUTES_SEPT_VE_DISABLE BIT_ULL(28) #define TDX_TD_ATTRIBUTES_PKS BIT_ULL(30) @@ -247,6 +250,28 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp) return r; } =20 + if (env->tsc_khz && (env->tsc_khz < TDX_MIN_TSC_FREQUENCY_KHZ || + env->tsc_khz > TDX_MAX_TSC_FREQUENCY_KHZ)) { + error_setg(errp, "Invalid TSC %ld KHz, must specify cpu_frequency " + "between [%d, %d] kHz", env->tsc_khz, + TDX_MIN_TSC_FREQUENCY_KHZ, TDX_MAX_TSC_FREQUENCY_= KHZ); + return -EINVAL; + } + + if (env->tsc_khz % (25 * 1000)) { + error_setg(errp, "Invalid TSC %ld KHz, it must be multiple of 25MH= z", + env->tsc_khz); + return -EINVAL; + } + + /* it's safe even env->tsc_khz is 0. KVM uses host's tsc_khz in this c= ase */ + r =3D kvm_vm_ioctl(kvm_state, KVM_SET_TSC_KHZ, env->tsc_khz); + if (r < 0) { + error_setg_errno(errp, -r, "Unable to set TSC frequency to %ld kHz= ", + env->tsc_khz); + return r; + } + #define SHA384_DIGEST_SIZE 48 if (tdx_guest->mrconfigid) { g_autofree uint8_t *data =3D qbase64_decode(tdx_guest->mrconfigid, --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730788680; cv=none; d=zohomail.com; s=zohoarc; b=REJY+oVDI+QBqgGqGXq08Vwk6/pJ/uzxeO0ugfXHXfJ1J9aBIg2DkGS6ADYjbVpQ1+jVxTg6k70wgfmxY67HfH17VqYQJ5oxhsTHjvXf+4KrdTAs/fTEJ3DotCG5Fanqz8RmM5/2v1Z0yESJ34YNbeqDMfvQRPIxqsSeocZrdW0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730788680; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cw73k2JclDw+UmDr1fEy/qfzR2w3IDMbnLQecJGJSmU=; b=eeulEPPTr4+kOevFEYbKbZlOdtqS0XpTbl7mcaHAPjJJR7DoBXxaNsk1BedfFMYvQ892KqHRV1bMmw4aPVvYnb9K/pO0AMt6iClOSP6yzBRSFr/36kIb4n4Y2tYK5ROEcwRIYeHNB/M7SqQVlCubR0Q13KW/NeEUboaKj5N5yqw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730788680109210.46069668372866; Mon, 4 Nov 2024 22:38:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DCE-0005kl-V3; Tue, 05 Nov 2024 01:37:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DC9-0005Rl-4K for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:37:41 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DC7-0001vJ-5L for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:37:40 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:37:38 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:37:30 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788659; x=1762324659; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eviZxt2uHCaBFHxS9OQDjWkbBKzkgFdGvefQVCQtPgg=; b=A1oG4MNKZRB6H0b7HYYv1iGqgeyi5f1ao5hDzCpt0itAXQ+5J/ctczL9 3p1ZVsxsir33nUS8RsNNNwxXcZhULA6pW4hbA2kGc3/5pmGV1WuG3JSya a/MtJPLXLTq8wzurnGlKgumWP68ZvRqLqexe3lDmfsyIAnyIvFSDMgvSZ bIQ/k2SYw/VnwCn4ze1rcr2nwMGH2ql85qWqAlKzPRN+SjdQw1HZ8bdPr v5nn6VGo4c9mPeBzMzO2gb5qzYSyt7npToK623GyzPaPtpIicP8YZ29nO 9EGs9xVx8lf2wcgN/HEuyRCuSoL71Q2YtlpPYBJY0FYezAqo4pwVbNf3E A==; X-CSE-ConnectionGUID: 5ivbuK6pSZmxtT0EBpWxLQ== X-CSE-MsgGUID: p9BFSTonQR+cc9x1QMMNlw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689480" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689480" X-CSE-ConnectionGUID: h4M+rUgqSuWhYI8H31oyhw== X-CSE-MsgGUID: rtUp98ElRPurPn+fT+1nsg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83988899" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 17/60] i386/tdx: load TDVF for TD guest Date: Tue, 5 Nov 2024 01:23:25 -0500 Message-Id: <20241105062408.3533704-18-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730788681463116600 Content-Type: text/plain; charset="utf-8" From: Chao Peng TDVF(OVMF) needs to run at private memory for TD guest. TDX cannot support pflash device since it doesn't support read-only private memory. Thus load TDVF(OVMF) with -bios option for TDs. Use memory_region_init_ram_guest_memfd() to allocate the MemoryRegion for TDVF because it needs to be located at private memory. Also store the MemoryRegion pointer of TDVF since the shared ramblock of it can be discared after it gets copied to private ramblock. Signed-off-by: Chao Peng Co-developed-by: Xiaoyao Li Signed-off-by: Xiaoyao Li --- hw/i386/x86-common.c | 6 +++++- target/i386/kvm/tdx.c | 6 ++++++ target/i386/kvm/tdx.h | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/hw/i386/x86-common.c b/hw/i386/x86-common.c index b86c38212eab..1df496a15eff 100644 --- a/hw/i386/x86-common.c +++ b/hw/i386/x86-common.c @@ -44,6 +44,7 @@ #include "standard-headers/asm-x86/bootparam.h" #include CONFIG_DEVICES #include "kvm/kvm_i386.h" +#include "kvm/tdx.h" =20 #ifdef CONFIG_XEN_EMU #include "hw/xen/xen.h" @@ -1007,11 +1008,14 @@ void x86_bios_rom_init(X86MachineState *x86ms, cons= t char *default_firmware, if (machine_require_guest_memfd(MACHINE(x86ms))) { memory_region_init_ram_guest_memfd(&x86ms->bios, NULL, "pc.bios", bios_size, &error_fatal); + if (is_tdx_vm()) { + tdx_set_tdvf_region(&x86ms->bios); + } } else { memory_region_init_ram(&x86ms->bios, NULL, "pc.bios", bios_size, &error_fatal); } - if (sev_enabled()) { + if (sev_enabled() || is_tdx_vm()) { /* * The concept of a "reset" simply doesn't exist for * confidential computing guests, we have to destroy and diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 4193211c3190..d5ebc2430fd1 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -120,6 +120,12 @@ static int get_tdx_capabilities(Error **errp) return 0; } =20 +void tdx_set_tdvf_region(MemoryRegion *tdvf_mr) +{ + assert(!tdx_guest->tdvf_mr); + tdx_guest->tdvf_mr =3D tdvf_mr; +} + static int tdx_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) { TdxGuest *tdx =3D TDX_GUEST(cgs); diff --git a/target/i386/kvm/tdx.h b/target/i386/kvm/tdx.h index 0aebc7e3f6c9..e5d836805385 100644 --- a/target/i386/kvm/tdx.h +++ b/target/i386/kvm/tdx.h @@ -28,6 +28,8 @@ typedef struct TdxGuest { char *mrconfigid; /* base64 encoded sha348 digest */ char *mrowner; /* base64 encoded sha348 digest */ char *mrownerconfig; /* base64 encoded sha348 digest */ + + MemoryRegion *tdvf_mr; } TdxGuest; =20 #ifdef CONFIG_TDX @@ -37,5 +39,6 @@ bool is_tdx_vm(void); #endif /* CONFIG_TDX */ =20 int tdx_pre_create_vcpu(CPUState *cpu, Error **errp); +void tdx_set_tdvf_region(MemoryRegion *tdvf_mr); =20 #endif /* QEMU_I386_TDX_H */ --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730788746; cv=none; d=zohomail.com; s=zohoarc; b=Om6YuWvJDRY9MIvH6aMkiahzTJ7RMg+1tCXsSqJ81sWUwFpMPgIqAkgAkROPfZUc/35VpHJw59uTlOYfo5sI+sCFfDOvau+D/SsobiTv0AIFpHhxMICuGWzariyoRb1gqs3QJAPeSvhYpc/2IC6yIWwVFc65KBXJjBbKSJEK2UU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730788746; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/qkczrKaLolruoDn+/KLz+S2SESr2iyOCTqWw4Cvwdg=; b=HjDamjLPO2s67k4iX2GND1jRpYGk7UiN523d12XrrBJalv++d6BsVgYIM32BY+zPfRYod4e8ssz4V/YzBU/QfI0EK6spgMVKq7XmGsDlQNagObZdMgZOxm2A7rHgtl5/xj/O1c3d6yAynwT0WBSJIS9OSNY3PJTAkhJTKRCyJ0Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730788746341969.7128525127233; Mon, 4 Nov 2024 22:39:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DCP-0005wS-9d; Tue, 05 Nov 2024 01:37:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DCE-0005km-Ea for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:37:46 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DCB-0001vd-T1 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:37:45 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:37:42 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:37:35 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788664; x=1762324664; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MB450M7DhV+Mw3GU//ZlpYPh2anAB1c4R48Atz8u8+E=; b=QjP9I0og9ckOriDgQxeodpG4ZNbzJsMFxvxTCDNbBwHTY9HDB3Cr/J5k nwQfB6hDwneTCdjwhIIddBryowTWyq+3nkHcvo4B3nd8NqRMVSJe6atmV JFjqYVZr1RWtlg6RohiqBV6CEZOBnwxgLoZaU8s5bFH0wAnvcrgh7LI7L HLHYIhw2hDu8rx8YljTNvwrlCqpZlZ5m+J8QYLIibjXLR1maGJkR8CBCt 90XRmWuAaO+zdzVvGkA4mXI6MRBUAVr8QfD5nbN3dzGBJzAc/M20f/UMJ 6M1+3KelYP2pHm9DB2+NxHnLrLw7Q5PtdR9auwTVkZkHZcXv/TlcG1ADT A==; X-CSE-ConnectionGUID: 3oFOTSffTPuuhV3u4/wh7g== X-CSE-MsgGUID: J37XsgkASDaJbbobVEobZA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689489" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689489" X-CSE-ConnectionGUID: rbEn1p/vQZSeVaXsKkoaBQ== X-CSE-MsgGUID: QJiZgFZnTRCR08aV8dJgjQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83988911" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 18/60] i386/tdvf: Introduce function to parse TDVF metadata Date: Tue, 5 Nov 2024 01:23:26 -0500 Message-Id: <20241105062408.3533704-19-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730788746966116600 Content-Type: text/plain; charset="utf-8" From: Isaku Yamahata TDX VM needs to boot with its specialized firmware, Trusted Domain Virtual Firmware (TDVF). QEMU needs to parse TDVF and map it in TD guest memory prior to running the TDX VM. A TDVF Metadata in TDVF image describes the structure of firmware. QEMU refers to it to setup memory for TDVF. Introduce function tdvf_parse_metadata() to parse the metadata from TDVF image and store the info of each TDVF section. TDX metadata is located by a TDX metadata offset block, which is a GUID-ed structure. The data portion of the GUID structure contains only an 4-byte field that is the offset of TDX metadata to the end of firmware file. Select X86_FW_OVMF when TDX is enable to leverage existing functions to parse and search OVMF's GUID-ed structures. Signed-off-by: Isaku Yamahata Co-developed-by: Xiaoyao Li Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- Changes in v6: - Drop the the data endianness change for metadata->Length; Changes in v1: - rename tdvf_parse_section_entry() to tdvf_parse_and_check_section_entry() Changes in RFC v4: - rename TDX_METADATA_GUID to TDX_METADATA_OFFSET_GUID --- hw/i386/Kconfig | 1 + hw/i386/meson.build | 1 + hw/i386/tdvf.c | 200 +++++++++++++++++++++++++++++++++++++++++ include/hw/i386/tdvf.h | 51 +++++++++++ 4 files changed, 253 insertions(+) create mode 100644 hw/i386/tdvf.c create mode 100644 include/hw/i386/tdvf.h diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig index 86bc10377c4f..555a000037bc 100644 --- a/hw/i386/Kconfig +++ b/hw/i386/Kconfig @@ -12,6 +12,7 @@ config SGX =20 config TDX bool + select X86_FW_OVMF depends on KVM =20 config PC diff --git a/hw/i386/meson.build b/hw/i386/meson.build index 10bdfde27c69..3bc1da2b6eb4 100644 --- a/hw/i386/meson.build +++ b/hw/i386/meson.build @@ -32,6 +32,7 @@ i386_ss.add(when: 'CONFIG_PC', if_true: files( 'port92.c')) i386_ss.add(when: 'CONFIG_X86_FW_OVMF', if_true: files('pc_sysfw_ovmf.c'), if_false: files('pc_sysfw_ovmf-stu= bs.c')) +i386_ss.add(when: 'CONFIG_TDX', if_true: files('tdvf.c')) =20 subdir('kvm') subdir('xen') diff --git a/hw/i386/tdvf.c b/hw/i386/tdvf.c new file mode 100644 index 000000000000..4afa636bfa0e --- /dev/null +++ b/hw/i386/tdvf.c @@ -0,0 +1,200 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + + * Copyright (c) 2020 Intel Corporation + * Author: Isaku Yamahata + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu/error-report.h" + +#include "hw/i386/pc.h" +#include "hw/i386/tdvf.h" +#include "sysemu/kvm.h" + +#define TDX_METADATA_OFFSET_GUID "e47a6535-984a-4798-865e-4685a7bf8ec2" +#define TDX_METADATA_VERSION 1 +#define TDVF_SIGNATURE 0x46564454 /* TDVF as little endian */ + +typedef struct { + uint32_t DataOffset; + uint32_t RawDataSize; + uint64_t MemoryAddress; + uint64_t MemoryDataSize; + uint32_t Type; + uint32_t Attributes; +} TdvfSectionEntry; + +typedef struct { + uint32_t Signature; + uint32_t Length; + uint32_t Version; + uint32_t NumberOfSectionEntries; + TdvfSectionEntry SectionEntries[]; +} TdvfMetadata; + +struct tdx_metadata_offset { + uint32_t offset; +}; + +static TdvfMetadata *tdvf_get_metadata(void *flash_ptr, int size) +{ + TdvfMetadata *metadata; + uint32_t offset =3D 0; + uint8_t *data; + + if ((uint32_t) size !=3D size) { + return NULL; + } + + if (pc_system_ovmf_table_find(TDX_METADATA_OFFSET_GUID, &data, NULL)) { + offset =3D size - le32_to_cpu(((struct tdx_metadata_offset *)data)= ->offset); + + if (offset + sizeof(*metadata) > size) { + return NULL; + } + } else { + error_report("Cannot find TDX_METADATA_OFFSET_GUID"); + return NULL; + } + + metadata =3D flash_ptr + offset; + + /* Finally, verify the signature to determine if this is a TDVF image.= */ + metadata->Signature =3D le32_to_cpu(metadata->Signature); + if (metadata->Signature !=3D TDVF_SIGNATURE) { + error_report("Invalid TDVF signature in metadata!"); + return NULL; + } + + /* Sanity check that the TDVF doesn't overlap its own metadata. */ + metadata->Length =3D le32_to_cpu(metadata->Length); + if (offset + metadata->Length > size) { + return NULL; + } + + /* Only version 1 is supported/defined. */ + metadata->Version =3D le32_to_cpu(metadata->Version); + if (metadata->Version !=3D TDX_METADATA_VERSION) { + return NULL; + } + + return metadata; +} + +static int tdvf_parse_and_check_section_entry(const TdvfSectionEntry *src, + TdxFirmwareEntry *entry) +{ + entry->data_offset =3D le32_to_cpu(src->DataOffset); + entry->data_len =3D le32_to_cpu(src->RawDataSize); + entry->address =3D le64_to_cpu(src->MemoryAddress); + entry->size =3D le64_to_cpu(src->MemoryDataSize); + entry->type =3D le32_to_cpu(src->Type); + entry->attributes =3D le32_to_cpu(src->Attributes); + + /* sanity check */ + if (entry->size < entry->data_len) { + error_report("Broken metadata RawDataSize 0x%x MemoryDataSize 0x%l= x", + entry->data_len, entry->size); + return -1; + } + if (!QEMU_IS_ALIGNED(entry->address, TARGET_PAGE_SIZE)) { + error_report("MemoryAddress 0x%lx not page aligned", entry->addres= s); + return -1; + } + if (!QEMU_IS_ALIGNED(entry->size, TARGET_PAGE_SIZE)) { + error_report("MemoryDataSize 0x%lx not page aligned", entry->size); + return -1; + } + + switch (entry->type) { + case TDVF_SECTION_TYPE_BFV: + case TDVF_SECTION_TYPE_CFV: + /* The sections that must be copied from firmware image to TD memo= ry */ + if (entry->data_len =3D=3D 0) { + error_report("%d section with RawDataSize =3D=3D 0", entry->ty= pe); + return -1; + } + break; + case TDVF_SECTION_TYPE_TD_HOB: + case TDVF_SECTION_TYPE_TEMP_MEM: + /* The sections that no need to be copied from firmware image */ + if (entry->data_len !=3D 0) { + error_report("%d section with RawDataSize 0x%x !=3D 0", + entry->type, entry->data_len); + return -1; + } + break; + default: + error_report("TDVF contains unsupported section type %d", entry->t= ype); + return -1; + } + + return 0; +} + +int tdvf_parse_metadata(TdxFirmware *fw, void *flash_ptr, int size) +{ + TdvfSectionEntry *sections; + TdvfMetadata *metadata; + ssize_t entries_size; + int i; + + metadata =3D tdvf_get_metadata(flash_ptr, size); + if (!metadata) { + return -EINVAL; + } + + /* load and parse metadata entries */ + fw->nr_entries =3D le32_to_cpu(metadata->NumberOfSectionEntries); + if (fw->nr_entries < 2) { + error_report("Invalid number of fw entries (%u) in TDVF Metadata", + fw->nr_entries); + return -EINVAL; + } + + entries_size =3D fw->nr_entries * sizeof(TdvfSectionEntry); + if (metadata->Length !=3D sizeof(*metadata) + entries_size) { + error_report("TDVF metadata len (0x%x) mismatch, expected (0x%x)", + metadata->Length, + (uint32_t)(sizeof(*metadata) + entries_size)); + return -EINVAL; + } + + fw->entries =3D g_new(TdxFirmwareEntry, fw->nr_entries); + sections =3D g_new(TdvfSectionEntry, fw->nr_entries); + + if (!memcpy(sections, (void *)metadata + sizeof(*metadata), entries_si= ze)) { + error_report("Failed to read TDVF section entries"); + goto err; + } + + for (i =3D 0; i < fw->nr_entries; i++) { + if (tdvf_parse_and_check_section_entry(§ions[i], &fw->entries[= i])) { + goto err; + } + } + g_free(sections); + + return 0; + +err: + g_free(sections); + fw->entries =3D 0; + g_free(fw->entries); + return -EINVAL; +} diff --git a/include/hw/i386/tdvf.h b/include/hw/i386/tdvf.h new file mode 100644 index 000000000000..593341eb2e93 --- /dev/null +++ b/include/hw/i386/tdvf.h @@ -0,0 +1,51 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + + * Copyright (c) 2020 Intel Corporation + * Author: Isaku Yamahata + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + */ + +#ifndef HW_I386_TDVF_H +#define HW_I386_TDVF_H + +#include "qemu/osdep.h" + +#define TDVF_SECTION_TYPE_BFV 0 +#define TDVF_SECTION_TYPE_CFV 1 +#define TDVF_SECTION_TYPE_TD_HOB 2 +#define TDVF_SECTION_TYPE_TEMP_MEM 3 + +#define TDVF_SECTION_ATTRIBUTES_MR_EXTEND (1U << 0) +#define TDVF_SECTION_ATTRIBUTES_PAGE_AUG (1U << 1) + +typedef struct TdxFirmwareEntry { + uint32_t data_offset; + uint32_t data_len; + uint64_t address; + uint64_t size; + uint32_t type; + uint32_t attributes; +} TdxFirmwareEntry; + +typedef struct TdxFirmware { + uint32_t nr_entries; + TdxFirmwareEntry *entries; +} TdxFirmware; + +int tdvf_parse_metadata(TdxFirmware *fw, void *flash_ptr, int size); + +#endif /* HW_I386_TDVF_H */ --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789233; cv=none; d=zohomail.com; s=zohoarc; b=H5KZkakzBqeBp/vkmZynBFEgG8sCzugtGrcuf1AVZAIpLdUwD/XwLSiXWf0EfjC7SEB9KZu/tYpcF2VzpcrZzuAhutCBHWK+i/47P35oui5zce1xDAryEL2ruq/wrbOdW5K15dakiP6Lxwvcl4XcE8365VE8rQxs2ebXDgTsLPo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789233; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zY4OmDZ1+xQCMYzjNR5Zcf+qVFAtKWXLadukz7REXLc=; b=cO7n8uc1fUk3l2FMkuDyq/XzV8uCUrmUsdmlVUOn1EMVP884xlcctfIleItj8fDugpQ+bE3nxzzCCXVwfiv/KBcIvcr7vYwIbkWC2Q7MEfEcKFFYY88K4FjB+Dq7A0pUZHsTyCHFrxbuytFFrL3Av1IB9HKrvucKu389pL4mPqs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789233428732.3425301852567; Mon, 4 Nov 2024 22:47:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DCT-0006In-C5; Tue, 05 Nov 2024 01:38:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DCQ-00066H-VS for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:37:59 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DCO-0001vj-CP for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:37:58 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:37:44 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:37:40 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788676; x=1762324676; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Uv4z8mL1bvbBNMAeIE2zAJ1MiSnqSKEkHnSLrWnImks=; b=bwOx2qc2iq7Xfw37v+gjCKnrEQKGMkf+fTIYYVb8eGW/7Py43z04rZTm 8Ra0YmQx12qEhHMlt3GFMhUh0RkHjolUkSyXaseHF0pvF6jY5QWNGjR+G DtpkB9tAyFVvoilPPPruJQiLVbvO1oJOH0Nt/sZvMPyrWl83GUTMfuZGb NF0ekyPqJXfUQ+3M8gA9Kz+8lfuM1AYjGhpCYtRjvwZlSjw13lWhrqkT0 UZub8Dm8KCcvcKfy+EvZaNDrEDwNMPng5JktleXSts6SWNNjawEhzM7/P 9hScXbPelvEeNvOdrs80UTSaQNCHYW95Zm1UJfjNDn9RBgYGIU4qRv9sc w==; X-CSE-ConnectionGUID: u+vxIyeBTGyKMlO9dFyIww== X-CSE-MsgGUID: 5EVdNcIcS8S8PF35UaHLSg== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689497" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689497" X-CSE-ConnectionGUID: uLi/5UJcRZuoX2fSx3LoXg== X-CSE-MsgGUID: uLUYXO3NRLOALI68fRxdFg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83988934" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 19/60] i386/tdx: Parse TDVF metadata for TDX VM Date: Tue, 5 Nov 2024 01:23:27 -0500 Message-Id: <20241105062408.3533704-20-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789234879116600 Content-Type: text/plain; charset="utf-8" After TDVF is loaded to bios MemoryRegion, it needs parse TDVF metadata. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- hw/i386/pc_sysfw.c | 7 +++++++ target/i386/kvm/tdx-stub.c | 5 +++++ target/i386/kvm/tdx.c | 5 +++++ target/i386/kvm/tdx.h | 3 +++ 4 files changed, 20 insertions(+) diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c index ef80281d28bb..5a373bf129a1 100644 --- a/hw/i386/pc_sysfw.c +++ b/hw/i386/pc_sysfw.c @@ -37,6 +37,7 @@ #include "hw/block/flash.h" #include "sysemu/kvm.h" #include "sev.h" +#include "kvm/tdx.h" =20 #define FLASH_SECTOR_SIZE 4096 =20 @@ -280,5 +281,11 @@ void x86_firmware_configure(hwaddr gpa, void *ptr, int= size) } =20 sev_encrypt_flash(gpa, ptr, size, &error_fatal); + } else if (is_tdx_vm()) { + ret =3D tdx_parse_tdvf(ptr, size); + if (ret) { + error_report("failed to parse TDVF for TDX VM"); + exit(1); + } } } diff --git a/target/i386/kvm/tdx-stub.c b/target/i386/kvm/tdx-stub.c index b614b46d3f4a..a064d583d393 100644 --- a/target/i386/kvm/tdx-stub.c +++ b/target/i386/kvm/tdx-stub.c @@ -6,3 +6,8 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp) { return -EINVAL; } + +int tdx_parse_tdvf(void *flash_ptr, int size) +{ + return -EINVAL; +} diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index d5ebc2430fd1..334dbe95cc77 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -338,6 +338,11 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp) return 0; } =20 +int tdx_parse_tdvf(void *flash_ptr, int size) +{ + return tdvf_parse_metadata(&tdx_guest->tdvf, flash_ptr, size); +} + static bool tdx_guest_get_sept_ve_disable(Object *obj, Error **errp) { TdxGuest *tdx =3D TDX_GUEST(obj); diff --git a/target/i386/kvm/tdx.h b/target/i386/kvm/tdx.h index e5d836805385..6b7926be3efe 100644 --- a/target/i386/kvm/tdx.h +++ b/target/i386/kvm/tdx.h @@ -6,6 +6,7 @@ #endif =20 #include "confidential-guest.h" +#include "hw/i386/tdvf.h" =20 #define TYPE_TDX_GUEST "tdx-guest" #define TDX_GUEST(obj) OBJECT_CHECK(TdxGuest, (obj), TYPE_TDX_GUEST) @@ -30,6 +31,7 @@ typedef struct TdxGuest { char *mrownerconfig; /* base64 encoded sha348 digest */ =20 MemoryRegion *tdvf_mr; + TdxFirmware tdvf; } TdxGuest; =20 #ifdef CONFIG_TDX @@ -40,5 +42,6 @@ bool is_tdx_vm(void); =20 int tdx_pre_create_vcpu(CPUState *cpu, Error **errp); void tdx_set_tdvf_region(MemoryRegion *tdvf_mr); +int tdx_parse_tdvf(void *flash_ptr, int size); =20 #endif /* QEMU_I386_TDX_H */ --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730788792; cv=none; d=zohomail.com; s=zohoarc; b=OoIUfNTdPBu/8AboZKQR1HovbYoBWJC+s35acNctup8m+WKnXcb/UPpfnETQ4gNPdSbvJKSBStLnwjQyxHj0ZNG1+FYRz/JVp2SERpbYUV0DZDjwy9695Cjj+Q/nJy8Qw9YD5YufV/ulO+22ODO/R0ox6QgQ6O17ygUnCWalhuE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730788792; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=E+NZiMesqX4kufl3VHC5bq6QzNKaE/uzonbHUS+G22o=; b=MX1fey1zFDAsWbUgjLHtgFdqOHabw3TWhrw+GtdtSSTn2/6pz0rTqkXVkgwVpsfPGKl75COZ1tRKndy2sImmNJ+s42njQm/a591hcgvFJKZYTVJL4Tph2hrasG/BQjj6+SrwZIngzOYYlfTbxfoJB1RBOlFZzOuLSMcFXiEtJsU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730788792293461.30735386914637; Mon, 4 Nov 2024 22:39:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DCV-0006ZN-Rv; Tue, 05 Nov 2024 01:38:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DCT-0006IC-3A for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:01 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DCR-0001vd-F2 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:00 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:37:49 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:37:44 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788679; x=1762324679; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UOhXpmceQkEx8s4Oa9vrgi40TyS418oe+WG7+rZTz0Q=; b=NRha1ua7Ozst4Om2qAcCu/C0Oiys4vNhjx6jH79KedQCNosPPMxmxQX9 x+Llj7K04aietu0BRsdVOtUJ6j9LzQX4eGChzfauErEWC/aipXVr8mCDU bWrGL0ql2mzKULs553UfGI5+IdGF0PW2Iia2mQvUOkw/3pev4pM+9DeEE vTq8szha6zUlSPsLwTu3xnuAolSeFwZtTHbd9q/s3qy64ojUu57LlwwWL Sq0LkOQJ2SCiTwi+9LzVdmJgszSSNpOGQt53T+c4pQ5IyBsNuOyHB/G2J 0m8umwABdkuhf+F9Bd24A5plr6Xc6MNIOV2mZvFf8Du7FFSUVDN6g3x+1 g==; X-CSE-ConnectionGUID: 3frwkflJRCetIJE+3FsAiw== X-CSE-MsgGUID: Iim5R/PZShmVVbz1a37ZIQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689518" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689518" X-CSE-ConnectionGUID: EWYM0303ShenTTql/6GbMg== X-CSE-MsgGUID: Nr3+H8eZQYORr8CJ9auVUg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83988959" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 20/60] i386/tdx: Don't initialize pc.rom for TDX VMs Date: Tue, 5 Nov 2024 01:23:28 -0500 Message-Id: <20241105062408.3533704-21-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730788792991116600 Content-Type: text/plain; charset="utf-8" For TDX, the address below 1MB are entirely general RAM. No need to initialize pc.rom memory region for TDs. Signed-off-by: Xiaoyao Li --- This is more as a workaround of the issue that for q35 machine type, the real memslot update (which requires memslot deletion )for pc.rom happens after tdx_init_memory_region. It leads to the private memory ADD'ed before get lost. I haven't work out a good solution to resolve the order issue. So just skip the pc.rom setup to avoid memslot deletion. --- hw/i386/pc.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 2047633e4cf7..4a23856aed47 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -43,6 +43,7 @@ #include "sysemu/xen.h" #include "sysemu/reset.h" #include "kvm/kvm_i386.h" +#include "kvm/tdx.h" #include "hw/xen/xen.h" #include "qapi/qmp/qlist.h" #include "qemu/error-report.h" @@ -966,21 +967,23 @@ void pc_memory_init(PCMachineState *pcms, /* Initialize PC system firmware */ pc_system_firmware_init(pcms, rom_memory); =20 - option_rom_mr =3D g_malloc(sizeof(*option_rom_mr)); - if (machine_require_guest_memfd(machine)) { - memory_region_init_ram_guest_memfd(option_rom_mr, NULL, "pc.rom", - PC_ROM_SIZE, &error_fatal); - } else { - memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE, - &error_fatal); - if (pcmc->pci_enabled) { - memory_region_set_readonly(option_rom_mr, true); + if (!is_tdx_vm()) { + option_rom_mr =3D g_malloc(sizeof(*option_rom_mr)); + if (machine_require_guest_memfd(machine)) { + memory_region_init_ram_guest_memfd(option_rom_mr, NULL, "pc.ro= m", + PC_ROM_SIZE, &error_fatal); + } else { + memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_S= IZE, + &error_fatal); + if (pcmc->pci_enabled) { + memory_region_set_readonly(option_rom_mr, true); + } } + memory_region_add_subregion_overlap(rom_memory, + PC_ROM_MIN_VGA, + option_rom_mr, + 1); } - memory_region_add_subregion_overlap(rom_memory, - PC_ROM_MIN_VGA, - option_rom_mr, - 1); =20 fw_cfg =3D fw_cfg_arch_create(machine, x86ms->boot_cpus, x86ms->apic_id_limit); --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789264; cv=none; d=zohomail.com; s=zohoarc; b=OcnYAV9U1c1LGPAWQh8YTlNxAL9Z3Ly3dt7KVrgQKyz/eHjg0qEe9LbZxKDGiq3hlg4S+Decr0lMVnxMFrGLSGaLpjxAjK6iI9znZX319UZmti6a+NOdErJNV9RngctF0ZoZ0rQ0Q1v6GsmyAzLyeNrvMSq41onHRJ077wELWiQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789264; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=sWmTwr2hMF2w9bYUwZ4zyKtxi11ah/OA84lA8IjKE0s=; b=eW8ljSfFFEWLMIAXUcXTTYancQatoSmGVpC+ogLqXOgN/eDzxbRFiYxkuJ6e8Z1I720q5ltl67TIfqhcZuGvD1ww0sketrpC3aD8jdVaqI2fOw5xQgjHuW1SmpvRa9LO6oX33/cQKQGg6LEBRXQI1e1OiuzzCYlreYrgsru2HJU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789264375370.89792794594666; Mon, 4 Nov 2024 22:47:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DCi-0006wn-Kj; Tue, 05 Nov 2024 01:38:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DCY-0006qW-Po for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:07 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DCW-0001w0-Nk for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:06 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:37:53 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:37:49 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788685; x=1762324685; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=O+bsng0OpqwNAjJu2viZcM1uSHuVeOnU2MBD79mzkgE=; b=PUZBP6zLhSPTE2x7zaapKFJML+dBcd9elxC554SRoPtFvJWSZeoFPSLh rfr0Nr+O7VtG5EFVOGMnp8+6TuZppwBSrGl1jts1LMracpEDjLp1QeR9a cUJD8twJIKUL/p2vR+nF72yDNVG8W4VefLqJnTTqxVVNEYyIpqZtZEEkn 66kxDgJ9BAxXNIFaHiYBGiywOzSjSD9WwZVaiSG7f40X1RMFjYSlJJrb7 YrGOonus1hr4DNUa5SwZyla9dgf07VgmM+rNnoALc8qWLxemQbXTsRsfF U6AZ7ePh8nimLfpatF9o2TESyfEqixSE6Li7bYiiyEgM9RX9HvFIDNNXM A==; X-CSE-ConnectionGUID: LTsvNPZcTAuvR8l1Thm0Xg== X-CSE-MsgGUID: SxWbRQ7zQqSP4jOF0LI4Cw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689533" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689533" X-CSE-ConnectionGUID: igX+T3kWQlmGCs/qvn4FXA== X-CSE-MsgGUID: flkki1dAQsOAxyMp0EcImg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83988983" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 21/60] i386/tdx: Track mem_ptr for each firmware entry of TDVF Date: Tue, 5 Nov 2024 01:23:29 -0500 Message-Id: <20241105062408.3533704-22-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789265155116600 Content-Type: text/plain; charset="utf-8" For each TDVF sections, QEMU needs to copy the content to guest private memory via KVM API (KVM_TDX_INIT_MEM_REGION). Introduce a field @mem_ptr for TdxFirmwareEntry to track the memory pointer of each TDVF sections. So that QEMU can add/copy them to guest private memory later. TDVF sections can be classified into two groups: - Firmware itself, e.g., TDVF BFV and CFV, that located separately from guest RAM. Its memory pointer is the bios pointer. - Sections located at guest RAM, e.g., TEMP_MEM and TD_HOB. mmap a new memory range for them. Register a machine_init_done callback to do the stuff. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- hw/i386/tdvf.c | 1 + include/hw/i386/tdvf.h | 7 +++++++ target/i386/kvm/tdx.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/hw/i386/tdvf.c b/hw/i386/tdvf.c index 4afa636bfa0e..535409f34b41 100644 --- a/hw/i386/tdvf.c +++ b/hw/i386/tdvf.c @@ -190,6 +190,7 @@ int tdvf_parse_metadata(TdxFirmware *fw, void *flash_pt= r, int size) } g_free(sections); =20 + fw->mem_ptr =3D flash_ptr; return 0; =20 err: diff --git a/include/hw/i386/tdvf.h b/include/hw/i386/tdvf.h index 593341eb2e93..d880af245a73 100644 --- a/include/hw/i386/tdvf.h +++ b/include/hw/i386/tdvf.h @@ -39,13 +39,20 @@ typedef struct TdxFirmwareEntry { uint64_t size; uint32_t type; uint32_t attributes; + + void *mem_ptr; } TdxFirmwareEntry; =20 typedef struct TdxFirmware { + void *mem_ptr; + uint32_t nr_entries; TdxFirmwareEntry *entries; } TdxFirmware; =20 +#define for_each_tdx_fw_entry(fw, e) \ + for (e =3D (fw)->entries; e !=3D (fw)->entries + (fw)->nr_entries; e++) + int tdvf_parse_metadata(TdxFirmware *fw, void *flash_ptr, int size); =20 #endif /* HW_I386_TDVF_H */ diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 334dbe95cc77..6777f66a6451 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -14,9 +14,13 @@ #include "qemu/osdep.h" #include "qemu/error-report.h" #include "qemu/base64.h" +#include "qemu/mmap-alloc.h" #include "qapi/error.h" #include "qom/object_interfaces.h" +#include "sysemu/sysemu.h" =20 +#include "hw/i386/x86.h" +#include "hw/i386/tdvf.h" #include "hw/i386/x86.h" #include "kvm_i386.h" #include "tdx.h" @@ -126,6 +130,33 @@ void tdx_set_tdvf_region(MemoryRegion *tdvf_mr) tdx_guest->tdvf_mr =3D tdvf_mr; } =20 +static void tdx_finalize_vm(Notifier *notifier, void *unused) +{ + TdxFirmware *tdvf =3D &tdx_guest->tdvf; + TdxFirmwareEntry *entry; + + for_each_tdx_fw_entry(tdvf, entry) { + switch (entry->type) { + case TDVF_SECTION_TYPE_BFV: + case TDVF_SECTION_TYPE_CFV: + entry->mem_ptr =3D tdvf->mem_ptr + entry->data_offset; + break; + case TDVF_SECTION_TYPE_TD_HOB: + case TDVF_SECTION_TYPE_TEMP_MEM: + entry->mem_ptr =3D qemu_ram_mmap(-1, entry->size, + qemu_real_host_page_size(), 0, = 0); + break; + default: + error_report("Unsupported TDVF section %d", entry->type); + exit(1); + } + } +} + +static Notifier tdx_machine_done_notify =3D { + .notify =3D tdx_finalize_vm, +}; + static int tdx_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) { TdxGuest *tdx =3D TDX_GUEST(cgs); @@ -140,6 +171,8 @@ static int tdx_kvm_init(ConfidentialGuestSupport *cgs, = Error **errp) } } =20 + qemu_add_machine_init_done_notifier(&tdx_machine_done_notify); + tdx_guest =3D tdx; return 0; } --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730788792; cv=none; d=zohomail.com; s=zohoarc; b=Zb0NcaV8gC3XKUYZWcHAqylYvEvrF6283CtHHBDdg8GxWUAf8x1a17Z6q0ZqMph9O7Dxcbg7vhR8FOr3c5CYij+rfIdakPoxqSXD7mNue9vqlcXNhb0aLNXFhovw3xQKB375l2/7GEVMHqVjE1D/206/3KTAlB3eunbgMa50Cbk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730788792; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XTTKKlCjadq3apGa1L1rFVkdcV40l4urK4JJywvb++Q=; b=LeQJ3K4VnzLHiycJMdZ7twSMN4uUeXUlm6AtSGuaT6DkodGlMs5sqllA+RpScXty0kbY+ncaCVA2PkW3lTBG+zn7Didw+CE7jt9TWyIAjYKanIeA/dMJkZ8IPfTXFJ8QPFmlWHbpzTZy6AUZiVIqGa7c6GDi/98rrCdrwzDDPIQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730788792096399.9767568753208; Mon, 4 Nov 2024 22:39:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DDJ-0007ts-EN; Tue, 05 Nov 2024 01:38:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DCe-0006xy-Pj for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:16 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DCb-0001vj-Ab for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:11 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:37:57 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:37:53 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788689; x=1762324689; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tiZmHs4SbtcRLxGmTdYVWdzKXeiosxgYMBJw0d6ZN1Y=; b=MFMPHUxDhQcKQlLug0QrAfvj5NqexNkrdTVmBQnPQwhFgN0PHvaBq2tp w5iotpqjfWYLc5wqzyitpSFP3K9PDLny8r7OHOyLLA16LOJzW3hvS27lU gtbTfLwbFZHafkdHEJcCWKw/D1CIiC3gAnbUpVd8nSUTD5QhNffMlzSpv jlBdWFxqSwY3jQlNuFWSgRPTjGHtSYpd6RHbLN8ygm/CyKzoMrFOe0vQY U67w9oQ+7SCKL0gj8Ww+piuCgkmK7GowVpAHHMpB2/swtBe+DCLqUTcgo 4dy08KuPQrKQaSDD/6P/jhBaG8a9yhIuCLq4nhZG4fm2QBWUzCjwLIlR2 w==; X-CSE-ConnectionGUID: avjBGPJnS+eMhzjvTKwVgA== X-CSE-MsgGUID: 0Z1F/r2DTDOpkq9vhUaM4w== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689543" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689543" X-CSE-ConnectionGUID: 32Lx/LQZQMqakH3q9ZtDCA== X-CSE-MsgGUID: VWRxPBIxTIWZtwHpbO/mfQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83988996" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 22/60] i386/tdx: Track RAM entries for TDX VM Date: Tue, 5 Nov 2024 01:23:30 -0500 Message-Id: <20241105062408.3533704-23-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730788793105116600 Content-Type: text/plain; charset="utf-8" The RAM of TDX VM can be classified into two types: - TDX_RAM_UNACCEPTED: default type of TDX memory, which needs to be accepted by TDX guest before it can be used and will be all-zeros after being accepted. - TDX_RAM_ADDED: the RAM that is ADD'ed to TD guest before running, and can be used directly. E.g., TD HOB and TEMP MEM that needed by TDVF. Maintain TdxRamEntries[] which grabs the initial RAM info from e820 table and mark each RAM range as default type TDX_RAM_UNACCEPTED. Then turn the range of TD HOB and TEMP MEM to TDX_RAM_ADDED since these ranges will be ADD'ed before TD runs and no need to be accepted runtime. The TdxRamEntries[] are later used to setup the memory TD resource HOB that passes memory info from QEMU to TDVF. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- Changes in v3: - use enum TdxRamType in struct TdxRamEntry; (Isaku) - Fix the indention; (Daniel) Changes in v1: - simplify the algorithm of tdx_accept_ram_range() (Suggested-by: Gerd Ho= ffman) (1) Change the existing entry to cover the accepted ram range. (2) If there is room before the accepted ram range add a TDX_RAM_UNACCEPTED entry for that. (3) If there is room after the accepted ram range add a TDX_RAM_UNACCEPTED entry for that. --- target/i386/kvm/tdx.c | 111 ++++++++++++++++++++++++++++++++++++++++++ target/i386/kvm/tdx.h | 14 ++++++ 2 files changed, 125 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 6777f66a6451..76b40f278dd4 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -19,6 +19,7 @@ #include "qom/object_interfaces.h" #include "sysemu/sysemu.h" =20 +#include "hw/i386/e820_memory_layout.h" #include "hw/i386/x86.h" #include "hw/i386/tdvf.h" #include "hw/i386/x86.h" @@ -130,11 +131,117 @@ void tdx_set_tdvf_region(MemoryRegion *tdvf_mr) tdx_guest->tdvf_mr =3D tdvf_mr; } =20 +static void tdx_add_ram_entry(uint64_t address, uint64_t length, + enum TdxRamType type) +{ + uint32_t nr_entries =3D tdx_guest->nr_ram_entries; + tdx_guest->ram_entries =3D g_renew(TdxRamEntry, tdx_guest->ram_entries, + nr_entries + 1); + + tdx_guest->ram_entries[nr_entries].address =3D address; + tdx_guest->ram_entries[nr_entries].length =3D length; + tdx_guest->ram_entries[nr_entries].type =3D type; + tdx_guest->nr_ram_entries++; +} + +static int tdx_accept_ram_range(uint64_t address, uint64_t length) +{ + uint64_t head_start, tail_start, head_length, tail_length; + uint64_t tmp_address, tmp_length; + TdxRamEntry *e; + int i; + + for (i =3D 0; i < tdx_guest->nr_ram_entries; i++) { + e =3D &tdx_guest->ram_entries[i]; + + if (address + length <=3D e->address || + e->address + e->length <=3D address) { + continue; + } + + /* + * The to-be-accepted ram range must be fully contained by one + * RAM entry. + */ + if (e->address > address || + e->address + e->length < address + length) { + return -EINVAL; + } + + if (e->type =3D=3D TDX_RAM_ADDED) { + return -EINVAL; + } + + break; + } + + if (i =3D=3D tdx_guest->nr_ram_entries) { + return -1; + } + + tmp_address =3D e->address; + tmp_length =3D e->length; + + e->address =3D address; + e->length =3D length; + e->type =3D TDX_RAM_ADDED; + + head_length =3D address - tmp_address; + if (head_length > 0) { + head_start =3D tmp_address; + tdx_add_ram_entry(head_start, head_length, TDX_RAM_UNACCEPTED); + } + + tail_start =3D address + length; + if (tail_start < tmp_address + tmp_length) { + tail_length =3D tmp_address + tmp_length - tail_start; + tdx_add_ram_entry(tail_start, tail_length, TDX_RAM_UNACCEPTED); + } + + return 0; +} + +static int tdx_ram_entry_compare(const void *lhs_, const void* rhs_) +{ + const TdxRamEntry *lhs =3D lhs_; + const TdxRamEntry *rhs =3D rhs_; + + if (lhs->address =3D=3D rhs->address) { + return 0; + } + if (le64_to_cpu(lhs->address) > le64_to_cpu(rhs->address)) { + return 1; + } + return -1; +} + +static void tdx_init_ram_entries(void) +{ + unsigned i, j, nr_e820_entries; + + nr_e820_entries =3D e820_get_table(NULL); + tdx_guest->ram_entries =3D g_new(TdxRamEntry, nr_e820_entries); + + for (i =3D 0, j =3D 0; i < nr_e820_entries; i++) { + uint64_t addr, len; + + if (e820_get_entry(i, E820_RAM, &addr, &len)) { + tdx_guest->ram_entries[j].address =3D addr; + tdx_guest->ram_entries[j].length =3D len; + tdx_guest->ram_entries[j].type =3D TDX_RAM_UNACCEPTED; + j++; + } + } + tdx_guest->nr_ram_entries =3D j; +} + static void tdx_finalize_vm(Notifier *notifier, void *unused) { TdxFirmware *tdvf =3D &tdx_guest->tdvf; TdxFirmwareEntry *entry; =20 + tdx_init_ram_entries(); + for_each_tdx_fw_entry(tdvf, entry) { switch (entry->type) { case TDVF_SECTION_TYPE_BFV: @@ -145,12 +252,16 @@ static void tdx_finalize_vm(Notifier *notifier, void = *unused) case TDVF_SECTION_TYPE_TEMP_MEM: entry->mem_ptr =3D qemu_ram_mmap(-1, entry->size, qemu_real_host_page_size(), 0, = 0); + tdx_accept_ram_range(entry->address, entry->size); break; default: error_report("Unsupported TDVF section %d", entry->type); exit(1); } } + + qsort(tdx_guest->ram_entries, tdx_guest->nr_ram_entries, + sizeof(TdxRamEntry), &tdx_ram_entry_compare); } =20 static Notifier tdx_machine_done_notify =3D { diff --git a/target/i386/kvm/tdx.h b/target/i386/kvm/tdx.h index 6b7926be3efe..c669e0d0daca 100644 --- a/target/i386/kvm/tdx.h +++ b/target/i386/kvm/tdx.h @@ -18,6 +18,17 @@ typedef struct TdxGuestClass { /* TDX requires bus frequency 25MHz */ #define TDX_APIC_BUS_CYCLES_NS 40 =20 +enum TdxRamType { + TDX_RAM_UNACCEPTED, + TDX_RAM_ADDED, +}; + +typedef struct TdxRamEntry { + uint64_t address; + uint64_t length; + enum TdxRamType type; +} TdxRamEntry; + typedef struct TdxGuest { X86ConfidentialGuest parent_obj; =20 @@ -32,6 +43,9 @@ typedef struct TdxGuest { =20 MemoryRegion *tdvf_mr; TdxFirmware tdvf; + + uint32_t nr_ram_entries; + TdxRamEntry *ram_entries; } TdxGuest; =20 #ifdef CONFIG_TDX --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789224; cv=none; d=zohomail.com; s=zohoarc; b=TOjgX0plTYgtdYt9Yb7+GH7NDRPFqMtU+Cq4WTdwdKKceARqmulsZAhcQ5fd/p4gJvjs5Ia5Fb7a9BDJC6EBnx75Xho5xLmbCF/k5Kqq+Gm0xn6rcEQT7yG5bllK9gBioqEfWRbrPsdPE7rqTHapdSXbq1xrFiMt0RVTfCaVX0o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789224; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jjhJwGLwirbYa/lLoyYcnRB8vI5CYrmsF5ADVX0TxIk=; b=M+18hO4Z9SEb0SlcLvLHuqykukk9MfTTVclsOWKhtN6iIeRuVZkrtDEqLilIMCZ4zXUzjuv1sTXZbl0TWgLdw3KVWBBVShQ7CjthxR1+2alI5GOy0LBlnW0e/KSiHRc3Cwx5pWAGXdxLDmHpFx+dWeS7a9DFdTEizAYxQ1gAn80= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789224908646.629655126074; Mon, 4 Nov 2024 22:47:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DD0-0007K5-Km; Tue, 05 Nov 2024 01:38:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DCh-000763-66 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:19 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DCe-0001vd-L9 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:14 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:38:02 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:37:58 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788693; x=1762324693; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pw70+E9f7yP0q/kg6tok3Z3RGqPvOBZoP8fDG+f0630=; b=jJ4+g5e2hlFALtviDAmS5inKIcIxKig8h9+M3tLKIoeMXYtym4p1LGtl uta/4EP4a6H/VSI7rRM+15jZjG1nlbwsL4YpwB9y5vQGa1BWakz4S9iep F9Xaz8L4xj6EB6KPsHAVdwudtpFlDS+1vcbWx73ScXwD136xHnbKqDn6s 2q9daN05PLOoNiHR+UYE4kZ+3hTLIohMRYv8DYdT8jEbXITvxz3IJQHlr 7gNedSpgbz/nKn9epUDNHjGmCdcEecFQB7ABL0WlaiH2gH1jKdW7/NZO7 RyR2QosEwwUy7mXRySp8jutce8WBPCRC6bKBwPF2ggFd6n4OJ0CTJVjZ3 A==; X-CSE-ConnectionGUID: vkzRP36vT4KKAEMSzHbuCA== X-CSE-MsgGUID: PZ4q2RRNR9maEeE3TvkUpQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689552" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689552" X-CSE-ConnectionGUID: RVGuAhgLRpqW3JT0yZtiFg== X-CSE-MsgGUID: vTO8ntceRhecz3VMf69SWw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989010" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 23/60] headers: Add definitions from UEFI spec for volumes, resources, etc... Date: Tue, 5 Nov 2024 01:23:31 -0500 Message-Id: <20241105062408.3533704-24-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789227073116600 Content-Type: text/plain; charset="utf-8" Add UEFI definitions for literals, enums, structs, GUIDs, etc... that will be used by TDX to build the UEFI Hand-Off Block (HOB) that is passed to the Trusted Domain Virtual Firmware (TDVF). All values come from the UEFI specification [1], PI spec [2] and TDVF design guide[3]. [1] UEFI Specification v2.1.0 https://uefi.org/sites/default/files/resource= s/UEFI_Spec_2_10_Aug29.pdf [2] UEFI PI spec v1.8 https://uefi.org/sites/default/files/resources/UEFI_P= I_Spec_1_8_March3.pdf [3] https://software.intel.com/content/dam/develop/external/us/en/documents= /tdx-virtual-firmware-design-guide-rev-1.pdf Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- include/standard-headers/uefi/uefi.h | 198 +++++++++++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 include/standard-headers/uefi/uefi.h diff --git a/include/standard-headers/uefi/uefi.h b/include/standard-header= s/uefi/uefi.h new file mode 100644 index 000000000000..b15aba796156 --- /dev/null +++ b/include/standard-headers/uefi/uefi.h @@ -0,0 +1,198 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * Author: Isaku Yamahata + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + * + */ + +#ifndef HW_I386_UEFI_H +#define HW_I386_UEFI_H + +/*************************************************************************= **/ +/* + * basic EFI definitions + * supplemented with UEFI Specification Version 2.8 (Errata A) + * released February 2020 + */ +/* UEFI integer is little endian */ + +typedef struct { + uint32_t Data1; + uint16_t Data2; + uint16_t Data3; + uint8_t Data4[8]; +} EFI_GUID; + +typedef enum { + EfiReservedMemoryType, + EfiLoaderCode, + EfiLoaderData, + EfiBootServicesCode, + EfiBootServicesData, + EfiRuntimeServicesCode, + EfiRuntimeServicesData, + EfiConventionalMemory, + EfiUnusableMemory, + EfiACPIReclaimMemory, + EfiACPIMemoryNVS, + EfiMemoryMappedIO, + EfiMemoryMappedIOPortSpace, + EfiPalCode, + EfiPersistentMemory, + EfiUnacceptedMemoryType, + EfiMaxMemoryType +} EFI_MEMORY_TYPE; + +#define EFI_HOB_HANDOFF_TABLE_VERSION 0x0009 + +#define EFI_HOB_TYPE_HANDOFF 0x0001 +#define EFI_HOB_TYPE_MEMORY_ALLOCATION 0x0002 +#define EFI_HOB_TYPE_RESOURCE_DESCRIPTOR 0x0003 +#define EFI_HOB_TYPE_GUID_EXTENSION 0x0004 +#define EFI_HOB_TYPE_FV 0x0005 +#define EFI_HOB_TYPE_CPU 0x0006 +#define EFI_HOB_TYPE_MEMORY_POOL 0x0007 +#define EFI_HOB_TYPE_FV2 0x0009 +#define EFI_HOB_TYPE_LOAD_PEIM_UNUSED 0x000A +#define EFI_HOB_TYPE_UEFI_CAPSULE 0x000B +#define EFI_HOB_TYPE_FV3 0x000C +#define EFI_HOB_TYPE_UNUSED 0xFFFE +#define EFI_HOB_TYPE_END_OF_HOB_LIST 0xFFFF + +typedef struct { + uint16_t HobType; + uint16_t HobLength; + uint32_t Reserved; +} EFI_HOB_GENERIC_HEADER; + +typedef uint64_t EFI_PHYSICAL_ADDRESS; +typedef uint32_t EFI_BOOT_MODE; + +typedef struct { + EFI_HOB_GENERIC_HEADER Header; + uint32_t Version; + EFI_BOOT_MODE BootMode; + EFI_PHYSICAL_ADDRESS EfiMemoryTop; + EFI_PHYSICAL_ADDRESS EfiMemoryBottom; + EFI_PHYSICAL_ADDRESS EfiFreeMemoryTop; + EFI_PHYSICAL_ADDRESS EfiFreeMemoryBottom; + EFI_PHYSICAL_ADDRESS EfiEndOfHobList; +} EFI_HOB_HANDOFF_INFO_TABLE; + +#define EFI_RESOURCE_SYSTEM_MEMORY 0x00000000 +#define EFI_RESOURCE_MEMORY_MAPPED_IO 0x00000001 +#define EFI_RESOURCE_IO 0x00000002 +#define EFI_RESOURCE_FIRMWARE_DEVICE 0x00000003 +#define EFI_RESOURCE_MEMORY_MAPPED_IO_PORT 0x00000004 +#define EFI_RESOURCE_MEMORY_RESERVED 0x00000005 +#define EFI_RESOURCE_IO_RESERVED 0x00000006 +#define EFI_RESOURCE_MEMORY_UNACCEPTED 0x00000007 +#define EFI_RESOURCE_MAX_MEMORY_TYPE 0x00000008 + +#define EFI_RESOURCE_ATTRIBUTE_PRESENT 0x00000001 +#define EFI_RESOURCE_ATTRIBUTE_INITIALIZED 0x00000002 +#define EFI_RESOURCE_ATTRIBUTE_TESTED 0x00000004 +#define EFI_RESOURCE_ATTRIBUTE_SINGLE_BIT_ECC 0x00000008 +#define EFI_RESOURCE_ATTRIBUTE_MULTIPLE_BIT_ECC 0x00000010 +#define EFI_RESOURCE_ATTRIBUTE_ECC_RESERVED_1 0x00000020 +#define EFI_RESOURCE_ATTRIBUTE_ECC_RESERVED_2 0x00000040 +#define EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED 0x00000080 +#define EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTED 0x00000100 +#define EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTED 0x00000200 +#define EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE 0x00000400 +#define EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE 0x00000800 +#define EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE 0x00001000 +#define EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE 0x00002000 +#define EFI_RESOURCE_ATTRIBUTE_16_BIT_IO 0x00004000 +#define EFI_RESOURCE_ATTRIBUTE_32_BIT_IO 0x00008000 +#define EFI_RESOURCE_ATTRIBUTE_64_BIT_IO 0x00010000 +#define EFI_RESOURCE_ATTRIBUTE_UNCACHED_EXPORTED 0x00020000 +#define EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTED 0x00040000 +#define EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTABLE 0x00080000 +#define EFI_RESOURCE_ATTRIBUTE_READ_PROTECTABLE 0x00100000 +#define EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTABLE 0x00200000 +#define EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTABLE 0x00400000 +#define EFI_RESOURCE_ATTRIBUTE_PERSISTENT 0x00800000 +#define EFI_RESOURCE_ATTRIBUTE_PERSISTABLE 0x01000000 +#define EFI_RESOURCE_ATTRIBUTE_MORE_RELIABLE 0x02000000 + +typedef uint32_t EFI_RESOURCE_TYPE; +typedef uint32_t EFI_RESOURCE_ATTRIBUTE_TYPE; + +typedef struct { + EFI_HOB_GENERIC_HEADER Header; + EFI_GUID Owner; + EFI_RESOURCE_TYPE ResourceType; + EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute; + EFI_PHYSICAL_ADDRESS PhysicalStart; + uint64_t ResourceLength; +} EFI_HOB_RESOURCE_DESCRIPTOR; + +typedef struct { + EFI_HOB_GENERIC_HEADER Header; + EFI_GUID Name; + + /* guid specific data follows */ +} EFI_HOB_GUID_TYPE; + +typedef struct { + EFI_HOB_GENERIC_HEADER Header; + EFI_PHYSICAL_ADDRESS BaseAddress; + uint64_t Length; +} EFI_HOB_FIRMWARE_VOLUME; + +typedef struct { + EFI_HOB_GENERIC_HEADER Header; + EFI_PHYSICAL_ADDRESS BaseAddress; + uint64_t Length; + EFI_GUID FvName; + EFI_GUID FileName; +} EFI_HOB_FIRMWARE_VOLUME2; + +typedef struct { + EFI_HOB_GENERIC_HEADER Header; + EFI_PHYSICAL_ADDRESS BaseAddress; + uint64_t Length; + uint32_t AuthenticationStatus; + bool ExtractedFv; + EFI_GUID FvName; + EFI_GUID FileName; +} EFI_HOB_FIRMWARE_VOLUME3; + +typedef struct { + EFI_HOB_GENERIC_HEADER Header; + uint8_t SizeOfMemorySpace; + uint8_t SizeOfIoSpace; + uint8_t Reserved[6]; +} EFI_HOB_CPU; + +typedef struct { + EFI_HOB_GENERIC_HEADER Header; +} EFI_HOB_MEMORY_POOL; + +typedef struct { + EFI_HOB_GENERIC_HEADER Header; + + EFI_PHYSICAL_ADDRESS BaseAddress; + uint64_t Length; +} EFI_HOB_UEFI_CAPSULE; + +#define EFI_HOB_OWNER_ZERO \ + ((EFI_GUID){ 0x00000000, 0x0000, 0x0000, \ + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }) + +#endif --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789269; cv=none; d=zohomail.com; s=zohoarc; b=DfK3ILL9otFDHl2pOXvdqOk0IxAkbK0U+iAdxcUZHe0w4NHyRpClmdIrH8WxNut413au+ZpP2n0mZMpEOnIYZD06r5+chNIZLXNedH4uBQL19fdQ43D8vTGSd7zULY/ML+CFkEAkPMtwnVNFV1y29G8JoIpGvRANp4axgGAddxY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789269; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lssVsLuNC4nya/Nc2kAckX+IDhzoUEe2F8xi643+m50=; b=fby6Ku7h/HUWPW0/pQaFoAbBrw+2ShLcqzB0WfS1HLW5Y3JZ7VtRVRODKbNsFs0PQmFFsP0nz9+AABlIZRgGL5lsiEZMfVbybhEu5+ZoNR5EDlwe6Eb78eMDp/OiF4PILUd0YVRqybFyLXmB+f6Sh5eptaGgR4Xpkb9bghG0cQ0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789269476268.0301996003884; Mon, 4 Nov 2024 22:47:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DD5-0007S7-4N; Tue, 05 Nov 2024 01:38:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DCm-0007CR-BZ for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:21 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DCk-0001w0-4q for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:20 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:38:06 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:38:02 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788698; x=1762324698; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ztCvbGM6vH5Ut/+6plgKBcbU9yS14b6PXdQLMgJMQR8=; b=ScoH3BaMkLJg85KwQY/NzxI2Y7wVo6xIMgemXyUkTgpQfXx5mP86h9nq f6vreLbbi9+7oTeZcniCGetReC7yvRCjzxzL6I9eQFToBmdBs3Axq8ZdE n+k2mURsp/PQp1XqZwxVHAqGIwD6UGTaTfSMHnL1cf8DgHfPWLvjMh4Rw xhfQGnvGlbSgrx+mjTtaTN8RJHioKXM6TSF78xMGR6F9rpP0TD8N8rS+H aWKtlVdV1rCO2wLWbXA3UNXe8Bq9PK07hg4RlT3Uxuzm3pOLwGEToXwRP 2qRAbW93blAQjfagKuvravfSkI3xnfVLRa7ZoVl+xazSGS6vwOeVHVeyI Q==; X-CSE-ConnectionGUID: fITmyElfSVy1fAQ+gynuug== X-CSE-MsgGUID: lKeC3msQQtqPNRw08BnlhQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689562" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689562" X-CSE-ConnectionGUID: ZLFkEOq6TdaE8lHC8X/acQ== X-CSE-MsgGUID: 3H/zKqOtTnK0X2RtBtjvWA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989023" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 24/60] i386/tdx: Setup the TD HOB list Date: Tue, 5 Nov 2024 01:23:32 -0500 Message-Id: <20241105062408.3533704-25-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789271257116600 Content-Type: text/plain; charset="utf-8" The TD HOB list is used to pass the information from VMM to TDVF. The TD HOB must include PHIT HOB and Resource Descriptor HOB. More details can be found in TDVF specification and PI specification. Build the TD HOB in TDX's machine_init_done callback. Co-developed-by: Isaku Yamahata Signed-off-by: Isaku Yamahata Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- Changes in v1: - drop the code of adding mmio resources since OVMF prepares all the MMIO hob itself. --- hw/i386/meson.build | 2 +- hw/i386/tdvf-hob.c | 147 ++++++++++++++++++++++++++++++++++++++++++ hw/i386/tdvf-hob.h | 24 +++++++ target/i386/kvm/tdx.c | 16 +++++ 4 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 hw/i386/tdvf-hob.c create mode 100644 hw/i386/tdvf-hob.h diff --git a/hw/i386/meson.build b/hw/i386/meson.build index 3bc1da2b6eb4..7896f348cff8 100644 --- a/hw/i386/meson.build +++ b/hw/i386/meson.build @@ -32,7 +32,7 @@ i386_ss.add(when: 'CONFIG_PC', if_true: files( 'port92.c')) i386_ss.add(when: 'CONFIG_X86_FW_OVMF', if_true: files('pc_sysfw_ovmf.c'), if_false: files('pc_sysfw_ovmf-stu= bs.c')) -i386_ss.add(when: 'CONFIG_TDX', if_true: files('tdvf.c')) +i386_ss.add(when: 'CONFIG_TDX', if_true: files('tdvf.c', 'tdvf-hob.c')) =20 subdir('kvm') subdir('xen') diff --git a/hw/i386/tdvf-hob.c b/hw/i386/tdvf-hob.c new file mode 100644 index 000000000000..e00de256ea8c --- /dev/null +++ b/hw/i386/tdvf-hob.c @@ -0,0 +1,147 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + + * Copyright (c) 2020 Intel Corporation + * Author: Isaku Yamahata + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qemu/error-report.h" +#include "e820_memory_layout.h" +#include "hw/i386/pc.h" +#include "hw/i386/x86.h" +#include "hw/pci/pcie_host.h" +#include "sysemu/kvm.h" +#include "standard-headers/uefi/uefi.h" +#include "tdvf-hob.h" + +typedef struct TdvfHob { + hwaddr hob_addr; + void *ptr; + int size; + + /* working area */ + void *current; + void *end; +} TdvfHob; + +static uint64_t tdvf_current_guest_addr(const TdvfHob *hob) +{ + return hob->hob_addr + (hob->current - hob->ptr); +} + +static void tdvf_align(TdvfHob *hob, size_t align) +{ + hob->current =3D QEMU_ALIGN_PTR_UP(hob->current, align); +} + +static void *tdvf_get_area(TdvfHob *hob, uint64_t size) +{ + void *ret; + + if (hob->current + size > hob->end) { + error_report("TD_HOB overrun, size =3D 0x%" PRIx64, size); + exit(1); + } + + ret =3D hob->current; + hob->current +=3D size; + tdvf_align(hob, 8); + return ret; +} + +static void tdvf_hob_add_memory_resources(TdxGuest *tdx, TdvfHob *hob) +{ + EFI_HOB_RESOURCE_DESCRIPTOR *region; + EFI_RESOURCE_ATTRIBUTE_TYPE attr; + EFI_RESOURCE_TYPE resource_type; + + TdxRamEntry *e; + int i; + + for (i =3D 0; i < tdx->nr_ram_entries; i++) { + e =3D &tdx->ram_entries[i]; + + if (e->type =3D=3D TDX_RAM_UNACCEPTED) { + resource_type =3D EFI_RESOURCE_MEMORY_UNACCEPTED; + attr =3D EFI_RESOURCE_ATTRIBUTE_TDVF_UNACCEPTED; + } else if (e->type =3D=3D TDX_RAM_ADDED) { + resource_type =3D EFI_RESOURCE_SYSTEM_MEMORY; + attr =3D EFI_RESOURCE_ATTRIBUTE_TDVF_PRIVATE; + } else { + error_report("unknown TDX_RAM_ENTRY type %d", e->type); + exit(1); + } + + region =3D tdvf_get_area(hob, sizeof(*region)); + *region =3D (EFI_HOB_RESOURCE_DESCRIPTOR) { + .Header =3D { + .HobType =3D EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, + .HobLength =3D cpu_to_le16(sizeof(*region)), + .Reserved =3D cpu_to_le32(0), + }, + .Owner =3D EFI_HOB_OWNER_ZERO, + .ResourceType =3D cpu_to_le32(resource_type), + .ResourceAttribute =3D cpu_to_le32(attr), + .PhysicalStart =3D cpu_to_le64(e->address), + .ResourceLength =3D cpu_to_le64(e->length), + }; + } +} + +void tdvf_hob_create(TdxGuest *tdx, TdxFirmwareEntry *td_hob) +{ + TdvfHob hob =3D { + .hob_addr =3D td_hob->address, + .size =3D td_hob->size, + .ptr =3D td_hob->mem_ptr, + + .current =3D td_hob->mem_ptr, + .end =3D td_hob->mem_ptr + td_hob->size, + }; + + EFI_HOB_GENERIC_HEADER *last_hob; + EFI_HOB_HANDOFF_INFO_TABLE *hit; + + /* Note, Efi{Free}Memory{Bottom,Top} are ignored, leave 'em zeroed. */ + hit =3D tdvf_get_area(&hob, sizeof(*hit)); + *hit =3D (EFI_HOB_HANDOFF_INFO_TABLE) { + .Header =3D { + .HobType =3D EFI_HOB_TYPE_HANDOFF, + .HobLength =3D cpu_to_le16(sizeof(*hit)), + .Reserved =3D cpu_to_le32(0), + }, + .Version =3D cpu_to_le32(EFI_HOB_HANDOFF_TABLE_VERSION), + .BootMode =3D cpu_to_le32(0), + .EfiMemoryTop =3D cpu_to_le64(0), + .EfiMemoryBottom =3D cpu_to_le64(0), + .EfiFreeMemoryTop =3D cpu_to_le64(0), + .EfiFreeMemoryBottom =3D cpu_to_le64(0), + .EfiEndOfHobList =3D cpu_to_le64(0), /* initialized later */ + }; + + tdvf_hob_add_memory_resources(tdx, &hob); + + last_hob =3D tdvf_get_area(&hob, sizeof(*last_hob)); + *last_hob =3D (EFI_HOB_GENERIC_HEADER) { + .HobType =3D EFI_HOB_TYPE_END_OF_HOB_LIST, + .HobLength =3D cpu_to_le16(sizeof(*last_hob)), + .Reserved =3D cpu_to_le32(0), + }; + hit->EfiEndOfHobList =3D tdvf_current_guest_addr(&hob); +} diff --git a/hw/i386/tdvf-hob.h b/hw/i386/tdvf-hob.h new file mode 100644 index 000000000000..1b737e946a8d --- /dev/null +++ b/hw/i386/tdvf-hob.h @@ -0,0 +1,24 @@ +#ifndef HW_I386_TD_HOB_H +#define HW_I386_TD_HOB_H + +#include "hw/i386/tdvf.h" +#include "target/i386/kvm/tdx.h" + +void tdvf_hob_create(TdxGuest *tdx, TdxFirmwareEntry *td_hob); + +#define EFI_RESOURCE_ATTRIBUTE_TDVF_PRIVATE \ + (EFI_RESOURCE_ATTRIBUTE_PRESENT | \ + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \ + EFI_RESOURCE_ATTRIBUTE_TESTED) + +#define EFI_RESOURCE_ATTRIBUTE_TDVF_UNACCEPTED \ + (EFI_RESOURCE_ATTRIBUTE_PRESENT | \ + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \ + EFI_RESOURCE_ATTRIBUTE_TESTED) + +#define EFI_RESOURCE_ATTRIBUTE_TDVF_MMIO \ + (EFI_RESOURCE_ATTRIBUTE_PRESENT | \ + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \ + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE) + +#endif diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 76b40f278dd4..6720c785a4ad 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -23,6 +23,7 @@ #include "hw/i386/x86.h" #include "hw/i386/tdvf.h" #include "hw/i386/x86.h" +#include "hw/i386/tdvf-hob.h" #include "kvm_i386.h" #include "tdx.h" =20 @@ -131,6 +132,19 @@ void tdx_set_tdvf_region(MemoryRegion *tdvf_mr) tdx_guest->tdvf_mr =3D tdvf_mr; } =20 +static TdxFirmwareEntry *tdx_get_hob_entry(TdxGuest *tdx) +{ + TdxFirmwareEntry *entry; + + for_each_tdx_fw_entry(&tdx->tdvf, entry) { + if (entry->type =3D=3D TDVF_SECTION_TYPE_TD_HOB) { + return entry; + } + } + error_report("TDVF metadata doesn't specify TD_HOB location."); + exit(1); +} + static void tdx_add_ram_entry(uint64_t address, uint64_t length, enum TdxRamType type) { @@ -262,6 +276,8 @@ static void tdx_finalize_vm(Notifier *notifier, void *u= nused) =20 qsort(tdx_guest->ram_entries, tdx_guest->nr_ram_entries, sizeof(TdxRamEntry), &tdx_ram_entry_compare); + + tdvf_hob_create(tdx_guest, tdx_get_hob_entry(tdx_guest)); } =20 static Notifier tdx_machine_done_notify =3D { --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789195; cv=none; d=zohomail.com; s=zohoarc; b=nNSw5xQU4RXFIXjoSIEtMXem+4oEo3I+ecMLkzSyJANvWI3ODW6Gf4KbvyCcHUuGjDedxtrHljcAyrZHVaEAexkPYy4BCHUoMngS6r0gMDQgPu0li5a7OuBKOAB5BaU3msQzYGd+iKHIqQ9fXvaVf342LIQe01R3NqvMHnLw6co= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789195; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Ia+d/YRyW9D6KLEaaKS9359ARCV3oI9dbUMnLrbIhqM=; b=KPyKTZ8f1Wix7oPehHAKXEN72AUi3P7TVYaR9vPpmVOVv6u97rXVIPOEErmVwtEoiTbrDNOkCVj36GxsFyTk88Wxgge3tTiW/biD1leMvyW+Ijikq58jLX61DpqWD6XaxHDTnazZuqRgYSW8Vc/W12bzOxX6dJIJAyaa7MT6cds= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789195192376.1783497423212; Mon, 4 Nov 2024 22:46:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DD5-0007cA-Qd; Tue, 05 Nov 2024 01:38:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DCq-0007D3-SS for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:28 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DCp-0001vj-6Y for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:24 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:38:12 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:38:06 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788703; x=1762324703; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rvObCK3RI5s5qGyDuVPMqNnDGspWafj/j5UMlEUdJUA=; b=QqKscTgaDq0UekwpPd4VlGdfuJ+AuNHHrILg7qCydeX3HK3uS68B/qgZ 0N5BJBtj47lcI7dcXnh438AY7jWb+iuqrvTtAGW+CGDllYpSg0WhY0ORb mv9xJwqvPBjhAVOUGR1gpTzTPf8uKoLnQI3Trxiigw6ImAhx/246vVxmf sljZJ7nXIGvQwTF1k1GL+JKu/e24R9iLb1HVa7v5yMoac9l9BMexBChdD FayrFNav/f7qzV7a2kKhHYNlqmQOox/pc+VPQgcKv8veosSPTnClcQc9Q Jl+ELdjKDyHdyWh1zuOcuapogrSpowuexMtpZBx4NKheedoO6vOQvEWFH Q==; X-CSE-ConnectionGUID: MxyL6mhFQ6O9FWISGb0cHg== X-CSE-MsgGUID: fgc09E45TmGeT8vwKF/pHQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689576" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689576" X-CSE-ConnectionGUID: O+gOavi8QUaJkXjcuFvZWw== X-CSE-MsgGUID: f4LDZ/alR22cvlK2YFWB8w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989038" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 25/60] i386/tdx: Add TDVF memory via KVM_TDX_INIT_MEM_REGION Date: Tue, 5 Nov 2024 01:23:33 -0500 Message-Id: <20241105062408.3533704-26-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789196793116600 Content-Type: text/plain; charset="utf-8" From: Isaku Yamahata TDVF firmware (CODE and VARS) needs to be copied to TD's private memory via KVM_TDX_INIT_MEM_REGION, as well as TD HOB and TEMP memory. If the TDVF section has TDVF_SECTION_ATTRIBUTES_MR_EXTEND set in the flag, calling KVM_TDX_EXTEND_MEMORY to extend the measurement. After populating the TDVF memory, the original image located in shared ramblock can be discarded. Signed-off-by: Isaku Yamahata Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- Changes in v6: - switch back to use KVM_TDX_INIT_MEM_REGION according to KVM's change; --- target/i386/kvm/tdx.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 6720c785a4ad..0a6ac62de7ff 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -18,6 +18,7 @@ #include "qapi/error.h" #include "qom/object_interfaces.h" #include "sysemu/sysemu.h" +#include "exec/ramblock.h" =20 #include "hw/i386/e820_memory_layout.h" #include "hw/i386/x86.h" @@ -253,6 +254,8 @@ static void tdx_finalize_vm(Notifier *notifier, void *u= nused) { TdxFirmware *tdvf =3D &tdx_guest->tdvf; TdxFirmwareEntry *entry; + RAMBlock *ram_block; + int r; =20 tdx_init_ram_entries(); =20 @@ -278,6 +281,42 @@ static void tdx_finalize_vm(Notifier *notifier, void *= unused) sizeof(TdxRamEntry), &tdx_ram_entry_compare); =20 tdvf_hob_create(tdx_guest, tdx_get_hob_entry(tdx_guest)); + + for_each_tdx_fw_entry(tdvf, entry) { + struct kvm_tdx_init_mem_region region; + uint32_t flags; + + region =3D (struct kvm_tdx_init_mem_region) { + .source_addr =3D (uint64_t)entry->mem_ptr, + .gpa =3D entry->address, + .nr_pages =3D entry->size >> 12, + }; + + flags =3D entry->attributes & TDVF_SECTION_ATTRIBUTES_MR_EXTEND ? + KVM_TDX_MEASURE_MEMORY_REGION : 0; + + do { + r =3D tdx_vcpu_ioctl(first_cpu, KVM_TDX_INIT_MEM_REGION, flags, + ®ion); + } while (r =3D=3D -EAGAIN || r =3D=3D -EINTR); + if (r < 0) { + error_report("KVM_TDX_INIT_MEM_REGION failed %s", strerror(-r)= ); + exit(1); + } + + if (entry->type =3D=3D TDVF_SECTION_TYPE_TD_HOB || + entry->type =3D=3D TDVF_SECTION_TYPE_TEMP_MEM) { + qemu_ram_munmap(-1, entry->mem_ptr, entry->size); + entry->mem_ptr =3D NULL; + } + } + + /* + * TDVF image has been copied into private region above via + * KVM_MEMORY_MAPPING. It becomes useless. + */ + ram_block =3D tdx_guest->tdvf_mr->ram_block; + ram_block_discard_range(ram_block, 0, ram_block->max_length); } =20 static Notifier tdx_machine_done_notify =3D { --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789270; cv=none; d=zohomail.com; s=zohoarc; b=QttnT97vsMhYB2ZO59LAk74bA4KxDtB3Q0Pywl7NZUCuR+p1qsOvbyDZyGyuQNJxuRUS6dldxzAJn/fnr+zQ8EFeYJjt6+/ZMy/fVl0MRBGG/70lL/6DqkPLD0eM57/1L6xXLUpD8ATsvWedPMpgSE3avsiy9drgWOu2sf6/A+A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789270; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lDyIfx0ZDHLTGU09OzvnEoEReK6zCrxaouwDVLChuwc=; b=Q62+UgVjbAaJw4KFnN2BaMvNzDtVHsXI3m9a+jjdgIPJQgSRUSlZp+f/hZkbZ9ib5hUq5pamh142Lk8KwMTk1xq23Byq7TiIEntqWW/x7NPxkezQLN5Uold4aNvxnRo3N8T5JQ6LjE7mUNhzI40dZitNX3nmBbMHeDCYcnjBTaE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789270896648.2181761156304; Mon, 4 Nov 2024 22:47:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DDQ-0008Ow-8G; Tue, 05 Nov 2024 01:39:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DCt-0007Hy-C5 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:30 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DCr-0001vd-NM for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:27 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:38:15 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:38:11 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788706; x=1762324706; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lKT4R+z384ZnSwuZplcbwrI7VIz8YVlbaPogqTQylkI=; b=J81gx0O1+YE/pqzmHhDbDMURcv/OI1zsOBo7mgpwCzw+E7libtZhGdqG rJOZHjy6Mga0IXk8BwZ8HCePQrXAL/mlVTdqD7GljpmMFJEIPb2GnJqVZ 5mGMBWcVPTi1FY9Mplp3TNCFyVK9GuBKZk57v0uFaJ4wJJMbK3VUzURrL uTn9pOSab8ecfRP8YTIAQPt+G4EyUlc3RkEJ01WSEfH223TQavAXhKiAv XdAN21lnl360zOJy3OspxqJ6r3lbHFiR9Jup/Iszb/fYJ+zZgl96AnJCx UAru38T75fZPMyo/pL4B/O2sw4rFoIsiIXKn4WEOVqJVDgubVLQ7/kRDB A==; X-CSE-ConnectionGUID: mXDBPH1VQpSvkSZT3OmHPQ== X-CSE-MsgGUID: doyJyjIbR7iKkjQDVzNv5w== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689588" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689588" X-CSE-ConnectionGUID: fMPbZ0l5SYCOMqH44oNg1w== X-CSE-MsgGUID: ghpoWLs8SMOi/kGwz41ALQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989055" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 26/60] i386/tdx: Call KVM_TDX_INIT_VCPU to initialize TDX vcpu Date: Tue, 5 Nov 2024 01:23:34 -0500 Message-Id: <20241105062408.3533704-27-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789271065116600 Content-Type: text/plain; charset="utf-8" TDX vcpu needs to be initialized by SEAMCALL(TDH.VP.INIT) and KVM provides vcpu level IOCTL KVM_TDX_INIT_VCPU for it. KVM_TDX_INIT_VCPU needs the address of the HOB as input. Invoke it for each vcpu after HOB list is created. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- target/i386/kvm/tdx.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 0a6ac62de7ff..1abca7a5be6d 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -250,6 +250,22 @@ static void tdx_init_ram_entries(void) tdx_guest->nr_ram_entries =3D j; } =20 +static void tdx_post_init_vcpus(void) +{ + TdxFirmwareEntry *hob; + CPUState *cpu; + int r; + + hob =3D tdx_get_hob_entry(tdx_guest); + CPU_FOREACH(cpu) { + r =3D tdx_vcpu_ioctl(cpu, KVM_TDX_INIT_VCPU, 0, (void *)hob->addre= ss); + if (r < 0) { + error_report("KVM_TDX_INIT_VCPU failed %s", strerror(-r)); + exit(1); + } + } +} + static void tdx_finalize_vm(Notifier *notifier, void *unused) { TdxFirmware *tdvf =3D &tdx_guest->tdvf; @@ -282,6 +298,8 @@ static void tdx_finalize_vm(Notifier *notifier, void *u= nused) =20 tdvf_hob_create(tdx_guest, tdx_get_hob_entry(tdx_guest)); =20 + tdx_post_init_vcpus(); + for_each_tdx_fw_entry(tdvf, entry) { struct kvm_tdx_init_mem_region region; uint32_t flags; --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789458; cv=none; d=zohomail.com; s=zohoarc; b=U484tES6r2GLH1rLCKRgqH/THSYURevHyouXy7Gau8psLUc4PhFbhJZ8IWjtFg9oYpF/D6qrVJN3uvb4j4OyxM4hiPQCiIwjL+PX//mh8r4TQbPZxhqYdAhrjYXq91DuV3aLS/n+mwUnAVeIIuv4HerIs0cuoFvMgeWlBu2jfmA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789458; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=eA/vT/vgOhZGgvGS6R8zk7aO3RneeAkCnFtq9YbpIeg=; b=TKaeOkDv0GEU8bkv94eIXMXHJOeL3zpOltP431LNt5X99McN5M+pSFKmpUlQwRIT11AkNYvsWFiPYRWJ2b2XUTzZqMjLM/+/aX5wGWh3yFbDAbvzTl7YYNj9fNI2ul2s3k1hFHDMeGB4hv/pufobnD55qyNtCfTPxdbjKBGW8kY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789458088385.27713668326805; Mon, 4 Nov 2024 22:50:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DDN-00088z-ON; Tue, 05 Nov 2024 01:38:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DCy-0007NG-H2 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:34 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DCw-0001w0-T8 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:32 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:38:19 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:38:15 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788711; x=1762324711; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CqV8pOHF0zado4AcM+LoYPzs2/IDXl5pQDk/iq626Nc=; b=Y/oUrl9056PH3+6F/t9+xIvaymLJ8Pd3m5WtQAtcImN7k4VuEIpDW+RH of6VMoan+ZT5PyfAzGbcZAzp9JUkR7Ujh0beDii1FMOCo9BaD6+sQ3OEy Fg4yEjNk+nM9NTxrubbJvraxux/bENu5sVm5at+akM4WzndVVZ6sDC+eG KitKKTQsyK+TlmWNzljVNTZLfRma2EjVE9oli0O+N8L7om05TCavmOpf+ v9lcTr9+4Mv6lI7+hJYyniwRwOHZAxkGT2AAS7ALCd/OR0Yg0c/d4BkUk Xo71BPJeYWHIN+lwYa54r1RNAQMvROfw2+OIvKOiN9LJgWhKSG4oewBjD Q==; X-CSE-ConnectionGUID: r8ZCd4niSSeJRKyZ3mhaBw== X-CSE-MsgGUID: dayljLufQm2e1YIH4itlOQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689602" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689602" X-CSE-ConnectionGUID: Kz4s4N8uRXmCfX4vxeZZNw== X-CSE-MsgGUID: gzLPe+K2QjucAkeJFr6zoQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989076" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 27/60] i386/tdx: Finalize TDX VM Date: Tue, 5 Nov 2024 01:23:35 -0500 Message-Id: <20241105062408.3533704-28-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789460004116600 Content-Type: text/plain; charset="utf-8" Invoke KVM_TDX_FINALIZE_VM to finalize the TD's measurement and make the TD vCPUs runnable once machine initialization is complete. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- target/i386/kvm/tdx.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 1abca7a5be6d..33d7ed039051 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -335,6 +335,13 @@ static void tdx_finalize_vm(Notifier *notifier, void *= unused) */ ram_block =3D tdx_guest->tdvf_mr->ram_block; ram_block_discard_range(ram_block, 0, ram_block->max_length); + + r =3D tdx_vm_ioctl(KVM_TDX_FINALIZE_VM, 0, NULL); + if (r < 0) { + error_report("KVM_TDX_FINALIZE_VM failed %s", strerror(-r)); + exit(0); + } + CONFIDENTIAL_GUEST_SUPPORT(tdx_guest)->ready =3D true; } =20 static Notifier tdx_machine_done_notify =3D { --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789025; cv=none; d=zohomail.com; s=zohoarc; b=PsPYbjj/yFyfQZ2Fo5wiG62Y78m/zMEGTDMpT64sKiGsb6/j5W3SZdzGQKoWN/jrCpYgwIYympWu3EQoReWVFFXum5ycLyV0x9KbN62DLDZycpVGxkT1gAbhFEONDBn5Rkcs2dEwhmN9Au8Pyf8USRQh/HSh9YjqhGJmFh4Ch0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789025; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IljKA3d5tlztaaKXiLIfucsiTCg8wsYf0T29GDFQS4g=; b=VWPHAWlS5E3Wfux4O7jJW1o4zJPCaZJcgQgvTyQcdbThjkzAacG+mtIZ2A7qSbduSKQEBZ8ogWQtjuR5pUCH2UH+qujjLWp2sO+eUxQeBGMPr1UI4NSh18ozLJMftohw0NGGw9EhMsRhEz5ZfMW7TzmMycSak+hJsYmKohqwSvk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789025353238.64788651230526; Mon, 4 Nov 2024 22:43:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DDO-0008DX-EX; Tue, 05 Nov 2024 01:38:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DD3-0007U7-NE for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:38 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DD1-0001vj-Bi for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:37 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:38:23 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:38:19 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788715; x=1762324715; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yTZNX+NQ5Q3yptqAX7/efQmRoNrRURBtZaK/2Teq53U=; b=QHB5L4XmfGlnU0sRpXAKdEb2awJCbNqlMkrALPT6EvFjhnNCISjEwFLS WX4emvncX7I/lKsOGgdV3iDy4YdOB3abuP9J1osHIvuH1OX0TNzaQPvlg +4ifuFm17tk8XxelbgKcxm5DgHHhsjWVm8HcwjQ4wJlNZYzubWdmgKHio j9swXG0CBShSq5uGuWeSdIxycPSVHcF9tUGn6cVBQFs9yJmIZSn4/MGFb tSZ2Pb6zXya+29NWzbBhHI860v7/VTxsp7/1eok0DX5V7dsLQP2f/7qSG /V490gypBxk9oD9oKyHcaLBOYKbpUrIsuWb9LN8+gqeayx/r/bikaKuBP A==; X-CSE-ConnectionGUID: 0ydHHBfaRw6qKh13/+JG4Q== X-CSE-MsgGUID: Je4kr+MxSsmSe4nL4UQ50A== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689613" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689613" X-CSE-ConnectionGUID: BJdYU1grQeKHRWNJj1QRwA== X-CSE-MsgGUID: M0YwmNanRkGKH2IyrQ+pEw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989093" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 28/60] i386/tdx: Enable user exit on KVM_HC_MAP_GPA_RANGE Date: Tue, 5 Nov 2024 01:23:36 -0500 Message-Id: <20241105062408.3533704-29-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789025859116600 Content-Type: text/plain; charset="utf-8" KVM translates TDG.VP.VMCALL to KVM_HC_MAP_GPA_RANGE, and QEMU needs to enable user exit on KVM_HC_MAP_GPA_RANGE in order to handle the memory conversion requested by TD guest. Signed-off-by: Xiaoyao Li --- changes in v6: - new patch; --- target/i386/kvm/tdx.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 33d7ed039051..b34707e93f4d 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -20,6 +20,8 @@ #include "sysemu/sysemu.h" #include "exec/ramblock.h" =20 +#include + #include "hw/i386/e820_memory_layout.h" #include "hw/i386/x86.h" #include "hw/i386/tdvf.h" @@ -362,6 +364,11 @@ static int tdx_kvm_init(ConfidentialGuestSupport *cgs,= Error **errp) } } =20 + /* TDX relies on KVM_HC_MAP_GPA_RANGE to handle TDG.VP.VMCALL = */ + if (!kvm_enable_hypercall(BIT_ULL(KVM_HC_MAP_GPA_RANGE))) { + return -EOPNOTSUPP; + } + qemu_add_machine_init_done_notifier(&tdx_machine_done_notify); =20 tdx_guest =3D tdx; --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789040; cv=none; d=zohomail.com; s=zohoarc; b=Hmg9CC1ynlflTQqW1R5493omElVea3NicAhKJUmQ7WKlJLIGZUTCSwTR+X9QiLUzbKKyaMcDIDVLtKE5dkzvZmk/0GJppYH9siXm3xYk24MT5kv42e6/PnN3uSB1E0EqvlqvHrI1BFTyk682cvbK2yzNkZ9yHtRKvk42FPUBwQQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789040; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NgOXXkCzDZ5CTniw0bm6lWml4RJOKfURYCTEyQ2LOeI=; b=NitxBh2NanMYTQgq+EifVoLpFitIcXhMpFnGyUwdBeNTgcH38UGICjNXoeAqZDw1Opm2TPrHzUd+7B3Qol95XATuGztE3FB4fnqeijDNlH3hepPSfW1xRa5KRzSAv+QM9lSWcU2BYsyte1VHaDPkPgjdysnQJ81Ss5lKx1JuHzo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17307890401671022.3053027358097; Mon, 4 Nov 2024 22:44:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DDS-0000AM-5U; Tue, 05 Nov 2024 01:39:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DD6-0007lN-1U for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:44 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DD4-0001vd-4c for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:39 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:38:27 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:38:23 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788718; x=1762324718; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hTO3AoGf1nt//dmP+tTmzwZEz/P9eM+x0h2usNJWysY=; b=N0wHGTlVj39h8rYeXfY4lBAWb9ljfncyRfaDFsK1pgy7jFoA4lAhlzLY qRLBQmV3N8qthzLAebQ1uVhZU9efTpr9DMtSq+uCGEIhHAwQ1GjXn02jW sJIC0pltZw/6nkkRxFwS+TAs2dO7EM0kt5MRbp8GqGfoas3VLORwvurot YIG81UDVQJtTqYJdliIVxzbu3KVKlZtJNqevxgQ/BKYMecsd25aJYvVZm EQ3PP1xB9xIO5tvzc5CJ6km4lHh1w2F45hW3YtuSO6vRVLNNX2MGiDsTm FSAGXpBFNeI27bCVKEdEcqrXjqyRqhsSfCQ9R8XIP9f5GZ7Zl5qPNCPPn A==; X-CSE-ConnectionGUID: Be/x2GTEQoug2BbLuYyeow== X-CSE-MsgGUID: C3ZQI1AzSoq3O7PSdW8lCA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689634" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689634" X-CSE-ConnectionGUID: 6+S6bBOERHqqKH31mEtJoA== X-CSE-MsgGUID: 0k0dK/97R56/U3RTPqjZig== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989108" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 29/60] i386/tdx: Handle KVM_SYSTEM_EVENT_TDX_FATAL Date: Tue, 5 Nov 2024 01:23:37 -0500 Message-Id: <20241105062408.3533704-30-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789041934116600 Content-Type: text/plain; charset="utf-8" TD guest can use TDG.VP.VMCALL to request termination. KVM translates such request into KVM_EXIT_SYSTEM_EVENT with type of KVM_SYSTEM_EVENT_TDX_FATAL. Add hanlder for such exit. Parse and print the error message, and terminate the TD guest in the handler. Signed-off-by: Xiaoyao Li --- Changes in v6: - replace the patch " i386/tdx: Handle TDG.VP.VMCALL" in v5; --- target/i386/kvm/kvm.c | 10 ++++++++++ target/i386/kvm/tdx-stub.c | 5 +++++ target/i386/kvm/tdx.c | 24 ++++++++++++++++++++++++ target/i386/kvm/tdx.h | 2 ++ 4 files changed, 41 insertions(+) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 4fafc003e9a7..dea0f83370d5 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -6116,6 +6116,16 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_ru= n *run) case KVM_EXIT_HYPERCALL: ret =3D kvm_handle_hypercall(run); break; + case KVM_EXIT_SYSTEM_EVENT: + switch (run->system_event.type) { + case KVM_SYSTEM_EVENT_TDX_FATAL: + ret =3D tdx_handle_report_fatal_error(cpu, run); + break; + default: + ret =3D -1; + break; + } + break; default: fprintf(stderr, "KVM: unknown exit reason %d\n", run->exit_reason); ret =3D -1; diff --git a/target/i386/kvm/tdx-stub.c b/target/i386/kvm/tdx-stub.c index a064d583d393..b5cb6d56c46a 100644 --- a/target/i386/kvm/tdx-stub.c +++ b/target/i386/kvm/tdx-stub.c @@ -11,3 +11,8 @@ int tdx_parse_tdvf(void *flash_ptr, int size) { return -EINVAL; } + +int tdx_handle_report_fatal_error(X86CPU *cpu, struct kvm_run *run) +{ + return -EINVAL; +} diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index b34707e93f4d..3f44dfbf6585 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -574,6 +574,30 @@ int tdx_parse_tdvf(void *flash_ptr, int size) return tdvf_parse_metadata(&tdx_guest->tdvf, flash_ptr, size); } =20 +int tdx_handle_report_fatal_error(X86CPU *cpu, struct kvm_run *run) +{ + uint64_t error_code =3D run->system_event.data[0]; + char *message =3D NULL; + + if (error_code & 0xffff) { + error_report("TDX: REPORT_FATAL_ERROR: invalid error code: 0x%lx", + error_code); + return -1; + } + + /* It has optional message */ + if (run->system_event.data[2]) { +#define TDX_FATAL_MESSAGE_MAX 64 + message =3D g_malloc0(TDX_FATAL_MESSAGE_MAX + 1); + + memcpy(message, &run->system_event.data[2], TDX_FATAL_MESSAGE_MAX); + message[TDX_FATAL_MESSAGE_MAX] =3D '\0'; + } + + error_report("TD guest reports fatal error. %s", message ? : ""); + return -1; +} + static bool tdx_guest_get_sept_ve_disable(Object *obj, Error **errp) { TdxGuest *tdx =3D TDX_GUEST(obj); diff --git a/target/i386/kvm/tdx.h b/target/i386/kvm/tdx.h index c669e0d0daca..7222a5d31359 100644 --- a/target/i386/kvm/tdx.h +++ b/target/i386/kvm/tdx.h @@ -6,6 +6,7 @@ #endif =20 #include "confidential-guest.h" +#include "cpu.h" #include "hw/i386/tdvf.h" =20 #define TYPE_TDX_GUEST "tdx-guest" @@ -57,5 +58,6 @@ bool is_tdx_vm(void); int tdx_pre_create_vcpu(CPUState *cpu, Error **errp); void tdx_set_tdvf_region(MemoryRegion *tdvf_mr); int tdx_parse_tdvf(void *flash_ptr, int size); +int tdx_handle_report_fatal_error(X86CPU *cpu, struct kvm_run *run); =20 #endif /* QEMU_I386_TDX_H */ --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789221; cv=none; d=zohomail.com; s=zohoarc; b=FdRgh4wuRGShWONiZfurSN+vfHDYq+fnZnL/vcxsbgBBSr8CWlxsgCPb2QEPkZFaJ8ofwmuAXVS/PimSS3C/mSWG+nwLV5H4QAl2RmSKo3af4rDKZ995HlkRMQ9xSFhB8/Ozl+wn1C9W96S0/6XC0TcDAU0ZAKIOW4gYKAfMJ8k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789221; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=l0EjObk8QQ/1pO01B5tq4hq6iDxxD9X33xbBAYRBIj8=; b=PM451yy9MwpB3s8gjBR/opQfNuZ2VNrrkv1RVptIqbugViFFJYA5hO2krPPM3fdwrGffBFmxvYXZcYNlUKAiZTnzyK3PRrXB67w7hErXFB5igJQdvYxKA5PUK0Qi5rVbrE4QE+g8TvIScd75BN2Zeda10hGpD8UYb4I9TwnCpiY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789221661716.7570312857019; Mon, 4 Nov 2024 22:47:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DDd-0000ef-B8; Tue, 05 Nov 2024 01:39:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDB-0007uW-3w for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:51 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DD9-0001w0-2x for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:44 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:38:32 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:38:27 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788723; x=1762324723; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6uInE5yDbMnbDX6d9fyJjDXgIoMCCobDyV6ItNz4Zao=; b=UuQFuDBQVGTCq7SLg8jQDgR1t1MOIpyj/GpmU4BGBrjoGH1mHnuz21jp Eq33agUO7xykpLbL5JqEzdX2BITv1J3vOWddwcJc4hxdSmU6MAfGubCwJ g7fTOzneckZNaaMB5v0raxhoKym0F64cqAprP2PgAOIrpVBUvkm6o+LdE ie0e3PmJm1MLMbQmTI7Vg7l86ozekrEddcrNJKhoYgLtnMAtt5uA75iUm XoWW8OsfXkmfOyKCRh5yzKVLZlYOXp5Ie6tqMPSr3aU9Bc2NlAwBYyq5i EGX9ax8IL/XEiBwODxGCi2VSopObfS9K5d0RJJXul2L5GZwL9E+uBEt1x Q==; X-CSE-ConnectionGUID: hycp3DhGQvCfF4VPkoNKvA== X-CSE-MsgGUID: fjoXKwBrSeSNtUGiaL/I0Q== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689652" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689652" X-CSE-ConnectionGUID: svLfrtNRRe2nzq6dLY2BYA== X-CSE-MsgGUID: iUPoEBAiSDGKObyzPN4S6A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989128" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 30/60] i386/tdx: Wire TDX_REPORT_FATAL_ERROR with GuestPanic facility Date: Tue, 5 Nov 2024 01:23:38 -0500 Message-Id: <20241105062408.3533704-31-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789223263116600 Content-Type: text/plain; charset="utf-8" Integrate TDX's TDX_REPORT_FATAL_ERROR into QEMU GuestPanic facility Originated-from: Isaku Yamahata Signed-off-by: Xiaoyao Li --- Changes in v6: - change error_code of GuestPanicInformationTdx from uint64_t to uint32_t, to only contains the bit 31:0 returned in r12. Changes in v5: - mention additional error information in gpa when it presents; - refine the documentation; (Markus) Changes in v4: - refine the documentation; (Markus) Changes in v3: - Add docmentation of new type and struct; (Daniel) - refine the error message handling; (Daniel) --- qapi/run-state.json | 31 +++++++++++++++++++++-- system/runstate.c | 58 +++++++++++++++++++++++++++++++++++++++++++ target/i386/kvm/tdx.c | 24 +++++++++++++++++- 3 files changed, 110 insertions(+), 3 deletions(-) diff --git a/qapi/run-state.json b/qapi/run-state.json index ce95cfa46b73..c5b0b747b30d 100644 --- a/qapi/run-state.json +++ b/qapi/run-state.json @@ -501,10 +501,12 @@ # # @s390: s390 guest panic information type (Since: 2.12) # +# @tdx: tdx guest panic information type (Since: 9.0) +# # Since: 2.9 ## { 'enum': 'GuestPanicInformationType', - 'data': [ 'hyper-v', 's390' ] } + 'data': [ 'hyper-v', 's390', 'tdx' ] } =20 ## # @GuestPanicInformation: @@ -519,7 +521,8 @@ 'base': {'type': 'GuestPanicInformationType'}, 'discriminator': 'type', 'data': {'hyper-v': 'GuestPanicInformationHyperV', - 's390': 'GuestPanicInformationS390'}} + 's390': 'GuestPanicInformationS390', + 'tdx' : 'GuestPanicInformationTdx'}} =20 ## # @GuestPanicInformationHyperV: @@ -598,6 +601,30 @@ 'psw-addr': 'uint64', 'reason': 'S390CrashReason'}} =20 +## +# @GuestPanicInformationTdx: +# +# TDX Guest panic information specific to TDX, as specified in the +# "Guest-Hypervisor Communication Interface (GHCI) Specification", +# section TDG.VP.VMCALL. +# +# @error-code: TD-specific error code +# +# @message: Human-readable error message provided by the guest. Not +# to be trusted. +# +# @gpa: guest-physical address of a page that contains more verbose +# error information, as zero-terminated string. Present when the +# "GPA valid" bit (bit 63) is set in @error-code. +# +# +# Since: 9.0 +## +{'struct': 'GuestPanicInformationTdx', + 'data': {'error-code': 'uint32', + 'message': 'str', + '*gpa': 'uint64'}} + ## # @MEMORY_FAILURE: # diff --git a/system/runstate.c b/system/runstate.c index c2c9afa905a6..9bb8162eb28f 100644 --- a/system/runstate.c +++ b/system/runstate.c @@ -565,6 +565,52 @@ static void qemu_system_wakeup(void) } } =20 +static char *tdx_parse_panic_message(char *message) +{ + bool printable =3D false; + char *buf =3D NULL; + int len =3D 0, i; + + /* + * Although message is defined as a json string, we shouldn't + * unconditionally treat it as is because the guest generated it and + * it's not necessarily trustable. + */ + if (message) { + /* The caller guarantees the NUL-terminated string. */ + len =3D strlen(message); + + printable =3D len > 0; + for (i =3D 0; i < len; i++) { + if (!(0x20 <=3D message[i] && message[i] <=3D 0x7e)) { + printable =3D false; + break; + } + } + } + + if (!printable && len) { + /* 3 =3D length of "%02x " */ + buf =3D g_malloc(len * 3); + for (i =3D 0; i < len; i++) { + if (message[i] =3D=3D '\0') { + break; + } else { + sprintf(buf + 3 * i, "%02x ", message[i]); + } + } + if (i > 0) + /* replace the last ' '(space) to NUL */ + buf[i * 3 - 1] =3D '\0'; + else + buf[0] =3D '\0'; + + return buf; + } + + return message; +} + void qemu_system_guest_panicked(GuestPanicInformation *info) { qemu_log_mask(LOG_GUEST_ERROR, "Guest crashed"); @@ -606,7 +652,19 @@ void qemu_system_guest_panicked(GuestPanicInformation = *info) S390CrashReason_str(info->u.s390.reason), info->u.s390.psw_mask, info->u.s390.psw_addr); + } else if (info->type =3D=3D GUEST_PANIC_INFORMATION_TYPE_TDX) { + qemu_log_mask(LOG_GUEST_ERROR, + "\nTDX guest reports fatal error:" + " error code: 0x%" PRIx32 " error message:\"%s\"= \n", + info->u.tdx.error_code, + tdx_parse_panic_message(info->u.tdx.message)); + if (info->u.tdx.gpa !=3D -1ull) { + qemu_log_mask(LOG_GUEST_ERROR, "Additional error informati= on " + "can be found at gpa page: 0x%" PRIx64 "\n", + info->u.tdx.gpa); + } } + qapi_free_GuestPanicInformation(info); } } diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 3f44dfbf6585..394f1d75dc0d 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -17,6 +17,7 @@ #include "qemu/mmap-alloc.h" #include "qapi/error.h" #include "qom/object_interfaces.h" +#include "sysemu/runstate.h" #include "sysemu/sysemu.h" #include "exec/ramblock.h" =20 @@ -574,10 +575,25 @@ int tdx_parse_tdvf(void *flash_ptr, int size) return tdvf_parse_metadata(&tdx_guest->tdvf, flash_ptr, size); } =20 +static void tdx_panicked_on_fatal_error(X86CPU *cpu, uint64_t error_code, + char *message, uint64_t gpa) +{ + GuestPanicInformation *panic_info; + + panic_info =3D g_new0(GuestPanicInformation, 1); + panic_info->type =3D GUEST_PANIC_INFORMATION_TYPE_TDX; + panic_info->u.tdx.error_code =3D (uint32_t) error_code; + panic_info->u.tdx.message =3D message; + panic_info->u.tdx.gpa =3D gpa; + + qemu_system_guest_panicked(panic_info); +} + int tdx_handle_report_fatal_error(X86CPU *cpu, struct kvm_run *run) { uint64_t error_code =3D run->system_event.data[0]; char *message =3D NULL; + uint64_t gpa =3D -1ull; =20 if (error_code & 0xffff) { error_report("TDX: REPORT_FATAL_ERROR: invalid error code: 0x%lx", @@ -594,7 +610,13 @@ int tdx_handle_report_fatal_error(X86CPU *cpu, struct = kvm_run *run) message[TDX_FATAL_MESSAGE_MAX] =3D '\0'; } =20 - error_report("TD guest reports fatal error. %s", message ? : ""); +#define TDX_REPORT_FATAL_ERROR_GPA_VALID BIT_ULL(63) + if (error_code & TDX_REPORT_FATAL_ERROR_GPA_VALID) { + gpa =3D run->system_event.data[1]; + } + + tdx_panicked_on_fatal_error(cpu, error_code, message, gpa); + return -1; } =20 --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730788933; cv=none; d=zohomail.com; s=zohoarc; b=g4rKy1znwdCUqwhZdJBVGoUd2QQVr+bpUptsVZybms6Klqa/S6O14xyY7lqrcqi/okYmb7nK8LDQIuDXdBNPJAvyw7RM4S2EO3CJh6b7ujVNBaMXhdueBtieIH3YuW8hhHi0EoJkbRKAYAX/h8I5sc/SGNXbDifS0b0U0RygDJ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730788933; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vQpqvqA3uWeof92xgsJ+2rwRF+90JeTnnUzo0QpEzOk=; b=LpRh/rxuVJNn+pP/LevOMZBB40xRiFBeXKSJ30LAyZEv5o5TWIrnIuVV8TXwQfGa0i8+QdUFMxNMaLitk00TRs/dufs+TIUbMIthRBISl3zjcb7Vh6AE/CnQtLIGwPGYAqtAl+A3+KBbLSjAK+TmwZ1i1n6omRtXNRqwYN2Rms4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTP id 1730788933848420.88568600424435; Mon, 4 Nov 2024 22:42:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DEB-0001Cl-2x; Tue, 05 Nov 2024 01:39:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDG-0007xo-UT for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:53 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDF-0001vj-9n for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:50 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:38:36 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:38:32 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788729; x=1762324729; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PjQf7e/17C3WWdlE56nodz232TMn447UvRVBPAlFKX4=; b=nAg6lAzF8wis5CFbO1FR1Gcr5K/dF7EwQdAu18/4WXYuEeEs+c3wtqgK /zjMDjF7gFE+r00eTQa3OFfIIg0HGugZp0CZChvM6IVd46OfRU2ZtypM8 s1YX901uB9IKT7u4nY354K009mi0hK5vYPzyYN4QoifM9l26V/sGy30ZP lY8Lds474OcE2qqOcoZ7cI91QDkCLHqJPO5N92/VOfr6wf8Yyr3cw4OxX YFrfJg9FctDEtB6mTpnvu2PiTY9EhpMHlVvXSYdsoApJ7POeSjcuyMkMJ JjM9+8JP5e9V775NHOMcCh0NTXoYdC1xjF7wXBd9I+JfcnC7fJs1hXEgO g==; X-CSE-ConnectionGUID: I2M16RwaSU64L2Js+ffg0Q== X-CSE-MsgGUID: rz6ubgvoTI+JYiU3KKg5zw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689667" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689667" X-CSE-ConnectionGUID: HBu2ooFlQVmCgAlxAclJfw== X-CSE-MsgGUID: YoO5oAvySVuB4CPn/mfq7w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989162" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 31/60] i386/cpu: introduce x86_confidential_guest_cpu_instance_init() Date: Tue, 5 Nov 2024 01:23:39 -0500 Message-Id: <20241105062408.3533704-32-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730788935492116600 Content-Type: text/plain; charset="utf-8" To allow execute confidential guest specific cpu init operations. Signed-off-by: Xiaoyao Li --- Changes in v6: - new patch; --- target/i386/confidential-guest.h | 11 +++++++++++ target/i386/cpu.c | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/target/i386/confidential-guest.h b/target/i386/confidential-gu= est.h index 7342d2843aa5..38169ed68e06 100644 --- a/target/i386/confidential-guest.h +++ b/target/i386/confidential-guest.h @@ -39,6 +39,7 @@ struct X86ConfidentialGuestClass { =20 /* */ int (*kvm_type)(X86ConfidentialGuest *cg); + void (*cpu_instance_init)(X86ConfidentialGuest *cg, CPUState *cpu); uint32_t (*mask_cpuid_features)(X86ConfidentialGuest *cg, uint32_t fea= ture, uint32_t index, int reg, uint32_t value); }; @@ -59,6 +60,16 @@ static inline int x86_confidential_guest_kvm_type(X86Con= fidentialGuest *cg) } } =20 +static inline void x86_confidential_guest_cpu_instance_init(X86Confidentia= lGuest *cg, + CPUState *cpu) +{ + X86ConfidentialGuestClass *klass =3D X86_CONFIDENTIAL_GUEST_GET_CLASS(= cg); + + if (klass->cpu_instance_init) { + klass->cpu_instance_init(cg, cpu); + } +} + /** * x86_confidential_guest_mask_cpuid_features: * diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 3baa95481fbc..c7d65bbeab9b 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -35,6 +35,7 @@ #include "hw/qdev-properties.h" #include "hw/i386/topology.h" #ifndef CONFIG_USER_ONLY +#include "confidential-guest.h" #include "sysemu/reset.h" #include "qapi/qapi-commands-machine-target.h" #include "exec/address-spaces.h" @@ -8157,6 +8158,15 @@ static void x86_cpu_post_initfn(Object *obj) } =20 accel_cpu_instance_init(CPU(obj)); + +#ifndef CONFIG_USER_ONLY + MachineState *ms =3D MACHINE(object_dynamic_cast(qdev_get_machine(), + TYPE_MACHINE)); + if (ms && ms->cgs) { + x86_confidential_guest_cpu_instance_init(X86_CONFIDENTIAL_GUEST(ms= ->cgs), + (CPU(obj))); + } +#endif } =20 static void x86_cpu_init_default_topo(X86CPU *cpu) --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730788974; cv=none; d=zohomail.com; s=zohoarc; b=VeGqSqMuoDFNxv8IAKfSg3imb1OUHB9pYcaYXNupS8nFO9zgdM7SSQpLqfA6U+y68KrSR2iCvBrxsOS1VgYqkOZCL75CKAEykHIzwAlKV+ce4r8r5V+XBHzv4m4pgLBddyUiawGs/U9pFxUntlSvCNtAvLynZdHuc1qAb8tYahw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730788974; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=x8ET4bS3iIkB5HDUgRIRmimWTHHt1W70E85dTADn5tE=; b=WQE6JuQpWy3/sEHgbpdUVVl3MxStoobImHGA/PbZGA3nFwxuzGjincPtn8y2cZs/XPEEFZf680NE5utSeNsn94HBTL4xHh8Yr/7SrF3gjXgCPTU9nQ+4XLfYVMey/0dAmqa8jsGAzEcCkqNK2uRClz4qFsejh6y10uHOuHMfJV8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 173078897445361.20736620146397; Mon, 4 Nov 2024 22:42:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DEE-0001ZT-QO; Tue, 05 Nov 2024 01:39:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDJ-0007yX-LL for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:55 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDG-0001vd-LK for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:52 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:38:40 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:38:36 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788731; x=1762324731; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IFyldM/wkLLjkzgvXirqmq3JCBeSDG+HIbY0Aejj2GY=; b=jY5Xol2L2k9Yl/rytxWsgRZPJMHRIXRyWdaDkRFfDvIFukH2usdmTy5j xo1NPXyvdodpUe6MiJMplqBJUaORso2qx1ELZmbGQMillglOD8PHeIgt+ SyC/njbY+tIx7go2Xk0hlYOFLajCE84e4dd1rqv4LqEH0h1ihwKkvPPac jAlJO/7AXEYXSUdRnbKZYcmzxOWqihzaf3Icqp0gAPDjCaDZF/VKBRBW1 f9Iz9zwEuHyE0fkq/PEpcXS5sO0tS38csgqQOOomoy9MBYv+DeloNwkb+ C2L6OA93U2vHTDlUrNg7mNx8xw846NZYx62wkr4e4PnUC7/00mVAfiphM w==; X-CSE-ConnectionGUID: vLbXF8/ASZWx0BbpdUDSXQ== X-CSE-MsgGUID: OYsubaVMT2WkfyZmkPCg+A== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689680" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689680" X-CSE-ConnectionGUID: iuT24egDTnOHJU8nk9k9hQ== X-CSE-MsgGUID: 35Pm2IzXRcuowvndLGKt2A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989208" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 32/60] i386/tdx: implement tdx_cpu_instance_init() Date: Tue, 5 Nov 2024 01:23:40 -0500 Message-Id: <20241105062408.3533704-33-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730788975603116600 Content-Type: text/plain; charset="utf-8" Currently, pmu is not supported for TDX by KVM. Signed-off-by: Xiaoyao Li --- chanegs in v6: - new patch; --- target/i386/kvm/tdx.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 394f1d75dc0d..61fb1f184149 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -384,6 +384,11 @@ static int tdx_kvm_type(X86ConfidentialGuest *cg) return KVM_X86_TDX_VM; } =20 +static void tdx_cpu_instance_init(X86ConfidentialGuest *cg, CPUState *cpu) +{ + object_property_set_bool(OBJECT(cpu), "pmu", false, &error_abort); +} + static int tdx_validate_attributes(TdxGuest *tdx, Error **errp) { if ((tdx->attributes & ~tdx_caps->supported_attrs)) { @@ -727,4 +732,5 @@ static void tdx_guest_class_init(ObjectClass *oc, void = *data) =20 klass->kvm_init =3D tdx_kvm_init; x86_klass->kvm_type =3D tdx_kvm_type; + x86_klass->cpu_instance_init =3D tdx_cpu_instance_init; } --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789270; cv=none; d=zohomail.com; s=zohoarc; b=O4K+tCUFCA9tZKyfT09jWX97D+GS7of8JdKr59W01wQ92NT/Sy/5Ilh/ommegINp/hmeC1e+ml+C687+ZpXLtFrv+b/NypwtXYfSeLMiPS1nre8SFrHIt7OY4sc5OrMWdq0163uv29ziJaSBA1HIlaTbdjR/xjZWn7+2rvwEbDs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789270; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XtWtv1+N8nTYy4SEc0JXoLi2ncdLwMrQJNGj3taUgR8=; b=OOg+dACJXYOh5ELlUlY5UysxyM73YYbp0Q3Ugt5EwSoNR5xDfm2Bu7AgV4/dTwoC+hn7+gE96RzmuxWZ0UVmuVq70vlOXKOzwRyS7rxMMDzbg5YAcODLJLVAViyw3kBsH72DeBan7IaxBZeqkJtnPrWeZzWdHBY3e/NrCo/+5Zk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789270049239.44194936771294; Mon, 4 Nov 2024 22:47:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DDZ-0000XA-Bf; Tue, 05 Nov 2024 01:39:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDN-000896-I8 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:57 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDL-0001w0-F3 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:38:57 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:38:45 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:38:40 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788735; x=1762324735; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=63P5g04tq2r6PcAIPsWb8iPHQuE0MH+gEuTLFzYddZI=; b=cTAdsF7XPNnZHGt8qt1fk7zeI73w44GZJvRyatd3UqHVVBoSaSsinAw8 zsDW5NcoaRE06Pt3KDq+0f6aMRlgj8Z0avJrd8Xqh9uAGJIgYhog9pNoP Y4rnf1brIjgpu1TEjML7oeU6Yq1GDSaCWMC/CxJoDv/V98ehtixH/jnnP 6ibx3Q7ZLwqdAmGv7OmQFF1yVnhc+ylQzMgZDex8BoPdOGtN7bS+cOnGB N5A7lrHKcFYfXspX38laWDnty9IN7Ai534fAMTVutlmQB4HdxGs09GBs7 cHDJu04sRUPu4KRkz9xm9I3c7mU8ca3oo69W52a/hs9jrgvoBIH0t8ogH A==; X-CSE-ConnectionGUID: CGoGwe+YT8SOJE1XHz5Wzg== X-CSE-MsgGUID: 8MqhssINTvuUjlr46ub66g== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689689" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689689" X-CSE-ConnectionGUID: MdCsSwMrQqKD4Co1gmDzvA== X-CSE-MsgGUID: KOGn8PVPRDGFMXhDPQsGvQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989240" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 33/60] i386/cpu: introduce x86_confidenetial_guest_cpu_realizefn() Date: Tue, 5 Nov 2024 01:23:41 -0500 Message-Id: <20241105062408.3533704-34-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789271028116600 Content-Type: text/plain; charset="utf-8" To execute confidential guest specific cpu realize operations. Signed-off-by: Xiaoyao Li --- changes in v6: - new patch; --- target/i386/confidential-guest.h | 12 ++++++++++++ target/i386/cpu.c | 13 ++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/target/i386/confidential-guest.h b/target/i386/confidential-gu= est.h index 38169ed68e06..4b7ea91023dc 100644 --- a/target/i386/confidential-guest.h +++ b/target/i386/confidential-guest.h @@ -40,6 +40,7 @@ struct X86ConfidentialGuestClass { /* */ int (*kvm_type)(X86ConfidentialGuest *cg); void (*cpu_instance_init)(X86ConfidentialGuest *cg, CPUState *cpu); + void (*cpu_realizefn)(X86ConfidentialGuest *cg, CPUState *cpu, Error *= *errp); uint32_t (*mask_cpuid_features)(X86ConfidentialGuest *cg, uint32_t fea= ture, uint32_t index, int reg, uint32_t value); }; @@ -70,6 +71,17 @@ static inline void x86_confidential_guest_cpu_instance_i= nit(X86ConfidentialGuest } } =20 +static inline void x86_confidenetial_guest_cpu_realizefn(X86ConfidentialGu= est *cg, + CPUState *cpu, + Error **errp) +{ + X86ConfidentialGuestClass *klass =3D X86_CONFIDENTIAL_GUEST_GET_CLASS(= cg); + + if (klass->cpu_realizefn) { + klass->cpu_realizefn(cg, cpu, errp); + } +} + /** * x86_confidential_guest_mask_cpuid_features: * diff --git a/target/i386/cpu.c b/target/i386/cpu.c index c7d65bbeab9b..1ffbafef03e7 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7848,6 +7848,18 @@ static void x86_cpu_realizefn(DeviceState *dev, Erro= r **errp) return; } =20 +#ifndef CONFIG_USER_ONLY + MachineState *ms =3D MACHINE(qdev_get_machine()); + + if (ms->cgs) { + x86_confidenetial_guest_cpu_realizefn(X86_CONFIDENTIAL_GUEST(ms->c= gs), + cs, &local_err); + if (local_err !=3D NULL) { + goto out; + } + } +#endif + if (xcc->host_cpuid_required && !accel_uses_host_cpuid()) { g_autofree char *name =3D x86_cpu_class_get_model_name(xcc); error_setg(&local_err, "CPU model '%s' requires KVM or HVF", name); @@ -7972,7 +7984,6 @@ static void x86_cpu_realizefn(DeviceState *dev, Error= **errp) } =20 #ifndef CONFIG_USER_ONLY - MachineState *ms =3D MACHINE(qdev_get_machine()); qemu_register_reset(x86_cpu_machine_reset_cb, cpu); =20 if (cpu->env.features[FEAT_1_EDX] & CPUID_APIC || ms->smp.cpus > 1) { --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789555; cv=none; d=zohomail.com; s=zohoarc; b=b+Hdj7m7OTZ+UYdjbkRDd1bdXcrP3d8ilv5LcM+kiM3NmgDBM+qeQad52BYS+9nrfUKSlmT5/9tHK5bLZfcJXSrJEoZM2r+YOpRfsmJQl2I5tvhb0j0j11Gw4E98B7qLOTisOBnM0fAu6BwMrqZE6VsBb+8Qx/iPnGvbDxL7rTY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789555; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=b4FihTLwOQP7/eeBmI6dIy3wiNRyNGEmwDuQHeJlMao=; b=H+pVjdGBWdFGDdW4EKcXCjTUQ2n5mdeNyyoa2eepeJOuu0sy9ktb0R1as2kCrRvLPKS5txmhJSPHtiM926kKSlJJHvgiQC4SK2++T/JTakRi8pEF8FHllRrHQCsqKe8T9vQiwspizL+YjN5rJBE9OhirnlHLPHEElU5hJAEj06Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 173078955560713.27938572029359; Mon, 4 Nov 2024 22:52:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DEH-0001uu-NZ; Tue, 05 Nov 2024 01:39:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDT-0000MC-5S for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:03 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDR-0001vj-9W for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:02 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:38:49 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:38:44 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788741; x=1762324741; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nkZUZZFxnGCMa4wnPLMg+4QnO1QTfXvDpRrYii+EGk0=; b=kjIASGDBiB3jX6OEp8se78ITLHZ+/0e2zkI/YYKtxoyvOhJE/qKFIsFs YTL2BU8VUMEyNDbF3YEg2IDyn+DCetbwr8m1I7IFn/L+DKtrZUpJ84Z7e kf446b6mC/bJDnsMU6b6J29TBChTmcfYpkWgyLBOgvhBj0wfvfbAFi8so EJC1j5m35r6/EWIFDViF7z8FeUV3jLoT371klREQg/90NTNVIGDramkZF YwgSSwH3TVWmTUrybILrdkINttMDbEZpv2PC0ejE8hk+xy2U/4JVv6pej /yycUmedsxQCm4D4j8uu9jubi+iRH3QPZnsJch166fLFLhjoVx4/6ohvL Q==; X-CSE-ConnectionGUID: IKnvWhBVS/qAtC3vwurVLw== X-CSE-MsgGUID: YSPcJQOlQumSJaBQXKYDng== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689700" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689700" X-CSE-ConnectionGUID: tBqCUn3tQC6VO3jLGAIGQg== X-CSE-MsgGUID: Ion8spsGRbqXdvTLwF6aBA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989310" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 34/60] i386/tdx: implement tdx_cpu_realizefn() Date: Tue, 5 Nov 2024 01:23:42 -0500 Message-Id: <20241105062408.3533704-35-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789557296116600 Content-Type: text/plain; charset="utf-8" For TDX guest, KVM doesn't allow phys_bits configuration and the phys_bits can only be native/host value. Add the logic to set cpu->phys_bits to host value when user doesn't give a explicit one and error out when user desires a different one than host value. Signed-off-by: Xiaoyao Li --- Changes in v6: - new patches; --- target/i386/host-cpu.c | 2 +- target/i386/host-cpu.h | 1 + target/i386/kvm/tdx.c | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/target/i386/host-cpu.c b/target/i386/host-cpu.c index 03b9d1b169a5..e2c59e5ae288 100644 --- a/target/i386/host-cpu.c +++ b/target/i386/host-cpu.c @@ -15,7 +15,7 @@ #include "sysemu/sysemu.h" =20 /* Note: Only safe for use on x86(-64) hosts */ -static uint32_t host_cpu_phys_bits(void) +uint32_t host_cpu_phys_bits(void) { uint32_t eax; uint32_t host_phys_bits; diff --git a/target/i386/host-cpu.h b/target/i386/host-cpu.h index 6a9bc918baa4..b97ec01c9bec 100644 --- a/target/i386/host-cpu.h +++ b/target/i386/host-cpu.h @@ -10,6 +10,7 @@ #ifndef HOST_CPU_H #define HOST_CPU_H =20 +uint32_t host_cpu_phys_bits(void); void host_cpu_instance_init(X86CPU *cpu); void host_cpu_max_instance_init(X86CPU *cpu); bool host_cpu_realizefn(CPUState *cs, Error **errp); diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 61fb1f184149..289722a129ce 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -23,6 +23,8 @@ =20 #include =20 +#include "cpu.h" +#include "host-cpu.h" #include "hw/i386/e820_memory_layout.h" #include "hw/i386/x86.h" #include "hw/i386/tdvf.h" @@ -389,6 +391,20 @@ static void tdx_cpu_instance_init(X86ConfidentialGuest= *cg, CPUState *cpu) object_property_set_bool(OBJECT(cpu), "pmu", false, &error_abort); } =20 +static void tdx_cpu_realizefn(X86ConfidentialGuest *cg, CPUState *cs, + Error **errp) +{ + X86CPU *cpu =3D X86_CPU(cs); + uint32_t host_phys_bits =3D host_cpu_phys_bits(); + + if (!cpu->phys_bits) { + cpu->phys_bits =3D host_phys_bits; + } else if (cpu->phys_bits !=3D host_phys_bits) { + error_setg(errp, "TDX only supports host physical bits (%u)", + host_phys_bits); + } +} + static int tdx_validate_attributes(TdxGuest *tdx, Error **errp) { if ((tdx->attributes & ~tdx_caps->supported_attrs)) { @@ -733,4 +749,5 @@ static void tdx_guest_class_init(ObjectClass *oc, void = *data) klass->kvm_init =3D tdx_kvm_init; x86_klass->kvm_type =3D tdx_kvm_type; x86_klass->cpu_instance_init =3D tdx_cpu_instance_init; + x86_klass->cpu_realizefn =3D tdx_cpu_realizefn; } --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730788969; cv=none; d=zohomail.com; s=zohoarc; b=kXoIwNaKq/3emHDQPFYKnprFcHWQqBgjwCGZ31j041ZeeNAs7osrlCAd1umenfHCdvr5WF8aOLM0jCc9OhkRwbmM7YScUHjt7HgWDNOLOfasSqZmy0Wm4XGUDkLH0TLxRLY4rven2+qEHpFWpzWrxQCDQRfa2NM7UqhnqrLn1pk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730788969; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3lUMbprLWZ3hjzqIhPBf1SCBawQauH3IvQbkBh812O4=; b=fgBtrwTYrF7FJv2jIn5IiLILJcRg7YToVbVk2BryyeSt/uuJ4PQs8kB3AKtk87ZG+E4vRKCLVCQByiN6Yq5SjQYfVkVsOHYw/L8yTMxg92lvk547EmdwtvfNWVey5J0hLudbjICuLrQZsdYqTemK2J+4KD2AO/RQG6pzGpv4kow= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730788969702598.1312591608156; Mon, 4 Nov 2024 22:42:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DEF-0001eh-6y; Tue, 05 Nov 2024 01:39:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDX-0000di-E9 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:09 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDU-0001vd-0j for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:05 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:38:53 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:38:49 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788744; x=1762324744; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kqZuabcZCeMEwxC/J0aE7gtHFhAE9jCqlqQdO5TnUDc=; b=mBaOQdBNm18Q4ztGGACoeKGRpp+oj+Uq1gkREZ6KMFrFUJYHy+Adn8BD IWPAFiYxT1jSPyWiLdCzLuVPdDjf+2mPz+5RgnMu1kAZIhIIWprTwKntW 3idgma6w8oifflRBalFv4svbUjs9MHpaYu21a6vQ/EftP7CJi0gtPSYq2 2MCJ42IW6zUP5wjpFxxJJKKORoyNyJyEoQsxkNT4gcmVi3e5LpJRGykGX krBMobzlY/jZoS/kNkeBIKiuM7UDRMlqgrquGb3W2PxPfgI0SX5sRFCzq gA8iII49s3MbGUcT+GlmOZ3ma5rqrlbiOxhmMxkzPI4RUSB/+dcUsm3xS w==; X-CSE-ConnectionGUID: 3OXVvn4TRHSm2IxceGvD5w== X-CSE-MsgGUID: rQb05ET7Rre2TdcAlbpnzg== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689709" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689709" X-CSE-ConnectionGUID: djoKb6XrSbaa0uJJNx7iyQ== X-CSE-MsgGUID: Y6K1GjKyTai+AQIU8Wqo/Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989366" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 35/60] i386/cpu: Introduce enable_cpuid_0x1f to force exposing CPUID 0x1f Date: Tue, 5 Nov 2024 01:23:43 -0500 Message-Id: <20241105062408.3533704-36-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730788971844116600 Content-Type: text/plain; charset="utf-8" Currently, QEMU exposes CPUID 0x1f to guest only when necessary, i.e., when topology level that cannot be enumerated by leaf 0xB, e.g., die or module level, are configured for the guest, e.g., -smp xx,dies=3D2. However, TDX architecture forces to require CPUID 0x1f to configure CPU topology. Introduce a bool flag, enable_cpuid_0x1f, in CPU for the case that requires CPUID leaf 0x1f to be exposed to guest. Introduce a new function x86_has_cpuid_0x1f(), which is the warpper of cpu->enable_cpuid_0x1f and x86_has_extended_topo() to check if it needs to enable cpuid leaf 0x1f for the guest. Signed-off-by: Xiaoyao Li --- target/i386/cpu.c | 4 ++-- target/i386/cpu.h | 9 +++++++++ target/i386/kvm/kvm.c | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 1ffbafef03e7..119b38bcb0c1 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6731,7 +6731,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, break; case 0x1F: /* V2 Extended Topology Enumeration Leaf */ - if (!x86_has_extended_topo(env->avail_cpu_topo)) { + if (!x86_has_cpuid_0x1f(cpu)) { *eax =3D *ebx =3D *ecx =3D *edx =3D 0; break; } @@ -7588,7 +7588,7 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **err= p) * cpu->vendor_cpuid_only has been unset for compatibility with ol= der * machine types. */ - if (x86_has_extended_topo(env->avail_cpu_topo) && + if (x86_has_cpuid_0x1f(cpu) && (IS_INTEL_CPU(env) || !cpu->vendor_cpuid_only)) { x86_cpu_adjust_level(cpu, &env->cpuid_min_level, 0x1F); } diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 59959b8b7a4d..dcc673262c06 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2171,6 +2171,9 @@ struct ArchCPU { /* Compatibility bits for old machine types: */ bool enable_cpuid_0xb; =20 + /* Force to enable cpuid 0x1f */ + bool enable_cpuid_0x1f; + /* Enable auto level-increase for all CPUID leaves */ bool full_cpuid_auto_level; =20 @@ -2431,6 +2434,12 @@ void host_cpuid(uint32_t function, uint32_t count, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx= ); bool cpu_has_x2apic_feature(CPUX86State *env); =20 +static inline bool x86_has_cpuid_0x1f(X86CPU *cpu) +{ + return cpu->enable_cpuid_0x1f || + x86_has_extended_topo(cpu->env.avail_cpu_topo); +} + /* helper.c */ void x86_cpu_set_a20(X86CPU *cpu, int a20_state); void cpu_sync_avx_hflag(CPUX86State *env); diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index dea0f83370d5..022809bad36e 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1874,7 +1874,7 @@ uint32_t kvm_x86_build_cpuid(CPUX86State *env, struct= kvm_cpuid_entry2 *entries, break; } case 0x1f: - if (!x86_has_extended_topo(env->avail_cpu_topo)) { + if (!x86_has_cpuid_0x1f(env_archcpu(env))) { cpuid_i--; break; } --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789270; cv=none; d=zohomail.com; s=zohoarc; b=AdR1walYONAJOAMJl0n1DGfluOFZmumzBv/rp7cRhLfwq3LnYjUBgMJ2wvXFzYE440mR+NWviWTmCTEvf9z/38owZ+X+4esnSRv7GwmENkkP5hrKErV6C/szztRtbmq6uMfpw9RfPFhagvbcHZ/XD8eaHVm5cRTR9KZl263aHHY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789270; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kUI5ZoZ6Uuw8b2k1ftXM+Mj0JZBQJSldjP4lkOfZIJ4=; b=IjGdktIxWMp0O4nE2J0Fi5bq+v7MsY7L80uLITNS+f6qC4l/I2O+lHiYWhh/mhcu+xkpEZUK+OfWrOXsM/i5m4OoQgPt5RjzlzP2/0NqQZnawt0sERLtWEP9BTAyMdT3/vVSGBmcp56Yk7KNbUnkxY3siWBRShabL3PuPE/eqJw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789270059233.67472452735058; Mon, 4 Nov 2024 22:47:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DEG-0001sq-Np; Tue, 05 Nov 2024 01:39:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDb-0000h6-J1 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:13 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDX-0001w0-Ui for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:10 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:38:57 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:38:53 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788748; x=1762324748; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dyUD9Nwe8FsbgpcTWs2XG6l6cCFEI7AD/O96ORbLEfg=; b=GXH/sVX8slH4+OeZVtuRzAlf8pznZM169wkwciChuV3m+T5ZcnIXN8wo LuR5izjfqWDrBErPt2yLHLeoWrs7qBC+9EDZIjnIN+hYdMX/2eMkKexDO XKGbR92pSJDRMLeCosgDbRLJyZMrRUPHn+sedG5atvwNTE1HM0xdkalj4 +fQgJfPvdnuJTidzgH4mwy9eawdAS4OBdlCDCI4YNtcJi4RVSR87966Qn MCD9X+d3r0PhuyZHjG83POKBAN84GuwQwzmVnW11YX7ikxcRflIKzQeCl q45VuFHn+zYtAjgh7ZjsOgp3+JbMwdFhxmImlYUMYwI2pZ/qhZcHwQNHn g==; X-CSE-ConnectionGUID: YKxOqXRWQuOmj9kmVtoltA== X-CSE-MsgGUID: bHKqoQt7SKKg+sYdiwEucQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689718" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689718" X-CSE-ConnectionGUID: nBw1klSbQS65rq8tQKhmxQ== X-CSE-MsgGUID: 0zbx6/jETtKRuCVPbc4Ycg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989408" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 36/60] i386/tdx: Force exposing CPUID 0x1f Date: Tue, 5 Nov 2024 01:23:44 -0500 Message-Id: <20241105062408.3533704-37-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789271026116600 Content-Type: text/plain; charset="utf-8" TDX uses CPUID 0x1f to configure TD guest's CPU topology. So set enable_cpuid_0x1f for TDs. Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 289722a129ce..19ce90df4143 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -388,7 +388,11 @@ static int tdx_kvm_type(X86ConfidentialGuest *cg) =20 static void tdx_cpu_instance_init(X86ConfidentialGuest *cg, CPUState *cpu) { + X86CPU *x86cpu =3D X86_CPU(cpu); + object_property_set_bool(OBJECT(cpu), "pmu", false, &error_abort); + + x86cpu->enable_cpuid_0x1f =3D true; } =20 static void tdx_cpu_realizefn(X86ConfidentialGuest *cg, CPUState *cs, --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730788806; cv=none; d=zohomail.com; s=zohoarc; b=PoWo+C4hX7uzq6Zoqggmsj+Y4DuUj2vl4Ae9ihVZGF1MWIRtWnO74Mwg1LEbRLZovVCAteLoxb8Yu70yJPq5n6x42mBHx/+YJqLvFe8RtP5sd10SE+CPYllvXHzyQLhcb8ReOcvrY5nksd2xNsPUuSgRTp4NJ1uqzaZGAxBsUcg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730788806; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=N5RYyA6OLxgdPrf4wY0AXzDWdgHKUVY8Ffv1C/rPcFE=; b=fI2Bx9iM1L0Ae+3gIuY7O6RWTja8rp9O5QrJESgjdyAcEij57ekEL0IW7j2G8TF5XYiBPdPwhetFDjvtj5qqqUOAi72rz/nUCcd1V9o0MD7SyU2va+JTWdMU1TZCKYp1J+qJk88Kp5c/TfZKCV1A9/PSpWkAB+0/8C2cOeXu/zM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730788806771594.8216101538159; Mon, 4 Nov 2024 22:40:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DEN-0002cl-Tf; Tue, 05 Nov 2024 01:40:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDk-0000wX-3h for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:29 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDd-0001vj-LT for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:16 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:39:01 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:38:57 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788754; x=1762324754; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mgYnaE32reSGuV7hHoP0EJIpwxMG8v5/dHOATY3+4xU=; b=aUKJ5sDpMJcr5OnUGGYvuO0sOToLAj9HKZ20Yw8seCHNdOAvqsGj8R8N zNYJjeoXPP/Dm5XzzmEcfaeKyoKGnmNpK3kqtXyCkrMfPzrM2AZL7Meei nVV5wLwRiHesPMdmtvJvVW1Gi0Nz5IgPRlyPG1XZqnGAdHdM3scq34Wuq EG9ZZ7VIKydzRu1M7wknhrEVLsO7Zv13n29MlLHrNoGXt7WC3m95BZTSZ j9TPFhiynFyoRa+SgteEjWUg+7BiRR8f+/I+D8l/Q9bgUwJZuCWJzR3pI oBMmQal+W7ez4ZGrYkPC1Yzx0zCm7nx7xWPuhg1D0NVeFAUeSGcEC07bG Q==; X-CSE-ConnectionGUID: v91pdsrZTy+Eihch/3pinQ== X-CSE-MsgGUID: Z5E84DaIQ0WyN2AStAto8Q== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689725" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689725" X-CSE-ConnectionGUID: OxDsKalzR/SUCZQoWpLyNQ== X-CSE-MsgGUID: PurmE+u2Sx2SqBVZbB/RpQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989457" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 37/60] i386/tdx: Set kvm_readonly_mem_enabled to false for TDX VM Date: Tue, 5 Nov 2024 01:23:45 -0500 Message-Id: <20241105062408.3533704-38-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730788806980116600 Content-Type: text/plain; charset="utf-8" TDX only supports readonly for shared memory but not for private memory. In the view of QEMU, it has no idea whether a memslot is used as shared memory of private. Thus just mark kvm_readonly_mem_enabled to false to TDX VM for simplicity. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- target/i386/kvm/tdx.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 19ce90df4143..00faffa891e4 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -372,6 +372,15 @@ static int tdx_kvm_init(ConfidentialGuestSupport *cgs,= Error **errp) return -EOPNOTSUPP; } =20 + /* + * Set kvm_readonly_mem_allowed to false, because TDX only supports re= adonly + * memory for shared memory but not for private memory. Besides, wheth= er a + * memslot is private or shared is not determined by QEMU. + * + * Thus, just mark readonly memory not supported for simplicity. + */ + kvm_readonly_mem_allowed =3D false; + qemu_add_machine_init_done_notifier(&tdx_machine_done_notify); =20 tdx_guest =3D tdx; --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730788812; cv=none; d=zohomail.com; s=zohoarc; b=dRZTvt3T6nKQw/RLKBbFXxOdxfr3OtkkFB1X+vqR2a9WUrlBzr3izrNAKuS6DliyrpF41L8pnohn5NLPTWRbuGBDM4gI9g6/Nwu1/nJ6BbmaGFzP+LppGmbnGQr5KuiUU6KIYSK11IyLAJlzbOx5akP/a6RM7pbA7xJfjYrqQAE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730788812; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2mJOLfp8TftaiybJ1kbQzlzIW2pxWu1gV9t+R0DUCX0=; b=a6aoCXRAalZTlKV1XNnTR7LLYc8Vbf8NWk4o9ozAA3MNUKa0dNDPeZacJ0UnHqH+Z4h7vPUXvi6MZfqATJ+x4OlW3WHJ2/ItexmxEsG3LNwOmPaj9Z3O9KvPABIbD94yHbgmzdkV4Wr9KLA/EwtncAwMSns2xS8U8APrsLsP62Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730788812247146.97850091467467; Mon, 4 Nov 2024 22:40:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DEB-0001Hc-PJ; Tue, 05 Nov 2024 01:39:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDm-00012U-64 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:31 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDh-0001vd-P5 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:21 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:39:06 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:39:01 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788758; x=1762324758; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oaeUYxWxoTsbbEf4Af9Nw3NbJLsiof0AXokRyvVuUyo=; b=MrUB6rrVvf7+ZuHrHc4sSHEomrE8MB4PmFC4rMYdLxXecVs0zqUVTDv7 +DF1yLaFq+u9hkPRMV/kABXdnQbwbLmOwOtKfd9ZYSGg6U3amnLDbtMb/ +VvgegmJLwujJMz7BpBg9R60ipdTplCg90l/0ekKnfxPoVBg5WCgUWU60 cQLHZQK+bNySnPqML7/kp1ydKwiDtS7DlZXagRpZgJl2XAl6hbp0vfnFG TAsG6NyNmLt5wqQn+SXeNXvHx4pPloUV4Prx+nn4tIBQERTn/18lsrt2E PiVXH8KUQgxPq0Tm3rU0PvOIs+E5ZYuTyYv/FNR2fU9r7lPjv+Geg0hgT A==; X-CSE-ConnectionGUID: i7acg9kFQzqJQ0uakwJ5yg== X-CSE-MsgGUID: ZNhI++QeRAae7yA+RincxA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689733" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689733" X-CSE-ConnectionGUID: EI5xNTcOT4uw11Kv11bggg== X-CSE-MsgGUID: 2ryCymgaT3yCWbd2Jfig5A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989510" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 38/60] i386/tdx: Disable SMM for TDX VMs Date: Tue, 5 Nov 2024 01:23:46 -0500 Message-Id: <20241105062408.3533704-39-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730788813036116600 Content-Type: text/plain; charset="utf-8" TDX doesn't support SMM and VMM cannot emulate SMM for TDX VMs because VMM cannot manipulate TDX VM's memory. Disable SMM for TDX VMs and error out if user requests to enable SMM. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- target/i386/kvm/tdx.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 00faffa891e4..68d90a180db7 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -355,11 +355,20 @@ static Notifier tdx_machine_done_notify =3D { =20 static int tdx_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) { + MachineState *ms =3D MACHINE(qdev_get_machine()); + X86MachineState *x86ms =3D X86_MACHINE(ms); TdxGuest *tdx =3D TDX_GUEST(cgs); int r =3D 0; =20 kvm_mark_guest_state_protected(); =20 + if (x86ms->smm =3D=3D ON_OFF_AUTO_AUTO) { + x86ms->smm =3D ON_OFF_AUTO_OFF; + } else if (x86ms->smm =3D=3D ON_OFF_AUTO_ON) { + error_setg(errp, "TDX VM doesn't support SMM"); + return -EINVAL; + } + if (!tdx_caps) { r =3D get_tdx_capabilities(errp); if (r) { --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789633; cv=none; d=zohomail.com; s=zohoarc; b=gbmUi4XmoBrtoFwSt4rWVWQzuFcQw82S+2Y3akJakfuAe78ppoV4InwePB1XF15ewKT7lpqY/Y905NqIj2gw0JxyRPSnD6f/ws2KVuluAHsf0tC7V1q+qWsH9Qq4vB0ba+n/lwdSF3TcaZK+QrJK+NZcVTJlGOZP6GDa+lo0kEo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789633; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=K5SzSHtVU30KbDyi7slJM012MO5Fyde2xSONG2FhS8Q=; b=TvbDxHx1nPiTFkt9WF3DNuFVRww0saYmLtly4rJn+68rrh/yn0N6K7iBRLd18UNOHZGUVG//DMbhwVPHKirZBJ0tVQL7HiHPYYalVNW758l5O1eBUC1lMQjmfPsdpjPfhevT3aWLVN59OKYl8/vBrXdogIdHphyTZQGeiN+jzWE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789633680510.07983923026075; Mon, 4 Nov 2024 22:53:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DED-0001XX-UE; Tue, 05 Nov 2024 01:39:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDn-00012V-Ep for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:32 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDl-0001w0-Rk for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:23 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:39:10 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:39:06 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788762; x=1762324762; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ETTKI5+hacWoJJE2C+uh6AGfusJHWOqz7xoddYnIUoE=; b=FKDKrUoBUtKQuf/WXMH2bC+ksZYMtbrdC30yFkl0xtUQFRhDR3IbFJm5 FoddTEQPgN9Bc9j7kK1LVBrnkABFHuiSNMgUYbSrNj/151dZc85nrGB+1 YKl1NKy33Zx7kdqypQr5Pfw+/oWHrkyM4nAhVNwfUsXo0wOYntoQ0khGy rz25+N5uGQ12rUjKtU5JFRckVc1SJjGoQQWfk4+HsY3nxccs8zi/Qicu3 mxh1Bq3NrcOXrA9ieOIa6A12zUxYDoX05QAVTOC+ad/qR5Zwqr3cl64dX +lxrnk5w68NpIXW9+rs4VzkvTqOA0YP83GhpEHOa8I6Eq9k3zxABtxdsL w==; X-CSE-ConnectionGUID: Tb+CEjsuSLuHaNr01hrT0w== X-CSE-MsgGUID: Z9xIKhy5TSuowgHZ3cUevA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689748" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689748" X-CSE-ConnectionGUID: aHXP1H8NQpSpWutRAMliPQ== X-CSE-MsgGUID: 8S17/192T7WLzQnztIR5qQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989534" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 39/60] i386/tdx: Disable PIC for TDX VMs Date: Tue, 5 Nov 2024 01:23:47 -0500 Message-Id: <20241105062408.3533704-40-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789635691116600 Content-Type: text/plain; charset="utf-8" Legacy PIC (8259) cannot be supported for TDX VMs since TDX module doesn't allow directly interrupt injection. Using posted interrupts for the PIC is not a viable option as the guest BIOS/kernel will not do EOI for PIC IRQs, i.e. will leave the vIRR bit set. Hence disable PIC for TDX VMs and error out if user wants PIC. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- target/i386/kvm/tdx.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 68d90a180db7..9ab4e911f78a 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -369,6 +369,13 @@ static int tdx_kvm_init(ConfidentialGuestSupport *cgs,= Error **errp) return -EINVAL; } =20 + if (x86ms->pic =3D=3D ON_OFF_AUTO_AUTO) { + x86ms->pic =3D ON_OFF_AUTO_OFF; + } else if (x86ms->pic =3D=3D ON_OFF_AUTO_ON) { + error_setg(errp, "TDX VM doesn't support PIC"); + return -EINVAL; + } + if (!tdx_caps) { r =3D get_tdx_capabilities(errp); if (r) { --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789230; cv=none; d=zohomail.com; s=zohoarc; b=jHumIpeY2R1ddaWwQBsx2ra3galvkTpK12R4xXEf9ch2fHTj4DIkdcUV6IzTa91rdtDGuX9tr9FjdckB8gaFSQ9aNhPwjRKcAdukENBnqILxmemaSwzapJgIgfHRda7ynetASTCzFOV/P5QLJ/WTgNy4JGO2NRCz9vBhMkn24kI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789230; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=U74mMkvfYr8BmgBX/0CNJgl7R60UWBg4Opf4LzYbBtw=; b=l3UeB7sWDdg1FhUAdMwYPNCsWcxVkTg//2FSVWowiX69z2qfEEIqLBZuBbqmmvH5GK+HUOzChqLKqHQ6m+IWpomszBBax015gHtf2JxaYa0ZURXJPxrkeSU3jt2BlLdN70C263V/brpoyB3rWU0uKDZR1NwxrS8plre5XX1HHA8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789230885107.8916988407492; Mon, 4 Nov 2024 22:47:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DEI-00028V-76; Tue, 05 Nov 2024 01:39:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDx-00014A-TE for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:37 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDu-0001vj-Ey for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:33 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:39:14 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:39:10 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788770; x=1762324770; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BHXWCaOd3UyAcZOJUgpgw+yI5VVHsxLUYqIIcqCHqr8=; b=HvWbleQoW/muLTfk3+6Z6K6YwC3EmbfFRYIpeIIPcdZ4ubQNDV/7Q4oR QS91z96XUJ+k75U2Wrd0uhY5iE4a1U/kjnXiBzUdAiO+q3f5r7Q5NTLP8 HyGSdBOnr4Opk034JsJ8Z0DHNmz9YIrQKma1DXZqiI1ZWn9McndOkHhOx y2Lr4EisMs2HTZfcjKF1yPZMchjwoOSRtgmxb8iPm3CLiQ2SUWuZM8d03 OV8cQlf6MaZcsTADlXRKXo9M39j2O9DZEjIHXVaIGgkY7MQ6y43JX2Syw xgnqPykawRAtn7ZHJeXoFyB0oGUYfYUW6Ecl2KWDt9dwPLEdv4oru158s g==; X-CSE-ConnectionGUID: P5clSLOZQuq1ofvYKwctRQ== X-CSE-MsgGUID: 0++UfrRcRIWEaWaaafeoMA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689759" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689759" X-CSE-ConnectionGUID: AYU/sAKLS2q3DkWuAe4Fxw== X-CSE-MsgGUID: VBH/u/1NTEmaD6xbyYj7Gw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989566" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 40/60] hw/i386: add eoi_intercept_unsupported member to X86MachineState Date: Tue, 5 Nov 2024 01:23:48 -0500 Message-Id: <20241105062408.3533704-41-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789232955116600 Content-Type: text/plain; charset="utf-8" Add a new bool member, eoi_intercept_unsupported, to X86MachineState with default value false. Set true for TDX VM. Inability to intercept eoi causes impossibility to emulate level triggered interrupt to be re-injected when level is still kept active. which affects interrupt controller emulation. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- hw/i386/x86.c | 1 + include/hw/i386/x86.h | 1 + target/i386/kvm/tdx.c | 2 ++ 3 files changed, 4 insertions(+) diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 01fc5e656272..82faeed24ff9 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -370,6 +370,7 @@ static void x86_machine_initfn(Object *obj) x86ms->oem_table_id =3D g_strndup(ACPI_BUILD_APPNAME8, 8); x86ms->bus_lock_ratelimit =3D 0; x86ms->above_4g_mem_start =3D 4 * GiB; + x86ms->eoi_intercept_unsupported =3D false; } =20 static void x86_machine_class_init(ObjectClass *oc, void *data) diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h index d43cb3908e65..fd9a30391755 100644 --- a/include/hw/i386/x86.h +++ b/include/hw/i386/x86.h @@ -73,6 +73,7 @@ struct X86MachineState { uint64_t above_4g_mem_start; =20 /* CPU and apic information: */ + bool eoi_intercept_unsupported; unsigned pci_irq_mask; unsigned apic_id_limit; uint16_t boot_cpus; diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 9ab4e911f78a..9dcb77e011bd 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -388,6 +388,8 @@ static int tdx_kvm_init(ConfidentialGuestSupport *cgs, = Error **errp) return -EOPNOTSUPP; } =20 + x86ms->eoi_intercept_unsupported =3D true; + /* * Set kvm_readonly_mem_allowed to false, because TDX only supports re= adonly * memory for shared memory but not for private memory. Besides, wheth= er a --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789633; cv=none; d=zohomail.com; s=zohoarc; b=F/e36kDoDwtrQGExbTGbKi/5kQSR4aesw0/UFItoEFRX0s7HLfFpnj6CJmqKepBNcuLmusldze/ofGZ7OYw0usLB8Fy3pO4O0vRmMOX25Dq1qsn2x3ZVE+qyEecCawjUT9gGbypasz8jLD14j6O3HQS+BfVczSMJpJxwymvRdf4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789633; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+x86go3li+2sUcYUPjRQTauBseRlYmkDHbYmE+tRnwE=; b=D5BSIHj/gZG4nhNUmHV5ENjNvT1VMFw8sGtjuBvKvU2Oj/gQpMwG4wGIT8RCGUvv3BS9Bc6mucPVRbZvVx6vpPu+10c4buV8fs/ZfabyDrPH8d4w4pvjmcKl+ZW42srhlLes1HJXdeKNCKMzmntJbjBXRYyKmsvFm/laRkW3U/0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789633745888.9659322668189; Mon, 4 Nov 2024 22:53:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DFK-0003XW-KF; Tue, 05 Nov 2024 01:41:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDz-00014F-0a for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:37 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDw-0001vd-IW for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:34 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:39:19 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:39:14 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788773; x=1762324773; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8uEuNvmf9noH27+CtakzBXFvtETe/Vb0IM6iwSDYV+w=; b=O4EJ/IZilSSlzrHD5e4gYjArH1caaAJfyKRSVArbi9wAyjGSyrv5cMmn MjnwrfqFKjSb0niFSa9+4B2xmeM3YJPauuSrouMfaOzkgNx62y0HHgt5J zH0FdqVXDc4DONijarREUWzMjX1M+hk7UVZvas5o4UJRDHgnEG15VlZMF SunH5QWyR4CbwqlNhik9hnjlodY4f1wHLLGcEjLCcH0IaKS+c+XEJkmLz taoopcb/evfIBElpQXt6qlNqhIEBT10ytCE9Q2RMmDK5ch4sK9D1W8EGf mdeTND9w8vtk2Gd2r3FzljVd+QeEI7uqHWT6uv8w0ChN4UlGSAAFb4AtT A==; X-CSE-ConnectionGUID: a8Yz8QX5RleCkt4P9wY6Gg== X-CSE-MsgGUID: 3Cfeah4tQPWJ0aFuD0pKag== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689766" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689766" X-CSE-ConnectionGUID: DcXkl4xzR2q/ZU3Wc71OxQ== X-CSE-MsgGUID: EsjtOYi6QOKwTZwDwlyv1g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989595" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 41/60] hw/i386: add option to forcibly report edge trigger in acpi tables Date: Tue, 5 Nov 2024 01:23:49 -0500 Message-Id: <20241105062408.3533704-42-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789635563116600 Content-Type: text/plain; charset="utf-8" From: Isaku Yamahata When level trigger isn't supported on x86 platform, forcibly report edge trigger in acpi tables. Signed-off-by: Isaku Yamahata Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- hw/i386/acpi-build.c | 99 ++++++++++++++++++++++++++++--------------- hw/i386/acpi-common.c | 45 +++++++++++++++----- 2 files changed, 101 insertions(+), 43 deletions(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 4967aa745902..d0a5bfc69e9a 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -888,7 +888,8 @@ static void build_dbg_aml(Aml *table) aml_append(table, scope); } =20 -static Aml *build_link_dev(const char *name, uint8_t uid, Aml *reg) +static Aml *build_link_dev(const char *name, uint8_t uid, Aml *reg, + bool level_trigger_unsupported) { Aml *dev; Aml *crs; @@ -900,7 +901,10 @@ static Aml *build_link_dev(const char *name, uint8_t u= id, Aml *reg) aml_append(dev, aml_name_decl("_UID", aml_int(uid))); =20 crs =3D aml_resource_template(); - aml_append(crs, aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH, + aml_append(crs, aml_interrupt(AML_CONSUMER, + level_trigger_unsupported ? + AML_EDGE : AML_LEVEL, + AML_ACTIVE_HIGH, AML_SHARED, irqs, ARRAY_SIZE(irqs))); aml_append(dev, aml_name_decl("_PRS", crs)); =20 @@ -924,7 +928,8 @@ static Aml *build_link_dev(const char *name, uint8_t ui= d, Aml *reg) return dev; } =20 -static Aml *build_gsi_link_dev(const char *name, uint8_t uid, uint8_t gsi) +static Aml *build_gsi_link_dev(const char *name, uint8_t uid, + uint8_t gsi, bool level_trigger_unsupported) { Aml *dev; Aml *crs; @@ -937,7 +942,10 @@ static Aml *build_gsi_link_dev(const char *name, uint8= _t uid, uint8_t gsi) =20 crs =3D aml_resource_template(); irqs =3D gsi; - aml_append(crs, aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH, + aml_append(crs, aml_interrupt(AML_CONSUMER, + level_trigger_unsupported ? + AML_EDGE : AML_LEVEL, + AML_ACTIVE_HIGH, AML_SHARED, &irqs, 1)); aml_append(dev, aml_name_decl("_PRS", crs)); =20 @@ -956,7 +964,7 @@ static Aml *build_gsi_link_dev(const char *name, uint8_= t uid, uint8_t gsi) } =20 /* _CRS method - get current settings */ -static Aml *build_iqcr_method(bool is_piix4) +static Aml *build_iqcr_method(bool is_piix4, bool level_trigger_unsupporte= d) { Aml *if_ctx; uint32_t irqs; @@ -964,7 +972,9 @@ static Aml *build_iqcr_method(bool is_piix4) Aml *crs =3D aml_resource_template(); =20 irqs =3D 0; - aml_append(crs, aml_interrupt(AML_CONSUMER, AML_LEVEL, + aml_append(crs, aml_interrupt(AML_CONSUMER, + level_trigger_unsupported ? + AML_EDGE : AML_LEVEL, AML_ACTIVE_HIGH, AML_SHARED, &irqs, 1)); aml_append(method, aml_name_decl("PRR0", crs)); =20 @@ -998,7 +1008,7 @@ static Aml *build_irq_status_method(void) return method; } =20 -static void build_piix4_pci0_int(Aml *table) +static void build_piix4_pci0_int(Aml *table, bool level_trigger_unsupporte= d) { Aml *dev; Aml *crs; @@ -1011,12 +1021,16 @@ static void build_piix4_pci0_int(Aml *table) aml_append(sb_scope, pci0_scope); =20 aml_append(sb_scope, build_irq_status_method()); - aml_append(sb_scope, build_iqcr_method(true)); + aml_append(sb_scope, build_iqcr_method(true, level_trigger_unsupported= )); =20 - aml_append(sb_scope, build_link_dev("LNKA", 0, aml_name("PRQ0"))); - aml_append(sb_scope, build_link_dev("LNKB", 1, aml_name("PRQ1"))); - aml_append(sb_scope, build_link_dev("LNKC", 2, aml_name("PRQ2"))); - aml_append(sb_scope, build_link_dev("LNKD", 3, aml_name("PRQ3"))); + aml_append(sb_scope, build_link_dev("LNKA", 0, aml_name("PRQ0"), + level_trigger_unsupported)); + aml_append(sb_scope, build_link_dev("LNKB", 1, aml_name("PRQ1"), + level_trigger_unsupported)); + aml_append(sb_scope, build_link_dev("LNKC", 2, aml_name("PRQ2"), + level_trigger_unsupported)); + aml_append(sb_scope, build_link_dev("LNKD", 3, aml_name("PRQ3"), + level_trigger_unsupported)); =20 dev =3D aml_device("LNKS"); { @@ -1025,7 +1039,9 @@ static void build_piix4_pci0_int(Aml *table) =20 crs =3D aml_resource_template(); irqs =3D 9; - aml_append(crs, aml_interrupt(AML_CONSUMER, AML_LEVEL, + aml_append(crs, aml_interrupt(AML_CONSUMER, + level_trigger_unsupported ? + AML_EDGE : AML_LEVEL, AML_ACTIVE_HIGH, AML_SHARED, &irqs, 1)); aml_append(dev, aml_name_decl("_PRS", crs)); @@ -1111,7 +1127,7 @@ static Aml *build_q35_routing_table(const char *str) return pkg; } =20 -static void build_q35_pci0_int(Aml *table) +static void build_q35_pci0_int(Aml *table, bool level_trigger_unsupported) { Aml *method; Aml *sb_scope =3D aml_scope("_SB"); @@ -1150,25 +1166,41 @@ static void build_q35_pci0_int(Aml *table) aml_append(sb_scope, pci0_scope); =20 aml_append(sb_scope, build_irq_status_method()); - aml_append(sb_scope, build_iqcr_method(false)); + aml_append(sb_scope, build_iqcr_method(false, level_trigger_unsupporte= d)); =20 - aml_append(sb_scope, build_link_dev("LNKA", 0, aml_name("PRQA"))); - aml_append(sb_scope, build_link_dev("LNKB", 1, aml_name("PRQB"))); - aml_append(sb_scope, build_link_dev("LNKC", 2, aml_name("PRQC"))); - aml_append(sb_scope, build_link_dev("LNKD", 3, aml_name("PRQD"))); - aml_append(sb_scope, build_link_dev("LNKE", 4, aml_name("PRQE"))); - aml_append(sb_scope, build_link_dev("LNKF", 5, aml_name("PRQF"))); - aml_append(sb_scope, build_link_dev("LNKG", 6, aml_name("PRQG"))); - aml_append(sb_scope, build_link_dev("LNKH", 7, aml_name("PRQH"))); + aml_append(sb_scope, build_link_dev("LNKA", 0, aml_name("PRQA"), + level_trigger_unsupported)); + aml_append(sb_scope, build_link_dev("LNKB", 1, aml_name("PRQB"), + level_trigger_unsupported)); + aml_append(sb_scope, build_link_dev("LNKC", 2, aml_name("PRQC"), + level_trigger_unsupported)); + aml_append(sb_scope, build_link_dev("LNKD", 3, aml_name("PRQD"), + level_trigger_unsupported)); + aml_append(sb_scope, build_link_dev("LNKE", 4, aml_name("PRQE"), + level_trigger_unsupported)); + aml_append(sb_scope, build_link_dev("LNKF", 5, aml_name("PRQF"), + level_trigger_unsupported)); + aml_append(sb_scope, build_link_dev("LNKG", 6, aml_name("PRQG"), + level_trigger_unsupported)); + aml_append(sb_scope, build_link_dev("LNKH", 7, aml_name("PRQH"), + level_trigger_unsupported)); =20 - aml_append(sb_scope, build_gsi_link_dev("GSIA", 0x10, 0x10)); - aml_append(sb_scope, build_gsi_link_dev("GSIB", 0x11, 0x11)); - aml_append(sb_scope, build_gsi_link_dev("GSIC", 0x12, 0x12)); - aml_append(sb_scope, build_gsi_link_dev("GSID", 0x13, 0x13)); - aml_append(sb_scope, build_gsi_link_dev("GSIE", 0x14, 0x14)); - aml_append(sb_scope, build_gsi_link_dev("GSIF", 0x15, 0x15)); - aml_append(sb_scope, build_gsi_link_dev("GSIG", 0x16, 0x16)); - aml_append(sb_scope, build_gsi_link_dev("GSIH", 0x17, 0x17)); + aml_append(sb_scope, build_gsi_link_dev("GSIA", 0x10, 0x10, + level_trigger_unsupported)); + aml_append(sb_scope, build_gsi_link_dev("GSIB", 0x11, 0x11, + level_trigger_unsupported)); + aml_append(sb_scope, build_gsi_link_dev("GSIC", 0x12, 0x12, + level_trigger_unsupported)); + aml_append(sb_scope, build_gsi_link_dev("GSID", 0x13, 0x13, + level_trigger_unsupported)); + aml_append(sb_scope, build_gsi_link_dev("GSIE", 0x14, 0x14, + level_trigger_unsupported)); + aml_append(sb_scope, build_gsi_link_dev("GSIF", 0x15, 0x15, + level_trigger_unsupported)); + aml_append(sb_scope, build_gsi_link_dev("GSIG", 0x16, 0x16, + level_trigger_unsupported)); + aml_append(sb_scope, build_gsi_link_dev("GSIH", 0x17, 0x17, + level_trigger_unsupported)); =20 aml_append(table, sb_scope); } @@ -1350,6 +1382,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, PCMachineState *pcms =3D PC_MACHINE(machine); PCMachineClass *pcmc =3D PC_MACHINE_GET_CLASS(machine); X86MachineState *x86ms =3D X86_MACHINE(machine); + bool level_trigger_unsupported =3D x86ms->eoi_intercept_unsupported; AcpiMcfgInfo mcfg; bool mcfg_valid =3D !!acpi_get_mcfg(&mcfg); uint32_t nr_mem =3D machine->ram_slots; @@ -1382,7 +1415,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, if (pm->pcihp_bridge_en || pm->pcihp_root_en) { build_x86_acpi_pci_hotplug(dsdt, pm->pcihp_io_base); } - build_piix4_pci0_int(dsdt); + build_piix4_pci0_int(dsdt, level_trigger_unsupported); } else if (q35) { sb_scope =3D aml_scope("_SB"); dev =3D aml_device("PCI0"); @@ -1426,7 +1459,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, if (pm->pcihp_bridge_en) { build_x86_acpi_pci_hotplug(dsdt, pm->pcihp_io_base); } - build_q35_pci0_int(dsdt); + build_q35_pci0_int(dsdt, level_trigger_unsupported); } =20 if (misc->has_hpet) { diff --git a/hw/i386/acpi-common.c b/hw/i386/acpi-common.c index 0cc2919bb851..ad38a6b31162 100644 --- a/hw/i386/acpi-common.c +++ b/hw/i386/acpi-common.c @@ -103,6 +103,7 @@ void acpi_build_madt(GArray *table_data, BIOSLinker *li= nker, const CPUArchIdList *apic_ids =3D mc->possible_cpu_arch_ids(MACHINE(x8= 6ms)); AcpiTable table =3D { .sig =3D "APIC", .rev =3D 3, .oem_id =3D oem_id, .oem_table_id =3D oem_table_id }; + bool level_trigger_unsupported =3D x86ms->eoi_intercept_unsupported; =20 acpi_table_begin(&table, table_data); /* Local APIC Address */ @@ -124,18 +125,42 @@ void acpi_build_madt(GArray *table_data, BIOSLinker *= linker, IO_APIC_SECONDARY_ADDRESS, IO_APIC_SECONDARY_IRQBASE); } =20 - if (x86mc->apic_xrupt_override) { - build_xrupt_override(table_data, 0, 2, - 0 /* Flags: Conforms to the specifications of the bus */); - } + if (level_trigger_unsupported) { + /* Force edge trigger */ + if (x86mc->apic_xrupt_override) { + build_xrupt_override(table_data, 0, 2, + /* Flags: active high, edge triggered */ + 1 | (1 << 2)); + } + + for (i =3D x86mc->apic_xrupt_override ? 1 : 0; i < 16; i++) { + build_xrupt_override(table_data, i, i, + /* Flags: active high, edge triggered */ + 1 | (1 << 2)); + } + + if (x86ms->ioapic2) { + for (i =3D 0; i < 16; i++) { + build_xrupt_override(table_data, IO_APIC_SECONDARY_IRQBASE= + i, + IO_APIC_SECONDARY_IRQBASE + i, + /* Flags: active high, edge triggered= */ + 1 | (1 << 2)); + } + } + } else { + if (x86mc->apic_xrupt_override) { + build_xrupt_override(table_data, 0, 2, + 0 /* Flags: Conforms to the specifications of the bus = */); + } =20 - for (i =3D 1; i < 16; i++) { - if (!(x86ms->pci_irq_mask & (1 << i))) { - /* No need for a INT source override structure. */ - continue; + for (i =3D 1; i < 16; i++) { + if (!(x86ms->pci_irq_mask & (1 << i))) { + /* No need for a INT source override structure. */ + continue; + } + build_xrupt_override(table_data, i, i, + 0xd /* Flags: Active high, Level Triggered */); } - build_xrupt_override(table_data, i, i, - 0xd /* Flags: Active high, Level Triggered */); } =20 if (x2apic_mode) { --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789306; cv=none; d=zohomail.com; s=zohoarc; b=FbafSUFcDK6J/I+uLs2cA7CaZLYYPXTL83TrnicglDG85phzpQ58FTa7TCTkgCkwocQPdMg8Pkc3yNTKQlOAlcxAIgNHTW9ar3d226+L8TxWq3RzG/zXmht5+AVVXlLnxkzsdqgxO6+AWpS0OkFRd6gEc2Yfg7FdTGl8PxpXt9Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789306; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zr22Yeis30paA2QxSJ0/OjwY3JdXtiotQHeXLK7saYg=; b=cQoeiAxKuSXEYl3mj4gpqyJBNlm03tHf0dO6AnB68KztfRreE9WS2VekHlOZeSjIcU1lEDZIkDCmbug8D5G1aeclvkwhIkCgvg0wtFhcSTY7iLfeRPNCQaLnAG5kSFYH5GdtZsDxwZ8672ViFnTy85eNyTp4OmRgPBkZz6HMkfs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789306960358.9960872294306; Mon, 4 Nov 2024 22:48:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DEW-00038u-F1; Tue, 05 Nov 2024 01:40:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDz-00014I-Cw for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:38 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DDx-0001w0-Pf for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:35 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:39:23 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:39:19 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788774; x=1762324774; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uFxOU0S0tIUsyV9rR7mBF54/Xh/koV03EYrPligZB2A=; b=lSMrt1dCVu5NBgrJcLjz5n0sCOZf4hvDc+nlQk2Hc5KrY3cDbGrfbBav zilkZuz3huVIcZJuX5p5K+lTgQbpxucfDZhdn7DqKWze8A9G2HmR/A66J 8hmHxOPohxSXI1I9MorMrlyuILaylbKtWuAJaYmGlS42RZ3Uqx70VEWme RT+gJj+mEUhVMQaAfg8pm8ei7NyZ2vnUphWN2akPSGxqfDZ+5Q2LzzPGn Blis517V/yjSUNBOJbuly3p42iNzg1quK7HE/7wuoh6d/vK1l5ZEyGBHs FPzkoTVZ2j9SofWzamCRglOX1zM5mxXua4FCU2RROKJVJXjawhILx+yzN Q==; X-CSE-ConnectionGUID: eWISOf6zT86KnS5C8/j+Xg== X-CSE-MsgGUID: gnlQe1piRRKD/8J0hF0ldQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689774" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689774" X-CSE-ConnectionGUID: fZqnB8jWQYyh3dtw65a9ag== X-CSE-MsgGUID: UaR6lv4fRS+2sLaYX0hujA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989612" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 42/60] i386/tdx: Don't synchronize guest tsc for TDs Date: Tue, 5 Nov 2024 01:23:50 -0500 Message-Id: <20241105062408.3533704-43-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789307291116600 Content-Type: text/plain; charset="utf-8" From: Isaku Yamahata TSC of TDs is not accessible and KVM doesn't allow access of MSR_IA32_TSC for TDs. To avoid the assert() in kvm_get_tsc, make kvm_synchronize_all_tsc() noop for TDs, Signed-off-by: Isaku Yamahata Reviewed-by: Connor Kuehl Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- target/i386/kvm/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 022809bad36e..595439f4a4d6 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -330,7 +330,7 @@ void kvm_synchronize_all_tsc(void) { CPUState *cpu; =20 - if (kvm_enabled()) { + if (kvm_enabled() && !is_tdx_vm()) { CPU_FOREACH(cpu) { run_on_cpu(cpu, do_kvm_synchronize_tsc, RUN_ON_CPU_NULL); } --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789557; cv=none; d=zohomail.com; s=zohoarc; b=m+q7i0Xk+jYeko+n8vNxXTuNAd3YDTwLpf/MBkjuDUzEXNbVJDSHACQ6VK8EMr7gxfSMFjb5uy0YbqLtdQbG6MCaJVC8td7Wig8KNoywexXJjUqQDfdWv59JRk4T4PD/TB/yDjD6WKppwEyRK1M6rIurtTK/2fPxur3Drvc+IHY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789557; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Qvs+cmcN3UYtBVs0sIBZ0aNs33n7G7REw3obDoYJB0w=; b=YRASTXCrfZpKExZCwyY/E3b+99l+KbQ+1pGZe7Nu8q3VRHCSdgY1mX+JIzGh6TtrtPM87HXy8TCqvzhQBLelrTEi9+KDGBj0ooUan6xZDTCU0SA3BC+19qbQ+swCm/D2Zf3fTqG5MIrGnr4a+ZhTSJvrRvVeXGD6h73ajnPxiQU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789557120106.15483313466268; Mon, 4 Nov 2024 22:52:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DEP-0002gF-8v; Tue, 05 Nov 2024 01:40:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DEA-0001Gy-Up for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:47 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DE8-0001vj-Ac for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:45 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:39:27 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:39:23 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788784; x=1762324784; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sfRTE3KuC3TUYSe9/IzIJIb3zhuizbpOCanDRw/1dzs=; b=QDUYqhJ8A64ZiOc5a7kXHNgeDemHjzezMXCBvqNGpX9ZV4MPGauIpD5x EB3UYg9p4vt7bk1eTGIWtHuLmmAgTZN8XduN3ZPsjplYPVg0HMko8mVt0 XOcv+p5iXpdSmiExthoHEPhESFVhBbRTYVUJGYjRZcxBEA2+Kdcli3Fl4 zHhIGNtzFU52GfYGikk0I6jF94iIOZ8t5u1+hjClHNctUE1GPQtzCy0n1 zUtUgqYwnNQh7r+pTory6yE4HWeQLdCH1Qy1g8/5i2RJBWjg33vA0cKdg q2uJvnBasfDM/9DRWwKJm0PpEqSts7FEdNyV8SLa/NpPLyrItREkzj9Ca Q==; X-CSE-ConnectionGUID: imm7mhVCTIiFuZKYogs1qQ== X-CSE-MsgGUID: ZuQE2lcnT8ujhl9G2UKjRg== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689787" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689787" X-CSE-ConnectionGUID: wooCqLHeS6GiI0bPYQB6Sg== X-CSE-MsgGUID: Nssb6yFVSEmGQHaQCO+BPQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989635" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 43/60] i386/tdx: Only configure MSR_IA32_UCODE_REV in kvm_init_msrs() for TDs Date: Tue, 5 Nov 2024 01:23:51 -0500 Message-Id: <20241105062408.3533704-44-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789559292116601 Content-Type: text/plain; charset="utf-8" For TDs, only MSR_IA32_UCODE_REV in kvm_init_msrs() can be configured by VMM, while the features enumerated/controlled by other MSRs except MSR_IA32_UCODE_REV in kvm_init_msrs() are not under control of VMM. Only configure MSR_IA32_UCODE_REV for TDs. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- target/i386/kvm/kvm.c | 44 ++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 595439f4a4d6..8909fce14909 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -3852,32 +3852,34 @@ static void kvm_init_msrs(X86CPU *cpu) CPUX86State *env =3D &cpu->env; =20 kvm_msr_buf_reset(cpu); - if (has_msr_arch_capabs) { - kvm_msr_entry_add(cpu, MSR_IA32_ARCH_CAPABILITIES, - env->features[FEAT_ARCH_CAPABILITIES]); - } - - if (has_msr_core_capabs) { - kvm_msr_entry_add(cpu, MSR_IA32_CORE_CAPABILITY, - env->features[FEAT_CORE_CAPABILITY]); - } - - if (has_msr_perf_capabs && cpu->enable_pmu) { - kvm_msr_entry_add_perf(cpu, env->features); + + if (!is_tdx_vm()) { + if (has_msr_arch_capabs) { + kvm_msr_entry_add(cpu, MSR_IA32_ARCH_CAPABILITIES, + env->features[FEAT_ARCH_CAPABILITIES]); + } + + if (has_msr_core_capabs) { + kvm_msr_entry_add(cpu, MSR_IA32_CORE_CAPABILITY, + env->features[FEAT_CORE_CAPABILITY]); + } + + if (has_msr_perf_capabs && cpu->enable_pmu) { + kvm_msr_entry_add_perf(cpu, env->features); + } + + /* + * Older kernels do not include VMX MSRs in KVM_GET_MSR_INDEX_LIST= , but + * all kernels with MSR features should have them. + */ + if (kvm_feature_msrs && cpu_has_vmx(env)) { + kvm_msr_entry_add_vmx(cpu, env->features); + } } =20 if (has_msr_ucode_rev) { kvm_msr_entry_add(cpu, MSR_IA32_UCODE_REV, cpu->ucode_rev); } - - /* - * Older kernels do not include VMX MSRs in KVM_GET_MSR_INDEX_LIST, but - * all kernels with MSR features should have them. - */ - if (kvm_feature_msrs && cpu_has_vmx(env)) { - kvm_msr_entry_add_vmx(cpu, env->features); - } - assert(kvm_buf_set_msrs(cpu) =3D=3D 0); } =20 --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789355; cv=none; d=zohomail.com; s=zohoarc; b=cIMWbMKPCkz9W0RbTvsyl04UK7i3V4qwuOlMZKJJfvapHFY4KjXBvlWStEvu/mbISz2T/6xwUg8C7mD78aA03CzYB0A0U15UNy+9ULm5DS6lMoXXcYfqlYu+0Cmk3qNQgY/XXfJZoM7IYtTlskXZsLT1WwHqzuyH97lSz/6Tfas= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789355; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=y1uyLVeBQlKxmu/7N5SuoU3tPsD71q2RbzmRQbfDyO4=; b=KLl4lV6Ya6vC7JiVic81nXSSKWMUU0FAmCiDohn8C3YShGsP7X/B8Z4srxuzizMMPzc5w1kuv9SQ/tAVBPE/a/rEgUltwUjx3WeHDWRyrZNQn4QxQR4WrkLBetQfRQrhiJuzRToZk6o05maz0seFjTdQjjXK7hHFCfWb9+xB6jA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789355316474.6531659016671; Mon, 4 Nov 2024 22:49:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DEV-00036B-PY; Tue, 05 Nov 2024 01:40:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DEC-0001Q4-5u for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:48 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DE9-0001vd-Az for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:47 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:39:31 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:39:27 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788785; x=1762324785; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+XE3AzklwMx8qhJJ+4Ok+j4KRAHEYu5njiiWc5OMr0s=; b=F3pDIQ0NVxzDnKy8hR8PR6BvRXHbKqoIAwObdlDQq8chOPqqb1Rqdqif k9vcJ6rvsXEdZ1dAIxiboQToBPt9oIMEZGRI+66kv2kCxALuCU5d3qx7U lM++uVuCv6nVE9RO6c9yvb/CvNeG5NbLqTu0EY7kqBYqep/kf/6CRL5Da eCopyuHW7hFAQmjvzn6l7S7cl8wyRJDsWExc4XhcBZvPQ93fDpqNnuSlK GJ1LSj2Kqb/T+xByY1jsWyr2T36fbBERlWJABEmLF1lJgA7wsJts0mnFU bS/KEPubtEQyHvNyjhmbVCWqMg0jOduBfuEhDVKGF5pn2uz90iS5Sa1AE w==; X-CSE-ConnectionGUID: D5fO8PP8Ql6VbuLeTynOOw== X-CSE-MsgGUID: B1lT4XivT0yLahDYwu7GAQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689801" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689801" X-CSE-ConnectionGUID: /q6YE+zjQ2S+qPxXDNLUQw== X-CSE-MsgGUID: 8D/bpe6kSS61Uxuq3srC+w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989664" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 44/60] i386/tdx: Skip kvm_put_apicbase() for TDs Date: Tue, 5 Nov 2024 01:23:52 -0500 Message-Id: <20241105062408.3533704-45-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789357474116600 Content-Type: text/plain; charset="utf-8" KVM doesn't allow wirting to MSR_IA32_APICBASE for TDs. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- target/i386/kvm/kvm.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 8909fce14909..c39e879a77e9 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -3627,6 +3627,11 @@ void kvm_put_apicbase(X86CPU *cpu, uint64_t value) { int ret; =20 + /* TODO: Allow accessing guest state for debug TDs. */ + if (is_tdx_vm()) { + return; + } + ret =3D kvm_put_one_msr(cpu, MSR_IA32_APICBASE, value); assert(ret =3D=3D 1); } --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730788997; cv=none; d=zohomail.com; s=zohoarc; b=PJEVDRZlaYqzHyuX+8K5gsunZK0vbpSDwuCuPhD7FemsEDHB4xreRyG/zL6oS03gCAeqGR2w2td3HX/A1RDJJwsKT09qhV8ZV/U/2mkcAWs3hR4fy9180bRfsxYnlmF7lgt36/01OQvLL/5ycvj47RiU4+qR9BCFhHoyRHs5zt0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730788997; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uaskrK3C/vkKL9pj/RGJ02d3WHRRNWzAfVL/yS68yJ8=; b=YArU4DGid7MB4rBeHoLFQoiFbquAz5G5PFXbqhizwDjIl8bka6988xKDUwJXm+sBa2eeClqkGZ0v8XiV3BgiDhoYFJ1WJWzKF8Bxw42krj68oU5UmMAH4Qy3HGVFzOJx/Af063mUIaPPx1z1K8yfPZjITcJKJSqSASotFLNBJYE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730788997692780.486374342787; Mon, 4 Nov 2024 22:43:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DEM-0002IO-25; Tue, 05 Nov 2024 01:39:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DED-0001V2-7j for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:49 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DEB-0001w0-CD for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:48 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:39:35 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:39:31 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788787; x=1762324787; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=C2RlAuENX7AQKgB6fkf8PxOsDfhUa1Oh2lPmCd3nnHY=; b=gOqr5VF2w5XABWJ/DvoH/Ih+u7hgppt+TtQxFjfQy0lfHGHJT5rFqPRC GsxYZY6sKTGeB+4bAj8O4J+Vu9k1v8+A0cgrcVVlcrx5jBe8WyZKrw6Et /OQRucOTMmWUxu4Ksdn4jeLejvhqXhRVBK3kdX55njmBr5/qhDGQDslpR EgXEI6dD9uk2NSi+9gnvVBCcmonFLCDXX0RnFyCuIBSyx8Eab9BBeTGB6 5DVqda1OhunysKXglp6SWTg4Bi9MLNKykOol/c3MY5acU9s7ybyXZbjbM VOZERSGWZOafI13i7pmOOyWiQL8x3fg0EtQJq2ceQsxFZQJHAU27MloKQ g==; X-CSE-ConnectionGUID: YVOZJdZIR1KMYYQazAA28w== X-CSE-MsgGUID: a+C4OmGKSHKaRDq91qW4tQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689810" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689810" X-CSE-ConnectionGUID: nQHxqnLjRaOvI8sC+/HFoA== X-CSE-MsgGUID: w5YMLsrFQWCEEsV4cIXAAw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989690" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 45/60] i386/tdx: Don't get/put guest state for TDX VMs Date: Tue, 5 Nov 2024 01:23:53 -0500 Message-Id: <20241105062408.3533704-46-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730788999771116600 Content-Type: text/plain; charset="utf-8" From: Sean Christopherson Don't get/put state of TDX VMs since accessing/mutating guest state of production TDs is not supported. Note, it will be allowed for a debug TD. Corresponding support will be introduced when debug TD support is implemented in the future. Signed-off-by: Sean Christopherson Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- target/i386/kvm/kvm.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index c39e879a77e9..e47aa32233e6 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -5254,6 +5254,11 @@ int kvm_arch_put_registers(CPUState *cpu, int level,= Error **errp) =20 assert(cpu_is_stopped(cpu) || qemu_cpu_is_self(cpu)); =20 + /* TODO: Allow accessing guest state for debug TDs. */ + if (is_tdx_vm()) { + return 0; + } + /* * Put MSR_IA32_FEATURE_CONTROL first, this ensures the VM gets out of= VMX * root operation upon vCPU reset. kvm_put_msr_feature_control() shoul= d also @@ -5368,6 +5373,12 @@ int kvm_arch_get_registers(CPUState *cs, Error **err= p) error_setg_errno(errp, -ret, "Failed to get MP state"); goto out; } + + /* TODO: Allow accessing guest state for debug TDs. */ + if (is_tdx_vm()) { + return 0; + } + ret =3D kvm_getput_regs(cpu, 0); if (ret < 0) { error_setg_errno(errp, -ret, "Failed to get general purpose regist= ers"); --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730788969; cv=none; d=zohomail.com; s=zohoarc; b=eJkQoHMwGA0agfcHAH+5deeq1X88UGmmglvB50x7ya/xw9RGWklfthWcYZ8qJ9HUhP3U62SPhmKPSGNLvwOuL10vHer9Zrn/QPpBjTkCs+jy+CWkGNEApm+Nv5MTIroWLQthT5kBaAw3MmaOZJwShiK8rPWZW26JodHtmlrZuS0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730788969; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=s/K5Hm/Olz9KoksN4m7GCFlmPrQze7XrLquKGkbgnNk=; b=Azh105h6wftZje1YEsDEfRx7WZie/VmB/IUTb3uyl6O9Auo1fRHRfsgQg0juOYoDT9OvNtkY1MaJVZQ+azwYGRPHIeArPJ9tcGRVb8MKIm+8V/5i29y2twjwIgx0mUJwDBjgIeDdxiQWbtw+yZbjW1FxXxGE4+prk0hMmeTEokc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730788969683939.8816543287658; Mon, 4 Nov 2024 22:42:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DG2-0003wI-Ad; Tue, 05 Nov 2024 01:41:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DEO-0002gD-2m for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:40:00 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DEL-0001vj-7w for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:39:58 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:39:40 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:39:35 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788797; x=1762324797; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8SBCXjeKuMoMULo/dUKnjmMZB22IpUgmloGXn6p/MT4=; b=mx+IZt1N+waJSvcn1QzbKrXX7+XqjB5+7q4ZRc2GE4Gc0836QC/n8nyb zJV7NeJKj3/vXIWBZ6+n8HJNs4ROrWUqoC4WcnozGZohMrFkp1UsihSX2 9uD26QXKdhgpCJIg/PpxvSni488M0o9kfBj+RQKjXxVfiwr8ljQeQ0pYt OpLXf38Kh1v4dgExTYKH9Dr4SQNFwM/tO7u0F73V5WC1YUZwhELDXEW93 NBvu3ZMPmijcLO6ylO9czoGUzOGv2rDbIyqcfMUSMl6xqIXBJVptN9QQR FrkRmCPtddjeeRgnDBbENH8PO4IT70vGScGzl0o7QBsn4GlsexWO8Dz7D A==; X-CSE-ConnectionGUID: SjTKgVkiQzuM3jkK3YT8qw== X-CSE-MsgGUID: qk9B9KSOTuG7T2NJ0IU+dg== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689821" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689821" X-CSE-ConnectionGUID: 02jwTyEjT4W7WgQAzjU8Tg== X-CSE-MsgGUID: bd629gL+QAag3jRWFrdaqw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989718" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 46/60] i386/cgs: Rename *mask_cpuid_features() to *adjust_cpuid_features() Date: Tue, 5 Nov 2024 01:23:54 -0500 Message-Id: <20241105062408.3533704-47-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730788971967116600 Content-Type: text/plain; charset="utf-8" Because for TDX case, there are also fixed-1 bits that enfored by TDX module. Signed-off-by: Xiaoyao Li --- target/i386/confidential-guest.h | 20 ++++++++++---------- target/i386/kvm/kvm.c | 2 +- target/i386/sev.c | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/target/i386/confidential-guest.h b/target/i386/confidential-gu= est.h index 4b7ea91023dc..2dde29889c23 100644 --- a/target/i386/confidential-guest.h +++ b/target/i386/confidential-guest.h @@ -41,8 +41,8 @@ struct X86ConfidentialGuestClass { int (*kvm_type)(X86ConfidentialGuest *cg); void (*cpu_instance_init)(X86ConfidentialGuest *cg, CPUState *cpu); void (*cpu_realizefn)(X86ConfidentialGuest *cg, CPUState *cpu, Error *= *errp); - uint32_t (*mask_cpuid_features)(X86ConfidentialGuest *cg, uint32_t fea= ture, uint32_t index, - int reg, uint32_t value); + uint32_t (*adjust_cpuid_features)(X86ConfidentialGuest *cg, uint32_t f= eature, + uint32_t index, int reg, uint32_t va= lue); }; =20 /** @@ -83,21 +83,21 @@ static inline void x86_confidenetial_guest_cpu_realizef= n(X86ConfidentialGuest *c } =20 /** - * x86_confidential_guest_mask_cpuid_features: + * x86_confidential_guest_adjust_cpuid_features: * - * Removes unsupported features from a confidential guest's CPUID values, = returns - * the value with the bits removed. The bits removed should be those that= KVM - * provides independent of host-supported CPUID features, but are not supp= orted by - * the confidential computing firmware. + * Adjust the supported features from a confidential guest's CPUID values, + * returns the adjusted value. There are bits being removed that are not + * supported by the confidential computing firmware or bits being added th= at + * are forcibly exposed to guest by the confidential computing firmware. */ -static inline int x86_confidential_guest_mask_cpuid_features(X86Confidenti= alGuest *cg, +static inline int x86_confidential_guest_adjust_cpuid_features(X86Confiden= tialGuest *cg, uint32_t feat= ure, uint32_t index, int reg, uint= 32_t value) { X86ConfidentialGuestClass *klass =3D X86_CONFIDENTIAL_GUEST_GET_CLASS(= cg); =20 - if (klass->mask_cpuid_features) { - return klass->mask_cpuid_features(cg, feature, index, reg, value); + if (klass->adjust_cpuid_features) { + return klass->adjust_cpuid_features(cg, feature, index, reg, value= ); } else { return value; } diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index e47aa32233e6..f067961fba43 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -576,7 +576,7 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint= 32_t function, } =20 if (current_machine->cgs) { - ret =3D x86_confidential_guest_mask_cpuid_features( + ret =3D x86_confidential_guest_adjust_cpuid_features( X86_CONFIDENTIAL_GUEST(current_machine->cgs), function, index, reg, ret); } diff --git a/target/i386/sev.c b/target/i386/sev.c index 1a4eb1ada624..4e6582c6a666 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -946,7 +946,7 @@ out: } =20 static uint32_t -sev_snp_mask_cpuid_features(X86ConfidentialGuest *cg, uint32_t feature, ui= nt32_t index, +sev_snp_adjust_cpuid_features(X86ConfidentialGuest *cg, uint32_t feature, = uint32_t index, int reg, uint32_t value) { switch (feature) { @@ -2404,7 +2404,7 @@ sev_snp_guest_class_init(ObjectClass *oc, void *data) klass->launch_finish =3D sev_snp_launch_finish; klass->launch_update_data =3D sev_snp_launch_update_data; klass->kvm_init =3D sev_snp_kvm_init; - x86_klass->mask_cpuid_features =3D sev_snp_mask_cpuid_features; + x86_klass->adjust_cpuid_features =3D sev_snp_adjust_cpuid_features; x86_klass->kvm_type =3D sev_snp_kvm_type; =20 object_class_property_add(oc, "policy", "uint64", --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789460; cv=none; d=zohomail.com; s=zohoarc; b=EG1D0w4cY4pRmF63xaMockN7QPblFOawp0lDq1ezwXTYKJNFpQzJRsfQqhM0aqJwspNflzC6LUCpxcg+AzUlKTNhNNyFNLBv9PuASD5lY+Co8UzL2Vasb/BrwmZIISQHRAihPkc0T4hLLbX22dvkRlamnYYQREYFzH6/f79JSqE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789460; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9ShoMY3Ne1WzagY0VghFsHX6CUAjLTOw8QmyCpvzAp8=; b=XMYBNdnxsXVqIsyur1cjjkCq8Lzo88duz0yKg2XJ/DmACJYA3Cmc93EK2F3TDiUibK7YKSeLTd0DIbX6B00MQuhldbywv3Fxo6q5c8iQ9/D2haaFCTSQ67k1XDJ9AhLQviRBffSlRDELCMX/KyI6RsQbRx0Umrx8yD2EEIkrb0E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789460466591.4950105217486; Mon, 4 Nov 2024 22:51:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DG7-000410-IH; Tue, 05 Nov 2024 01:41:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DEO-0002gx-Fs for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:40:01 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DEM-0001vd-Hf for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:40:00 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:39:44 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:39:40 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788799; x=1762324799; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xbrsyTH8bvg8xsrUxtQa3cOVPKG1OlwWAfdK7z7v1Zw=; b=Pe0HaStynf2Zw8aZj1/ySwOCEkkdSEJfaaUz9tILiPf7FFUibLsiydDG UG2i3tZ+aM+MS14qIpAj4J0wnVwOGXikpAq+uRqQL+mbT3nTpl7PqwhO+ oaJeJ3waOR+2PUsOCA3c0Lyp9XR3w2eSFBeOKUwT4t+cuO4jLOjlvBVoR xgYul+kp/7oixf+Q/MGzFozYXT61trrlhLbA+5cson50YnFgJ7IEbupvy ZMohJ59RaK+r6ni4snGcPBjmikuCLDxVPoBEHFnq0/5NAjcsfHtvSj9ai Neig/h0tpXBnr/70pOmUSYQMPpJ9rXmnE5gPIHSsyOmwtfrr4+e2UbhXo A==; X-CSE-ConnectionGUID: fyacEsJgRP2WjnuIA+1WMg== X-CSE-MsgGUID: eV+WfMCJQy6c9MghH4a2NA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689834" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689834" X-CSE-ConnectionGUID: I1dHo+kSQGaDnrUYcs9Eow== X-CSE-MsgGUID: xUQf/ZneTdyrNfoRVh6f7g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989754" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 47/60] i386/tdx: Implement adjust_cpuid_features() for TDX Date: Tue, 5 Nov 2024 01:23:55 -0500 Message-Id: <20241105062408.3533704-48-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789462272116600 Content-Type: text/plain; charset="utf-8" 1. QEMU's support for Intel PT is borken in general, thus doesn't support for TDX. 2. Only limited KVM PV features are supported for TD guest. 3. Drop the AMD specific bits that are reserved on Intel platform. Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 9dcb77e011bd..ba723db92bfe 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -33,6 +33,8 @@ #include "kvm_i386.h" #include "tdx.h" =20 +#include "standard-headers/asm-x86/kvm_para.h" + #define TDX_MIN_TSC_FREQUENCY_KHZ (100 * 1000) #define TDX_MAX_TSC_FREQUENCY_KHZ (10 * 1000 * 1000) =20 @@ -41,6 +43,14 @@ #define TDX_TD_ATTRIBUTES_PKS BIT_ULL(30) #define TDX_TD_ATTRIBUTES_PERFMON BIT_ULL(63) =20 +#define TDX_SUPPORTED_KVM_FEATURES ((1U << KVM_FEATURE_NOP_IO_DELAY) | \ + (1U << KVM_FEATURE_PV_UNHALT) | \ + (1U << KVM_FEATURE_PV_TLB_FLUSH) | \ + (1U << KVM_FEATURE_PV_SEND_IPI) | \ + (1U << KVM_FEATURE_POLL_CONTROL) | \ + (1U << KVM_FEATURE_PV_SCHED_YIELD) | \ + (1U << KVM_FEATURE_MSI_EXT_DEST_ID)) + static TdxGuest *tdx_guest; =20 static struct kvm_tdx_capabilities *tdx_caps; @@ -436,6 +446,39 @@ static void tdx_cpu_realizefn(X86ConfidentialGuest *cg= , CPUState *cs, } } =20 +static uint32_t tdx_adjust_cpuid_features(X86ConfidentialGuest *cg, + uint32_t feature, uint32_t index, + int reg, uint32_t value) +{ + switch (feature) { + case 0x7: + if (index =3D=3D 0 && reg =3D=3D R_EBX) { + /* QEMU Intel PT support is broken */ + value &=3D ~CPUID_7_0_EBX_INTEL_PT; + } + break; + case 0x40000001: + if (reg =3D=3D R_EAX) { + value &=3D TDX_SUPPORTED_KVM_FEATURES; + } + break; + case 0x80000001: + if (reg =3D=3D R_EDX) { + value &=3D ~CPUID_EXT2_AMD_ALIASES; + } + break; + case 0x80000008: + if (reg =3D=3D R_EBX) { + value &=3D CPUID_8000_0008_EBX_WBNOINVD; + } + break; + default: + break; + } + + return value; +} + static int tdx_validate_attributes(TdxGuest *tdx, Error **errp) { if ((tdx->attributes & ~tdx_caps->supported_attrs)) { @@ -781,4 +824,5 @@ static void tdx_guest_class_init(ObjectClass *oc, void = *data) x86_klass->kvm_type =3D tdx_kvm_type; x86_klass->cpu_instance_init =3D tdx_cpu_instance_init; x86_klass->cpu_realizefn =3D tdx_cpu_realizefn; + x86_klass->adjust_cpuid_features =3D tdx_adjust_cpuid_features; } --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789040; cv=none; d=zohomail.com; s=zohoarc; b=flNzVGMWMeQdjRBoXoX1bEru6yPJRW6dv4llYCoNRqu0nqqmsAYzPC80/1BS8sPBpLxwgYkPIPxSDhdSC6lScqAzSlOC4h4Gry3E/ATwiHuUpWrzd2TjUBWIOvNK6c0jrLtdpzYhBn2MWSyUmWX6q7jSWYvsnKFFW1J0dinA2qc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789040; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VYvw/YIdfJ6WOQkCeGqEs/+HpgbViJ/XWBGaeqwJIAw=; b=CuY1TURg7EeIsk7JyIIVUkIh8r7C8tr5GXa502qWq6ujVN0gwK1m1L4cnQo6XPrXSQgFmT7AFpAaY4CiDml5PJa3IGc2sMPPR4BTFambnHk7pCCZy3v0jQ0sKbUKNT1e0pVnnKtCAq3dGobra9WCIWkNUXn3y60hi1KLmkekKZA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789040129244.8023004185219; Mon, 4 Nov 2024 22:44:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DGR-0003wQ-8F; Tue, 05 Nov 2024 01:42:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DEP-0002jw-Pt for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:40:02 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DEN-0001w0-Iy for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:40:01 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:39:48 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:39:44 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788800; x=1762324800; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=deJjyJ9mt80ns5ej0bXUJMHjNBnYjzuUgaD7RaYuZHg=; b=CF65ixPH+49hN905BvW6k43KUERifGoUZAlsw44RLH4lZZNOvEBXVO2t tdRmyUJC6qbYa7vmaVaMmNwZn5l59FCjRMNXMpyrQMexAv+yGp5aCtzIp pXasCk7HtJZvXkP8VSL9SL1APKAsLoyMsNwzIfAJvyopotW5+vvqZLkKE DA1SzCJOgDWjZ2jWUPEJaHoFmTCUkyJ4p+wdyVs+xPTEfiI7tXIFQeRwZ xxMd5zZ/E1oHT8URO5gYRSRi1qVRPnrN3549WKyBTjxs7Jhswc/HRrXIK 4QaetMTq+IxReymnea1Or6lbPDQj0dUHPDG678OxY3nlsqR+tylum+yLN w==; X-CSE-ConnectionGUID: PJebBBoRSJWk53Sn+1iXNg== X-CSE-MsgGUID: GQGVILnERTS6KPyHQrA9GA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689844" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689844" X-CSE-ConnectionGUID: DRI0gvHuR1iEyNYSoW/T8w== X-CSE-MsgGUID: XNjENJeDQkSChrVYaaBSCA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989792" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 48/60] i386/tdx: Apply TDX fixed0 and fixed1 information to supported CPUIDs Date: Tue, 5 Nov 2024 01:23:56 -0500 Message-Id: <20241105062408.3533704-49-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789041941116600 Content-Type: text/plain; charset="utf-8" TDX architecture forcibly sets some CPUID bits for TD guest that VMM cannot disable it. It also disallows some CPUID bits though they might be supported for VMX VMs. The fixed0 and fixed1 bits may vary on different TDX module and on different host. It's a huge burden to maintain all combination. To simplify it, hardcode the fixed0 and fixed1 CPUID bits that irrelative with host in QEMU based on a new enough TDX module version. Ideally, future TDX module can expose such fixed0 and fixed1 information via some interface, then KVM can reported them to QEMU. Signed-off-by: Xiaoyao Li --- target/i386/cpu.h | 2 + target/i386/kvm/kvm_i386.h | 6 +++ target/i386/kvm/tdx.c | 102 +++++++++++++++++++++++++++++++++++++ target/i386/sev.c | 5 -- 4 files changed, 110 insertions(+), 5 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index dcc673262c06..8118356af4fc 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -854,6 +854,8 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu= , FeatureWord w); #define CPUID_7_0_EBX_SMAP (1U << 20) /* AVX-512 Integer Fused Multiply Add */ #define CPUID_7_0_EBX_AVX512IFMA (1U << 21) +/* PCOMMIT instruction */ +#define CPUID_7_0_EBX_PCOMMIT (1U << 22) /* Flush a Cache Line Optimized */ #define CPUID_7_0_EBX_CLFLUSHOPT (1U << 23) /* Cache Line Write Back */ diff --git a/target/i386/kvm/kvm_i386.h b/target/i386/kvm/kvm_i386.h index b1baf9e7f910..0b8240266dd9 100644 --- a/target/i386/kvm/kvm_i386.h +++ b/target/i386/kvm/kvm_i386.h @@ -12,9 +12,15 @@ #define QEMU_KVM_I386_H =20 #include "sysemu/kvm.h" +#include =20 #define KVM_MAX_CPUID_ENTRIES 100 =20 +typedef struct KvmCpuidInfo { + struct kvm_cpuid2 cpuid; + struct kvm_cpuid_entry2 entries[KVM_MAX_CPUID_ENTRIES]; +} KvmCpuidInfo; + #ifdef CONFIG_KVM =20 #define kvm_pit_in_kernel() \ diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index ba723db92bfe..bc1581d1e43b 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -446,10 +446,100 @@ static void tdx_cpu_realizefn(X86ConfidentialGuest *= cg, CPUState *cs, } } =20 +/* + * Fixed0 and Fixed1 bits info are grabbed from TDX 1.5.06 spec. + */ +KvmCpuidInfo tdx_fixed0_bits =3D { + .cpuid.nent =3D 3, + .entries[0] =3D { + .function =3D 0x1, + .index =3D 0x0, + .ecx =3D CPUID_EXT_VMX | CPUID_EXT_SMX, + .edx =3D CPUID_PSE36 | CPUID_IA64, + }, + .entries[1] =3D { + .function =3D 0x7, + .index =3D 0x0, + .flags =3D KVM_CPUID_FLAG_SIGNIFCANT_INDEX, + .ebx =3D CPUID_7_0_EBX_TSC_ADJUST | CPUID_7_0_EBX_SGX | + CPUID_7_0_EBX_PCOMMIT, + .ecx =3D CPUID_7_0_ECX_SGX_LC | (1U << 15) | (0x1fU << 17) | (1U <= < 26) | + (1U << 29), + .edx =3D (1U << 0) | (1U << 1) | (1U << 7) | (1U << 9) | (1U << 11= ) | + (1U << 12) | (1U << 13) | (1U << 15) | (1U << 17) | (1U << = 21), + }, + .entries[2] =3D { + .function =3D 0x80000001, + .index =3D 0x0, + .ecx =3D 0xFFFFFEDE, + .edx =3D 0xD3EFF7FF, + }, +}; + +KvmCpuidInfo tdx_fixed1_bits =3D { + .cpuid.nent =3D 6, + .entries[0] =3D { + .function =3D 0x1, + .index =3D 0, + .ecx =3D CPUID_EXT_SSE3 | CPUID_EXT_PCLMULQDQ | CPUID_EXT_DTES64 | + CPUID_EXT_DSCPL | CPUID_EXT_SSE3 | CPUID_EXT_CX16 | + CPUID_EXT_PDCM | CPUID_EXT_PCID | CPUID_EXT_SSE41 | + CPUID_EXT_SSE42 | CPUID_EXT_X2APIC | CPUID_EXT_MOVBE | + CPUID_EXT_POPCNT | CPUID_EXT_AES | CPUID_EXT_XSAVE | + CPUID_EXT_RDRAND | CPUID_EXT_HYPERVISOR, + .edx =3D CPUID_FP87 | CPUID_VME | CPUID_DE | CPUID_PSE | CPUID_TSC= | + CPUID_MSR | CPUID_PAE | CPUID_MCE | CPUID_CX8 | CPUID_APIC | + CPUID_SEP | CPUID_MTRR | CPUID_PGE | CPUID_MCA | CPUID_CMOV= | + CPUID_PAT | CPUID_CLFLUSH | CPUID_DTS | CPUID_MMX | CPUID_F= XSR | + CPUID_SSE | CPUID_SSE2, + }, + .entries[1] =3D { + .function =3D 0x6, + .index =3D 0, + .eax =3D CPUID_6_EAX_ARAT, + }, + .entries[2] =3D { + .function =3D 0x7, + .index =3D 0, + .flags =3D KVM_CPUID_FLAG_SIGNIFCANT_INDEX, + .ebx =3D CPUID_7_0_EBX_FSGSBASE | CPUID_7_0_EBX_FDP_EXCPTN_ONLY | + CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_INVPCID | + CPUID_7_0_EBX_ZERO_FCS_FDS | CPUID_7_0_EBX_RDSEED | + CPUID_7_0_EBX_SMAP | CPUID_7_0_EBX_CLFLUSHOPT | + CPUID_7_0_EBX_CLWB | CPUID_7_0_EBX_SHA_NI, + .ecx =3D CPUID_7_0_ECX_BUS_LOCK_DETECT | CPUID_7_0_ECX_MOVDIRI | + CPUID_7_0_ECX_MOVDIR64B, + .edx =3D (1U << 10) | CPUID_7_0_EDX_SPEC_CTRL | CPUID_7_0_EDX_STIB= P | + CPUID_7_0_EDX_FLUSH_L1D | CPUID_7_0_EDX_ARCH_CAPABILITIES | + CPUID_7_0_EDX_CORE_CAPABILITY | CPUID_7_0_EDX_SPEC_CTRL_SSB= D, + }, + .entries[3] =3D { + .function =3D 0x7, + .index =3D 2, + .flags =3D KVM_CPUID_FLAG_SIGNIFCANT_INDEX, + .edx =3D (1U << 0) | (1U << 1) | (1U << 2) | (1U << 4), + }, + .entries[4] =3D { + .function =3D 0x80000001, + .index =3D 0, + .ecx =3D CPUID_EXT3_LAHF_LM | CPUID_EXT3_ABM | CPUID_EXT3_3DNOWPRE= FETCH, + .edx =3D CPUID_EXT2_NX | CPUID_EXT2_PDPE1GB | CPUID_EXT2_RDTSCP | + CPUID_EXT2_LM, + }, + .entries[5] =3D { + .function =3D 0x80000007, + .index =3D 0, + .edx =3D CPUID_APM_INVTSC, + }, +}; + static uint32_t tdx_adjust_cpuid_features(X86ConfidentialGuest *cg, uint32_t feature, uint32_t index, int reg, uint32_t value) { + struct kvm_cpuid_entry2 *e; + uint32_t fixed0, fixed1; + switch (feature) { case 0x7: if (index =3D=3D 0 && reg =3D=3D R_EBX) { @@ -476,6 +566,18 @@ static uint32_t tdx_adjust_cpuid_features(X86Confident= ialGuest *cg, break; } =20 + e =3D cpuid_find_entry(&tdx_fixed0_bits.cpuid, feature, index); + if (e) { + fixed0 =3D cpuid_entry_get_reg(e, reg); + value &=3D ~fixed0; + } + + e =3D cpuid_find_entry(&tdx_fixed1_bits.cpuid, feature, index); + if (e) { + fixed1 =3D cpuid_entry_get_reg(e, reg); + value |=3D fixed1; + } + return value; } =20 diff --git a/target/i386/sev.c b/target/i386/sev.c index 4e6582c6a666..6982a957a6f7 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -214,11 +214,6 @@ static const char *const sev_fw_errlist[] =3D { /* doesn't expose this, so re-use the max from kvm.c */ #define KVM_MAX_CPUID_ENTRIES 100 =20 -typedef struct KvmCpuidInfo { - struct kvm_cpuid2 cpuid; - struct kvm_cpuid_entry2 entries[KVM_MAX_CPUID_ENTRIES]; -} KvmCpuidInfo; - #define SNP_CPUID_FUNCTION_MAXCOUNT 64 #define SNP_CPUID_FUNCTION_UNKNOWN 0xFFFFFFFF =20 --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730788974; cv=none; d=zohomail.com; s=zohoarc; b=NNTfokGI/pBVRuiHDp9bGTC94lV4eEyHCU7P9bA9jeuaHENQ9kQwV2Ehw1QFM7oyEP9Vuz6+oaDmy31Q1WGFV4Nn3UudY/RbScy0T9XowN9eXFMJe8Mk7CWjG67nTVlYiSZiFEHJrxbKAMkvyXJ9v6BtREOv0SFH3sEgmMpUnZQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730788974; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Z80OGiXRMpUBHGGQUj9JJU0czfhy/mZAH9V91kBTWhQ=; b=LAFE+lsxE28xhsDfIlWSDne6+nFMGNthXHE2/ewJVQ1Ywpj0nfXiJegr3Qu8LjriWQbaiFS6AyWiBIkL6QUNkrKXqhvZ9u3LUD0o3mWPLYGBAcEw3ydwMV+FwqxTTNPFRXRrGAE4uUV6HbS8btB0EkBoYWFCF1DQFGTvSDCSD8Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730788974361954.859262748189; Mon, 4 Nov 2024 22:42:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DGJ-0003wC-FS; Tue, 05 Nov 2024 01:41:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DEZ-0003Jp-H3 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:40:12 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DEX-0001vj-Lv for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:40:11 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:39:53 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:39:48 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788810; x=1762324810; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=st5/vyvnaPY+w7rPqzvPYRhQDfLRvMD4QU7tirPy57w=; b=iJxjlLww7BNiFkAYoXyPBWZwzy30x0TtsrRp1/OJhGG9LIHGDrUPlLOT iUdtWB4gbE4AEq1gPMg5Fr70k/zn/oUjQ4P2abYCuNM+geefvBRmpX1Wc e2u5jvd/t6TA7sxoqJwu7N0PJbmeNmGKW8in8f7ELf7LRPq3DFTto/MTa owdOORmaDYERJFwJU+/ACgWcer5On+pIDByUmsKlGcx1RSyE4nEWiTCZy j7bdBHhXqaEndwPGp79lC2B+ON3aoIZlhflzm58UV6tx8rN5bs+/XW+Jo RHR3cfK6TqKJYs9qDMtgn7UepIcKlVWakUDv9WN34y0lMZHFMPgFqDlsE g==; X-CSE-ConnectionGUID: LieXTUHJTECa6eTN059MJg== X-CSE-MsgGUID: s561OErZQsq58I0Zx7SzDQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689854" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689854" X-CSE-ConnectionGUID: 5WJ5xED5SVGuZQVUr6MnSA== X-CSE-MsgGUID: 5It1nMLzSeKHTxiykp0Vsg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989825" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 49/60] i386/tdx: Mask off CPUID bits by unsupported TD Attributes Date: Tue, 5 Nov 2024 01:23:57 -0500 Message-Id: <20241105062408.3533704-50-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730788975692116600 Content-Type: text/plain; charset="utf-8" For TDX, some CPUID feature bit is configured via TD attributes. Adjust the supported CPUID to mask off the bit if its matched attribute is unsupported. Signed-off-by: Xiaoyao Li --- target/i386/cpu.h | 4 ++++ target/i386/kvm/tdx.c | 54 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 8118356af4fc..e02e23d972a0 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -903,6 +903,8 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu= , FeatureWord w); #define CPUID_7_0_ECX_LA57 (1U << 16) /* Read Processor ID */ #define CPUID_7_0_ECX_RDPID (1U << 22) +/* KeyLocker */ +#define CPUID_7_0_ECX_KeyLocker (1U << 23) /* Bus Lock Debug Exception */ #define CPUID_7_0_ECX_BUS_LOCK_DETECT (1U << 24) /* Cache Line Demote Instruction */ @@ -955,6 +957,8 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu= , FeatureWord w); #define CPUID_7_1_EAX_AVX_VNNI (1U << 4) /* AVX512 BFloat16 Instruction */ #define CPUID_7_1_EAX_AVX512_BF16 (1U << 5) +/* Linear address space separation */ +#define CPUID_7_1_EAX_LASS (1U << 6) /* CMPCCXADD Instructions */ #define CPUID_7_1_EAX_CMPCCXADD (1U << 7) /* Fast Zero REP MOVS */ diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index bc1581d1e43b..5ac5f93907ca 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -533,6 +533,58 @@ KvmCpuidInfo tdx_fixed1_bits =3D { }, }; =20 +typedef struct TdxAttrsMap { + uint32_t attr_index; + uint32_t cpuid_leaf; + uint32_t cpuid_subleaf; + int cpuid_reg; + uint32_t feat_mask; +} TdxAttrsMap; + +static TdxAttrsMap tdx_attrs_maps[] =3D { + {.attr_index =3D 27, + .cpuid_leaf =3D 7, + .cpuid_subleaf =3D 1, + .cpuid_reg =3D R_EAX, + .feat_mask =3D CPUID_7_1_EAX_LASS}, + {.attr_index =3D 30, + .cpuid_leaf =3D 7, + .cpuid_subleaf =3D 0, + .cpuid_reg =3D R_ECX, + .feat_mask =3D CPUID_7_0_ECX_PKS,}, + {.attr_index =3D 31, + .cpuid_leaf =3D 7, + .cpuid_subleaf =3D 0, + .cpuid_reg =3D R_ECX, + .feat_mask =3D CPUID_7_0_ECX_KeyLocker, + }, +}; + +static void tdx_mask_cpuid_by_attrs(uint32_t feature, uint32_t index, + int reg, uint32_t *value) +{ + TdxAttrsMap *map; + uint64_t unavail =3D 0; + int i; + + for (i =3D 0; i < ARRAY_SIZE(tdx_attrs_maps); i++) { + map =3D &tdx_attrs_maps[i]; + + if (feature !=3D map->cpuid_leaf || index !=3D map->cpuid_subleaf = || + reg !=3D map->cpuid_reg) { + continue; + } + + if (!((1ULL << map->attr_index) & tdx_caps->supported_attrs)) { + unavail |=3D map->feat_mask; + } + } + + if (unavail) { + *value &=3D ~unavail; + } +} + static uint32_t tdx_adjust_cpuid_features(X86ConfidentialGuest *cg, uint32_t feature, uint32_t index, int reg, uint32_t value) @@ -566,6 +618,8 @@ static uint32_t tdx_adjust_cpuid_features(X86Confidenti= alGuest *cg, break; } =20 + tdx_mask_cpuid_by_attrs(feature, index, reg, &value); + e =3D cpuid_find_entry(&tdx_fixed0_bits.cpuid, feature, index); if (e) { fixed0 =3D cpuid_entry_get_reg(e, reg); --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789264; cv=none; d=zohomail.com; s=zohoarc; b=lg/VlExNVYgLr/SPJxVc0nRMzOtN3VSUqlLmuXmRzPFh1VbcIDr3BUc566suikoskR8jrXMZm9NWquxVDrU8jWygtDwehtNJg9CSGANhzeoZQU0KrnVTcnFxyiTUjgAbVyX8BEFK+qSKgKJ3QgxoMK5HI/kV29/ZN3/nszWcZYU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789264; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uzTmp6gQ72yYbtSBsNfDnCI5DZmbyn36WdUQOa7QyM8=; b=ROxPl+Hkfpw4WvkjaDwDvTUuP6Hat/tE6NVM/VhrsTQcuCEzekg0rV6ReVE/YXc7LyvlopwiAYi+LDgQZQN4ljMYaTpHX39h5+Zo73dIrhDsLfLI9mOUdk2+GGNRMhHHY++Tti9hLkTqmS8czj/I78pq+gd2DhU40gDzgG162Dk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789264021991.7871375070542; Mon, 4 Nov 2024 22:47:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DGu-00051L-E9; Tue, 05 Nov 2024 01:42:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DEa-0003OU-Jy for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:40:14 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DEY-0001vd-SP for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:40:12 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:39:57 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:39:53 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788811; x=1762324811; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=f1vBUeMjW4fPDV+AM3GOU/JcU0MWDw60zLwDbytS/8c=; b=aa5VEWKOmh9ykSrkRhngNZsQAiqr8l/yjq/jl3YFv03g8EIFLJE3xspz Y7y8qXVIDn/a9dwmcg4k1ArkMo/XAaMPPZbu60S2G6R6Ssau3O7F0SAwQ 9vQMRdZASZMBWEI7yiX6U/giMoc6p9A6UaNWw1ZmrgNZYTcgf8DGw8W5F afgjrmqr5Zr3awL+YjpkSUmyQUwy9iynydKnUxPhHtB/fomgGNuOYJTkl HfP9pXsG5saOUYTzE1QgnVgzeqT0WB+w3Qyo/rjAU6ceM6+cY1ABcQGzR EWlKyzOzg7IEr5RT0lkMLryA4GSsUtKNWt0hinnWlY0eioXXn6Zj/uoui w==; X-CSE-ConnectionGUID: EBLiuByLQdWXewPleI7/Ng== X-CSE-MsgGUID: xgwJGJXHTp+zeAAc838zAg== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689863" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689863" X-CSE-ConnectionGUID: AyZ+kzahRb2rPCJpujgR5g== X-CSE-MsgGUID: YIvu0W5xTNuM1XUDVf3m0A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989850" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 50/60] i386/cpu: Move CPUID_XSTATE_XSS_MASK to header file and introduce CPUID_XSTATE_MASK Date: Tue, 5 Nov 2024 01:23:58 -0500 Message-Id: <20241105062408.3533704-51-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789265050116600 Content-Type: text/plain; charset="utf-8" They will be used by TDX. Signed-off-by: Xiaoyao Li --- target/i386/cpu.c | 3 --- target/i386/cpu.h | 5 +++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 119b38bcb0c1..8c507ad406e7 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1827,9 +1827,6 @@ static const X86RegisterInfo32 x86_reg_info_32[CPU_NB= _REGS32] =3D { }; #undef REGISTER =20 -/* CPUID feature bits available in XSS */ -#define CPUID_XSTATE_XSS_MASK (XSTATE_ARCH_LBR_MASK) - ExtSaveArea x86_ext_save_areas[XSAVE_STATE_AREA_COUNT] =3D { [XSTATE_FP_BIT] =3D { /* x87 FP state component is always enabled if XSAVE is supported = */ diff --git a/target/i386/cpu.h b/target/i386/cpu.h index e02e23d972a0..0cc88c470dfb 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -621,6 +621,11 @@ typedef enum X86Seg { XSTATE_Hi16_ZMM_MASK | XSTATE_PKRU_MASK |= \ XSTATE_XTILE_CFG_MASK | XSTATE_XTILE_DATA= _MASK) =20 +/* CPUID feature bits available in XSS */ +#define CPUID_XSTATE_XSS_MASK (XSTATE_ARCH_LBR_MASK) + +#define CPUID_XSTATE_MASK (CPUID_XSTATE_XCR0_MASK | CPUID_XSTATE_XSS= _MASK) + /* CPUID feature words */ typedef enum FeatureWord { FEAT_1_EDX, /* CPUID[1].EDX */ --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789232; cv=none; d=zohomail.com; s=zohoarc; b=GUiPr4HDMuk8vrqxYXsOcXfs/GTbn9974fmVfhI93CyC3rvSZ6ytQgzkqBFL6qyJo/vai3x6Hlgj8OBP1abQ5DGNelgGq+Jt+o7EZyqF1bBHBvO9hYz38eLuSDdfpOhLSyJxYXgUcDBgMKTFI3wlkU7txjaszjHsdGpN3bWnOP0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789232; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CKuZpZe7FwkMKxWfDZAfSO3PCdo1NAzA3UFbTcU/62k=; b=NUPW9D3YhlCdrj2mSGlnIu0jIBbVvNknrxXW5B/EbJz0HyC5U8YR8+IrYj9en7ofEmpmDphJhX+95YDULuIDpUMUhPaG8zPbonmzxIR8RJpsIe2+CEUvhI3rrQF86lRY6fYFVgcarEzduJaMllL60KyWkwcJDP382FGX0YsJxzE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789232867842.6611191068524; Mon, 4 Nov 2024 22:47:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DH4-0005lK-B9; Tue, 05 Nov 2024 01:42:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DEh-0003Ul-F3 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:40:28 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DEa-0001w0-9p for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:40:13 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:40:01 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:39:57 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788812; x=1762324812; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+RyN2ozpNF9/qWmSSJyynxhc2IsEJ+Gu8thAMTAlGko=; b=bpMcBrIaEuS8eG15sHJprjKq2P/bCUlxHliBH1377vHEKWzclQGFzWG9 7Ho8OFrRnFFRiiBCIfwe3U0yNXFvizn3yb9m2WViIzN8op0T5DsWs+BV6 mlvWTBOsdFHRn3hiMk+z7H3ArsxWUBBVBZZAizMWrb1ghYKI3kGjU6P1Y dPcb+PjEBM++Aqhv3hk8n93NbJstzuccIrs9GjK7U1YoWThq0trdyT+VL US1muR3I2LtqWNFMrk/M1G0I79eAu1PiAKlDFsSA7tZitLKWey9kVqRUy VqkdKRyTFKirWAKP/7Xqo26QlGFOY/QYGzR4f29DZmnmhWQLBJREDqrTJ Q==; X-CSE-ConnectionGUID: DIy7Jf1WQEmj/lS1URSlxg== X-CSE-MsgGUID: +y/VQ/3PQ62KA4QHNm9KtQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689872" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689872" X-CSE-ConnectionGUID: 5jqpsLxmSO+hY5dQHtlrcg== X-CSE-MsgGUID: fhbU8dw3QlKkdGhUX6WkBg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989877" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 51/60] i386/tdx: Mask off CPUID bits by unsupported XFAM Date: Tue, 5 Nov 2024 01:23:59 -0500 Message-Id: <20241105062408.3533704-52-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789234935116600 Content-Type: text/plain; charset="utf-8" Mask off the CPUID bits as unsupported if its matched XFAM bit is not supported. Otherwise, it might fail the check in setup_td_xfam() as unsupported XFAM being requested. Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 5ac5f93907ca..e7e0f073dfc9 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -24,6 +24,7 @@ #include =20 #include "cpu.h" +#include "cpu-internal.h" #include "host-cpu.h" #include "hw/i386/e820_memory_layout.h" #include "hw/i386/x86.h" @@ -585,6 +586,42 @@ static void tdx_mask_cpuid_by_attrs(uint32_t feature, = uint32_t index, } } =20 +static void tdx_mask_cpuid_by_xfam(uint32_t feature, uint32_t index, + int reg, uint32_t *value) +{ + const FeatureWordInfo *f; + const ExtSaveArea *esa; + uint64_t unavail =3D 0; + int i; + + assert(tdx_caps); + + for (i =3D 0; i < ARRAY_SIZE(x86_ext_save_areas); i++) { + if ((1ULL << i) & tdx_caps->supported_xfam) { + continue; + } + + if (!((1ULL << i) & CPUID_XSTATE_MASK)) { + continue; + } + + esa =3D &x86_ext_save_areas[i]; + f =3D &feature_word_info[esa->feature]; + assert(f->type =3D=3D CPUID_FEATURE_WORD); + if (f->cpuid.eax !=3D feature || + (f->cpuid.needs_ecx && f->cpuid.ecx !=3D index) || + f->cpuid.reg !=3D reg) { + continue; + } + + unavail |=3D esa->bits; + } + + if (unavail) { + *value &=3D ~unavail; + } +} + static uint32_t tdx_adjust_cpuid_features(X86ConfidentialGuest *cg, uint32_t feature, uint32_t index, int reg, uint32_t value) @@ -619,6 +656,7 @@ static uint32_t tdx_adjust_cpuid_features(X86Confidenti= alGuest *cg, } =20 tdx_mask_cpuid_by_attrs(feature, index, reg, &value); + tdx_mask_cpuid_by_xfam(feature, index, reg, &value); =20 e =3D cpuid_find_entry(&tdx_fixed0_bits.cpuid, feature, index); if (e) { --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789039; cv=none; d=zohomail.com; s=zohoarc; b=gc73AnhwvG+UtaPQvRw5q3gWLPJ2sF79ddfqJEFC3bnjAmw1yR8foSyc/aFlc4ZJIhch6NoROZy5X77Whn38ypQdnp04JO/dCVikLDCAiX697twEHvk/YRrvhZ51UwO4CIGULxrtXzvq9E98zNTUbGBlwAkwyx9L5PXUg5FgaQM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789039; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=J3OX9kVhbbSNskK0tUVGVQAkN3MQ8eoP9WnGxN5K500=; b=kK9FC3bKc+Dyp66pqkzjSgcRazBZpb6De66R5FBYmGpD0RWq3xMgMgNvpo7EmL4q4klsKVblTfoussBIxuMO46de5j54rFPmO/YRBC3nmPO7MNRwl1acbhyWwxsn7s8LQLhK2XixMuCARDOg3C6cuWMeJJA3poQq0zYSBw1wr/8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 173078903966982.53559208348781; Mon, 4 Nov 2024 22:43:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DH4-0005lW-AZ; Tue, 05 Nov 2024 01:42:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DEy-0003XE-F7 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:40:37 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DEj-0001vj-Uy for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:40:30 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:40:05 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:40:01 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788822; x=1762324822; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=P5Dpgnlq8pIkngj4xnDuBRfdAfvVDs1AjzLSgYZekNU=; b=hFQEwAiXqQKHSHvdCVtZDyi9zjvcHquIZ5uNuqBZ13qb0DbfV0H9IQlq aEoA7jlIzNVy+WZWzgrIUZF1K0i9qTUSAMy7B5/XOqJGOSRafhaVfTW+c C5JX5PqEbzRLuLt/1UhARBUcIrxv7l+NAb5AmME66qZASYmPKfGejuiJu n3nq5YPd8D6FKOHkXQamgnfDSV/DewUTY31HoAAbTkBtyiHWQ8AjcaNG2 Rshw6krVem6LkNHUmv4glasP0APDxMZcw4HH9+n++Kzxnc72yRtIMzAmj Nw1Nsc3d6us90KMzI66cyi2PLLQvyzB7prUdXkMtKdA7oVROh+bRIJvbN A==; X-CSE-ConnectionGUID: ogY3fIsVRC2g10wYBKtYvA== X-CSE-MsgGUID: C4FHXc3vSI25WJ2dcJtwAg== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689884" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689884" X-CSE-ConnectionGUID: c9TSTQY7QYKD76jrtTi9Dw== X-CSE-MsgGUID: zpSR5Yn5SvKva1MN49xPSA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989906" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 52/60] i386/cpu: Expose mark_unavailable_features() for TDX Date: Tue, 5 Nov 2024 01:24:00 -0500 Message-Id: <20241105062408.3533704-53-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789039948116600 Content-Type: text/plain; charset="utf-8" Expose mark_unavailable_features() out of cpu.c so that it can be used by TDX when features are masked off. Signed-off-by: Xiaoyao Li --- target/i386/cpu.c | 4 ++-- target/i386/cpu.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 8c507ad406e7..e728fb6b9f10 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5479,8 +5479,8 @@ static bool x86_cpu_have_filtered_features(X86CPU *cp= u) return false; } =20 -static void mark_unavailable_features(X86CPU *cpu, FeatureWord w, uint64_t= mask, - const char *verbose_prefix) +void mark_unavailable_features(X86CPU *cpu, FeatureWord w, uint64_t mask, + const char *verbose_prefix) { CPUX86State *env =3D &cpu->env; FeatureWordInfo *f =3D &feature_word_info[w]; diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 0cc88c470dfb..e70e7f5ced4b 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2444,6 +2444,8 @@ void cpu_set_apic_feature(CPUX86State *env); void host_cpuid(uint32_t function, uint32_t count, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx= ); bool cpu_has_x2apic_feature(CPUX86State *env); +void mark_unavailable_features(X86CPU *cpu, FeatureWord w, uint64_t mask, + const char *verbose_prefix); =20 static inline bool x86_has_cpuid_0x1f(X86CPU *cpu) { --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789633; cv=none; d=zohomail.com; s=zohoarc; b=jpoM5zJSckxneqNf/vsD7bAr5T4XwGHD/9S5oYaIdViASeQBjDjrgE5sn8CjFesFrtdrNe2cur8HeTgXgyKLqggOs4QeY6DpWY9d7NLlJM/J26Qx8EO/TTh47cKIH3YCe8TKH3tBMWPcwxaJx98g7K8FJmHmt0lm0EF1bhLmSdU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789633; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dNGE4Z9TVIG08KY/i69nTPe9NVQ9kAVZ92WIoh1h9P0=; b=KFz28NyZ3+l71N07d2rTRtV1t4RNKhxCgRHymuxvMYYJScMshWfGO9qOSgJkYmsreifKNTLyLiCGI8GvKEUz+xVH9V5BFqmCCfxzcD2I+ncLQLzNvwW7lShIyDkMT2I1tI0txcYT6e4UWspG5MpRrQuR9ZPfq1t6DdMWm8G+Pzc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 173078963380138.09687996834418; Mon, 4 Nov 2024 22:53:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DHK-0006hx-TG; Tue, 05 Nov 2024 01:43:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DEy-0003X1-Mc for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:40:45 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DEl-0001vd-3i for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:40:28 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:40:09 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:40:05 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788823; x=1762324823; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Cd6UQJeNLnYBe3u2FXzM6iswu2YcXGcY/0+XpTAWb5M=; b=HwK/YqSHttvDofiENIUswqt8RkZ09teQZ8gKtTDYCeuGvpreozuesbwG SW0MpAUA/s1ow5fRmCW5DvzLLOIIZp8v6xZ8H/Bo0OpHeJRMA4mrANKtc 9o3JFdJHy3c+W147Vvaa1DY2VHVDX3xUPswoyhBwbHoxv/+u4HQJnjXiD 4tShvjRpPppNzU1pXf9EHn7HZcCMp1PrLvfSiNFRDHmZ++HiW1gbyBvug C5IUOzoKdDPTK/H6SpP809EVC91e3xoKOGnACPuT20TH4uS3GPR16d9k/ Nj8EeOikz0D6KXRBrgGSbN9QQVuUXWnV+2BCXlepdBlo7bSdDMV8Bv3et g==; X-CSE-ConnectionGUID: yYQP5rIGRaeiwIxJjkonCA== X-CSE-MsgGUID: OwR2/IsQTGyR6dX3SV6i0w== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689896" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689896" X-CSE-ConnectionGUID: rHLLn7tpR9W0Ru67Q1UL8w== X-CSE-MsgGUID: ttu57Bs2RkOUlOsMPVmdKQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989941" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 53/60] i386/cpu: introduce mark_forced_on_features() Date: Tue, 5 Nov 2024 01:24:01 -0500 Message-Id: <20241105062408.3533704-54-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789635602116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Xiaoyao Li --- target/i386/cpu.c | 29 +++++++++++++++++++++++++++++ target/i386/cpu.h | 5 +++++ 2 files changed, 34 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index e728fb6b9f10..472ab206d8fe 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5507,6 +5507,35 @@ void mark_unavailable_features(X86CPU *cpu, FeatureW= ord w, uint64_t mask, } } =20 +void mark_forced_on_features(X86CPU *cpu, FeatureWord w, uint64_t mask, + const char *verbose_prefix) +{ + CPUX86State *env =3D &cpu->env; + FeatureWordInfo *f =3D &feature_word_info[w]; + int i; + + if (!cpu->force_features) { + env->features[w] |=3D mask; + } + + cpu->forced_on_features[w] |=3D mask; + + if (!verbose_prefix) { + return; + } + + for (i =3D 0; i < 64; ++i) { + if ((1ULL << i) & mask) { + g_autofree char *feat_word_str =3D feature_word_description(f,= i); + warn_report("%s: %s%s%s [bit %d]", + verbose_prefix, + feat_word_str, + f->feat_names[i] ? "." : "", + f->feat_names[i] ? f->feat_names[i] : "", i); + } + } +} + static void x86_cpuid_version_get_family(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index e70e7f5ced4b..b5b1c3917427 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2135,6 +2135,9 @@ struct ArchCPU { /* Features that were filtered out because of missing host capabilitie= s */ FeatureWordArray filtered_features; =20 + /* Features that are forced enabled by underlying hypervisor, e.g., TD= X */ + FeatureWordArray forced_on_features; + /* Enable PMU CPUID bits. This can't be enabled by default yet because * it doesn't have ABI stability guarantees, as it passes all PMU CPUID * bits returned by GET_SUPPORTED_CPUID (that depend on host CPU and k= ernel @@ -2446,6 +2449,8 @@ void host_cpuid(uint32_t function, uint32_t count, bool cpu_has_x2apic_feature(CPUX86State *env); void mark_unavailable_features(X86CPU *cpu, FeatureWord w, uint64_t mask, const char *verbose_prefix); +void mark_forced_on_features(X86CPU *cpu, FeatureWord w, uint64_t mask, + const char *verbose_prefix); =20 static inline bool x86_has_cpuid_0x1f(X86CPU *cpu) { --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789291; cv=none; d=zohomail.com; s=zohoarc; b=kps7rN1yuHy5GtajzcYK3EPgt8bjgrmpUmlpqF7zQZR67uWCvfaHRIT37+iwjfMoGYuVaea13DfkQ0iJfpoKchUoXemw0CGBYujH9o8WIMeIGzUB0FwI611qA9hBWDvkB/4V8qtYE8ZcniBML0lEwyL27vMYSZ/xByJvR5UzOWQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789291; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kuIY6+jJg8ZUDBdSlVCaYY1VZ2ZWcdB8wGr/uprURWs=; b=DueoSODAuc95z4YX5FJkKNUcbNLkGOyNejVJnhD+Y8Im8KruhfD1Ubz2iEAbdzAgPxCDO48C7uAVQ7smeHCsY6gbnKuzNtGhrpX7FVHTtY0VmDi7iKMAiBu8tGxrx4640kBZZ/cNWYHfrEZ2mAW3fqHS+e1jqKb9I0XO2KMHPho= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 173078929130175.37168404753675; Mon, 4 Nov 2024 22:48:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DGu-000558-RS; Tue, 05 Nov 2024 01:42:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DEw-0003X7-LE for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:40:44 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DEn-0001w0-OO for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:40:28 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:40:14 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:40:09 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788826; x=1762324826; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xs0CRmXKoLP85ntSNgfzBFyenj5am27Jk7rZikXTb+4=; b=U36pv/TlOWJa8NB1J4Kz6OzrBI39+xip/fh5irg7mzNU9Xf2yTPgPNdC Pvv8vQ1WCpbreRlMlmLo0hH1uxSbDnU5EcY80MZS/p5/v9SLg6TqhU6pf OnHiqxgkdUb4206yOqk0/iDgeXHQ96gsLxY5zrdAzU9v5ylBwtoaoP2wn fLG7HYhj7cr9IxpPO6WEK+99Md9kKyE8RTv/gVSyhtWlGhAaeJLHn2xQJ RKIvrUjyXIRX8NASFhTBV6FQkVuCrADImfECvD+UZHzoYig+moSxtqPTW fu1fPmV2/UWaxetUaXEdRrdu0OGkiIpI/eHGObY5eSfVLTuY70t7TW/Ty w==; X-CSE-ConnectionGUID: yiR6peEyTDC8SG4abNdtXw== X-CSE-MsgGUID: mmBd1LWWQOq+6gXqbiBbDw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689907" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689907" X-CSE-ConnectionGUID: +AXT2kK8SDWa5RYfBzoJxw== X-CSE-MsgGUID: xLmUcX+pSb2KsI+RjIq5Og== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83989984" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 54/60] i386/cgs: Introduce x86_confidential_guest_check_features() Date: Tue, 5 Nov 2024 01:24:02 -0500 Message-Id: <20241105062408.3533704-55-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789293165116600 Content-Type: text/plain; charset="utf-8" To do cgs specific feature checking. Note the feature checking in x86_cpu_filter_features() is valid for non-cgs VMs. For cgs VMs like TDX, what features can be supported has more restrictions. Signed-off-by: Xiaoyao Li --- target/i386/confidential-guest.h | 13 +++++++++++++ target/i386/kvm/kvm.c | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/target/i386/confidential-guest.h b/target/i386/confidential-gu= est.h index 2dde29889c23..3018f38e18bf 100644 --- a/target/i386/confidential-guest.h +++ b/target/i386/confidential-guest.h @@ -43,6 +43,7 @@ struct X86ConfidentialGuestClass { void (*cpu_realizefn)(X86ConfidentialGuest *cg, CPUState *cpu, Error *= *errp); uint32_t (*adjust_cpuid_features)(X86ConfidentialGuest *cg, uint32_t f= eature, uint32_t index, int reg, uint32_t va= lue); + int (*check_features)(X86ConfidentialGuest *cg, CPUState *cs); }; =20 /** @@ -103,4 +104,16 @@ static inline int x86_confidential_guest_adjust_cpuid_= features(X86ConfidentialGu } } =20 +static inline int x86_confidential_guest_check_features(X86ConfidentialGue= st *cg, + CPUState *cs) +{ + X86ConfidentialGuestClass *klass =3D X86_CONFIDENTIAL_GUEST_GET_CLASS(= cg); + + if (klass->check_features) { + return klass->check_features(cg, cs); + } + + return 0; +} + #endif diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index f067961fba43..42dc5b78faf0 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -2086,6 +2086,14 @@ int kvm_arch_init_vcpu(CPUState *cs) int r; Error *local_err =3D NULL; =20 + if (current_machine->cgs) { + r =3D x86_confidential_guest_check_features( + X86_CONFIDENTIAL_GUEST(current_machine->cgs), cs); + if (r < 0) { + return r; + } + } + memset(&cpuid_data, 0, sizeof(cpuid_data)); =20 cpuid_i =3D 0; --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789300; cv=none; d=zohomail.com; s=zohoarc; b=HVz9zj/LdQ5uEOtx4mfkFI06R52KUNrD5IgkDXfU9kn/h5dVONzfSa/t8AQKd/4G17ot70xxhcfWbeRDyVasN1vtPEkBb/p0odbZr3Wzzyn3edrlT4towZpJ7Z/CeygvtXXV++LlJG52pnB2tPny4WreV9lQPleLuliqcScE85Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789300; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rcVx+IWxwXuwDOaJ92dKTKREE9riC7H6Rrd1CJzoJDE=; b=Zew8NZJC0BNsP+pKanEfVFKFHsFMPV1I0BofZcNaiIFMGJW0eGd5NXpxArSx9p3t4vEak1lCUH12iU+syK/eE7tkvM3EiW+z/41PiG6g1IFcKRrf/3W1ypiA9edlIOugM5ZUgDTVDhjfFXBxZ98WDf/sBZppB3UFw1Lg2gAQyFw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789300279112.32842451532315; Mon, 4 Nov 2024 22:48:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DHE-0006X3-92; Tue, 05 Nov 2024 01:42:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DF6-0003Xb-Vn for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:40:50 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DF2-0001vd-FF for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:40:43 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:40:18 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:40:14 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788840; x=1762324840; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R3qGJveZ2fmuHjYuT93ENGzexAuyNwuq1EZaJ0+cqc0=; b=V2xxfs4KNBt4H4q0DTX+Xu8OKd1kmXgIfF0s5a27QWiJZNP4fm0iTrql u9RbcRpjKmYh+NjrbTzo7Dj3T4UrXxwjLGNGfbqtRHNDrfGcrnwYQMQEa ea8RnIr28gjGPRMhlWmh3HhrvAwjbzkayR8/A9ZTxTj2UNXzqaV8JLw+I vRTlZuwWueCota1pSWvXNRFFx7T1IUQyUvyGKShry8ki51Fl9HSK6nsf7 zPsx4vUUpXA28S6TVKwxVpu+R/VFePyVIYTNDd3uZWhI8x1TVMYkm88Ze bXvnCL12rc/nj4eZBb5ThzHNhm+BZb9sNAJFd7N30537++UdqA3tnh9pv A==; X-CSE-ConnectionGUID: B9a/kTtuSYWSRguMoZGYVA== X-CSE-MsgGUID: ySkMU0xyS4WIdddt8Ewd/w== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689917" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689917" X-CSE-ConnectionGUID: cCHE70fzS4uPY/tjfHAGjA== X-CSE-MsgGUID: 4cVcz/YWTguoW1CHzdYfFA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83990026" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 55/60] i386/tdx: Fetch and validate CPUID of TD guest Date: Tue, 5 Nov 2024 01:24:03 -0500 Message-Id: <20241105062408.3533704-56-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789301291116600 Content-Type: text/plain; charset="utf-8" Use KVM_TDX_GET_CPUID to get the CPUIDs that are managed and enfored by TDX module for TD guest. Check QEMU's configuration against the fetched data. Print wanring message when 1. a feature is not supported but requested by QEMU or 2. QEMU doesn't want to expose a feature while it is enforced enabled. - If cpu->enforced_cpuid is not set, prints the warning message of both 1) and 2) and tweak QEMU's configuration. - If cpu->enforced_cpuid is set, quit if any case of 1) or 2). Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 81 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index e7e0f073dfc9..9cb099e160e4 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -673,6 +673,86 @@ static uint32_t tdx_adjust_cpuid_features(X86Confident= ialGuest *cg, return value; } =20 + +static void tdx_fetch_cpuid(CPUState *cpu, struct kvm_cpuid2 *fetch_cpuid) +{ + int r; + + r =3D tdx_vcpu_ioctl(cpu, KVM_TDX_GET_CPUID, 0, fetch_cpuid); + if (r) { + error_report("KVM_TDX_GET_CPUID failed %s", strerror(-r)); + exit(1); + } +} + +static int tdx_check_features(X86ConfidentialGuest *cg, CPUState *cs) +{ + uint64_t actual, requested, unavailable, forced_on; + g_autofree struct kvm_cpuid2 *fetch_cpuid; + const char *forced_on_prefix =3D NULL; + const char *unav_prefix =3D NULL; + struct kvm_cpuid_entry2 *entry; + X86CPU *cpu =3D X86_CPU(cs); + CPUX86State *env =3D &cpu->env; + FeatureWordInfo *wi; + FeatureWord w; + bool mismatch =3D false; + + fetch_cpuid =3D g_malloc0(sizeof(*fetch_cpuid) + + sizeof(struct kvm_cpuid_entry2) * KVM_MAX_CPUID_ENTRIE= S); + tdx_fetch_cpuid(cs, fetch_cpuid); + + if (cpu->check_cpuid || cpu->enforce_cpuid) { + unav_prefix =3D "TDX doesn't support requested feature"; + forced_on_prefix =3D "TDX forcibly sets the feature"; + } + + for (w =3D 0; w < FEATURE_WORDS; w++) { + wi =3D &feature_word_info[w]; + actual =3D 0; + + switch (wi->type) { + case CPUID_FEATURE_WORD: + entry =3D cpuid_find_entry(fetch_cpuid, wi->cpuid.eax, wi->cpu= id.ecx); + if (!entry) { + /* + * If KVM doesn't report it means it's totally configurable + * by QEMU + */ + continue; + } + + actual =3D cpuid_entry_get_reg(entry, wi->cpuid.reg); + break; + case MSR_FEATURE_WORD: + /* + * TODO: + * validate MSR features when KVM has interface report them. + */ + continue; + } + + requested =3D env->features[w]; + unavailable =3D requested & ~actual; + mark_unavailable_features(cpu, w, unavailable, unav_prefix); + if (unavailable) { + mismatch =3D true; + } + + forced_on =3D actual & ~requested; + mark_forced_on_features(cpu, w, forced_on, forced_on_prefix); + if (forced_on) { + mismatch =3D true; + } + } + + if (cpu->enforce_cpuid && mismatch) { + return -1; + } + + return 0; +} + static int tdx_validate_attributes(TdxGuest *tdx, Error **errp) { if ((tdx->attributes & ~tdx_caps->supported_attrs)) { @@ -1019,4 +1099,5 @@ static void tdx_guest_class_init(ObjectClass *oc, voi= d *data) x86_klass->cpu_instance_init =3D tdx_cpu_instance_init; x86_klass->cpu_realizefn =3D tdx_cpu_realizefn; x86_klass->adjust_cpuid_features =3D tdx_adjust_cpuid_features; + x86_klass->check_features =3D tdx_check_features; } --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789328; cv=none; d=zohomail.com; s=zohoarc; b=U2yay9mLE/fRw0ACLD5tZ4/MorJUak9/p9IHgvtOqrS0SvPfaqo54I8Qo8FVcS12kRLZzym54yp9XuEdUu/XpgmK65X7KH1qNQJqr14JM6DPx5A3OWcGmQuPlosDwQwMp6pKKvceaevN3U4X1UIDoBlvjsBWXoyhyt/4OAwSZwM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789328; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UK148G/fB83FOeBRXwqMaCQvsW9Wt7dqO1omXPaVZoU=; b=nZKnV6YQhZej2rC7ln0Hq+edA+rpgwEYEv8lFoKP6dKKEKOMfh1lldByz1rHxHeCDLddVF140cjoVl3IcnLDwWamKag5yfyWKBeB8ZWCMPeZIwZ6DoJl87p2K7tW6TyoNT8kr77VGehEk9ykg+XpkrmdO0WdintkfbjMZFPz+G4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789328127881.1258685826718; Mon, 4 Nov 2024 22:48:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DH4-0005qd-Bo; Tue, 05 Nov 2024 01:42:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DF7-0003YJ-O8 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:40:50 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DF2-0001w0-LT for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:40:42 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:40:22 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:40:18 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788841; x=1762324841; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=N6wZGF3LbJuiZwh2h+P0qnuOeIsvhZtITe8MucmhR3Y=; b=nmGdyajjcbvXf2DHxxT5vhBvTC0dNIdQNyMfr+CGIfFrLVFqQuirYIpa dSb3YP6gnNHXrt0V9cs+TqIutSdyiiqiIv3yqGoSBYPogY0sTPvdwICE4 F6ed5P6WCD6LgWxq2AL4xoLcWAJdPmCo2ZEvSwjGsdC//6Y0C88PUneGY +s21W+modJNnyvf2XVv3N51+9DzGurjjss+8o+KK2t2Um0QS45VJgqGn3 WtfX0BnDaKymFySJYHyZhzPbKm4bnW4T4XN3z2SqLtJW6Ys0TaIa+Kfr/ gKgbeGtTpPi776o2SfbHlPjRcdTgj/2S3BbRnQ5xUBb4zVnxN8flLFnaI w==; X-CSE-ConnectionGUID: OoOeTxGXSoufjx13YronRQ== X-CSE-MsgGUID: M/3V27CaSpGbME/RQYhsqw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689925" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689925" X-CSE-ConnectionGUID: cui/g9wYSTW/R2q/F+xxag== X-CSE-MsgGUID: BO/sHFRmRSK/ivSD8JW1yA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83990064" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 56/60] i386/tdx: Don't treat SYSCALL as unavailable Date: Tue, 5 Nov 2024 01:24:04 -0500 Message-Id: <20241105062408.3533704-57-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789329268116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 9cb099e160e4..05475edf72bd 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -734,6 +734,13 @@ static int tdx_check_features(X86ConfidentialGuest *cg= , CPUState *cs) =20 requested =3D env->features[w]; unavailable =3D requested & ~actual; + /* + * Intel enumerates SYSCALL bit as 1 only when processor in 64-bit + * mode and before vcpu running it's not in 64-bit mode. + */ + if (w =3D=3D FEAT_8000_0001_EDX && unavailable & CPUID_EXT2_SYSCAL= L) { + unavailable &=3D ~CPUID_EXT2_SYSCALL; + } mark_unavailable_features(cpu, w, unavailable, unav_prefix); if (unavailable) { mismatch =3D true; --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789332; cv=none; d=zohomail.com; s=zohoarc; b=cpKhiC//fDxyevKrwB3fHgICeJEMGuf8O8FZ+bOr9Vi6zFnKCpiJJVV4POZAjyWr/DGW0uMRpEK2vxYW4N2nm6+/DDYZhoqrhPLnTo/R0qmAoAv/VGv28t3sQI9cx8YyMvk49s7wrNG2DgLO+veRmj7HMWRe9tb+RdgikSuACXQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789332; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Zc5Gt8PZl8uZIK3Y0YEgwsTIf/ghJYfI+XbFOY8a1Fs=; b=GM7K3MhMWdk4tU5Aqo1FgicyVkSlZGjlGZasS4j1DizCJPrM53grJ1wZdfWiS0U4/DTP/tzCAs+j+JXKJvsIFpc5dtWn6auj8HFUPG+LRm42wRkDnuFchuiPe/sQJUOC1Io6STT7DqGUIwJ12wb6coN3akgkKOEDtNqSWFCTEXs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789332276285.72006179245136; Mon, 4 Nov 2024 22:48:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DHE-0006X4-8M; Tue, 05 Nov 2024 01:42:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DF7-0003YW-Vc for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:40:51 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DF3-0001vj-HP for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:40:44 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:40:26 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:40:22 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788842; x=1762324842; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NKlDvzzDpP7N59sc27fzM1CZSPqI8zTcm+9UeKAwP8w=; b=QHNbqLuucstjHcOy9UV3xOmCHuLTv2HR54BYmBJ15nyrFQGfxsmlTnKr 0MdozpaIJFm3u8bmp094ac0ePm8eYXdsmjxNPpzz/yh2W8hZv4go3NvcT YOMcpBIyB3qGH2W4e1DHbA78E9lU0uMTUr+CpNXXhjRRaOanVncsZUipd ztk0gH+aldGW+0JRGif3VNEr+2C4qXIvnBBpono6zwCb9Q5o7dm/LPEmX SBeBdvzWa1yWakWSbIdNBbO+hRmRoqBe+NKILxIgz8mqECcTYkFQxcrmU 299jNcd/qXN9h1mjflFnTRV3REfLYkYfD/PQUDfZxY2W9CK16gzZd/3A1 Q==; X-CSE-ConnectionGUID: mIuGk7wWQPy6T81yX22kLQ== X-CSE-MsgGUID: 2eUyQLRiTmehAmyapHM+Pg== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689936" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689936" X-CSE-ConnectionGUID: fMooDLw8TVGkCNYMWGss5g== X-CSE-MsgGUID: Is1f+4fSQ9Kp08bHbbfQaw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83990085" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 57/60] i386/tdx: Make invtsc default on Date: Tue, 5 Nov 2024 01:24:05 -0500 Message-Id: <20241105062408.3533704-58-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789333307116600 Content-Type: text/plain; charset="utf-8" Because it's fixed1 bit that enforced by TDX module. Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 05475edf72bd..4cb1f4ac3479 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -430,6 +430,9 @@ static void tdx_cpu_instance_init(X86ConfidentialGuest = *cg, CPUState *cpu) =20 object_property_set_bool(OBJECT(cpu), "pmu", false, &error_abort); =20 + /* invtsc is fixed1 for TD guest */ + object_property_set_bool(OBJECT(cpu), "invtsc", true, &error_abort); + x86cpu->enable_cpuid_0x1f =3D true; } =20 --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789457; cv=none; d=zohomail.com; s=zohoarc; b=RrBb2xpK6B884YNmO8OYDDOP+tL8GTdeNjyBcS+pwDc+vAS1iU4u88aDTLBc7Nd9yBbAyFuFLJwQk5FsDssExtVLY4p1i0blPvI1IT+tgIgJL6MVn6J4+Sacw9hOENrUpgq74jrAWVaPCDWxaapBWnqlgHa20tsh/Z62D2w3t6A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789457; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rbrS6TwXhfASOLnXF2BON59nFFKGzTEg0x8WZRkV51A=; b=ZReCOcUqcBEs1yyOCcgbl1o+65ZBOe1MwVFe15lMGRNYtfFeIJWg1ggzfnQIuMyieteFDF9vxYFJsPr83+aeR2BM2qNsLfNBz8hQKbkXbRsCrUCgmxfAC/8KYfOy6pyX2MqCRQMTj0tmCbus6YSnXdbHeCFtn7U+sC9Z+87ufSU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789457853924.0525789647106; Mon, 4 Nov 2024 22:50:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DHc-00075b-53; Tue, 05 Nov 2024 01:43:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DFq-0003v8-Mb for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:41:31 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DFF-0001vd-Nc for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:41:03 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:40:31 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:40:26 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788854; x=1762324854; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Pfq6Mcq11nNik95S/q8D/VnbY9hYdtshEgdTuCa1i80=; b=QChRkxRZwNrq8GCwW26Ax5FxR1z34sxbilHz0/rblbNLqD+By90An9Pl CtQxhE7c1F8PxoRRD8nQ2eQ9qCYWrrtoueOFPr8T/2ZbfsOt2vst3Srrs ibSO2Vt5/F1uL/NaKTMzdQi3l+78k78UI3kjGy1st9Ji8mG3xq09y2AIA BFd1NPB9WGcXpXhXc1ewQJ2NPg2VboUgmA3ooxydO7vavZ9Wl/N5AENV8 aa8wNccZMhSJstqLPJWVSMVNYAQlHldw3p08JFp9i8sYRuIHMYTmZM7v3 wcmDMoSu9pw5WaKN0zQP0hCUnXjGAqpa9An9kIbW+q4DWPyNbxUKs4Qtm Q==; X-CSE-ConnectionGUID: Hggi8ScXS+KUluoimmC5og== X-CSE-MsgGUID: 0H4ma58zSvG3z3sB1gKUHg== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689951" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689951" X-CSE-ConnectionGUID: 1JcGSuUsQHiwhLm+UNgIxA== X-CSE-MsgGUID: 7h2gpC2BS6GDQQ3w3SMvwg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83990113" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 58/60] cpu: Introduce qemu_early_init_vcpu() Date: Tue, 5 Nov 2024 01:24:06 -0500 Message-Id: <20241105062408.3533704-59-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789458155116600 Content-Type: text/plain; charset="utf-8" Currently cpu->nr_cores and cpu->nr_threads are initialized in qemu_init_vcpu(), which is called a bit late in *cpu_realizefn() for each ARCHes. x86 arch would like to set CPUID_HT in env->features[FEAT_1_EDX] based on the value of cpu->nr_threads * cpu->nr_cores. It requires nr_cores and nr_threads being initialized earlier. Introdue qemu_early_init_vcpu() for this purpose. Signed-off-by: Xiaoyao Li --- accel/tcg/user-exec-stub.c | 4 ++++ include/hw/core/cpu.h | 8 ++++++++ system/cpus.c | 8 ++++++++ 3 files changed, 20 insertions(+) diff --git a/accel/tcg/user-exec-stub.c b/accel/tcg/user-exec-stub.c index 4fbe2dbdc883..64baf917b55c 100644 --- a/accel/tcg/user-exec-stub.c +++ b/accel/tcg/user-exec-stub.c @@ -10,6 +10,10 @@ void cpu_remove_sync(CPUState *cpu) { } =20 +void qemu_early_init_vcpu(CPUState *cpu) +{ +} + void qemu_init_vcpu(CPUState *cpu) { } diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index c3ca0babcb3f..854b244e1ad6 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -1063,6 +1063,14 @@ void start_exclusive(void); */ void end_exclusive(void); =20 +/** + * qemu_early_init_vcpu: + * @cpu: The vCPU to initialize. + * + * Early initializes a vCPU. + */ +void qemu_early_init_vcpu(CPUState *cpu); + /** * qemu_init_vcpu: * @cpu: The vCPU to initialize. diff --git a/system/cpus.c b/system/cpus.c index 1c818ff6828c..98cb8aafa50b 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -662,6 +662,14 @@ const AccelOpsClass *cpus_get_accel(void) return cpus_accel; } =20 +void qemu_early_init_vcpu(CPUState *cpu) +{ + MachineState *ms =3D MACHINE(qdev_get_machine()); + + cpu->nr_cores =3D machine_topo_get_cores_per_socket(ms); + cpu->nr_threads =3D ms->smp.threads; +} + void qemu_init_vcpu(CPUState *cpu) { MachineState *ms =3D MACHINE(qdev_get_machine()); --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789271; cv=none; d=zohomail.com; s=zohoarc; b=j4y8Yj0BHIUGdh8nlxk2sbd9mqZO08x7ElQnwv1E1C9dHdqfsjQIIuGwi08SYcdlaorjYEyVYtsJnXDO2rDduVVlaNv/QmdEB4pfpLpwWD6DewDwbC1CXCo8rGyBmYeFirD2WDwYZsWAJpwgr0UQhsAN/9WLpyTiyW290g5G7pU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789271; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=qXLULKqOe0XigTMZ+AZ1By+RIykUDM15Og72JEJkKLE=; b=Lmsf0s16DEERN2bPGGp651uMxAU6xJngXBxqoe445iL2MHymT6T8M1ErHsbySL1RU/u/LsrEZPTiBC1gmBaaqZsHLNIGWGd5FbClnfMHVpP3aLTaNZhdCzaT1O+4T4breVUU+o0QDksTVAt6g7oePtbpElxpnJ6xAqCahuqVZFM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789271462275.7145546218511; Mon, 4 Nov 2024 22:47:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DHb-00074z-TH; Tue, 05 Nov 2024 01:43:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DFp-0003v2-U2 for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:41:30 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DFF-0001w0-SW for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:41:04 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:40:35 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:40:31 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788854; x=1762324854; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oRT7vJ7+68FbrD5uefrUrGWOgNBDYndBP8Hc2+4+qeY=; b=NjvEAs3z5z2fc8EH6OyXRJXmX16kUQ/95AxdBxzAWzcX3GnK1rGXETvL Uv8rd1iLYU8xjntdBBoG+WrmaUZ6jpCShF9PjtxkVMGQt7TRwUpfe/uAp fFAHgpCgZUw4/6SQwF+ErFK5I7igXEH0uuIdX1XbN+Ohw4UjRrrP6QPEy pnasymMO33gxBPETh2HebwK6jgT1B8b7DvyMJTkWomBt3r2IXY1pm7ps8 ZjUUR8SrOYPY5teP3B56XiqTyd8zIGtx9GjBc5lsCwJnnahpjmMjJnlLb 9kbQJdnuz05qevxLspmwh4VsbullYwECrgclMoSNswAJqcLl/fxV5X/VW A==; X-CSE-ConnectionGUID: DuXghf5NRx29dZRSz3N2Fg== X-CSE-MsgGUID: C/i+O22ySwKhY7CqBhTzcA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689962" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689962" X-CSE-ConnectionGUID: LzAzyvrmS+yTZ8bmyu8w1Q== X-CSE-MsgGUID: 2ERfMEY6TBCvNuxBGJjdvw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83990148" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 59/60] i386/cpu: Set up CPUID_HT in x86_cpu_realizefn() instead of cpu_x86_cpuid() Date: Tue, 5 Nov 2024 01:24:07 -0500 Message-Id: <20241105062408.3533704-60-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789273149116600 Content-Type: text/plain; charset="utf-8" Otherwise, it gets warnings like below when number of vcpus > 1: warning: TDX enforces set the feature: CPUID.01H:EDX.ht [bit 28] This is because x86_confidential_guest_check_features() checks env->features[] instead of the cpuid date set up by cpu_x86_cpuid() Signed-off-by: Xiaoyao Li --- target/i386/cpu.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 472ab206d8fe..214a1b00a815 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6571,7 +6571,6 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, *edx =3D env->features[FEAT_1_EDX]; if (threads_per_pkg > 1) { *ebx |=3D threads_per_pkg << 16; - *edx |=3D CPUID_HT; } if (!cpu->enable_pmu) { *ecx &=3D ~CPUID_EXT_PDCM; @@ -7784,6 +7783,8 @@ static void x86_cpu_realizefn(DeviceState *dev, Error= **errp) Error *local_err =3D NULL; unsigned requested_lbr_fmt; =20 + qemu_early_init_vcpu(cs); + #if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY) /* Use pc-relative instructions in system-mode */ tcg_cflags_set(cs, CF_PCREL); @@ -7851,6 +7852,14 @@ static void x86_cpu_realizefn(DeviceState *dev, Erro= r **errp) } } =20 + /* + * It needs to called after feature filter because KVM doesn't report = HT + * as supported + */ + if (cs->nr_cores * cs->nr_threads > 1) { + env->features[FEAT_1_EDX] |=3D CPUID_HT; + } + /* On AMD CPUs, some CPUID[8000_0001].EDX bits must match the bits on * CPUID[1].EDX. */ --=20 2.34.1 From nobody Sat Nov 23 20:43:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1730789321; cv=none; d=zohomail.com; s=zohoarc; b=QrG1ko54uhUWRMCCAeBsQa0RLrdR7Eu/6a2Vw5qH2U/HWWMALrS+WyiftDmOi9fKmnrTOwQyLmQpofO4ntgvQ7Snd3VZyNi8tJ1C8IDXW2ueDenhzckbulmTOTDzyvH9RB6xjb7TkrLABz1DIiG9zQliND4q6bTGmBxC83t9M8c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730789321; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5yFJLtGBPvnTjF96UO08oJ65YdJNVL02r+HSn7WsOAI=; b=EZuM/Dduq88tlJq0ryjoFSKcmJ8Gg9muRorgYovNz9m8LkWBDqu2FldqZVCWdh6daPQiDg8i/vOGp3rYVgbjUJzNEzlkjmEtMCn50cxHzPUS8KG3FUXr8/NnVWtG0aRVSge7YTlhWdZUy+vjuQX1ee9dkgE9l/MmVwkid7A0c30= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730789321223649.862899507172; Mon, 4 Nov 2024 22:48:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8DHK-0006hy-T9; Tue, 05 Nov 2024 01:43:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DFs-0003vI-8P for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:41:32 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8DFG-0001vj-Pq for qemu-devel@nongnu.org; Tue, 05 Nov 2024 01:41:05 -0500 Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 22:40:39 -0800 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa009.fm.intel.com with ESMTP; 04 Nov 2024 22:40:35 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730788855; x=1762324855; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=prNelkC3OOqKiNVm+vMpEf1u/DtP+lyJhK2V/YRgjzw=; b=Ak1d0aKZXlTgypm4kR0Opy8p+rbc1xZ7r6JUobhQTQzc77u4WSRRv2RB d+ZW455y32Vqjzi/cNsFzZRM3UeJgJlu6Y7KrMnigj/Ufc4EVc4huI0EE y04F8cnq/kHTyo2N1tRTpNGf4A5E6r/HpUizpxUKXTvi3pbTzBwBK8YTu ivqItQ0LCR8a+8Twl/LFfV12Q7nIuIk3h3Gj/JqPhbXiPjucfa5G7Gve5 HU2p2Y8I5KiqvV5VY+j8RV02nCSUxf+NzBS5dxOG61fDTg4rkvVzwlij5 eBBQEru03KePVmjk+0rSwzAH60rcot079iBSDCXNIqffjIPSaO0jxYNvU g==; X-CSE-ConnectionGUID: DPFZyhcfQ0CrxUNlTqPJeg== X-CSE-MsgGUID: X164P7OXTJ6R+YSw8iQTQQ== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30689973" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30689973" X-CSE-ConnectionGUID: WC4TK0djRPSDZtiizpWwBg== X-CSE-MsgGUID: +YDffLFqRz2Vf56nozSFLA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="83990158" From: Xiaoyao Li To: Paolo Bonzini , Riku Voipio , Richard Henderson , Zhao Liu , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti , rick.p.edgecombe@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, xiaoyao.li@intel.com Subject: [PATCH v6 60/60] docs: Add TDX documentation Date: Tue, 5 Nov 2024 01:24:08 -0500 Message-Id: <20241105062408.3533704-61-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105062408.3533704-1-xiaoyao.li@intel.com> References: <20241105062408.3533704-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.18; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.781, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1730789323460116600 Content-Type: text/plain; charset="utf-8" Add docs/system/i386/tdx.rst for TDX support, and add tdx in confidential-guest-support.rst Signed-off-by: Xiaoyao Li --- Changes in v6: - Add more information of "Feature configuration" - Mark TD Attestation as future work because KVM now drops the support of it. Changes in v5: - Add TD attestation section and update the QEMU parameter; Changes since v1: - Add prerequisite of private gmem; - update example command to launch TD; Changes since RFC v4: - add the restriction that kernel-irqchip must be split --- docs/system/confidential-guest-support.rst | 1 + docs/system/i386/tdx.rst | 155 +++++++++++++++++++++ docs/system/target-i386.rst | 1 + 3 files changed, 157 insertions(+) create mode 100644 docs/system/i386/tdx.rst diff --git a/docs/system/confidential-guest-support.rst b/docs/system/confi= dential-guest-support.rst index 0c490dbda2b7..66129fbab64c 100644 --- a/docs/system/confidential-guest-support.rst +++ b/docs/system/confidential-guest-support.rst @@ -38,6 +38,7 @@ Supported mechanisms Currently supported confidential guest mechanisms are: =20 * AMD Secure Encrypted Virtualization (SEV) (see :doc:`i386/amd-memory-enc= ryption`) +* Intel Trust Domain Extension (TDX) (see :doc:`i386/tdx`) * POWER Protected Execution Facility (PEF) (see :ref:`power-papr-protected= -execution-facility-pef`) * s390x Protected Virtualization (PV) (see :doc:`s390x/protvirt`) =20 diff --git a/docs/system/i386/tdx.rst b/docs/system/i386/tdx.rst new file mode 100644 index 000000000000..60106b29bf72 --- /dev/null +++ b/docs/system/i386/tdx.rst @@ -0,0 +1,155 @@ +Intel Trusted Domain eXtension (TDX) +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Intel Trusted Domain eXtensions (TDX) refers to an Intel technology that e= xtends +Virtual Machine Extensions (VMX) and Multi-Key Total Memory Encryption (MK= TME) +with a new kind of virtual machine guest called a Trust Domain (TD). A TD = runs +in a CPU mode that is designed to protect the confidentiality of its memory +contents and its CPU state from any other software, including the hosting +Virtual Machine Monitor (VMM), unless explicitly shared by the TD itself. + +Prerequisites +------------- + +To run TD, the physical machine needs to have TDX module loaded and initia= lized +while KVM hypervisor has TDX support and has TDX enabled. If those require= ments +are met, the ``KVM_CAP_VM_TYPES`` will report the support of ``KVM_X86_TDX= _VM``. + +Trust Domain Virtual Firmware (TDVF) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Trust Domain Virtual Firmware (TDVF) is required to provide TD services to= boot +TD Guest OS. TDVF needs to be copied to guest private memory and measured = before +the TD boots. + +KVM vcpu ioctl ``KVM_TDX_INIT_MEM_REGION`` can be used to populates the TD= VF +content into its private memory. + +Since TDX doesn't support readonly memslot, TDVF cannot be mapped as pflash +device and it actually works as RAM. "-bios" option is chosen to load TDVF. + +OVMF is the opensource firmware that implements the TDVF support. Thus the +command line to specify and load TDVF is ``-bios OVMF.fd`` + +Feature Configuration +--------------------- + +Unlike non-TDX VM, the CPU features (enumerated by CPU or MSR) of a TD is = not +under full control of VMM. VMM can only configure part of features of a TD= on +``KVM_TDX_INIT_VM`` command of VM scope ``MEMORY_ENCRYPT_OP`` ioctl. + +The configurable features have three types: + +- Attributes: + - PKS (bit 30) controls whether Supervisor Protection Keys is exposed to= TD, + which determines related CPUID bit and CR4 bit; + - PERFMON (bit 63) controls whether PMU is exposed to TD. + +- XSAVE related features (XFAM): + XFAM is a 64b mask, which has the same format as XCR0 or IA32_XSS MSR. It + determines the set of extended features available for use by the guest T= D. + +- CPUID features: + Only some bits of some CPUID leaves are directly configurable by VMM. + +What features can be configured is reported via TDX capabilities. + +TDX capabilities +~~~~~~~~~~~~~~~~ + +The VM scope ``MEMORY_ENCRYPT_OP`` ioctl provides command ``KVM_TDX_CAPABI= LITIES`` +to get the TDX capabilities from KVM. It returns a data structure of +``struct kvm_tdx_capabilities``, which tells the supported configuration of +attributes, XFAM and CPUIDs. + +TD attributes +~~~~~~~~~~~~~ + +QEMU supports configuring raw 64-bit TD attributes directly via "attribute= s" +property of "tdx-guest" object. Note, it's users' responsibility to provid= e a +valid value because some bits may not supported by current QEMU or KVM yet. + +QEMU also supports the configuration of individual attribute bits that are +supported by it, via propertyies of "tdx-guest" object. +E.g., "sept-ve-disable" (bit 63). + +MSR based features +~~~~~~~~~~~~~~~~ + +Current KVM doesn't support MSR based feature (e.g., MSR_IA32_ARCH_CAPABIL= ITIES) +configuration for TDX, and it's a future work to enable it in QEMU when KV= M adds +support of it. + +Feature check +~~~~~~~~~~~~~ + +QEMU checks if the final (CPU) features, determined by given cpu model and +explicit feature adjustment of "+featureA/-featureB", can be supported or = not. +It can produce feature not supported warnning like + + "warning: host doesn't support requested feature: CPUID.07H:EBX.intel-pt= [bit 25]" + +It will also procude warning like + + "warning: TDX forcibly sets the feature: CPUID.80000007H:EDX.invtsc [bit= 8]" + +if the fixed-1 feature is requested to be disabled explicitly. This is new= ly +added to QEMU for TDX because TDX has fixed-1 features that are enfored en= abled +by TDX module and VMM cannot disable them. + +Launching a TD (TDX VM) +----------------------- + +To launch a TDX guest, below are new added and required: + +.. parsed-literal:: + + |qemu_system_x86| \\ + -object tdx-guest,id=3Dtdx0 \\ + -machine ...,kernel-irqchip=3Dsplit,confidential-guest-support=3Dt= dx0 \\ + -bios OVMF.fd \\ + +restrictions +------------ + + - kernel-irqchip must be split; + + - No readonly support for private memory; + + - No SMM support: SMM support requires manipulating the guset register st= ates + which is not allowed; + +Debugging +--------- + +Bit 0 of TD attributes, is DEBUG bit, which decides if the TD runs in off-= TD +debug mode. When in off-TD debug mode, TD's VCPU state and private memory = are +accessible via given SEAMCALLs. This requires KVM to expose APIs to invoke= those +SEAMCALLs and resonponding QEMU change. + +It's targeted as future work. + +TD attestation +-------------- + +In TD guest, the attestation process is used to verify the TDX guest +trustworthiness to other entities before provisioning secrets to the guest. + +TD attestation is initiated first by calling TDG.MR.REPORT inside TD to ge= t the +REPORT. Then the REPORT data needs to be converted into a remotely verifia= ble +Quote by SGX Quoting Enclave (QE). + +It's a future work in QEMU to add support of TD attestation since it lacks +support in current KVM. + +Live Migration +-------------- + +Future work. + +References +---------- + +- `TDX Homepage `__ + +- `SGX QE `__ diff --git a/docs/system/target-i386.rst b/docs/system/target-i386.rst index ab7af1a75d6e..43b09c79d6be 100644 --- a/docs/system/target-i386.rst +++ b/docs/system/target-i386.rst @@ -31,6 +31,7 @@ Architectural features i386/kvm-pv i386/sgx i386/amd-memory-encryption + i386/tdx =20 OS requirements ~~~~~~~~~~~~~~~ --=20 2.34.1