Fix error handling for callers of load_image_targphys, get_image_size, event_notifier_init, msix_init
PATCH v2 4/4 hw/pci/msix: fix error handling for msix_init callers
In reply to Trieu HuynhFrom: Trieu Huynh <[email protected]>
Check return value of msix_init() and return early on failure instead of continuing with invalid state.
- Use ret < 0 to handle negative return value.
- Use errp parameter to handle failure instead of NULL.
- No functional changes.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
---
v2:
- Use errp parameter to handle failure instead of NULL.
--- hw/net/igbvf.c | 2 +- hw/net/rocker/rocker.c | 2 +- hw/pci/msix.c | 2 +- hw/scsi/megasas.c | 18 +++++++++++++----- hw/usb/hcd-xhci-pci.c | 19 ++++++++++++++----- 5 files changed, 30 insertions(+), 13 deletions(-)
hw/net/igbvf.c +1 -1
@@ -260,7 +260,7 @@ static void igbvf_pci_realize(PCIDevice *dev, Error **errp) ret =msix_init (dev,IGBVF_MSIX_VEC_NUM , &s->msix,IGBVF_MSIX_BAR_IDX ,0 , &s->msix,IGBVF_MSIX_BAR_IDX ,0x2000 ,0x70 , errp); -if (ret) { +if (ret <0 ) {return ; }
hw/net/rocker/rocker.c +1 -1
@@ -1228,7 +1228,7 @@ static int rocker_msix_init(Rocker *r, Error **errp) &r->msix_bar,ROCKER_PCI_MSIX_BAR_IDX ,ROCKER_PCI_MSIX_PBA_OFFSET , 0, errp); -if (err) { +if (err <0 ) {return err; }
hw/pci/msix.c +1 -1
@@ -432,7 +432,7 @@ int msix_init_exclusive_bar(PCIDevice *dev, uint32_t nentries,0 , &dev->msix_exclusive_bar, bar_nr, bar_pba_offset, 0, errp); -if (ret) { +if (ret <0 ) {return ret; }
hw/scsi/megasas.c +13 -5
@@ -2380,11 +2380,19 @@ static void megasas_scsi_realize(PCIDevice *dev, Error **errp)memory_region_init_io (&s->queue_io,OBJECT (s), &megasas_queue_ops, s,"megasas-queue" ,0x40000 ); -if (megasas_use_msix (s) && -msix_init (dev,15 , &s->mmio_io, b->mmio_bar,0x2000 , - &s->mmio_io, b->mmio_bar,0x3800 ,0x68 ,NULL )) { -/* TODO: check msix_init's error, and should fail on msix=on */ - s->msix =ON_OFF_AUTO_OFF ; +if (megasas_use_msix (s)) { +Error *local_err =NULL ; + ret =msix_init (dev,15 , &s->mmio_io, b->mmio_bar,0x2000 , + &s->mmio_io, b->mmio_bar,0x3800 ,0x68 , &local_err); + +if (ret <0 ) { +if (s->msix ==ON_OFF_AUTO_ON ) { +error_propagate (errp, local_err); +return ; + } +error_free (local_err); + s->msix =ON_OFF_AUTO_OFF ; + } }if (pci_is_express (dev)) {
hw/usb/hcd-xhci-pci.c +14 -5
@@ -173,11 +173,20 @@ static void usb_xhci_pci_realize(struct PCIDevice *dev, Error **errp) }if (s->msix !=ON_OFF_AUTO_OFF ) { -/* TODO check for errors, and should fail when msix=on */ -msix_init (dev, s->xhci.numintrs, - &s->xhci.mem,0 ,OFF_MSIX_TABLE , - &s->xhci.mem,0 ,OFF_MSIX_PBA , -0x90 ,NULL ); +Error *local_err =NULL ; + ret =msix_init (dev, s->xhci.numintrs, + &s->xhci.mem,0 ,OFF_MSIX_TABLE , + &s->xhci.mem,0 ,OFF_MSIX_PBA , +0x90 , &local_err); + +if (ret <0 ) { +if (s->msix ==ON_OFF_AUTO_ON ) { +error_propagate (errp, local_err); +return ; + } +error_free (local_err); + s->msix =ON_OFF_AUTO_OFF ; + } } s->xhci.as =pci_get_address_space (dev); }
Signature · 1 line
2.43.0
PATCH v2 1/4 hw/core/loader: fix error handling for load_image_targphys callers
In reply to Trieu HuynhFrom: Trieu Huynh <[email protected]>
Use QEMU's Error API to handle load_image_targphys() failures consistently across callers.
- Use &error_fatal for callers that previously passed NULL, ensuring the process exits early on failure instead of continuing in an invalid state.
- No functional changes.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
---
v2:
- Use &error_fatal instead of manual return value checks.
- Remove redundant checks for ppc callers that already use &error_fatal.
- Note: This replaces the "ret < 0" approach proposed in v1.
--- hw/alpha/dp264.c | 2 +- hw/hppa/machine.c | 2 +- hw/m68k/next-cube.c | 2 +- hw/m68k/q800.c | 2 +- hw/m68k/virt.c | 2 +- hw/microblaze/boot.c | 3 ++- 6 files changed, 7 insertions(+), 6 deletions(-)
hw/alpha/dp264.c +1 -1
@@ -190,7 +190,7 @@ static void clipper_init(MachineState *machine)/* Put the initrd image as high in memory as possible. */ initrd_base = (ram_size - initrd_size) &TARGET_PAGE_MASK ;load_image_targphys (initrd_filename, initrd_base, - ram_size - initrd_base,NULL ); + ram_size - initrd_base, &error_fatal); address_space_stq_le(&address_space_memory, param_offset + 0x100, initrd_base + 0xfffffc0000000000ULL,
hw/hppa/machine.c +1 -1
@@ -507,7 +507,7 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus, }load_image_targphys (initrd_filename, initrd_base, initrd_size, -NULL ); + &error_fatal); cpu[0 ]->env.initrd_base = initrd_base; cpu[0 ]->env.initrd_end = initrd_base + initrd_size; }
hw/m68k/next-cube.c +1 -1
@@ -1326,7 +1326,7 @@ static void next_cube_init(MachineState *machine)memory_region_init_alias (&m->rom2,NULL ,"next.rom2" , &m->rom,0x0 ,0x20000 );memory_region_add_subregion (sysmem,0x0 , &m->rom2); -if (load_image_targphys (bios_name,0x01000000 ,0x20000 ,NULL ) <8 ) { +if (load_image_targphys (bios_name,0x01000000 ,0x20000 , &error_fatal) <8 ) {if (!qtest_enabled ()) {error_report ("Failed to load firmware '%s'." , bios_name); }
hw/m68k/q800.c +1 -1
@@ -633,7 +633,7 @@ static void q800_machine_init(MachineState *machine) initrd_base = (ram_size - initrd_size) &TARGET_PAGE_MASK ;load_image_targphys (initrd_filename, initrd_base, - ram_size - initrd_base,NULL ); + ram_size - initrd_base, &error_fatal);BOOTINFO2 (param_ptr,BI_RAMDISK , initrd_base, initrd_size); }else {
hw/m68k/virt.c +1 -1
@@ -292,7 +292,7 @@ static void virt_init(MachineState *machine) initrd_base = (ram_size - initrd_size) &TARGET_PAGE_MASK ;load_image_targphys (initrd_filename, initrd_base, - ram_size - initrd_base,NULL ); + ram_size - initrd_base, &error_fatal);BOOTINFO2 (param_ptr,BI_RAMDISK , initrd_base, initrd_size); }else {
hw/microblaze/boot.c +2 -1
@@ -38,6 +38,7 @@#include "hw/core/loader.h" #include "elf.h" #include "qemu/cutils.h" +#include "qapi/error.h" #include "boot.h"
@@ -171,7 +172,7 @@ void microblaze_load_kernel(MicroBlazeCPU *cpu, bool is_little_endian,/* Not an ELF image nor an u-boot image, try a RAW image. */ if (kernel_size <0 ) { kernel_size =load_image_targphys (kernel_filename, ddr_base, - ramsize,NULL ); + ramsize, &error_fatal); boot_info.bootstrap_pc = ddr_base; high = (ddr_base + kernel_size +3 ) & ~3 ; }
Signature · 1 line
2.43.0
v2 cover Fix error handling for callers of load_image_targphys, get_image_size, event_notifier_init, msix_init
From: Trieu Huynh <[email protected]>
Changes in v2:
- Patch 1: Remove redundant if (ret < 0) checks added after calls that already use &error_fatal (dead code, pointed out by BALATON Zoltan and Aditya Gupta). Use &error_fatal directly for NULL callers where failure is fatal.
- Patch 2: Fix to only exit when size < 0 since it is not mandatory, either BIOS or FRU (pointed out by Clément Chigot).
- Patch 3: No code changes. Add Acked-by and Reviewed-by tags.
- Patch 4: Use errp param instead of passing NULL as default to handle failure (pointed out by Akihiko Odaki).
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
Trieu Huynh (4):
hw/core/loader: fix error handling for load_image_targphys callers hw/core/loader: fix error handling for get_image_size callers util/event_notifier: fix error handling for event_notifier_init
callers
hw/pci/msix: fix error handling for msix_init callers
hw/alpha/dp264.c | 2 +- hw/hppa/machine.c | 2 +- hw/hyperv/hyperv.c | 4 ++-- hw/hyperv/vmbus.c | 4 ++-- hw/ipmi/ipmi_bmc_sim.c | 2 ++ hw/m68k/next-cube.c | 2 +- hw/m68k/q800.c | 2 +- hw/m68k/virt.c | 2 +- hw/microblaze/boot.c | 3 ++- hw/net/igbvf.c | 2 +- hw/net/rocker/rocker.c | 2 +- hw/pci/msix.c | 2 +- hw/remote/proxy.c | 15 +++++++++++++-- hw/scsi/megasas.c | 18 +++++++++++++----- hw/sparc/leon3.c | 4 ++++ hw/usb/hcd-xhci-pci.c | 19 ++++++++++++++----- hw/vfio/ap.c | 2 +- hw/vfio/ccw.c | 2 +- hw/vfio/pci-quirks.c | 2 +- hw/vfio/pci.c | 2 +- hw/virtio/vhost-vdpa.c | 4 ++-- 21 files changed, 66 insertions(+), 31 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 2/4 hw/core/loader: fix error handling for get_image_size callers
From: Trieu Huynh <[email protected]>
Check the return value of get_image_size() and report failures for non-mandatory files such as BIOS or FRU images.
- Use ret < 0 to detect failures in getting image size.
- No functional changes.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
---
v2:
- Keep error reporting as it is.
- Remove exit on error since it is not mandatory.
--- hw/ipmi/ipmi_bmc_sim.c | 2 ++ hw/sparc/leon3.c | 4 ++++ 2 files changed, 6 insertions(+)
hw/ipmi/ipmi_bmc_sim.c +2 -0
@@ -2561,6 +2561,8 @@ static void ipmi_fru_init(IPMIFru *fru)g_free (fru->data); fru->data =NULL ; } + }else { +error_report ("Could not get file size '%s'" , fru->filename); } out:
hw/sparc/leon3.c +4 -0
@@ -354,6 +354,10 @@ static void leon3_generic_hw_init(MachineState *machine) }else { bios_size =-1 ; } +if (bios_size <0 ) { +error_report ("could not found or failed to get file size: '%s'" , + filename); + }if (bios_size > prom_size) {error_report ("could not load prom '%s': file too big" , filename);
Signature · 1 line
2.43.0
PATCH v2 3/4 util/event_notifier: fix error handling for event_notifier_init callers
In reply to Trieu HuynhFrom: Trieu Huynh <[email protected]>
Check return value of event_notifier_init() and return early on failure instead of continuing with invalid state.
- Use ret < 0 to handle negative return value.
- No functional changes.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
--- hw/hyperv/hyperv.c | 4 ++-- hw/hyperv/vmbus.c | 4 ++-- hw/remote/proxy.c | 15 +++++++++++++-- hw/vfio/ap.c | 2 +- hw/vfio/ccw.c | 2 +- hw/vfio/pci-quirks.c | 2 +- hw/vfio/pci.c | 2 +- hw/virtio/vhost-vdpa.c | 4 ++-- 8 files changed, 23 insertions(+), 12 deletions(-)
hw/hyperv/hyperv.c +2 -2
@@ -439,7 +439,7 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, sint_route->staged_msg->cb_data = cb_data; r =event_notifier_init (ack_notifier, false); -if (r) { +if (r <0 ) { goto cleanup_err_sint; }event_notifier_set_handler (ack_notifier, sint_ack_handler);
@@ -453,7 +453,7 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint,/* We need to setup a GSI for this SintRoute */ r =event_notifier_init (&sint_route->sint_set_notifier, false); -if (r) { +if (r <0 ) { goto cleanup_err_sint; }
hw/hyperv/vmbus.c +2 -2
@@ -1432,7 +1432,7 @@ static void open_channel(VMBusChannel *chan) goto put_gpadl; } -if (event_notifier_init (&chan->notifier,0 )) { +if (event_notifier_init (&chan->notifier,0 ) <0 ) { goto put_gpadl; }
@@ -2450,7 +2450,7 @@ static void vmbus_realize(BusState *bus, Error **errp) } ret =event_notifier_init (&vmbus->notifier,0 ); -if (ret !=0 ) { +if (ret <0 ) {error_setg (errp,"event notifier failed to init with %d" , ret); goto remove_msg_handler; }
hw/remote/proxy.c +13 -2
@@ -52,9 +52,20 @@ static void setup_irqfd(PCIProxyDev *dev)PCIDevice *pci_dev =PCI_DEVICE (dev);MPQemuMsg msg;Error *local_err =NULL ; +int ret =0 ; -event_notifier_init (&dev->intr,0 ); -event_notifier_init (&dev->resample,0 ); + ret =event_notifier_init (&dev->intr,0 ); +if (ret <0 ) { +error_report ("Failed to init intr notifier: %s" ,strerror (-ret)); +return ; + } + + ret =event_notifier_init (&dev->resample,0 ); +if (ret <0 ) { +error_report ("Failed to init resample notifier: %s" ,strerror (-ret)); +event_notifier_cleanup (&dev->intr); +return ; + }memset (&msg,0 ,sizeof (MPQemuMsg)); msg.cmd =MPQEMU_CMD_SET_IRQFD ;
hw/vfio/ap.c +1 -1
@@ -180,7 +180,7 @@ static bool vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,return false; } -if (event_notifier_init (notifier,0 )) { +if (event_notifier_init (notifier,0 ) <0 ) {error_setg_errno (errp, errno,"vfio: Unable to init event notifier for irq (%d)" , irq);
hw/vfio/ccw.c +1 -1
@@ -418,7 +418,7 @@ static bool vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,return false; } -if (event_notifier_init (notifier,0 )) { +if (event_notifier_init (notifier,0 ) <0 ) {error_setg_errno (errp, errno,"vfio: Unable to init event notifier for irq (%d)" , irq);
hw/vfio/pci-quirks.c +1 -1
@@ -318,7 +318,7 @@ static VFIOIOEventFD *vfio_ioeventfd_init(VFIOPCIDevice *vdev, ioeventfd =g_malloc0 (sizeof (*ioeventfd)); -if (event_notifier_init (&ioeventfd->e,0 )) { +if (event_notifier_init (&ioeventfd->e,0 ) <0 ) {g_free (ioeventfd);return NULL ; }
hw/vfio/pci.c +1 -1
@@ -70,7 +70,7 @@ static bool vfio_notifier_init(VFIOPCIDevice *vdev, EventNotifier *e, } ret =event_notifier_init (e,0 ); -if (ret) { +if (ret <0 ) {error_setg_errno (errp, -ret,"vfio_notifier_init %s failed" , name);return false; }
hw/virtio/vhost-vdpa.c +2 -2
@@ -1075,13 +1075,13 @@ static int vhost_vdpa_svq_set_fds(struct vhost_dev *dev,int r; r =event_notifier_init (&svq->hdev_kick,0 ); -if (r !=0 ) { +if (r <0 ) {error_setg_errno (errp, -r,"Couldn't create kick event notifier" ); goto err_init_hdev_kick; } r =event_notifier_init (&svq->hdev_call,0 ); -if (r !=0 ) { +if (r <0 ) {error_setg_errno (errp, -r,"Couldn't create call event notifier" ); goto err_init_hdev_call; }
Signature · 1 line
2.43.0
Re: [PATCH v2 3/4] util/event_notifier: fix error handling for event_notifier_init callers
Quoted 155 lines · Trieu Huynh
From: Trieu Huynh <[email protected]>
Check return value of
event_notifier_init()and return early on failure instead of continuing with invalid state.
- Use ret < 0 to handle negative return value.
- No functional changes.Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
Signed-off-by Trieu Huynh <[email protected]>Acked-by Anthony Krowiak <[email protected]>Reviewed-by Jagannathan Raman <[email protected]>--- hw/hyperv/hyperv.c | 4 ++-- hw/hyperv/vmbus.c | 4 ++-- hw/remote/proxy.c | 15 +++++++++++++-- hw/vfio/ap.c | 2 +- hw/vfio/ccw.c | 2 +- hw/vfio/pci-quirks.c | 2 +- hw/vfio/pci.c | 2 +- hw/virtio/vhost-vdpa.c | 4 ++-- 8 files changed, 23 insertions(+), 12 deletions(-)hw/hyperv/hyperv.c +2
-2@@ -439,7 +439,7 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, sint_route->staged_msg->cb_data = cb_data; r =event_notifier_init (ack_notifier, false); -if (r) { +if (r <0 ) { goto cleanup_err_sint; }event_notifier_set_handler (ack_notifier, sint_ack_handler);@@ -453,7 +453,7 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint,/* We need to setup a GSI for this SintRoute */ r =event_notifier_init (&sint_route->sint_set_notifier, false); -if (r) { +if (r <0 ) { goto cleanup_err_sint; }hw/hyperv/vmbus.c +2
-2@@ -1432,7 +1432,7 @@ static void open_channel(VMBusChannel *chan) goto put_gpadl; } -if (event_notifier_init (&chan->notifier,0 )) { +if (event_notifier_init (&chan->notifier,0 ) <0 ) { goto put_gpadl; }@@ -2450,7 +2450,7 @@ static void vmbus_realize(BusState *bus, Error **errp) } ret =event_notifier_init (&vmbus->notifier,0 ); -if (ret !=0 ) { +if (ret <0 ) {error_setg (errp,"event notifier failed to init with %d" , ret); goto remove_msg_handler; }hw/remote/proxy.c +13
-2@@ -52,9 +52,20 @@ static void setup_irqfd(PCIProxyDev *dev)PCIDevice *pci_dev =PCI_DEVICE (dev);MPQemuMsg msg;Error *local_err =NULL ; +int ret =0 ; -event_notifier_init (&dev->intr,0 ); -event_notifier_init (&dev->resample,0 ); + ret =event_notifier_init (&dev->intr,0 ); +if (ret <0 ) { +error_report ("Failed to init intr notifier: %s" ,strerror (-ret)); +return ; + } + + ret =event_notifier_init (&dev->resample,0 ); +if (ret <0 ) { +error_report ("Failed to init resample notifier: %s" ,strerror (-ret)); +event_notifier_cleanup (&dev->intr); +return ; + }memset (&msg,0 ,sizeof (MPQemuMsg)); msg.cmd =MPQEMU_CMD_SET_IRQFD ;hw/vfio/ap.c +1
-1@@ -180,7 +180,7 @@ static bool vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,return false; } -if (event_notifier_init (notifier,0 )) { +if (event_notifier_init (notifier,0 ) <0 ) {error_setg_errno (errp, errno,"vfio: Unable to init event notifier for irq (%d)" , irq);hw/vfio/ccw.c +1
-1@@ -418,7 +418,7 @@ static bool vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,return false; } -if (event_notifier_init (notifier,0 )) { +if (event_notifier_init (notifier,0 ) <0 ) {error_setg_errno (errp, errno,"vfio: Unable to init event notifier for irq (%d)" , irq);hw/vfio/pci-quirks.c +1
-1@@ -318,7 +318,7 @@ static VFIOIOEventFD *vfio_ioeventfd_init(VFIOPCIDevice *vdev, ioeventfd =g_malloc0 (sizeof (*ioeventfd)); -if (event_notifier_init (&ioeventfd->e,0 )) { +if (event_notifier_init (&ioeventfd->e,0 ) <0 ) {g_free (ioeventfd);return NULL ; }hw/vfio/pci.c +1
-1@@ -70,7 +70,7 @@ static bool vfio_notifier_init(VFIOPCIDevice *vdev, EventNotifier *e, } ret =event_notifier_init (e,0 ); -if (ret) { +if (ret <0 ) {error_setg_errno (errp, -ret,"vfio_notifier_init %s failed" , name);return false; }hw/virtio/vhost-vdpa.c +1
-1@@ -1075,13 +1075,13 @@ static int vhost_vdpa_svq_set_fds(struct vhost_dev *dev,int r; r =event_notifier_init (&svq->hdev_kick,0 ); -if (r !=0 ) { +if (r <0 ) {
hw/virtio/vhost-vdpa.c static int vhost_vdpa_svq_set_fds(struct vhost_dev *dev, · line 1087
Quoted 10 lines
hw/virtio/vhost-vdpa.c +1
-1error_setg_errno (errp, -r,"Couldn't create kick event notifier" ); goto err_init_hdev_kick; } r =event_notifier_init (&svq->hdev_call,0 ); -if (r !=0 ) { +if (r <0 ) {error_setg_errno (errp, -r,"Couldn't create call event notifier" ); goto err_init_hdev_call; }
Thanks,
C.
Re: [PATCH v2 2/4] hw/core/loader: fix error handling for get_image_size callers
In reply to Trieu HuynhQuoted 39 lines · Trieu Huynh
From: Trieu Huynh <[email protected]>
Check the return value of
get_image_size()and report failures for non-mandatory files such as BIOS or FRU images.- Use ret < 0 to detect failures in getting image size.
- No functional changes.Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
Signed-off-by Trieu Huynh <[email protected]>---
v2:
- Keep error reporting as it is.
- Remove exit on error since it is not mandatory.--- hw/ipmi/ipmi_bmc_sim.c | 2 ++ hw/sparc/leon3.c | 4 ++++ 2 files changed, 6 insertions(+)hw/ipmi/ipmi_bmc_sim.c +2
-0@@ -2561,6 +2561,8 @@ static void ipmi_fru_init(IPMIFru *fru)g_free (fru->data); fru->data =NULL ; } + }else { +error_report ("Could not get file size '%s'" , fru->filename); } out:hw/sparc/leon3.c +0
-0
hw/sparc/leon3.c static void leon3_generic_hw_init(MachineState *machine) · line 360
Quoted 7 lines
hw/sparc/leon3.c +4
-0@@ -354,6 +354,10 @@ static void leon3_generic_hw_init(MachineState *machine) }else { bios_size =-1 ; } +if (bios_size <0 ) { +error_report ("could not found or failed to get file size: '%s'" , + filename); + }
Honestly, I'm not sure what improvements that brings. This warning is meaningless for Baremetal programs (launched without bios). Moreover, an error handling is already there if "bios_size < 0" and -kernel is not provided (just below).
A better approach could be to add support for "-bios none". With the whole bios handling section (from "Allocate BIOS" up to "g_free(filename);") could be wrapped under "if -bios != none". But that differs slightly from your initial goal. So up to you.
Quoted 5 lines
hw/sparc/leon3.c +0
-1if (bios_size > prom_size) {error_report ("could not load prom '%s': file too big" , filename); --2.43.0
Re: [PATCH v2 1/4] hw/core/loader: fix error handling for load_image_targphys callers
In reply to Trieu HuynhQuoted 12 lines · Trieu Huynh
From: Trieu Huynh <[email protected]>
Use QEMU's Error API to handle
load_image_targphys()failures consistently across callers.- Use
&error_fatalfor callers that previously passed NULL, ensuring the process exits early on failure instead of continuing in an invalid state.
- No functional changes.
Quoted 8 lines
Signed-off-by Trieu Huynh <[email protected]>---
v2:
- Use&error_fatalinstead of manual return value checks.
- Remove redundant checks for ppc callers that already use&error_fatal.
- Note: This replaces the "ret < 0" approach proposed in v1.
Hi; this patch breaks "make check" for me:
13/1040 qtest+qtest-m68k - qemu:qtest-m68k/qom-test
ERROR 1.35s killed by signal 6 SIGABRT
113/1040 qtest+qtest-m68k - qemu:qtest-m68k/test-hmp
ERROR 1.36s killed by signal 6 SIGABRT
This is because these tests check that every machine can be started without errors (when run with the 'qtest' accelerator), and now next-cube cannot:
$ ./build/clang/qemu-system-m68k -display none -machine next-cube -accel qtest qemu-system-m68k: Could not open 'Rev_2.5_v66.bin': No such file or directory
Where the machine init code is calling load_image_targphys() because the user passed in a particular filename to load, then we definitely want to use error_fatal. But some of these cases use these codepaths for "try to load the default BIOS filename" and rely on ignoring the error if it doesn't actually exist.
I think of the machines you change here, only next-cube has this issue, and that change has other problems:
hw/m68k/next-cube.c static void next_cube_init(MachineState *machine) · line 1329
Quoted 10 lines
hw/m68k/next-cube.c +1
-1@@ -1326,7 +1326,7 @@ static void next_cube_init(MachineState *machine)memory_region_init_alias (&m->rom2,NULL ,"next.rom2" , &m->rom,0x0 ,0x20000 );memory_region_add_subregion (sysmem,0x0 , &m->rom2); -if (load_image_targphys (bios_name,0x01000000 ,0x20000 ,NULL ) <8 ) { +if (load_image_targphys (bios_name,0x01000000 ,0x20000 , &error_fatal) <8 ) {
We were already doing an error check here, by looking at the return value and insisting it was at least 8 bytes.
hw/m68k/next-cube.c static void next_cube_init(MachineState *machine) · line 1331
Quoted 2 lines
hw/m68k/next-cube.c +0
-0if (!qtest_enabled ()) {error_report ("Failed to load firmware '%s'." , bios_name);
We could if we liked report the error to the user, by passing an Error* to load_image_targphys(), reporting the error if it is set, and otherwise reporting "file too short" (since that's the other reason we'll get here).
The reason for the !qtest_enabled() here, by the way, is to get the "report this error to the user if run in the normal way, but don't report the error if this is one of the tests that is doing the "check every machine can be started" test.)
hw/m68k/next-cube.c static void next_cube_init(MachineState *machine) · line 1332
Quoted 1 line
hw/m68k/next-cube.c +0
-0}
thanks
-- PMM
Re: [PATCH v2 4/4] hw/pci/msix: fix error handling for msix_init callers
In reply to Trieu HuynhQuoted 72 lines · Trieu Huynh
From: Trieu Huynh <[email protected]>
Check return value of
msix_init()and return early on failure instead of continuing with invalid state.
- Use ret < 0 to handle negative return value.
- Use errp parameter to handle failure instead of NULL.
- No functional changes.Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
Signed-off-by Trieu Huynh <[email protected]>---
v2:
- Use errp parameter to handle failure instead of NULL.--- hw/net/igbvf.c | 2 +- hw/net/rocker/rocker.c | 2 +- hw/pci/msix.c | 2 +- hw/scsi/megasas.c | 18 +++++++++++++----- hw/usb/hcd-xhci-pci.c | 19 ++++++++++++++----- 5 files changed, 30 insertions(+), 13 deletions(-)hw/net/igbvf.c +1
-1@@ -260,7 +260,7 @@ static void igbvf_pci_realize(PCIDevice *dev, Error **errp) ret =msix_init (dev,IGBVF_MSIX_VEC_NUM , &s->msix,IGBVF_MSIX_BAR_IDX ,0 , &s->msix,IGBVF_MSIX_BAR_IDX ,0x2000 ,0x70 , errp); -if (ret) { +if (ret <0 ) {return ; }hw/net/rocker/rocker.c +1
-1@@ -1228,7 +1228,7 @@ static int rocker_msix_init(Rocker *r, Error **errp) &r->msix_bar,ROCKER_PCI_MSIX_BAR_IDX ,ROCKER_PCI_MSIX_PBA_OFFSET , 0, errp); -if (err) { +if (err <0 ) {return err; }hw/pci/msix.c +1
-1@@ -432,7 +432,7 @@ int msix_init_exclusive_bar(PCIDevice *dev, uint32_t nentries,0 , &dev->msix_exclusive_bar, bar_nr, bar_pba_offset, 0, errp); -if (ret) { +if (ret <0 ) {return ret; }hw/scsi/megasas.c +0
-3@@ -2380,11 +2380,19 @@ static void megasas_scsi_realize(PCIDevice *dev, Error **errp)memory_region_init_io (&s->queue_io,OBJECT (s), &megasas_queue_ops, s,"megasas-queue" ,0x40000 ); -if (megasas_use_msix (s) && -msix_init (dev,15 , &s->mmio_io, b->mmio_bar,0x2000 , - &s->mmio_io, b->mmio_bar,0x3800 ,0x68 ,NULL )) {
hw/scsi/megasas.c static void megasas_scsi_realize(PCIDevice *dev, Error **errp) · line 2390
Quoted 10 lines
hw/scsi/megasas.c +8
-2-/* TODO: check msix_init's error, and should fail on msix=on */ - s->msix =ON_OFF_AUTO_OFF ; +if (megasas_use_msix (s)) { +Error *local_err =NULL ; + ret =msix_init (dev,15 , &s->mmio_io, b->mmio_bar,0x2000 , + &s->mmio_io, b->mmio_bar,0x3800 ,0x68 , &local_err); + +if (ret <0 ) { +if (s->msix ==ON_OFF_AUTO_ON ) { +error_propagate (errp, local_err);
error_propagate() is discouraged in include/qapi/error.h because ERRP_GUARD() exists as an alternative so I thought of using it, but perhaps it may be a better to avoid having a local error variable altogether.
Instead, you can pass (s->msix == ON_OF_AUTO_ON ? errp : NULL) to msix_init() as the errp parameter.
Regards,
Akihiko Odaki
Quoted 38 lines
hw/scsi/megasas.c +5
-0+return ; + } +error_free (local_err); + s->msix =ON_OFF_AUTO_OFF ; + } }if (pci_is_express (dev)) {hw/usb/hcd-xhci-pci.c +14
-5@@ -173,11 +173,20 @@ static void usb_xhci_pci_realize(struct PCIDevice *dev, Error **errp) }if (s->msix !=ON_OFF_AUTO_OFF ) { -/* TODO check for errors, and should fail when msix=on */ -msix_init (dev, s->xhci.numintrs, - &s->xhci.mem,0 ,OFF_MSIX_TABLE , - &s->xhci.mem,0 ,OFF_MSIX_PBA , -0x90 ,NULL ); +Error *local_err =NULL ; + ret =msix_init (dev, s->xhci.numintrs, + &s->xhci.mem,0 ,OFF_MSIX_TABLE , + &s->xhci.mem,0 ,OFF_MSIX_PBA , +0x90 , &local_err); + +if (ret <0 ) { +if (s->msix ==ON_OFF_AUTO_ON ) { +error_propagate (errp, local_err); +return ; + } +error_free (local_err); + s->msix =ON_OFF_AUTO_OFF ; + } } s->xhci.as =pci_get_address_space (dev); }
Re: [PATCH v2 3/4] util/event_notifier: fix error handling for event_notifier_init callers
In reply to Trieu HuynhQuoted 58 lines · Trieu Huynh
From: Trieu Huynh <[email protected]>
Check return value of
event_notifier_init()and return early on failure instead of continuing with invalid state.
- Use ret < 0 to handle negative return value.
- No functional changes.Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
Signed-off-by Trieu Huynh <[email protected]>Acked-by Anthony Krowiak <[email protected]>Reviewed-by Jagannathan Raman <[email protected]>--- hw/hyperv/hyperv.c | 4 ++-- hw/hyperv/vmbus.c | 4 ++-- hw/remote/proxy.c | 15 +++++++++++++-- hw/vfio/ap.c | 2 +- hw/vfio/ccw.c | 2 +- hw/vfio/pci-quirks.c | 2 +- hw/vfio/pci.c | 2 +- hw/virtio/vhost-vdpa.c | 4 ++-- 8 files changed, 23 insertions(+), 12 deletions(-)hw/hyperv/hyperv.c +2
-2@@ -439,7 +439,7 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, sint_route->staged_msg->cb_data = cb_data; r =event_notifier_init (ack_notifier, false); -if (r) { +if (r <0 ) { goto cleanup_err_sint; }event_notifier_set_handler (ack_notifier, sint_ack_handler);@@ -453,7 +453,7 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint,/* We need to setup a GSI for this SintRoute */ r =event_notifier_init (&sint_route->sint_set_notifier, false); -if (r) { +if (r <0 ) { goto cleanup_err_sint; }hw/hyperv/vmbus.c +1
-1@@ -1432,7 +1432,7 @@ static void open_channel(VMBusChannel *chan) goto put_gpadl; } -if (event_notifier_init (&chan->notifier,0 )) { +if (event_notifier_init (&chan->notifier,0 ) <0 ) { goto put_gpadl; }
hw/hyperv/vmbus.c static void vmbus_realize(BusState *bus, Error **errp) · line 2456
Quoted 8 lines
hw/hyperv/vmbus.c +1
-1@@ -2450,7 +2450,7 @@ static void vmbus_realize(BusState *bus, Error **errp) } ret =event_notifier_init (&vmbus->notifier,0 ); -if (ret !=0 ) { +if (ret <0 ) {error_setg (errp,"event notifier failed to init with %d" , ret); goto remove_msg_handler; }
Thanks,
Maciej
Re: [PATCH v2 3/4] util/event_notifier: fix error handling for event_notifier_init callers
In reply to Trieu HuynhQuoted 22 lines · Trieu Huynh
From: Trieu Huynh <[email protected]>
Check return value of
event_notifier_init()and return early on failure instead of continuing with invalid state.
- Use ret < 0 to handle negative return value.
- No functional changes.Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
Signed-off-by Trieu Huynh <[email protected]>Acked-by Anthony Krowiak <[email protected]>Reviewed-by Jagannathan Raman <[email protected]>--- hw/hyperv/hyperv.c | 4 ++-- hw/hyperv/vmbus.c | 4 ++-- hw/remote/proxy.c | 15 +++++++++++++-- hw/vfio/ap.c | 2 +- hw/vfio/ccw.c | 2 +- hw/vfio/pci-quirks.c | 2 +- hw/vfio/pci.c | 2 +- hw/virtio/vhost-vdpa.c | 4 ++-- 8 files changed, 23 insertions(+), 12 deletions(-)
[...]
Quoted 20 lines
memset(&msg, 0, sizeof(MPQemuMsg)); msg.cmd = MPQEMU_CMD_SET_IRQFD;hw/vfio/ap.c +1
-1@@ -180,7 +180,7 @@ static bool vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,return false; } -if (event_notifier_init (notifier,0 )) { +if (event_notifier_init (notifier,0 ) <0 ) {error_setg_errno (errp, errno,"vfio: Unable to init event notifier for irq (%d)" , irq);hw/vfio/ccw.c +0
-0
hw/vfio/ccw.c static bool vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev, · line 424
Quoted 8 lines
hw/vfio/ccw.c +1
-1@@ -418,7 +418,7 @@ static bool vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,return false; } -if (event_notifier_init (notifier,0 )) { +if (event_notifier_init (notifier,0 ) <0 ) {error_setg_errno (errp, errno,"vfio: Unable to init event notifier for irq (%d)" , irq);
PATCH v3 1/4 hw/core/loader: fix error handling for load_image_targphys callers
In reply to Trieu HuynhUse QEMU's Error API to handle load_image_targphys() failures consistently across callers.
- Use &error_fatal for callers that previously passed NULL, ensuring the process exits early on failure instead of continuing in an invalid state.
- No functional changes.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
--- hw/alpha/dp264.c | 2 +- hw/hppa/machine.c | 2 +- hw/m68k/next-cube.c | 11 +++++++++-- hw/m68k/q800.c | 2 +- hw/m68k/virt.c | 2 +- hw/microblaze/boot.c | 3 ++- 6 files changed, 15 insertions(+), 7 deletions(-)
hw/alpha/dp264.c +1 -1
@@ -190,7 +190,7 @@ static void clipper_init(MachineState *machine)/* Put the initrd image as high in memory as possible. */ initrd_base = (ram_size - initrd_size) &TARGET_PAGE_MASK ;load_image_targphys (initrd_filename, initrd_base, - ram_size - initrd_base,NULL ); + ram_size - initrd_base, &error_fatal); address_space_stq_le(&address_space_memory, param_offset + 0x100, initrd_base + 0xfffffc0000000000ULL,
hw/hppa/machine.c +1 -1
@@ -507,7 +507,7 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus, }load_image_targphys (initrd_filename, initrd_base, initrd_size, -NULL ); + &error_fatal); cpu[0 ]->env.initrd_base = initrd_base; cpu[0 ]->env.initrd_end = initrd_base + initrd_size; }
hw/m68k/next-cube.c +9 -2
@@ -1326,9 +1326,16 @@ static void next_cube_init(MachineState *machine)memory_region_init_alias (&m->rom2,NULL ,"next.rom2" , &m->rom,0x0 ,0x20000 );memory_region_add_subregion (sysmem,0x0 , &m->rom2); -if (load_image_targphys (bios_name,0x01000000 ,0x20000 ,NULL ) <8 ) { +Error *local_err =NULL ; +if (load_image_targphys (bios_name,0x01000000 ,0x20000 , &local_err) <8 ) {if (!qtest_enabled ()) { -error_report ("Failed to load firmware '%s'." , bios_name); +if (local_err) { +error_report_err (local_err); + }else { +error_report ("Firmware image '%s' is too short." , bios_name); + } + }else { +error_free (local_err); } }else {uint8_t *ptr;
hw/m68k/q800.c +1 -1
@@ -633,7 +633,7 @@ static void q800_machine_init(MachineState *machine) initrd_base = (ram_size - initrd_size) &TARGET_PAGE_MASK ;load_image_targphys (initrd_filename, initrd_base, - ram_size - initrd_base,NULL ); + ram_size - initrd_base, &error_fatal);BOOTINFO2 (param_ptr,BI_RAMDISK , initrd_base, initrd_size); }else {
hw/m68k/virt.c +1 -1
@@ -292,7 +292,7 @@ static void virt_init(MachineState *machine) initrd_base = (ram_size - initrd_size) &TARGET_PAGE_MASK ;load_image_targphys (initrd_filename, initrd_base, - ram_size - initrd_base,NULL ); + ram_size - initrd_base, &error_fatal);BOOTINFO2 (param_ptr,BI_RAMDISK , initrd_base, initrd_size); }else {
hw/microblaze/boot.c +2 -1
@@ -38,6 +38,7 @@#include "hw/core/loader.h" #include "elf.h" #include "qemu/cutils.h" +#include "qapi/error.h" #include "boot.h"
@@ -171,7 +172,7 @@ void microblaze_load_kernel(MicroBlazeCPU *cpu, bool is_little_endian,/* Not an ELF image nor an u-boot image, try a RAW image. */ if (kernel_size <0 ) { kernel_size =load_image_targphys (kernel_filename, ddr_base, - ramsize,NULL ); + ramsize, &error_fatal); boot_info.bootstrap_pc = ddr_base; high = (ddr_base + kernel_size +3 ) & ~3 ; }
Signature · 1 line
2.43.0
PATCH v3 2/4 hw/core/loader: fix error handling for get_image_size callers
In reply to Trieu HuynhCheck the return value of get_image_size() and report failures for non-mandatory file such as FRU image.
- Use ret < 0 to detect failures in getting image size.
- No functional changes.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
--- hw/ipmi/ipmi_bmc_sim.c | 2 ++ 1 file changed, 2 insertions(+)
hw/ipmi/ipmi_bmc_sim.c +2 -0
@@ -2561,6 +2561,8 @@ static void ipmi_fru_init(IPMIFru *fru)g_free (fru->data); fru->data =NULL ; } + }else { +error_report ("Could not get file size '%s'" , fru->filename); } out:
Signature · 1 line
2.43.0
PATCH v3 3/4 util/event_notifier: fix error handling for event_notifier_init callers
In reply to Trieu HuynhCheck return value of event_notifier_init() and return early on failure instead of continuing with invalid state.
- Use ret < 0 to handle negative return value.
- No functional changes.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
--- hw/hyperv/hyperv.c | 4 ++-- hw/hyperv/vmbus.c | 4 ++-- hw/remote/proxy.c | 15 +++++++++++++-- hw/vfio/ap.c | 2 +- hw/vfio/ccw.c | 2 +- hw/vfio/pci-quirks.c | 2 +- hw/vfio/pci.c | 2 +- hw/virtio/vhost-vdpa.c | 4 ++-- 8 files changed, 23 insertions(+), 12 deletions(-)
hw/hyperv/hyperv.c +2 -2
@@ -439,7 +439,7 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, sint_route->staged_msg->cb_data = cb_data; r =event_notifier_init (ack_notifier, false); -if (r) { +if (r <0 ) { goto cleanup_err_sint; }event_notifier_set_handler (ack_notifier, sint_ack_handler);
@@ -453,7 +453,7 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint,/* We need to setup a GSI for this SintRoute */ r =event_notifier_init (&sint_route->sint_set_notifier, false); -if (r) { +if (r <0 ) { goto cleanup_err_sint; }
hw/hyperv/vmbus.c +2 -2
@@ -1432,7 +1432,7 @@ static void open_channel(VMBusChannel *chan) goto put_gpadl; } -if (event_notifier_init (&chan->notifier,0 )) { +if (event_notifier_init (&chan->notifier,0 ) <0 ) { goto put_gpadl; }
@@ -2450,7 +2450,7 @@ static void vmbus_realize(BusState *bus, Error **errp) } ret =event_notifier_init (&vmbus->notifier,0 ); -if (ret !=0 ) { +if (ret <0 ) {error_setg (errp,"event notifier failed to init with %d" , ret); goto remove_msg_handler; }
hw/remote/proxy.c +13 -2
@@ -52,9 +52,20 @@ static void setup_irqfd(PCIProxyDev *dev)PCIDevice *pci_dev =PCI_DEVICE (dev);MPQemuMsg msg;Error *local_err =NULL ; +int ret =0 ; -event_notifier_init (&dev->intr,0 ); -event_notifier_init (&dev->resample,0 ); + ret =event_notifier_init (&dev->intr,0 ); +if (ret <0 ) { +error_report ("Failed to init intr notifier: %s" ,strerror (-ret)); +return ; + } + + ret =event_notifier_init (&dev->resample,0 ); +if (ret <0 ) { +error_report ("Failed to init resample notifier: %s" ,strerror (-ret)); +event_notifier_cleanup (&dev->intr); +return ; + }memset (&msg,0 ,sizeof (MPQemuMsg)); msg.cmd =MPQEMU_CMD_SET_IRQFD ;
hw/vfio/ap.c +1 -1
@@ -180,7 +180,7 @@ static bool vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,return false; } -if (event_notifier_init (notifier,0 )) { +if (event_notifier_init (notifier,0 ) <0 ) {error_setg_errno (errp, errno,"vfio: Unable to init event notifier for irq (%d)" , irq);
hw/vfio/ccw.c +1 -1
@@ -418,7 +418,7 @@ static bool vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,return false; } -if (event_notifier_init (notifier,0 )) { +if (event_notifier_init (notifier,0 ) <0 ) {error_setg_errno (errp, errno,"vfio: Unable to init event notifier for irq (%d)" , irq);
hw/vfio/pci-quirks.c +1 -1
@@ -318,7 +318,7 @@ static VFIOIOEventFD *vfio_ioeventfd_init(VFIOPCIDevice *vdev, ioeventfd =g_malloc0 (sizeof (*ioeventfd)); -if (event_notifier_init (&ioeventfd->e,0 )) { +if (event_notifier_init (&ioeventfd->e,0 ) <0 ) {g_free (ioeventfd);return NULL ; }
hw/vfio/pci.c +1 -1
@@ -70,7 +70,7 @@ static bool vfio_notifier_init(VFIOPCIDevice *vdev, EventNotifier *e, } ret =event_notifier_init (e,0 ); -if (ret) { +if (ret <0 ) {error_setg_errno (errp, -ret,"vfio_notifier_init %s failed" , name);return false; }
hw/virtio/vhost-vdpa.c +2 -2
@@ -1075,13 +1075,13 @@ static int vhost_vdpa_svq_set_fds(struct vhost_dev *dev,int r; r =event_notifier_init (&svq->hdev_kick,0 ); -if (r !=0 ) { +if (r <0 ) {error_setg_errno (errp, -r,"Couldn't create kick event notifier" ); goto err_init_hdev_kick; } r =event_notifier_init (&svq->hdev_call,0 ); -if (r !=0 ) { +if (r <0 ) {error_setg_errno (errp, -r,"Couldn't create call event notifier" ); goto err_init_hdev_call; }
Signature · 1 line
2.43.0
PATCH v3 4/4 hw/pci/msix: fix error handling for msix_init callers
In reply to Trieu HuynhCheck return value of msix_init() and return early on failure instead of continuing with invalid state.
- Use ret < 0 to handle negative return value.
- Use errp parameter to handle failure instead of NULL.
- No functional changes.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
--- hw/net/igbvf.c | 2 +- hw/net/rocker/rocker.c | 2 +- hw/pci/msix.c | 2 +- hw/scsi/megasas.c | 16 +++++++++++----- hw/usb/hcd-xhci-pci.c | 16 +++++++++++----- 5 files changed, 25 insertions(+), 13 deletions(-)
hw/net/igbvf.c +1 -1
@@ -260,7 +260,7 @@ static void igbvf_pci_realize(PCIDevice *dev, Error **errp) ret =msix_init (dev,IGBVF_MSIX_VEC_NUM , &s->msix,IGBVF_MSIX_BAR_IDX ,0 , &s->msix,IGBVF_MSIX_BAR_IDX ,0x2000 ,0x70 , errp); -if (ret) { +if (ret <0 ) {return ; }
hw/net/rocker/rocker.c +1 -1
@@ -1228,7 +1228,7 @@ static int rocker_msix_init(Rocker *r, Error **errp) &r->msix_bar,ROCKER_PCI_MSIX_BAR_IDX ,ROCKER_PCI_MSIX_PBA_OFFSET , 0, errp); -if (err) { +if (err <0 ) {return err; }
hw/pci/msix.c +1 -1
@@ -432,7 +432,7 @@ int msix_init_exclusive_bar(PCIDevice *dev, uint32_t nentries,0 , &dev->msix_exclusive_bar, bar_nr, bar_pba_offset, 0, errp); -if (ret) { +if (ret <0 ) {return ret; }
hw/scsi/megasas.c +11 -5
@@ -2380,11 +2380,17 @@ static void megasas_scsi_realize(PCIDevice *dev, Error **errp)memory_region_init_io (&s->queue_io,OBJECT (s), &megasas_queue_ops, s,"megasas-queue" ,0x40000 ); -if (megasas_use_msix (s) && -msix_init (dev,15 , &s->mmio_io, b->mmio_bar,0x2000 , - &s->mmio_io, b->mmio_bar,0x3800 ,0x68 ,NULL )) { -/* TODO: check msix_init's error, and should fail on msix=on */ - s->msix =ON_OFF_AUTO_OFF ; +if (megasas_use_msix (s)) { + ret =msix_init (dev,15 , &s->mmio_io, b->mmio_bar,0x2000 , + &s->mmio_io, b->mmio_bar,0x3800 ,0x68 , + s->msix ==ON_OFF_AUTO_ON ? errp :NULL ); + +if (ret <0 ) { +if (s->msix ==ON_OFF_AUTO_ON ) { +return ; + } + s->msix =ON_OFF_AUTO_OFF ; + } }if (pci_is_express (dev)) {
hw/usb/hcd-xhci-pci.c +11 -5
@@ -173,11 +173,17 @@ static void usb_xhci_pci_realize(struct PCIDevice *dev, Error **errp) }if (s->msix !=ON_OFF_AUTO_OFF ) { -/* TODO check for errors, and should fail when msix=on */ -msix_init (dev, s->xhci.numintrs, - &s->xhci.mem,0 ,OFF_MSIX_TABLE , - &s->xhci.mem,0 ,OFF_MSIX_PBA , -0x90 ,NULL ); + ret =msix_init (dev, s->xhci.numintrs, + &s->xhci.mem,0 ,OFF_MSIX_TABLE , + &s->xhci.mem,0 ,OFF_MSIX_PBA , +0x90 , s->msix ==ON_OFF_AUTO_ON ? errp :NULL ); + +if (ret <0 ) { +if (s->msix ==ON_OFF_AUTO_ON ) { +return ; + } + s->msix =ON_OFF_AUTO_OFF ; + } } s->xhci.as =pci_get_address_space (dev); }
Signature · 1 line
2.43.0
v3 cover Fix error handling for callers of load_image_targphys, get_image_size, event_notifier_init, msix_init
In reply to Trieu HuynhChanges in v3:
- Patch 1: For next-cube, use a local Error* instead of &error_fatal so that load failures are reported only when !qtest_enabled(), matching the existing guard. Distinguishes "file not found" (error set) from "file too short" (no error, size < 8) in next-cube. (pointed out by Peter Maydell)
- Patch 2: Drop leon3.c change: warning is meaningless for baremetal programs where no BIOS is expected, and error handling already exists downstream. (pointed out by Clément Chigot)
- Patch 3: No code changes. Add Reviewed-by tags.
- Patch 4: Replace error_propagate() with conditional errp passing:
(s->msix == ON_OFF_AUTO_ON ? errp : NULL), avoiding the need for a local error variable. (pointed out by Akihiko Odaki)
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
Trieu Huynh (4):
hw/core/loader: fix error handling for load_image_targphys callers hw/core/loader: fix error handling for get_image_size callers util/event_notifier: fix error handling for event_notifier_init
callers
hw/pci/msix: fix error handling for msix_init callers
hw/alpha/dp264.c | 2 +- hw/hppa/machine.c | 2 +- hw/hyperv/hyperv.c | 4 ++-- hw/hyperv/vmbus.c | 4 ++-- hw/ipmi/ipmi_bmc_sim.c | 2 ++ hw/m68k/next-cube.c | 11 +++++++++-- hw/m68k/q800.c | 2 +- hw/m68k/virt.c | 2 +- hw/microblaze/boot.c | 3 ++- hw/net/igbvf.c | 2 +- hw/net/rocker/rocker.c | 2 +- hw/pci/msix.c | 2 +- hw/remote/proxy.c | 15 +++++++++++++-- hw/scsi/megasas.c | 16 +++++++++++----- hw/usb/hcd-xhci-pci.c | 16 +++++++++++----- hw/vfio/ap.c | 2 +- hw/vfio/ccw.c | 2 +- hw/vfio/pci-quirks.c | 2 +- hw/vfio/pci.c | 2 +- hw/virtio/vhost-vdpa.c | 4 ++-- 20 files changed, 65 insertions(+), 32 deletions(-)
Signature · 1 line
2.43.0