From: Cornelia Huck <cornelia.huck@de.ibm.com>
To: qemu-devel@nongnu.org
Cc: mst@redhat.com, famz@redhat.com, stefanha@redhat.com,
jasowang@redhat.com, pl@kamp.de, marcandre.lureau@gmail.com,
pbonzini@redhat.com, Cornelia Huck <cornelia.huck@de.ibm.com>
Subject: [Qemu-devel] [PATCH v2] virtio: Fix setting up host notifiers for vhost
Date: Thu, 30 Jun 2016 13:52:47 +0200 [thread overview]
Message-ID: <1467287567-2632-1-git-send-email-cornelia.huck@de.ibm.com> (raw)
When setting up host notifiers, virtio_bus_set_host_notifier()
simply switches the handler. This will only work, however, if
the ioeventfd has already been setup; this is true for dataplane,
but not for vhost, and will completely break things if the
ioeventfd is disabled for the device.
Fix this by starting the ioeventfd on assign if that has not
happened before, and only switch the handler if the ioeventfd
has really been started.
While we're at it, also fixup the unsetting path of
set_host_notifier_internal().
Fixes: 6798e245a3 ("virtio-bus: common ioeventfd infrastructure")
Reported-by: Jason Wang <jasowang@redhat.com>
Reported-by: Marc-André Lureau <marcandre.lureau@gmail.com>
Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
Changes v1->v2:
- don't switch the handler if the eventfd has not been setup - this
fixes the failure of vhost-user-test for me
- add more comments
---
hw/virtio/virtio-bus.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c
index 1313760..dfe24fc 100644
--- a/hw/virtio/virtio-bus.c
+++ b/hw/virtio/virtio-bus.c
@@ -176,8 +176,8 @@ static int set_host_notifier_internal(DeviceState *proxy, VirtioBusState *bus,
return r;
}
} else {
- virtio_queue_set_host_notifier_fd_handler(vq, false, false);
k->ioeventfd_assign(proxy, notifier, n, assign);
+ virtio_queue_set_host_notifier_fd_handler(vq, false, false);
event_notifier_cleanup(notifier);
}
return r;
@@ -246,6 +246,9 @@ void virtio_bus_stop_ioeventfd(VirtioBusState *bus)
/*
* This function switches from/to the generic ioeventfd handler.
* assign==false means 'use generic ioeventfd handler'.
+ * It is only considered an error if the binding does not support
+ * host notifiers at all, not when they are not available for the
+ * individual device.
*/
int virtio_bus_set_host_notifier(VirtioBusState *bus, int n, bool assign)
{
@@ -259,6 +262,13 @@ int virtio_bus_set_host_notifier(VirtioBusState *bus, int n, bool assign)
}
if (assign) {
/*
+ * Not yet started? assign==true implies we want to use an
+ * eventfd, so let's do the requisite setup.
+ */
+ if (!k->ioeventfd_started(proxy)) {
+ virtio_bus_start_ioeventfd(bus);
+ }
+ /*
* Stop using the generic ioeventfd, we are doing eventfd handling
* ourselves below
*/
@@ -269,8 +279,13 @@ int virtio_bus_set_host_notifier(VirtioBusState *bus, int n, bool assign)
* Otherwise, there's a window where we don't have an
* ioeventfd and we may end up with a notification where
* we don't expect one.
+ *
+ * Also note that we should only do something with the eventfd
+ * handler if the eventfd has actually been setup.
*/
- virtio_queue_set_host_notifier_fd_handler(vq, assign, !assign);
+ if (k->ioeventfd_started(proxy)) {
+ virtio_queue_set_host_notifier_fd_handler(vq, assign, !assign);
+ }
if (!assign) {
/* Use generic ioeventfd handler again. */
k->ioeventfd_set_disabled(proxy, false);
--
2.6.6
next reply other threads:[~2016-06-30 11:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-30 11:52 Cornelia Huck [this message]
2016-06-30 12:04 ` [Qemu-devel] [PATCH v2] virtio: Fix setting up host notifiers for vhost Peter Lieven
2016-06-30 14:12 ` Marc-André Lureau
2016-06-30 15:07 ` Cornelia Huck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1467287567-2632-1-git-send-email-cornelia.huck@de.ibm.com \
--to=cornelia.huck@de.ibm.com \
--cc=famz@redhat.com \
--cc=jasowang@redhat.com \
--cc=marcandre.lureau@gmail.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=pl@kamp.de \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).