From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Xiaoyao Li <xiaoyao.li@intel.com>
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Riku Voipio" <riku.voipio@iki.fi>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Zhao Liu" <zhao1.liu@intel.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Igor Mammedov" <imammedo@redhat.com>,
"Ani Sinha" <anisinha@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Yanan Wang" <wangyanan55@huawei.com>,
"Cornelia Huck" <cohuck@redhat.com>,
"Eric Blake" <eblake@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Marcelo Tosatti" <mtosatti@redhat.com>,
rick.p.edgecombe@intel.com, kvm@vger.kernel.org,
qemu-devel@nongnu.org
Subject: Re: [PATCH v6 18/60] i386/tdvf: Introduce function to parse TDVF metadata
Date: Tue, 5 Nov 2024 10:42:47 +0000 [thread overview]
Message-ID: <Zyn2p9wD2SnisXhT@redhat.com> (raw)
In-Reply-To: <20241105062408.3533704-19-xiaoyao.li@intel.com>
On Tue, Nov 05, 2024 at 01:23:26AM -0500, Xiaoyao Li wrote:
> From: Isaku Yamahata <isaku.yamahata@intel.com>
>
> 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 <isaku.yamahata@intel.com>
> Co-developed-by: Xiaoyao Li <xiaoyao.li@intel.com>
> Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
> Acked-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
> 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
>
> config TDX
> bool
> + select X86_FW_OVMF
> depends on KVM
>
> 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-stubs.c'))
> +i386_ss.add(when: 'CONFIG_TDX', if_true: files('tdvf.c'))
>
> 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
Since you have this SPDX tag....
> +
> + * Copyright (c) 2020 Intel Corporation
> + * Author: Isaku Yamahata <isaku.yamahata at gmail.com>
> + * <isaku.yamahata at intel.com>
> + *
> + * 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 <http://www.gnu.org/licenses/>.
...you should omit the GPL boilerplate text here, as the new
QEMU standard is to use only SPDX for new files.
> +
> +int tdvf_parse_metadata(TdxFirmware *fw, void *flash_ptr, int size)
> +{
> + TdvfSectionEntry *sections;
g_autofree TdvfSectionEntry *sections = NULL;
will avoid the duplicated 'g_free' calls later
> + TdvfMetadata *metadata;
> + ssize_t entries_size;
> + int i;
> +
> + metadata = tdvf_get_metadata(flash_ptr, size);
> + if (!metadata) {
> + return -EINVAL;
> + }
> +
> + /* load and parse metadata entries */
> + fw->nr_entries = 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 = fw->nr_entries * sizeof(TdvfSectionEntry);
> + if (metadata->Length != 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 = g_new(TdxFirmwareEntry, fw->nr_entries);
> + sections = g_new(TdvfSectionEntry, fw->nr_entries);
> +
> + if (!memcpy(sections, (void *)metadata + sizeof(*metadata), entries_size)) {
> + error_report("Failed to read TDVF section entries");
> + goto err;
> + }
> +
> + for (i = 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 = 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 <isaku.yamahata at gmail.com>
> + * <isaku.yamahata at intel.com>
> + *
> + * 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 <http://www.gnu.org/licenses/>.
> + */
Same note about only using SPDX.
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2024-11-05 10:43 UTC|newest]
Thread overview: 125+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-05 6:23 [PATCH v6 00/60] QEMU TDX support Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 01/60] *** HACK *** linux-headers: Update headers to pull in TDX API changes Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 02/60] i386: Introduce tdx-guest object Xiaoyao Li
2024-11-05 10:18 ` Daniel P. Berrangé
2024-11-05 11:42 ` Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 03/60] i386/tdx: Implement tdx_kvm_type() for TDX Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 04/60] i386/tdx: Implement tdx_kvm_init() to initialize TDX VM context Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 05/60] i386/tdx: Get tdx_capabilities via KVM_TDX_CAPABILITIES Xiaoyao Li
2024-11-05 10:30 ` Daniel P. Berrangé
2024-11-05 6:23 ` [PATCH v6 06/60] i386/tdx: Introduce is_tdx_vm() helper and cache tdx_guest object Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 07/60] kvm: Introduce kvm_arch_pre_create_vcpu() Xiaoyao Li
2024-11-13 6:28 ` Philippe Mathieu-Daudé
2024-11-25 7:27 ` Xiaoyao Li
2024-11-26 9:46 ` Philippe Mathieu-Daudé
2024-11-05 6:23 ` [PATCH v6 08/60] i386/kvm: Export cpuid_entry_get_reg() and cpuid_find_entry() Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 09/60] i386/tdx: Initialize TDX before creating TD vcpus Xiaoyao Li
2024-11-05 10:34 ` Daniel P. Berrangé
2024-11-05 11:51 ` Xiaoyao Li
2024-11-05 11:53 ` Daniel P. Berrangé
2024-11-05 20:51 ` Edgecombe, Rick P
2024-11-06 2:01 ` Xiaoyao Li
2024-11-06 5:13 ` Tony Lindgren
2024-12-12 17:24 ` Ira Weiny
2024-12-17 13:10 ` Tony Lindgren
2025-01-14 12:39 ` Xiaoyao Li
2025-01-15 12:12 ` Tony Lindgren
2024-11-05 6:23 ` [PATCH v6 10/60] i386/tdx: Add property sept-ve-disable for tdx-guest object Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 11/60] i386/tdx: Make sept_ve_disable set by default Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 12/60] i386/tdx: Wire CPU features up with attributes of TD guest Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 13/60] i386/tdx: Validate TD attributes Xiaoyao Li
2024-11-05 10:36 ` Daniel P. Berrangé
2024-11-05 11:53 ` Xiaoyao Li
2024-11-05 11:54 ` Daniel P. Berrangé
2024-11-05 20:56 ` Edgecombe, Rick P
2024-11-06 1:38 ` Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 14/60] i386/tdx: Support user configurable mrconfigid/mrowner/mrownerconfig Xiaoyao Li
2024-11-05 10:38 ` Daniel P. Berrangé
2024-11-05 11:54 ` Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 15/60] i386/tdx: Set APIC bus rate to match with what TDX module enforces Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 16/60] i386/tdx: Implement user specified tsc frequency Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 17/60] i386/tdx: load TDVF for TD guest Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 18/60] i386/tdvf: Introduce function to parse TDVF metadata Xiaoyao Li
2024-11-05 10:42 ` Daniel P. Berrangé [this message]
2024-11-05 6:23 ` [PATCH v6 19/60] i386/tdx: Parse TDVF metadata for TDX VM Xiaoyao Li
2024-12-12 17:55 ` Ira Weiny
2024-11-05 6:23 ` [PATCH v6 20/60] i386/tdx: Don't initialize pc.rom for TDX VMs Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 21/60] i386/tdx: Track mem_ptr for each firmware entry of TDVF Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 22/60] i386/tdx: Track RAM entries for TDX VM Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 23/60] headers: Add definitions from UEFI spec for volumes, resources, etc Xiaoyao Li
2024-11-05 10:45 ` Daniel P. Berrangé
2024-11-05 6:23 ` [PATCH v6 24/60] i386/tdx: Setup the TD HOB list Xiaoyao Li
2024-11-05 10:46 ` Daniel P. Berrangé
2024-11-05 6:23 ` [PATCH v6 25/60] i386/tdx: Add TDVF memory via KVM_TDX_INIT_MEM_REGION Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 26/60] i386/tdx: Call KVM_TDX_INIT_VCPU to initialize TDX vcpu Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 27/60] i386/tdx: Finalize TDX VM Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 28/60] i386/tdx: Enable user exit on KVM_HC_MAP_GPA_RANGE Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 29/60] i386/tdx: Handle KVM_SYSTEM_EVENT_TDX_FATAL Xiaoyao Li
2024-11-05 20:55 ` Edgecombe, Rick P
2024-11-06 14:28 ` Edgecombe, Rick P
2024-11-05 6:23 ` [PATCH v6 30/60] i386/tdx: Wire TDX_REPORT_FATAL_ERROR with GuestPanic facility Xiaoyao Li
2024-11-05 10:53 ` Daniel P. Berrangé
2024-11-05 6:23 ` [PATCH v6 31/60] i386/cpu: introduce x86_confidential_guest_cpu_instance_init() Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 32/60] i386/tdx: implement tdx_cpu_instance_init() Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 33/60] i386/cpu: introduce x86_confidenetial_guest_cpu_realizefn() Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 34/60] i386/tdx: implement tdx_cpu_realizefn() Xiaoyao Li
2024-11-05 10:06 ` Paolo Bonzini
2024-11-05 11:38 ` Xiaoyao Li
2024-11-05 11:53 ` Paolo Bonzini
2024-12-12 22:04 ` Ira Weiny
2025-01-14 8:52 ` Xiaoyao Li
2025-01-14 13:10 ` Daniel P. Berrangé
2024-11-05 6:23 ` [PATCH v6 35/60] i386/cpu: Introduce enable_cpuid_0x1f to force exposing CPUID 0x1f Xiaoyao Li
2024-12-12 22:16 ` Ira Weiny
2025-01-14 12:51 ` Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 36/60] i386/tdx: Force " Xiaoyao Li
2024-12-12 22:17 ` Ira Weiny
2025-01-14 12:55 ` Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 37/60] i386/tdx: Set kvm_readonly_mem_enabled to false for TDX VM Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 38/60] i386/tdx: Disable SMM for TDX VMs Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 39/60] i386/tdx: Disable PIC " Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 40/60] hw/i386: add eoi_intercept_unsupported member to X86MachineState Xiaoyao Li
2025-01-23 12:41 ` Igor Mammedov
2025-01-23 16:45 ` Xiaoyao Li
2025-01-24 13:00 ` Igor Mammedov
2024-11-05 6:23 ` [PATCH v6 41/60] hw/i386: add option to forcibly report edge trigger in acpi tables Xiaoyao Li
2024-12-12 22:39 ` Ira Weiny
2025-01-14 13:01 ` Xiaoyao Li
2025-01-23 12:53 ` Igor Mammedov
2025-01-24 13:53 ` Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 42/60] i386/tdx: Don't synchronize guest tsc for TDs Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 43/60] i386/tdx: Only configure MSR_IA32_UCODE_REV in kvm_init_msrs() " Xiaoyao Li
2024-12-13 14:42 ` Ira Weiny
2024-12-17 9:41 ` Paolo Bonzini
2024-11-05 6:23 ` [PATCH v6 44/60] i386/tdx: Skip kvm_put_apicbase() " Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 45/60] i386/tdx: Don't get/put guest state for TDX VMs Xiaoyao Li
2024-11-05 9:55 ` Paolo Bonzini
2024-11-05 11:25 ` Xiaoyao Li
2024-11-05 14:23 ` Paolo Bonzini
2024-11-06 13:57 ` Xiaoyao Li
2024-11-06 19:56 ` Paolo Bonzini
2024-11-05 6:23 ` [PATCH v6 46/60] i386/cgs: Rename *mask_cpuid_features() to *adjust_cpuid_features() Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 47/60] i386/tdx: Implement adjust_cpuid_features() for TDX Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 48/60] i386/tdx: Apply TDX fixed0 and fixed1 information to supported CPUIDs Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 49/60] i386/tdx: Mask off CPUID bits by unsupported TD Attributes Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 50/60] i386/cpu: Move CPUID_XSTATE_XSS_MASK to header file and introduce CPUID_XSTATE_MASK Xiaoyao Li
2024-11-05 6:23 ` [PATCH v6 51/60] i386/tdx: Mask off CPUID bits by unsupported XFAM Xiaoyao Li
2024-11-05 6:24 ` [PATCH v6 52/60] i386/cpu: Expose mark_unavailable_features() for TDX Xiaoyao Li
2024-11-05 6:24 ` [PATCH v6 53/60] i386/cpu: introduce mark_forced_on_features() Xiaoyao Li
2024-11-05 6:24 ` [PATCH v6 54/60] i386/cgs: Introduce x86_confidential_guest_check_features() Xiaoyao Li
2024-11-05 6:24 ` [PATCH v6 55/60] i386/tdx: Fetch and validate CPUID of TD guest Xiaoyao Li
2024-12-12 17:52 ` Ira Weiny
2025-01-14 13:03 ` Xiaoyao Li
2024-11-05 6:24 ` [PATCH v6 56/60] i386/tdx: Don't treat SYSCALL as unavailable Xiaoyao Li
2024-11-05 9:59 ` Paolo Bonzini
2025-01-16 8:53 ` Xiaoyao Li
2024-11-05 11:07 ` Daniel P. Berrangé
2024-11-05 6:24 ` [PATCH v6 57/60] i386/tdx: Make invtsc default on Xiaoyao Li
2024-11-05 6:24 ` [PATCH v6 58/60] cpu: Introduce qemu_early_init_vcpu() Xiaoyao Li
2024-11-05 6:24 ` [PATCH v6 59/60] i386/cpu: Set up CPUID_HT in x86_cpu_realizefn() instead of cpu_x86_cpuid() Xiaoyao Li
2024-11-05 9:12 ` Paolo Bonzini
2024-11-05 9:33 ` Xiaoyao Li
2024-11-05 9:53 ` Paolo Bonzini
2024-11-05 6:24 ` [PATCH v6 60/60] docs: Add TDX documentation Xiaoyao Li
2024-11-05 11:14 ` Daniel P. Berrangé
2024-11-12 10:17 ` Francesco Lavra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zyn2p9wD2SnisXhT@redhat.com \
--to=berrange@redhat.com \
--cc=anisinha@redhat.com \
--cc=armbru@redhat.com \
--cc=cohuck@redhat.com \
--cc=eblake@redhat.com \
--cc=imammedo@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=rick.p.edgecombe@intel.com \
--cc=riku.voipio@iki.fi \
--cc=wangyanan55@huawei.com \
--cc=xiaoyao.li@intel.com \
--cc=zhao1.liu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).