* [PATCH v2 0/3] i386: firmware parsing and sev setup for -bios loaded firmware
@ 2022-04-25 13:50 Gerd Hoffmann
2022-04-25 13:50 ` [PATCH v2 1/3] i386: move bios load error message Gerd Hoffmann
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Gerd Hoffmann @ 2022-04-25 13:50 UTC (permalink / raw)
To: qemu-devel
Cc: Eduardo Habkost, Michael S. Tsirkin, Richard Henderson,
Gerd Hoffmann, Paolo Bonzini
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(-)
--
2.35.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/3] i386: move bios load error message
2022-04-25 13:50 [PATCH v2 0/3] i386: firmware parsing and sev setup for -bios loaded firmware Gerd Hoffmann
@ 2022-04-25 13:50 ` Gerd Hoffmann
2022-04-25 13:50 ` [PATCH v2 2/3] i386: factor out x86_firmware_configure() Gerd Hoffmann
2022-04-25 13:50 ` [PATCH v2 3/3] i386: firmware parsing and sev setup for -bios loaded firmware Gerd Hoffmann
2 siblings, 0 replies; 4+ messages in thread
From: Gerd Hoffmann @ 2022-04-25 13:50 UTC (permalink / raw)
To: qemu-devel
Cc: Eduardo Habkost, Daniel P . Berrangé, Michael S. Tsirkin,
Xiaoyao Li, Richard Henderson, Philippe Mathieu-Daudé,
Gerd Hoffmann, Paolo Bonzini
Switch to usual goto-end-of-function error handling style.
No functional change.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Tested-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/i386/x86.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index bb6727279097..ced31f67b9a8 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -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)
--
2.35.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/3] i386: factor out x86_firmware_configure()
2022-04-25 13:50 [PATCH v2 0/3] i386: firmware parsing and sev setup for -bios loaded firmware Gerd Hoffmann
2022-04-25 13:50 ` [PATCH v2 1/3] i386: move bios load error message Gerd Hoffmann
@ 2022-04-25 13:50 ` Gerd Hoffmann
2022-04-25 13:50 ` [PATCH v2 3/3] i386: firmware parsing and sev setup for -bios loaded firmware Gerd Hoffmann
2 siblings, 0 replies; 4+ messages in thread
From: Gerd Hoffmann @ 2022-04-25 13:50 UTC (permalink / raw)
To: qemu-devel
Cc: Eduardo Habkost, Daniel P . Berrangé, Michael S. Tsirkin,
Xiaoyao Li, Richard Henderson, Philippe Mathieu-Daudé,
Gerd Hoffmann, Paolo Bonzini
move sev firmware setup to separate function so it can be used from
other code paths. No functional change.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Tested-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/i386/x86.h | 3 +++
hw/i386/pc_sysfw.c | 36 ++++++++++++++++++++++--------------
2 files changed, 25 insertions(+), 14 deletions(-)
diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h
index 916cc325eeb1..4841a49f86c0 100644
--- a/include/hw/i386/x86.h
+++ b/include/hw/i386/x86.h
@@ -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
diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c
index 0540047bad22..c8d9e71b889b 100644
--- a/hw/i386/pc_sysfw.c
+++ b/hw/i386/pc_sysfw.c
@@ -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);
+ }
+}
--
2.35.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 3/3] i386: firmware parsing and sev setup for -bios loaded firmware
2022-04-25 13:50 [PATCH v2 0/3] i386: firmware parsing and sev setup for -bios loaded firmware Gerd Hoffmann
2022-04-25 13:50 ` [PATCH v2 1/3] i386: move bios load error message Gerd Hoffmann
2022-04-25 13:50 ` [PATCH v2 2/3] i386: factor out x86_firmware_configure() Gerd Hoffmann
@ 2022-04-25 13:50 ` Gerd Hoffmann
2 siblings, 0 replies; 4+ messages in thread
From: Gerd Hoffmann @ 2022-04-25 13:50 UTC (permalink / raw)
To: qemu-devel
Cc: Eduardo Habkost, Daniel P . Berrangé, Michael S. Tsirkin,
Xiaoyao Li, Richard Henderson, Philippe Mathieu-Daudé,
Gerd Hoffmann, Paolo Bonzini
Don't register firmware as rom, not needed (see comment).
Add x86_firmware_configure() call for proper sev initialization.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Tested-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Tested-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/i386/x86.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index ced31f67b9a8..79ebdface6e2 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -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);
--
2.35.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-04-25 13:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-25 13:50 [PATCH v2 0/3] i386: firmware parsing and sev setup for -bios loaded firmware Gerd Hoffmann
2022-04-25 13:50 ` [PATCH v2 1/3] i386: move bios load error message Gerd Hoffmann
2022-04-25 13:50 ` [PATCH v2 2/3] i386: factor out x86_firmware_configure() Gerd Hoffmann
2022-04-25 13:50 ` [PATCH v2 3/3] i386: firmware parsing and sev setup for -bios loaded firmware Gerd Hoffmann
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).