The method event_notifier_init doesn't assure that eventfd is used. Create a new method (eventfd_notifier_init) to initialize only eventfd file descriptors. This method is also used by event_notifier_init which has not been modified to keep compatibility with util/event_notifier-win32.c.
Signed-off-by: Alvise Rigo <a.r...@virtualopensystems.com> --- hw/vfio/pci.c | 18 +++++++++--------- hw/vfio/platform.c | 8 ++++---- include/qemu/event_notifier.h | 1 + util/event_notifier-posix.c | 24 +++++++++++++++++++++--- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index c86bef9..eae7dce 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -261,8 +261,8 @@ static void vfio_enable_intx_kvm(VFIOPCIDevice *vdev) pci_irq_deassert(&vdev->pdev); /* Get an eventfd for resample/unmask */ - if (event_notifier_init(&vdev->intx.unmask, 0)) { - error_report("vfio: Error: event_notifier_init failed eoi"); + if (eventfd_notifier_init(&vdev->intx.unmask, 0)) { + error_report("vfio: Error: eventfd_notifier_init failed eoi"); goto fail; } @@ -414,9 +414,9 @@ static int vfio_enable_intx(VFIOPCIDevice *vdev) } #endif - ret = event_notifier_init(&vdev->intx.interrupt, 0); + ret = eventfd_notifier_init(&vdev->intx.interrupt, 0); if (ret) { - error_report("vfio: Error: event_notifier_init failed"); + error_report("vfio: Error: eventfd_notifier_init failed"); return ret; } @@ -555,8 +555,8 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr, msix_vector_use(pdev, nr); - if (event_notifier_init(&vector->interrupt, 0)) { - error_report("vfio: Error: event_notifier_init failed"); + if (eventfd_notifier_init(&vector->interrupt, 0)) { + error_report("vfio: Error: eventfd_notifier_init failed"); } /* @@ -718,8 +718,8 @@ retry: vector->vdev = vdev; vector->use = true; - if (event_notifier_init(&vector->interrupt, 0)) { - error_report("vfio: Error: event_notifier_init failed"); + if (eventfd_notifier_init(&vector->interrupt, 0)) { + error_report("vfio: Error: eventfd_notifier_init failed"); } vector->msg = msi_get_message(&vdev->pdev, i); @@ -2925,7 +2925,7 @@ static void vfio_register_err_notifier(VFIOPCIDevice *vdev) return; } - if (event_notifier_init(&vdev->err_notifier, 0)) { + if (eventfd_notifier_init(&vdev->err_notifier, 0)) { error_report("vfio: Unable to init event notifier for error detection"); vdev->pci_aer = false; return; diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index d87fcc3..65dcf0e 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -349,9 +349,9 @@ static int vfio_enable_intp(VFIODevice *vdev, unsigned int index) sysbus_init_irq(sbdev, &intp->qemuirq); - ret = event_notifier_init(&intp->interrupt, 0); + ret = eventfd_notifier_init(&intp->interrupt, 0); if (ret) { - error_report("vfio: Error: event_notifier_init failed "); + error_report("vfio: Error: eventfd_notifier_init failed "); return ret; } /* build the irq_set to be passed to the vfio kernel driver */ @@ -471,8 +471,8 @@ static void vfio_enable_intp_kvm(VFIOINTp *intp) qemu_set_irq(intp->qemuirq, 0); /* Get an eventfd for resample/unmask */ - if (event_notifier_init(&intp->unmask, 0)) { - error_report("vfio: Error: event_notifier_init failed eoi"); + if (eventfd_notifier_init(&intp->unmask, 0)) { + error_report("vfio: Error: eventfd_notifier_init failed eoi"); goto fail; } diff --git a/include/qemu/event_notifier.h b/include/qemu/event_notifier.h index 88b57af..9220069 100644 --- a/include/qemu/event_notifier.h +++ b/include/qemu/event_notifier.h @@ -30,6 +30,7 @@ struct EventNotifier { typedef void EventNotifierHandler(EventNotifier *); +int eventfd_notifier_init(EventNotifier *, int active); int event_notifier_init(EventNotifier *, int active); void event_notifier_cleanup(EventNotifier *); int event_notifier_set(EventNotifier *); diff --git a/util/event_notifier-posix.c b/util/event_notifier-posix.c index 8442c6e..bb29760 100644 --- a/util/event_notifier-posix.c +++ b/util/event_notifier-posix.c @@ -25,19 +25,37 @@ void event_notifier_init_fd(EventNotifier *e, int fd) e->wfd = fd; } -int event_notifier_init(EventNotifier *e, int active) +int eventfd_notifier_init(EventNotifier *e, int active) { - int fds[2]; int ret; #ifdef CONFIG_EVENTFD ret = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); + if (ret >= 0) { + e->rfd = e->wfd = ret; + ret = 0; + + if (active) { + event_notifier_set(e); + } + } #else ret = -1; errno = ENOSYS; #endif + + return ret; +} + +int event_notifier_init(EventNotifier *e, int active) +{ + int fds[2]; + int ret; + + ret = eventfd_notifier_init(e, active); + if (ret >= 0) { - e->rfd = e->wfd = ret; + return 0; } else { if (errno != ENOSYS) { return -errno; -- 1.9.1