Blame SOURCES/kvm-virtio-pci-correctly-set-host-notifiers-for-modern-b.patch

8be556
From d8e5a36995271120c98604e386e927e2c56cc2d0 Mon Sep 17 00:00:00 2001
8be556
From: Xiao Wang <jasowang@redhat.com>
8be556
Date: Tue, 7 Jul 2015 09:18:46 +0200
8be556
Subject: [PATCH 158/217] virtio-pci: correctly set host notifiers for modern
8be556
 bar
8be556
8be556
Message-id: <1436260751-25015-44-git-send-email-jasowang@redhat.com>
8be556
Patchwork-id: 66818
8be556
O-Subject: [RHEL7.2 qemu-kvm-rhev PATCH V2 43/68] virtio-pci: correctly set host notifiers for modern bar
8be556
Bugzilla: 1227343
8be556
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
8be556
RH-Acked-by: David Gibson <dgibson@redhat.com>
8be556
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
8be556
RH-Acked-by: Thomas Huth <thuth@redhat.com>
8be556
8be556
Currently, during host notifier set. We only add eventfd for legacy
8be556
bar, this is not correct since:
8be556
8be556
- Non-transitional device does not have legacy bar, so qemu will crash
8be556
  since proxy->bar was not initialized.
8be556
- Modern device uses modern bar and notify cap to notify the device,
8be556
  we should add eventfd for proxy->notify.
8be556
8be556
So this patch fixes the above two issues by adding eventfd based on
8be556
whether legacy or modern device were supported.
8be556
8be556
Signed-off-by: Jason Wang <jasowang@redhat.com>
8be556
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
8be556
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
8be556
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
8be556
8be556
(cherry picked from commit 975acc0ae6d60260859884a9235ae3c62e2969a2)
8be556
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
8be556
---
8be556
 hw/virtio/virtio-pci.c | 31 +++++++++++++++++++++++++------
8be556
 1 file changed, 25 insertions(+), 6 deletions(-)
8be556
8be556
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
8be556
index 4d80716..9677ec2 100644
8be556
--- a/hw/virtio/virtio-pci.c
8be556
+++ b/hw/virtio/virtio-pci.c
8be556
@@ -135,12 +135,21 @@ static int virtio_pci_load_queue(DeviceState *d, int n, QEMUFile *f)
8be556
     return 0;
8be556
 }
8be556
 
8be556
+#define QEMU_VIRTIO_PCI_QUEUE_MEM_MULT 0x1000
8be556
+
8be556
 static int virtio_pci_set_host_notifier_internal(VirtIOPCIProxy *proxy,
8be556
                                                  int n, bool assign, bool set_handler)
8be556
 {
8be556
     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
8be556
     VirtQueue *vq = virtio_get_queue(vdev, n);
8be556
     EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
8be556
+    bool legacy = !(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_LEGACY);
8be556
+    bool modern = !(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_MODERN);
8be556
+    MemoryRegion *modern_mr = &proxy->notify;
8be556
+    MemoryRegion *legacy_mr = &proxy->bar;
8be556
+    hwaddr modern_addr = QEMU_VIRTIO_PCI_QUEUE_MEM_MULT *
8be556
+                         virtio_get_queue_index(vq);
8be556
+    hwaddr legacy_addr = VIRTIO_PCI_QUEUE_NOTIFY;
8be556
     int r = 0;
8be556
 
8be556
     if (assign) {
8be556
@@ -151,11 +160,23 @@ static int virtio_pci_set_host_notifier_internal(VirtIOPCIProxy *proxy,
8be556
             return r;
8be556
         }
8be556
         virtio_queue_set_host_notifier_fd_handler(vq, true, set_handler);
8be556
-        memory_region_add_eventfd(&proxy->bar, VIRTIO_PCI_QUEUE_NOTIFY, 2,
8be556
-                                  true, n, notifier);
8be556
+        if (modern) {
8be556
+            memory_region_add_eventfd(modern_mr, modern_addr, 2,
8be556
+                                      true, n, notifier);
8be556
+        }
8be556
+        if (legacy) {
8be556
+            memory_region_add_eventfd(legacy_mr, legacy_addr, 2,
8be556
+                                      true, n, notifier);
8be556
+        }
8be556
     } else {
8be556
-        memory_region_del_eventfd(&proxy->bar, VIRTIO_PCI_QUEUE_NOTIFY, 2,
8be556
-                                  true, n, notifier);
8be556
+        if (modern) {
8be556
+            memory_region_del_eventfd(modern_mr, modern_addr, 2,
8be556
+                                      true, n, notifier);
8be556
+        }
8be556
+        if (legacy) {
8be556
+            memory_region_del_eventfd(legacy_mr, legacy_addr, 2,
8be556
+                                      true, n, notifier);
8be556
+        }
8be556
         virtio_queue_set_host_notifier_fd_handler(vq, false, false);
8be556
         event_notifier_cleanup(notifier);
8be556
     }
8be556
@@ -934,8 +955,6 @@ static void virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy,
8be556
            cap->cap_len - PCI_CAP_FLAGS);
8be556
 }
8be556
 
8be556
-#define QEMU_VIRTIO_PCI_QUEUE_MEM_MULT 0x1000
8be556
-
8be556
 static uint64_t virtio_pci_common_read(void *opaque, hwaddr addr,
8be556
                                        unsigned size)
8be556
 {
8be556
-- 
8be556
1.8.3.1
8be556