[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 21/33] virtio-pci: correctly set host notifiers for
From: |
Gerd Hoffmann |
Subject: |
[Qemu-devel] [PATCH 21/33] virtio-pci: correctly set host notifiers for modern bar |
Date: |
Thu, 4 Jun 2015 12:34:30 +0200 |
From: Jason Wang <address@hidden>
Currently, during host notifier set. We only add eventfd for legacy
bar, this is not correct since:
- Non-transitional device does not have legacy bar, so qemu will crash
since proxy->bar was not initialized.
- Modern device uses modern bar and notify cap to notify the device,
we should add eventfd for proxy->notify.
So this patch fixes the above two issues by adding eventfd based on
whether legacy or modern device were supported.
Signed-off-by: Jason Wang <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
---
hw/virtio/virtio-pci.c | 31 +++++++++++++++++++++++++------
1 file changed, 25 insertions(+), 6 deletions(-)
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 558cb53..62a106b 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -135,12 +135,21 @@ static int virtio_pci_load_queue(DeviceState *d, int n,
QEMUFile *f)
return 0;
}
+#define QEMU_VIRTIO_PCI_QUEUE_MEM_MULT 0x1000
+
static int virtio_pci_set_host_notifier_internal(VirtIOPCIProxy *proxy,
int n, bool assign, bool
set_handler)
{
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
VirtQueue *vq = virtio_get_queue(vdev, n);
EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
+ bool legacy = !(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_LEGACY);
+ bool modern = !(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_MODERN);
+ MemoryRegion *modern_mr = &proxy->notify;
+ MemoryRegion *legacy_mr = &proxy->bar;
+ hwaddr modern_addr = QEMU_VIRTIO_PCI_QUEUE_MEM_MULT *
+ virtio_get_queue_index(vq);
+ hwaddr legacy_addr = VIRTIO_PCI_QUEUE_NOTIFY;
int r = 0;
if (assign) {
@@ -151,11 +160,23 @@ static int
virtio_pci_set_host_notifier_internal(VirtIOPCIProxy *proxy,
return r;
}
virtio_queue_set_host_notifier_fd_handler(vq, true, set_handler);
- memory_region_add_eventfd(&proxy->bar, VIRTIO_PCI_QUEUE_NOTIFY, 2,
- true, n, notifier);
+ if (modern) {
+ memory_region_add_eventfd(modern_mr, modern_addr, 2,
+ true, n, notifier);
+ }
+ if (legacy) {
+ memory_region_add_eventfd(legacy_mr, legacy_addr, 2,
+ true, n, notifier);
+ }
} else {
- memory_region_del_eventfd(&proxy->bar, VIRTIO_PCI_QUEUE_NOTIFY, 2,
- true, n, notifier);
+ if (modern) {
+ memory_region_del_eventfd(modern_mr, modern_addr, 2,
+ true, n, notifier);
+ }
+ if (legacy) {
+ memory_region_del_eventfd(legacy_mr, legacy_addr, 2,
+ true, n, notifier);
+ }
virtio_queue_set_host_notifier_fd_handler(vq, false, false);
event_notifier_cleanup(notifier);
}
@@ -927,8 +948,6 @@ static void virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy,
cap->cap_len - PCI_CAP_FLAGS);
}
-#define QEMU_VIRTIO_PCI_QUEUE_MEM_MULT 0x1000
-
static uint64_t virtio_pci_common_read(void *opaque, hwaddr addr,
unsigned size)
{
--
1.8.3.1
- [Qemu-devel] [PATCH 01/33] virtio: 64bit features fixups., (continued)
- [Qemu-devel] [PATCH 01/33] virtio: 64bit features fixups., Gerd Hoffmann, 2015/06/04
- [Qemu-devel] [PATCH 09/33] virtio-net: enable virtio 1.0, Gerd Hoffmann, 2015/06/04
- [Qemu-devel] [PATCH 10/33] vhost_net: add version_1 feature, Gerd Hoffmann, 2015/06/04
- [Qemu-devel] [PATCH 03/33] virtio: allow virtio-1 queue layout, Gerd Hoffmann, 2015/06/04
- [Qemu-devel] [PATCH 02/33] virtio: endianness checks for virtio 1.0 devices, Gerd Hoffmann, 2015/06/04
- [Qemu-devel] [PATCH 17/33] virtio-pci: add flags to enable/disable legacy/modern, Gerd Hoffmann, 2015/06/04
- [Qemu-devel] [PATCH 08/33] virtio-net: support longer header, Gerd Hoffmann, 2015/06/04
- [Qemu-devel] [PATCH 15/33] virtio: add modern config accessors, Gerd Hoffmann, 2015/06/04
- [Qemu-devel] [PATCH 14/33] virtio: generation counter support, Gerd Hoffmann, 2015/06/04
- [Qemu-devel] [PATCH 21/33] virtio-pci: correctly set host notifiers for modern bar,
Gerd Hoffmann <=
- [Qemu-devel] [PATCH 16/33] virtio-pci: switch to modern accessors for 1.0, Gerd Hoffmann, 2015/06/04
- [Qemu-devel] [PATCH 11/33] vhost: 64 bit features, Gerd Hoffmann, 2015/06/04
- [Qemu-devel] [PATCH 22/33] virtio_balloon: header update, Gerd Hoffmann, 2015/06/04
- [Qemu-devel] [PATCH 19/33] virtio-pci: change & document virtio pci bar layout., Gerd Hoffmann, 2015/06/04
- [Qemu-devel] [PATCH 29/33] virtio-pci: drop identical virtio_pci_cap, Gerd Hoffmann, 2015/06/04
- [Qemu-devel] [PATCH 26/33] virtio-pci: add virtio_pci_modern_region_map(), Gerd Hoffmann, 2015/06/04
- [Qemu-devel] [PATCH 06/33] virtio: allow to fail setting status, Gerd Hoffmann, 2015/06/04
- [Qemu-devel] [PATCH 23/33] virtio-balloon: switch to virtio_add_feature, Gerd Hoffmann, 2015/06/04
- [Qemu-devel] [PATCH 20/33] virtio-pci: make modern bar 64bit + prefetchable, Gerd Hoffmann, 2015/06/04
- [Qemu-devel] [PATCH 27/33] virtio-pci: move virtio_pci_add_mem_cap call to virtio_pci_modern_region_map, Gerd Hoffmann, 2015/06/04