@samitouri / QOSamiQemu / commits / 40c015e969

hw/i386: export a new function x86_bios_rom_reload

Confidential guest smust reload their bios rom upon reset. This is because bios memory is encrypted and upon reset, the contents of the old bios memory is lost and cannot be re-used. To this end, export a new x86 function x86_bios_rom_reload() to reload the bios again. This function will be used in the subsequent patches. Reviewed-by: Bernhard Beschow <shentey@gmail.com> Signed-off-by: Ani Sinha <anisinha@redhat.com> Link: https://lore.kernel.org/r/20260225035000.385950-14-anisinha@redhat.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Ani Sinha committed Feb 25, 2026 at 09:19 UTC 40c015e96942fd2a3e4d5ace6063b3333a3dd372
2 files changed +22
hw/i386/x86-common.c
+21
@@ -1085,6 +1085,27 @@ static void load_bios_from_file(X86MachineState *x86ms, const char *bios_name,
1085 exit(1);
1086 }
1087
1088 +void x86_bios_rom_reload(X86MachineState *x86ms)
1089 +{
1090 + int bios_size;
1091 + const char *bios_name;
1092 + char *filename;
1093 +
1094 + if (memory_region_size(&x86ms->bios) == 0) {
1095 + /* if -bios is not used */
1096 + return;
1097 + }
1098 +
1099 + bios_name = MACHINE(x86ms)->firmware ?: "bios.bin";
1100 + filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
1101 +
1102 + bios_size = get_bios_size(x86ms, bios_name, filename);
1103 +
1104 + void *ptr = memory_region_get_ram_ptr(&x86ms->bios);
1105 + load_image_size(filename, ptr, bios_size);
1106 + x86_firmware_configure(0x100000000ULL - bios_size, ptr, bios_size);
1107 +}
1108 +
1109 void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware,
1110 MemoryRegion *rom_memory, bool isapc_ram_fw)
1111 {
include/hw/i386/x86.h
+1
@@ -125,6 +125,7 @@ void x86_isa_bios_init(MemoryRegion *isa_bios, MemoryRegion *isa_memory,
125 MemoryRegion *bios, bool read_only);
126 void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware,
127 MemoryRegion *rom_memory, bool isapc_ram_fw);
128 +void x86_bios_rom_reload(X86MachineState *x86ms);
129
130 void x86_load_linux(X86MachineState *x86ms,
131 FWCfgState *fw_cfg,