aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/virtio
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2014-12-04 13:20:27 -0500
committerMichael S. Tsirkin <mst@redhat.com>2014-12-09 09:32:32 -0500
commit5c609a5ef05d98e26778824ba84581fe5e400db6 (patch)
tree487da89e8ad7ef9d3bcb485ae877518f1669e18b /drivers/virtio
parentce15408f350c4b97635618692a45aedabfdd2696 (diff)
virtio: allow finalize_features to fail
This will make it easy for transports to validate features and return failure. Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'drivers/virtio')
-rw-r--r--drivers/virtio/virtio.c21
-rw-r--r--drivers/virtio/virtio_mmio.c4
-rw-r--r--drivers/virtio/virtio_pci.c4
3 files changed, 20 insertions, 9 deletions
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index 224f85442f3f..e1673a511d17 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -212,7 +212,9 @@ static int virtio_dev_probe(struct device *_d)
212 if (device_features & (1ULL << i)) 212 if (device_features & (1ULL << i))
213 __virtio_set_bit(dev, i); 213 __virtio_set_bit(dev, i);
214 214
215 dev->config->finalize_features(dev); 215 err = dev->config->finalize_features(dev);
216 if (err)
217 goto err;
216 218
217 if (virtio_has_feature(dev, VIRTIO_F_VERSION_1)) { 219 if (virtio_has_feature(dev, VIRTIO_F_VERSION_1)) {
218 add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK); 220 add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK);
@@ -354,6 +356,7 @@ EXPORT_SYMBOL_GPL(virtio_device_freeze);
354int virtio_device_restore(struct virtio_device *dev) 356int virtio_device_restore(struct virtio_device *dev)
355{ 357{
356 struct virtio_driver *drv = drv_to_virtio(dev->dev.driver); 358 struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
359 int ret;
357 360
358 /* We always start by resetting the device, in case a previous 361 /* We always start by resetting the device, in case a previous
359 * driver messed it up. */ 362 * driver messed it up. */
@@ -373,14 +376,14 @@ int virtio_device_restore(struct virtio_device *dev)
373 /* We have a driver! */ 376 /* We have a driver! */
374 add_status(dev, VIRTIO_CONFIG_S_DRIVER); 377 add_status(dev, VIRTIO_CONFIG_S_DRIVER);
375 378
376 dev->config->finalize_features(dev); 379 ret = dev->config->finalize_features(dev);
380 if (ret)
381 goto err;
377 382
378 if (drv->restore) { 383 if (drv->restore) {
379 int ret = drv->restore(dev); 384 ret = drv->restore(dev);
380 if (ret) { 385 if (ret)
381 add_status(dev, VIRTIO_CONFIG_S_FAILED); 386 goto err;
382 return ret;
383 }
384 } 387 }
385 388
386 /* Finally, tell the device we're all set */ 389 /* Finally, tell the device we're all set */
@@ -389,6 +392,10 @@ int virtio_device_restore(struct virtio_device *dev)
389 virtio_config_enable(dev); 392 virtio_config_enable(dev);
390 393
391 return 0; 394 return 0;
395
396err:
397 add_status(dev, VIRTIO_CONFIG_S_FAILED);
398 return ret;
392} 399}
393EXPORT_SYMBOL_GPL(virtio_device_restore); 400EXPORT_SYMBOL_GPL(virtio_device_restore);
394#endif 401#endif
diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
index aec1daee9ada..5219210d31ce 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -152,7 +152,7 @@ static u64 vm_get_features(struct virtio_device *vdev)
152 return readl(vm_dev->base + VIRTIO_MMIO_HOST_FEATURES); 152 return readl(vm_dev->base + VIRTIO_MMIO_HOST_FEATURES);
153} 153}
154 154
155static void vm_finalize_features(struct virtio_device *vdev) 155static int vm_finalize_features(struct virtio_device *vdev)
156{ 156{
157 struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev); 157 struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
158 158
@@ -164,6 +164,8 @@ static void vm_finalize_features(struct virtio_device *vdev)
164 164
165 writel(0, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES_SEL); 165 writel(0, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES_SEL);
166 writel(vdev->features, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES); 166 writel(vdev->features, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES);
167
168 return 0;
167} 169}
168 170
169static void vm_get(struct virtio_device *vdev, unsigned offset, 171static void vm_get(struct virtio_device *vdev, unsigned offset,
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
index dd6df979862b..9be59d9f2f19 100644
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -112,7 +112,7 @@ static u64 vp_get_features(struct virtio_device *vdev)
112} 112}
113 113
114/* virtio config->finalize_features() implementation */ 114/* virtio config->finalize_features() implementation */
115static void vp_finalize_features(struct virtio_device *vdev) 115static int vp_finalize_features(struct virtio_device *vdev)
116{ 116{
117 struct virtio_pci_device *vp_dev = to_vp_device(vdev); 117 struct virtio_pci_device *vp_dev = to_vp_device(vdev);
118 118
@@ -124,6 +124,8 @@ static void vp_finalize_features(struct virtio_device *vdev)
124 124
125 /* We only support 32 feature bits. */ 125 /* We only support 32 feature bits. */
126 iowrite32(vdev->features, vp_dev->ioaddr + VIRTIO_PCI_GUEST_FEATURES); 126 iowrite32(vdev->features, vp_dev->ioaddr + VIRTIO_PCI_GUEST_FEATURES);
127
128 return 0;
127} 129}
128 130
129/* virtio config->get() implementation */ 131/* virtio config->get() implementation */