From: Andrew Morton <akpm@linux-foundation.org>
To: Hongfu Li <hongfu.li@linux.dev>
Cc: hughd@google.com, baolin.wang@linux.alibaba.com,
vivek.kasireddy@intel.com, muchun.song@linux.dev,
osalvador@suse.de, david@kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, Hongfu Li <lihongfu@kylinos.cn>
Subject: Re: [PATCH v2] mm/memfd: fix hugetlb reservation accounting in error paths
Date: Thu, 3 Sep 2026 13:21:58 -0700 [thread overview]
Message-ID: <20260903132158.a2d6f965477220838d884bae@linux-foundation.org> (raw)
In-Reply-To: <20260903030134.7407-1-hongfu.li@linux.dev>
On Thu, 3 Sep 2026 11:01:34 +0800 Hongfu Li <hongfu.li@linux.dev> wrote:
> From: Hongfu Li <lihongfu@kylinos.cn>
>
> If hugetlb_add_to_page_cache() in memfd_alloc_folio() fails with
> -EEXIST, a concurrent fault has already instantiated the folio in the
> page cache, and the reservation now belongs to that folio. Calling
> hugetlb_unreserve_pages() in that case incorrectly removes the region
> backing the cached folio. A later truncate or inode eviction then passes
> a negative (chg - freed) into hugepage_subpool_put_pages(), corrupting
> subpool and resv_huge_pages accounting.
Ho hum.
I've asked so many times "what are the userspace-visible runtime
effects of this bug". Nowadays I often just ask Gemini instead. It
told me:
Over time, these corrupted counters would leak huge page reservations.
Applications using hugetlb memfds would eventually find themselves
unable to allocate huge pages, receiving unexpected ENOMEM errors even
though system memory and pool capacities appeared free and healthy.
and
The corrupted accounting caused hugepage_subpool_put_pages() to
receive a negative value during a later file truncation or inode
eviction.
While this typically manifests as kernel logs (WARN traces or
badness flags regarding subpool page counts), it could cause
misbehaved resource tracking that impacts subsequent system
operations, unmounts, or process teardowns interacting with that
hugetlb file descriptor.
All of which sounds rather unpleasant, so I suggest a cc:stable here.
To help people understand why we propose a backport and to help others
understand the impact the fix will have upon their system, I'll paste
the above into the changelog. Please send any necessary corrections.
Please also update your prompts (if using them) to ensure that the
changelogging includes this info in the future.
I'll queue it for testing and shall await maintainer review.
prev parent reply other threads:[~2026-09-03 20:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 3:01 [PATCH v2] mm/memfd: fix hugetlb reservation accounting in error paths Hongfu Li
2026-09-03 20:21 ` Andrew Morton [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260903132158.a2d6f965477220838d884bae@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@kernel.org \
--cc=hongfu.li@linux.dev \
--cc=hughd@google.com \
--cc=lihongfu@kylinos.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=osalvador@suse.de \
--cc=vivek.kasireddy@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox