[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFC PATCH v3 18/36] i386/tdvf: Introduce function to parse TDVF met
From: |
Isaku Yamahata |
Subject: |
Re: [RFC PATCH v3 18/36] i386/tdvf: Introduce function to parse TDVF metadata |
Date: |
Fri, 18 Mar 2022 10:19:24 -0700 |
On Thu, Mar 17, 2022 at 09:58:55PM +0800,
Xiaoyao Li <xiaoyao.li@intel.com> wrote:
> diff --git a/hw/i386/tdvf.c b/hw/i386/tdvf.c
> new file mode 100644
> index 000000000000..02da1d2c12dd
> --- /dev/null
> +++ b/hw/i386/tdvf.c
> @@ -0,0 +1,196 @@
> +/*
> + * 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/>.
> + */
> +
> +#include "qemu/osdep.h"
> +#include "hw/i386/pc.h"
> +#include "hw/i386/tdvf.h"
> +#include "sysemu/kvm.h"
> +
> +#define TDX_METADATA_GUID "e47a6535-984a-4798-865e-4685a7bf8ec2"
> +#define TDX_METADATA_VERSION 1
> +#define TDVF_SIGNATURE_LE32 0x46564454 /* TDVF as little endian */
_LE32 doesn't make sense. qemu doesn't provide macro version for byteswap.
Let's convert at the usage point.
> +
> +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 = 0;
> + uint8_t *data;
> +
> + if ((uint32_t) size != size) {
> + return NULL;
> + }
> +
> + if (pc_system_ovmf_table_find(TDX_METADATA_GUID, &data, NULL)) {
> + offset = size - le32_to_cpu(((struct tdx_metadata_offset
> *)data)->offset);
> +
> + if (offset + sizeof(*metadata) > size) {
> + return NULL;
> + }
> + } else {
> + error_report("Cannot find TDX_METADATA_GUID\n");
> + return NULL;
> + }
> +
> + metadata = flash_ptr + offset;
> +
> + /* Finally, verify the signature to determine if this is a TDVF image. */
> + if (metadata->Signature != TDVF_SIGNATURE_LE32) {
metadata->Signature = le32_to_cpu(metadata->Signature);
metadata->Signature != TDVF_SIGNATURE for consistency.
--
Isaku Yamahata <isaku.yamahata@gmail.com>
- [RFC PATCH v3 11/36] i386/tdx: Initialize TDX before creating TD vcpus, (continued)
- [RFC PATCH v3 11/36] i386/tdx: Initialize TDX before creating TD vcpus, Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 12/36] i386/tdx: Add property sept-ve-disable for tdx-guest object, Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 13/36] i386/tdx: Wire CPU features up with attributes of TD guest, Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 14/36] i386/tdx: Validate TD attributes, Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 16/36] i386/tdx: Set kvm_readonly_mem_enabled to false for TDX VM, Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 15/36] i386/tdx: Implement user specified tsc frequency, Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 17/36] pflash_cfi01/tdx: Introduce ram_mode of pflash for TDVF, Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 18/36] i386/tdvf: Introduce function to parse TDVF metadata, Xiaoyao Li, 2022/03/17
- Re: [RFC PATCH v3 18/36] i386/tdvf: Introduce function to parse TDVF metadata,
Isaku Yamahata <=
- [RFC PATCH v3 19/36] i386/tdx: Parse TDVF metadata for TDX VM, Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 20/36] i386/tdx: Get and store the mem_ptr of TDVF firmware, Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 21/36] i386/tdx: Track mem_ptr for each firmware entry of TDVF, Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 22/36] i386/tdx: Track RAM entries for TDX VM, Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 23/36] i386/tdx: Create the TD HOB list upon machine init done, Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 24/36] i386/tdx: Call KVM_TDX_INIT_VCPU to initialize TDX vcpu, Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 25/36] i386/tdx: Add TDVF memory via KVM_TDX_INIT_MEM_REGION, Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 26/36] i386/tdx: Finalize TDX VM, Xiaoyao Li, 2022/03/17
- [RFC PATCH v3 27/36] i386/tdx: Disable SMM for TDX VMs, Xiaoyao Li, 2022/03/17