From: Karl Mehltretter <kmehltretter@gmail.com>
To: Ackerley Tng <ackerleytng@google.com>
Cc: Karl Mehltretter <kmehltretter@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Joshua Hahn <joshua.hahnjy@gmail.com>,
Muchun Song <muchun.song@linux.dev>,
Oscar Salvador <osalvador@suse.de>, Peter Xu <peterx@redhat.com>,
Zhao Li <enderaoelyther@gmail.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v3 3/4] mm: hugetlb: Fix subpool usage leak on allocation failure
Date: Sun, 27 Sep 2026 19:04:26 +0200 [thread overview]
Message-ID: <20260927170426.2467-1-kmehltretter@gmail.com> (raw)
In-Reply-To: <20260916-hugetlb-subpool-always-track-used-v3-3-38aae9b5ccdd@google.com>
On Wed, 16 Sep 2026 16:39:03 -0700, Ackerley Tng wrote:
> out_subpool_put:
> + if (map_chg) {
> + long gbl_resv_put = hugepage_subpool_put_pages(spool, 1);
> +
> + hugetlb_acct_memory(h, gbl_resv_get - gbl_resv_put);
> }
I reproduced the same fallible-positive-adjustment problem in this
calculation.
The complete subpool put is locally correct, but it can expose capacity
which another operation consumes before this call tries to restore the
corresponding global reservation. A positive hugetlb_acct_memory() can
then fail with -ENOMEM, and its return value is ignored.
I tested the exact patch prefixes on v7.3-rc3 in x86-64 QEMU with 2 MiB
huge pages, at both one and four vCPUs. A default-off test hook enforced
this ordering:
1. A shared MAP_NORESERVE fault acquires one page from a four-page
minimum subpool while the global pool has no spare capacity.
2. Folio allocation fails.
3. Before rollback, an existing reservation is released and a competing
reservation consumes that newly available capacity.
4. The subpool put restores the local minimum state, but its required +1
global correction fails with -ENOMEM.
Both CPU counts produced the same result:
Source state Cleanup result After file removal / after unmount
------------ -------------- ---------------------------------
v7.3-rc3 old cleanup 4 / 0
patches 1-2 old local leak 3 / 3
patches 1-3 +1, -ENOMEM 3 / ULONG_MAX
patches 1-4 +1, -ENOMEM 3 / ULONG_MAX
The expected values are 4 after file removal and 0 after unmount. Patch 3
removes the local usage leak, but the failed positive correction replaces
it with globally unbacked subpool reservations and the unmount underflow.
Patch 4 does not cover this earlier allocation-failure path.
As in the reservation case, the base remains balanced in this controlled
interleaving. Patch 1 makes the path observable on the minimum-only mount,
and patch 3 changes the local leak into globally unbacked reservations.
As for 2/4, I think the subpool get must remain provisional until the
allocation commits or aborts.
A LLM agent helped me with the tests.
Thanks,
Karl
next prev parent reply other threads:[~2026-09-27 17:04 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-16 23:39 [PATCH v3 0/4] Fix HugeTLB subpool used_hpages tracking Ackerley Tng via B4 Relay
2026-09-16 23:39 ` [PATCH v3 1/4] mm: hugetlb: Track used_hpages when getting/putting pages from subpool Ackerley Tng via B4 Relay
2026-09-16 23:39 ` [PATCH v3 2/4] mm: hugetlb: Fix out_put_pages subpool reserve calculation Ackerley Tng via B4 Relay
2026-09-27 17:01 ` Karl Mehltretter
2026-09-16 23:39 ` [PATCH v3 3/4] mm: hugetlb: Fix subpool usage leak on allocation failure Ackerley Tng via B4 Relay
2026-09-27 17:04 ` Karl Mehltretter [this message]
2026-09-28 5:19 ` Ackerley Tng
2026-09-28 6:28 ` Karl Mehltretter
2026-09-16 23:39 ` [PATCH v3 4/4] mm: hugetlb: Avoid re-allocating global reservations on region add failure Ackerley Tng via B4 Relay
2026-09-17 19:26 ` Joshua Hahn
2026-09-18 3:13 ` Ackerley Tng
2026-09-17 3:13 ` [PATCH v3 0/4] Fix HugeTLB subpool used_hpages tracking Andrew Morton
2026-09-17 19:29 ` Joshua Hahn
2026-09-18 3:05 ` Ackerley Tng
2026-09-18 3:53 ` Andrew Morton
2026-09-18 3:21 ` Ackerley Tng
2026-09-23 22:09 ` Karl Mehltretter
2026-09-24 0:27 ` Ackerley Tng
2026-09-26 22:42 ` Ackerley Tng
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=20260927170426.2467-1-kmehltretter@gmail.com \
--to=kmehltretter@gmail.com \
--cc=ackerleytng@google.com \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=enderaoelyther@gmail.com \
--cc=joshua.hahnjy@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=osalvador@suse.de \
--cc=peterx@redhat.com \
--cc=stable@vger.kernel.org \
/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®