The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* Re: [PATCH] mm/hugetlb: fix resv_huge_pages double decrement in memfd error path
       [not found] <20260825021013.25672-1-hongfu.li@linux.dev>
@ 2026-08-25  5:42 ` Muchun Song
  0 siblings, 0 replies; only message in thread
From: Muchun Song @ 2026-08-25  5:42 UTC (permalink / raw)
  To: Hongfu Li
  Cc: osalvador, david, akpm, steven.sistare, vivek.kasireddy, linux-mm,
	linux-kernel, Hongfu Li



> On Aug 25, 2026, at 10:10, Hongfu Li <hongfu.li@linux.dev> wrote:
> 
> From: Hongfu Li <lihongfu@kylinos.cn>
> 
> alloc_hugetlb_folio_reserve() decrements h->resv_huge_pages when
> dequeuing a folio, but unlike the use_global_reservation handling in
> hugetlb_alloc_folio(), it does not set HPageRestoreReserve on the folio.
> 
> Its sole caller memfd_alloc_folio() pre-allocates a reservation via
> hugetlb_reserve_pages() before allocating. When hugetlb_add_to_page_cache()
> fails, folio_put() drops the folio without HPageRestoreReserve set, so
> free_huge_folio() does not restore the reservation. The subsequent
> hugetlb_unreserve_pages() on the err_unresv path decrements the counter
> a second time, leaving resv_huge_pages off by one for every failed
> allocation.
> 
> Set HPageRestoreReserve when consuming the reservation in
> alloc_hugetlb_folio_reserve(). On the error path, free_huge_folio() then
> restores the reservation before hugetlb_unreserve_pages() releases it.
> The success path is unaffected, as hugetlb_add_to_page_cache() clears
> the flag once the folio is added to the page cache.
> 
> Fixes: 26a8ea80929c ("mm/hugetlb: fix memfd_pin_folios resv_huge_pages leak")
> Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>

Reviewed-by: Muchun Song <muchun.song@linux.dev>

Thanks.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-08-25  5:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20260825021013.25672-1-hongfu.li@linux.dev>
2026-08-25  5:42 ` [PATCH] mm/hugetlb: fix resv_huge_pages double decrement in memfd error path Muchun Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox