Skip to contentSkip to conversation

Fix error handling for callers of

PATCH Superseded Trieu Huynh 8 participants 15 messages Mar 10 – Mar 11

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Fix error handling for callers of

From: Trieu Huynh <[email protected]>

This series audits callers of load_image_targphys(), get_image_size(), event_notifier_init(), and msix_init() as discussed in issue #413. The callers are updated to cover negative return value instead of continuing with invalid state or failure.

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       |  8 ++++++--
 hw/hppa/machine.c      |  7 +++++--
 hw/hyperv/hyperv.c     |  4 ++--
 hw/hyperv/vmbus.c      |  4 ++--
 hw/ipmi/ipmi_bmc_sim.c |  2 ++
 hw/m68k/next-cube.c    |  9 ++++++++-
 hw/m68k/q800.c         |  7 +++++--
 hw/m68k/virt.c         |  7 +++++--
 hw/microblaze/boot.c   |  4 ++++
 hw/net/igbvf.c         |  2 +-
 hw/net/rocker/rocker.c |  2 +-
 hw/pci/msix.c          |  2 +-
 hw/ppc/amigaone.c      |  9 +++++++++
 hw/ppc/e500.c          | 10 ++++++++++
 hw/ppc/mac_newworld.c  | 10 ++++++++++
 hw/ppc/mac_oldworld.c  | 10 ++++++++++
 hw/ppc/pegasos.c       |  5 +++++
 hw/ppc/pnv.c           | 20 ++++++++++++++++----
 hw/ppc/ppc440_bamboo.c |  4 ++++
 hw/ppc/prep.c          | 10 ++++++++++
 hw/ppc/sam460ex.c      |  5 +++++
 hw/ppc/spapr.c         |  8 ++++++++
 hw/ppc/virtex_ml507.c  |  9 +++++++++
 hw/remote/proxy.c      | 15 +++++++++++++--
 hw/scsi/megasas.c      | 16 +++++++++++-----
 hw/sparc/leon3.c       |  5 +++++
 hw/usb/hcd-xhci-pci.c  | 17 ++++++++++++-----
 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 ++--
 32 files changed, 185 insertions(+), 38 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/4 hw/core/loader: fix error handling for load_image_targphys callers

From: Trieu Huynh <[email protected]>

Check return value of load_image_targphys() 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/alpha/dp264.c       |  8 ++++++--
 hw/hppa/machine.c      |  7 +++++--
 hw/m68k/next-cube.c    |  9 ++++++++-
 hw/m68k/q800.c         |  7 +++++--
 hw/m68k/virt.c         |  7 +++++--
 hw/microblaze/boot.c   |  4 ++++
 hw/ppc/amigaone.c      |  9 +++++++++
 hw/ppc/e500.c          | 10 ++++++++++
 hw/ppc/mac_newworld.c  | 10 ++++++++++
 hw/ppc/mac_oldworld.c  | 10 ++++++++++
 hw/ppc/pegasos.c       |  5 +++++
 hw/ppc/pnv.c           | 20 ++++++++++++++++----
 hw/ppc/ppc440_bamboo.c |  4 ++++
 hw/ppc/prep.c          | 10 ++++++++++
 hw/ppc/sam460ex.c      |  5 +++++
 hw/ppc/spapr.c         |  8 ++++++++
 hw/ppc/virtex_ml507.c  |  9 +++++++++
 17 files changed, 129 insertions(+), 13 deletions(-)
hw/alpha/dp264.c +6 -2
index 98219f0456..830d14a509 100644
@@ -189,8 +189,12 @@ 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);
+            if (load_image_targphys(initrd_filename, initrd_base,
+                                ram_size - initrd_base, NULL) < 0) {
+                error_report("could not load initrd '%s'",
+                             initrd_filename);
+                exit(1);
+            }
 
             address_space_stq_le(&address_space_memory, param_offset + 0x100,
                                  initrd_base + 0xfffffc0000000000ULL,
hw/hppa/machine.c +5 -2
index f55e84529f..0bf3bccb07 100644
@@ -507,8 +507,11 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus,
                 exit(1);
             }
 
-            load_image_targphys(initrd_filename, initrd_base, initrd_size,
-                                NULL);
+            if (load_image_targphys(initrd_filename, initrd_base, initrd_size,
+                                NULL) < 0) {
+                error_report("Could not load initrd '%s'", initrd_filename);
+                exit(1);
+            }
             cpu[0]->env.initrd_base = initrd_base;
             cpu[0]->env.initrd_end  = initrd_base + initrd_size;
         }
hw/m68k/next-cube.c +8 -1
index 26177c7b86..77a88d1dde 100644
@@ -1326,7 +1326,14 @@ 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) {
+    int bios_size = 0;
+    bios_size = load_image_targphys(bios_name, 0x01000000, 0x20000, NULL);
+    if (bios_size <  0) {
+        /* Shoud report failure and exit regardless of qtest enabled or not */
+        error_report("Failed to load firmware (bios size < 0) '%s'.",
+                     bios_name);
+        exit(1);
+    } else if (bios_size < 8) {
         if (!qtest_enabled()) {
             error_report("Failed to load firmware '%s'.", bios_name);
         }
hw/m68k/q800.c +5 -2
index ded531394e..3266617ad7 100644
@@ -632,8 +632,11 @@ 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);
+            if (load_image_targphys(initrd_filename, initrd_base,
+                                ram_size - initrd_base, NULL) < 0) {
+                error_report("Could not load initrd '%s'", initrd_filename);
+                exit(1);
+            }
             BOOTINFO2(param_ptr, BI_RAMDISK, initrd_base,
                       initrd_size);
         } else {
hw/m68k/virt.c +5 -2
index e67900c727..90f52f26e5 100644
@@ -291,8 +291,11 @@ 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);
+            if (load_image_targphys(initrd_filename, initrd_base,
+                                ram_size - initrd_base, NULL) < 0) {
+                error_report("Could not load initrd '%s'", initrd_filename);
+                exit(1);
+            }
             BOOTINFO2(param_ptr, BI_RAMDISK, initrd_base,
                       initrd_size);
         } else {
hw/microblaze/boot.c +4 -0
index a6f9ebab90..9fa8885dd3 100644
@@ -172,6 +172,10 @@ void microblaze_load_kernel(MicroBlazeCPU *cpu, bool is_little_endian,
         if (kernel_size < 0) {
             kernel_size = load_image_targphys(kernel_filename, ddr_base,
                                               ramsize, NULL);
+            if (kernel_size < 0) {
+                error_report("could not load kernel '%s'", kernel_filename);
+                exit(EXIT_FAILURE);
+            }
             boot_info.bootstrap_pc = ddr_base;
             high = (ddr_base + kernel_size + 3) & ~3;
         }
hw/ppc/amigaone.c +9 -0
index 8074713fbe..bb5e712c1b 100644
@@ -326,6 +326,10 @@ static void amigaone_init(MachineState *machine)
             exit(1);
         }
         sz = load_image_targphys(filename, PROM_ADDR, PROM_SIZE, &error_fatal);
+        if (sz < 0) {
+            error_report("Could not load firmware '%s'", filename);
+            exit(1);
+        }
     }
 
     /* Articia S */
@@ -411,6 +415,11 @@ static void amigaone_init(MachineState *machine)
         loadaddr = MAX(loadaddr, INITRD_MIN_ADDR);
         sz = load_image_targphys(machine->initrd_filename, loadaddr,
                                  bi->bd_info - loadaddr, &error_fatal);
+        if (sz < 0) {
+            error_report("Could not load initrd '%s'",
+                         machine->initrd_filename);
+            exit(1);
+        }
         bi->initrd_start = loadaddr;
         bi->initrd_end = loadaddr + sz;
     }
hw/ppc/e500.c +10 -0
index d6ca2e8563..3117a05b59 100644
@@ -1221,6 +1221,11 @@ void ppce500_init(MachineState *machine)
         kernel_size = load_image_targphys(machine->kernel_filename,
                                       cur_base, machine->ram_size - cur_base,
                                       &error_fatal);
+        if (kernel_size < 0) {
+            error_report("Could not load kernel '%s'",
+                         machine->kernel_filename);
+            exit(1);
+        }
         cur_base += kernel_size;
     }
 
@@ -1230,6 +1235,11 @@ void ppce500_init(MachineState *machine)
         initrd_size = load_image_targphys(machine->initrd_filename, initrd_base,
                                           machine->ram_size - initrd_base,
                                           &error_fatal);
+        if (initrd_size < 0) {
+            error_report("Could not load initrd '%s'",
+                         machine->initrd_filename);
+            exit(1);
+        }
         cur_base = initrd_base + initrd_size;
     }
 
hw/ppc/mac_newworld.c +10 -0
index 3680d96ed3..5e9556af33 100644
@@ -213,6 +213,11 @@ static void ppc_core99_init(MachineState *machine)
                                               kernel_base,
                                               machine->ram_size - kernel_base,
                                               &error_fatal);
+            if (kernel_size < 0) {
+                error_report("Could not load kernel '%s'",
+                             machine->kernel_filename);
+                exit(1);
+            }
         }
         /* load initrd */
         if (machine->initrd_filename) {
@@ -221,6 +226,11 @@ static void ppc_core99_init(MachineState *machine)
                                               initrd_base,
                                               machine->ram_size - initrd_base,
                                               &error_fatal);
+            if (initrd_size < 0) {
+                error_report("Could not load initrd '%s'",
+                             machine->initrd_filename);
+                exit(1);
+            }
             cmdline_base = TARGET_PAGE_ALIGN(initrd_base + initrd_size);
         } else {
             cmdline_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size + KERNEL_GAP);
hw/ppc/mac_oldworld.c +10 -0
index 24d9f2e3d5..fdbbfed52a 100644
@@ -169,6 +169,11 @@ static void ppc_heathrow_init(MachineState *machine)
                                               kernel_base,
                                               machine->ram_size - kernel_base,
                                               &error_fatal);
+            if (kernel_size < 0) {
+                error_report("Could not load kernel '%s'",
+                             machine->kernel_filename);
+                exit(1);
+            }
         }
         /* load initrd */
         if (machine->initrd_filename) {
@@ -178,6 +183,11 @@ static void ppc_heathrow_init(MachineState *machine)
                                               initrd_base,
                                               machine->ram_size - initrd_base,
                                               &error_fatal);
+            if (initrd_size < 0) {
+                error_report("Could not load initrd '%s'",
+                             machine->initrd_filename);
+                exit(1);
+            }
             cmdline_base = TARGET_PAGE_ALIGN(initrd_base + initrd_size);
         } else {
             cmdline_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size + KERNEL_GAP);
hw/ppc/pegasos.c +5 -0
index ac9fc5a654..0f03691f52 100644
@@ -304,6 +304,11 @@ static void pegasos_init(MachineState *machine)
         pm->initrd_addr = MAX(pm->initrd_addr, INITRD_MIN_ADDR);
         sz = load_image_targphys(machine->initrd_filename, pm->initrd_addr,
                             machine->ram_size - pm->initrd_addr, &error_fatal);
+        if (sz < 0) {
+            error_report("Could not load initrd '%s'",
+                         machine->initrd_filename);
+            exit(1);
+        }
         pm->initrd_size = sz;
     }
 
hw/ppc/pnv.c +16 -4
index 1513575b8f..aecffb211b 100644
@@ -1068,14 +1068,21 @@ static void pnv_init(MachineState *machine)
         exit(1);
     }
 
-    load_image_targphys(fw_filename, pnv->fw_load_addr, FW_MAX_SIZE,
-                        &error_fatal);
+    if (load_image_targphys(fw_filename, pnv->fw_load_addr, FW_MAX_SIZE,
+                        &error_fatal) < 0) {
+        error_report("Could not load OPAL firmware '%s'", fw_filename);
+        exit(1);
+    }
     g_free(fw_filename);
 
     /* load kernel */
     if (machine->kernel_filename) {
-        load_image_targphys(machine->kernel_filename,
-                            KERNEL_LOAD_ADDR, KERNEL_MAX_SIZE, &error_fatal);
+        if (load_image_targphys(machine->kernel_filename,
+                        KERNEL_LOAD_ADDR, KERNEL_MAX_SIZE, &error_fatal) < 0) {
+            error_report("Could not load kernel '%s'",
+                         machine->kernel_filename);
+            exit(1);
+        }
     }
 
     /* load initrd */
@@ -1084,6 +1091,11 @@ static void pnv_init(MachineState *machine)
         pnv->initrd_size = load_image_targphys(machine->initrd_filename,
                                                pnv->initrd_base,
                                                INITRD_MAX_SIZE, &error_fatal);
+        if (pnv->initrd_size < 0) {
+            error_report("Could not load initrd '%s'",
+                         machine->initrd_filename);
+            exit(1);
+        }
     }
 
     /* load dtb if passed */
hw/ppc/ppc440_bamboo.c +4 -0
index 2dde008b0e..b9c30d8929 100644
@@ -244,6 +244,10 @@ static void bamboo_init(MachineState *machine)
         initrd_size = load_image_targphys(initrd_filename, RAMDISK_ADDR,
                                           machine->ram_size - RAMDISK_ADDR,
                                           &error_fatal);
+        if (initrd_size < 0) {
+            error_report("Could not load initrd '%s'", initrd_filename);
+            exit(1);
+        }
     }
 
     /* If we're loading a kernel directly, we must load the device tree too. */
hw/ppc/prep.c +10 -0
index e973b34099..172a4afd71 100644
@@ -382,6 +382,11 @@ static void ibm_40p_init(MachineState *machine)
                                           kernel_base,
                                           machine->ram_size - kernel_base,
                                           &error_fatal);
+        if (kernel_size < 0) {
+            error_report("Could not load kernel '%s'",
+                         machine->kernel_filename);
+            exit(1);
+        }
         fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_base);
         fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
         /* load initrd */
@@ -391,6 +396,11 @@ static void ibm_40p_init(MachineState *machine)
                                               initrd_base,
                                               machine->ram_size - initrd_base,
                                               &error_fatal);
+            if (initrd_size < 0) {
+                error_report("Could not load initrd '%s'",
+                             machine->initrd_filename);
+                exit(1);
+            }
             fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_base);
             fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
         }
hw/ppc/sam460ex.c +5 -0
index b13dd224ba..0747555bc8 100644
@@ -493,6 +493,11 @@ static void sam460ex_init(MachineState *machine)
                                           RAMDISK_ADDR,
                                           machine->ram_size - RAMDISK_ADDR,
                                           &error_fatal);
+        if (initrd_size < 0) {
+            error_report("Could not load initrd '%s'",
+                         machine->initrd_filename);
+            exit(1);
+        }
     }
 
     /* If we're loading a kernel directly, we must load the device tree too. */
hw/ppc/spapr.c +8 -0
index 0ab39dfea6..7ab6a47c5b 100644
@@ -2865,6 +2865,10 @@ static void spapr_machine_init(MachineState *machine)
         exit(1);
     }
     fw_size = load_image_targphys(filename, 0, FW_MAX_SIZE, &error_fatal);
+    if (fw_size < 0) {
+        error_report("Could not load LPAR firmware '%s'", filename);
+        exit(1);
+    }
 
     /*
      * if Secure VM (PEF) support is configured, then initialize it
@@ -3124,6 +3128,10 @@ static void spapr_machine_init(MachineState *machine)
                                                 spapr->initrd_base,
                                                 load_limit - spapr->initrd_base,
                                                 &error_fatal);
+            if (spapr->initrd_size < 0) {
+                error_report("Could not load initrd '%s'", initrd_filename);
+                exit(1);
+            }
         }
     }
 
hw/ppc/virtex_ml507.c +9 -0
index 51b3d7d712..b125561dd6 100644
@@ -255,6 +255,10 @@ static void virtex_init(MachineState *machine)
             kernel_size = load_image_targphys(kernel_filename,
                                               boot_offset,
                                               machine->ram_size, &error_fatal);
+            if (kernel_size < 0) {
+                error_report("could not load kernel '%s'", kernel_filename);
+                exit(1);
+            }
             boot_info.bootstrap_pc = boot_offset;
             high = boot_info.bootstrap_pc + kernel_size + 8192;
         }
@@ -267,6 +271,11 @@ static void virtex_init(MachineState *machine)
             initrd_size = load_image_targphys(machine->initrd_filename,
                                               high, machine->ram_size - high,
                                               &error_fatal);
+            if (initrd_size < 0) {
+                error_report("could not load initrd '%s'",
+                             machine->initrd_filename);
+                exit(1);
+            }
             high = ROUND_UP(high + initrd_size, 4);
         }
 
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 1/4] hw/core/loader: fix error handling for load_image_targphys callers

Quoted 8 lines · Trieu Huynh

From: Trieu Huynh <[email protected]>

Check return value of load_image_targphys() 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

Quoted 8 lines

---

hw/alpha/dp264.c       |  8 ++++++--
hw/hppa/machine.c      |  7 +++++--
hw/m68k/next-cube.c    |  9 ++++++++-
hw/m68k/q800.c         |  7 +++++--
hw/m68k/virt.c         |  7 +++++--
hw/microblaze/boot.c   |  4 ++++

I don't know about these above,

Quoted 11 lines
hw/ppc/amigaone.c      |  9 +++++++++
hw/ppc/e500.c          | 10 ++++++++++
hw/ppc/mac_newworld.c  | 10 ++++++++++
hw/ppc/mac_oldworld.c  | 10 ++++++++++
hw/ppc/pegasos.c       |  5 +++++
hw/ppc/pnv.c           | 20 ++++++++++++++++----
hw/ppc/ppc440_bamboo.c |  4 ++++
hw/ppc/prep.c          | 10 ++++++++++
hw/ppc/sam460ex.c      |  5 +++++
hw/ppc/spapr.c         |  8 ++++++++
hw/ppc/virtex_ml507.c  |  9 +++++++++

but unless I missed something all these call it with error_fatal so the check added should never be reached therefore should not be needed.

Regards,
BALATON Zoltan

#3 lore raw

Re: [PATCH 1/4] hw/core/loader: fix error handling for load_image_targphys callers

In reply to Trieu Huynh
Quoted 45 lines · Trieu Huynh

From: Trieu Huynh <[email protected]>

Check return value of load_image_targphys() 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

<...snip...>

hw/ppc/pnv.c +11 -4
index 1513575b8f..aecffb211b 100644
@@ -1068,14 +1068,21 @@ static void pnv_init(MachineState *machine)
          exit(1);
      }
 
-    load_image_targphys(fw_filename, pnv->fw_load_addr, FW_MAX_SIZE,
-                        &error_fatal);
+    if (load_image_targphys(fw_filename, pnv->fw_load_addr, FW_MAX_SIZE,
+                        &error_fatal) < 0) {
+        error_report("Could not load OPAL firmware '%s'", fw_filename);
+        exit(1);
+    }
      g_free(fw_filename);
 
      /* load kernel */
      if (machine->kernel_filename) {
-        load_image_targphys(machine->kernel_filename,
-                            KERNEL_LOAD_ADDR, KERNEL_MAX_SIZE, &error_fatal);
+        if (load_image_targphys(machine->kernel_filename,
+                        KERNEL_LOAD_ADDR, KERNEL_MAX_SIZE, &error_fatal) < 0) {
+            error_report("Could not load kernel '%s'",
+                         machine->kernel_filename);
+            exit(1);
+        }
      }
 
      /* load initrd */
@@ -1084,6 +1091,11 @@ static void pnv_init(MachineState *machine)
          pnv->initrd_size = load_image_targphys(machine->initrd_filename,

hw/ppc/pnv.c static void pnv_init(MachineState *machine) · line 1101

Quoted 10 lines
hw/ppc/pnv.c +5 -0
                                                 pnv->initrd_base,
                                                 INITRD_MAX_SIZE, &error_fatal);
+        if (pnv->initrd_size < 0) {
+            error_report("Could not load initrd '%s'",
+                         machine->initrd_filename);
+            exit(1);
+        }
      }
 
      /* load dtb if passed */

Thanks for the patch, but as balaton said, atleast in this case, the condition is not needed since it's have error_fatal.

Previously the if checks you added used to there, these were recently changed to not have the conditions, by this patch from vishal:

    commit cd274e83d50ba52ede62d2a8ea0f0ae7cb1ef469
    Author: Vishal Chourasia <[email protected]> Date:   Fri Oct 24 18:36:03 2025 +0530

    hw/ppc: Pass error_fatal to load_image_targphys()

    Pass error_fatal to load_image_targphys() calls in ppc machine initialization to capture detailed error information when loading firmware, kernel, and initrd images.

Thanks,

- Aditya G

#4 lore raw

Re: [PATCH 1/4] hw/core/loader: fix error handling for load_image_targphys callers

Sorry, I was missed on that change.
Pls ignore patch 1/4.

BRs,

Vào 02:02 AM T.4, 11 Th3, 2026 Aditya Gupta <[email protected]> đã viết:

Quoted 86 lines · Trieu Huynh
Quoted 23 lines

From: Trieu Huynh <[email protected]>

Check return value of load_image_targphys() 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

<...snip...>

hw/ppc/pnv.c +1 -2
index 1513575b8f..aecffb211b 100644
@@ -1068,14 +1068,21 @@ static void pnv_init(MachineState *machine)
          exit(1);
      }
 
-    load_image_targphys(fw_filename, pnv->fw_load_addr, FW_MAX_SIZE,
-                        &error_fatal);
+    if (load_image_targphys(fw_filename, pnv->fw_load_addr, FW_MAX_SIZE,

hw/ppc/pnv.c static void pnv_init(MachineState *machine) · line 1078

Quoted 10 lines
hw/ppc/pnv.c +4 -2
+                        &error_fatal) < 0) {
+        error_report("Could not load OPAL firmware '%s'", fw_filename);
+        exit(1);
+    }
      g_free(fw_filename);
 
      /* load kernel */
      if (machine->kernel_filename) {
-        load_image_targphys(machine->kernel_filename,
-                            KERNEL_LOAD_ADDR, KERNEL_MAX_SIZE,

&error_fatal);

hw/ppc/pnv.c static void pnv_init(MachineState *machine) · line 1081

Quoted 2 lines
hw/ppc/pnv.c +2 -0
+        if (load_image_targphys(machine->kernel_filename,
+                        KERNEL_LOAD_ADDR, KERNEL_MAX_SIZE,

&error_fatal) < 0) {

hw/ppc/pnv.c static void pnv_init(MachineState *machine) · line 1091

Quoted 9 lines
hw/ppc/pnv.c +4 -0
+            error_report("Could not load kernel '%s'",
+                         machine->kernel_filename);
+            exit(1);
+        }
      }
 
      /* load initrd */
@@ -1084,6 +1091,11 @@ static void pnv_init(MachineState *machine)
          pnv->initrd_size =

load_image_targphys(machine->initrd_filename,

hw/ppc/pnv.c static void pnv_init(MachineState *machine) · line 1093

Quoted 2 lines
hw/ppc/pnv.c +0 -0
                                                 pnv->initrd_base,
                                                 INITRD_MAX_SIZE,

&error_fatal);

hw/ppc/pnv.c static void pnv_init(MachineState *machine) · line 1101

Quoted 9 lines
hw/ppc/pnv.c +5 -0
+        if (pnv->initrd_size < 0) {
+            error_report("Could not load initrd '%s'",
+                         machine->initrd_filename);
+            exit(1);
+        }
      }
 
      /* load dtb if passed */

Thanks for the patch, but as balaton said, atleast in this case, the condition is not needed since it's have error_fatal.

Previously the if checks you added used to there, these were recently changed to not have the conditions,
by this patch from vishal:

commit cd274e83d50ba52ede62d2a8ea0f0ae7cb1ef469
Author: Vishal Chourasia <[email protected]>
Date: Fri Oct 24 18:36:03 2025 +0530

hw/ppc: Pass error_fatal to load_image_targphys()

Pass error_fatal to load_image_targphys() calls in ppc machine
initialization
to capture detailed error information when loading firmware, kernel, and initrd images.

Thanks,

- Aditya G

#5 lore raw

Re: [PATCH 1/4] hw/core/loader: fix error handling for load_image_targphys callers

In reply to Aditya Gupta
Quoted 65 lines · Aditya Gupta
Quoted 43 lines · Trieu Huynh

From: Trieu Huynh <[email protected]>

Check return value of load_image_targphys() 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

<...snip...>
  diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
index 1513575b8f..aecffb211b 100644

hw/ppc/pnv.c +11 -3
@@ -1068,14 +1068,21 @@ static void pnv_init(MachineState *machine)
           exit(1);
       }
   -    load_image_targphys(fw_filename, pnv->fw_load_addr, FW_MAX_SIZE,
-                        &error_fatal);
+    if (load_image_targphys(fw_filename, pnv->fw_load_addr, 
 FW_MAX_SIZE,
+                        &error_fatal) < 0) {
+        error_report("Could not load OPAL firmware '%s'", fw_filename);
+        exit(1);
+    }
       g_free(fw_filename);
         /* load kernel */
       if (machine->kernel_filename) {
-        load_image_targphys(machine->kernel_filename,
-                            KERNEL_LOAD_ADDR, KERNEL_MAX_SIZE, 
 &error_fatal);
+        if (load_image_targphys(machine->kernel_filename,
+                        KERNEL_LOAD_ADDR, KERNEL_MAX_SIZE, 
 &error_fatal) < 0) {
+            error_report("Could not load kernel '%s'",
+                         machine->kernel_filename);
+            exit(1);
+        }
       }

        /* load initrd */

hw/ppc/pnv.c +0 -0
@@ -1084,6 +1091,11 @@ static void pnv_init(MachineState *machine)
           pnv->initrd_size = load_image_targphys(machine->initrd_filename,

hw/ppc/pnv.c static void pnv_init(MachineState *machine) · line 1101

Quoted 10 lines
hw/ppc/pnv.c +5 -0
 pnv->initrd_base,
 INITRD_MAX_SIZE, &error_fatal);
+        if (pnv->initrd_size < 0) {
+            error_report("Could not load initrd '%s'",
+                         machine->initrd_filename);
+            exit(1);
+        }
       }
         /* load dtb if passed */
 

Thanks for the patch, but as balaton said, atleast in this case, the condition is not needed since it's have error_fatal.

Previously the if checks you added used to there, these were recently changed to not have the conditions, by this patch from vishal:

    commit cd274e83d50ba52ede62d2a8ea0f0ae7cb1ef469
    Author: Vishal Chourasia <[email protected]> Date:   Fri Oct 24 18:36:03 2025 +0530

Quoted 5 lines

    hw/ppc: Pass error_fatal to load_image_targphys()

    Pass error_fatal to load_image_targphys() calls in ppc machine initialization to capture detailed error information when loading firmware, kernel, and initrd images.

To add to this, it might be better to pass an error object to load_image_targphys, or error_fatal if we are exiting in the if condition. That gives more details for why the load failed.

The NULL arguments were added in this: https://lore.kernel.org/qemu-devel/[email protected]/

That was because it was intended to not affect other machines, and hence it stayed with default behavior of ignoring return value of load_image_targphys

This can be changed to use similar to PPC's approach to use error_fatal, if that's intended.

Thanks,
- Aditya G

#6 lore raw

PATCH 2/4 hw/core/loader: fix error handling for get_image_size callers

In reply to Trieu Huynh

From: Trieu Huynh <[email protected]>

Check return value of get_image_size() 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/ipmi/ipmi_bmc_sim.c | 2 ++
 hw/sparc/leon3.c       | 5 +++++
 2 files changed, 7 insertions(+)
hw/ipmi/ipmi_bmc_sim.c +2 -0
index 012e2ee4fe..fd875491f5 100644
@@ -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 +5 -0
index 9147d56bd4..c821dfd3bb 100644
@@ -354,6 +354,11 @@ 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);
+        exit(1);
+    }
 
     if (bios_size > prom_size) {
         error_report("could not load prom '%s': file too big", filename);
Signature · 1 line
2.43.0
#7 lore raw

Re: [PATCH 2/4] hw/core/loader: fix error handling for get_image_size callers

Quoted 33 lines · Trieu Huynh

From: Trieu Huynh <[email protected]>

Check return value of get_image_size() 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/ipmi/ipmi_bmc_sim.c | 2 ++
 hw/sparc/leon3.c       | 5 +++++
 2 files changed, 7 insertions(+)
hw/ipmi/ipmi_bmc_sim.c +2 -0
index 012e2ee4fe..fd875491f5 100644
@@ -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
index 9147d56bd4..c821dfd3bb 100644

hw/sparc/leon3.c static void leon3_generic_hw_init(MachineState *machine) · line 361

Quoted 8 lines
hw/sparc/leon3.c +5 -0
@@ -354,6 +354,11 @@ 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);
+        exit(1);
+    }

This makes the bios mandatory for leon3 machines, which has not been the case until now. I think we should introduce -bios none, as in RiscV to allow such possibility.

Quoted 5 lines
hw/sparc/leon3.c +0 -1
     if (bios_size > prom_size) {
         error_report("could not load prom '%s': file too big", filename);
--

2.43.0

#8 lore raw

PATCH 3/4 util/event_notifier: fix error handling for event_notifier_init callers

In reply to 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

---
 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
index 27e323a819..aa278b179e 100644
@@ -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
index c5bab5d245..2f0d2a03d8 100644
@@ -1425,7 +1425,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;
     }
 
@@ -2416,7 +2416,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
index 5081d67e7f..e91566509f 100644
@@ -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
index e58a0169af..5c8f305653 100644
@@ -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
index 2251facb35..ce9c014e6a 100644
@@ -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
index 7b907b9360..66e02b15a4 100644
@@ -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
index c89f3fbea3..29bf6511b3 100644
@@ -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
index 2f8f11df86..9c7634e243 100644
@@ -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
Acked-by on v1 3/4
#9 lore raw

Re: [PATCH 3/4] util/event_notifier: fix error handling for event_notifier_init callers

Quoted 96 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

---
  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
index 27e323a819..aa278b179e 100644
@@ -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
index c5bab5d245..2f0d2a03d8 100644
@@ -1425,7 +1425,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;
      }
 
@@ -2416,7 +2416,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
index 5081d67e7f..e91566509f 100644
@@ -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 +0 -0
index e58a0169af..5c8f305653 100644

hw/vfio/ap.c static bool vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev, · line 183

Quoted 5 lines
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) {
Quoted 62 lines
hw/vfio/ap.c +0 -0
          error_setg_errno(errp, errno,
                           "vfio: Unable to init event notifier for irq (%d)",
                           irq);
hw/vfio/ccw.c +1 -1
index 2251facb35..ce9c014e6a 100644
@@ -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
index 7b907b9360..66e02b15a4 100644
@@ -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
index c89f3fbea3..29bf6511b3 100644
@@ -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
index 2f8f11df86..9c7634e243 100644
@@ -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;
      }
Reviewed-by on v1 3/4
#10 lore raw

Re: [PATCH 3/4] util/event_notifier: fix error handling for event_notifier_init callers

In reply to Trieu Huynh
Quoted 13 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

LGTM

Please see note below.

Quoted 60 lines

---

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
index 27e323a819..aa278b179e 100644
@@ -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
index c5bab5d245..2f0d2a03d8 100644
@@ -1425,7 +1425,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;
    }
 
@@ -2416,7 +2416,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 +0 -0
index 5081d67e7f..e91566509f 100644

hw/remote/proxy.c static void setup_irqfd(PCIProxyDev *dev) · line 59

Quoted 10 lines
hw/remote/proxy.c +4 -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));

setup_irqfd() should ideally propagate the error up the stack. But hw/remote/proxy.c is planned for removal as it is superseded by vfio-user, so we don’t need to do it.

Thanks,
Jag

Quoted 87 lines
hw/remote/proxy.c +9 -0
+        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
index e58a0169af..5c8f305653 100644
@@ -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
index 2251facb35..ce9c014e6a 100644
@@ -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
index 7b907b9360..66e02b15a4 100644
@@ -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
index c89f3fbea3..29bf6511b3 100644
@@ -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
index 2f8f11df86..9c7634e243 100644
@@ -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
#11 lore raw

Deprecate Multi-process QEMU (Re: [PATCH 3/4] util/event_notifier: fix error handling for event_notifier_init callers)

Hello Jag,

+ John

Quoted 10 lines
Quoted 10 lines
hw/remote/proxy.c +1 -0
index 5081d67e7f..e91566509f 100644
@@ -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;
 
Quoted 9 lines

hw/remote/proxy.c static void setup_irqfd(PCIProxyDev *dev) · line 59

Quoted 5 lines
hw/remote/proxy.c +3 -2
-    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));

setup_irqfd() should ideally propagate the error up the stack. But hw/remote/proxy.c is planned for removal as it is superseded by vfio-user, so we don’t need to do it.

In that case, could you please send an update of docs/about/deprecated.rst to deprecate Multi-process QEMU ?

Thanks,

C.

#12 lore raw

Re: Deprecate Multi-process QEMU (Re: [PATCH 3/4] util/event_notifier: fix error handling for event_notifier_init callers)

Quoted 27 lines · Cédric Le Goater

Hello Jag,

+ John

Quoted 10 lines
Quoted 10 lines
hw/remote/proxy.c +1 -0
index 5081d67e7f..e91566509f 100644
@@ -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;
 
Quoted 8 lines

hw/remote/proxy.c static void setup_irqfd(PCIProxyDev *dev) · line 59

Quoted 5 lines
hw/remote/proxy.c +3 -2
-    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));

setup_irqfd() should ideally propagate the error up the stack. But hw/remote/proxy.c is planned for removal as it is superseded by vfio-user, so we don’t need to do it.

Quoted 2 lines

In that case, could you please send an update of docs/about/deprecated.rst to deprecate Multi-process QEMU ?

Sounds good, Cedric. Will do.

Quoted 5 lines

Thanks,

C.

#13 lore raw

PATCH 4/4 hw/pci/msix: fix error handling for msix_init callers

In reply to 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.
- 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  | 17 ++++++++++++-----
 5 files changed, 26 insertions(+), 13 deletions(-)
hw/net/igbvf.c +1 -1
index 48d56e43ac..9a165c7063 100644
@@ -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
index 4a7056bd45..910dce901b 100644
@@ -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
index b35476d057..1b23eaf100 100644
@@ -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
index f62e420a91..90d397374e 100644
@@ -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, NULL);
+
+        if (ret < 0) {
+            if (s->msix == ON_OFF_AUTO_ON) {
+                error_setg(errp, "MSI-X initialization failed");
+                return;
+            }
+            s->msix = ON_OFF_AUTO_OFF;
+        }
     }
 
     if (pci_is_express(dev)) {
hw/usb/hcd-xhci-pci.c +12 -5
index aa570506fc..7bd4425b34 100644
@@ -173,11 +173,18 @@ 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, NULL);
+
+        if (ret < 0) {
+            if (s->msix == ON_OFF_AUTO_ON) {
+                error_setg(errp, "MSI-X initialization failed");
+                return;
+            }
+            s->msix = ON_OFF_AUTO_OFF;
+        }
     }
     s->xhci.as = pci_get_address_space(dev);
 }
Signature · 1 line
2.43.0
#14 lore raw

Re: [PATCH 4/4] hw/pci/msix: fix error handling for msix_init callers

Quoted 66 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.
- 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  | 17 ++++++++++++-----
  5 files changed, 26 insertions(+), 13 deletions(-)
hw/net/igbvf.c +1 -1
index 48d56e43ac..9a165c7063 100644
@@ -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
index 4a7056bd45..910dce901b 100644
@@ -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
index b35476d057..1b23eaf100 100644
@@ -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 -2
index f62e420a91..90d397374e 100644
@@ -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,

hw/scsi/megasas.c static void megasas_scsi_realize(PCIDevice *dev, Error **errp) · line 2389

Quoted 10 lines
hw/scsi/megasas.c +7 -3
-                  &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, NULL);
+
+        if (ret < 0) {
+            if (s->msix == ON_OFF_AUTO_ON) {
+                error_setg(errp, "MSI-X initialization failed");

msix_init() has the errp parameter so let's use it.

Regards,
Akihiko Odaki

Quoted 35 lines
hw/scsi/megasas.c +4 -0
+                return;
+            }
+            s->msix = ON_OFF_AUTO_OFF;
+        }
      }
 
      if (pci_is_express(dev)) {
hw/usb/hcd-xhci-pci.c +12 -5
index aa570506fc..7bd4425b34 100644
@@ -173,11 +173,18 @@ 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, NULL);
+
+        if (ret < 0) {
+            if (s->msix == ON_OFF_AUTO_ON) {
+                error_setg(errp, "MSI-X initialization failed");
+                return;
+            }
+            s->msix = ON_OFF_AUTO_OFF;
+        }
      }
      s->xhci.as = pci_get_address_space(dev);
  }