linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hugetlb: Fix __prep_compound_gigantic_page page flag setting
@ 2022-11-18 19:52 Mike Kravetz
  2022-11-19  2:05 ` Miaohe Lin
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Mike Kravetz @ 2022-11-18 19:52 UTC (permalink / raw)
  To: linux-mm, linux-kernel, Andrew Morton
  Cc: Muchun Song, Joao Martins, Matthew Wilcox, Michal Hocko,
	Peter Xu, Miaohe Lin, Oscar Salvador, Naoya Horiguchi,
	Vlastimil Babka, Sidhartha Kumar, Mike Kravetz,
	Aneesh Kumar K . V

Commit 2b21624fc232 ("hugetlb: freeze allocated pages before creating
hugetlb pages") changed the order page flags were cleared and set in the
head page.  It moved the __ClearPageReserved after __SetPageHead.
However, there is a check to make sure __ClearPageReserved is never
done on a head page.  If CONFIG_DEBUG_VM_PGFLAGS is enabled, the
following BUG will be hit when creating a hugetlb gigantic page:

    page dumped because: VM_BUG_ON_PAGE(1 && PageCompound(page))
    ------------[ cut here ]------------
    kernel BUG at include/linux/page-flags.h:500!
    Call Trace will differ depending on whether hugetlb page is created
    at boot time or run time.

Make sure to __ClearPageReserved BEFORE __SetPageHead.

Reported-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Fixes: 2b21624fc232 ("hugetlb: freeze allocated pages before creating hugetlb pages")
Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
---
 mm/hugetlb.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index e48f8ef45b17..f1385c3b6c96 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1800,6 +1800,7 @@ static bool __prep_compound_gigantic_page(struct page *page, unsigned int order,
 
 	/* we rely on prep_new_huge_page to set the destructor */
 	set_compound_order(page, order);
+	__ClearPageReserved(page);
 	__SetPageHead(page);
 	for (i = 0; i < nr_pages; i++) {
 		p = nth_page(page, i);
@@ -1816,7 +1817,8 @@ static bool __prep_compound_gigantic_page(struct page *page, unsigned int order,
 		 * on the head page when they need know if put_page() is needed
 		 * after get_user_pages().
 		 */
-		__ClearPageReserved(p);
+		if (i != 0)	/* head page cleared above */
+			__ClearPageReserved(p);
 		/*
 		 * Subtle and very unlikely
 		 *
-- 
2.38.1


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

* Re: [PATCH] hugetlb: Fix __prep_compound_gigantic_page page flag setting
  2022-11-18 19:52 [PATCH] hugetlb: Fix __prep_compound_gigantic_page page flag setting Mike Kravetz
@ 2022-11-19  2:05 ` Miaohe Lin
  2022-11-19 14:44 ` Tarun Sahu
  2022-11-20  4:03 ` Muchun Song
  2 siblings, 0 replies; 4+ messages in thread
From: Miaohe Lin @ 2022-11-19  2:05 UTC (permalink / raw)
  To: Mike Kravetz, linux-mm, linux-kernel
  Cc: Muchun Song, Joao Martins, Matthew Wilcox, Michal Hocko,
	Peter Xu, Oscar Salvador, Naoya Horiguchi, Vlastimil Babka,
	Sidhartha Kumar, Aneesh Kumar K . V, Andrew Morton

On 2022/11/19 3:52, Mike Kravetz wrote:
> Commit 2b21624fc232 ("hugetlb: freeze allocated pages before creating
> hugetlb pages") changed the order page flags were cleared and set in the
> head page.  It moved the __ClearPageReserved after __SetPageHead.
> However, there is a check to make sure __ClearPageReserved is never
> done on a head page.  If CONFIG_DEBUG_VM_PGFLAGS is enabled, the
> following BUG will be hit when creating a hugetlb gigantic page:
> 
>     page dumped because: VM_BUG_ON_PAGE(1 && PageCompound(page))
>     ------------[ cut here ]------------
>     kernel BUG at include/linux/page-flags.h:500!
>     Call Trace will differ depending on whether hugetlb page is created
>     at boot time or run time.
> 
> Make sure to __ClearPageReserved BEFORE __SetPageHead.
> 
> Reported-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
> Fixes: 2b21624fc232 ("hugetlb: freeze allocated pages before creating hugetlb pages")
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>

Yes, PG_reserved is PF_NO_COMPOUND policy. Thanks for fixing this.

Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>

Thanks,
Miaohe Lin


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

* Re: [PATCH] hugetlb: Fix __prep_compound_gigantic_page page flag setting
  2022-11-18 19:52 [PATCH] hugetlb: Fix __prep_compound_gigantic_page page flag setting Mike Kravetz
  2022-11-19  2:05 ` Miaohe Lin
@ 2022-11-19 14:44 ` Tarun Sahu
  2022-11-20  4:03 ` Muchun Song
  2 siblings, 0 replies; 4+ messages in thread
From: Tarun Sahu @ 2022-11-19 14:44 UTC (permalink / raw)
  To: Mike Kravetz
  Cc: linux-mm, linux-kernel, Andrew Morton, Muchun Song, Joao Martins,
	Matthew Wilcox, Michal Hocko, Peter Xu, Miaohe Lin,
	Oscar Salvador, Naoya Horiguchi, Vlastimil Babka,
	Sidhartha Kumar, Aneesh Kumar K . V

Hi,

Tested it on top of v6.1.0-rc5
with 1G Hugepages on PPC64le radix MMU.

Tested-by: Tarun Sahu <tsahu@linux.ibm.com>


~Tarun

On Nov 18 2022, Mike Kravetz wrote:
> Commit 2b21624fc232 ("hugetlb: freeze allocated pages before creating
> hugetlb pages") changed the order page flags were cleared and set in the
> head page.  It moved the __ClearPageReserved after __SetPageHead.
> However, there is a check to make sure __ClearPageReserved is never
> done on a head page.  If CONFIG_DEBUG_VM_PGFLAGS is enabled, the
> following BUG will be hit when creating a hugetlb gigantic page:
> 
>     page dumped because: VM_BUG_ON_PAGE(1 && PageCompound(page))
>     ------------[ cut here ]------------
>     kernel BUG at include/linux/page-flags.h:500!
>     Call Trace will differ depending on whether hugetlb page is created
>     at boot time or run time.
> 
> Make sure to __ClearPageReserved BEFORE __SetPageHead.
> 
> Reported-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
> Fixes: 2b21624fc232 ("hugetlb: freeze allocated pages before creating hugetlb pages")
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
> ---
>  mm/hugetlb.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index e48f8ef45b17..f1385c3b6c96 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -1800,6 +1800,7 @@ static bool __prep_compound_gigantic_page(struct page *page, unsigned int order,
>  
>  	/* we rely on prep_new_huge_page to set the destructor */
>  	set_compound_order(page, order);
> +	__ClearPageReserved(page);
>  	__SetPageHead(page);
>  	for (i = 0; i < nr_pages; i++) {
>  		p = nth_page(page, i);
> @@ -1816,7 +1817,8 @@ static bool __prep_compound_gigantic_page(struct page *page, unsigned int order,
>  		 * on the head page when they need know if put_page() is needed
>  		 * after get_user_pages().
>  		 */
> -		__ClearPageReserved(p);
> +		if (i != 0)	/* head page cleared above */
> +			__ClearPageReserved(p);
>  		/*
>  		 * Subtle and very unlikely
>  		 *
> -- 
> 2.38.1
> 

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

* Re: [PATCH] hugetlb: Fix __prep_compound_gigantic_page page flag setting
  2022-11-18 19:52 [PATCH] hugetlb: Fix __prep_compound_gigantic_page page flag setting Mike Kravetz
  2022-11-19  2:05 ` Miaohe Lin
  2022-11-19 14:44 ` Tarun Sahu
@ 2022-11-20  4:03 ` Muchun Song
  2 siblings, 0 replies; 4+ messages in thread
From: Muchun Song @ 2022-11-20  4:03 UTC (permalink / raw)
  To: Mike Kravetz
  Cc: Linux Memory Management List, linux-kernel, Andrew Morton,
	Muchun Song, Joao Martins, Matthew Wilcox, Michal Hocko,
	Peter Xu, Miaohe Lin, Oscar Salvador, Naoya Horiguchi,
	Vlastimil Babka, Sidhartha Kumar, Aneesh Kumar K . V



> On Nov 19, 2022, at 03:52, Mike Kravetz <mike.kravetz@oracle.com> wrote:
> 
> Commit 2b21624fc232 ("hugetlb: freeze allocated pages before creating
> hugetlb pages") changed the order page flags were cleared and set in the
> head page.  It moved the __ClearPageReserved after __SetPageHead.
> However, there is a check to make sure __ClearPageReserved is never
> done on a head page.  If CONFIG_DEBUG_VM_PGFLAGS is enabled, the
> following BUG will be hit when creating a hugetlb gigantic page:
> 
>    page dumped because: VM_BUG_ON_PAGE(1 && PageCompound(page))
>    ------------[ cut here ]------------
>    kernel BUG at include/linux/page-flags.h:500!
>    Call Trace will differ depending on whether hugetlb page is created
>    at boot time or run time.
> 
> Make sure to __ClearPageReserved BEFORE __SetPageHead.
> 
> Reported-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
> Fixes: 2b21624fc232 ("hugetlb: freeze allocated pages before creating hugetlb pages")
> Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>

Acked-by: Muchun Song <songmuchun@bytedance.com>

Thanks.


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

end of thread, other threads:[~2022-11-20  4:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-18 19:52 [PATCH] hugetlb: Fix __prep_compound_gigantic_page page flag setting Mike Kravetz
2022-11-19  2:05 ` Miaohe Lin
2022-11-19 14:44 ` Tarun Sahu
2022-11-20  4:03 ` Muchun Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).