Patchwork eventfd: making it thread safe

login
register
mail settings
Submitter David Gibson
Date Aug. 22, 2012, 3:01 a.m.
Message ID <1345604494-24778-1-git-send-email-david@gibson.dropbear.id.au>
Download mbox | patch
Permalink /patch/179223/
State New
Headers show

Comments

David Gibson - Aug. 22, 2012, 3:01 a.m.
From: Alexey Kardashevskiy <aik@ozlabs.ru>

QEMU uses IO handlers to run select() in the main loop.
The handlers list is managed by qemu_set_fd_handler() helper
which works fine when called from the main thread as it is
called when select() is not waiting.

However IO handlers list can be changed in the thread other than
the main one doing os_host_main_loop_wait(), for example, as a result
of a hypercall which changes PCI config space (VFIO on POWER is the case)
and enables/disabled MSI/MSIX which creates eventfd handles.
As the main loop should be waiting on the newly created eventfds,
it has to be restarted.

The patch adds the qemu_notify_event() call to interrupt select()
to make main_loop() restart select() with the updated IO handlers
list.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>

---
 iohandler.c |    1 +
 1 file changed, 1 insertion(+)

Anthony, this bugfix for eventfds has been sent before, but seems to
have fallen through the cracks.  Please apply.

Patch

diff --git a/iohandler.c b/iohandler.c
index 3c74de6..dea4355 100644
--- a/iohandler.c
+++ b/iohandler.c
@@ -77,6 +77,7 @@  int qemu_set_fd_handler2(int fd,
         ioh->fd_write = fd_write;
         ioh->opaque = opaque;
         ioh->deleted = 0;
+        qemu_notify_event();
     }
     return 0;
 }