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>
This commit is contained in:
@@ -212,7 +212,9 @@ static int virtio_dev_probe(struct device *_d)
|
||||
if (device_features & (1ULL << i))
|
||||
__virtio_set_bit(dev, i);
|
||||
|
||||
dev->config->finalize_features(dev);
|
||||
err = dev->config->finalize_features(dev);
|
||||
if (err)
|
||||
goto err;
|
||||
|
||||
if (virtio_has_feature(dev, VIRTIO_F_VERSION_1)) {
|
||||
add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK);
|
||||
@@ -354,6 +356,7 @@ EXPORT_SYMBOL_GPL(virtio_device_freeze);
|
||||
int virtio_device_restore(struct virtio_device *dev)
|
||||
{
|
||||
struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
|
||||
int ret;
|
||||
|
||||
/* We always start by resetting the device, in case a previous
|
||||
* driver messed it up. */
|
||||
@@ -373,14 +376,14 @@ int virtio_device_restore(struct virtio_device *dev)
|
||||
/* We have a driver! */
|
||||
add_status(dev, VIRTIO_CONFIG_S_DRIVER);
|
||||
|
||||
dev->config->finalize_features(dev);
|
||||
ret = dev->config->finalize_features(dev);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
if (drv->restore) {
|
||||
int ret = drv->restore(dev);
|
||||
if (ret) {
|
||||
add_status(dev, VIRTIO_CONFIG_S_FAILED);
|
||||
return ret;
|
||||
}
|
||||
ret = drv->restore(dev);
|
||||
if (ret)
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Finally, tell the device we're all set */
|
||||
@@ -389,6 +392,10 @@ int virtio_device_restore(struct virtio_device *dev)
|
||||
virtio_config_enable(dev);
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
add_status(dev, VIRTIO_CONFIG_S_FAILED);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(virtio_device_restore);
|
||||
#endif
|
||||
|
@@ -152,7 +152,7 @@ static u64 vm_get_features(struct virtio_device *vdev)
|
||||
return readl(vm_dev->base + VIRTIO_MMIO_HOST_FEATURES);
|
||||
}
|
||||
|
||||
static void vm_finalize_features(struct virtio_device *vdev)
|
||||
static int vm_finalize_features(struct virtio_device *vdev)
|
||||
{
|
||||
struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
|
||||
|
||||
@@ -164,6 +164,8 @@ static void vm_finalize_features(struct virtio_device *vdev)
|
||||
|
||||
writel(0, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES_SEL);
|
||||
writel(vdev->features, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void vm_get(struct virtio_device *vdev, unsigned offset,
|
||||
|
@@ -112,7 +112,7 @@ static u64 vp_get_features(struct virtio_device *vdev)
|
||||
}
|
||||
|
||||
/* virtio config->finalize_features() implementation */
|
||||
static void vp_finalize_features(struct virtio_device *vdev)
|
||||
static int vp_finalize_features(struct virtio_device *vdev)
|
||||
{
|
||||
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
|
||||
|
||||
@@ -124,6 +124,8 @@ static void vp_finalize_features(struct virtio_device *vdev)
|
||||
|
||||
/* We only support 32 feature bits. */
|
||||
iowrite32(vdev->features, vp_dev->ioaddr + VIRTIO_PCI_GUEST_FEATURES);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* virtio config->get() implementation */
|
||||
|
Fai riferimento in un nuovo problema
Block a user