Commit bf152b0b authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost

Pull virtio fixes from Michael Tsirkin:
 "Some fixes and cleanups all over the place"

* tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost:
  vhost-vdpa: set v->config_ctx to NULL if eventfd_ctx_fdget() fails
  vhost-vdpa: fix use-after-free of v->config_ctx
  vhost: Fix vhost_vq_reset()
  vhost_vdpa: fix the missing irq_bypass_unregister_producer() invocation
  vdpa_sim: Skip typecasting from void*
  virtio: remove export for virtio_config_{enable, disable}
  virtio-mmio: Use to_virtio_mmio_device() to simply code
  vdpa: set the virtqueue num during register
parents 8ff0f3bf 0bde59c1
...@@ -431,8 +431,7 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) ...@@ -431,8 +431,7 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
} }
adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa, adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa,
dev, &ifc_vdpa_ops, dev, &ifc_vdpa_ops, NULL);
IFCVF_MAX_QUEUE_PAIRS * 2, NULL);
if (adapter == NULL) { if (adapter == NULL) {
IFCVF_ERR(pdev, "Failed to allocate vDPA structure"); IFCVF_ERR(pdev, "Failed to allocate vDPA structure");
return -ENOMEM; return -ENOMEM;
...@@ -456,7 +455,7 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) ...@@ -456,7 +455,7 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
for (i = 0; i < IFCVF_MAX_QUEUE_PAIRS * 2; i++) for (i = 0; i < IFCVF_MAX_QUEUE_PAIRS * 2; i++)
vf->vring[i].irq = -EINVAL; vf->vring[i].irq = -EINVAL;
ret = vdpa_register_device(&adapter->vdpa); ret = vdpa_register_device(&adapter->vdpa, IFCVF_MAX_QUEUE_PAIRS * 2);
if (ret) { if (ret) {
IFCVF_ERR(pdev, "Failed to register ifcvf to vdpa bus"); IFCVF_ERR(pdev, "Failed to register ifcvf to vdpa bus");
goto err; goto err;
......
...@@ -1982,7 +1982,7 @@ static int mlx5v_probe(struct auxiliary_device *adev, ...@@ -1982,7 +1982,7 @@ static int mlx5v_probe(struct auxiliary_device *adev,
max_vqs = min_t(u32, max_vqs, MLX5_MAX_SUPPORTED_VQS); max_vqs = min_t(u32, max_vqs, MLX5_MAX_SUPPORTED_VQS);
ndev = vdpa_alloc_device(struct mlx5_vdpa_net, mvdev.vdev, mdev->device, &mlx5_vdpa_ops, ndev = vdpa_alloc_device(struct mlx5_vdpa_net, mvdev.vdev, mdev->device, &mlx5_vdpa_ops,
2 * mlx5_vdpa_max_qps(max_vqs), NULL); NULL);
if (IS_ERR(ndev)) if (IS_ERR(ndev))
return PTR_ERR(ndev); return PTR_ERR(ndev);
...@@ -2009,7 +2009,7 @@ static int mlx5v_probe(struct auxiliary_device *adev, ...@@ -2009,7 +2009,7 @@ static int mlx5v_probe(struct auxiliary_device *adev,
if (err) if (err)
goto err_res; goto err_res;
err = vdpa_register_device(&mvdev->vdev); err = vdpa_register_device(&mvdev->vdev, 2 * mlx5_vdpa_max_qps(max_vqs));
if (err) if (err)
goto err_reg; goto err_reg;
......
...@@ -69,7 +69,6 @@ static void vdpa_release_dev(struct device *d) ...@@ -69,7 +69,6 @@ static void vdpa_release_dev(struct device *d)
* initialized but before registered. * initialized but before registered.
* @parent: the parent device * @parent: the parent device
* @config: the bus operations that is supported by this device * @config: the bus operations that is supported by this device
* @nvqs: number of virtqueues supported by this device
* @size: size of the parent structure that contains private data * @size: size of the parent structure that contains private data
* @name: name of the vdpa device; optional. * @name: name of the vdpa device; optional.
* *
...@@ -81,7 +80,7 @@ static void vdpa_release_dev(struct device *d) ...@@ -81,7 +80,7 @@ static void vdpa_release_dev(struct device *d)
*/ */
struct vdpa_device *__vdpa_alloc_device(struct device *parent, struct vdpa_device *__vdpa_alloc_device(struct device *parent,
const struct vdpa_config_ops *config, const struct vdpa_config_ops *config,
int nvqs, size_t size, const char *name) size_t size, const char *name)
{ {
struct vdpa_device *vdev; struct vdpa_device *vdev;
int err = -EINVAL; int err = -EINVAL;
...@@ -107,7 +106,6 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent, ...@@ -107,7 +106,6 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent,
vdev->index = err; vdev->index = err;
vdev->config = config; vdev->config = config;
vdev->features_valid = false; vdev->features_valid = false;
vdev->nvqs = nvqs;
if (name) if (name)
err = dev_set_name(&vdev->dev, "%s", name); err = dev_set_name(&vdev->dev, "%s", name);
...@@ -136,10 +134,12 @@ static int vdpa_name_match(struct device *dev, const void *data) ...@@ -136,10 +134,12 @@ static int vdpa_name_match(struct device *dev, const void *data)
return (strcmp(dev_name(&vdev->dev), data) == 0); return (strcmp(dev_name(&vdev->dev), data) == 0);
} }
static int __vdpa_register_device(struct vdpa_device *vdev) static int __vdpa_register_device(struct vdpa_device *vdev, int nvqs)
{ {
struct device *dev; struct device *dev;
vdev->nvqs = nvqs;
lockdep_assert_held(&vdpa_dev_mutex); lockdep_assert_held(&vdpa_dev_mutex);
dev = bus_find_device(&vdpa_bus, NULL, dev_name(&vdev->dev), vdpa_name_match); dev = bus_find_device(&vdpa_bus, NULL, dev_name(&vdev->dev), vdpa_name_match);
if (dev) { if (dev) {
...@@ -155,15 +155,16 @@ static int __vdpa_register_device(struct vdpa_device *vdev) ...@@ -155,15 +155,16 @@ static int __vdpa_register_device(struct vdpa_device *vdev)
* Caller must invoke this routine in the management device dev_add() * Caller must invoke this routine in the management device dev_add()
* callback after setting up valid mgmtdev for this vdpa device. * callback after setting up valid mgmtdev for this vdpa device.
* @vdev: the vdpa device to be registered to vDPA bus * @vdev: the vdpa device to be registered to vDPA bus
* @nvqs: number of virtqueues supported by this device
* *
* Returns an error when fail to add device to vDPA bus * Returns an error when fail to add device to vDPA bus
*/ */
int _vdpa_register_device(struct vdpa_device *vdev) int _vdpa_register_device(struct vdpa_device *vdev, int nvqs)
{ {
if (!vdev->mdev) if (!vdev->mdev)
return -EINVAL; return -EINVAL;
return __vdpa_register_device(vdev); return __vdpa_register_device(vdev, nvqs);
} }
EXPORT_SYMBOL_GPL(_vdpa_register_device); EXPORT_SYMBOL_GPL(_vdpa_register_device);
...@@ -171,15 +172,16 @@ EXPORT_SYMBOL_GPL(_vdpa_register_device); ...@@ -171,15 +172,16 @@ EXPORT_SYMBOL_GPL(_vdpa_register_device);
* vdpa_register_device - register a vDPA device * vdpa_register_device - register a vDPA device
* Callers must have a succeed call of vdpa_alloc_device() before. * Callers must have a succeed call of vdpa_alloc_device() before.
* @vdev: the vdpa device to be registered to vDPA bus * @vdev: the vdpa device to be registered to vDPA bus
* @nvqs: number of virtqueues supported by this device
* *
* Returns an error when fail to add to vDPA bus * Returns an error when fail to add to vDPA bus
*/ */
int vdpa_register_device(struct vdpa_device *vdev) int vdpa_register_device(struct vdpa_device *vdev, int nvqs)
{ {
int err; int err;
mutex_lock(&vdpa_dev_mutex); mutex_lock(&vdpa_dev_mutex);
err = __vdpa_register_device(vdev); err = __vdpa_register_device(vdev, nvqs);
mutex_unlock(&vdpa_dev_mutex); mutex_unlock(&vdpa_dev_mutex);
return err; return err;
} }
......
...@@ -235,7 +235,7 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr) ...@@ -235,7 +235,7 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr)
ops = &vdpasim_config_ops; ops = &vdpasim_config_ops;
vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops, vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops,
dev_attr->nvqs, dev_attr->name); dev_attr->name);
if (!vdpasim) if (!vdpasim)
goto err_alloc; goto err_alloc;
......
...@@ -110,8 +110,7 @@ static void vdpasim_net_work(struct work_struct *work) ...@@ -110,8 +110,7 @@ static void vdpasim_net_work(struct work_struct *work)
static void vdpasim_net_get_config(struct vdpasim *vdpasim, void *config) static void vdpasim_net_get_config(struct vdpasim *vdpasim, void *config)
{ {
struct virtio_net_config *net_config = struct virtio_net_config *net_config = config;
(struct virtio_net_config *)config;
net_config->mtu = cpu_to_vdpasim16(vdpasim, 1500); net_config->mtu = cpu_to_vdpasim16(vdpasim, 1500);
net_config->status = cpu_to_vdpasim16(vdpasim, VIRTIO_NET_S_LINK_UP); net_config->status = cpu_to_vdpasim16(vdpasim, VIRTIO_NET_S_LINK_UP);
...@@ -147,7 +146,7 @@ static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name) ...@@ -147,7 +146,7 @@ static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name)
if (IS_ERR(simdev)) if (IS_ERR(simdev))
return PTR_ERR(simdev); return PTR_ERR(simdev);
ret = _vdpa_register_device(&simdev->vdpa); ret = _vdpa_register_device(&simdev->vdpa, VDPASIM_NET_VQ_NUM);
if (ret) if (ret)
goto reg_err; goto reg_err;
......
...@@ -308,8 +308,10 @@ static long vhost_vdpa_get_vring_num(struct vhost_vdpa *v, u16 __user *argp) ...@@ -308,8 +308,10 @@ static long vhost_vdpa_get_vring_num(struct vhost_vdpa *v, u16 __user *argp)
static void vhost_vdpa_config_put(struct vhost_vdpa *v) static void vhost_vdpa_config_put(struct vhost_vdpa *v)
{ {
if (v->config_ctx) if (v->config_ctx) {
eventfd_ctx_put(v->config_ctx); eventfd_ctx_put(v->config_ctx);
v->config_ctx = NULL;
}
} }
static long vhost_vdpa_set_config_call(struct vhost_vdpa *v, u32 __user *argp) static long vhost_vdpa_set_config_call(struct vhost_vdpa *v, u32 __user *argp)
...@@ -329,8 +331,12 @@ static long vhost_vdpa_set_config_call(struct vhost_vdpa *v, u32 __user *argp) ...@@ -329,8 +331,12 @@ static long vhost_vdpa_set_config_call(struct vhost_vdpa *v, u32 __user *argp)
if (!IS_ERR_OR_NULL(ctx)) if (!IS_ERR_OR_NULL(ctx))
eventfd_ctx_put(ctx); eventfd_ctx_put(ctx);
if (IS_ERR(v->config_ctx)) if (IS_ERR(v->config_ctx)) {
return PTR_ERR(v->config_ctx); long ret = PTR_ERR(v->config_ctx);
v->config_ctx = NULL;
return ret;
}
v->vdpa->config->set_config_cb(v->vdpa, &cb); v->vdpa->config->set_config_cb(v->vdpa, &cb);
...@@ -900,14 +906,10 @@ static int vhost_vdpa_open(struct inode *inode, struct file *filep) ...@@ -900,14 +906,10 @@ static int vhost_vdpa_open(struct inode *inode, struct file *filep)
static void vhost_vdpa_clean_irq(struct vhost_vdpa *v) static void vhost_vdpa_clean_irq(struct vhost_vdpa *v)
{ {
struct vhost_virtqueue *vq;
int i; int i;
for (i = 0; i < v->nvqs; i++) { for (i = 0; i < v->nvqs; i++)
vq = &v->vqs[i]; vhost_vdpa_unsetup_vq_irq(v, i);
if (vq->call_ctx.producer.irq)
irq_bypass_unregister_producer(&vq->call_ctx.producer);
}
} }
static int vhost_vdpa_release(struct inode *inode, struct file *filep) static int vhost_vdpa_release(struct inode *inode, struct file *filep)
......
...@@ -332,8 +332,8 @@ static void vhost_vq_reset(struct vhost_dev *dev, ...@@ -332,8 +332,8 @@ static void vhost_vq_reset(struct vhost_dev *dev,
vq->error_ctx = NULL; vq->error_ctx = NULL;
vq->kick = NULL; vq->kick = NULL;
vq->log_ctx = NULL; vq->log_ctx = NULL;
vhost_reset_is_le(vq);
vhost_disable_cross_endian(vq); vhost_disable_cross_endian(vq);
vhost_reset_is_le(vq);
vq->busyloop_timeout = 0; vq->busyloop_timeout = 0;
vq->umem = NULL; vq->umem = NULL;
vq->iotlb = NULL; vq->iotlb = NULL;
......
...@@ -141,15 +141,14 @@ void virtio_config_changed(struct virtio_device *dev) ...@@ -141,15 +141,14 @@ void virtio_config_changed(struct virtio_device *dev)
} }
EXPORT_SYMBOL_GPL(virtio_config_changed); EXPORT_SYMBOL_GPL(virtio_config_changed);
void virtio_config_disable(struct virtio_device *dev) static void virtio_config_disable(struct virtio_device *dev)
{ {
spin_lock_irq(&dev->config_lock); spin_lock_irq(&dev->config_lock);
dev->config_enabled = false; dev->config_enabled = false;
spin_unlock_irq(&dev->config_lock); spin_unlock_irq(&dev->config_lock);
} }
EXPORT_SYMBOL_GPL(virtio_config_disable);
void virtio_config_enable(struct virtio_device *dev) static void virtio_config_enable(struct virtio_device *dev)
{ {
spin_lock_irq(&dev->config_lock); spin_lock_irq(&dev->config_lock);
dev->config_enabled = true; dev->config_enabled = true;
...@@ -158,7 +157,6 @@ void virtio_config_enable(struct virtio_device *dev) ...@@ -158,7 +157,6 @@ void virtio_config_enable(struct virtio_device *dev)
dev->config_change_pending = false; dev->config_change_pending = false;
spin_unlock_irq(&dev->config_lock); spin_unlock_irq(&dev->config_lock);
} }
EXPORT_SYMBOL_GPL(virtio_config_enable);
void virtio_add_status(struct virtio_device *dev, unsigned int status) void virtio_add_status(struct virtio_device *dev, unsigned int status)
{ {
......
...@@ -548,8 +548,7 @@ static void virtio_mmio_release_dev(struct device *_d) ...@@ -548,8 +548,7 @@ static void virtio_mmio_release_dev(struct device *_d)
{ {
struct virtio_device *vdev = struct virtio_device *vdev =
container_of(_d, struct virtio_device, dev); container_of(_d, struct virtio_device, dev);
struct virtio_mmio_device *vm_dev = struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
container_of(vdev, struct virtio_mmio_device, vdev);
struct platform_device *pdev = vm_dev->pdev; struct platform_device *pdev = vm_dev->pdev;
devm_kfree(&pdev->dev, vm_dev); devm_kfree(&pdev->dev, vm_dev);
......
...@@ -250,20 +250,20 @@ struct vdpa_config_ops { ...@@ -250,20 +250,20 @@ struct vdpa_config_ops {
struct vdpa_device *__vdpa_alloc_device(struct device *parent, struct vdpa_device *__vdpa_alloc_device(struct device *parent,
const struct vdpa_config_ops *config, const struct vdpa_config_ops *config,
int nvqs, size_t size, const char *name); size_t size, const char *name);
#define vdpa_alloc_device(dev_struct, member, parent, config, nvqs, name) \ #define vdpa_alloc_device(dev_struct, member, parent, config, name) \
container_of(__vdpa_alloc_device( \ container_of(__vdpa_alloc_device( \
parent, config, nvqs, \ parent, config, \
sizeof(dev_struct) + \ sizeof(dev_struct) + \
BUILD_BUG_ON_ZERO(offsetof( \ BUILD_BUG_ON_ZERO(offsetof( \
dev_struct, member)), name), \ dev_struct, member)), name), \
dev_struct, member) dev_struct, member)
int vdpa_register_device(struct vdpa_device *vdev); int vdpa_register_device(struct vdpa_device *vdev, int nvqs);
void vdpa_unregister_device(struct vdpa_device *vdev); void vdpa_unregister_device(struct vdpa_device *vdev);
int _vdpa_register_device(struct vdpa_device *vdev); int _vdpa_register_device(struct vdpa_device *vdev, int nvqs);
void _vdpa_unregister_device(struct vdpa_device *vdev); void _vdpa_unregister_device(struct vdpa_device *vdev);
/** /**
......
...@@ -132,8 +132,6 @@ bool is_virtio_device(struct device *dev); ...@@ -132,8 +132,6 @@ bool is_virtio_device(struct device *dev);
void virtio_break_device(struct virtio_device *dev); void virtio_break_device(struct virtio_device *dev);
void virtio_config_changed(struct virtio_device *dev); void virtio_config_changed(struct virtio_device *dev);
void virtio_config_disable(struct virtio_device *dev);
void virtio_config_enable(struct virtio_device *dev);
int virtio_finalize_features(struct virtio_device *dev); int virtio_finalize_features(struct virtio_device *dev);
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
int virtio_device_freeze(struct virtio_device *dev); int virtio_device_freeze(struct virtio_device *dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment