mbox series

[v3,0/2] vhost-vdpa mapping error path fixes

Message ID 1601701330-16837-1-git-send-email-si-wei.liu@oracle.com
Headers show
Series vhost-vdpa mapping error path fixes | expand

Message

Si-Wei Liu Oct. 3, 2020, 5:02 a.m. UTC
Commit 4c8cf31885f6 ("vhost: introduce vDPA-based backend")
has following issues in the failure path of IOTLB update:

1) vhost_vdpa_map() does not clean up dangling iotlb entry
   upon mapping failure

2) vhost_vdpa_process_iotlb_update() has leakage of pinned
   pages in case of vhost_vdpa_map() failure

This patchset attempts to address the above issues.

Changes in v3:
- Factor out changes in vhost_vdpa_map() and the fix for
  page pinning leak to separate patches (Jason)

---
Si-Wei Liu (2):
  vhost-vdpa: fix vhost_vdpa_map() on error condition
  vhost-vdpa: fix page pinning leakage in error path

 drivers/vhost/vdpa.c | 122 +++++++++++++++++++++++++++++++--------------------
 1 file changed, 74 insertions(+), 48 deletions(-)

Comments

Jason Wang Oct. 10, 2020, 1:48 a.m. UTC | #1
On 2020/10/3 下午1:02, Si-Wei Liu wrote:
> vhost_vdpa_map() should remove the iotlb entry just added
> if the corresponding mapping fails to set up properly.
>
> Fixes: 4c8cf31885f6 ("vhost: introduce vDPA-based backend")
> Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
> ---
>   drivers/vhost/vdpa.c | 3 +++
>   1 file changed, 3 insertions(+)
>
> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> index 796fe97..0f27919 100644
> --- a/drivers/vhost/vdpa.c
> +++ b/drivers/vhost/vdpa.c
> @@ -565,6 +565,9 @@ static int vhost_vdpa_map(struct vhost_vdpa *v,
>   			      perm_to_iommu_flags(perm));
>   	}
>   
> +	if (r)
> +		vhost_iotlb_del_range(dev->iotlb, iova, iova + size - 1);
> +
>   	return r;
>   }
>   


Acked-by: Jason Wang <jasowang@redhat.com>
Michael S. Tsirkin Oct. 11, 2020, 6:45 a.m. UTC | #2
On Sat, Oct 10, 2020 at 09:48:42AM +0800, Jason Wang wrote:
> 
> On 2020/10/3 下午1:02, Si-Wei Liu wrote:
> > vhost_vdpa_map() should remove the iotlb entry just added
> > if the corresponding mapping fails to set up properly.
> > 
> > Fixes: 4c8cf31885f6 ("vhost: introduce vDPA-based backend")
> > Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
> > ---
> >   drivers/vhost/vdpa.c | 3 +++
> >   1 file changed, 3 insertions(+)
> > 
> > diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> > index 796fe97..0f27919 100644
> > --- a/drivers/vhost/vdpa.c
> > +++ b/drivers/vhost/vdpa.c
> > @@ -565,6 +565,9 @@ static int vhost_vdpa_map(struct vhost_vdpa *v,
> >   			      perm_to_iommu_flags(perm));
> >   	}
> > +	if (r)
> > +		vhost_iotlb_del_range(dev->iotlb, iova, iova + size - 1);
> > +
> >   	return r;
> >   }
> 
> 
> Acked-by: Jason Wang <jasowang@redhat.com>

Linus already merged this, I can't add your ack, sorry!