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=1796102713; b=H66k/cgGBd4FWuZR8gGOwdwSCP+pUkqtPdHIv+3p/qXt8iVhN00h7TLsvVFpnCo19Rn8 +cm0F1Db3FOfURDaogpN1pw7YYZ0cVRW8ccQsb1XucjXPBgxeWdO7kuZzm7+MyGnVHiOr XUv6WYG23Pk//ebDkd+oYJ6zuFYodjROXqagn9K+0TUMuILq/op9t3d9XkE+cVaEbLc6V WwNjYdmUC3ew1y6q5xTKtk4WkQ/CRR1k6A3DwIRGtv87HaZnEsTa3I2zKpqMUHJCa6OZO bE5lR8DrROQ+8GZwOtX1/oxPuXjnSQcaq7/GIw3A2zphqJGogo3nLGS0BGvAqTfa7rg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796102713; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=O0ZSQf/0rwJquNyr7X6H5fSMRzGl0A3cxC87gC0spOQ=; b=Eecp0S327fz+q/SQuftu+VI0EDmKo+jBOs4PtVlPbrAJjHSSJpnGpxZt1MYSPBsAR5Mu XWODWTL7xr9fxa9cG6RozeAPhZ77NnxqiRQzeMLWygGFP7REdBeBEavjnVoRxK/srvsMp F5zrbJrqSlWC6ZYK3jdg8GV3Z/vMAHmp4AV/HPsayUNqTCOsYBsvYPjvP/M2oKxZSm7So FQCXTUrzRnTgUQrYFI+KBdG6e4fqLKthUINuHSjf2tiHAulPdD4lPyIwEjyQHcL/19Du/ ItVeSJMtHzjepJkppRcsLxQYvhO6JpmrD+o7AxMgoTAb7qRbJpq1WUv+feUfcT9rz/w== 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=knFnHEqz; 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 C97AB606A334; Tue, 1 Dec 2026 05:25:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=knFnHEqz Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4CB251F00899; Tue, 1 Dec 2026 05:25:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796102713; bh=O0ZSQf/0rwJquNyr7X6H5fSMRzGl0A3cxC87gC0spOQ=; h=Date:To:From:In-Reply-To:References:Subject; b=knFnHEqzGbUHxB3CXD/Ik0klBtA0y+qzBBcwfasgdRnHNKNYYvMzefNRfnHX/86Lc 9NXM8XBuCdwDuzguZD01aAHmTsNBM0fpm2rjpl8Gq7LX+PQW8296chYm051hqG07wq 2elNZXHf/62oCyppCn4cZbrjB0REEAKVWmEbOeCg= Date: Mon, 30 Nov 2026 21:25:12 -0800 To: mm-commits@vger.kernel.org,ziy@nvidia.com,willy@infradead.org, vbabka@kernel.org,usama.arif@linux.dev,surenb@google.com, stable@vger.kernel.org,shakeel.butt@linux.dev,ryan.roberts@arm.com, roman.gushchin@linux.dev,nico.pache@linux.dev,muchun.song@linux.dev, mhocko@kernel.org,liam@infradead.org,lance.yang@linux.dev,kas@kernel.org, hannes@cmpxchg.org,escape@deepseek.com,dev.jain@arm.com,david@kernel.org, brendan.jackman@linux.dev,baolin.wang@linux.alibaba.com,baohua@kernel.org, daejun7.park@samsung.com,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261104-kpagecgroup-split-v1-1-f70e947fec85@samsung.com> References: <20261104-kpagecgroup-split-v1-1-f70e947fec85@samsung.com> Subject: + mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio.patch added to mm-new branch Message-Id: <20261201052513.4CB251F00899@smtp.kernel.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The patch titled Subject: mm/huge_memory: set memcg_data before a split page leaves the folio has been added to the -mm mm-new branch. Its filename is mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Daejun Park Subject: mm/huge_memory: set memcg_data before a split page leaves the folio Date: Wed, 04 Nov 2026 18:59:08 +0900 Patch series "mm: fix memcg_data reads during a THP split". Tao Yi reported an oops in page_cgroup_ino() while reading /proc/kpagecgroup and traced it to the THP split in an RFC [1]. The RFC skips frozen folios in the reader. Patch 1 moves the memcg_data copy in the split instead. Patch 2 orders the same loads in page_owner and needs patch 1. Charged large kmalloc pages are frozen, so the RFC would report them as uncharged. My review of the RFC [2] got no reply. Tested on x86_64 with KASAN, see patch 1. This patch (of 2): __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 while folios are split to order 0. Copy memcg_data before the smp_wmb(), as before commit fa23a338de93 ("mm: separate folio_split_memcg_refs() from split_page_memcg()"). Add the paired smp_rmb() to page_cgroup_ino(). Link: https://lore.kernel.org/20261104-kpagecgroup-split-v1-0-f70e947fec85@samsung.com Link: https://patch.msgid.link/20261104-kpagecgroup-split-v1-1-f70e947fec85@samsung.com Link: https://lore.kernel.org/all/20260907124001.1544655-1-escape@deepseek.com/ [1] Link: https://lore.kernel.org/all/20261028040418epcms2p7ac0f584cdfdc6a0ea9b7f20eadeada3d@epcms2p7/ [2] Fixes: fa23a338de93 ("mm: separate folio_split_memcg_refs() from split_page_memcg()") Signed-off-by: Daejun Park Signed-off-by: Andrew Morton Reported-by: Tao Yi Closes: https://lore.kernel.org/all/20260907124001.1544655-1-escape@deepseek.com/ Reviewed-by: Zi Yan Cc: Johannes Weiner Cc: Michal Hocko Cc: Roman Gushchin Cc: Shakeel Butt Cc: Muchun Song Cc: David Hildenbrand Cc: Matthew Wilcox (Oracle) Cc: Baolin Wang Cc: Liam R. Howlett Cc: Nico Pache Cc: Ryan Roberts Cc: Dev Jain Cc: Barry Song Cc: Lance Yang Cc: Usama Arif Cc: Kiryl Shutsemau Cc: Vlastimil Babka Cc: Suren Baghdasaryan Cc: Brendan Jackman Cc: mm/huge_memory.c | 17 +++++++++++++---- mm/memcontrol.c | 9 ++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) --- a/mm/huge_memory.c~mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio +++ a/mm/huge_memory.c @@ -3858,7 +3858,19 @@ static void __split_folio_to_order(struc if (folio_test_swapcache(folio)) new_folio->swap.val = folio->swap.val + i; - /* Page flags must be visible before we make the page non-compound. */ +#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. + */ + new_folio->memcg_data = folio->memcg_data; +#endif + + /* + * Page flags and memcg_data must be visible before we make the + * page non-compound. + */ smp_wmb(); /* @@ -3889,9 +3901,6 @@ static void __split_folio_to_order(struc folio_set_young(new_folio); if (folio_test_idle(folio)) folio_set_idle(new_folio); -#ifdef CONFIG_MEMCG - new_folio->memcg_data = folio->memcg_data; -#endif folio_xchg_last_cpupid(new_folio, folio_last_cpupid(folio)); } --- a/mm/memcontrol.c~mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio +++ a/mm/memcontrol.c @@ -373,12 +373,19 @@ struct cgroup_subsys_state *get_mem_cgro */ ino_t page_cgroup_ino(const struct page *page) { + const struct folio *folio; struct mem_cgroup *memcg; unsigned long ino = 0; rcu_read_lock(); /* page_folio() is racy here, but the entire function is racy anyway */ - memcg = folio_memcg_check(page_folio(page)); + folio = page_folio(page); + /* + * Order the memcg_data load after the compound_info load in + * page_folio(). Pairs with smp_wmb() in __split_folio_to_order(). + */ + smp_rmb(); + memcg = folio_memcg_check(folio); while (memcg && !css_is_online(&memcg->css)) memcg = parent_mem_cgroup(memcg); _ Patches currently in -mm which might be from daejun7.park@samsung.com are mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio.patch mm-page_owner-also-check-pagetail-before-reading-memcg_data.patch