Skip to content

Commit 2e02104

Browse files
Heinz GraalfsChristian Borntraeger
authored andcommitted
virtio_ccw: fix vcdev pointer handling issues
The interrupt handler virtio_ccw_int_handler() using the vcdev pointer is protected by the ccw_device lock. Resetting the pointer within the ccw_device structure should be done when holding this lock. Also resetting the vcdev pointer (under the ccw_device lock) prior to freeing the vcdev pointer memory removes a critical path. Signed-off-by: Heinz Graalfs <graalfs@linux.vnet.ibm.com> Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
1 parent 1ee0bc5 commit 2e02104

1 file changed

Lines changed: 28 additions & 7 deletions

File tree

‎drivers/s390/kvm/virtio_ccw.c‎

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,8 @@ static void virtio_ccw_int_handler(struct ccw_device *cdev,
636636
struct virtqueue *vq;
637637
struct virtio_driver *drv;
638638

639+
if (!vcdev)
640+
return;
639641
/* Check if it's a notification from the host. */
640642
if ((intparm == 0) &&
641643
(scsw_stctl(&irb->scsw) ==
@@ -734,23 +736,37 @@ static int virtio_ccw_probe(struct ccw_device *cdev)
734736
return 0;
735737
}
736738

739+
static struct virtio_ccw_device *virtio_grab_drvdata(struct ccw_device *cdev)
740+
{
741+
unsigned long flags;
742+
struct virtio_ccw_device *vcdev;
743+
744+
spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
745+
vcdev = dev_get_drvdata(&cdev->dev);
746+
if (!vcdev) {
747+
spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
748+
return NULL;
749+
}
750+
dev_set_drvdata(&cdev->dev, NULL);
751+
spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
752+
return vcdev;
753+
}
754+
737755
static void virtio_ccw_remove(struct ccw_device *cdev)
738756
{
739-
struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev);
757+
struct virtio_ccw_device *vcdev = virtio_grab_drvdata(cdev);
740758

741-
if (cdev->online) {
759+
if (vcdev && cdev->online)
742760
unregister_virtio_device(&vcdev->vdev);
743-
dev_set_drvdata(&cdev->dev, NULL);
744-
}
745761
cdev->handler = NULL;
746762
}
747763

748764
static int virtio_ccw_offline(struct ccw_device *cdev)
749765
{
750-
struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev);
766+
struct virtio_ccw_device *vcdev = virtio_grab_drvdata(cdev);
751767

752-
unregister_virtio_device(&vcdev->vdev);
753-
dev_set_drvdata(&cdev->dev, NULL);
768+
if (vcdev)
769+
unregister_virtio_device(&vcdev->vdev);
754770
return 0;
755771
}
756772

@@ -759,6 +775,7 @@ static int virtio_ccw_online(struct ccw_device *cdev)
759775
{
760776
int ret;
761777
struct virtio_ccw_device *vcdev;
778+
unsigned long flags;
762779

763780
vcdev = kzalloc(sizeof(*vcdev), GFP_KERNEL);
764781
if (!vcdev) {
@@ -786,7 +803,9 @@ static int virtio_ccw_online(struct ccw_device *cdev)
786803
INIT_LIST_HEAD(&vcdev->virtqueues);
787804
spin_lock_init(&vcdev->lock);
788805

806+
spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
789807
dev_set_drvdata(&cdev->dev, vcdev);
808+
spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
790809
vcdev->vdev.id.vendor = cdev->id.cu_type;
791810
vcdev->vdev.id.device = cdev->id.cu_model;
792811
ret = register_virtio_device(&vcdev->vdev);
@@ -797,7 +816,9 @@ static int virtio_ccw_online(struct ccw_device *cdev)
797816
}
798817
return 0;
799818
out_put:
819+
spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
800820
dev_set_drvdata(&cdev->dev, NULL);
821+
spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
801822
put_device(&vcdev->vdev.dev);
802823
return ret;
803824
out_free:

0 commit comments

Comments
 (0)