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; }
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);
goto done; }ret = -EBUSY;
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.
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);
goto done; }ret = -EBUSY;
2.13.6
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);
goto done; }ret = -EBUSY;
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);
goto done;ret = -EBUSY;
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.
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);
goto done;ret = -EBUSY;
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.
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
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
*/ ret = __alloc_contig_migrate_range(&cc, start, end); if (ret && ret != -EBUSY) goto done;* -EBUSY is not accidentally used or returned to caller.
- ret =0;
^ missing space
/* * Pages from [start, end) are within a MAX_ORDER_NR_PAGES
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
*/ ret = __alloc_contig_migrate_range(&cc, start, end); if (ret && ret != -EBUSY) goto done;* -EBUSY is not accidentally used or returned to caller.
- ret =0;
/* * Pages from [start, end) are within a MAX_ORDER_NR_PAGES -- 2.13.6
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
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.
linux-stable-mirror@lists.linaro.org