[v3] vhost_vdpa: fix unmap process in no-batch mode

Message ID 20230420151734.860168-1-lulu@redhat.com
State New
Headers
Series [v3] vhost_vdpa: fix unmap process in no-batch mode |

Commit Message

Cindy Lu April 20, 2023, 3:17 p.m. UTC
  While using the vdpa device with vIOMMU enabled
in the guest VM, when the vdpa device bind to vfio-pci and run testpmd
then system will fail to unmap.
The test process is
Load guest VM --> attach to virtio driver--> bind to vfio-pci driver
So the mapping process is
1)batched mode map to normal MR
2)batched mode unmapped the normal MR
3)unmapped all the memory
4)mapped to iommu MR

This error happened in step 3). The iotlb was freed in step 2)
and the function vhost_vdpa_process_iotlb_msg will return fail
Which causes failure.

To fix this, we will not remove the AS while the iotlb->nmaps is 0.
This will free in the vhost_vdpa_clean

Cc: stable@vger.kernel.org
Fixes: aaca8373c4b1 ("vhost-vdpa: support ASID based IOTLB API")
Signed-off-by: Cindy Lu <lulu@redhat.com>
---
 drivers/vhost/vdpa.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
  

Comments

Jason Wang April 24, 2023, 3:47 a.m. UTC | #1
On Thu, Apr 20, 2023 at 11:17 PM Cindy Lu <lulu@redhat.com> wrote:
>
> While using the vdpa device with vIOMMU enabled
> in the guest VM, when the vdpa device bind to vfio-pci and run testpmd
> then system will fail to unmap.
> The test process is
> Load guest VM --> attach to virtio driver--> bind to vfio-pci driver
> So the mapping process is
> 1)batched mode map to normal MR
> 2)batched mode unmapped the normal MR
> 3)unmapped all the memory
> 4)mapped to iommu MR
>
> This error happened in step 3). The iotlb was freed in step 2)
> and the function vhost_vdpa_process_iotlb_msg will return fail
> Which causes failure.
>
> To fix this, we will not remove the AS while the iotlb->nmaps is 0.
> This will free in the vhost_vdpa_clean
>
> Cc: stable@vger.kernel.org
> Fixes: aaca8373c4b1 ("vhost-vdpa: support ASID based IOTLB API")
> Signed-off-by: Cindy Lu <lulu@redhat.com>

Acked-by: Jason Wang <jasowang@redhat.com>

Thanks

> ---
>  drivers/vhost/vdpa.c | 8 +-------
>  1 file changed, 1 insertion(+), 7 deletions(-)
>
> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> index 7be9d9d8f01c..74c7d1f978b7 100644
> --- a/drivers/vhost/vdpa.c
> +++ b/drivers/vhost/vdpa.c
> @@ -851,11 +851,7 @@ static void vhost_vdpa_unmap(struct vhost_vdpa *v,
>                 if (!v->in_batch)
>                         ops->set_map(vdpa, asid, iotlb);
>         }
> -       /* If we are in the middle of batch processing, delay the free
> -        * of AS until BATCH_END.
> -        */
> -       if (!v->in_batch && !iotlb->nmaps)
> -               vhost_vdpa_remove_as(v, asid);
> +
>  }
>
>  static int vhost_vdpa_va_map(struct vhost_vdpa *v,
> @@ -1112,8 +1108,6 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, u32 asid,
>                 if (v->in_batch && ops->set_map)
>                         ops->set_map(vdpa, asid, iotlb);
>                 v->in_batch = false;
> -               if (!iotlb->nmaps)
> -                       vhost_vdpa_remove_as(v, asid);
>                 break;
>         default:
>                 r = -EINVAL;
> --
> 2.34.3
>
  

Patch

diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index 7be9d9d8f01c..74c7d1f978b7 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -851,11 +851,7 @@  static void vhost_vdpa_unmap(struct vhost_vdpa *v,
 		if (!v->in_batch)
 			ops->set_map(vdpa, asid, iotlb);
 	}
-	/* If we are in the middle of batch processing, delay the free
-	 * of AS until BATCH_END.
-	 */
-	if (!v->in_batch && !iotlb->nmaps)
-		vhost_vdpa_remove_as(v, asid);
+
 }
 
 static int vhost_vdpa_va_map(struct vhost_vdpa *v,
@@ -1112,8 +1108,6 @@  static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, u32 asid,
 		if (v->in_batch && ops->set_map)
 			ops->set_map(vdpa, asid, iotlb);
 		v->in_batch = false;
-		if (!iotlb->nmaps)
-			vhost_vdpa_remove_as(v, asid);
 		break;
 	default:
 		r = -EINVAL;