All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
To: Zi Yan <ziy@nvidia.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>,
	Brendan Jackman <jackmanb@google.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	David Hildenbrand <david@kernel.org>,
	Lorenzo Stoakes <ljs@kernel.org>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	"Liam R. Howlett" <liam@infradead.org>,
	Nico Pache <npache@redhat.com>,
	Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
	Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
	Mike Rapoport <rppt@kernel.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/4] mm/page_alloc: make sure subpage->private is zero at page free time
Date: Mon, 29 Jun 2026 16:53:46 +0200	[thread overview]
Message-ID: <43b67098-b9b3-448f-aa7a-43b7ef678e1c@kernel.org> (raw)
In-Reply-To: <20260628-keep-subpage-private-zero-at-free-v1-3-f4ce3930d10f@nvidia.com>

On 6/29/26 04:56, Zi Yan wrote:
> Any code using subpage->private of a folio, a compound page or a high-order
> page is supposed to reset it after use, otherwise ->private data can leak
> to new page user and cause unexpected issues. Add a bad_page() check at
> page free path for it.
> 
> Assisted-by: Codex:gpt-5 # add the missing "return false" after bad_page()
> Signed-off-by: Zi Yan <ziy@nvidia.com>

I noticed the word 'subpage' is now frowned upon ;)
See https://lore.kernel.org/all/20260623125723.2503832-1-dev.jain@arm.com/

since this is about tail pages, just call them as such?

> ---
>  mm/page_alloc.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index ee902a468c2f..13c2655e24fb 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -1374,15 +1374,21 @@ static __always_inline bool __free_pages_prepare(struct page *page,
>  #endif
>  		}
>  		for (i = 1; i < (1 << order); i++) {

i starts at 1

> +			struct page *subpage = page + i;

so "tail_page" is accurate?

> +
>  			if (compound)
> -				bad += free_tail_page_prepare(page, page + i);
> +				bad += free_tail_page_prepare(page, subpage);
>  			if (is_check_pages_enabled()) {
> -				if (free_page_is_bad(page + i)) {
> +				if (free_page_is_bad(subpage)) {
>  					bad++;
>  					continue;
>  				}
>  			}
> -			(page + i)->flags.f &= ~PAGE_FLAGS_CHECK_AT_PREP;
> +			subpage->flags.f &= ~PAGE_FLAGS_CHECK_AT_PREP;
> +			if (subpage->private) {
> +				bad_page(subpage, "nonzero private");
> +				return false;
> +			}

Also why not put this check into the is_check_pages_enabled() block and
handle it the same way?

>  		}
>  	}
>  	if (folio_test_anon(folio)) {
> 



  reply	other threads:[~2026-06-29 14:53 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-29  2:56 [PATCH 0/4] Keep subpage private zero at free and folio split time Zi Yan
2026-06-29  2:56 ` [PATCH 1/4] mm/compaction: stop recording free page order in page->private Zi Yan
2026-06-29 14:28   ` Vlastimil Babka (SUSE)
2026-06-29 15:03     ` Zi Yan
2026-06-30  1:32   ` Baolin Wang
2026-06-30  1:37     ` Zi Yan
2026-07-01  8:54       ` David Hildenbrand (Arm)
2026-07-01  6:49   ` Lance Yang
2026-06-29  2:56 ` [PATCH 2/4] mm/huge_memory: add page->private check back in __split_folio_to_order() Zi Yan
2026-06-29 14:39   ` Vlastimil Babka (SUSE)
2026-06-29 15:05     ` Zi Yan
2026-07-01  8:56     ` David Hildenbrand (Arm)
2026-07-01 11:01       ` Lance Yang
2026-07-01 11:08         ` David Hildenbrand (Arm)
2026-07-01 13:32           ` Zi Yan
2026-06-29  2:56 ` [PATCH 3/4] mm/page_alloc: make sure subpage->private is zero at page free time Zi Yan
2026-06-29 14:53   ` Vlastimil Babka (SUSE) [this message]
2026-06-29 15:07     ` Zi Yan
2026-06-29  2:56 ` [PATCH 4/4] mm/page_alloc: remove set_page_private() in prep_compound_tail() Zi Yan
2026-06-29 15:45   ` Vlastimil Babka (SUSE)
2026-06-29 16:50     ` Zi Yan
2026-07-01  8:58   ` David Hildenbrand (Arm)
2026-07-01 12:25     ` Lance Yang
2026-07-01 13:33       ` Zi Yan

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=43b67098-b9b3-448f-aa7a-43b7ef678e1c@kernel.org \
    --to=vbabka@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=hannes@cmpxchg.org \
    --cc=jackmanb@google.com \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=npache@redhat.com \
    --cc=rppt@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=surenb@google.com \
    --cc=ziy@nvidia.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 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.