peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

Blame 0006-virtio-ccw-remove-vdev-field.patch

bacd9b
From 6f5e351c3f91e76a70c0684276af8070cfeb07da Mon Sep 17 00:00:00 2001
298366
From: Paolo Bonzini <pbonzini@redhat.com>
298366
Date: Fri, 20 Sep 2013 16:57:52 +0200
298366
Subject: [PATCH] virtio-ccw: remove vdev field
298366
298366
The vdev field is complicated to synchronize.  Just access the
298366
BusState's list of children.
298366
298366
Cc: qemu-stable@nongnu.org
298366
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
298366
---
298366
 hw/s390x/virtio-ccw.c | 80 ++++++++++++++++++++++++++++-----------------------
298366
 1 file changed, 44 insertions(+), 36 deletions(-)
298366
298366
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
45bdef
index f93a81c..8947196 100644
298366
--- a/hw/s390x/virtio-ccw.c
298366
+++ b/hw/s390x/virtio-ccw.c
45bdef
@@ -57,9 +57,10 @@ static const TypeInfo virtual_css_bus_info = {
298366
 VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch)
298366
 {
298366
     VirtIODevice *vdev = NULL;
298366
+    VirtioCcwDevice *dev = sch->driver_data;
298366
 
298366
-    if (sch->driver_data) {
298366
-        vdev = ((VirtioCcwDevice *)sch->driver_data)->vdev;
298366
+    if (dev) {
298366
+        vdev = virtio_bus_get_device(&dev->bus);
298366
     }
298366
     return vdev;
298366
 }
45bdef
@@ -67,7 +68,8 @@ VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch)
298366
 static int virtio_ccw_set_guest2host_notifier(VirtioCcwDevice *dev, int n,
298366
                                               bool assign, bool set_handler)
298366
 {
298366
-    VirtQueue *vq = virtio_get_queue(dev->vdev, n);
298366
+    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
298366
+    VirtQueue *vq = virtio_get_queue(vdev, n);
298366
     EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
298366
     int r = 0;
298366
     SubchDev *sch = dev->sch;
45bdef
@@ -97,6 +99,7 @@ static int virtio_ccw_set_guest2host_notifier(VirtioCcwDevice *dev, int n,
298366
 
298366
 static void virtio_ccw_start_ioeventfd(VirtioCcwDevice *dev)
298366
 {
298366
+    VirtIODevice *vdev;
298366
     int n, r;
298366
 
298366
     if (!(dev->flags & VIRTIO_CCW_FLAG_USE_IOEVENTFD) ||
45bdef
@@ -104,8 +107,9 @@ static void virtio_ccw_start_ioeventfd(VirtioCcwDevice *dev)
298366
         dev->ioeventfd_started) {
298366
         return;
298366
     }
298366
+    vdev = virtio_bus_get_device(&dev->bus);
298366
     for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
298366
-        if (!virtio_queue_get_num(dev->vdev, n)) {
298366
+        if (!virtio_queue_get_num(vdev, n)) {
298366
             continue;
298366
         }
298366
         r = virtio_ccw_set_guest2host_notifier(dev, n, true, true);
45bdef
@@ -118,7 +122,7 @@ static void virtio_ccw_start_ioeventfd(VirtioCcwDevice *dev)
298366
 
298366
   assign_error:
298366
     while (--n >= 0) {
298366
-        if (!virtio_queue_get_num(dev->vdev, n)) {
298366
+        if (!virtio_queue_get_num(vdev, n)) {
298366
             continue;
298366
         }
298366
         r = virtio_ccw_set_guest2host_notifier(dev, n, false, false);
45bdef
@@ -132,13 +136,15 @@ static void virtio_ccw_start_ioeventfd(VirtioCcwDevice *dev)
298366
 
298366
 static void virtio_ccw_stop_ioeventfd(VirtioCcwDevice *dev)
298366
 {
298366
+    VirtIODevice *vdev;
298366
     int n, r;
298366
 
298366
     if (!dev->ioeventfd_started) {
298366
         return;
298366
     }
298366
+    vdev = virtio_bus_get_device(&dev->bus);
298366
     for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
298366
-        if (!virtio_queue_get_num(dev->vdev, n)) {
298366
+        if (!virtio_queue_get_num(vdev, n)) {
298366
             continue;
298366
         }
298366
         r = virtio_ccw_set_guest2host_notifier(dev, n, false, false);
45bdef
@@ -189,7 +195,7 @@ typedef struct VirtioFeatDesc {
298366
 static int virtio_ccw_set_vqs(SubchDev *sch, uint64_t addr, uint32_t align,
298366
                               uint16_t index, uint16_t num)
298366
 {
298366
-    VirtioCcwDevice *dev = sch->driver_data;
298366
+    VirtIODevice *vdev = virtio_ccw_get_vdev(sch);
298366
 
298366
     if (index > VIRTIO_PCI_QUEUE_MAX) {
298366
         return -EINVAL;
45bdef
@@ -200,23 +206,23 @@ static int virtio_ccw_set_vqs(SubchDev *sch, uint64_t addr, uint32_t align,
298366
         return -EINVAL;
298366
     }
298366
 
298366
-    if (!dev) {
298366
+    if (!vdev) {
298366
         return -EINVAL;
298366
     }
298366
 
298366
-    virtio_queue_set_addr(dev->vdev, index, addr);
298366
+    virtio_queue_set_addr(vdev, index, addr);
298366
     if (!addr) {
298366
-        virtio_queue_set_vector(dev->vdev, index, 0);
298366
+        virtio_queue_set_vector(vdev, index, 0);
298366
     } else {
298366
         /* Fail if we don't have a big enough queue. */
298366
         /* TODO: Add interface to handle vring.num changing */
298366
-        if (virtio_queue_get_num(dev->vdev, index) > num) {
298366
+        if (virtio_queue_get_num(vdev, index) > num) {
298366
             return -EINVAL;
298366
         }
298366
-        virtio_queue_set_vector(dev->vdev, index, index);
298366
+        virtio_queue_set_vector(vdev, index, index);
298366
     }
298366
     /* tell notify handler in case of config change */
298366
-    dev->vdev->config_vector = VIRTIO_PCI_QUEUE_MAX;
298366
+    vdev->config_vector = VIRTIO_PCI_QUEUE_MAX;
298366
     return 0;
298366
 }
298366
 
45bdef
@@ -230,6 +236,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
298366
     hwaddr indicators;
298366
     VqConfigBlock vq_config;
298366
     VirtioCcwDevice *dev = sch->driver_data;
298366
+    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
298366
     bool check_len;
298366
     int len;
298366
     hwaddr hw_len;
45bdef
@@ -272,7 +279,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
298366
         break;
298366
     case CCW_CMD_VDEV_RESET:
298366
         virtio_ccw_stop_ioeventfd(dev);
298366
-        virtio_reset(dev->vdev);
298366
+        virtio_reset(vdev);
298366
         ret = 0;
298366
         break;
298366
     case CCW_CMD_READ_FEAT:
45bdef
@@ -319,7 +326,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
298366
             features.features = ldl_le_phys(ccw.cda);
298366
             if (features.index < ARRAY_SIZE(dev->host_features)) {
298366
                 virtio_bus_set_vdev_features(&dev->bus, features.features);
298366
-                dev->vdev->guest_features = features.features;
298366
+                vdev->guest_features = features.features;
298366
             } else {
298366
                 /*
298366
                  * If the guest supports more feature bits, assert that it
45bdef
@@ -337,30 +344,30 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
298366
         break;
298366
     case CCW_CMD_READ_CONF:
298366
         if (check_len) {
298366
-            if (ccw.count > dev->vdev->config_len) {
298366
+            if (ccw.count > vdev->config_len) {
298366
                 ret = -EINVAL;
298366
                 break;
298366
             }
298366
         }
298366
-        len = MIN(ccw.count, dev->vdev->config_len);
298366
+        len = MIN(ccw.count, vdev->config_len);
298366
         if (!ccw.cda) {
298366
             ret = -EFAULT;
298366
         } else {
298366
-            virtio_bus_get_vdev_config(&dev->bus, dev->vdev->config);
298366
+            virtio_bus_get_vdev_config(&dev->bus, vdev->config);
298366
             /* XXX config space endianness */
298366
-            cpu_physical_memory_write(ccw.cda, dev->vdev->config, len);
298366
+            cpu_physical_memory_write(ccw.cda, vdev->config, len);
298366
             sch->curr_status.scsw.count = ccw.count - len;
298366
             ret = 0;
298366
         }
298366
         break;
298366
     case CCW_CMD_WRITE_CONF:
298366
         if (check_len) {
298366
-            if (ccw.count > dev->vdev->config_len) {
298366
+            if (ccw.count > vdev->config_len) {
298366
                 ret = -EINVAL;
298366
                 break;
298366
             }
298366
         }
298366
-        len = MIN(ccw.count, dev->vdev->config_len);
298366
+        len = MIN(ccw.count, vdev->config_len);
298366
         hw_len = len;
298366
         if (!ccw.cda) {
298366
             ret = -EFAULT;
45bdef
@@ -371,9 +378,9 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
298366
             } else {
298366
                 len = hw_len;
298366
                 /* XXX config space endianness */
298366
-                memcpy(dev->vdev->config, config, len);
298366
+                memcpy(vdev->config, config, len);
298366
                 cpu_physical_memory_unmap(config, hw_len, 0, hw_len);
298366
-                virtio_bus_set_vdev_config(&dev->bus, dev->vdev->config);
298366
+                virtio_bus_set_vdev_config(&dev->bus, vdev->config);
298366
                 sch->curr_status.scsw.count = ccw.count - len;
298366
                 ret = 0;
298366
             }
45bdef
@@ -397,9 +404,9 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
298366
             if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) {
298366
                 virtio_ccw_stop_ioeventfd(dev);
298366
             }
298366
-            virtio_set_status(dev->vdev, status);
298366
-            if (dev->vdev->status == 0) {
298366
-                virtio_reset(dev->vdev);
298366
+            virtio_set_status(vdev, status);
298366
+            if (vdev->status == 0) {
298366
+                virtio_reset(vdev);
298366
             }
298366
             if (status & VIRTIO_CONFIG_S_DRIVER_OK) {
298366
                 virtio_ccw_start_ioeventfd(dev);
45bdef
@@ -463,7 +470,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
298366
             ret = -EFAULT;
298366
         } else {
298366
             vq_config.index = lduw_phys(ccw.cda);
298366
-            vq_config.num_max = virtio_queue_get_num(dev->vdev,
298366
+            vq_config.num_max = virtio_queue_get_num(vdev,
298366
                                                      vq_config.index);
298366
             stw_phys(ccw.cda + sizeof(vq_config.index), vq_config.num_max);
298366
             sch->curr_status.scsw.count = ccw.count - sizeof(vq_config);
45bdef
@@ -495,7 +502,6 @@ static int virtio_ccw_device_init(VirtioCcwDevice *dev, VirtIODevice *vdev)
298366
     sch->driver_data = dev;
298366
     dev->sch = sch;
298366
 
298366
-    dev->vdev = vdev;
298366
     dev->indicators = 0;
298366
 
298366
     /* Initialize subchannel structure. */
45bdef
@@ -608,7 +614,7 @@ static int virtio_ccw_device_init(VirtioCcwDevice *dev, VirtIODevice *vdev)
298366
     memset(&sch->id, 0, sizeof(SenseId));
298366
     sch->id.reserved = 0xff;
298366
     sch->id.cu_type = VIRTIO_CCW_CU_TYPE;
298366
-    sch->id.cu_model = dev->vdev->device_id;
298366
+    sch->id.cu_model = vdev->device_id;
298366
 
298366
     /* Only the first 32 feature bits are used. */
298366
     dev->host_features[0] = virtio_bus_get_vdev_features(&dev->bus,
45bdef
@@ -892,9 +898,10 @@ static unsigned virtio_ccw_get_features(DeviceState *d)
298366
 static void virtio_ccw_reset(DeviceState *d)
298366
 {
298366
     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
298366
+    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
298366
 
298366
     virtio_ccw_stop_ioeventfd(dev);
298366
-    virtio_reset(dev->vdev);
298366
+    virtio_reset(vdev);
298366
     css_reset_sch(dev->sch);
298366
     dev->indicators = 0;
298366
     dev->indicators2 = 0;
45bdef
@@ -934,9 +941,10 @@ static int virtio_ccw_set_host_notifier(DeviceState *d, int n, bool assign)
298366
 static int virtio_ccw_set_guest_notifier(VirtioCcwDevice *dev, int n,
298366
                                          bool assign, bool with_irqfd)
298366
 {
298366
-    VirtQueue *vq = virtio_get_queue(dev->vdev, n);
298366
+    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
298366
+    VirtQueue *vq = virtio_get_queue(vdev, n);
298366
     EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
298366
-    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(dev->vdev);
298366
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
298366
 
298366
     if (assign) {
298366
         int r = event_notifier_init(notifier, 0);
45bdef
@@ -952,16 +960,16 @@ static int virtio_ccw_set_guest_notifier(VirtioCcwDevice *dev, int n,
298366
          * land in qemu (and only the irq fd) in this code.
298366
          */
298366
         if (k->guest_notifier_mask) {
298366
-            k->guest_notifier_mask(dev->vdev, n, false);
298366
+            k->guest_notifier_mask(vdev, n, false);
298366
         }
298366
         /* get lost events and re-inject */
298366
         if (k->guest_notifier_pending &&
298366
-            k->guest_notifier_pending(dev->vdev, n)) {
298366
+            k->guest_notifier_pending(vdev, n)) {
298366
             event_notifier_set(notifier);
298366
         }
298366
     } else {
298366
         if (k->guest_notifier_mask) {
298366
-            k->guest_notifier_mask(dev->vdev, n, true);
298366
+            k->guest_notifier_mask(vdev, n, true);
298366
         }
298366
         virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd);
298366
         event_notifier_cleanup(notifier);
45bdef
@@ -973,7 +981,7 @@ static int virtio_ccw_set_guest_notifiers(DeviceState *d, int nvqs,
298366
                                           bool assigned)
298366
 {
298366
     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
298366
-    VirtIODevice *vdev = dev->vdev;
298366
+    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
298366
     int r, n;
298366
 
298366
     for (n = 0; n < nvqs; n++) {