All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/1] mm/cma: fix alloc_contig_range ret code/potential leak
@ 2017-11-20 19:39 ` Mike Kravetz
  0 siblings, 0 replies; 27+ messages in thread
From: Mike Kravetz @ 2017-11-20 19:39 UTC (permalink / raw)
  To: linux-mm, linux-kernel
  Cc: Joonsoo Kim, Vlastimil Babka, Michal Nazarewicz, Michal Hocko,
	Mel Gorman, Johannes Weiner, Andrew Morton, Mike Kravetz

In an attempt to make contiguous allocation routines more available to
drivers, I have been experimenting with code similar to that used by
alloc_gigantic_page().  While stressing this code with many other
allocations and frees in progress, I would sometimes notice large 'leaks'
of page ranges.

I traced this down to the routine alloc_contig_range() itself.  In commit
8ef5849fa8a2 the code was changed so that an -EBUSY returned by
__alloc_contig_migrate_range() would not immediately return to the caller.
Rather, processing continues so that test_pages_isolated() is eventually
called.  This is done because test_pages_isolated() has a tracepoint to
identify the busy pages.

However, it is possible (observed in my testing) that pages which were
busy when __alloc_contig_migrate_range was called may become available
by the time test_pages_isolated is called.  Further, it is possible that
the entire range can actually be allocated.  Unfortunately, in this case
the return code originally set by __alloc_contig_migrate_range (-EBUSY)
is returned to the calller.  Therefore, the caller assumes the range was
not allocated and the pages are essentially leaked.

The following patch simply updates the return code based on the value
returned from test_pages_isolated.

It is unlikely that we will hit this issue today based on the limited
number of callers to alloc_contig_range.  However, I have Cc'ed stable
because if we do hit this issue it has the potential to leak a large
number of pages.

Mike Kravetz (1):
  mm/cma: fix alloc_contig_range ret code/potential leak

 mm/page_alloc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

-- 
2.13.6

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 0/1] mm/cma: fix alloc_contig_range ret code/potential leak
@ 2017-11-20 19:39 ` Mike Kravetz
  0 siblings, 0 replies; 27+ messages in thread
From: Mike Kravetz @ 2017-11-20 19:39 UTC (permalink / raw)
  To: linux-mm, linux-kernel
  Cc: Joonsoo Kim, Vlastimil Babka, Michal Nazarewicz, Michal Hocko,
	Mel Gorman, Johannes Weiner, Andrew Morton, Mike Kravetz

In an attempt to make contiguous allocation routines more available to
drivers, I have been experimenting with code similar to that used by
alloc_gigantic_page().  While stressing this code with many other
allocations and frees in progress, I would sometimes notice large 'leaks'
of page ranges.

I traced this down to the routine alloc_contig_range() itself.  In commit
8ef5849fa8a2 the code was changed so that an -EBUSY returned by
__alloc_contig_migrate_range() would not immediately return to the caller.
Rather, processing continues so that test_pages_isolated() is eventually
called.  This is done because test_pages_isolated() has a tracepoint to
identify the busy pages.

However, it is possible (observed in my testing) that pages which were
busy when __alloc_contig_migrate_range was called may become available
by the time test_pages_isolated is called.  Further, it is possible that
the entire range can actually be allocated.  Unfortunately, in this case
the return code originally set by __alloc_contig_migrate_range (-EBUSY)
is returned to the calller.  Therefore, the caller assumes the range was
not allocated and the pages are essentially leaked.

The following patch simply updates the return code based on the value
returned from test_pages_isolated.

It is unlikely that we will hit this issue today based on the limited
number of callers to alloc_contig_range.  However, I have Cc'ed stable
because if we do hit this issue it has the potential to leak a large
number of pages.

Mike Kravetz (1):
  mm/cma: fix alloc_contig_range ret code/potential leak

 mm/page_alloc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

-- 
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 1/1] mm/cma: fix alloc_contig_range ret code/potential leak
  2017-11-20 19:39 ` Mike Kravetz
@ 2017-11-20 19:39   ` Mike Kravetz
  -1 siblings, 0 replies; 27+ messages in thread
From: Mike Kravetz @ 2017-11-20 19:39 UTC (permalink / raw)
  To: linux-mm, linux-kernel
  Cc: Joonsoo Kim, Vlastimil Babka, Michal Nazarewicz, Michal Hocko,
	Mel Gorman, Johannes Weiner, Andrew Morton, Mike Kravetz, stable

If the call __alloc_contig_migrate_range() in alloc_contig_range
returns -EBUSY, processing continues so that test_pages_isolated()
is called where there is a tracepoint to identify the busy pages.
However, it is possible for busy pages to become available between
the calls to these two routines.  In this case, the range of pages
may be allocated.   Unfortunately, the original return code (ret
== -EBUSY) is still set and returned to the caller.  Therefore,
the caller believes the pages were not allocated and they are leaked.

Update the return code with the value from test_pages_isolated().

Fixes: 8ef5849fa8a2 ("mm/cma: always check which page caused allocation failure")
Cc: <stable@vger.kernel.org>
Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
---
 mm/page_alloc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 77e4d3c5c57b..3605ca82fd29 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -7632,10 +7632,10 @@ int alloc_contig_range(unsigned long start, unsigned long end,
 	}
 
 	/* Make sure the range is really isolated. */
-	if (test_pages_isolated(outer_start, end, false)) {
+	ret = test_pages_isolated(outer_start, end, false);
+	if (ret) {
 		pr_info_ratelimited("%s: [%lx, %lx) PFNs busy\n",
 			__func__, outer_start, end);
-		ret = -EBUSY;
 		goto done;
 	}
 
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 1/1] mm/cma: fix alloc_contig_range ret code/potential leak
@ 2017-11-20 19:39   ` Mike Kravetz
  0 siblings, 0 replies; 27+ messages in thread
From: Mike Kravetz @ 2017-11-20 19:39 UTC (permalink / raw)
  To: linux-mm, linux-kernel
  Cc: Joonsoo Kim, Vlastimil Babka, Michal Nazarewicz, Michal Hocko,
	Mel Gorman, Johannes Weiner, Andrew Morton, Mike Kravetz, stable

If the call __alloc_contig_migrate_range() in alloc_contig_range
returns -EBUSY, processing continues so that test_pages_isolated()
is called where there is a tracepoint to identify the busy pages.
However, it is possible for busy pages to become available between
the calls to these two routines.  In this case, the range of pages
may be allocated.   Unfortunately, the original return code (ret
== -EBUSY) is still set and returned to the caller.  Therefore,
the caller believes the pages were not allocated and they are leaked.

Update the return code with the value from test_pages_isolated().

Fixes: 8ef5849fa8a2 ("mm/cma: always check which page caused allocation failure")
Cc: <stable@vger.kernel.org>
Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
---
 mm/page_alloc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 77e4d3c5c57b..3605ca82fd29 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -7632,10 +7632,10 @@ int alloc_contig_range(unsigned long start, unsigned long end,
 	}
 
 	/* Make sure the range is really isolated. */
-	if (test_pages_isolated(outer_start, end, false)) {
+	ret = test_pages_isolated(outer_start, end, false);
+	if (ret) {
 		pr_info_ratelimited("%s: [%lx, %lx) PFNs busy\n",
 			__func__, outer_start, end);
-		ret = -EBUSY;
 		goto done;
 	}
 
-- 
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/1] mm/cma: fix alloc_contig_range ret code/potential leak
  2017-11-20 19:39   ` Mike Kravetz
@ 2017-11-21  7:53     ` Vlastimil Babka
  -1 siblings, 0 replies; 27+ messages in thread
From: Vlastimil Babka @ 2017-11-21  7:53 UTC (permalink / raw)
  To: Mike Kravetz, linux-mm, linux-kernel
  Cc: Joonsoo Kim, Michal Nazarewicz, Michal Hocko, Mel Gorman,
	Johannes Weiner, Andrew Morton, stable

On 11/20/2017 08:39 PM, Mike Kravetz wrote:
> If the call __alloc_contig_migrate_range() in alloc_contig_range
> returns -EBUSY, processing continues so that test_pages_isolated()
> is called where there is a tracepoint to identify the busy pages.
> However, it is possible for busy pages to become available between
> the calls to these two routines.  In this case, the range of pages
> may be allocated.   Unfortunately, the original return code (ret
> == -EBUSY) is still set and returned to the caller.  Therefore,
> the caller believes the pages were not allocated and they are leaked.
> 
> Update the return code with the value from test_pages_isolated().

Good catch and seems ok for a stable fix. But it's another indication
that this area needs some larger rewrite.

For example, it seems that the tracepoints in test_pages_isolated() will
report not only pages which were busy during migration attempt, but also
pages that were not at all attempted, because
__alloc_contig_migrate_range() gave up?

> Fixes: 8ef5849fa8a2 ("mm/cma: always check which page caused allocation failure")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>  mm/page_alloc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 77e4d3c5c57b..3605ca82fd29 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -7632,10 +7632,10 @@ int alloc_contig_range(unsigned long start, unsigned long end,
>  	}
>  
>  	/* Make sure the range is really isolated. */
> -	if (test_pages_isolated(outer_start, end, false)) {
> +	ret = test_pages_isolated(outer_start, end, false);
> +	if (ret) {
>  		pr_info_ratelimited("%s: [%lx, %lx) PFNs busy\n",
>  			__func__, outer_start, end);
> -		ret = -EBUSY;
>  		goto done;
>  	}
>  
> 

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/1] mm/cma: fix alloc_contig_range ret code/potential leak
@ 2017-11-21  7:53     ` Vlastimil Babka
  0 siblings, 0 replies; 27+ messages in thread
From: Vlastimil Babka @ 2017-11-21  7:53 UTC (permalink / raw)
  To: Mike Kravetz, linux-mm, linux-kernel
  Cc: Joonsoo Kim, Michal Nazarewicz, Michal Hocko, Mel Gorman,
	Johannes Weiner, Andrew Morton, stable

On 11/20/2017 08:39 PM, Mike Kravetz wrote:
> If the call __alloc_contig_migrate_range() in alloc_contig_range
> returns -EBUSY, processing continues so that test_pages_isolated()
> is called where there is a tracepoint to identify the busy pages.
> However, it is possible for busy pages to become available between
> the calls to these two routines.  In this case, the range of pages
> may be allocated.   Unfortunately, the original return code (ret
> == -EBUSY) is still set and returned to the caller.  Therefore,
> the caller believes the pages were not allocated and they are leaked.
> 
> Update the return code with the value from test_pages_isolated().

Good catch and seems ok for a stable fix. But it's another indication
that this area needs some larger rewrite.

For example, it seems that the tracepoints in test_pages_isolated() will
report not only pages which were busy during migration attempt, but also
pages that were not at all attempted, because
__alloc_contig_migrate_range() gave up?

> Fixes: 8ef5849fa8a2 ("mm/cma: always check which page caused allocation failure")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>  mm/page_alloc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 77e4d3c5c57b..3605ca82fd29 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -7632,10 +7632,10 @@ int alloc_contig_range(unsigned long start, unsigned long end,
>  	}
>  
>  	/* Make sure the range is really isolated. */
> -	if (test_pages_isolated(outer_start, end, false)) {
> +	ret = test_pages_isolated(outer_start, end, false);
> +	if (ret) {
>  		pr_info_ratelimited("%s: [%lx, %lx) PFNs busy\n",
>  			__func__, outer_start, end);
> -		ret = -EBUSY;
>  		goto done;
>  	}
>  
> 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/1] mm/cma: fix alloc_contig_range ret code/potential leak
  2017-11-20 19:39   ` Mike Kravetz
@ 2017-11-21 13:04     ` Michal Hocko
  -1 siblings, 0 replies; 27+ messages in thread
From: Michal Hocko @ 2017-11-21 13:04 UTC (permalink / raw)
  To: Mike Kravetz
  Cc: linux-mm, linux-kernel, Joonsoo Kim, Vlastimil Babka,
	Michal Nazarewicz, Mel Gorman, Johannes Weiner, Andrew Morton,
	stable

On Mon 20-11-17 11:39:30, Mike Kravetz wrote:
> If the call __alloc_contig_migrate_range() in alloc_contig_range
> returns -EBUSY, processing continues so that test_pages_isolated()
> is called where there is a tracepoint to identify the busy pages.
> However, it is possible for busy pages to become available between
> the calls to these two routines.  In this case, the range of pages
> may be allocated.   Unfortunately, the original return code (ret
> == -EBUSY) is still set and returned to the caller.  Therefore,
> the caller believes the pages were not allocated and they are leaked.
> 
> Update the return code with the value from test_pages_isolated().

I find the description in 0/0 much more easier to grasp so I would
vote for merging it into the changelog. It took me a while to realize
that we are talking about the success path just from staring into the
diff which doesn't have a sufficient scope to tell the whole story.

Btw. I find embeded description in the diffstat area much more easier to
follow for single patches. Having a cover for a single patch sounds more
like a distraction. Just my 2c

> Fixes: 8ef5849fa8a2 ("mm/cma: always check which page caused allocation failure")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  mm/page_alloc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 77e4d3c5c57b..3605ca82fd29 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -7632,10 +7632,10 @@ int alloc_contig_range(unsigned long start, unsigned long end,
>  	}
>  
>  	/* Make sure the range is really isolated. */
> -	if (test_pages_isolated(outer_start, end, false)) {
> +	ret = test_pages_isolated(outer_start, end, false);
> +	if (ret) {
>  		pr_info_ratelimited("%s: [%lx, %lx) PFNs busy\n",
>  			__func__, outer_start, end);
> -		ret = -EBUSY;
>  		goto done;
>  	}
>  
> -- 
> 2.13.6
> 

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/1] mm/cma: fix alloc_contig_range ret code/potential leak
@ 2017-11-21 13:04     ` Michal Hocko
  0 siblings, 0 replies; 27+ messages in thread
From: Michal Hocko @ 2017-11-21 13:04 UTC (permalink / raw)
  To: Mike Kravetz
  Cc: linux-mm, linux-kernel, Joonsoo Kim, Vlastimil Babka,
	Michal Nazarewicz, Mel Gorman, Johannes Weiner, Andrew Morton,
	stable

On Mon 20-11-17 11:39:30, Mike Kravetz wrote:
> If the call __alloc_contig_migrate_range() in alloc_contig_range
> returns -EBUSY, processing continues so that test_pages_isolated()
> is called where there is a tracepoint to identify the busy pages.
> However, it is possible for busy pages to become available between
> the calls to these two routines.  In this case, the range of pages
> may be allocated.   Unfortunately, the original return code (ret
> == -EBUSY) is still set and returned to the caller.  Therefore,
> the caller believes the pages were not allocated and they are leaked.
> 
> Update the return code with the value from test_pages_isolated().

I find the description in 0/0 much more easier to grasp so I would
vote for merging it into the changelog. It took me a while to realize
that we are talking about the success path just from staring into the
diff which doesn't have a sufficient scope to tell the whole story.

Btw. I find embeded description in the diffstat area much more easier to
follow for single patches. Having a cover for a single patch sounds more
like a distraction. Just my 2c

> Fixes: 8ef5849fa8a2 ("mm/cma: always check which page caused allocation failure")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  mm/page_alloc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 77e4d3c5c57b..3605ca82fd29 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -7632,10 +7632,10 @@ int alloc_contig_range(unsigned long start, unsigned long end,
>  	}
>  
>  	/* Make sure the range is really isolated. */
> -	if (test_pages_isolated(outer_start, end, false)) {
> +	ret = test_pages_isolated(outer_start, end, false);
> +	if (ret) {
>  		pr_info_ratelimited("%s: [%lx, %lx) PFNs busy\n",
>  			__func__, outer_start, end);
> -		ret = -EBUSY;
>  		goto done;
>  	}
>  
> -- 
> 2.13.6
> 

-- 
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/1] mm/cma: fix alloc_contig_range ret code/potential leak
  2017-11-21  7:53     ` Vlastimil Babka
@ 2017-11-21 13:06       ` Michal Hocko
  -1 siblings, 0 replies; 27+ messages in thread
From: Michal Hocko @ 2017-11-21 13:06 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: Mike Kravetz, linux-mm, linux-kernel, Joonsoo Kim,
	Michal Nazarewicz, Mel Gorman, Johannes Weiner, Andrew Morton,
	stable

On Tue 21-11-17 08:53:11, Vlastimil Babka wrote:
> On 11/20/2017 08:39 PM, Mike Kravetz wrote:
> > If the call __alloc_contig_migrate_range() in alloc_contig_range
> > returns -EBUSY, processing continues so that test_pages_isolated()
> > is called where there is a tracepoint to identify the busy pages.
> > However, it is possible for busy pages to become available between
> > the calls to these two routines.  In this case, the range of pages
> > may be allocated.   Unfortunately, the original return code (ret
> > == -EBUSY) is still set and returned to the caller.  Therefore,
> > the caller believes the pages were not allocated and they are leaked.
> > 
> > Update the return code with the value from test_pages_isolated().
> 
> Good catch and seems ok for a stable fix. But it's another indication
> that this area needs some larger rewrite.

Absolutely. The whole thing is subtle as hell. And shaping the code just
around the tracepoint here smells like the whole design could be thought
through much more.
-- 
Michal Hocko
SUSE Labs

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/1] mm/cma: fix alloc_contig_range ret code/potential leak
@ 2017-11-21 13:06       ` Michal Hocko
  0 siblings, 0 replies; 27+ messages in thread
From: Michal Hocko @ 2017-11-21 13:06 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: Mike Kravetz, linux-mm, linux-kernel, Joonsoo Kim,
	Michal Nazarewicz, Mel Gorman, Johannes Weiner, Andrew Morton,
	stable

On Tue 21-11-17 08:53:11, Vlastimil Babka wrote:
> On 11/20/2017 08:39 PM, Mike Kravetz wrote:
> > If the call __alloc_contig_migrate_range() in alloc_contig_range
> > returns -EBUSY, processing continues so that test_pages_isolated()
> > is called where there is a tracepoint to identify the busy pages.
> > However, it is possible for busy pages to become available between
> > the calls to these two routines.  In this case, the range of pages
> > may be allocated.   Unfortunately, the original return code (ret
> > == -EBUSY) is still set and returned to the caller.  Therefore,
> > the caller believes the pages were not allocated and they are leaked.
> > 
> > Update the return code with the value from test_pages_isolated().
> 
> Good catch and seems ok for a stable fix. But it's another indication
> that this area needs some larger rewrite.

Absolutely. The whole thing is subtle as hell. And shaping the code just
around the tracepoint here smells like the whole design could be thought
through much more.
-- 
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/1] mm/cma: fix alloc_contig_range ret code/potential leak
  2017-11-20 19:39   ` Mike Kravetz
  (?)
@ 2017-11-21 14:20     ` Michal Nazarewicz
  -1 siblings, 0 replies; 27+ messages in thread
From: Michal Nazarewicz @ 2017-11-21 14:20 UTC (permalink / raw)
  To: Mike Kravetz, linux-mm, linux-kernel
  Cc: Joonsoo Kim, Vlastimil Babka, Michal Hocko, Mel Gorman,
	Johannes Weiner, Andrew Morton, Mike Kravetz, stable

On Mon, Nov 20 2017, Mike Kravetz wrote:
> If the call __alloc_contig_migrate_range() in alloc_contig_range
> returns -EBUSY, processing continues so that test_pages_isolated()
> is called where there is a tracepoint to identify the busy pages.
> However, it is possible for busy pages to become available between
> the calls to these two routines.  In this case, the range of pages
> may be allocated.   Unfortunately, the original return code (ret
> == -EBUSY) is still set and returned to the caller.  Therefore,
> the caller believes the pages were not allocated and they are leaked.
>
> Update the return code with the value from test_pages_isolated().
>
> Fixes: 8ef5849fa8a2 ("mm/cma: always check which page caused allocation failure")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>

Acked-by: Michal Nazarewicz <mina86@mina86.com>

> ---
>  mm/page_alloc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 77e4d3c5c57b..3605ca82fd29 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -7632,10 +7632,10 @@ int alloc_contig_range(unsigned long start, unsigned long end,
>  	}
>  
>  	/* Make sure the range is really isolated. */
> -	if (test_pages_isolated(outer_start, end, false)) {
> +	ret = test_pages_isolated(outer_start, end, false);
> +	if (ret) {
>  		pr_info_ratelimited("%s: [%lx, %lx) PFNs busy\n",
>  			__func__, outer_start, end);
> -		ret = -EBUSY;
>  		goto done;
>  	}

-- 
Best regards
ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴイツ
«If at first you don’t succeed, give up skydiving»

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/1] mm/cma: fix alloc_contig_range ret code/potential leak
@ 2017-11-21 14:20     ` Michal Nazarewicz
  0 siblings, 0 replies; 27+ messages in thread
From: Michal Nazarewicz @ 2017-11-21 14:20 UTC (permalink / raw)
  To: Mike Kravetz, linux-mm, linux-kernel
  Cc: Joonsoo Kim, Vlastimil Babka, Michal Hocko, Mel Gorman,
	Johannes Weiner, Andrew Morton, Mike Kravetz, stable

On Mon, Nov 20 2017, Mike Kravetz wrote:
> If the call __alloc_contig_migrate_range() in alloc_contig_range
> returns -EBUSY, processing continues so that test_pages_isolated()
> is called where there is a tracepoint to identify the busy pages.
> However, it is possible for busy pages to become available between
> the calls to these two routines.  In this case, the range of pages
> may be allocated.   Unfortunately, the original return code (ret
> == -EBUSY) is still set and returned to the caller.  Therefore,
> the caller believes the pages were not allocated and they are leaked.
>
> Update the return code with the value from test_pages_isolated().
>
> Fixes: 8ef5849fa8a2 ("mm/cma: always check which page caused allocation failure")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>

Acked-by: Michal Nazarewicz <mina86@mina86.com>

> ---
>  mm/page_alloc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 77e4d3c5c57b..3605ca82fd29 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -7632,10 +7632,10 @@ int alloc_contig_range(unsigned long start, unsigned long end,
>  	}
>  
>  	/* Make sure the range is really isolated. */
> -	if (test_pages_isolated(outer_start, end, false)) {
> +	ret = test_pages_isolated(outer_start, end, false);
> +	if (ret) {
>  		pr_info_ratelimited("%s: [%lx, %lx) PFNs busy\n",
>  			__func__, outer_start, end);
> -		ret = -EBUSY;
>  		goto done;
>  	}

-- 
Best regards
ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴイツ
«If at first you don’t succeed, give up skydiving»

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/1] mm/cma: fix alloc_contig_range ret code/potential leak
@ 2017-11-21 14:20     ` Michal Nazarewicz
  0 siblings, 0 replies; 27+ messages in thread
From: Michal Nazarewicz @ 2017-11-21 14:20 UTC (permalink / raw)
  To: Mike Kravetz, linux-mm, linux-kernel
  Cc: Joonsoo Kim, Vlastimil Babka, Michal Hocko, Mel Gorman,
	Johannes Weiner, Andrew Morton, stable

On Mon, Nov 20 2017, Mike Kravetz wrote:
> If the call __alloc_contig_migrate_range() in alloc_contig_range
> returns -EBUSY, processing continues so that test_pages_isolated()
> is called where there is a tracepoint to identify the busy pages.
> However, it is possible for busy pages to become available between
> the calls to these two routines.  In this case, the range of pages
> may be allocated.   Unfortunately, the original return code (ret
> == -EBUSY) is still set and returned to the caller.  Therefore,
> the caller believes the pages were not allocated and they are leaked.
>
> Update the return code with the value from test_pages_isolated().
>
> Fixes: 8ef5849fa8a2 ("mm/cma: always check which page caused allocation failure")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>

Acked-by: Michal Nazarewicz <mina86@mina86.com>

> ---
>  mm/page_alloc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 77e4d3c5c57b..3605ca82fd29 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -7632,10 +7632,10 @@ int alloc_contig_range(unsigned long start, unsigned long end,
>  	}
>  
>  	/* Make sure the range is really isolated. */
> -	if (test_pages_isolated(outer_start, end, false)) {
> +	ret = test_pages_isolated(outer_start, end, false);
> +	if (ret) {
>  		pr_info_ratelimited("%s: [%lx, %lx) PFNs busy\n",
>  			__func__, outer_start, end);
> -		ret = -EBUSY;
>  		goto done;
>  	}

-- 
Best regards
ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴイツ
«If at first you don’t succeed, give up skydiving»

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/1] mm/cma: fix alloc_contig_range ret code/potential leak
  2017-11-20 19:39   ` Mike Kravetz
@ 2017-11-22 12:00     ` Johannes Weiner
  -1 siblings, 0 replies; 27+ messages in thread
From: Johannes Weiner @ 2017-11-22 12:00 UTC (permalink / raw)
  To: Mike Kravetz
  Cc: linux-mm, linux-kernel, Joonsoo Kim, Vlastimil Babka,
	Michal Nazarewicz, Michal Hocko, Mel Gorman, Andrew Morton,
	stable

On Mon, Nov 20, 2017 at 11:39:30AM -0800, Mike Kravetz wrote:
> If the call __alloc_contig_migrate_range() in alloc_contig_range
> returns -EBUSY, processing continues so that test_pages_isolated()
> is called where there is a tracepoint to identify the busy pages.
> However, it is possible for busy pages to become available between
> the calls to these two routines.  In this case, the range of pages
> may be allocated.   Unfortunately, the original return code (ret
> == -EBUSY) is still set and returned to the caller.  Therefore,
> the caller believes the pages were not allocated and they are leaked.
> 
> Update the return code with the value from test_pages_isolated().
> 
> Fixes: 8ef5849fa8a2 ("mm/cma: always check which page caused allocation failure")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>

Wow, good catch.

> ---
>  mm/page_alloc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 77e4d3c5c57b..3605ca82fd29 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -7632,10 +7632,10 @@ int alloc_contig_range(unsigned long start, unsigned long end,
>  	}
>  
>  	/* Make sure the range is really isolated. */
> -	if (test_pages_isolated(outer_start, end, false)) {
> +	ret = test_pages_isolated(outer_start, end, false);
> +	if (ret) {
>  		pr_info_ratelimited("%s: [%lx, %lx) PFNs busy\n",
>  			__func__, outer_start, end);
> -		ret = -EBUSY;
>  		goto done;

Essentially, an -EBUSY from __alloc_contig_migrate_range() doesn't
mean anything, and we return 0 if the rest of the operations succeed.

Since we never plan on returning that particular -EBUSY, would it be
more robust to reset it right then and there, rather than letting it
run on in ret for more than a screenful?

It would also be good to note in that fall-through comment that the
pages becoming free on their own is a distinct possibility.

As Michal points out, this is really subtle. It makes sense to make it
as explicit as possible.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/1] mm/cma: fix alloc_contig_range ret code/potential leak
@ 2017-11-22 12:00     ` Johannes Weiner
  0 siblings, 0 replies; 27+ messages in thread
From: Johannes Weiner @ 2017-11-22 12:00 UTC (permalink / raw)
  To: Mike Kravetz
  Cc: linux-mm, linux-kernel, Joonsoo Kim, Vlastimil Babka,
	Michal Nazarewicz, Michal Hocko, Mel Gorman, Andrew Morton,
	stable

On Mon, Nov 20, 2017 at 11:39:30AM -0800, Mike Kravetz wrote:
> If the call __alloc_contig_migrate_range() in alloc_contig_range
> returns -EBUSY, processing continues so that test_pages_isolated()
> is called where there is a tracepoint to identify the busy pages.
> However, it is possible for busy pages to become available between
> the calls to these two routines.  In this case, the range of pages
> may be allocated.   Unfortunately, the original return code (ret
> == -EBUSY) is still set and returned to the caller.  Therefore,
> the caller believes the pages were not allocated and they are leaked.
> 
> Update the return code with the value from test_pages_isolated().
> 
> Fixes: 8ef5849fa8a2 ("mm/cma: always check which page caused allocation failure")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>

Wow, good catch.

> ---
>  mm/page_alloc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 77e4d3c5c57b..3605ca82fd29 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -7632,10 +7632,10 @@ int alloc_contig_range(unsigned long start, unsigned long end,
>  	}
>  
>  	/* Make sure the range is really isolated. */
> -	if (test_pages_isolated(outer_start, end, false)) {
> +	ret = test_pages_isolated(outer_start, end, false);
> +	if (ret) {
>  		pr_info_ratelimited("%s: [%lx, %lx) PFNs busy\n",
>  			__func__, outer_start, end);
> -		ret = -EBUSY;
>  		goto done;

Essentially, an -EBUSY from __alloc_contig_migrate_range() doesn't
mean anything, and we return 0 if the rest of the operations succeed.

Since we never plan on returning that particular -EBUSY, would it be
more robust to reset it right then and there, rather than letting it
run on in ret for more than a screenful?

It would also be good to note in that fall-through comment that the
pages becoming free on their own is a distinct possibility.

As Michal points out, this is really subtle. It makes sense to make it
as explicit as possible.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/1] mm/cma: fix alloc_contig_range ret code/potential leak
  2017-11-22 12:00     ` Johannes Weiner
@ 2017-11-22 17:46       ` Mike Kravetz
  -1 siblings, 0 replies; 27+ messages in thread
From: Mike Kravetz @ 2017-11-22 17:46 UTC (permalink / raw)
  To: Johannes Weiner
  Cc: linux-mm, linux-kernel, Joonsoo Kim, Vlastimil Babka,
	Michal Nazarewicz, Michal Hocko, Mel Gorman, Andrew Morton,
	stable

On 11/22/2017 04:00 AM, Johannes Weiner wrote:
> On Mon, Nov 20, 2017 at 11:39:30AM -0800, Mike Kravetz wrote:
>> If the call __alloc_contig_migrate_range() in alloc_contig_range
>> returns -EBUSY, processing continues so that test_pages_isolated()
>> is called where there is a tracepoint to identify the busy pages.
>> However, it is possible for busy pages to become available between
>> the calls to these two routines.  In this case, the range of pages
>> may be allocated.   Unfortunately, the original return code (ret
>> == -EBUSY) is still set and returned to the caller.  Therefore,
>> the caller believes the pages were not allocated and they are leaked.
>>
>> Update the return code with the value from test_pages_isolated().
>>
>> Fixes: 8ef5849fa8a2 ("mm/cma: always check which page caused allocation failure")
>> Cc: <stable@vger.kernel.org>
>> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
> 
> Wow, good catch.
> 
>> ---
>>  mm/page_alloc.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>> index 77e4d3c5c57b..3605ca82fd29 100644
>> --- a/mm/page_alloc.c
>> +++ b/mm/page_alloc.c
>> @@ -7632,10 +7632,10 @@ int alloc_contig_range(unsigned long start, unsigned long end,
>>  	}
>>  
>>  	/* Make sure the range is really isolated. */
>> -	if (test_pages_isolated(outer_start, end, false)) {
>> +	ret = test_pages_isolated(outer_start, end, false);
>> +	if (ret) {
>>  		pr_info_ratelimited("%s: [%lx, %lx) PFNs busy\n",
>>  			__func__, outer_start, end);
>> -		ret = -EBUSY;
>>  		goto done;
> 
> Essentially, an -EBUSY from __alloc_contig_migrate_range() doesn't
> mean anything, and we return 0 if the rest of the operations succeed.
> 
> Since we never plan on returning that particular -EBUSY, would it be
> more robust to reset it right then and there, rather than letting it
> run on in ret for more than a screenful?
> 
> It would also be good to note in that fall-through comment that the
> pages becoming free on their own is a distinct possibility.
> 
> As Michal points out, this is really subtle. It makes sense to make it
> as explicit as possible.

Ok, I thought about zero'ing ret right after the call to
__alloc_contig_migrate_range and return of -EBUSY.  It just didn't look
right to me.  But, you are correct.  We should make this as explicit as
possible.  I will respin the patch as suggested and be sure to include an
explicit comment when setting ret = 0.

-- 
Mike Kravetz

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/1] mm/cma: fix alloc_contig_range ret code/potential leak
@ 2017-11-22 17:46       ` Mike Kravetz
  0 siblings, 0 replies; 27+ messages in thread
From: Mike Kravetz @ 2017-11-22 17:46 UTC (permalink / raw)
  To: Johannes Weiner
  Cc: linux-mm, linux-kernel, Joonsoo Kim, Vlastimil Babka,
	Michal Nazarewicz, Michal Hocko, Mel Gorman, Andrew Morton,
	stable

On 11/22/2017 04:00 AM, Johannes Weiner wrote:
> On Mon, Nov 20, 2017 at 11:39:30AM -0800, Mike Kravetz wrote:
>> If the call __alloc_contig_migrate_range() in alloc_contig_range
>> returns -EBUSY, processing continues so that test_pages_isolated()
>> is called where there is a tracepoint to identify the busy pages.
>> However, it is possible for busy pages to become available between
>> the calls to these two routines.  In this case, the range of pages
>> may be allocated.   Unfortunately, the original return code (ret
>> == -EBUSY) is still set and returned to the caller.  Therefore,
>> the caller believes the pages were not allocated and they are leaked.
>>
>> Update the return code with the value from test_pages_isolated().
>>
>> Fixes: 8ef5849fa8a2 ("mm/cma: always check which page caused allocation failure")
>> Cc: <stable@vger.kernel.org>
>> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
> 
> Wow, good catch.
> 
>> ---
>>  mm/page_alloc.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>> index 77e4d3c5c57b..3605ca82fd29 100644
>> --- a/mm/page_alloc.c
>> +++ b/mm/page_alloc.c
>> @@ -7632,10 +7632,10 @@ int alloc_contig_range(unsigned long start, unsigned long end,
>>  	}
>>  
>>  	/* Make sure the range is really isolated. */
>> -	if (test_pages_isolated(outer_start, end, false)) {
>> +	ret = test_pages_isolated(outer_start, end, false);
>> +	if (ret) {
>>  		pr_info_ratelimited("%s: [%lx, %lx) PFNs busy\n",
>>  			__func__, outer_start, end);
>> -		ret = -EBUSY;
>>  		goto done;
> 
> Essentially, an -EBUSY from __alloc_contig_migrate_range() doesn't
> mean anything, and we return 0 if the rest of the operations succeed.
> 
> Since we never plan on returning that particular -EBUSY, would it be
> more robust to reset it right then and there, rather than letting it
> run on in ret for more than a screenful?
> 
> It would also be good to note in that fall-through comment that the
> pages becoming free on their own is a distinct possibility.
> 
> As Michal points out, this is really subtle. It makes sense to make it
> as explicit as possible.

Ok, I thought about zero'ing ret right after the call to
__alloc_contig_migrate_range and return of -EBUSY.  It just didn't look
right to me.  But, you are correct.  We should make this as explicit as
possible.  I will respin the patch as suggested and be sure to include an
explicit comment when setting ret = 0.

-- 
Mike Kravetz

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH v2] mm/cma: fix alloc_contig_range ret code/potential leak
  2017-11-22 17:46       ` Mike Kravetz
@ 2017-11-22 18:52         ` Mike Kravetz
  -1 siblings, 0 replies; 27+ messages in thread
From: Mike Kravetz @ 2017-11-22 18:52 UTC (permalink / raw)
  To: linux-mm, linux-kernel
  Cc: Joonsoo Kim, Vlastimil Babka, Michal Nazarewicz, Michal Hocko,
	Mel Gorman, Johannes Weiner, Andrew Morton, Mike Kravetz, stable

If the call __alloc_contig_migrate_range() in alloc_contig_range
returns -EBUSY, processing continues so that test_pages_isolated()
is called where there is a tracepoint to identify the busy pages.
However, it is possible for busy pages to become available between
the calls to these two routines.  In this case, the range of pages
may be allocated.   Unfortunately, the original return code (ret
== -EBUSY) is still set and returned to the caller.  Therefore,
the caller believes the pages were not allocated and they are leaked.

Update comment to indicate that allocation is still possible even if
__alloc_contig_migrate_range returns -EBUSY.  Also, clear return code
in this case so that it is not accidentally used or returned to caller.

Fixes: 8ef5849fa8a2 ("mm/cma: always check which page caused allocation failure")
Cc: <stable@vger.kernel.org>
Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
---
 mm/page_alloc.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 77e4d3c5c57b..25e81844d1aa 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -7582,11 +7582,18 @@ int alloc_contig_range(unsigned long start, unsigned long end,
 
 	/*
 	 * In case of -EBUSY, we'd like to know which page causes problem.
-	 * So, just fall through. We will check it in test_pages_isolated().
+	 * So, just fall through. test_pages_isolated() has a tracepoint
+	 * which will report the busy page.
+	 *
+	 * It is possible that busy pages could become available before
+	 * the call to test_pages_isolated, and the range will actually be
+	 * allocated.  So, if we fall through be sure to clear ret so that
+	 * -EBUSY is not accidentally used or returned to caller.
 	 */
 	ret = __alloc_contig_migrate_range(&cc, start, end);
 	if (ret && ret != -EBUSY)
 		goto done;
+	ret =0;
 
 	/*
 	 * Pages from [start, end) are within a MAX_ORDER_NR_PAGES
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH v2] mm/cma: fix alloc_contig_range ret code/potential leak
@ 2017-11-22 18:52         ` Mike Kravetz
  0 siblings, 0 replies; 27+ messages in thread
From: Mike Kravetz @ 2017-11-22 18:52 UTC (permalink / raw)
  To: linux-mm, linux-kernel
  Cc: Joonsoo Kim, Vlastimil Babka, Michal Nazarewicz, Michal Hocko,
	Mel Gorman, Johannes Weiner, Andrew Morton, Mike Kravetz, stable

If the call __alloc_contig_migrate_range() in alloc_contig_range
returns -EBUSY, processing continues so that test_pages_isolated()
is called where there is a tracepoint to identify the busy pages.
However, it is possible for busy pages to become available between
the calls to these two routines.  In this case, the range of pages
may be allocated.   Unfortunately, the original return code (ret
== -EBUSY) is still set and returned to the caller.  Therefore,
the caller believes the pages were not allocated and they are leaked.

Update comment to indicate that allocation is still possible even if
__alloc_contig_migrate_range returns -EBUSY.  Also, clear return code
in this case so that it is not accidentally used or returned to caller.

Fixes: 8ef5849fa8a2 ("mm/cma: always check which page caused allocation failure")
Cc: <stable@vger.kernel.org>
Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
---
 mm/page_alloc.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 77e4d3c5c57b..25e81844d1aa 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -7582,11 +7582,18 @@ int alloc_contig_range(unsigned long start, unsigned long end,
 
 	/*
 	 * In case of -EBUSY, we'd like to know which page causes problem.
-	 * So, just fall through. We will check it in test_pages_isolated().
+	 * So, just fall through. test_pages_isolated() has a tracepoint
+	 * which will report the busy page.
+	 *
+	 * It is possible that busy pages could become available before
+	 * the call to test_pages_isolated, and the range will actually be
+	 * allocated.  So, if we fall through be sure to clear ret so that
+	 * -EBUSY is not accidentally used or returned to caller.
 	 */
 	ret = __alloc_contig_migrate_range(&cc, start, end);
 	if (ret && ret != -EBUSY)
 		goto done;
+	ret =0;
 
 	/*
 	 * Pages from [start, end) are within a MAX_ORDER_NR_PAGES
-- 
2.13.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH v2] mm/cma: fix alloc_contig_range ret code/potential leak
  2017-11-22 18:52         ` Mike Kravetz
@ 2017-11-23  8:05           ` Vlastimil Babka
  -1 siblings, 0 replies; 27+ messages in thread
From: Vlastimil Babka @ 2017-11-23  8:05 UTC (permalink / raw)
  To: Mike Kravetz, linux-mm, linux-kernel
  Cc: Joonsoo Kim, Michal Nazarewicz, Michal Hocko, Mel Gorman,
	Johannes Weiner, Andrew Morton, stable

On 11/22/2017 07:52 PM, Mike Kravetz wrote:
> If the call __alloc_contig_migrate_range() in alloc_contig_range
> returns -EBUSY, processing continues so that test_pages_isolated()
> is called where there is a tracepoint to identify the busy pages.
> However, it is possible for busy pages to become available between
> the calls to these two routines.  In this case, the range of pages
> may be allocated.   Unfortunately, the original return code (ret
> == -EBUSY) is still set and returned to the caller.  Therefore,
> the caller believes the pages were not allocated and they are leaked.
> 
> Update comment to indicate that allocation is still possible even if
> __alloc_contig_migrate_range returns -EBUSY.  Also, clear return code
> in this case so that it is not accidentally used or returned to caller.
> 
> Fixes: 8ef5849fa8a2 ("mm/cma: always check which page caused allocation failure")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>  mm/page_alloc.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 77e4d3c5c57b..25e81844d1aa 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -7582,11 +7582,18 @@ int alloc_contig_range(unsigned long start, unsigned long end,
>  
>  	/*
>  	 * In case of -EBUSY, we'd like to know which page causes problem.
> -	 * So, just fall through. We will check it in test_pages_isolated().
> +	 * So, just fall through. test_pages_isolated() has a tracepoint
> +	 * which will report the busy page.
> +	 *
> +	 * It is possible that busy pages could become available before
> +	 * the call to test_pages_isolated, and the range will actually be
> +	 * allocated.  So, if we fall through be sure to clear ret so that
> +	 * -EBUSY is not accidentally used or returned to caller.
>  	 */
>  	ret = __alloc_contig_migrate_range(&cc, start, end);
>  	if (ret && ret != -EBUSY)
>  		goto done;
> +	ret =0;

             ^ missing space
>  
>  	/*
>  	 * Pages from [start, end) are within a MAX_ORDER_NR_PAGES
> 

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v2] mm/cma: fix alloc_contig_range ret code/potential leak
@ 2017-11-23  8:05           ` Vlastimil Babka
  0 siblings, 0 replies; 27+ messages in thread
From: Vlastimil Babka @ 2017-11-23  8:05 UTC (permalink / raw)
  To: Mike Kravetz, linux-mm, linux-kernel
  Cc: Joonsoo Kim, Michal Nazarewicz, Michal Hocko, Mel Gorman,
	Johannes Weiner, Andrew Morton, stable

On 11/22/2017 07:52 PM, Mike Kravetz wrote:
> If the call __alloc_contig_migrate_range() in alloc_contig_range
> returns -EBUSY, processing continues so that test_pages_isolated()
> is called where there is a tracepoint to identify the busy pages.
> However, it is possible for busy pages to become available between
> the calls to these two routines.  In this case, the range of pages
> may be allocated.   Unfortunately, the original return code (ret
> == -EBUSY) is still set and returned to the caller.  Therefore,
> the caller believes the pages were not allocated and they are leaked.
> 
> Update comment to indicate that allocation is still possible even if
> __alloc_contig_migrate_range returns -EBUSY.  Also, clear return code
> in this case so that it is not accidentally used or returned to caller.
> 
> Fixes: 8ef5849fa8a2 ("mm/cma: always check which page caused allocation failure")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>  mm/page_alloc.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 77e4d3c5c57b..25e81844d1aa 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -7582,11 +7582,18 @@ int alloc_contig_range(unsigned long start, unsigned long end,
>  
>  	/*
>  	 * In case of -EBUSY, we'd like to know which page causes problem.
> -	 * So, just fall through. We will check it in test_pages_isolated().
> +	 * So, just fall through. test_pages_isolated() has a tracepoint
> +	 * which will report the busy page.
> +	 *
> +	 * It is possible that busy pages could become available before
> +	 * the call to test_pages_isolated, and the range will actually be
> +	 * allocated.  So, if we fall through be sure to clear ret so that
> +	 * -EBUSY is not accidentally used or returned to caller.
>  	 */
>  	ret = __alloc_contig_migrate_range(&cc, start, end);
>  	if (ret && ret != -EBUSY)
>  		goto done;
> +	ret =0;

             ^ missing space
>  
>  	/*
>  	 * Pages from [start, end) are within a MAX_ORDER_NR_PAGES
> 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v2] mm/cma: fix alloc_contig_range ret code/potential leak
  2017-11-22 18:52         ` Mike Kravetz
@ 2017-11-23  9:19           ` Michal Hocko
  -1 siblings, 0 replies; 27+ messages in thread
From: Michal Hocko @ 2017-11-23  9:19 UTC (permalink / raw)
  To: Mike Kravetz
  Cc: linux-mm, linux-kernel, Joonsoo Kim, Vlastimil Babka,
	Michal Nazarewicz, Mel Gorman, Johannes Weiner, Andrew Morton,
	stable

On Wed 22-11-17 10:52:14, Mike Kravetz wrote:
> If the call __alloc_contig_migrate_range() in alloc_contig_range
> returns -EBUSY, processing continues so that test_pages_isolated()
> is called where there is a tracepoint to identify the busy pages.
> However, it is possible for busy pages to become available between
> the calls to these two routines.  In this case, the range of pages
> may be allocated.   Unfortunately, the original return code (ret
> == -EBUSY) is still set and returned to the caller.  Therefore,
> the caller believes the pages were not allocated and they are leaked.
> 
> Update comment to indicate that allocation is still possible even if
> __alloc_contig_migrate_range returns -EBUSY.  Also, clear return code
> in this case so that it is not accidentally used or returned to caller.
> 
> Fixes: 8ef5849fa8a2 ("mm/cma: always check which page caused allocation failure")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>

OK, this one looks reasonable as well.
Acked-by: Michal Hocko <mhocko@suse.com>

Thanks!

> ---
>  mm/page_alloc.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 77e4d3c5c57b..25e81844d1aa 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -7582,11 +7582,18 @@ int alloc_contig_range(unsigned long start, unsigned long end,
>  
>  	/*
>  	 * In case of -EBUSY, we'd like to know which page causes problem.
> -	 * So, just fall through. We will check it in test_pages_isolated().
> +	 * So, just fall through. test_pages_isolated() has a tracepoint
> +	 * which will report the busy page.
> +	 *
> +	 * It is possible that busy pages could become available before
> +	 * the call to test_pages_isolated, and the range will actually be
> +	 * allocated.  So, if we fall through be sure to clear ret so that
> +	 * -EBUSY is not accidentally used or returned to caller.
>  	 */
>  	ret = __alloc_contig_migrate_range(&cc, start, end);
>  	if (ret && ret != -EBUSY)
>  		goto done;
> +	ret =0;
>  
>  	/*
>  	 * Pages from [start, end) are within a MAX_ORDER_NR_PAGES
> -- 
> 2.13.6
> 

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v2] mm/cma: fix alloc_contig_range ret code/potential leak
@ 2017-11-23  9:19           ` Michal Hocko
  0 siblings, 0 replies; 27+ messages in thread
From: Michal Hocko @ 2017-11-23  9:19 UTC (permalink / raw)
  To: Mike Kravetz
  Cc: linux-mm, linux-kernel, Joonsoo Kim, Vlastimil Babka,
	Michal Nazarewicz, Mel Gorman, Johannes Weiner, Andrew Morton,
	stable

On Wed 22-11-17 10:52:14, Mike Kravetz wrote:
> If the call __alloc_contig_migrate_range() in alloc_contig_range
> returns -EBUSY, processing continues so that test_pages_isolated()
> is called where there is a tracepoint to identify the busy pages.
> However, it is possible for busy pages to become available between
> the calls to these two routines.  In this case, the range of pages
> may be allocated.   Unfortunately, the original return code (ret
> == -EBUSY) is still set and returned to the caller.  Therefore,
> the caller believes the pages were not allocated and they are leaked.
> 
> Update comment to indicate that allocation is still possible even if
> __alloc_contig_migrate_range returns -EBUSY.  Also, clear return code
> in this case so that it is not accidentally used or returned to caller.
> 
> Fixes: 8ef5849fa8a2 ("mm/cma: always check which page caused allocation failure")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>

OK, this one looks reasonable as well.
Acked-by: Michal Hocko <mhocko@suse.com>

Thanks!

> ---
>  mm/page_alloc.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 77e4d3c5c57b..25e81844d1aa 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -7582,11 +7582,18 @@ int alloc_contig_range(unsigned long start, unsigned long end,
>  
>  	/*
>  	 * In case of -EBUSY, we'd like to know which page causes problem.
> -	 * So, just fall through. We will check it in test_pages_isolated().
> +	 * So, just fall through. test_pages_isolated() has a tracepoint
> +	 * which will report the busy page.
> +	 *
> +	 * It is possible that busy pages could become available before
> +	 * the call to test_pages_isolated, and the range will actually be
> +	 * allocated.  So, if we fall through be sure to clear ret so that
> +	 * -EBUSY is not accidentally used or returned to caller.
>  	 */
>  	ret = __alloc_contig_migrate_range(&cc, start, end);
>  	if (ret && ret != -EBUSY)
>  		goto done;
> +	ret =0;
>  
>  	/*
>  	 * Pages from [start, end) are within a MAX_ORDER_NR_PAGES
> -- 
> 2.13.6
> 

-- 
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v2] mm/cma: fix alloc_contig_range ret code/potential leak
  2017-11-22 18:52         ` Mike Kravetz
@ 2017-11-27 16:59           ` Johannes Weiner
  -1 siblings, 0 replies; 27+ messages in thread
From: Johannes Weiner @ 2017-11-27 16:59 UTC (permalink / raw)
  To: Mike Kravetz
  Cc: linux-mm, linux-kernel, Joonsoo Kim, Vlastimil Babka,
	Michal Nazarewicz, Michal Hocko, Mel Gorman, Andrew Morton,
	stable

On Wed, Nov 22, 2017 at 10:52:14AM -0800, Mike Kravetz wrote:
> If the call __alloc_contig_migrate_range() in alloc_contig_range
> returns -EBUSY, processing continues so that test_pages_isolated()
> is called where there is a tracepoint to identify the busy pages.
> However, it is possible for busy pages to become available between
> the calls to these two routines.  In this case, the range of pages
> may be allocated.   Unfortunately, the original return code (ret
> == -EBUSY) is still set and returned to the caller.  Therefore,
> the caller believes the pages were not allocated and they are leaked.
> 
> Update comment to indicate that allocation is still possible even if
> __alloc_contig_migrate_range returns -EBUSY.  Also, clear return code
> in this case so that it is not accidentally used or returned to caller.
> 
> Fixes: 8ef5849fa8a2 ("mm/cma: always check which page caused allocation failure")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>

Acked-by: Johannes Weiner <hannes@cmpxchg.org>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v2] mm/cma: fix alloc_contig_range ret code/potential leak
@ 2017-11-27 16:59           ` Johannes Weiner
  0 siblings, 0 replies; 27+ messages in thread
From: Johannes Weiner @ 2017-11-27 16:59 UTC (permalink / raw)
  To: Mike Kravetz
  Cc: linux-mm, linux-kernel, Joonsoo Kim, Vlastimil Babka,
	Michal Nazarewicz, Michal Hocko, Mel Gorman, Andrew Morton,
	stable

On Wed, Nov 22, 2017 at 10:52:14AM -0800, Mike Kravetz wrote:
> If the call __alloc_contig_migrate_range() in alloc_contig_range
> returns -EBUSY, processing continues so that test_pages_isolated()
> is called where there is a tracepoint to identify the busy pages.
> However, it is possible for busy pages to become available between
> the calls to these two routines.  In this case, the range of pages
> may be allocated.   Unfortunately, the original return code (ret
> == -EBUSY) is still set and returned to the caller.  Therefore,
> the caller believes the pages were not allocated and they are leaked.
> 
> Update comment to indicate that allocation is still possible even if
> __alloc_contig_migrate_range returns -EBUSY.  Also, clear return code
> in this case so that it is not accidentally used or returned to caller.
> 
> Fixes: 8ef5849fa8a2 ("mm/cma: always check which page caused allocation failure")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>

Acked-by: Johannes Weiner <hannes@cmpxchg.org>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v2] mm/cma: fix alloc_contig_range ret code/potential leak
  2017-11-22 18:52         ` Mike Kravetz
@ 2017-11-29  5:38           ` Joonsoo Kim
  -1 siblings, 0 replies; 27+ messages in thread
From: Joonsoo Kim @ 2017-11-29  5:38 UTC (permalink / raw)
  To: Mike Kravetz
  Cc: linux-mm, linux-kernel, Vlastimil Babka, Michal Nazarewicz,
	Michal Hocko, Mel Gorman, Johannes Weiner, Andrew Morton, stable

On Wed, Nov 22, 2017 at 10:52:14AM -0800, Mike Kravetz wrote:
> If the call __alloc_contig_migrate_range() in alloc_contig_range
> returns -EBUSY, processing continues so that test_pages_isolated()
> is called where there is a tracepoint to identify the busy pages.
> However, it is possible for busy pages to become available between
> the calls to these two routines.  In this case, the range of pages
> may be allocated.   Unfortunately, the original return code (ret
> == -EBUSY) is still set and returned to the caller.  Therefore,
> the caller believes the pages were not allocated and they are leaked.
> 
> Update comment to indicate that allocation is still possible even if
> __alloc_contig_migrate_range returns -EBUSY.  Also, clear return code
> in this case so that it is not accidentally used or returned to caller.
> 
> Fixes: 8ef5849fa8a2 ("mm/cma: always check which page caused allocation failure")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>

Good catch!!

Acked-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>

Thanks.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH v2] mm/cma: fix alloc_contig_range ret code/potential leak
@ 2017-11-29  5:38           ` Joonsoo Kim
  0 siblings, 0 replies; 27+ messages in thread
From: Joonsoo Kim @ 2017-11-29  5:38 UTC (permalink / raw)
  To: Mike Kravetz
  Cc: linux-mm, linux-kernel, Vlastimil Babka, Michal Nazarewicz,
	Michal Hocko, Mel Gorman, Johannes Weiner, Andrew Morton, stable

On Wed, Nov 22, 2017 at 10:52:14AM -0800, Mike Kravetz wrote:
> If the call __alloc_contig_migrate_range() in alloc_contig_range
> returns -EBUSY, processing continues so that test_pages_isolated()
> is called where there is a tracepoint to identify the busy pages.
> However, it is possible for busy pages to become available between
> the calls to these two routines.  In this case, the range of pages
> may be allocated.   Unfortunately, the original return code (ret
> == -EBUSY) is still set and returned to the caller.  Therefore,
> the caller believes the pages were not allocated and they are leaked.
> 
> Update comment to indicate that allocation is still possible even if
> __alloc_contig_migrate_range returns -EBUSY.  Also, clear return code
> in this case so that it is not accidentally used or returned to caller.
> 
> Fixes: 8ef5849fa8a2 ("mm/cma: always check which page caused allocation failure")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>

Good catch!!

Acked-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>

Thanks.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2017-11-29  5:38 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-20 19:39 [PATCH 0/1] mm/cma: fix alloc_contig_range ret code/potential leak Mike Kravetz
2017-11-20 19:39 ` Mike Kravetz
2017-11-20 19:39 ` [PATCH 1/1] " Mike Kravetz
2017-11-20 19:39   ` Mike Kravetz
2017-11-21  7:53   ` Vlastimil Babka
2017-11-21  7:53     ` Vlastimil Babka
2017-11-21 13:06     ` Michal Hocko
2017-11-21 13:06       ` Michal Hocko
2017-11-21 13:04   ` Michal Hocko
2017-11-21 13:04     ` Michal Hocko
2017-11-21 14:20   ` Michal Nazarewicz
2017-11-21 14:20     ` Michal Nazarewicz
2017-11-21 14:20     ` Michal Nazarewicz
2017-11-22 12:00   ` Johannes Weiner
2017-11-22 12:00     ` Johannes Weiner
2017-11-22 17:46     ` Mike Kravetz
2017-11-22 17:46       ` Mike Kravetz
2017-11-22 18:52       ` [PATCH v2] " Mike Kravetz
2017-11-22 18:52         ` Mike Kravetz
2017-11-23  8:05         ` Vlastimil Babka
2017-11-23  8:05           ` Vlastimil Babka
2017-11-23  9:19         ` Michal Hocko
2017-11-23  9:19           ` Michal Hocko
2017-11-27 16:59         ` Johannes Weiner
2017-11-27 16:59           ` Johannes Weiner
2017-11-29  5:38         ` Joonsoo Kim
2017-11-29  5:38           ` Joonsoo Kim

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.