All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: shao.mingyin@zte.com.cn, akpm@linux-foundation.org, david@kernel.org
Cc: linux-mm@kvack.org, liam@infradead.org, vbabka@kernel.org,
	rppt@kernel.org, surenb@google.com, mhocko@suse.com
Subject: Re: [PATCH] mm/util: fix off-by-one when checking folio index in snapshot_page()
Date: Sun, 15 Nov 2026 16:47:26 +0000	[thread overview]
Message-ID: <sashiko-outbox-215658@kernel.org> (raw)
In-Reply-To: <20261115004657890Pz8ERDf5nCtE-B6M7KFzu@zte.com.cn>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mm/util: head page with zero _nr_pages hits tail fallback in
  snapshot_page()
--

commit c1bbaeb218bb3e6717e9e858cb2ae698eb9ee371
Author: Shao Mingyin <shao.mingyin@zte.com.cn>

mm/util: fix off-by-one when checking folio index in snapshot_page()

This commit changes the folio index bounds check in snapshot_page() from
> to >= so that snapshots whose page index equals the copied folio's
page count are retried or treated as unfaithful.

> diff --git a/mm/util.c b/mm/util.c
> index a5140b3b70f33..6e6a8f8640a75 100644
> --- a/mm/util.c
> +++ b/mm/util.c
> @@ -1462,7 +1462,7 @@ void snapshot_page(struct page_snapshot *ps, const struct page *page)
>  		set_ps_flags(ps, foliop, page);
>  	}
>  
> -	if (ps->idx > nr_pages) {
> +	if (ps->idx >= nr_pages) {
>  		if (loops-- > 0)
>  			goto again;
>  		clear_compound_head(&ps->page_snapshot);

[Severity: Medium]
Can this cause a compound head page with folio->_nr_pages == 0 to enter
the tail-page fallback block?

When snapshot_page() inspects a compound head page (ps->idx == 0) while
folio->_nr_pages is 0 under NR_PAGES_IN_LARGE_FOLIO, nr_pages is 0 and
ps->idx >= nr_pages now evaluates to true.  This happens deterministically
when __free_pages_prepare() reports a bad compound page, because it zeroes
folio->_nr_pages before calling free_page_is_bad() -> bad_page() ->
dump_page() and before clearing PG_head:

mm/page_alloc.c:__free_pages_prepare() {
    ...
		if (compound) {
			page[1].flags.f &= ~PAGE_FLAGS_SECOND;
#ifdef NR_PAGES_IN_LARGE_FOLIO
			folio->_nr_pages = 0;
#endif
		}
    ...
	if (is_check_pages_enabled()) {
		if (free_page_is_bad(page))
			bad++;
    ...
}

After the retries expire, the fallback calls
clear_compound_head(&ps->page_snapshot), which overwrites the compound_info
union word (lru.next or pp_magic on a head page) with 0, copies only
sizeof(struct page) into ps->folio_snapshot while leaving PG_head set, and
clears ps->flags.  In __dump_page(), this triggers a bogus "page does not
match folio" warning on a head page and zeroes the lru.next word in the hex
dump.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261115004657890Pz8ERDf5nCtE-B6M7KFzu@zte.com.cn?part=1


      parent reply	other threads:[~2026-11-15 16:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14 16:46 [PATCH] mm/util: fix off-by-one when checking folio index in snapshot_page() shao.mingyin
2026-11-14 17:33 ` Lorenzo Stoakes (ARM)
2026-11-15 17:32   ` David Hildenbrand (Arm)
2026-11-15 19:15     ` Lorenzo Stoakes (ARM)
2026-11-15 16:47 ` sashiko-bot [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=sashiko-outbox-215658@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=rppt@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shao.mingyin@zte.com.cn \
    --cc=surenb@google.com \
    --cc=vbabka@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.