aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/virtio
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2014-10-13 20:10:29 -0400
committerRusty Russell <rusty@rustcorp.com.au>2014-10-14 19:54:53 -0400
commit6fbc198cf623944ab60a1db6d306a4d55cdd820d (patch)
treef0e9102dc35317a14829f0109ef999bc65379cd8 /drivers/virtio
parent7ec62d421bdf29cb31101ae2689f7f3a9906289a (diff)
virtio_pci: fix virtio spec compliance on restore
On restore, virtio pci does the following: + set features + init vqs etc - device can be used at this point! + set ACKNOWLEDGE,DRIVER and DRIVER_OK status bits This is in violation of the virtio spec, which requires the following order: - ACKNOWLEDGE - DRIVER - init vqs - DRIVER_OK This behaviour will break with hypervisors that assume spec compliant behaviour. It seems like a good idea to have this patch applied to stable branches to reduce the support butden for the hypervisors. Cc: stable@vger.kernel.org Cc: Amit Shah <amit.shah@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'drivers/virtio')
-rw-r--r--drivers/virtio/virtio_pci.c33
1 files changed, 30 insertions, 3 deletions
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
index 3d1463c6b120..add40d00dcdb 100644
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -789,6 +789,7 @@ static int virtio_pci_restore(struct device *dev)
789 struct pci_dev *pci_dev = to_pci_dev(dev); 789 struct pci_dev *pci_dev = to_pci_dev(dev);
790 struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev); 790 struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
791 struct virtio_driver *drv; 791 struct virtio_driver *drv;
792 unsigned status = 0;
792 int ret; 793 int ret;
793 794
794 drv = container_of(vp_dev->vdev.dev.driver, 795 drv = container_of(vp_dev->vdev.dev.driver,
@@ -799,14 +800,40 @@ static int virtio_pci_restore(struct device *dev)
799 return ret; 800 return ret;
800 801
801 pci_set_master(pci_dev); 802 pci_set_master(pci_dev);
803 /* We always start by resetting the device, in case a previous
804 * driver messed it up. */
805 vp_reset(&vp_dev->vdev);
806
807 /* Acknowledge that we've seen the device. */
808 status |= VIRTIO_CONFIG_S_ACKNOWLEDGE;
809 vp_set_status(&vp_dev->vdev, status);
810
811 /* Maybe driver failed before freeze.
812 * Restore the failed status, for debugging. */
813 status |= vp_dev->saved_status & VIRTIO_CONFIG_S_FAILED;
814 vp_set_status(&vp_dev->vdev, status);
815
816 if (!drv)
817 return 0;
818
819 /* We have a driver! */
820 status |= VIRTIO_CONFIG_S_DRIVER;
821 vp_set_status(&vp_dev->vdev, status);
822
802 vp_finalize_features(&vp_dev->vdev); 823 vp_finalize_features(&vp_dev->vdev);
803 824
804 if (drv && drv->restore) 825 if (drv->restore) {
805 ret = drv->restore(&vp_dev->vdev); 826 ret = drv->restore(&vp_dev->vdev);
827 if (ret) {
828 status |= VIRTIO_CONFIG_S_FAILED;
829 vp_set_status(&vp_dev->vdev, status);
830 return ret;
831 }
832 }
806 833
807 /* Finally, tell the device we're all set */ 834 /* Finally, tell the device we're all set */
808 if (!ret) 835 status |= VIRTIO_CONFIG_S_DRIVER_OK;
809 vp_set_status(&vp_dev->vdev, vp_dev->saved_status); 836 vp_set_status(&vp_dev->vdev, status);
810 837
811 return ret; 838 return ret;
812} 839}