i386: firmware parsing and sev setup for -bios loaded firmware
v2 cover i386: firmware parsing and sev setup for -bios loaded firmware
v2:
- rebased to latest master, post-freeze repost.
- picked up review tags.
Gerd Hoffmann (3):
i386: move bios load error message
i386: factor out x86_firmware_configure()
i386: firmware parsing and sev setup for -bios loaded firmware
include/hw/i386/x86.h | 3 +++ hw/i386/pc_sysfw.c | 36 ++++++++++++++++++++++-------------- hw/i386/x86.c | 32 ++++++++++++++++++++++++-------- 3 files changed, 49 insertions(+), 22 deletions(-)
Signature · 1 line
2.35.1
PATCH v2 1/3 i386: move bios load error message
Switch to usual goto-end-of-function error handling style. No functional change.
--- hw/i386/x86.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
hw/i386/x86.c +6 -3
@@ -1120,9 +1120,7 @@ void x86_bios_rom_init(MachineState *ms, const char *default_firmware, } ret =rom_add_file_fixed (bios_name, (uint32_t )(-bios_size),-1 );if (ret !=0 ) { - bios_error: -fprintf (stderr,"qemu: could not load PC BIOS '%s'\n" , bios_name); -exit (1 ); + goto bios_error; }g_free (filename);
@@ -1143,6 +1141,11 @@ void x86_bios_rom_init(MachineState *ms, const char *default_firmware,memory_region_add_subregion (rom_memory, (uint32_t )(-bios_size), bios); +return ; + +bios_error: +fprintf (stderr,"qemu: could not load PC BIOS '%s'\n" , bios_name); +exit (1 ); }bool x86_machine_is_smm_enabled (const X86MachineState *x86ms)
Signature · 1 line
2.35.1
PATCH v2 2/3 i386: factor out x86_firmware_configure()
In reply to Gerd Hoffmannmove sev firmware setup to separate function so it can be used from other code paths. No functional change.
--- include/hw/i386/x86.h | 3 +++ hw/i386/pc_sysfw.c | 36 ++++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 14 deletions(-)
include/hw/i386/x86.h +3 -0
@@ -140,4 +140,7 @@ void gsi_handler(void *opaque, int n, int level);void ioapic_init_gsi (GSIState *gsi_state,const char *parent_name);DeviceState *ioapic_init_secondary (GSIState *gsi_state); +/* pc_sysfw.c */ +void x86_firmware_configure (void *ptr,int size); +#endif
hw/i386/pc_sysfw.c +22 -14
@@ -147,7 +147,6 @@ static void pc_system_flash_map(PCMachineState *pcms,MemoryRegion *flash_mem;void *flash_ptr;int flash_size; -int ret;assert (PC_MACHINE_GET_CLASS (pcms)->pci_enabled);
@@ -195,19 +194,7 @@ static void pc_system_flash_map(PCMachineState *pcms,if (sev_enabled ()) { 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); - - ret =sev_es_save_reset_vector (flash_ptr, flash_size); -if (ret) { -error_report ("failed to locate and/or save reset vector" ); -exit (1 ); - } - -sev_encrypt_flash (flash_ptr, flash_size, &error_fatal); +x86_firmware_configure (flash_ptr, flash_size); } } }
@@ -259,3 +246,24 @@ void pc_system_firmware_init(PCMachineState *pcms,pc_system_flash_cleanup_unused (pcms); } + +void x86_firmware_configure (void *ptr,int size) +{ +int ret; + +/* +* OVMF places a GUIDed structures in the flash, so +* search for them +*/ +pc_system_parse_ovmf_flash (ptr, size); + +if (sev_enabled ()) { + ret =sev_es_save_reset_vector (ptr, size); +if (ret) { +error_report ("failed to locate and/or save reset vector" ); +exit (1 ); + } + +sev_encrypt_flash (ptr, size, &error_fatal); + } +}
Signature · 1 line
2.35.1
PATCH v2 3/3 i386: firmware parsing and sev setup for -bios loaded firmware
In reply to Gerd HoffmannDon't register firmware as rom, not needed (see comment). Add x86_firmware_configure() call for proper sev initialization.
--- hw/i386/x86.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
hw/i386/x86.c +19 -6
@@ -1115,12 +1115,25 @@ void x86_bios_rom_init(MachineState *ms, const char *default_firmware, } bios =g_malloc (sizeof (*bios));memory_region_init_ram (bios,NULL ,"pc.bios" , bios_size, &error_fatal); -if (!isapc_ram_fw) { -memory_region_set_readonly (bios, true); - } - ret =rom_add_file_fixed (bios_name, (uint32_t )(-bios_size),-1 ); -if (ret !=0 ) { - goto bios_error; +if (sev_enabled ()) { +/* +* The concept of a "reset" simply doesn't exist for +* confidential computing guests, we have to destroy and +* re-launch them instead. So there is no need to register +* the firmware as rom to properly re-initialize on reset. +* Just go for a straight file load instead. +*/ +void *ptr =memory_region_get_ram_ptr (bios); +load_image_size (filename, ptr, bios_size); +x86_firmware_configure (ptr, bios_size); + }else { +if (!isapc_ram_fw) { +memory_region_set_readonly (bios, true); + } + ret =rom_add_file_fixed (bios_name, (uint32_t )(-bios_size),-1 ); +if (ret !=0 ) { + goto bios_error; + } }g_free (filename);
Signature · 1 line
2.35.1