From: Hongfu Li memfd_alloc_folio() derives its allocation mask from htlb_alloc_mask() and then clears __GFP_HIGHMEM and __GFP_MOVABLE. This mask handling was introduced by commit 89c1905d9c14 ("mm/gup: introduce memfd_pin_folios() for pinning memfd folios"), when the fallback path in alloc_hugetlb_folio_nodemask() could still call alloc_migrate_hugetlb_folio() and reach the buddy allocator, so the mask decided the zone and migratetype of freshly allocated pages. Since commit 26a8ea80929c ("mm/hugetlb: fix memfd_pin_folios resv_huge_pages leak"), this call site uses alloc_hugetlb_folio_reserve(), which only dequeues folios from the existing hugetlb pool and never falls back to the buddy allocator. The mask therefore no longer decides where any page comes from. Long-term pinning safety no longer depends on the mask either: memfd_pin_folios() obtains its folios (dequeued from the pool, or freshly allocated) under memalloc_pin_save(), so PF_MEMALLOC_PIN makes dequeue_hugetlb_folio_node_exact() skip any folio that fails folio_is_longterm_pinnable(), and current_gfp_context() already clears __GFP_MOVABLE from any page allocator request made under PF_MEMALLOC_PIN. Drop the narrowing, which has had no effect since 26a8ea80929c. Signed-off-by: Hongfu Li --- mm/memfd.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mm/memfd.c b/mm/memfd.c index 0e3ff3eebfa8..8905e3e9efc8 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -85,7 +85,6 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx) u32 hash; gfp_mask = htlb_alloc_mask(h); - gfp_mask &= ~(__GFP_HIGHMEM | __GFP_MOVABLE); idx >>= huge_page_order(h); /* -- 2.54.0 From: Hongfu Li alloc_hugetlb_folio_reserve() takes a gfp_mask argument that memfd_alloc_folio() always sets to exactly htlb_alloc_mask(h), which the helper can derive by itself. Derive the mask inside alloc_hugetlb_folio_reserve() as alloc_hugetlb_folio() does, and drop the argument. No functional change intended. Signed-off-by: Hongfu Li --- include/linux/hugetlb.h | 4 ++-- mm/hugetlb.c | 3 ++- mm/memfd.c | 13 +------------ 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 69732e4cc03e..a88c59476e79 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -735,7 +735,7 @@ struct folio *alloc_hugetlb_folio_nodemask(struct hstate *h, int preferred_nid, nodemask_t *nmask, gfp_t gfp_mask, bool allow_alloc_fallback); struct folio *alloc_hugetlb_folio_reserve(struct hstate *h, int preferred_nid, - nodemask_t *nmask, gfp_t gfp_mask); + nodemask_t *nmask); int hugetlb_add_to_page_cache(struct folio *folio, struct address_space *mapping, pgoff_t idx); @@ -1161,7 +1161,7 @@ static inline struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, static inline struct folio * alloc_hugetlb_folio_reserve(struct hstate *h, int preferred_nid, - nodemask_t *nmask, gfp_t gfp_mask) + nodemask_t *nmask) { return NULL; } diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 88c9aa700533..e84203406da3 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2221,8 +2221,9 @@ struct folio *alloc_buddy_hugetlb_folio(struct hstate *h, } struct folio *alloc_hugetlb_folio_reserve(struct hstate *h, int preferred_nid, - nodemask_t *nmask, gfp_t gfp_mask) + nodemask_t *nmask) { + gfp_t gfp_mask = htlb_alloc_mask(h); struct hugetlb_cgroup *h_cg = NULL; size_t nr_pages = pages_per_huge_page(h); struct folio *folio; diff --git a/mm/memfd.c b/mm/memfd.c index 8905e3e9efc8..08b9d54b0d8a 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -69,22 +69,14 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx) { #ifdef CONFIG_HUGETLB_PAGE struct folio *folio; - gfp_t gfp_mask; if (is_file_hugepages(memfd)) { - /* - * The folio would most likely be accessed by a DMA driver, - * therefore, we have zone memory constraints where we can - * alloc from. Also, the folio will be pinned for an indefinite - * amount of time, so it is not expected to be migrated away. - */ struct inode *inode = file_inode(memfd); struct hstate *h = hstate_file(memfd); int err = -ENOMEM; long nr_resv; u32 hash; - gfp_mask = htlb_alloc_mask(h); idx >>= huge_page_order(h); /* @@ -101,10 +93,7 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx) goto out_unlock; } - folio = alloc_hugetlb_folio_reserve(h, - numa_node_id(), - NULL, - gfp_mask); + folio = alloc_hugetlb_folio_reserve(h, numa_node_id(), NULL); if (folio) { /* * Zero the folio to prevent information leaks to userspace. -- 2.54.0