Re: [PATCH v2 6/6] mm: hugetlb: remove VM_BUG_ON_PAGE from page_huge_active

From: Mike Kravetz
Date: Fri Jan 08 2021 - 17:25:15 EST


On 1/6/21 12:47 AM, Muchun Song wrote:
> The page_huge_active() can be called from scan_movable_pages() which
> do not hold a reference count to the HugeTLB page. So when we call
> page_huge_active() from scan_movable_pages(), the HugeTLB page can
> be freed parallel. Then we will trigger a BUG_ON which is in the
> page_huge_active() when CONFIG_DEBUG_VM is enabled. Just remove the
> VM_BUG_ON_PAGE.
>
> Fixes: 7e1f049efb86 ("mm: hugetlb: cleanup using paeg_huge_active()")
> Signed-off-by: Muchun Song <songmuchun@xxxxxxxxxxxxx>
> Reviewed-by: Mike Kravetz <mike.kravetz@xxxxxxxxxx>
> ---
> mm/hugetlb.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 67200dd25b1d..7a24ed28ec4f 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -1372,7 +1372,6 @@ struct hstate *size_to_hstate(unsigned long size)
> */
> bool page_huge_active(struct page *page)
> {
> - VM_BUG_ON_PAGE(!PageHuge(page), page);
> return PageHead(page) && PagePrivate(&page[1]);
> }

After more thought, should that return statement be changed to?
return PageHeadHuge(page) && PagePrivate(&page[1]);

We only want to test that PagePrivate flag for hugetlb head pages.
Although, the possibility that the hugetlb page was freed and turned
into another compound page in this race window is REALLY small.
--
Mike Kravetz