Commit 9289f020 authored by Steve Sistare's avatar Steve Sistare Committed by Andrew Morton

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/1725373521-451395-5-git-send-email-steven.sistare@oracle.com
Fixes: 89c1905d ("mm/gup: introduce memfd_pin_folios() for pinning memfd folios")
Signed-off-by: default avatarSteve Sistare <steven.sistare@oracle.com>
Acked-by: default avatarVivek Kasireddy <vivek.kasireddy@intel.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Peter Xu <peterx@redhat.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 26a8ea80
...@@ -79,10 +79,13 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx) ...@@ -79,10 +79,13 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx)
* alloc from. Also, the folio will be pinned for an indefinite * alloc from. Also, the folio will be pinned for an indefinite
* amount of time, so it is not expected to be migrated away. * amount of time, so it is not expected to be migrated away.
*/ */
gfp_mask = htlb_alloc_mask(hstate_file(memfd)); struct hstate *h = hstate_file(memfd);
gfp_mask = htlb_alloc_mask(h);
gfp_mask &= ~(__GFP_HIGHMEM | __GFP_MOVABLE); gfp_mask &= ~(__GFP_HIGHMEM | __GFP_MOVABLE);
idx >>= huge_page_order(h);
folio = alloc_hugetlb_folio_reserve(hstate_file(memfd), folio = alloc_hugetlb_folio_reserve(h,
numa_node_id(), numa_node_id(),
NULL, NULL,
gfp_mask); gfp_mask);
...@@ -95,6 +98,7 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx) ...@@ -95,6 +98,7 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx)
free_huge_folio(folio); free_huge_folio(folio);
return ERR_PTR(err); return ERR_PTR(err);
} }
folio_unlock(folio);
return folio; return folio;
} }
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment