Skip to content

Commit

Permalink
virtio: unify config_changed handling
Browse files Browse the repository at this point in the history
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 3fff017
	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>
  • Loading branch information
Michael S. Tsirkin authored and Rusty Russell committed Oct 14, 2014
1 parent 6fbc198 commit 016c98c
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 28 deletions.
6 changes: 1 addition & 5 deletions drivers/misc/mic/card/mic_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
9 changes: 1 addition & 8 deletions drivers/s390/kvm/kvm_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 1 addition & 5 deletions drivers/s390/kvm/virtio_ccw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
9 changes: 9 additions & 0 deletions drivers/virtio/virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 2 additions & 5 deletions drivers/virtio/virtio_mmio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
6 changes: 1 addition & 5 deletions drivers/virtio/virtio_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions include/linux/virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down

0 comments on commit 016c98c

Please sign in to comment.