Skip to contentSkip to conversation

hw/misc/ivshmem-pci: Improve error handling

PATCH New David Hamilton 1 participant 3 messages Feb 26

lore
Share & tools
lore
#0 lore raw

v3 cover hw/misc/ivshmem-pci: Improve error handling

This series addresses two error handling issues in the ivshmem PCI device:

1. Handle the return value of kvm_irqchip_add_irqfd_notifier_gsi() which was being silently ignored.

2. Check for errors from setup_interrupt() in process_msg_connect() before continuing to ioeventfd setup.

Changes from v2:
- Added close(fd) cleanup on setup_interrupt() failure (Markus)

Changes from v1:
- Made setup_interrupt() return bool per QEMU conventions (Markus)
- Simplified errp check using bool return, dropped ERRP_GUARD()
- Dropped vector number from error message

David Hamilton (2):
hw/misc/ivshmem-pci: Handle error from
kvm_irqchip_add_irqfd_notifier_gsi()
hw/misc/ivshmem-pci: Check error after setup_interrupt() in
process_msg_connect()

 hw/misc/ivshmem-pci.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
Signature · 1 line
2.50.1 (Apple Git-155)
#1 lore raw

PATCH v3 1/2 hw/misc/ivshmem-pci: Handle error from kvm_irqchip_add_irqfd_notifier_gsi()

The return value of kvm_irqchip_add_irqfd_notifier_gsi() was being ignored. Propagate the error to the caller via errp.

Also change setup_interrupt() to return bool to follow QEMU error handling conventions, making error checks at call sites simpler.

Resolves the TODO comment at the call site.

---
 hw/misc/ivshmem-pci.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
hw/misc/ivshmem-pci.c +9 -4
index a3a43f53bd..c987eebb98 100644
@@ -442,13 +442,14 @@ static void ivshmem_add_kvm_msi_virq(IVShmemState *s, int vector,
     s->msi_vectors[vector].pdev = pdev;
 }
 
-static void setup_interrupt(IVShmemState *s, int vector, Error **errp)
+static bool setup_interrupt(IVShmemState *s, int vector, Error **errp)
 {
     EventNotifier *n = &s->peers[s->vm_id].eventfds[vector];
     bool with_irqfd = kvm_msi_via_irqfd_enabled() &&
         ivshmem_has_feature(s, IVSHMEM_MSI);
     PCIDevice *pdev = PCI_DEVICE(s);
     Error *err = NULL;
+    int ret;
 
     IVSHMEM_DPRINTF("setting up interrupt for vector: %d\n", vector);
 
@@ -460,18 +461,22 @@ static void setup_interrupt(IVShmemState *s, int vector, Error **errp)
         ivshmem_add_kvm_msi_virq(s, vector, &err);
         if (err) {
             error_propagate(errp, err);
-            return;
+            return false;
         }
 
         if (!msix_is_masked(pdev, vector)) {
-            kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, n, NULL,
+            ret = kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, n, NULL,
                                                s->msi_vectors[vector].virq);
-            /* TODO handle error */
+            if (ret < 0) {
+                error_setg(errp, "Failed to configure irqfd notifier");
+                return false;
+            }
         }
     } else {
         /* it will be delayed until msix is enabled, in write_config */
         IVSHMEM_DPRINTF("with irqfd, delayed until msix enabled\n");
     }
+    return true;
 }
 
 static void process_msg_shmem(IVShmemState *s, int fd, Error **errp)
Signature · 1 line
2.50.1 (Apple Git-155)
#2 lore raw

PATCH v3 2/2 hw/misc/ivshmem-pci: Check error after setup_interrupt() in process_msg_connect()

In reply to David Hamilton

setup_interrupt() can fail and report via errp, but process_msg_connect() was ignoring the error and continuing to ivshmem_add_eventfd(). Check the bool return to avoid operating on a vector whose interrupt setup failed.

Resolves the TODO comment at the call site.

---
 hw/misc/ivshmem-pci.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/misc/ivshmem-pci.c +4 -2
index c987eebb98..147e8223bb 100644
@@ -553,8 +553,10 @@ static void process_msg_connect(IVShmemState *s, uint16_t posn, int fd,
     }
 
     if (posn == s->vm_id) {
-        setup_interrupt(s, vector, errp);
-        /* TODO do we need to handle the error? */
+        if (!setup_interrupt(s, vector, errp)) {
+            close(fd);
+            return;
+        }
     }
 
     if (ivshmem_has_feature(s, IVSHMEM_IOEVENTFD)) {
Signature · 1 line
2.50.1 (Apple Git-155)