diff mbox series

[RFC,06/24] vhost-vdpa: switch to use vhost-vdpa specific IOTLB

Message ID 20200924032125.18619-7-jasowang@redhat.com
State New
Headers show
Series Control VQ support in vDPA | expand

Commit Message

Jason Wang Sept. 24, 2020, 3:21 a.m. UTC
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>
---
 drivers/vhost/vdpa.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

Comments

Eli Cohen Sept. 30, 2020, 12:02 p.m. UTC | #1
On Thu, Sep 24, 2020 at 11:21:07AM +0800, Jason Wang wrote:
> 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>
> ---
>  drivers/vhost/vdpa.c | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> index 74bef1c15a70..ec3c94f706c1 100644
> --- a/drivers/vhost/vdpa.c
> +++ b/drivers/vhost/vdpa.c
> @@ -40,6 +40,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;
> @@ -514,12 +515,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)
> @@ -681,7 +681,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;
>  
>  	r = vhost_dev_check_owner(dev);
> @@ -812,12 +812,14 @@ static int vhost_vdpa_open(struct inode *inode, struct file *filep)
>  
>  	r = vhost_vdpa_alloc_domain(v);
>  	if (r)
> -		goto err_init_iotlb;
> +		goto err_alloc_domain;

You're still using this:
dev->iotlb = vhost_iotlb_alloc(0, 0);

Shouldn't you use
v->iotlb = host_iotlb_alloc(0, 0);

to set the vdpa device iotlb field?

>  
>  	filep->private_data = v;
>  
>  	return 0;
>  
> +err_alloc_domain:
> +	vhost_vdpa_iotlb_free(v);
>  err_init_iotlb:
>  	vhost_vdpa_cleanup(v);
>  err:
> -- 
> 2.20.1
>
Jason Wang Oct. 9, 2020, 3:46 a.m. UTC | #2
On 2020/9/30 下午8:02, Eli Cohen wrote:
> On Thu, Sep 24, 2020 at 11:21:07AM +0800, Jason Wang wrote:
>> 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>
>> ---
>>   drivers/vhost/vdpa.c | 14 ++++++++------
>>   1 file changed, 8 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
>> index 74bef1c15a70..ec3c94f706c1 100644
>> --- a/drivers/vhost/vdpa.c
>> +++ b/drivers/vhost/vdpa.c
>> @@ -40,6 +40,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;
>> @@ -514,12 +515,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)
>> @@ -681,7 +681,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;
>>   
>>   	r = vhost_dev_check_owner(dev);
>> @@ -812,12 +812,14 @@ static int vhost_vdpa_open(struct inode *inode, struct file *filep)
>>   
>>   	r = vhost_vdpa_alloc_domain(v);
>>   	if (r)
>> -		goto err_init_iotlb;
>> +		goto err_alloc_domain;
> You're still using this:
> dev->iotlb = vhost_iotlb_alloc(0, 0);
>
> Shouldn't you use
> v->iotlb = host_iotlb_alloc(0, 0);
>
> to set the vdpa device iotlb field?


Yes, you're right.

Will fix.

Thanks


>
>>   
>>   	filep->private_data = v;
>>   
>>   	return 0;
>>   
>> +err_alloc_domain:
>> +	vhost_vdpa_iotlb_free(v);
>>   err_init_iotlb:
>>   	vhost_vdpa_cleanup(v);
>>   err:
>> -- 
>> 2.20.1
>>
diff mbox series

Patch

diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index 74bef1c15a70..ec3c94f706c1 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -40,6 +40,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;
@@ -514,12 +515,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)
@@ -681,7 +681,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;
 
 	r = vhost_dev_check_owner(dev);
@@ -812,12 +812,14 @@  static int vhost_vdpa_open(struct inode *inode, struct file *filep)
 
 	r = vhost_vdpa_alloc_domain(v);
 	if (r)
-		goto err_init_iotlb;
+		goto err_alloc_domain;
 
 	filep->private_data = v;
 
 	return 0;
 
+err_alloc_domain:
+	vhost_vdpa_iotlb_free(v);
 err_init_iotlb:
 	vhost_vdpa_cleanup(v);
 err: