linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [patch] mm, hugetlb: close race when setting PageTail for gigantic pages
@ 2015-02-25  0:16 David Rientjes
  2015-02-25  2:20 ` Davidlohr Bueso
  0 siblings, 1 reply; 3+ messages in thread
From: David Rientjes @ 2015-02-25  0:16 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Davidlohr Bueso, Luiz Capitulino, Joonsoo Kim, linux-kernel, linux-mm

Now that gigantic pages are dynamically allocatable, care must be taken
to ensure that p->first_page is valid before setting PageTail.

If this isn't done, then it is possible to race and have compound_head()
return NULL.

Signed-off-by: David Rientjes <rientjes@google.com>
---
 mm/hugetlb.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -917,7 +917,6 @@ static void prep_compound_gigantic_page(struct page *page, unsigned long order)
 	__SetPageHead(page);
 	__ClearPageReserved(page);
 	for (i = 1; i < nr_pages; i++, p = mem_map_next(p, page, i)) {
-		__SetPageTail(p);
 		/*
 		 * For gigantic hugepages allocated through bootmem at
 		 * boot, it's safer to be consistent with the not-gigantic
@@ -933,6 +932,9 @@ static void prep_compound_gigantic_page(struct page *page, unsigned long order)
 		__ClearPageReserved(p);
 		set_page_count(p, 0);
 		p->first_page = page;
+		/* Make sure p->first_page is always valid for PageTail() */
+		smp_wmb();
+		__SetPageTail(p);
 	}
 }
 

--
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] 3+ messages in thread

* Re: [patch] mm, hugetlb: close race when setting PageTail for gigantic pages
  2015-02-25  0:16 [patch] mm, hugetlb: close race when setting PageTail for gigantic pages David Rientjes
@ 2015-02-25  2:20 ` Davidlohr Bueso
  0 siblings, 0 replies; 3+ messages in thread
From: Davidlohr Bueso @ 2015-02-25  2:20 UTC (permalink / raw)
  To: David Rientjes
  Cc: Andrew Morton, Luiz Capitulino, Joonsoo Kim, linux-kernel, linux-mm

On Tue, 2015-02-24 at 16:16 -0800, David Rientjes wrote:
> Now that gigantic pages are dynamically allocatable, care must be taken
> to ensure that p->first_page is valid before setting PageTail.
> 
> If this isn't done, then it is possible to race and have compound_head()
> return NULL.
> 
> Signed-off-by: David Rientjes <rientjes@google.com>

Acked-by: Davidlohr Bueso <dave@stgolabs.net>


--
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] 3+ messages in thread

* Re: [patch] mm, hugetlb: close race when setting PageTail for gigantic pages
@ 2015-02-25  2:32 Hillf Danton
  0 siblings, 0 replies; 3+ messages in thread
From: Hillf Danton @ 2015-02-25  2:32 UTC (permalink / raw)
  To: 'David Rientjes'
  Cc: Andrew Morton, 'Davidlohr Bueso',
	'Luiz Capitulino', 'Joonsoo Kim',
	linux-kernel, linux-mm, Hillf Danton

> Now that gigantic pages are dynamically allocatable, care must be taken
> to ensure that p->first_page is valid before setting PageTail.
> 
> If this isn't done, then it is possible to race and have compound_head()
> return NULL.
> 
> Signed-off-by: David Rientjes <rientjes@google.com>
> ---
Acked-by: Hillf Danton <hillf.zj@alibaba-inc.com>

>  mm/hugetlb.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -917,7 +917,6 @@ static void prep_compound_gigantic_page(struct page *page, unsigned long order)
>  	__SetPageHead(page);
>  	__ClearPageReserved(page);
>  	for (i = 1; i < nr_pages; i++, p = mem_map_next(p, page, i)) {
> -		__SetPageTail(p);
>  		/*
>  		 * For gigantic hugepages allocated through bootmem at
>  		 * boot, it's safer to be consistent with the not-gigantic
> @@ -933,6 +932,9 @@ static void prep_compound_gigantic_page(struct page *page, unsigned long order)
>  		__ClearPageReserved(p);
>  		set_page_count(p, 0);
>  		p->first_page = page;
> +		/* Make sure p->first_page is always valid for PageTail() */
> +		smp_wmb();
> +		__SetPageTail(p);
>  	}
>  }
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/


--
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] 3+ messages in thread

end of thread, other threads:[~2015-02-25  2:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-25  0:16 [patch] mm, hugetlb: close race when setting PageTail for gigantic pages David Rientjes
2015-02-25  2:20 ` Davidlohr Bueso
2015-02-25  2:32 Hillf Danton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox