hw/misc/ivshmem-pci: Improve error handling
v2 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 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 | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v2 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
@@ -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)
Re: [PATCH v2 1/2] hw/misc/ivshmem-pci: Handle error from kvm_irqchip_add_irqfd_notifier_gsi()
Quoted 9 lines · David Hamilton
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.
Signed-off-by David Hamilton <[email protected]>
PATCH v2 2/2 hw/misc/ivshmem-pci: Check error after setup_interrupt() in process_msg_connect()
In reply to David Hamiltonsetup_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 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/misc/ivshmem-pci.c +3 -2
@@ -553,8 +553,9 @@ 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)) { +return ; + } }if (ivshmem_has_feature (s,IVSHMEM_IOEVENTFD )) {
Signature · 1 line
2.50.1 (Apple Git-155)
Re: [PATCH v2 2/2] hw/misc/ivshmem-pci: Check error after setup_interrupt() in process_msg_connect()
Quoted 17 lines · David Hamilton
setup_interrupt()can fail and report via errp, butprocess_msg_connect()was ignoring the error and continuing toivshmem_add_eventfd(). Check the bool return to avoid operating on a vector whose interrupt setup failed.Resolves the TODO comment at the call site.
Signed-off-by David Hamilton <[email protected]>--- hw/misc/ivshmem-pci.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)hw/misc/ivshmem-pci.c +0
-0
hw/misc/ivshmem-pci.c static void process_msg_connect(IVShmemState *s, uint16_t posn, int fd, · line 556
Quoted 6 lines
hw/misc/ivshmem-pci.c +1
-2@@ -553,8 +553,9 @@ 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)) {
Any cleanup needed here? Error returns above close(fd).
Quoted 5 lines
hw/misc/ivshmem-pci.c +2
-0+return ; + } }if (ivshmem_has_feature (s,IVSHMEM_IOEVENTFD )) {