hw/uefi: some bugfixes
v3 cover hw/uefi: some bugfixes
v3 changes:
- rename firmware.json flag, more verbose documentation.
- add support for riscv and loongarch.
Gerd Hoffmann (6):
hw/uefi: flush variable store to disk in post load hw/uefi: fix error handling in uefi_vars_json_save hw/uefi: fix error handling in uefi_vars_json_load hw/uefi-vars-sysbus: allow for riscv virt hw/uefi-vars-sysbus: allow for loongarch virt docs/firmware: add feature flag for host uefi variable store
hw/loongarch/virt.c | 2 ++ hw/riscv/virt.c | 2 ++ hw/uefi/var-service-core.c | 1 + hw/uefi/var-service-json.c | 24 +++++++++++++++++++----- docs/interop/firmware.json | 12 +++++++++++- hw/uefi/Kconfig | 2 +- 6 files changed, 36 insertions(+), 7 deletions(-)
Signature · 1 line
2.48.1
PATCH v3 1/6 hw/uefi: flush variable store to disk in post load
Make live migration more robust. Commit 4c0cfc72b31a ("pflash_cfi01:
write flash contents to bdrv on incoming migration") elaborates in detail on the motivation.
--- hw/uefi/var-service-core.c | 1 + 1 file changed, 1 insertion(+)
hw/uefi/var-service-core.c +1 -0
@@ -29,6 +29,7 @@ static int uefi_vars_post_load(void *opaque, int version_id)uefi_vars_state *uv = opaque;uefi_vars_update_storage (uv); +uefi_vars_json_save (uv); uv->buffer =g_malloc (uv->buf_size);return 0 ; }
Signature · 1 line
2.48.1
PATCH v3 2/6 hw/uefi: fix error handling in uefi_vars_json_save
In reply to Gerd HoffmannCatch lseek errors. Return on errors.
Use autoptr for the GString to simplify cleanup.
--- hw/uefi/var-service-json.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
hw/uefi/var-service-json.c +11 -4
@@ -178,7 +178,7 @@ void uefi_vars_json_init(uefi_vars_state *uv, Error **errp)void uefi_vars_json_save (uefi_vars_state *uv) { -GString *gstr; +g_autoptr (GString) gstr =NULL ;int rc;if (uv->jsonfd ==-1 ) {
@@ -187,18 +187,25 @@ void uefi_vars_json_save(uefi_vars_state *uv) gstr =uefi_vars_to_json (uv); -lseek (uv->jsonfd,0 ,SEEK_SET ); + rc =lseek (uv->jsonfd,0 ,SEEK_SET ); +if (rc <0 ) { +warn_report ("%s: lseek error" , __func__); +return ; + } + rc =ftruncate (uv->jsonfd,0 );if (rc !=0 ) {warn_report ("%s: ftruncate error" , __func__); +return ; } + rc =write (uv->jsonfd, gstr->str, gstr->len);if (rc != gstr->len) {warn_report ("%s: write error" , __func__); +return ; } +fsync (uv->jsonfd); - -g_string_free (gstr, true); }void uefi_vars_json_load (uefi_vars_state *uv,Error **errp)
Signature · 1 line
2.48.1
PATCH v3 3/6 hw/uefi: fix error handling in uefi_vars_json_load
In reply to Gerd HoffmannCatch lseek errors. Return on read errors.
--- hw/uefi/var-service-json.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
hw/uefi/var-service-json.c +8 -1
@@ -214,7 +214,7 @@ void uefi_vars_json_load(uefi_vars_state *uv, Error **errp)QObject *qobj;Visitor *v;char *str; -size_t len; +ssize_t len;int rc;if (uv->jsonfd ==-1 ) {
@@ -222,7 +222,12 @@ void uefi_vars_json_load(uefi_vars_state *uv, Error **errp) } len =lseek (uv->jsonfd,0 ,SEEK_END ); +if (len <0 ) { +warn_report ("%s: lseek error" , __func__); +return ; + }if (len ==0 ) { +/* empty file */ return ; }
@@ -231,6 +236,8 @@ void uefi_vars_json_load(uefi_vars_state *uv, Error **errp) rc =read (uv->jsonfd, str, len);if (rc != len) {warn_report ("%s: read error" , __func__); +g_free (str); +return ; } str[len] =0 ;
Signature · 1 line
2.48.1
PATCH v3 4/6 hw/uefi-vars-sysbus: allow for riscv virt
In reply to Gerd HoffmannAllow the device being added to riscv virt VMs.
--- hw/riscv/virt.c | 2 ++ hw/uefi/Kconfig | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
hw/riscv/virt.c +2 -0
@@ -57,6 +57,7 @@#include "hw/acpi/aml-build.h" #include "qapi/qapi-visit-common.h" #include "hw/virtio/virtio-iommu.h" +#include "hw/uefi/var-service-api.h" /* KVM AIA only supports APLIC MSI. APLIC Wired is always emulated by QEMU. */ static bool virt_use_kvm_aia_aplic_imsic (RISCVVirtAIAType aia_type)
@@ -1935,6 +1936,7 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) hc->plug = virt_machine_device_plug_cb;machine_class_allow_dynamic_sysbus_dev (mc,TYPE_RAMFB_DEVICE ); +machine_class_allow_dynamic_sysbus_dev (mc,TYPE_UEFI_VARS_SYSBUS );#ifdef CONFIG_TPM machine_class_allow_dynamic_sysbus_dev (mc,TYPE_TPM_TIS_SYSBUS );#endif
hw/uefi/Kconfig +1 -1
@@ -1,3 +1,3 @@ config UEFI_VARS bool - default y if X86_64 || AARCH64 + default y if X86_64 || AARCH64 || RISCV64
Signature · 1 line
2.48.1
Re: [PATCH v3 4/6] hw/uefi-vars-sysbus: allow for riscv virt
Quoted 7 lines · Gerd Hoffmann
Allow the device being added to riscv virt VMs.
Signed-off-by Gerd Hoffmann <[email protected]>--- hw/riscv/virt.c | 2 ++ hw/uefi/Kconfig | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v3 4/6] hw/uefi-vars-sysbus: allow for riscv virt
In reply to Gerd HoffmannQuoted 4 lines · Gerd Hoffmann
Allow the device being added to riscv virt VMs.
Signed-off-by Gerd Hoffmann <[email protected]>---
Quoted 33 lines
hw/riscv/virt.c | 2 ++ hw/uefi/Kconfig | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)hw/riscv/virt.c +2
-0@@ -57,6 +57,7 @@#include "hw/acpi/aml-build.h" #include "qapi/qapi-visit-common.h" #include "hw/virtio/virtio-iommu.h" +#include "hw/uefi/var-service-api.h" /* KVM AIA only supports APLIC MSI. APLIC Wired is always emulated by QEMU. */ static bool virt_use_kvm_aia_aplic_imsic (RISCVVirtAIAType aia_type)@@ -1935,6 +1936,7 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) hc->plug = virt_machine_device_plug_cb;machine_class_allow_dynamic_sysbus_dev (mc,TYPE_RAMFB_DEVICE ); +machine_class_allow_dynamic_sysbus_dev (mc,TYPE_UEFI_VARS_SYSBUS );#ifdef CONFIG_TPM machine_class_allow_dynamic_sysbus_dev (mc,TYPE_TPM_TIS_SYSBUS );#endif hw/uefi/Kconfig +1
-1@@ -1,3 +1,3 @@ config UEFI_VARS bool - default y if X86_64 || AARCH64 + default y if X86_64 || AARCH64 || RISCV64
PATCH v3 5/6 hw/uefi-vars-sysbus: allow for loongarch virt
In reply to Gerd HoffmannAllow the device being added to loongarch virt VMs.
--- hw/loongarch/virt.c | 2 ++ hw/uefi/Kconfig | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
hw/loongarch/virt.c +2 -0
@@ -38,6 +38,7 @@#include "hw/mem/nvdimm.h" #include "hw/platform-bus.h" #include "hw/display/ramfb.h" +#include "hw/uefi/var-service-api.h" #include "hw/mem/pc-dimm.h" #include "system/tpm.h" #include "system/block-backend.h"
@@ -1207,6 +1208,7 @@ static void virt_class_init(ObjectClass *oc, void *data)object_class_property_set_description (oc,"v-eiointc" ,"Enable Virt Extend I/O Interrupt Controller." );machine_class_allow_dynamic_sysbus_dev (mc,TYPE_RAMFB_DEVICE ); +machine_class_allow_dynamic_sysbus_dev (mc,TYPE_UEFI_VARS_SYSBUS );#ifdef CONFIG_TPM machine_class_allow_dynamic_sysbus_dev (mc,TYPE_TPM_TIS_SYSBUS );#endif
hw/uefi/Kconfig +1 -1
@@ -1,3 +1,3 @@ config UEFI_VARS bool - default y if X86_64 || AARCH64 || RISCV64 + default y if X86_64 || AARCH64 || RISCV64 || LOONGARCH64
Signature · 1 line
2.48.1
Re: [PATCH v3 5/6] hw/uefi-vars-sysbus: allow for loongarch virt
Quoted 7 lines · Gerd Hoffmann
Allow the device being added to loongarch virt VMs.
Signed-off-by Gerd Hoffmann <[email protected]>--- hw/loongarch/virt.c | 2 ++ hw/uefi/Kconfig | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
hw/uefi/Kconfig line 3
Quoted 10 lines
hw/uefi/Kconfig +1
-1@@ -1,3 +1,3 @@ config UEFI_VARS bool - default y if X86_64 || AARCH64 || RISCV64 + default y if X86_64 || AARCH64 || RISCV64 || LOONGARCH64
Could fix the missing newline when sending a PULL
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v3 6/6 docs/firmware: add feature flag for host uefi variable store
In reply to Gerd Hoffmann--- docs/interop/firmware.json | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
docs/interop/firmware.json +11 -1
@@ -214,13 +214,23 @@ # PL011 UART. @verbose-static is mutually exclusive # with @verbose-dynamic. # +# @host-uefi-vars: The firmware expects the host to provide an uefi +# variable store. qemu supports that via +# "uefi-vars-sysbus" (aarch64, riscv64, loongarch64) +# or "uefi-vars-x64" (x86_64) devices. The firmware +# will not use flash for nvram. When loading the +# firmware into flash the 'stateless' setup should be +# used. It is recommened to load the firmware into +# memory though. +# # Since: 3.0 ## { 'enum' : 'FirmwareFeature', 'data' : [ 'acpi-s3', 'acpi-s4', 'amd-sev', 'amd-sev-es', 'amd-sev-snp', 'intel-tdx', - 'enrolled-keys', 'requires-smm', 'secure-boot', + 'enrolled-keys', 'requires-smm', + 'secure-boot', 'host-uefi-vars', 'verbose-dynamic', 'verbose-static' ] } ##
Signature · 1 line
2.48.1
Re: [PATCH v3 6/6] docs/firmware: add feature flag for host uefi variable store
Quoted 4 lines · Gerd Hoffmann
Signed-off-by Gerd Hoffmann <[email protected]>--- docs/interop/firmware.json | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|