dcavalca / rpms / qemu

Forked from rpms/qemu 11 months ago
Clone

Blame 0001-virtio-fix-vhost-handling.patch

93c32f
From 26b9b5fe17cc1b6be2e8bf8b9d16094f420bb8ad Mon Sep 17 00:00:00 2001
93c32f
From: Paolo Bonzini <pbonzini@redhat.com>
93c32f
Date: Mon, 6 Aug 2012 15:26:14 +0200
93c32f
Subject: [PATCH] virtio: fix vhost handling
93c32f
93c32f
Commit b1f416aa8d870fab71030abc9401cfc77b948e8e breaks vhost_net
93c32f
because it always registers the virtio_pci_host_notifier_read() handler
93c32f
function on the ioeventfd, even when vhost_net.ko is using the ioeventfd.
93c32f
The result is both QEMU and vhost_net.ko polling on the same eventfd
93c32f
and the virtio_net.ko guest driver seeing inconsistent results:
93c32f
93c32f
  # ifconfig eth0 192.168.0.1 netmask 255.255.255.0
93c32f
  virtio_net virtio0: output:id 0 is not a head!
93c32f
93c32f
To fix this, proceed the same as we do for irqfd: add a parameter to
93c32f
virtio_queue_set_host_notifier_fd_handler and in that case only set
93c32f
the notifier, not the handler.
93c32f
93c32f
Cc: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
93c32f
Tested-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
93c32f
Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
93c32f
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
93c32f
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
93c32f
---
93c32f
 hw/virtio-pci.c |   14 +++++++-------
93c32f
 hw/virtio.c     |    7 +++++--
93c32f
 hw/virtio.h     |    3 ++-
93c32f
 3 files changed, 14 insertions(+), 10 deletions(-)
93c32f
93c32f
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
93c32f
index 3ab9747..125eded 100644
93c32f
--- a/hw/virtio-pci.c
93c32f
+++ b/hw/virtio-pci.c
93c32f
@@ -160,7 +160,7 @@ static int virtio_pci_load_queue(void * opaque, int n, QEMUFile *f)
93c32f
 }
93c32f
 
93c32f
 static int virtio_pci_set_host_notifier_internal(VirtIOPCIProxy *proxy,
93c32f
-                                                 int n, bool assign)
93c32f
+                                                 int n, bool assign, bool set_handler)
93c32f
 {
93c32f
     VirtQueue *vq = virtio_get_queue(proxy->vdev, n);
93c32f
     EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
93c32f
@@ -173,13 +173,13 @@ static int virtio_pci_set_host_notifier_internal(VirtIOPCIProxy *proxy,
93c32f
                          __func__, r);
93c32f
             return r;
93c32f
         }
93c32f
-        virtio_queue_set_host_notifier_fd_handler(vq, true);
93c32f
+        virtio_queue_set_host_notifier_fd_handler(vq, true, set_handler);
93c32f
         memory_region_add_eventfd(&proxy->bar, VIRTIO_PCI_QUEUE_NOTIFY, 2,
93c32f
                                   true, n, notifier);
93c32f
     } else {
93c32f
         memory_region_del_eventfd(&proxy->bar, VIRTIO_PCI_QUEUE_NOTIFY, 2,
93c32f
                                   true, n, notifier);
93c32f
-        virtio_queue_set_host_notifier_fd_handler(vq, false);
93c32f
+        virtio_queue_set_host_notifier_fd_handler(vq, false, false);
93c32f
         event_notifier_cleanup(notifier);
93c32f
     }
93c32f
     return r;
93c32f
@@ -200,7 +200,7 @@ static void virtio_pci_start_ioeventfd(VirtIOPCIProxy *proxy)
93c32f
             continue;
93c32f
         }
93c32f
 
93c32f
-        r = virtio_pci_set_host_notifier_internal(proxy, n, true);
93c32f
+        r = virtio_pci_set_host_notifier_internal(proxy, n, true, true);
93c32f
         if (r < 0) {
93c32f
             goto assign_error;
93c32f
         }
93c32f
@@ -214,7 +214,7 @@ assign_error:
93c32f
             continue;
93c32f
         }
93c32f
 
93c32f
-        r = virtio_pci_set_host_notifier_internal(proxy, n, false);
93c32f
+        r = virtio_pci_set_host_notifier_internal(proxy, n, false, false);
93c32f
         assert(r >= 0);
93c32f
     }
93c32f
     proxy->ioeventfd_started = false;
93c32f
@@ -235,7 +235,7 @@ static void virtio_pci_stop_ioeventfd(VirtIOPCIProxy *proxy)
93c32f
             continue;
93c32f
         }
93c32f
 
93c32f
-        r = virtio_pci_set_host_notifier_internal(proxy, n, false);
93c32f
+        r = virtio_pci_set_host_notifier_internal(proxy, n, false, false);
93c32f
         assert(r >= 0);
93c32f
     }
93c32f
     proxy->ioeventfd_started = false;
93c32f
@@ -683,7 +683,7 @@ static int virtio_pci_set_host_notifier(void *opaque, int n, bool assign)
93c32f
      * currently only stops on status change away from ok,
93c32f
      * reset, vmstop and such. If we do add code to start here,
93c32f
      * need to check vmstate, device state etc. */
93c32f
-    return virtio_pci_set_host_notifier_internal(proxy, n, assign);
93c32f
+    return virtio_pci_set_host_notifier_internal(proxy, n, assign, false);
93c32f
 }
93c32f
 
93c32f
 static void virtio_pci_vmstate_change(void *opaque, bool running)
93c32f
diff --git a/hw/virtio.c b/hw/virtio.c
93c32f
index d146f86..209c763 100644
93c32f
--- a/hw/virtio.c
93c32f
+++ b/hw/virtio.c
93c32f
@@ -1021,13 +1021,16 @@ static void virtio_queue_host_notifier_read(EventNotifier *n)
93c32f
     }
93c32f
 }
93c32f
 
93c32f
-void virtio_queue_set_host_notifier_fd_handler(VirtQueue *vq, bool assign)
93c32f
+void virtio_queue_set_host_notifier_fd_handler(VirtQueue *vq, bool assign,
93c32f
+                                               bool set_handler)
93c32f
 {
93c32f
-    if (assign) {
93c32f
+    if (assign && set_handler) {
93c32f
         event_notifier_set_handler(&vq->host_notifier,
93c32f
                                    virtio_queue_host_notifier_read);
93c32f
     } else {
93c32f
         event_notifier_set_handler(&vq->host_notifier, NULL);
93c32f
+    }
93c32f
+    if (!assign) {
93c32f
         /* Test and clear notifier before after disabling event,
93c32f
          * in case poll callback didn't have time to run. */
93c32f
         virtio_queue_host_notifier_read(&vq->host_notifier);
93c32f
diff --git a/hw/virtio.h b/hw/virtio.h
93c32f
index f8b5535..7a4f564 100644
93c32f
--- a/hw/virtio.h
93c32f
+++ b/hw/virtio.h
93c32f
@@ -233,7 +233,8 @@ EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq);
93c32f
 void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign,
93c32f
                                                 bool with_irqfd);
93c32f
 EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq);
93c32f
-void virtio_queue_set_host_notifier_fd_handler(VirtQueue *vq, bool assign);
93c32f
+void virtio_queue_set_host_notifier_fd_handler(VirtQueue *vq, bool assign,
93c32f
+                                               bool set_handler);
93c32f
 void virtio_queue_notify_vq(VirtQueue *vq);
93c32f
 void virtio_irq(VirtQueue *vq);
93c32f
 #endif
93c32f
-- 
93c32f
1.7.10.4
93c32f