From: sashiko-bot@kernel.org
To: "Nico Pache" <npache@redhat.com>
Cc: linux-cxl@vger.kernel.org
Subject: Re: [PATCH 1/2] mm: decrement MTHP_STAT_NR_ANON in free_zone_device_folio()
Date: Thu, 02 Jul 2026 17:41:10 +0000 [thread overview]
Message-ID: <20260702174111.46AB11F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260702172548.37075-2-npache@redhat.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] `free_zone_device_folio()` bypasses `folio_unqueue_deferred_split()`, causing list corruption on the deferred split LRU, leaking `MTHP_STAT_NR_ANON_PARTIALLY_MAPPED`, and triggering a `WARN_ON_ONCE`.
--
commit e9684c49325471cce57373674f8d1d1d76f029b6
Author: Nico Pache <npache@redhat.com>
mm: decrement MTHP_STAT_NR_ANON in free_zone_device_folio()
When a zone device folio is mapped as anonymous, folio_add_new_anon_rmap()
increments MTHP_STAT_NR_ANON. The corresponding decrement lives in
__free_pages_prepare() in page_alloc.c, but zone device folios are freed
via free_zone_device_folio() which never calls __free_pages_prepare().
> diff --git a/mm/memremap.c b/mm/memremap.c
> index 81766d8224009..accba23aef28c 100644
> --- a/mm/memremap.c
> +++ b/mm/memremap.c
> @@ -425,6 +425,7 @@ void free_zone_device_folio(struct folio *folio)
> if (WARN_ON_ONCE(!pgmap))
> return;
>
> mem_cgroup_uncharge(folio);
[Severity: High]
This is a pre-existing issue, but can bypassing
folio_unqueue_deferred_split() here lead to list corruption on the deferred
split LRU or leak MTHP_STAT_NR_ANON_PARTIALLY_MAPPED?
ZONE_DEVICE folios bypass the normal cleanup path in __folio_put():
mm/swap.c:__folio_put() {
if (unlikely(folio_is_zone_device(folio))) {
free_zone_device_folio(folio);
return;
}
...
}
If a ZONE_DEVICE folio (such as MEMORY_DEVICE_COHERENT) mapped as a large
anonymous folio is partially unmapped, folio_remove_rmap_pte() will queue
it on the deferred split list. When its refcount hits 0, it calls
free_zone_device_folio() directly.
When mem_cgroup_uncharge(folio) is called, if memcg is disabled or uncharged,
it returns early, leaving the freed folio linked in the deferred_split_lru.
When the deferred split shrinker runs under memory pressure, could this
iteration over freed memory cause a use-after-free crash? (If memcg is
enabled, the uncharge path forcefully unqueues it but emits a WARN_ON_ONCE).
Would explicitly calling folio_unqueue_deferred_split(folio) before
mem_cgroup_uncharge(folio) prevent this issue?
>
> if (folio_test_anon(folio)) {
> + mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_ANON, -1);
> for (i = 0; i < nr; i++)
> __ClearPageAnonExclusive(folio_page(folio, i));
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260702172548.37075-1-npache@redhat.com?part=1
next prev parent reply other threads:[~2026-07-02 17:41 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-02 17:25 [PATCH 0/2] mm: fix PMD level mTHP accounting bugs Nico Pache
2026-07-02 17:25 ` [PATCH 1/2] mm: decrement MTHP_STAT_NR_ANON in free_zone_device_folio() Nico Pache
2026-07-02 17:31 ` Zi Yan
2026-07-02 17:41 ` sashiko-bot [this message]
2026-07-02 17:25 ` [PATCH 2/2] mm/migrate: exclude hugetlb folios from MTHP_STAT_NR_ANON accounting Nico Pache
2026-07-02 17:33 ` Zi Yan
2026-07-03 3:09 ` Baolin Wang
2026-07-03 7:13 ` David Hildenbrand (Arm)
2026-07-03 8:25 ` Richard Cheng
2026-07-03 12:57 ` Nico Pache
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=20260702174111.46AB11F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=npache@redhat.com \
--cc=sashiko-reviews@lists.linux.dev \
/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