From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796102697; b=VgowjY7Me5fRADz5l8X7FsBeW9RqflQ1ht0C3k6YmSTQy1/ohmGTNsHAv9wiX0Ig1wi/ 4rwTHOBvrWMNH774RF8JoETEJ0nkEie/b4AhvG5ll2QH4nDcl3BDPT+NM6DWpw2nAGH3U jXeSI1NLRjKZAt0W1lfEM51bPBhpv2Db4g6lPGW9tpcojsRQzdH//pLrWBM6EtoRf+5m4 dcYgbeaMxmLOEgar8hs7LBXoHDXs0a8mbhZ4uY2MYcSbJXkxzuwn/Lsr5Q09nzp18Vaw4 uAGmt+DeuReYa0rwCW3JjiWGc3zdSlieQVfF8gbrjTPN37Hpe/U6kSWcMjq3CYpkynw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796102697; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-Id: In-Reply-To:References:X-Mailer:Mime-Version:Content-Type: Content-Transfer-Encoding; bh=0E+OW9JdjG3LwoTT9hTYwejJsaQsC7NuuOi+M5FHEag=; b=4M/tuPsWebWXY0qDgwstXRYGk3MP9HVxamnPdIFQ0yQywEm17Bd4p+z2x/T684WAMFge 4IsrwME1i7RxoIFioUsTpH8+P0k6w46K9hRllwNcDfiRj14Yt3J1monkX57t9OjKyz7GC pHNCu8cEa2WFthwRqJ60MuQxh8b/k3q8R+TTEqnV+EOukuO9EpA32RBuJAq7grHz1UJ1M 5yV4DBhbNvyLbdpPNPmsxPLXCyj5OjuYYTWj2ZD7CviiC6BXmRxnwRNd2G+N7oMpEDkc3 e/6hsE3YPL2uF5aZWJWU65UpxDqkFtg14v5RHgz4PiRA+YyyyaVkWpPzgiiTVz3StwQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=XBWW20Hz; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC9EE606A31A; Tue, 1 Dec 2026 05:24:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=XBWW20Hz Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8AF3B1F00893; Tue, 1 Dec 2026 05:24:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796102696; bh=0E+OW9JdjG3LwoTT9hTYwejJsaQsC7NuuOi+M5FHEag=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=XBWW20Hz8iX4sNhV4uByNXZIWavuvMlqLqRs/uqkHp/iJaIEH6ijQ6yQL6f8tBMYH qKrRSGBJcdpmaBCm8jGt82VI104woM/aD6j6Ruxzpao6vzHLfkMx0Cx+ZPYKczwqso VX7KAj7P2shj+w2AvbEF3u0P0sylNZGmOTfR0FIM= Date: Mon, 30 Nov 2026 21:24:55 -0800 From: Andrew Morton To: "Zi Yan" Cc: , "Tao Yi" , "Johannes Weiner" , "Michal Hocko" , "Roman Gushchin" , "Shakeel Butt" , "Muchun Song" , "David Hildenbrand" , "Matthew Wilcox" , "Baolin Wang" , "Liam R. Howlett" , "Nico Pache" , "Ryan Roberts" , "Dev Jain" , "Barry Song" , "Lance Yang" , "Usama Arif" , "Kiryl Shutsemau" , "Vlastimil Babka" , "Suren Baghdasaryan" , "Brendan Jackman" , , , , Subject: Re: [PATCH 1/2] mm/huge_memory: set memcg_data before a split page leaves the folio Message-Id: <20261130212455.6ffff196d7fd8d4cb2be2cd3@linux-foundation.org> In-Reply-To: References: <20261104-kpagecgroup-split-v1-0-f70e947fec85@samsung.com> <20261104-kpagecgroup-split-v1-1-f70e947fec85@samsung.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 04 Nov 2026 11:33:17 -0500 "Zi Yan" wrote: > On Wed Nov 4, 2026 at 4:59 AM EST, Daejun Park via B4 Relay wrote: > > From: Daejun Park > > > > __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 _