* [PATCH] mm/gup: Fix memory leak in __gup_benchmark_ioctl
@ 2019-12-11 17:46 Navid Emamdoost
2019-12-12 23:14 ` Ira Weiny
2019-12-13 21:40 ` John Hubbard
0 siblings, 2 replies; 10+ messages in thread
From: Navid Emamdoost @ 2019-12-11 17:46 UTC (permalink / raw)
To: Andrew Morton, Kirill A. Shutemov, Keith Busch, linux-mm, linux-kernel
Cc: emamd001, Navid Emamdoost
In the implementation of __gup_benchmark_ioctl() the allocated pages
should be released before returning in case of an invalid cmd. Release
pages via kvfree().
Fixes: 714a3a1ebafe ("mm/gup_benchmark.c: add additional pinning methods")
Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
mm/gup_benchmark.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/mm/gup_benchmark.c b/mm/gup_benchmark.c
index 7dd602d7f8db..b160638f647e 100644
--- a/mm/gup_benchmark.c
+++ b/mm/gup_benchmark.c
@@ -63,6 +63,7 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
NULL);
break;
default:
+ kvfree(pages);
return -1;
}
--
2.17.1
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH] mm/gup: Fix memory leak in __gup_benchmark_ioctl 2019-12-11 17:46 [PATCH] mm/gup: Fix memory leak in __gup_benchmark_ioctl Navid Emamdoost @ 2019-12-12 23:14 ` Ira Weiny 2019-12-13 21:40 ` John Hubbard 1 sibling, 0 replies; 10+ messages in thread From: Ira Weiny @ 2019-12-12 23:14 UTC (permalink / raw) To: Navid Emamdoost Cc: Andrew Morton, Kirill A. Shutemov, Keith Busch, linux-mm, linux-kernel, emamd001 On Wed, Dec 11, 2019 at 11:46:51AM -0600, Navid Emamdoost wrote: > In the implementation of __gup_benchmark_ioctl() the allocated pages > should be released before returning in case of an invalid cmd. Release > pages via kvfree(). > > Fixes: 714a3a1ebafe ("mm/gup_benchmark.c: add additional pinning methods") > Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com> > --- > mm/gup_benchmark.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/mm/gup_benchmark.c b/mm/gup_benchmark.c > index 7dd602d7f8db..b160638f647e 100644 > --- a/mm/gup_benchmark.c > +++ b/mm/gup_benchmark.c > @@ -63,6 +63,7 @@ static int __gup_benchmark_ioctl(unsigned int cmd, > NULL); > break; > default: > + kvfree(pages); I wonder if adding a ret value and a goto where the free is done would be better. But may be overkill at this time. So... Reviewed-by: Ira Weiny <ira.weiny@intel.com> > return -1; > } > > -- > 2.17.1 > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] mm/gup: Fix memory leak in __gup_benchmark_ioctl 2019-12-11 17:46 [PATCH] mm/gup: Fix memory leak in __gup_benchmark_ioctl Navid Emamdoost 2019-12-12 23:14 ` Ira Weiny @ 2019-12-13 21:40 ` John Hubbard 2019-12-13 22:23 ` Andrew Morton 2019-12-13 22:37 ` [PATCH v2] " Navid Emamdoost 1 sibling, 2 replies; 10+ messages in thread From: John Hubbard @ 2019-12-13 21:40 UTC (permalink / raw) To: Navid Emamdoost, Andrew Morton, Kirill A. Shutemov, Keith Busch, linux-mm, linux-kernel Cc: emamd001 On 12/11/19 9:46 AM, Navid Emamdoost wrote: > In the implementation of __gup_benchmark_ioctl() the allocated pages > should be released before returning in case of an invalid cmd. Release > pages via kvfree(). > > Fixes: 714a3a1ebafe ("mm/gup_benchmark.c: add additional pinning methods") > Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com> > --- > mm/gup_benchmark.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/mm/gup_benchmark.c b/mm/gup_benchmark.c > index 7dd602d7f8db..b160638f647e 100644 > --- a/mm/gup_benchmark.c > +++ b/mm/gup_benchmark.c > @@ -63,6 +63,7 @@ static int __gup_benchmark_ioctl(unsigned int cmd, > NULL); > break; > default: > + kvfree(pages); > return -1; > } > Hi, The patch is correct, but I would like to second Ira's request for a ret value, and a "goto done" to use a single place to kvfree, if you don't mind. Either way, you can add: Reviewed-by: John Hubbard <jhubbard@nvidia.com> thanks, -- John Hubbard NVIDIA ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] mm/gup: Fix memory leak in __gup_benchmark_ioctl 2019-12-13 21:40 ` John Hubbard @ 2019-12-13 22:23 ` Andrew Morton 2019-12-13 22:39 ` Navid Emamdoost 2019-12-13 22:37 ` [PATCH v2] " Navid Emamdoost 1 sibling, 1 reply; 10+ messages in thread From: Andrew Morton @ 2019-12-13 22:23 UTC (permalink / raw) To: John Hubbard Cc: Navid Emamdoost, Kirill A. Shutemov, Keith Busch, linux-mm, linux-kernel, emamd001 On Fri, 13 Dec 2019 13:40:15 -0800 John Hubbard <jhubbard@nvidia.com> wrote: > On 12/11/19 9:46 AM, Navid Emamdoost wrote: > > In the implementation of __gup_benchmark_ioctl() the allocated pages > > should be released before returning in case of an invalid cmd. Release > > pages via kvfree(). > > > > Fixes: 714a3a1ebafe ("mm/gup_benchmark.c: add additional pinning methods") > > Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com> > > --- > > mm/gup_benchmark.c | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/mm/gup_benchmark.c b/mm/gup_benchmark.c > > index 7dd602d7f8db..b160638f647e 100644 > > --- a/mm/gup_benchmark.c > > +++ b/mm/gup_benchmark.c > > @@ -63,6 +63,7 @@ static int __gup_benchmark_ioctl(unsigned int cmd, > > NULL); > > break; > > default: > > + kvfree(pages); > > return -1; > > } > > > > Hi, > > The patch is correct, but I would like to second Ira's request for a ret value, > and a "goto done" to use a single place to kvfree, if you don't mind. > Fair enough. And let's make it return -EINVAL rather than -1, which appears to be -EPERM. --- a/mm/gup_benchmark.c~mm-gup-fix-memory-leak-in-__gup_benchmark_ioctl-fix +++ a/mm/gup_benchmark.c @@ -26,6 +26,7 @@ static int __gup_benchmark_ioctl(unsigne unsigned long i, nr_pages, addr, next; int nr; struct page **pages; + int ret = 0; if (gup->size > ULONG_MAX) return -EINVAL; @@ -64,7 +65,8 @@ static int __gup_benchmark_ioctl(unsigne break; default: kvfree(pages); - return -1; + ret = -EINVAL; + goto out; } if (nr <= 0) @@ -86,7 +88,8 @@ static int __gup_benchmark_ioctl(unsigne gup->put_delta_usec = ktime_us_delta(end_time, start_time); kvfree(pages); - return 0; +out: + return ret; } static long gup_benchmark_ioctl(struct file *filep, unsigned int cmd, _ ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] mm/gup: Fix memory leak in __gup_benchmark_ioctl 2019-12-13 22:23 ` Andrew Morton @ 2019-12-13 22:39 ` Navid Emamdoost 0 siblings, 0 replies; 10+ messages in thread From: Navid Emamdoost @ 2019-12-13 22:39 UTC (permalink / raw) To: Andrew Morton Cc: John Hubbard, Kirill A. Shutemov, Keith Busch, linux-mm, LKML, Navid Emamdoost On Fri, Dec 13, 2019 at 4:23 PM Andrew Morton <akpm@linux-foundation.org> wrote: > > On Fri, 13 Dec 2019 13:40:15 -0800 John Hubbard <jhubbard@nvidia.com> wrote: > > > On 12/11/19 9:46 AM, Navid Emamdoost wrote: > > > In the implementation of __gup_benchmark_ioctl() the allocated pages > > > should be released before returning in case of an invalid cmd. Release > > > pages via kvfree(). > > > > > > Fixes: 714a3a1ebafe ("mm/gup_benchmark.c: add additional pinning methods") > > > Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com> > > > --- > > > mm/gup_benchmark.c | 1 + > > > 1 file changed, 1 insertion(+) > > > > > > diff --git a/mm/gup_benchmark.c b/mm/gup_benchmark.c > > > index 7dd602d7f8db..b160638f647e 100644 > > > --- a/mm/gup_benchmark.c > > > +++ b/mm/gup_benchmark.c > > > @@ -63,6 +63,7 @@ static int __gup_benchmark_ioctl(unsigned int cmd, > > > NULL); > > > break; > > > default: > > > + kvfree(pages); > > > return -1; > > > } > > > > > > > Hi, > > > > The patch is correct, but I would like to second Ira's request for a ret value, > > and a "goto done" to use a single place to kvfree, if you don't mind. > > > > Fair enough. > > And let's make it return -EINVAL rather than -1, which appears to be > -EPERM. Sure! patch v2 has been sent. > > --- a/mm/gup_benchmark.c~mm-gup-fix-memory-leak-in-__gup_benchmark_ioctl-fix > +++ a/mm/gup_benchmark.c > @@ -26,6 +26,7 @@ static int __gup_benchmark_ioctl(unsigne > unsigned long i, nr_pages, addr, next; > int nr; > struct page **pages; > + int ret = 0; > > if (gup->size > ULONG_MAX) > return -EINVAL; > @@ -64,7 +65,8 @@ static int __gup_benchmark_ioctl(unsigne > break; > default: > kvfree(pages); > - return -1; > + ret = -EINVAL; > + goto out; > } > > if (nr <= 0) > @@ -86,7 +88,8 @@ static int __gup_benchmark_ioctl(unsigne > gup->put_delta_usec = ktime_us_delta(end_time, start_time); > > kvfree(pages); > - return 0; > +out: > + return ret; > } > > static long gup_benchmark_ioctl(struct file *filep, unsigned int cmd, > _ > -- Navid. ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2] mm/gup: Fix memory leak in __gup_benchmark_ioctl 2019-12-13 21:40 ` John Hubbard 2019-12-13 22:23 ` Andrew Morton @ 2019-12-13 22:37 ` Navid Emamdoost 2019-12-13 23:12 ` Ira Weiny ` (3 more replies) 1 sibling, 4 replies; 10+ messages in thread From: Navid Emamdoost @ 2019-12-13 22:37 UTC (permalink / raw) To: Andrew Morton, Kirill A. Shutemov, Keith Busch, linux-mm, linux-kernel Cc: emamd001, jhubbard, Navid Emamdoost In the implementation of __gup_benchmark_ioctl() the allocated pages should be released before returning in case of an invalid cmd. Release pages via kvfree() by goto done. Fixes: 714a3a1ebafe ("mm/gup_benchmark.c: add additional pinning methods") Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com> --- Changes in v2: -- added goto and ret value instead of return -1. --- mm/gup_benchmark.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mm/gup_benchmark.c b/mm/gup_benchmark.c index b160638f647e..b773b2568544 100644 --- a/mm/gup_benchmark.c +++ b/mm/gup_benchmark.c @@ -24,7 +24,7 @@ static int __gup_benchmark_ioctl(unsigned int cmd, { ktime_t start_time, end_time; unsigned long i, nr_pages, addr, next; - int nr; + int nr, ret = 0; struct page **pages; if (gup->size > ULONG_MAX) @@ -63,8 +63,8 @@ static int __gup_benchmark_ioctl(unsigned int cmd, NULL); break; default: - kvfree(pages); - return -1; + ret = -EINVAL; + goto done; } if (nr <= 0) @@ -85,8 +85,9 @@ static int __gup_benchmark_ioctl(unsigned int cmd, end_time = ktime_get(); gup->put_delta_usec = ktime_us_delta(end_time, start_time); +done: kvfree(pages); - return 0; + return ret; } static long gup_benchmark_ioctl(struct file *filep, unsigned int cmd, -- 2.17.1 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] mm/gup: Fix memory leak in __gup_benchmark_ioctl 2019-12-13 22:37 ` [PATCH v2] " Navid Emamdoost @ 2019-12-13 23:12 ` Ira Weiny 2019-12-14 0:44 ` John Hubbard ` (2 subsequent siblings) 3 siblings, 0 replies; 10+ messages in thread From: Ira Weiny @ 2019-12-13 23:12 UTC (permalink / raw) To: Navid Emamdoost Cc: Andrew Morton, Kirill A. Shutemov, Keith Busch, linux-mm, linux-kernel, emamd001, jhubbard On Fri, Dec 13, 2019 at 04:37:41PM -0600, Navid Emamdoost wrote: > In the implementation of __gup_benchmark_ioctl() the allocated pages > should be released before returning in case of an invalid cmd. Release > pages via kvfree() by goto done. > > Fixes: 714a3a1ebafe ("mm/gup_benchmark.c: add additional pinning methods") > Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com> Reviewed-by: Ira Weiny <ira.weiny@intel.com> > --- > Changes in v2: > -- added goto and ret value instead of return -1. > --- > mm/gup_benchmark.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/mm/gup_benchmark.c b/mm/gup_benchmark.c > index b160638f647e..b773b2568544 100644 > --- a/mm/gup_benchmark.c > +++ b/mm/gup_benchmark.c > @@ -24,7 +24,7 @@ static int __gup_benchmark_ioctl(unsigned int cmd, > { > ktime_t start_time, end_time; > unsigned long i, nr_pages, addr, next; > - int nr; > + int nr, ret = 0; > struct page **pages; > > if (gup->size > ULONG_MAX) > @@ -63,8 +63,8 @@ static int __gup_benchmark_ioctl(unsigned int cmd, > NULL); > break; > default: > - kvfree(pages); > - return -1; > + ret = -EINVAL; > + goto done; > } > > if (nr <= 0) > @@ -85,8 +85,9 @@ static int __gup_benchmark_ioctl(unsigned int cmd, > end_time = ktime_get(); > gup->put_delta_usec = ktime_us_delta(end_time, start_time); > > +done: > kvfree(pages); > - return 0; > + return ret; > } > > static long gup_benchmark_ioctl(struct file *filep, unsigned int cmd, > -- > 2.17.1 > > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] mm/gup: Fix memory leak in __gup_benchmark_ioctl 2019-12-13 22:37 ` [PATCH v2] " Navid Emamdoost 2019-12-13 23:12 ` Ira Weiny @ 2019-12-14 0:44 ` John Hubbard 2019-12-14 18:10 ` Markus Elfring 2019-12-16 12:18 ` David Hildenbrand 3 siblings, 0 replies; 10+ messages in thread From: John Hubbard @ 2019-12-14 0:44 UTC (permalink / raw) To: Navid Emamdoost, Andrew Morton, Kirill A. Shutemov, Keith Busch, linux-mm, linux-kernel Cc: emamd001 On 12/13/19 2:37 PM, Navid Emamdoost wrote: > In the implementation of __gup_benchmark_ioctl() the allocated pages > should be released before returning in case of an invalid cmd. Release > pages via kvfree() by goto done. > > Fixes: 714a3a1ebafe ("mm/gup_benchmark.c: add additional pinning methods") > Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com> > --- > Changes in v2: > -- added goto and ret value instead of return -1. > --- > mm/gup_benchmark.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > Reviewed-by: John Hubbard <jhubbard@nvidia.com> thanks, -- John Hubbard NVIDIA > diff --git a/mm/gup_benchmark.c b/mm/gup_benchmark.c > index b160638f647e..b773b2568544 100644 > --- a/mm/gup_benchmark.c > +++ b/mm/gup_benchmark.c > @@ -24,7 +24,7 @@ static int __gup_benchmark_ioctl(unsigned int cmd, > { > ktime_t start_time, end_time; > unsigned long i, nr_pages, addr, next; > - int nr; > + int nr, ret = 0; > struct page **pages; > > if (gup->size > ULONG_MAX) > @@ -63,8 +63,8 @@ static int __gup_benchmark_ioctl(unsigned int cmd, > NULL); > break; > default: > - kvfree(pages); > - return -1; > + ret = -EINVAL; > + goto done; > } > > if (nr <= 0) > @@ -85,8 +85,9 @@ static int __gup_benchmark_ioctl(unsigned int cmd, > end_time = ktime_get(); > gup->put_delta_usec = ktime_us_delta(end_time, start_time); > > +done: > kvfree(pages); > - return 0; > + return ret; > } > > static long gup_benchmark_ioctl(struct file *filep, unsigned int cmd, > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] mm/gup: Fix memory leak in __gup_benchmark_ioctl 2019-12-13 22:37 ` [PATCH v2] " Navid Emamdoost 2019-12-13 23:12 ` Ira Weiny 2019-12-14 0:44 ` John Hubbard @ 2019-12-14 18:10 ` Markus Elfring 2019-12-16 12:18 ` David Hildenbrand 3 siblings, 0 replies; 10+ messages in thread From: Markus Elfring @ 2019-12-14 18:10 UTC (permalink / raw) To: Navid Emamdoost, Ira Weiny, John Hubbard, linux-mm Cc: linux-kernel, kernel-janitors, Andrew Morton, Keith Busch, Kirill A. Shutemov, Navid Emamdoost … > +++ b/mm/gup_benchmark.c … > @@ -85,8 +85,9 @@ static int __gup_benchmark_ioctl(unsigned int cmd, > end_time = ktime_get(); > gup->put_delta_usec = ktime_us_delta(end_time, start_time); > > +done: > kvfree(pages); > - return 0; > + return ret; > } > > static long gup_benchmark_ioctl(struct file *filep, unsigned int cmd, Can the addition of a label like “free_pages” be more appropriate here? Regards, Markus ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] mm/gup: Fix memory leak in __gup_benchmark_ioctl 2019-12-13 22:37 ` [PATCH v2] " Navid Emamdoost ` (2 preceding siblings ...) 2019-12-14 18:10 ` Markus Elfring @ 2019-12-16 12:18 ` David Hildenbrand 3 siblings, 0 replies; 10+ messages in thread From: David Hildenbrand @ 2019-12-16 12:18 UTC (permalink / raw) To: Navid Emamdoost, Andrew Morton, Kirill A. Shutemov, Keith Busch, linux-mm, linux-kernel Cc: emamd001, jhubbard On 13.12.19 23:37, Navid Emamdoost wrote: > In the implementation of __gup_benchmark_ioctl() the allocated pages > should be released before returning in case of an invalid cmd. Release > pages via kvfree() by goto done. > > Fixes: 714a3a1ebafe ("mm/gup_benchmark.c: add additional pinning methods") > Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com> > --- > Changes in v2: > -- added goto and ret value instead of return -1. > --- > mm/gup_benchmark.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/mm/gup_benchmark.c b/mm/gup_benchmark.c > index b160638f647e..b773b2568544 100644 > --- a/mm/gup_benchmark.c > +++ b/mm/gup_benchmark.c > @@ -24,7 +24,7 @@ static int __gup_benchmark_ioctl(unsigned int cmd, > { > ktime_t start_time, end_time; > unsigned long i, nr_pages, addr, next; > - int nr; > + int nr, ret = 0; > struct page **pages; > > if (gup->size > ULONG_MAX) > @@ -63,8 +63,8 @@ static int __gup_benchmark_ioctl(unsigned int cmd, > NULL); > break; > default: > - kvfree(pages); > - return -1; > + ret = -EINVAL; > + goto done; > } > > if (nr <= 0) > @@ -85,8 +85,9 @@ static int __gup_benchmark_ioctl(unsigned int cmd, > end_time = ktime_get(); > gup->put_delta_usec = ktime_us_delta(end_time, start_time); > > +done: > kvfree(pages); > - return 0; > + return ret; > } > > static long gup_benchmark_ioctl(struct file *filep, unsigned int cmd, > You should really CC people that give review feedback in previous iterations (IOW me :) ) and properly tag versions/mention code change since the last version. (v1 was already <20191122224117.2372-1-navid.emamdoost@gmail.com>, this here would be v3) Also, this patch here is not a standalone patch, it is an addon on top of <20191211174653.4102-1-navid.emamdoost@gmail.com> Enough rambling :) This squashed into <20191211174653.4102-1-navid.emamdoost@gmail.com>: Reviewed-by: David Hildenbrand <david@redhat.com> I agree that the label could have a better name (e.g., out_free) -- Thanks, David / dhildenb ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2019-12-16 12:18 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-12-11 17:46 [PATCH] mm/gup: Fix memory leak in __gup_benchmark_ioctl Navid Emamdoost 2019-12-12 23:14 ` Ira Weiny 2019-12-13 21:40 ` John Hubbard 2019-12-13 22:23 ` Andrew Morton 2019-12-13 22:39 ` Navid Emamdoost 2019-12-13 22:37 ` [PATCH v2] " Navid Emamdoost 2019-12-13 23:12 ` Ira Weiny 2019-12-14 0:44 ` John Hubbard 2019-12-14 18:10 ` Markus Elfring 2019-12-16 12:18 ` David Hildenbrand
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox