Skip to content

Commit

Permalink
vhost-vdpa: switch to use vhost-vdpa specific IOTLB
Browse files Browse the repository at this point in the history
To ease the implementation of per group ASID support for vDPA
device. This patch switches to use a vhost-vdpa specific IOTLB to
avoid the unnecessary refactoring of the vhost core.

Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Gautam Dawar <gdawar@xilinx.com>
Message-Id: <20220330180436.24644-5-gdawar@xilinx.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
  • Loading branch information
Gautam Dawar authored and mstsirkin committed May 31, 2022
1 parent ae96724 commit 0b7ee47
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions drivers/vhost/vdpa.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct vhost_vdpa {
struct vhost_virtqueue *vqs;
struct completion completion;
struct vdpa_device *vdpa;
struct vhost_iotlb *iotlb;
struct device dev;
struct cdev cdev;
atomic_t opened;
Expand Down Expand Up @@ -589,12 +590,11 @@ static void vhost_vdpa_iotlb_unmap(struct vhost_vdpa *v,

static void vhost_vdpa_iotlb_free(struct vhost_vdpa *v)
{
struct vhost_dev *dev = &v->vdev;
struct vhost_iotlb *iotlb = dev->iotlb;
struct vhost_iotlb *iotlb = v->iotlb;

vhost_vdpa_iotlb_unmap(v, iotlb, 0ULL, 0ULL - 1);
kfree(dev->iotlb);
dev->iotlb = NULL;
kfree(v->iotlb);
v->iotlb = NULL;
}

static int perm_to_iommu_flags(u32 perm)
Expand Down Expand Up @@ -876,7 +876,7 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev,
struct vhost_vdpa *v = container_of(dev, struct vhost_vdpa, vdev);
struct vdpa_device *vdpa = v->vdpa;
const struct vdpa_config_ops *ops = vdpa->config;
struct vhost_iotlb *iotlb = dev->iotlb;
struct vhost_iotlb *iotlb = v->iotlb;
int r = 0;

mutex_lock(&dev->mutex);
Expand Down Expand Up @@ -1017,22 +1017,24 @@ static int vhost_vdpa_open(struct inode *inode, struct file *filep)
vhost_dev_init(dev, vqs, nvqs, 0, 0, 0, false,
vhost_vdpa_process_iotlb_msg);

dev->iotlb = vhost_iotlb_alloc(0, 0);
if (!dev->iotlb) {
v->iotlb = vhost_iotlb_alloc(0, 0);
if (!v->iotlb) {
r = -ENOMEM;
goto err_init_iotlb;
}

r = vhost_vdpa_alloc_domain(v);
if (r)
goto err_init_iotlb;
goto err_alloc_domain;

vhost_vdpa_set_iova_range(v);

filep->private_data = v;

return 0;

err_alloc_domain:
vhost_vdpa_iotlb_free(v);
err_init_iotlb:
vhost_dev_cleanup(&v->vdev);
kfree(vqs);
Expand Down

0 comments on commit 0b7ee47

Please sign in to comment.