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.
Unified · Split
| @@ -39,6 +39,7 @@ struct vhost_vdpa { · 38 unmodified lines | ||
| 39 | 39 | struct vhost_virtqueue *vqs; |
| 40 | 40 | struct completion completion; |
| 41 | 41 | struct vdpa_device *vdpa; |
| 42 | + struct vhost_iotlb *iotlb; | |
| 42 | 43 | struct device dev; |
| 43 | 44 | struct cdev cdev; |
| 44 | 45 | atomic_t opened; |
| @@ -589,12 +590,11 @@ static void vhost_vdpa_iotlb_unmap(struct vhost_vdpa *v, · 544 unmodified lines | ||
| 589 | 590 | |
| 590 | 591 | static void vhost_vdpa_iotlb_free(struct vhost_vdpa *v) |
| 591 | 592 | { |
| 592 | − struct vhost_dev *dev = &v->vdev; | |
| 593 | − struct vhost_iotlb *iotlb = dev->iotlb; | |
| 593 | + struct vhost_iotlb *iotlb = v->iotlb; | |
| 594 | 594 | |
| 595 | 595 | vhost_vdpa_iotlb_unmap(v, iotlb, 0ULL, 0ULL - 1); |
| 596 | − kfree(dev->iotlb); | |
| 597 | − dev->iotlb = NULL; | |
| 596 | + kfree(v->iotlb); | |
| 597 | + v->iotlb = NULL; | |
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | static int perm_to_iommu_flags(u32 perm) |
| @@ -876,7 +876,7 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, · 275 unmodified lines | ||
| 876 | 876 | struct vhost_vdpa *v = container_of(dev, struct vhost_vdpa, vdev); |
| 877 | 877 | struct vdpa_device *vdpa = v->vdpa; |
| 878 | 878 | const struct vdpa_config_ops *ops = vdpa->config; |
| 879 | − struct vhost_iotlb *iotlb = dev->iotlb; | |
| 879 | + struct vhost_iotlb *iotlb = v->iotlb; | |
| 880 | 880 | int r = 0; |
| 881 | 881 | |
| 882 | 882 | mutex_lock(&dev->mutex); |
| @@ -1017,15 +1017,15 @@ static int vhost_vdpa_open(struct inode *inode, struct file *filep) · 134 unmodified lines | ||
| 1017 | 1017 | vhost_dev_init(dev, vqs, nvqs, 0, 0, 0, false, |
| 1018 | 1018 | vhost_vdpa_process_iotlb_msg); |
| 1019 | 1019 | |
| 1020 | − dev->iotlb = vhost_iotlb_alloc(0, 0); | |
| 1021 | − if (!dev->iotlb) { | |
| 1020 | + v->iotlb = vhost_iotlb_alloc(0, 0); | |
| 1021 | + if (!v->iotlb) { | |
| 1022 | 1022 | r = -ENOMEM; |
| 1023 | 1023 | goto err_init_iotlb; |
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | 1026 | r = vhost_vdpa_alloc_domain(v); |
| 1027 | 1027 | if (r) |
| 1028 | − goto err_init_iotlb; | |
| 1028 | + goto err_alloc_domain; | |
| 1029 | 1029 | |
| 1030 | 1030 | vhost_vdpa_set_iova_range(v); |
| 1031 | 1031 | |
| @@ -1033,6 +1033,8 @@ static int vhost_vdpa_open(struct inode *inode, struct file *filep) · 1 unmodified line | ||
| 1033 | 1033 | |
| 1034 | 1034 | return 0; |
| 1035 | 1035 | |
| 1036 | +err_alloc_domain: | |
| 1037 | + vhost_vdpa_iotlb_free(v); | |
| 1036 | 1038 | err_init_iotlb: |
| 1037 | 1039 | vhost_dev_cleanup(&v->vdev); |
| 1038 | 1040 | kfree(vqs); |