Linux cgroups development
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: "Zi Yan" <ziy@nvidia.com>
Cc: <daejun7.park@samsung.com>, "Tao Yi" <escape@deepseek.com>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Michal Hocko" <mhocko@kernel.org>,
	"Roman Gushchin" <roman.gushchin@linux.dev>,
	"Shakeel Butt" <shakeel.butt@linux.dev>,
	"Muchun Song" <muchun.song@linux.dev>,
	"David Hildenbrand" <david@kernel.org>,
	"Matthew Wilcox" <willy@infradead.org>,
	"Baolin Wang" <baolin.wang@linux.alibaba.com>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Nico Pache" <nico.pache@linux.dev>,
	"Ryan Roberts" <ryan.roberts@arm.com>,
	"Dev Jain" <dev.jain@arm.com>, "Barry Song" <baohua@kernel.org>,
	"Lance Yang" <lance.yang@linux.dev>,
	"Usama Arif" <usama.arif@linux.dev>,
	"Kiryl Shutsemau" <kas@kernel.org>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Brendan Jackman" <brendan.jackman@linux.dev>,
	<linux-mm@kvack.org>, <cgroups@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <stable@vger.kernel.org>
Subject: Re: [PATCH 1/2] mm/huge_memory: set memcg_data before a split page leaves the folio
Date: Mon, 30 Nov 2026 21:24:55 -0800	[thread overview]
Message-ID: <20261130212455.6ffff196d7fd8d4cb2be2cd3@linux-foundation.org> (raw)
In-Reply-To: <DMMKKOIGA9UJ.353PCUUMFLCCJ@nvidia.com>

On Wed, 04 Nov 2026 11:33:17 -0500 "Zi Yan" <ziy@nvidia.com> wrote:

> On Wed Nov 4, 2026 at 4:59 AM EST, Daejun Park via B4 Relay wrote:
> > From: Daejun Park <daejun7.park@samsung.com>
> >
> > __split_folio_to_order() copies memcg_data to a new folio after
> > clear_compound_head(). Until then, memcg_data of the first tail page
> > holds the folio's _nr_pages. page_cgroup_ino() can see that page as a
> > folio in the window and take _nr_pages for an objcg pointer. Reading
> > /proc/kpagecgroup as root then oopses

OK, so it's an oopser, normally requiring root to trigger it.

> > +#ifdef CONFIG_MEMCG
> > +		/*
> > +		 * In the first tail page, memcg_data still holds
> > +		 * folio->_nr_pages. Lockless PFN walkers (page_cgroup_ino(),
> > +		 * page_owner) read memcg_data once the page is not a tail.
> > +		 */
> 
> How about? Because clear_compound_head() makes the new_folio be
> recognized as a folio by reference-free readers.
> 
> Assign memcg data before clear_compound_head(), so lockless,
> reference-free readers get the right value instead of bogus data from
> the overlaid ->_nr_pages in the first tail page.

Thanks both, I queued this -fix,  Looks suitable?

+++ a/mm/huge_memory.c
@@ -3860,9 +3860,10 @@ static void __split_folio_to_order(struc
 
 #ifdef CONFIG_MEMCG
 		/*
-		 * In the first tail page, memcg_data still holds
-		 * folio->_nr_pages. Lockless PFN walkers (page_cgroup_ino(),
-		 * page_owner) read memcg_data once the page is not a tail.
+		 * clear_compound_head() makes new_folio visible as a folio to
+		 * lockless, reference-free PFN walkers. In the first tail page,
+		 * memcg_data overlays folio->_nr_pages. Set it before clearing
+		 * compound_head so readers cannot mistake _nr_pages for an objcg.
 		 */
 		new_folio->memcg_data = folio->memcg_data;
 #endif
_


  parent reply	other threads:[~2026-12-01  5:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04  9:59 [PATCH 0/2] mm: fix memcg_data reads during a THP split Daejun Park via B4 Relay
2026-11-04  9:59 ` [PATCH 1/2] mm/huge_memory: set memcg_data before a split page leaves the folio Daejun Park via B4 Relay
2026-11-04 16:33   ` Zi Yan
2026-11-05  1:06     ` Daejun Park
2026-12-01  5:24     ` Andrew Morton [this message]
2026-11-04  9:59 ` [PATCH 2/2] mm/page_owner: also check PageTail before reading memcg_data Daejun Park via B4 Relay
2026-11-04 16:38   ` Zi Yan
2026-11-06  8:57 ` [PATCH 0/2] mm: fix memcg_data reads during a THP split Tao Yi

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=20261130212455.6ffff196d7fd8d4cb2be2cd3@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=brendan.jackman@linux.dev \
    --cc=cgroups@vger.kernel.org \
    --cc=daejun7.park@samsung.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=escape@deepseek.com \
    --cc=hannes@cmpxchg.org \
    --cc=kas@kernel.org \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=nico.pache@linux.dev \
    --cc=roman.gushchin@linux.dev \
    --cc=ryan.roberts@arm.com \
    --cc=shakeel.butt@linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=surenb@google.com \
    --cc=usama.arif@linux.dev \
    --cc=vbabka@kernel.org \
    --cc=willy@infradead.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox