@@ -147,8 +147,8 @@ static void pc_system_flash_map(PCMachineState *pcms,
int64_t size;
PFlashCFI01 *system_flash;
MemoryRegion *flash_mem;
- void *flash_ptr;
- int flash_size;
+ void *flash_ptr[2] = {NULL, NULL};
+ int flash_size[2];
int ret;
assert(PC_MACHINE_GET_CLASS(pcms)->pci_enabled);
@@ -197,29 +197,29 @@ static void pc_system_flash_map(PCMachineState *pcms,
0x100000000ULL - total_size);
}
+ flash_ptr[i] = memory_region_get_ram_ptr(flash_mem);
+ flash_size[i] = memory_region_size(flash_mem);
if (i == 0) {
pc_isa_bios_init(rom_memory, flash_mem, size);
- flash_ptr = memory_region_get_ram_ptr(flash_mem);
- flash_size = memory_region_size(flash_mem);
/*
* OVMF places a GUIDed structures in the flash, so
* search for them
*/
- pc_system_parse_ovmf_flash(flash_ptr, flash_size);
+ pc_system_parse_ovmf_flash(flash_ptr[i], flash_size[i]);
/* Encrypt the pflash boot ROM */
if (sev_enabled()) {
- ret = sev_es_save_reset_vector(flash_ptr, flash_size);
+ ret = sev_es_save_reset_vector(flash_ptr[i], flash_size[i]);
if (ret) {
error_report("failed to locate and/or save reset vector");
exit(1);
}
- sev_encrypt_flash(flash_ptr, flash_size, &error_fatal);
+ sev_encrypt_flash(flash_ptr[i], flash_size[i], &error_fatal);
} else if (is_tdx_vm()) {
- ret = tdx_parse_tdvf(flash_ptr, flash_size);
+ ret = tdx_parse_tdvf(flash_ptr[i], flash_size[i]);
if (ret) {
error_report("failed to parse TDVF in pflash for TDX VM");
exit(1);
@@ -227,6 +227,10 @@ static void pc_system_flash_map(PCMachineState *pcms,
}
}
}
+
+ if (is_tdx_vm()) {
+ tdx_set_code_vars_ptr(flash_ptr[0], flash_ptr[1]);
+ }
}
void pc_system_firmware_init(PCMachineState *pcms,
@@ -42,6 +42,10 @@ typedef struct TdxFirmwareEntry {
} TdxFirmwareEntry;
typedef struct TdxFirmware {
+ bool split_tdvf;
+ void *code_ptr;
+ void *vars_ptr;
+
uint32_t nr_entries;
TdxFirmwareEntry *entries;
} TdxFirmware;
@@ -17,3 +17,8 @@ int tdx_parse_tdvf(void *flash_ptr, int size)
{
return -EINVAL;
}
+
+void tdx_set_code_vars_ptr(void *code_ptr, void *vars_ptr)
+{
+ g_assert_not_reached();
+}
@@ -265,6 +265,13 @@ int tdx_parse_tdvf(void *flash_ptr, int size)
return tdvf_parse_metadata(&tdx_guest->tdvf, flash_ptr, size);
}
+void tdx_set_code_vars_ptr(void *code_ptr, void *vars_ptr)
+{
+ tdx_guest->tdvf.code_ptr = code_ptr;
+ tdx_guest->tdvf.vars_ptr = vars_ptr;
+ tdx_guest->tdvf.split_tdvf = vars_ptr ? true : false;
+}
+
static bool tdx_guest_get_sept_ve_disable(Object *obj, Error **errp)
{
TdxGuest *tdx = TDX_GUEST(obj);
@@ -37,5 +37,6 @@ void tdx_get_supported_cpuid(uint32_t function, uint32_t index, int reg,
uint32_t *ret);
int tdx_pre_create_vcpu(CPUState *cpu);
int tdx_parse_tdvf(void *flash_ptr, int size);
+void tdx_set_code_vars_ptr(void *code_ptr, void *vars_ptr);
#endif /* QEMU_I386_TDX_H */
QEMU needs to later copy the context of TDVF firmware to guest private memory. So get the mem_ptr of CODE.fd and VARS.fd and store them in tdx_guest object. Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com> --- hw/i386/pc_sysfw.c | 20 ++++++++++++-------- include/hw/i386/tdvf.h | 4 ++++ target/i386/kvm/tdx-stub.c | 5 +++++ target/i386/kvm/tdx.c | 7 +++++++ target/i386/kvm/tdx.h | 1 + 5 files changed, 29 insertions(+), 8 deletions(-)