diff options
Diffstat (limited to 'drivers/vhost/vdpa.c')
| -rw-r--r-- | drivers/vhost/vdpa.c | 52 | 
1 files changed, 23 insertions, 29 deletions
| diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index ef688c8c0e0e..fb41db3da611 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -16,12 +16,12 @@  #include <linux/cdev.h>  #include <linux/device.h>  #include <linux/mm.h> +#include <linux/slab.h>  #include <linux/iommu.h>  #include <linux/uuid.h>  #include <linux/vdpa.h>  #include <linux/nospec.h>  #include <linux/vhost.h> -#include <linux/virtio_net.h>  #include "vhost.h" @@ -188,13 +188,8 @@ static long vhost_vdpa_set_status(struct vhost_vdpa *v, u8 __user *statusp)  static int vhost_vdpa_config_validate(struct vhost_vdpa *v,  				      struct vhost_vdpa_config *c)  { -	long size = 0; - -	switch (v->virtio_id) { -	case VIRTIO_ID_NET: -		size = sizeof(struct virtio_net_config); -		break; -	} +	struct vdpa_device *vdpa = v->vdpa; +	long size = vdpa->config->get_config_size(vdpa);  	if (c->len == 0)  		return -EINVAL; @@ -308,8 +303,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)  { -	if (v->config_ctx) +	if (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) @@ -329,8 +326,12 @@ static long vhost_vdpa_set_config_call(struct vhost_vdpa *v, u32 __user *argp)  	if (!IS_ERR_OR_NULL(ctx))  		eventfd_ctx_put(ctx); -	if (IS_ERR(v->config_ctx)) -		return PTR_ERR(v->config_ctx); +	if (IS_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); @@ -739,9 +740,11 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev,  	const struct vdpa_config_ops *ops = vdpa->config;  	int r = 0; +	mutex_lock(&dev->mutex); +  	r = vhost_dev_check_owner(dev);  	if (r) -		return r; +		goto unlock;  	switch (msg->type) {  	case VHOST_IOTLB_UPDATE: @@ -762,6 +765,8 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev,  		r = -EINVAL;  		break;  	} +unlock: +	mutex_unlock(&dev->mutex);  	return r;  } @@ -826,18 +831,14 @@ static void vhost_vdpa_free_domain(struct vhost_vdpa *v)  static void vhost_vdpa_set_iova_range(struct vhost_vdpa *v)  {  	struct vdpa_iova_range *range = &v->range; -	struct iommu_domain_geometry geo;  	struct vdpa_device *vdpa = v->vdpa;  	const struct vdpa_config_ops *ops = vdpa->config;  	if (ops->get_iova_range) {  		*range = ops->get_iova_range(vdpa); -	} else if (v->domain && -		   !iommu_domain_get_attr(v->domain, -		   DOMAIN_ATTR_GEOMETRY, &geo) && -		   geo.force_aperture) { -		range->first = geo.aperture_start; -		range->last = geo.aperture_end; +	} else if (v->domain && v->domain->geometry.force_aperture) { +		range->first = v->domain->geometry.aperture_start; +		range->last = v->domain->geometry.aperture_end;  	} else {  		range->first = 0;  		range->last = ULLONG_MAX; @@ -900,14 +901,10 @@ err:  static void vhost_vdpa_clean_irq(struct vhost_vdpa *v)  { -	struct vhost_virtqueue *vq;  	int i; -	for (i = 0; i < v->nvqs; i++) { -		vq = &v->vqs[i]; -		if (vq->call_ctx.producer.irq) -			irq_bypass_unregister_producer(&vq->call_ctx.producer); -	} +	for (i = 0; i < v->nvqs; i++) +		vhost_vdpa_unsetup_vq_irq(v, i);  }  static int vhost_vdpa_release(struct inode *inode, struct file *filep) @@ -987,6 +984,7 @@ static int vhost_vdpa_mmap(struct file *file, struct vm_area_struct *vma)  	if (vma->vm_end - vma->vm_start != notify.size)  		return -ENOTSUPP; +	vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP;  	vma->vm_ops = &vhost_vdpa_vm_ops;  	return 0;  } @@ -1021,10 +1019,6 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa)  	int minor;  	int r; -	/* Currently, we only accept the network devices. */ -	if (ops->get_device_id(vdpa) != VIRTIO_ID_NET) -		return -ENOTSUPP; -  	v = kzalloc(sizeof(*v), GFP_KERNEL | __GFP_RETRY_MAYFAIL);  	if (!v)  		return -ENOMEM; | 
