From: Hongfu Li <hongfu.li@linux.dev>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: hongfu.li@linux.dev, 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: Tue, 8 Sep 2026 09:35:23 +0800 [thread overview]
Message-ID: <638ae9ae-2cbc-47a4-85fd-52b67b74e351@linux.dev> (raw)
In-Reply-To: <20260903132158.a2d6f965477220838d884bae@linux-foundation.org>
On 9/4/26 4:21 AM, Andrew Morton wrote:
> 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.
Thanks for the detailed explanation.
I've updated the changelog to include the userspace-visible effects
and long-term impact as suggested.
Would you prefer that I send a v2 now, or should I wait for maintainer
feedback first?
--
Best regards,
Hongfu
next prev parent reply other threads:[~2026-09-08 1:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 3:01 Hongfu Li
2026-09-03 20:21 ` Andrew Morton
2026-09-08 1:35 ` Hongfu Li [this message]
2026-09-09 2:54 ` Andrew Morton
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=638ae9ae-2cbc-47a4-85fd-52b67b74e351@linux.dev \
--to=hongfu.li@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@kernel.org \
--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
all inboxes | Powered by JetHome®