Skip to content

Commit 9289f02

Browse files
Steve Sistareakpm00
authored andcommitted
mm/gup: fix memfd_pin_folios hugetlb page allocation
When memfd_pin_folios -> memfd_alloc_folio creates a hugetlb page, the index is wrong. The subsequent call to filemap_get_folios_contig thus cannot find it, and fails, and memfd_pin_folios loops forever. To fix, adjust the index for the huge_page_order. memfd_alloc_folio also forgets to unlock the folio, so the next touch of the page calls hugetlb_fault which blocks forever trying to take the lock. Unlock it. Link: https://lkml.kernel.org/r/[email protected] Fixes: 89c1905 ("mm/gup: introduce memfd_pin_folios() for pinning memfd folios") Signed-off-by: Steve Sistare <[email protected]> Acked-by: Vivek Kasireddy <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Jason Gunthorpe <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Muchun Song <[email protected]> Cc: Peter Xu <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 26a8ea8 commit 9289f02

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

mm/memfd.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,13 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx)
7979
* alloc from. Also, the folio will be pinned for an indefinite
8080
* amount of time, so it is not expected to be migrated away.
8181
*/
82-
gfp_mask = htlb_alloc_mask(hstate_file(memfd));
82+
struct hstate *h = hstate_file(memfd);
83+
84+
gfp_mask = htlb_alloc_mask(h);
8385
gfp_mask &= ~(__GFP_HIGHMEM | __GFP_MOVABLE);
86+
idx >>= huge_page_order(h);
8487

85-
folio = alloc_hugetlb_folio_reserve(hstate_file(memfd),
88+
folio = alloc_hugetlb_folio_reserve(h,
8689
numa_node_id(),
8790
NULL,
8891
gfp_mask);
@@ -95,6 +98,7 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx)
9598
free_huge_folio(folio);
9699
return ERR_PTR(err);
97100
}
101+
folio_unlock(folio);
98102
return folio;
99103
}
100104
return ERR_PTR(-ENOMEM);

0 commit comments

Comments
 (0)