Skip to content

Commit

Permalink
virtio: allow finalize_features to fail
Browse files Browse the repository at this point in the history
This will make it easy for transports to validate features and return
failure.

Signed-off-by: Michael S. Tsirkin <[email protected]>
  • Loading branch information
mstsirkin committed Dec 9, 2014
1 parent ce15408 commit 5c609a5
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 16 deletions.
4 changes: 3 additions & 1 deletion drivers/lguest/lguest_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static void status_notify(struct virtio_device *vdev)
* sorted out, this routine is called so we can tell the Host which features we
* understand and accept.
*/
static void lg_finalize_features(struct virtio_device *vdev)
static int lg_finalize_features(struct virtio_device *vdev)
{
unsigned int i, bits;
struct lguest_device_desc *desc = to_lgdev(vdev)->desc;
Expand All @@ -153,6 +153,8 @@ static void lg_finalize_features(struct virtio_device *vdev)

/* Tell Host we've finished with this device's feature negotiation */
status_notify(vdev);

return 0;
}

/* Once they've found a field, getting a copy of it is easy. */
Expand Down
4 changes: 3 additions & 1 deletion drivers/misc/mic/card/mic_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static u64 mic_get_features(struct virtio_device *vdev)
return features;
}

static void mic_finalize_features(struct virtio_device *vdev)
static int mic_finalize_features(struct virtio_device *vdev)
{
unsigned int i, bits;
struct mic_device_desc __iomem *desc = to_micvdev(vdev)->desc;
Expand All @@ -107,6 +107,8 @@ static void mic_finalize_features(struct virtio_device *vdev)
iowrite8(ioread8(&out_features[i / 8]) | (1 << (i % 8)),
&out_features[i / 8]);
}

return 0;
}

/*
Expand Down
4 changes: 3 additions & 1 deletion drivers/remoteproc/remoteproc_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ static u64 rproc_virtio_get_features(struct virtio_device *vdev)
return rsc->dfeatures;
}

static void rproc_virtio_finalize_features(struct virtio_device *vdev)
static int rproc_virtio_finalize_features(struct virtio_device *vdev)
{
struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
struct fw_rsc_vdev *rsc;
Expand All @@ -235,6 +235,8 @@ static void rproc_virtio_finalize_features(struct virtio_device *vdev)
* to the remote processor once it is powered on.
*/
rsc->gfeatures = vdev->features;

return 0;
}

static void rproc_virtio_get(struct virtio_device *vdev, unsigned offset,
Expand Down
4 changes: 3 additions & 1 deletion drivers/s390/kvm/kvm_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static u64 kvm_get_features(struct virtio_device *vdev)
return features;
}

static void kvm_finalize_features(struct virtio_device *vdev)
static int kvm_finalize_features(struct virtio_device *vdev)
{
unsigned int i, bits;
struct kvm_device_desc *desc = to_kvmdev(vdev)->desc;
Expand All @@ -112,6 +112,8 @@ static void kvm_finalize_features(struct virtio_device *vdev)
if (__virtio_test_bit(vdev, i))
out_features[i / 8] |= (1 << (i % 8));
}

return 0;
}

/*
Expand Down
6 changes: 4 additions & 2 deletions drivers/s390/kvm/virtio_ccw.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,15 +752,15 @@ static u64 virtio_ccw_get_features(struct virtio_device *vdev)
return rc;
}

static void virtio_ccw_finalize_features(struct virtio_device *vdev)
static int virtio_ccw_finalize_features(struct virtio_device *vdev)
{
struct virtio_ccw_device *vcdev = to_vc_device(vdev);
struct virtio_feature_desc *features;
struct ccw1 *ccw;

ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
if (!ccw)
return;
return 0;

features = kzalloc(sizeof(*features), GFP_DMA | GFP_KERNEL);
if (!features)
Expand Down Expand Up @@ -793,6 +793,8 @@ static void virtio_ccw_finalize_features(struct virtio_device *vdev)
out_free:
kfree(features);
kfree(ccw);

return 0;
}

static void virtio_ccw_get_config(struct virtio_device *vdev,
Expand Down
21 changes: 14 additions & 7 deletions drivers/virtio/virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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. */
Expand All @@ -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 */
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion drivers/virtio/virtio_mmio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion drivers/virtio/virtio_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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 */
Expand Down
3 changes: 2 additions & 1 deletion include/linux/virtio_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
* vdev: the virtio_device
* This gives the final feature bits for the device: it can change
* the dev->feature bits if it wants.
* Returns 0 on success or error status
* @bus_name: return the bus name associated with the device
* vdev: the virtio_device
* This returns a pointer to the bus name a la pci_name from which
Expand All @@ -68,7 +69,7 @@ struct virtio_config_ops {
const char *names[]);
void (*del_vqs)(struct virtio_device *);
u64 (*get_features)(struct virtio_device *vdev);
void (*finalize_features)(struct virtio_device *vdev);
int (*finalize_features)(struct virtio_device *vdev);
const char *(*bus_name)(struct virtio_device *vdev);
int (*set_vq_affinity)(struct virtqueue *vq, int cpu);
};
Expand Down

0 comments on commit 5c609a5

Please sign in to comment.