thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
0a122b
From 20d6241976e9adff2ae4a52defb8d8074ccbeff6 Mon Sep 17 00:00:00 2001
0a122b
From: Markus Armbruster <armbru@redhat.com>
0a122b
Date: Thu, 23 Jan 2014 14:03:32 +0100
0a122b
Subject: [PATCH 05/14] virtio-pci: remove vdev field
0a122b
0a122b
RH-Author: Markus Armbruster <armbru@redhat.com>
0a122b
Message-id: <1390485820-7585-3-git-send-email-armbru@redhat.com>
0a122b
Patchwork-id: 56925
0a122b
O-Subject: [PATCH 7.0 qemu-kvm 02/10] virtio-pci: remove vdev field
0a122b
Bugzilla: 983344
0a122b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
RH-Acked-by: Marcel Apfelbaum <marcel.a@redhat.com>
0a122b
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
0a122b
0a122b
From: Paolo Bonzini <pbonzini@redhat.com>
0a122b
0a122b
The vdev field is complicated to synchronize.  Just access the
0a122b
BusState's list of children.
0a122b
0a122b
Cc: qemu-stable@nongnu.org
0a122b
Acked-by: Andreas Faerber <afaerber@suse.de>
0a122b
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
(cherry picked from commit a3fc66d9fd37acbfcee013692246a8ae42bd93bb)
0a122b
0a122b
Conflicts:
0a122b
	hw/virtio/virtio-pci.c
0a122b
0a122b
Conflicts because we lack commit 9e64f8a "hw: set interrupts using pci
0a122b
irq wrappers".
0a122b
Signed-off-by: Markus Armbruster <armbru@redhat.com>
0a122b
---
0a122b
 hw/virtio/virtio-pci.c | 110 +++++++++++++++++++++++++++++--------------------
0a122b
 hw/virtio/virtio-pci.h |   1 -
0a122b
 2 files changed, 65 insertions(+), 46 deletions(-)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 hw/virtio/virtio-pci.c |  110 ++++++++++++++++++++++++++++-------------------
0a122b
 hw/virtio/virtio-pci.h |    1 -
0a122b
 2 files changed, 65 insertions(+), 46 deletions(-)
0a122b
0a122b
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
0a122b
index 1287e59..02ddbe9 100644
0a122b
--- a/hw/virtio/virtio-pci.c
0a122b
+++ b/hw/virtio/virtio-pci.c
0a122b
@@ -118,31 +118,40 @@ static inline VirtIOPCIProxy *to_virtio_pci_proxy_fast(DeviceState *d)
0a122b
 static void virtio_pci_notify(DeviceState *d, uint16_t vector)
0a122b
 {
0a122b
     VirtIOPCIProxy *proxy = to_virtio_pci_proxy_fast(d);
0a122b
+
0a122b
     if (msix_enabled(&proxy->pci_dev))
0a122b
         msix_notify(&proxy->pci_dev, vector);
0a122b
-    else
0a122b
-        qemu_set_irq(proxy->pci_dev.irq[0], proxy->vdev->isr & 1);
0a122b
+    else {
0a122b
+        VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
+        qemu_set_irq(proxy->pci_dev.irq[0], vdev->isr & 1);
0a122b
+    }
0a122b
 }
0a122b
 
0a122b
 static void virtio_pci_save_config(DeviceState *d, QEMUFile *f)
0a122b
 {
0a122b
     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
+
0a122b
     pci_device_save(&proxy->pci_dev, f);
0a122b
     msix_save(&proxy->pci_dev, f);
0a122b
     if (msix_present(&proxy->pci_dev))
0a122b
-        qemu_put_be16(f, proxy->vdev->config_vector);
0a122b
+        qemu_put_be16(f, vdev->config_vector);
0a122b
 }
0a122b
 
0a122b
 static void virtio_pci_save_queue(DeviceState *d, int n, QEMUFile *f)
0a122b
 {
0a122b
     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
+
0a122b
     if (msix_present(&proxy->pci_dev))
0a122b
-        qemu_put_be16(f, virtio_queue_vector(proxy->vdev, n));
0a122b
+        qemu_put_be16(f, virtio_queue_vector(vdev, n));
0a122b
 }
0a122b
 
0a122b
 static int virtio_pci_load_config(DeviceState *d, QEMUFile *f)
0a122b
 {
0a122b
     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
+
0a122b
     int ret;
0a122b
     ret = pci_device_load(&proxy->pci_dev, f);
0a122b
     if (ret) {
0a122b
@@ -151,12 +160,12 @@ static int virtio_pci_load_config(DeviceState *d, QEMUFile *f)
0a122b
     msix_unuse_all_vectors(&proxy->pci_dev);
0a122b
     msix_load(&proxy->pci_dev, f);
0a122b
     if (msix_present(&proxy->pci_dev)) {
0a122b
-        qemu_get_be16s(f, &proxy->vdev->config_vector);
0a122b
+        qemu_get_be16s(f, &vdev->config_vector);
0a122b
     } else {
0a122b
-        proxy->vdev->config_vector = VIRTIO_NO_VECTOR;
0a122b
+        vdev->config_vector = VIRTIO_NO_VECTOR;
0a122b
     }
0a122b
-    if (proxy->vdev->config_vector != VIRTIO_NO_VECTOR) {
0a122b
-        return msix_vector_use(&proxy->pci_dev, proxy->vdev->config_vector);
0a122b
+    if (vdev->config_vector != VIRTIO_NO_VECTOR) {
0a122b
+        return msix_vector_use(&proxy->pci_dev, vdev->config_vector);
0a122b
     }
0a122b
     return 0;
0a122b
 }
0a122b
@@ -164,13 +173,15 @@ static int virtio_pci_load_config(DeviceState *d, QEMUFile *f)
0a122b
 static int virtio_pci_load_queue(DeviceState *d, int n, QEMUFile *f)
0a122b
 {
0a122b
     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
+
0a122b
     uint16_t vector;
0a122b
     if (msix_present(&proxy->pci_dev)) {
0a122b
         qemu_get_be16s(f, &vector);
0a122b
     } else {
0a122b
         vector = VIRTIO_NO_VECTOR;
0a122b
     }
0a122b
-    virtio_queue_set_vector(proxy->vdev, n, vector);
0a122b
+    virtio_queue_set_vector(vdev, n, vector);
0a122b
     if (vector != VIRTIO_NO_VECTOR) {
0a122b
         return msix_vector_use(&proxy->pci_dev, vector);
0a122b
     }
0a122b
@@ -180,7 +191,8 @@ static int virtio_pci_load_queue(DeviceState *d, int n, QEMUFile *f)
0a122b
 static int virtio_pci_set_host_notifier_internal(VirtIOPCIProxy *proxy,
0a122b
                                                  int n, bool assign, bool set_handler)
0a122b
 {
0a122b
-    VirtQueue *vq = virtio_get_queue(proxy->vdev, n);
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
+    VirtQueue *vq = virtio_get_queue(vdev, n);
0a122b
     EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
0a122b
     int r = 0;
0a122b
 
0a122b
@@ -205,6 +217,7 @@ static int virtio_pci_set_host_notifier_internal(VirtIOPCIProxy *proxy,
0a122b
 
0a122b
 static void virtio_pci_start_ioeventfd(VirtIOPCIProxy *proxy)
0a122b
 {
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
     int n, r;
0a122b
 
0a122b
     if (!(proxy->flags & VIRTIO_PCI_FLAG_USE_IOEVENTFD) ||
0a122b
@@ -214,7 +227,7 @@ static void virtio_pci_start_ioeventfd(VirtIOPCIProxy *proxy)
0a122b
     }
0a122b
 
0a122b
     for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
0a122b
-        if (!virtio_queue_get_num(proxy->vdev, n)) {
0a122b
+        if (!virtio_queue_get_num(vdev, n)) {
0a122b
             continue;
0a122b
         }
0a122b
 
0a122b
@@ -228,7 +241,7 @@ static void virtio_pci_start_ioeventfd(VirtIOPCIProxy *proxy)
0a122b
 
0a122b
 assign_error:
0a122b
     while (--n >= 0) {
0a122b
-        if (!virtio_queue_get_num(proxy->vdev, n)) {
0a122b
+        if (!virtio_queue_get_num(vdev, n)) {
0a122b
             continue;
0a122b
         }
0a122b
 
0a122b
@@ -241,6 +254,7 @@ assign_error:
0a122b
 
0a122b
 static void virtio_pci_stop_ioeventfd(VirtIOPCIProxy *proxy)
0a122b
 {
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
     int r;
0a122b
     int n;
0a122b
 
0a122b
@@ -249,7 +263,7 @@ static void virtio_pci_stop_ioeventfd(VirtIOPCIProxy *proxy)
0a122b
     }
0a122b
 
0a122b
     for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
0a122b
-        if (!virtio_queue_get_num(proxy->vdev, n)) {
0a122b
+        if (!virtio_queue_get_num(vdev, n)) {
0a122b
             continue;
0a122b
         }
0a122b
 
0a122b
@@ -262,7 +276,7 @@ static void virtio_pci_stop_ioeventfd(VirtIOPCIProxy *proxy)
0a122b
 static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
0a122b
 {
0a122b
     VirtIOPCIProxy *proxy = opaque;
0a122b
-    VirtIODevice *vdev = proxy->vdev;
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
     hwaddr pa;
0a122b
 
0a122b
     switch (addr) {
0a122b
@@ -277,7 +291,7 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
0a122b
         pa = (hwaddr)val << VIRTIO_PCI_QUEUE_ADDR_SHIFT;
0a122b
         if (pa == 0) {
0a122b
             virtio_pci_stop_ioeventfd(proxy);
0a122b
-            virtio_reset(proxy->vdev);
0a122b
+            virtio_reset(vdev);
0a122b
             msix_unuse_all_vectors(&proxy->pci_dev);
0a122b
         }
0a122b
         else
0a122b
@@ -304,7 +318,7 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
0a122b
         }
0a122b
 
0a122b
         if (vdev->status == 0) {
0a122b
-            virtio_reset(proxy->vdev);
0a122b
+            virtio_reset(vdev);
0a122b
             msix_unuse_all_vectors(&proxy->pci_dev);
0a122b
         }
0a122b
 
0a122b
@@ -340,7 +354,7 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
0a122b
 
0a122b
 static uint32_t virtio_ioport_read(VirtIOPCIProxy *proxy, uint32_t addr)
0a122b
 {
0a122b
-    VirtIODevice *vdev = proxy->vdev;
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
     uint32_t ret = 0xFFFFFFFF;
0a122b
 
0a122b
     switch (addr) {
0a122b
@@ -386,6 +400,7 @@ static uint64_t virtio_pci_config_read(void *opaque, hwaddr addr,
0a122b
                                        unsigned size)
0a122b
 {
0a122b
     VirtIOPCIProxy *proxy = opaque;
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
     uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
0a122b
     uint64_t val = 0;
0a122b
     if (addr < config) {
0a122b
@@ -395,16 +410,16 @@ static uint64_t virtio_pci_config_read(void *opaque, hwaddr addr,
0a122b
 
0a122b
     switch (size) {
0a122b
     case 1:
0a122b
-        val = virtio_config_readb(proxy->vdev, addr);
0a122b
+        val = virtio_config_readb(vdev, addr);
0a122b
         break;
0a122b
     case 2:
0a122b
-        val = virtio_config_readw(proxy->vdev, addr);
0a122b
+        val = virtio_config_readw(vdev, addr);
0a122b
         if (virtio_is_big_endian()) {
0a122b
             val = bswap16(val);
0a122b
         }
0a122b
         break;
0a122b
     case 4:
0a122b
-        val = virtio_config_readl(proxy->vdev, addr);
0a122b
+        val = virtio_config_readl(vdev, addr);
0a122b
         if (virtio_is_big_endian()) {
0a122b
             val = bswap32(val);
0a122b
         }
0a122b
@@ -418,6 +433,7 @@ static void virtio_pci_config_write(void *opaque, hwaddr addr,
0a122b
 {
0a122b
     VirtIOPCIProxy *proxy = opaque;
0a122b
     uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
     if (addr < config) {
0a122b
         virtio_ioport_write(proxy, addr, val);
0a122b
         return;
0a122b
@@ -429,19 +445,19 @@ static void virtio_pci_config_write(void *opaque, hwaddr addr,
0a122b
      */
0a122b
     switch (size) {
0a122b
     case 1:
0a122b
-        virtio_config_writeb(proxy->vdev, addr, val);
0a122b
+        virtio_config_writeb(vdev, addr, val);
0a122b
         break;
0a122b
     case 2:
0a122b
         if (virtio_is_big_endian()) {
0a122b
             val = bswap16(val);
0a122b
         }
0a122b
-        virtio_config_writew(proxy->vdev, addr, val);
0a122b
+        virtio_config_writew(vdev, addr, val);
0a122b
         break;
0a122b
     case 4:
0a122b
         if (virtio_is_big_endian()) {
0a122b
             val = bswap32(val);
0a122b
         }
0a122b
-        virtio_config_writel(proxy->vdev, addr, val);
0a122b
+        virtio_config_writel(vdev, addr, val);
0a122b
         break;
0a122b
     }
0a122b
 }
0a122b
@@ -460,6 +476,7 @@ static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
0a122b
                                 uint32_t val, int len)
0a122b
 {
0a122b
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
 
0a122b
     pci_default_write_config(pci_dev, address, val, len);
0a122b
 
0a122b
@@ -467,8 +484,7 @@ static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
0a122b
         !(pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER) &&
0a122b
         !(proxy->flags & VIRTIO_PCI_FLAG_BUS_MASTER_BUG)) {
0a122b
         virtio_pci_stop_ioeventfd(proxy);
0a122b
-        virtio_set_status(proxy->vdev,
0a122b
-                          proxy->vdev->status & ~VIRTIO_CONFIG_S_DRIVER_OK);
0a122b
+        virtio_set_status(vdev, vdev->status & ~VIRTIO_CONFIG_S_DRIVER_OK);
0a122b
     }
0a122b
 }
0a122b
 
0a122b
@@ -511,7 +527,8 @@ static int kvm_virtio_pci_irqfd_use(VirtIOPCIProxy *proxy,
0a122b
                                  unsigned int vector)
0a122b
 {
0a122b
     VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector];
0a122b
-    VirtQueue *vq = virtio_get_queue(proxy->vdev, queue_no);
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
+    VirtQueue *vq = virtio_get_queue(vdev, queue_no);
0a122b
     EventNotifier *n = virtio_queue_get_guest_notifier(vq);
0a122b
     int ret;
0a122b
     ret = kvm_irqchip_add_irqfd_notifier(kvm_state, n, irqfd->virq);
0a122b
@@ -522,7 +539,8 @@ static void kvm_virtio_pci_irqfd_release(VirtIOPCIProxy *proxy,
0a122b
                                       unsigned int queue_no,
0a122b
                                       unsigned int vector)
0a122b
 {
0a122b
-    VirtQueue *vq = virtio_get_queue(proxy->vdev, queue_no);
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
+    VirtQueue *vq = virtio_get_queue(vdev, queue_no);
0a122b
     EventNotifier *n = virtio_queue_get_guest_notifier(vq);
0a122b
     VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector];
0a122b
     int ret;
0a122b
@@ -534,7 +552,7 @@ static void kvm_virtio_pci_irqfd_release(VirtIOPCIProxy *proxy,
0a122b
 static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)
0a122b
 {
0a122b
     PCIDevice *dev = &proxy->pci_dev;
0a122b
-    VirtIODevice *vdev = proxy->vdev;
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
0a122b
     unsigned int vector;
0a122b
     int ret, queue_no;
0a122b
@@ -583,7 +601,7 @@ undo:
0a122b
 static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)
0a122b
 {
0a122b
     PCIDevice *dev = &proxy->pci_dev;
0a122b
-    VirtIODevice *vdev = proxy->vdev;
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
     unsigned int vector;
0a122b
     int queue_no;
0a122b
     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
0a122b
@@ -611,8 +629,9 @@ static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy *proxy,
0a122b
                                        unsigned int vector,
0a122b
                                        MSIMessage msg)
0a122b
 {
0a122b
-    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(proxy->vdev);
0a122b
-    VirtQueue *vq = virtio_get_queue(proxy->vdev, queue_no);
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
0a122b
+    VirtQueue *vq = virtio_get_queue(vdev, queue_no);
0a122b
     EventNotifier *n = virtio_queue_get_guest_notifier(vq);
0a122b
     VirtIOIRQFD *irqfd;
0a122b
     int ret = 0;
0a122b
@@ -631,10 +650,10 @@ static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy *proxy,
0a122b
      * Otherwise, set it up now.
0a122b
      */
0a122b
     if (k->guest_notifier_mask) {
0a122b
-        k->guest_notifier_mask(proxy->vdev, queue_no, false);
0a122b
+        k->guest_notifier_mask(vdev, queue_no, false);
0a122b
         /* Test after unmasking to avoid losing events. */
0a122b
         if (k->guest_notifier_pending &&
0a122b
-            k->guest_notifier_pending(proxy->vdev, queue_no)) {
0a122b
+            k->guest_notifier_pending(vdev, queue_no)) {
0a122b
             event_notifier_set(n);
0a122b
         }
0a122b
     } else {
0a122b
@@ -647,13 +666,14 @@ static void virtio_pci_vq_vector_mask(VirtIOPCIProxy *proxy,
0a122b
                                              unsigned int queue_no,
0a122b
                                              unsigned int vector)
0a122b
 {
0a122b
-    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(proxy->vdev);
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
0a122b
 
0a122b
     /* If guest supports masking, keep irqfd but mask it.
0a122b
      * Otherwise, clean it up now.
0a122b
      */ 
0a122b
     if (k->guest_notifier_mask) {
0a122b
-        k->guest_notifier_mask(proxy->vdev, queue_no, true);
0a122b
+        k->guest_notifier_mask(vdev, queue_no, true);
0a122b
     } else {
0a122b
         kvm_virtio_pci_irqfd_release(proxy, queue_no, vector);
0a122b
     }
0a122b
@@ -663,7 +683,7 @@ static int virtio_pci_vector_unmask(PCIDevice *dev, unsigned vector,
0a122b
                                     MSIMessage msg)
0a122b
 {
0a122b
     VirtIOPCIProxy *proxy = container_of(dev, VirtIOPCIProxy, pci_dev);
0a122b
-    VirtIODevice *vdev = proxy->vdev;
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
     int ret, queue_no;
0a122b
 
0a122b
     for (queue_no = 0; queue_no < proxy->nvqs_with_notifiers; queue_no++) {
0a122b
@@ -693,7 +713,7 @@ undo:
0a122b
 static void virtio_pci_vector_mask(PCIDevice *dev, unsigned vector)
0a122b
 {
0a122b
     VirtIOPCIProxy *proxy = container_of(dev, VirtIOPCIProxy, pci_dev);
0a122b
-    VirtIODevice *vdev = proxy->vdev;
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
     int queue_no;
0a122b
 
0a122b
     for (queue_no = 0; queue_no < proxy->nvqs_with_notifiers; queue_no++) {
0a122b
@@ -712,7 +732,7 @@ static void virtio_pci_vector_poll(PCIDevice *dev,
0a122b
                                    unsigned int vector_end)
0a122b
 {
0a122b
     VirtIOPCIProxy *proxy = container_of(dev, VirtIOPCIProxy, pci_dev);
0a122b
-    VirtIODevice *vdev = proxy->vdev;
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
0a122b
     int queue_no;
0a122b
     unsigned int vector;
0a122b
@@ -744,8 +764,9 @@ static int virtio_pci_set_guest_notifier(DeviceState *d, int n, bool assign,
0a122b
                                          bool with_irqfd)
0a122b
 {
0a122b
     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
0a122b
-    VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(proxy->vdev);
0a122b
-    VirtQueue *vq = virtio_get_queue(proxy->vdev, n);
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
+    VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
0a122b
+    VirtQueue *vq = virtio_get_queue(vdev, n);
0a122b
     EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
0a122b
 
0a122b
     if (assign) {
0a122b
@@ -760,7 +781,7 @@ static int virtio_pci_set_guest_notifier(DeviceState *d, int n, bool assign,
0a122b
     }
0a122b
 
0a122b
     if (!msix_enabled(&proxy->pci_dev) && vdc->guest_notifier_mask) {
0a122b
-        vdc->guest_notifier_mask(proxy->vdev, n, !assign);
0a122b
+        vdc->guest_notifier_mask(vdev, n, !assign);
0a122b
     }
0a122b
 
0a122b
     return 0;
0a122b
@@ -775,7 +796,7 @@ static bool virtio_pci_query_guest_notifiers(DeviceState *d)
0a122b
 static int virtio_pci_set_guest_notifiers(DeviceState *d, int nvqs, bool assign)
0a122b
 {
0a122b
     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
0a122b
-    VirtIODevice *vdev = proxy->vdev;
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
0a122b
     int r, n;
0a122b
     bool with_irqfd = msix_enabled(&proxy->pci_dev) &&
0a122b
@@ -869,11 +890,12 @@ static int virtio_pci_set_host_notifier(DeviceState *d, int n, bool assign)
0a122b
 static void virtio_pci_vmstate_change(DeviceState *d, bool running)
0a122b
 {
0a122b
     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
0a122b
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
0a122b
 
0a122b
     if (running) {
0a122b
         /* Try to find out if the guest has bus master disabled, but is
0a122b
            in ready state. Then we have a buggy guest OS. */
0a122b
-        if ((proxy->vdev->status & VIRTIO_CONFIG_S_DRIVER_OK) &&
0a122b
+        if ((vdev->status & VIRTIO_CONFIG_S_DRIVER_OK) &&
0a122b
             !(proxy->pci_dev.config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
0a122b
             proxy->flags |= VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
0a122b
         }
0a122b
@@ -948,8 +970,6 @@ static void virtio_pci_device_plugged(DeviceState *d)
0a122b
     uint8_t *config;
0a122b
     uint32_t size;
0a122b
 
0a122b
-    proxy->vdev = virtio_bus_get_device(bus);
0a122b
-
0a122b
     config = proxy->pci_dev.config;
0a122b
     if (proxy->class_code) {
0a122b
         pci_config_set_class(config, proxy->class_code);
0a122b
diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
0a122b
index 917bcc5..dc332ae 100644
0a122b
--- a/hw/virtio/virtio-pci.h
0a122b
+++ b/hw/virtio/virtio-pci.h
0a122b
@@ -82,7 +82,6 @@ typedef struct VirtioPCIClass {
0a122b
 
0a122b
 struct VirtIOPCIProxy {
0a122b
     PCIDevice pci_dev;
0a122b
-    VirtIODevice *vdev;
0a122b
     MemoryRegion bar;
0a122b
     uint32_t flags;
0a122b
     uint32_t class_code;
0a122b
-- 
0a122b
1.7.1
0a122b