virtio: unify config_changed handling
authorMichael S. Tsirkin <mst@redhat.com>
Tue, 14 Oct 2014 00:10:34 +0000 (10:40 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 14 Oct 2014 23:54:54 +0000 (10:24 +1030)
Replace duplicated code in all transports with a single wrapper in
virtio.c.

The only functional change is in virtio_mmio.c: if a buggy device sends
us an interrupt before driver is set, we previously returned IRQ_NONE,
now we return IRQ_HANDLED.

As this must not happen in practice, this does not look like a big deal.

See also commit 3fff0179e33cd7d0a688dab65700c46ad089e934
virtio-pci: do not oops on config change if driver not loaded.
for the original motivation behind the driver check.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
drivers/misc/mic/card/mic_virtio.c
drivers/s390/kvm/kvm_virtio.c
drivers/s390/kvm/virtio_ccw.c
drivers/virtio/virtio.c
drivers/virtio/virtio_mmio.c
drivers/virtio/virtio_pci.c
include/linux/virtio.h

index f14b60080c210a6fa2b53071f40b3c0292f43905..e64794730e21561ed89011915da7c622b40e0c3a 100644 (file)
@@ -462,16 +462,12 @@ static void mic_handle_config_change(struct mic_device_desc __iomem *d,
        struct mic_device_ctrl __iomem *dc
                = (void __iomem *)d + mic_aligned_desc_size(d);
        struct mic_vdev *mvdev = (struct mic_vdev *)ioread64(&dc->vdev);
-       struct virtio_driver *drv;
 
        if (ioread8(&dc->config_change) != MIC_VIRTIO_PARAM_CONFIG_CHANGED)
                return;
 
        dev_dbg(mdrv->dev, "%s %d\n", __func__, __LINE__);
-       drv = container_of(mvdev->vdev.dev.driver,
-                               struct virtio_driver, driver);
-       if (drv->config_changed)
-               drv->config_changed(&mvdev->vdev);
+       virtio_config_changed(&mvdev->vdev);
        iowrite8(1, &dc->guest_ack);
 }
 
index a1349653c6d97dfcac5341b2ba38bebde27e8f2b..643129070c51e6fa8883b39216cfd269e439b7e6 100644 (file)
@@ -406,15 +406,8 @@ static void kvm_extint_handler(struct ext_code ext_code,
 
        switch (param) {
        case VIRTIO_PARAM_CONFIG_CHANGED:
-       {
-               struct virtio_driver *drv;
-               drv = container_of(vq->vdev->dev.driver,
-                                  struct virtio_driver, driver);
-               if (drv->config_changed)
-                       drv->config_changed(vq->vdev);
-
+               virtio_config_changed(vq->vdev);
                break;
-       }
        case VIRTIO_PARAM_DEV_ADD:
                schedule_work(&hotplug_work);
                break;
index d2c0b442bce5fb010fc43414a266c34ee245ca54..6cbe6ef3c889d14841e2c73aa848fa9f563b68ec 100644 (file)
@@ -940,11 +940,7 @@ static void virtio_ccw_int_handler(struct ccw_device *cdev,
                vring_interrupt(0, vq);
        }
        if (test_bit(0, &vcdev->indicators2)) {
-               drv = container_of(vcdev->vdev.dev.driver,
-                                  struct virtio_driver, driver);
-
-               if (drv && drv->config_changed)
-                       drv->config_changed(&vcdev->vdev);
+               virtio_config_changed(&vcdev->vdev);
                clear_bit(0, &vcdev->indicators2);
        }
 }
index fed0ce198ae3eacf76d747948f54cb051bda8d57..3980687401f691fa041552eb33a6d6b2253a3f86 100644 (file)
@@ -239,6 +239,15 @@ void unregister_virtio_device(struct virtio_device *dev)
 }
 EXPORT_SYMBOL_GPL(unregister_virtio_device);
 
+void virtio_config_changed(struct virtio_device *dev)
+{
+       struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
+
+       if (drv && drv->config_changed)
+               drv->config_changed(dev);
+}
+EXPORT_SYMBOL_GPL(virtio_config_changed);
+
 static int virtio_init(void)
 {
        if (bus_register(&virtio_bus) != 0)
index c600ccfd6922b8226727c516ba8a980502e05458..ef9a1650bb804147410f5f8c7ce2bb70426f2728 100644 (file)
@@ -234,8 +234,6 @@ static irqreturn_t vm_interrupt(int irq, void *opaque)
 {
        struct virtio_mmio_device *vm_dev = opaque;
        struct virtio_mmio_vq_info *info;
-       struct virtio_driver *vdrv = container_of(vm_dev->vdev.dev.driver,
-                       struct virtio_driver, driver);
        unsigned long status;
        unsigned long flags;
        irqreturn_t ret = IRQ_NONE;
@@ -244,9 +242,8 @@ static irqreturn_t vm_interrupt(int irq, void *opaque)
        status = readl(vm_dev->base + VIRTIO_MMIO_INTERRUPT_STATUS);
        writel(status, vm_dev->base + VIRTIO_MMIO_INTERRUPT_ACK);
 
-       if (unlikely(status & VIRTIO_MMIO_INT_CONFIG)
-                       && vdrv && vdrv->config_changed) {
-               vdrv->config_changed(&vm_dev->vdev);
+       if (unlikely(status & VIRTIO_MMIO_INT_CONFIG)) {
+               virtio_config_changed(&vm_dev->vdev);
                ret = IRQ_HANDLED;
        }
 
index add40d00dcdbd437333ab8fd7e0427991c92c4b0..f39f4e772e6aa7c9dbcd627dc056551fe4e7f6fd 100644 (file)
@@ -211,12 +211,8 @@ static bool vp_notify(struct virtqueue *vq)
 static irqreturn_t vp_config_changed(int irq, void *opaque)
 {
        struct virtio_pci_device *vp_dev = opaque;
-       struct virtio_driver *drv;
-       drv = container_of(vp_dev->vdev.dev.driver,
-                          struct virtio_driver, driver);
 
-       if (drv && drv->config_changed)
-               drv->config_changed(&vp_dev->vdev);
+       virtio_config_changed(&vp_dev->vdev);
        return IRQ_HANDLED;
 }
 
index b46671e28de29a39d52810e2d51ca36562692889..3c19bd3189cbf91ea6b61138917806760c7c4c06 100644 (file)
@@ -108,6 +108,8 @@ void unregister_virtio_device(struct virtio_device *dev);
 
 void virtio_break_device(struct virtio_device *dev);
 
+void virtio_config_changed(struct virtio_device *dev);
+
 /**
  * virtio_driver - operations for a virtio I/O driver
  * @driver: underlying device driver (populate name and owner).