aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Wang <jasowang@redhat.com>2015-04-10 18:00:14 +0800
committerMichael S. Tsirkin <mst@redhat.com>2015-04-28 11:38:25 +0200
commitbc7e85cccd2c8bdfb489a9acb2f9e43bd6ec727b (patch)
tree23c53f21c61f33ccf7d5145084b34a473236a2a0
parent36a7046c4a0b43fc250bc87a77682ed4eb698541 (diff)
downloadqemu-virtio-1.0.tar.gz
virtio-pci: correctly set host notifiers for modern barvirtio-1.0
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 <jasowang@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
-rw-r--r--hw/virtio/virtio-pci.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index e6b0df47da7..89ef5ed1814 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -180,12 +180,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) {
@@ -196,11 +205,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);
}
@@ -973,8 +994,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)
{