qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: lersek@redhat.com, qemu-stable@nongnu.org, Petar.Jovanovic@imgtec.com
Subject: [Qemu-devel] [PATCH 03/51] virtio-ccw: remove vdev field
Date: Fri, 21 Feb 2014 02:16:39 -0600	[thread overview]
Message-ID: <1392970647-21528-4-git-send-email-mdroth@linux.vnet.ibm.com> (raw)
In-Reply-To: <1392970647-21528-1-git-send-email-mdroth@linux.vnet.ibm.com>

From: Paolo Bonzini <pbonzini@redhat.com>

The vdev field is complicated to synchronize.  Just access the
BusState's list of children.

Cc: qemu-stable@nongnu.org
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Acked-by: Andreas Faerber <afaerber@suse.de>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit f24a684073bcdaf4e9d3c592345744ba3356d9e3)

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 hw/s390x/virtio-ccw.c |   80 +++++++++++++++++++++++++++----------------------
 hw/s390x/virtio-ccw.h |    1 -
 2 files changed, 44 insertions(+), 37 deletions(-)

diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index e8b4547..ecc80ec 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -57,9 +57,10 @@ static const TypeInfo virtual_css_bus_info = {
 VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch)
 {
     VirtIODevice *vdev = NULL;
+    VirtioCcwDevice *dev = sch->driver_data;
 
-    if (sch->driver_data) {
-        vdev = ((VirtioCcwDevice *)sch->driver_data)->vdev;
+    if (dev) {
+        vdev = virtio_bus_get_device(&dev->bus);
     }
     return vdev;
 }
@@ -67,7 +68,8 @@ VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch)
 static int virtio_ccw_set_guest2host_notifier(VirtioCcwDevice *dev, int n,
                                               bool assign, bool set_handler)
 {
-    VirtQueue *vq = virtio_get_queue(dev->vdev, n);
+    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
+    VirtQueue *vq = virtio_get_queue(vdev, n);
     EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
     int r = 0;
     SubchDev *sch = dev->sch;
@@ -97,6 +99,7 @@ static int virtio_ccw_set_guest2host_notifier(VirtioCcwDevice *dev, int n,
 
 static void virtio_ccw_start_ioeventfd(VirtioCcwDevice *dev)
 {
+    VirtIODevice *vdev;
     int n, r;
 
     if (!(dev->flags & VIRTIO_CCW_FLAG_USE_IOEVENTFD) ||
@@ -104,8 +107,9 @@ static void virtio_ccw_start_ioeventfd(VirtioCcwDevice *dev)
         dev->ioeventfd_started) {
         return;
     }
+    vdev = virtio_bus_get_device(&dev->bus);
     for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
-        if (!virtio_queue_get_num(dev->vdev, n)) {
+        if (!virtio_queue_get_num(vdev, n)) {
             continue;
         }
         r = virtio_ccw_set_guest2host_notifier(dev, n, true, true);
@@ -118,7 +122,7 @@ static void virtio_ccw_start_ioeventfd(VirtioCcwDevice *dev)
 
   assign_error:
     while (--n >= 0) {
-        if (!virtio_queue_get_num(dev->vdev, n)) {
+        if (!virtio_queue_get_num(vdev, n)) {
             continue;
         }
         r = virtio_ccw_set_guest2host_notifier(dev, n, false, false);
@@ -132,13 +136,15 @@ static void virtio_ccw_start_ioeventfd(VirtioCcwDevice *dev)
 
 static void virtio_ccw_stop_ioeventfd(VirtioCcwDevice *dev)
 {
+    VirtIODevice *vdev;
     int n, r;
 
     if (!dev->ioeventfd_started) {
         return;
     }
+    vdev = virtio_bus_get_device(&dev->bus);
     for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
-        if (!virtio_queue_get_num(dev->vdev, n)) {
+        if (!virtio_queue_get_num(vdev, n)) {
             continue;
         }
         r = virtio_ccw_set_guest2host_notifier(dev, n, false, false);
@@ -189,7 +195,7 @@ typedef struct VirtioFeatDesc {
 static int virtio_ccw_set_vqs(SubchDev *sch, uint64_t addr, uint32_t align,
                               uint16_t index, uint16_t num)
 {
-    VirtioCcwDevice *dev = sch->driver_data;
+    VirtIODevice *vdev = virtio_ccw_get_vdev(sch);
 
     if (index > VIRTIO_PCI_QUEUE_MAX) {
         return -EINVAL;
@@ -200,23 +206,23 @@ static int virtio_ccw_set_vqs(SubchDev *sch, uint64_t addr, uint32_t align,
         return -EINVAL;
     }
 
-    if (!dev) {
+    if (!vdev) {
         return -EINVAL;
     }
 
-    virtio_queue_set_addr(dev->vdev, index, addr);
+    virtio_queue_set_addr(vdev, index, addr);
     if (!addr) {
-        virtio_queue_set_vector(dev->vdev, index, 0);
+        virtio_queue_set_vector(vdev, index, 0);
     } else {
         /* Fail if we don't have a big enough queue. */
         /* TODO: Add interface to handle vring.num changing */
-        if (virtio_queue_get_num(dev->vdev, index) > num) {
+        if (virtio_queue_get_num(vdev, index) > num) {
             return -EINVAL;
         }
-        virtio_queue_set_vector(dev->vdev, index, index);
+        virtio_queue_set_vector(vdev, index, index);
     }
     /* tell notify handler in case of config change */
-    dev->vdev->config_vector = VIRTIO_PCI_QUEUE_MAX;
+    vdev->config_vector = VIRTIO_PCI_QUEUE_MAX;
     return 0;
 }
 
@@ -230,6 +236,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
     hwaddr indicators;
     VqConfigBlock vq_config;
     VirtioCcwDevice *dev = sch->driver_data;
+    VirtIODevice *vdev = virtio_ccw_get_vdev(sch);
     bool check_len;
     int len;
     hwaddr hw_len;
@@ -272,7 +279,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
         break;
     case CCW_CMD_VDEV_RESET:
         virtio_ccw_stop_ioeventfd(dev);
-        virtio_reset(dev->vdev);
+        virtio_reset(vdev);
         ret = 0;
         break;
     case CCW_CMD_READ_FEAT:
@@ -319,7 +326,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
             features.features = ldl_le_phys(ccw.cda);
             if (features.index < ARRAY_SIZE(dev->host_features)) {
                 virtio_bus_set_vdev_features(&dev->bus, features.features);
-                dev->vdev->guest_features = features.features;
+                vdev->guest_features = features.features;
             } else {
                 /*
                  * If the guest supports more feature bits, assert that it
@@ -337,30 +344,30 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
         break;
     case CCW_CMD_READ_CONF:
         if (check_len) {
-            if (ccw.count > dev->vdev->config_len) {
+            if (ccw.count > vdev->config_len) {
                 ret = -EINVAL;
                 break;
             }
         }
-        len = MIN(ccw.count, dev->vdev->config_len);
+        len = MIN(ccw.count, vdev->config_len);
         if (!ccw.cda) {
             ret = -EFAULT;
         } else {
-            virtio_bus_get_vdev_config(&dev->bus, dev->vdev->config);
+            virtio_bus_get_vdev_config(&dev->bus, vdev->config);
             /* XXX config space endianness */
-            cpu_physical_memory_write(ccw.cda, dev->vdev->config, len);
+            cpu_physical_memory_write(ccw.cda, vdev->config, len);
             sch->curr_status.scsw.count = ccw.count - len;
             ret = 0;
         }
         break;
     case CCW_CMD_WRITE_CONF:
         if (check_len) {
-            if (ccw.count > dev->vdev->config_len) {
+            if (ccw.count > vdev->config_len) {
                 ret = -EINVAL;
                 break;
             }
         }
-        len = MIN(ccw.count, dev->vdev->config_len);
+        len = MIN(ccw.count, vdev->config_len);
         hw_len = len;
         if (!ccw.cda) {
             ret = -EFAULT;
@@ -371,9 +378,9 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
             } else {
                 len = hw_len;
                 /* XXX config space endianness */
-                memcpy(dev->vdev->config, config, len);
+                memcpy(vdev->config, config, len);
                 cpu_physical_memory_unmap(config, hw_len, 0, hw_len);
-                virtio_bus_set_vdev_config(&dev->bus, dev->vdev->config);
+                virtio_bus_set_vdev_config(&dev->bus, vdev->config);
                 sch->curr_status.scsw.count = ccw.count - len;
                 ret = 0;
             }
@@ -397,9 +404,9 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
             if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) {
                 virtio_ccw_stop_ioeventfd(dev);
             }
-            virtio_set_status(dev->vdev, status);
-            if (dev->vdev->status == 0) {
-                virtio_reset(dev->vdev);
+            virtio_set_status(vdev, status);
+            if (vdev->status == 0) {
+                virtio_reset(vdev);
             }
             if (status & VIRTIO_CONFIG_S_DRIVER_OK) {
                 virtio_ccw_start_ioeventfd(dev);
@@ -463,7 +470,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
             ret = -EFAULT;
         } else {
             vq_config.index = lduw_phys(ccw.cda);
-            vq_config.num_max = virtio_queue_get_num(dev->vdev,
+            vq_config.num_max = virtio_queue_get_num(vdev,
                                                      vq_config.index);
             stw_phys(ccw.cda + sizeof(vq_config.index), vq_config.num_max);
             sch->curr_status.scsw.count = ccw.count - sizeof(vq_config);
@@ -495,7 +502,6 @@ static int virtio_ccw_device_init(VirtioCcwDevice *dev, VirtIODevice *vdev)
     sch->driver_data = dev;
     dev->sch = sch;
 
-    dev->vdev = vdev;
     dev->indicators = 0;
 
     /* Initialize subchannel structure. */
@@ -608,7 +614,7 @@ static int virtio_ccw_device_init(VirtioCcwDevice *dev, VirtIODevice *vdev)
     memset(&sch->id, 0, sizeof(SenseId));
     sch->id.reserved = 0xff;
     sch->id.cu_type = VIRTIO_CCW_CU_TYPE;
-    sch->id.cu_model = dev->vdev->device_id;
+    sch->id.cu_model = vdev->device_id;
 
     /* Only the first 32 feature bits are used. */
     dev->host_features[0] = virtio_bus_get_vdev_features(&dev->bus,
@@ -891,9 +897,10 @@ static unsigned virtio_ccw_get_features(DeviceState *d)
 static void virtio_ccw_reset(DeviceState *d)
 {
     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
+    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
 
     virtio_ccw_stop_ioeventfd(dev);
-    virtio_reset(dev->vdev);
+    virtio_reset(vdev);
     css_reset_sch(dev->sch);
     dev->indicators = 0;
     dev->indicators2 = 0;
@@ -933,9 +940,10 @@ static int virtio_ccw_set_host_notifier(DeviceState *d, int n, bool assign)
 static int virtio_ccw_set_guest_notifier(VirtioCcwDevice *dev, int n,
                                          bool assign, bool with_irqfd)
 {
-    VirtQueue *vq = virtio_get_queue(dev->vdev, n);
+    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
+    VirtQueue *vq = virtio_get_queue(vdev, n);
     EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
-    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(dev->vdev);
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
 
     if (assign) {
         int r = event_notifier_init(notifier, 0);
@@ -951,16 +959,16 @@ static int virtio_ccw_set_guest_notifier(VirtioCcwDevice *dev, int n,
          * land in qemu (and only the irq fd) in this code.
          */
         if (k->guest_notifier_mask) {
-            k->guest_notifier_mask(dev->vdev, n, false);
+            k->guest_notifier_mask(vdev, n, false);
         }
         /* get lost events and re-inject */
         if (k->guest_notifier_pending &&
-            k->guest_notifier_pending(dev->vdev, n)) {
+            k->guest_notifier_pending(vdev, n)) {
             event_notifier_set(notifier);
         }
     } else {
         if (k->guest_notifier_mask) {
-            k->guest_notifier_mask(dev->vdev, n, true);
+            k->guest_notifier_mask(vdev, n, true);
         }
         virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd);
         event_notifier_cleanup(notifier);
@@ -972,7 +980,7 @@ static int virtio_ccw_set_guest_notifiers(DeviceState *d, int nvqs,
                                           bool assigned)
 {
     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
-    VirtIODevice *vdev = dev->vdev;
+    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
     int r, n;
 
     for (n = 0; n < nvqs; n++) {
diff --git a/hw/s390x/virtio-ccw.h b/hw/s390x/virtio-ccw.h
index 96d6f5d..00932c7 100644
--- a/hw/s390x/virtio-ccw.h
+++ b/hw/s390x/virtio-ccw.h
@@ -77,7 +77,6 @@ typedef struct VirtIOCCWDeviceClass {
 struct VirtioCcwDevice {
     DeviceState parent_obj;
     SubchDev *sch;
-    VirtIODevice *vdev;
     char *bus_id;
     uint32_t host_features[VIRTIO_CCW_FEATURE_SIZE];
     VirtioBusState bus;
-- 
1.7.9.5

  parent reply	other threads:[~2014-02-21  8:18 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-21  8:16 [Qemu-devel] Patch Round-up for stable 1.7.1, freeze on 2013-02-27 Michael Roth
2014-02-21  8:16 ` [Qemu-devel] [PATCH 01/51] virtio-ccw: move virtio_ccw_stop_ioeventfd to virtio_ccw_busdev_unplug Michael Roth
2014-02-21  8:16 ` [Qemu-devel] [PATCH 02/51] virtio-bus: remove vdev field Michael Roth
2014-02-21  8:16 ` Michael Roth [this message]
2014-02-21  8:16 ` [Qemu-devel] [PATCH 04/51] virtio-pci: " Michael Roth
2014-02-21  8:16 ` [Qemu-devel] [PATCH 05/51] virtio-bus: cleanup plug/unplug interface Michael Roth
2014-02-21  8:16 ` [Qemu-devel] [PATCH 06/51] virtio-blk: switch exit callback to VirtioDeviceClass Michael Roth
2014-02-21  8:16 ` [Qemu-devel] [PATCH 07/51] virtio-serial: " Michael Roth
2014-02-21  8:16 ` [Qemu-devel] [PATCH 08/51] virtio-net: " Michael Roth
2014-02-21  8:16 ` [Qemu-devel] [PATCH 09/51] virtio-scsi: " Michael Roth
2014-02-21  8:16 ` [Qemu-devel] [PATCH 10/51] virtio-balloon: " Michael Roth
2014-02-21  8:16 ` [Qemu-devel] [PATCH 11/51] virtio-rng: " Michael Roth
2014-02-21  8:16 ` [Qemu-devel] [PATCH 12/51] virtio-pci: add device_unplugged callback Michael Roth
2014-02-21  8:16 ` [Qemu-devel] [PATCH 13/51] scsi-bus: fix transfer length and direction for VERIFY command Michael Roth
2014-02-21  8:16 ` [Qemu-devel] [PATCH 14/51] scsi-disk: fix VERIFY emulation Michael Roth
2014-02-21  8:16 ` [Qemu-devel] [PATCH 15/51] intel-hda: fix position buffer Michael Roth
2014-02-21  8:16 ` [Qemu-devel] [PATCH 16/51] memory.c: bugfix - ref counting mismatch in memory_region_find Michael Roth
2014-02-21  8:16 ` [Qemu-devel] [PATCH 17/51] qom: Split out object and class caches Michael Roth
2014-02-21  8:16 ` [Qemu-devel] [PATCH 18/51] migration: Fix rate limit Michael Roth
2014-02-21  8:16 ` [Qemu-devel] [PATCH 19/51] vl: add missing transition debug->finish_migrate Michael Roth
2014-02-21  8:16 ` [Qemu-devel] [PATCH 20/51] x86: only allow real mode to access 32bit without LMA Michael Roth
2014-02-21  8:16 ` [Qemu-devel] [PATCH 21/51] qdev-monitor: Avoid device_add crashing on non-device driver name Michael Roth
2014-02-21  8:16 ` [Qemu-devel] [PATCH 22/51] split definitions for exec.c and translate-all.c radix trees Michael Roth
2014-02-21  8:16 ` [Qemu-devel] [PATCH 23/51] exec: replace leaf with skip Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 24/51] exec: pass hw address to phys_page_find Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 25/51] exec: separate sections and nodes per address space Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 26/51] pc: map PCI address space as catchall region for not mapped addresses Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 27/51] piix: fix 32bit pci hole Michael Roth
2014-02-21 14:15   ` Laszlo Ersek
2014-02-21  8:17 ` [Qemu-devel] [PATCH 28/51] target-mips: fix 64-bit FPU config for user-mode emulation Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 29/51] linux-user: pass correct parameter to do_shmctl() Michael Roth
2014-02-21  9:58   ` Laurent Vivier
2014-02-21 20:14     ` Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 30/51] linux-user: create target_structs header to place ipc_perm and shmid_ds Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 31/51] Fix QEMU build on OpenBSD on x86 archs Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 32/51] tcg/optimize: fix known-zero bits for right shift ops Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 33/51] hpet: fix build with CONFIG_HPET off Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 34/51] block/iscsi: use a bh to schedule co reentrance Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 35/51] qemu_opts_parse(): always check return value Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 36/51] s390x/kvm: Fix diagnose handling Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 37/51] seccomp: exit if seccomp_init() fails Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 38/51] mainstone: Fix duplicate array values for key 'space' Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 39/51] migration: qmp_migrate(): keep working after syntax error Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 40/51] vfio-pci: Release all MSI-X vectors when disabled Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 41/51] block/curl: Implement the libcurl timer callback interface Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 42/51] scsi: Support TEST UNIT READY in the dummy LUN0 Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 43/51] scsi: Assign cancel_io vector for scsi_disk_emulate_ops Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 44/51] virtio-scsi: Cleanup of I/Os that never started Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 45/51] virtio-scsi: Prevent assertion on missed events Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 46/51] KVM: Retry KVM_CREATE_VM on EINTR Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 47/51] i386: Add missing include file for QEMU_PACKED Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 48/51] linux-user: Fix trampoline code for CRIS Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 50/51] memory: fix limiting of translation at a page boundary Michael Roth
2014-02-21  8:17 ` [Qemu-devel] [PATCH 51/51] tcg-arm: The shift count of op_rotl_i32 is in args[2] not args[1] Michael Roth
2014-02-21 10:23 ` [Qemu-devel] Patch Round-up for stable 1.7.1, freeze on 2013-02-27 Paolo Bonzini
2014-03-04 17:04 ` Laszlo Ersek
2014-03-04 17:46   ` Petar Jovanovic
2014-03-04 17:54     ` Michael Roth
2014-03-12 10:53       ` [Qemu-devel] [Qemu-stable] " Michael Tokarev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1392970647-21528-4-git-send-email-mdroth@linux.vnet.ibm.com \
    --to=mdroth@linux.vnet.ibm.com \
    --cc=Petar.Jovanovic@imgtec.com \
    --cc=lersek@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).