2020-09-09 16:01:58

by Li Qiang

[permalink] [raw]
Subject: [PATCH] vhost-vdpa: fix memory leak in error path

Free the 'page_list' when the 'npages' is zero.

Signed-off-by: Li Qiang <[email protected]>
---
drivers/vhost/vdpa.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index 3fab94f88894..6a9fcaf1831d 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -609,8 +609,10 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v,
gup_flags |= FOLL_WRITE;

npages = PAGE_ALIGN(msg->size + (iova & ~PAGE_MASK)) >> PAGE_SHIFT;
- if (!npages)
- return -EINVAL;
+ if (!npages) {
+ ret = -EINVAL;
+ goto free_page;
+ }

mmap_read_lock(dev->mm);

@@ -666,6 +668,8 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v,
atomic64_sub(npages, &dev->mm->pinned_vm);
}
mmap_read_unlock(dev->mm);
+
+free_page:
free_page((unsigned long)page_list);
return ret;
}
--
2.25.1


2020-09-10 02:57:06

by Jason Wang

[permalink] [raw]
Subject: Re: [PATCH] vhost-vdpa: fix memory leak in error path


On 2020/9/9 下午11:41, Li Qiang wrote:
> Free the 'page_list' when the 'npages' is zero.
>
> Signed-off-by: Li Qiang <[email protected]>
> ---
> drivers/vhost/vdpa.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> index 3fab94f88894..6a9fcaf1831d 100644
> --- a/drivers/vhost/vdpa.c
> +++ b/drivers/vhost/vdpa.c
> @@ -609,8 +609,10 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v,
> gup_flags |= FOLL_WRITE;
>
> npages = PAGE_ALIGN(msg->size + (iova & ~PAGE_MASK)) >> PAGE_SHIFT;
> - if (!npages)
> - return -EINVAL;
> + if (!npages) {
> + ret = -EINVAL;
> + goto free_page;
> + }
>
> mmap_read_lock(dev->mm);
>
> @@ -666,6 +668,8 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v,
> atomic64_sub(npages, &dev->mm->pinned_vm);
> }
> mmap_read_unlock(dev->mm);
> +
> +free_page:
> free_page((unsigned long)page_list);
> return ret;
> }


Cc: [email protected]

Acked-by: Jason Wang <[email protected]>



2020-09-18 13:02:55

by Li Qiang

[permalink] [raw]
Subject: Re: [PATCH] vhost-vdpa: fix memory leak in error path

Any status update?

Thanks,
Li Qiang

Li Qiang <[email protected]> 于2020年9月9日周三 下午11:42写道:
>
> Free the 'page_list' when the 'npages' is zero.
>
> Signed-off-by: Li Qiang <[email protected]>
> ---
> drivers/vhost/vdpa.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> index 3fab94f88894..6a9fcaf1831d 100644
> --- a/drivers/vhost/vdpa.c
> +++ b/drivers/vhost/vdpa.c
> @@ -609,8 +609,10 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v,
> gup_flags |= FOLL_WRITE;
>
> npages = PAGE_ALIGN(msg->size + (iova & ~PAGE_MASK)) >> PAGE_SHIFT;
> - if (!npages)
> - return -EINVAL;
> + if (!npages) {
> + ret = -EINVAL;
> + goto free_page;
> + }
>
> mmap_read_lock(dev->mm);
>
> @@ -666,6 +668,8 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v,
> atomic64_sub(npages, &dev->mm->pinned_vm);
> }
> mmap_read_unlock(dev->mm);
> +
> +free_page:
> free_page((unsigned long)page_list);
> return ret;
> }
> --
> 2.25.1
>

2020-09-18 13:07:50

by Tianjia Zhang

[permalink] [raw]
Subject: Re: [PATCH] vhost-vdpa: fix memory leak in error path

LGTM.

Reviewed-by: Tianjia Zhang <[email protected]>

Thanks.

On 9/9/20 11:41 PM, Li Qiang wrote:
> Free the 'page_list' when the 'npages' is zero.
>
> Signed-off-by: Li Qiang <[email protected]>
> ---
> drivers/vhost/vdpa.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> index 3fab94f88894..6a9fcaf1831d 100644
> --- a/drivers/vhost/vdpa.c
> +++ b/drivers/vhost/vdpa.c
> @@ -609,8 +609,10 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v,
> gup_flags |= FOLL_WRITE;
>
> npages = PAGE_ALIGN(msg->size + (iova & ~PAGE_MASK)) >> PAGE_SHIFT;
> - if (!npages)
> - return -EINVAL;
> + if (!npages) {
> + ret = -EINVAL;
> + goto free_page;
> + }
>
> mmap_read_lock(dev->mm);
>
> @@ -666,6 +668,8 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v,
> atomic64_sub(npages, &dev->mm->pinned_vm);
> }
> mmap_read_unlock(dev->mm);
> +
> +free_page:
> free_page((unsigned long)page_list);
> return ret;
> }
>