Skip to content

Commit 7fb0728

Browse files
mjkravetzakpm00
authored andcommitted
hugetlb: fix __prep_compound_gigantic_page page flag setting
Commit 2b21624 ("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. Link: https://lkml.kernel.org/r/20221118195249.178319-1-mike.kravetz@oracle.com Fixes: 2b21624 ("hugetlb: freeze allocated pages before creating hugetlb pages") Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com> Reported-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> Acked-by: Muchun Song <songmuchun@bytedance.com> Tested-by: Tarun Sahu <tsahu@linux.ibm.com> Reviewed-by: Miaohe Lin <linmiaohe@huawei.com> Cc: Joao Martins <joao.m.martins@oracle.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Naoya Horiguchi <naoya.horiguchi@nec.com> Cc: Oscar Salvador <osalvador@suse.de> Cc: Peter Xu <peterx@redhat.com> Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 747c0f3 commit 7fb0728

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

mm/hugetlb.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,7 @@ static bool __prep_compound_gigantic_page(struct page *page, unsigned int order,
18001800

18011801
/* we rely on prep_new_huge_page to set the destructor */
18021802
set_compound_order(page, order);
1803+
__ClearPageReserved(page);
18031804
__SetPageHead(page);
18041805
for (i = 0; i < nr_pages; i++) {
18051806
p = nth_page(page, i);
@@ -1816,7 +1817,8 @@ static bool __prep_compound_gigantic_page(struct page *page, unsigned int order,
18161817
* on the head page when they need know if put_page() is needed
18171818
* after get_user_pages().
18181819
*/
1819-
__ClearPageReserved(p);
1820+
if (i != 0) /* head page cleared above */
1821+
__ClearPageReserved(p);
18201822
/*
18211823
* Subtle and very unlikely
18221824
*

0 commit comments

Comments
 (0)