* [PATCH 0/2] mm: fix memcg_data reads during a THP split
@ 2026-11-04 9:59 ` Daejun Park via B4 Relay
0 siblings, 0 replies; 17+ messages in thread
From: Daejun Park @ 2026-11-04 9:59 UTC (permalink / raw)
To: Andrew Morton
Cc: Tao Yi, Johannes Weiner, Michal Hocko, Roman Gushchin,
Shakeel Butt, Muchun Song, David Hildenbrand, Zi Yan,
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, linux-mm, cgroups, linux-kernel, stable,
Daejun Park
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.
[1] https://lore.kernel.org/all/20260907124001.1544655-1-escape@deepseek.com/
[2] https://lore.kernel.org/all/20261028040418epcms2p7ac0f584cdfdc6a0ea9b7f20eadeada3d@epcms2p7/
---
Daejun Park (2):
mm/huge_memory: set memcg_data before a split page leaves the folio
mm/page_owner: also check PageTail before reading memcg_data
mm/huge_memory.c | 17 +++++++++++++----
mm/memcontrol.c | 9 ++++++++-
mm/page_owner.c | 7 +++++++
3 files changed, 28 insertions(+), 5 deletions(-)
---
base-commit: a13b500946e5dc467976838572b8ddd2fd777ca7
change-id: 20261028-kpagecgroup-split-8a749c6ee27e
Best regards,
--
Daejun Park <daejun7.park@samsung.com>
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 0/2] mm: fix memcg_data reads during a THP split
@ 2026-11-04 9:59 ` Daejun Park via B4 Relay
0 siblings, 0 replies; 17+ messages in thread
From: Daejun Park via B4 Relay @ 2026-11-04 9:59 UTC (permalink / raw)
To: Andrew Morton
Cc: Tao Yi, Johannes Weiner, Michal Hocko, Roman Gushchin,
Shakeel Butt, Muchun Song, David Hildenbrand, Zi Yan,
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, linux-mm, cgroups, linux-kernel, stable,
Daejun Park
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.
[1] https://lore.kernel.org/all/20260907124001.1544655-1-escape@deepseek.com/
[2] https://lore.kernel.org/all/20261028040418epcms2p7ac0f584cdfdc6a0ea9b7f20eadeada3d@epcms2p7/
---
Daejun Park (2):
mm/huge_memory: set memcg_data before a split page leaves the folio
mm/page_owner: also check PageTail before reading memcg_data
mm/huge_memory.c | 17 +++++++++++++----
mm/memcontrol.c | 9 ++++++++-
mm/page_owner.c | 7 +++++++
3 files changed, 28 insertions(+), 5 deletions(-)
---
base-commit: a13b500946e5dc467976838572b8ddd2fd777ca7
change-id: 20261028-kpagecgroup-split-8a749c6ee27e
Best regards,
--
Daejun Park <daejun7.park@samsung.com>
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 1/2] mm/huge_memory: set memcg_data before a split page leaves the folio
2026-11-04 9:59 ` Daejun Park via B4 Relay
@ 2026-11-04 9:59 ` Daejun Park via B4 Relay
-1 siblings, 0 replies; 17+ messages in thread
From: Daejun Park @ 2026-11-04 9:59 UTC (permalink / raw)
To: Andrew Morton
Cc: Tao Yi, Johannes Weiner, Michal Hocko, Roman Gushchin,
Shakeel Butt, Muchun Song, David Hildenbrand, Zi Yan,
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, linux-mm, cgroups, linux-kernel, stable,
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 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().
Fixes: fa23a338de93 ("mm: separate folio_split_memcg_refs() from split_page_memcg()")
Reported-by: Tao Yi <escape@deepseek.com>
Closes: https://lore.kernel.org/all/20260907124001.1544655-1-escape@deepseek.com/
Cc: stable@vger.kernel.org
Signed-off-by: Daejun Park <daejun7.park@samsung.com>
---
Tested on x86_64 with KASAN (7.3-rc7 and mm-hotfixes-unstable) in an
8-vCPU QEMU guest: six threads read /proc/kpagecgroup for page 1 of 64
THPs that debugfs split_huge_pages splits to order 0. Base oopsed in 6
of 6 runs, 4 of them within 1.5 s. With patch 1, 8 runs of 300 s had
no oops.
Before 7.4, page_cgroup_ino() and folio_memcg_check() take non-const
pointers, so a stable backport needs "struct folio *folio" there. The
hunk applies to those trees without a conflict, and the build then
fails with CONFIG_WERROR=y (-Wdiscarded-qualifiers).
---
mm/huge_memory.c | 17 +++++++++++++----
mm/memcontrol.c | 9 ++++++++-
2 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 14599d0fff..adc5a47ee7 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -3768,7 +3768,19 @@ static void __split_folio_to_order(struct folio *folio, int old_order,
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();
/*
@@ -3803,9 +3815,6 @@ static void __split_folio_to_order(struct folio *folio, int old_order,
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));
}
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 84f4a8fd4d..c244d56446 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -375,12 +375,19 @@ struct cgroup_subsys_state *get_mem_cgroup_css_from_folio(const struct folio *fo
*/
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);
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 1/2] mm/huge_memory: set memcg_data before a split page leaves the folio
@ 2026-11-04 9:59 ` Daejun Park via B4 Relay
0 siblings, 0 replies; 17+ messages in thread
From: Daejun Park via B4 Relay @ 2026-11-04 9:59 UTC (permalink / raw)
To: Andrew Morton
Cc: Tao Yi, Johannes Weiner, Michal Hocko, Roman Gushchin,
Shakeel Butt, Muchun Song, David Hildenbrand, Zi Yan,
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, linux-mm, cgroups, linux-kernel, stable,
Daejun Park
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 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().
Fixes: fa23a338de93 ("mm: separate folio_split_memcg_refs() from split_page_memcg()")
Reported-by: Tao Yi <escape@deepseek.com>
Closes: https://lore.kernel.org/all/20260907124001.1544655-1-escape@deepseek.com/
Cc: stable@vger.kernel.org
Signed-off-by: Daejun Park <daejun7.park@samsung.com>
---
Tested on x86_64 with KASAN (7.3-rc7 and mm-hotfixes-unstable) in an
8-vCPU QEMU guest: six threads read /proc/kpagecgroup for page 1 of 64
THPs that debugfs split_huge_pages splits to order 0. Base oopsed in 6
of 6 runs, 4 of them within 1.5 s. With patch 1, 8 runs of 300 s had
no oops.
Before 7.4, page_cgroup_ino() and folio_memcg_check() take non-const
pointers, so a stable backport needs "struct folio *folio" there. The
hunk applies to those trees without a conflict, and the build then
fails with CONFIG_WERROR=y (-Wdiscarded-qualifiers).
---
mm/huge_memory.c | 17 +++++++++++++----
mm/memcontrol.c | 9 ++++++++-
2 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 14599d0fff..adc5a47ee7 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -3768,7 +3768,19 @@ static void __split_folio_to_order(struct folio *folio, int old_order,
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();
/*
@@ -3803,9 +3815,6 @@ static void __split_folio_to_order(struct folio *folio, int old_order,
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));
}
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 84f4a8fd4d..c244d56446 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -375,12 +375,19 @@ struct cgroup_subsys_state *get_mem_cgroup_css_from_folio(const struct folio *fo
*/
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);
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 2/2] mm/page_owner: also check PageTail before reading memcg_data
2026-11-04 9:59 ` Daejun Park via B4 Relay
@ 2026-11-04 9:59 ` Daejun Park via B4 Relay
-1 siblings, 0 replies; 17+ messages in thread
From: Daejun Park @ 2026-11-04 9:59 UTC (permalink / raw)
To: Andrew Morton
Cc: Tao Yi, Johannes Weiner, Michal Hocko, Roman Gushchin,
Shakeel Butt, Muchun Song, David Hildenbrand, Zi Yan,
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, linux-mm, cgroups, linux-kernel, Daejun Park
print_page_owner_memcg() loads memcg_data before it tests PageTail().
In the first tail page, memcg_data holds the folio's _nr_pages. A split
can make the page a folio between the two loads. The stale _nr_pages
then passes the PageTail() test and is used as an objcg pointer.
__split_folio_to_order() stores memcg_data before the smp_wmb() that
precedes clear_compound_head(). Also test PageTail() before the load,
with a paired smp_rmb(). Keep the test after the load for a page that
becomes a tail in between.
Fixes: 4996fc547f5b ("mm: let _folio_nr_pages overlay memcg_data in first tail page")
Signed-off-by: Daejun Park <daejun7.park@samsung.com>
---
Needs patch 1 for the store order. Found by reading the code, not
reproduced. The page_owner oops seen with a delay after
clear_compound_head() is the window patch 1 closes.
---
mm/page_owner.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/mm/page_owner.c b/mm/page_owner.c
index cfc31c92d7..058d4dec84 100644
--- a/mm/page_owner.c
+++ b/mm/page_owner.c
@@ -564,6 +564,13 @@ static inline int print_page_owner_memcg(char *kbuf, size_t count, int ret,
char name[80];
rcu_read_lock();
+ if (PageTail(page))
+ goto out_unlock;
+ /*
+ * Order the memcg_data load after the PageTail() load. Pairs with
+ * smp_wmb() in __split_folio_to_order().
+ */
+ smp_rmb();
memcg_data = READ_ONCE(page->memcg_data);
if (!memcg_data || PageTail(page))
goto out_unlock;
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 2/2] mm/page_owner: also check PageTail before reading memcg_data
@ 2026-11-04 9:59 ` Daejun Park via B4 Relay
0 siblings, 0 replies; 17+ messages in thread
From: Daejun Park via B4 Relay @ 2026-11-04 9:59 UTC (permalink / raw)
To: Andrew Morton
Cc: Tao Yi, Johannes Weiner, Michal Hocko, Roman Gushchin,
Shakeel Butt, Muchun Song, David Hildenbrand, Zi Yan,
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, linux-mm, cgroups, linux-kernel, Daejun Park
From: Daejun Park <daejun7.park@samsung.com>
print_page_owner_memcg() loads memcg_data before it tests PageTail().
In the first tail page, memcg_data holds the folio's _nr_pages. A split
can make the page a folio between the two loads. The stale _nr_pages
then passes the PageTail() test and is used as an objcg pointer.
__split_folio_to_order() stores memcg_data before the smp_wmb() that
precedes clear_compound_head(). Also test PageTail() before the load,
with a paired smp_rmb(). Keep the test after the load for a page that
becomes a tail in between.
Fixes: 4996fc547f5b ("mm: let _folio_nr_pages overlay memcg_data in first tail page")
Signed-off-by: Daejun Park <daejun7.park@samsung.com>
---
Needs patch 1 for the store order. Found by reading the code, not
reproduced. The page_owner oops seen with a delay after
clear_compound_head() is the window patch 1 closes.
---
mm/page_owner.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/mm/page_owner.c b/mm/page_owner.c
index cfc31c92d7..058d4dec84 100644
--- a/mm/page_owner.c
+++ b/mm/page_owner.c
@@ -564,6 +564,13 @@ static inline int print_page_owner_memcg(char *kbuf, size_t count, int ret,
char name[80];
rcu_read_lock();
+ if (PageTail(page))
+ goto out_unlock;
+ /*
+ * Order the memcg_data load after the PageTail() load. Pairs with
+ * smp_wmb() in __split_folio_to_order().
+ */
+ smp_rmb();
memcg_data = READ_ONCE(page->memcg_data);
if (!memcg_data || PageTail(page))
goto out_unlock;
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH 1/2] mm/huge_memory: set memcg_data before a split page leaves the folio
2026-11-04 9:59 ` Daejun Park via B4 Relay
(?)
@ 2026-11-04 16:33 ` Zi Yan
2026-11-05 1:06 ` Daejun Park
` (2 more replies)
-1 siblings, 3 replies; 17+ messages in thread
From: Zi Yan @ 2026-11-04 16:33 UTC (permalink / raw)
To: daejun7.park, Andrew Morton
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, linux-mm,
cgroups, linux-kernel, stable
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 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().
>
> Fixes: fa23a338de93 ("mm: separate folio_split_memcg_refs() from split_page_memcg()")
> Reported-by: Tao Yi <escape@deepseek.com>
> Closes: https://lore.kernel.org/all/20260907124001.1544655-1-escape@deepseek.com/
> Cc: stable@vger.kernel.org
> Signed-off-by: Daejun Park <daejun7.park@samsung.com>
> ---
> Tested on x86_64 with KASAN (7.3-rc7 and mm-hotfixes-unstable) in an
> 8-vCPU QEMU guest: six threads read /proc/kpagecgroup for page 1 of 64
> THPs that debugfs split_huge_pages splits to order 0. Base oopsed in 6
> of 6 runs, 4 of them within 1.5 s. With patch 1, 8 runs of 300 s had
> no oops.
>
> Before 7.4, page_cgroup_ino() and folio_memcg_check() take non-const
> pointers, so a stable backport needs "struct folio *folio" there. The
> hunk applies to those trees without a conflict, and the build then
> fails with CONFIG_WERROR=y (-Wdiscarded-qualifiers).
> ---
> mm/huge_memory.c | 17 +++++++++++++----
> mm/memcontrol.c | 9 ++++++++-
> 2 files changed, 21 insertions(+), 5 deletions(-)
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 14599d0fff..adc5a47ee7 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -3768,7 +3768,19 @@ static void __split_folio_to_order(struct folio *folio, int old_order,
> 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.
> + */
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.
> + 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();
>
> /*
> @@ -3803,9 +3815,6 @@ static void __split_folio_to_order(struct folio *folio, int old_order,
> 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));
> }
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 84f4a8fd4d..c244d56446 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -375,12 +375,19 @@ struct cgroup_subsys_state *get_mem_cgroup_css_from_folio(const struct folio *fo
> */
> 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);
Otherwise, LGTM. Thanks.
Reviewed-by: Zi Yan <ziy@nvidia.com>
--
Best Regards,
Yan, Zi
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 2/2] mm/page_owner: also check PageTail before reading memcg_data
2026-11-04 9:59 ` Daejun Park via B4 Relay
(?)
@ 2026-11-04 16:38 ` Zi Yan
-1 siblings, 0 replies; 17+ messages in thread
From: Zi Yan @ 2026-11-04 16:38 UTC (permalink / raw)
To: daejun7.park, Andrew Morton
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, linux-mm,
cgroups, linux-kernel
On Wed Nov 4, 2026 at 4:59 AM EST, Daejun Park via B4 Relay wrote:
> From: Daejun Park <daejun7.park@samsung.com>
>
> print_page_owner_memcg() loads memcg_data before it tests PageTail().
> In the first tail page, memcg_data holds the folio's _nr_pages. A split
> can make the page a folio between the two loads. The stale _nr_pages
> then passes the PageTail() test and is used as an objcg pointer.
>
> __split_folio_to_order() stores memcg_data before the smp_wmb() that
> precedes clear_compound_head(). Also test PageTail() before the load,
> with a paired smp_rmb(). Keep the test after the load for a page that
> becomes a tail in between.
>
> Fixes: 4996fc547f5b ("mm: let _folio_nr_pages overlay memcg_data in first tail page")
> Signed-off-by: Daejun Park <daejun7.park@samsung.com>
> ---
> Needs patch 1 for the store order. Found by reading the code, not
> reproduced. The page_owner oops seen with a delay after
> clear_compound_head() is the window patch 1 closes.
> ---
> mm/page_owner.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
Makes sense.
Reviewed-by: Zi Yan <ziy@nvidia.com>
--
Best Regards,
Yan, Zi
^ permalink raw reply [flat|nested] 17+ messages in thread
* RE:(2) [PATCH 1/2] mm/huge_memory: set memcg_data before a split page leaves the folio
2026-11-04 16:33 ` Zi Yan
@ 2026-11-05 1:06 ` Daejun Park
2026-12-01 5:24 ` Andrew Morton
2026-12-01 5:25 ` + mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio-fix.patch added to mm-new branch Andrew Morton
2 siblings, 0 replies; 17+ messages in thread
From: Daejun Park @ 2026-11-05 1:06 UTC (permalink / raw)
To: Zi Yan, Andrew Morton
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,
linux-mm@kvack.org, cgroups@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org, Daejun Park
On Wed Nov 4, 2026 at 11:33 AM EST, Zi Yan wrote:
> 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, agreed. Your wording says why the assignment has to come before
clear_compound_head(), which my comment left implicit.
Thanks,
Daejun
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 0/2] mm: fix memcg_data reads during a THP split
2026-11-04 9:59 ` Daejun Park via B4 Relay
` (2 preceding siblings ...)
(?)
@ 2026-11-06 8:57 ` Tao Yi
-1 siblings, 0 replies; 17+ messages in thread
From: Tao Yi @ 2026-11-06 8:57 UTC (permalink / raw)
To: daejun7.park
Cc: Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt,
Muchun Song, David Hildenbrand, Zi Yan, 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, linux-mm,
cgroups, linux-kernel, stable, Andrew Morton
Hi Daejun,
Sorry, I missed your email on the RFC thread. Thanks for following up
and for taking care of the fix.
在 2026/11/4 17:59, Daejun Park via B4 Relay 写道:
> 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.
>
> [1] https://lore.kernel.org/all/20260907124001.1544655-1-escape@deepseek.com/
> [2] https://lore.kernel.org/all/20261028040418epcms2p7ac0f584cdfdc6a0ea9b7f20eadeada3d@epcms2p7/
>
> ---
> Daejun Park (2):
> mm/huge_memory: set memcg_data before a split page leaves the folio
> mm/page_owner: also check PageTail before reading memcg_data
>
> mm/huge_memory.c | 17 +++++++++++++----
> mm/memcontrol.c | 9 ++++++++-
> mm/page_owner.c | 7 +++++++
> 3 files changed, 28 insertions(+), 5 deletions(-)
> ---
> base-commit: a13b500946e5dc467976838572b8ddd2fd777ca7
> change-id: 20261028-kpagecgroup-split-8a749c6ee27e
>
> Best regards,
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 1/2] mm/huge_memory: set memcg_data before a split page leaves the folio
2026-11-04 16:33 ` Zi Yan
2026-11-05 1:06 ` Daejun Park
@ 2026-12-01 5:24 ` Andrew Morton
2026-12-01 5:25 ` + mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio-fix.patch added to mm-new branch Andrew Morton
2 siblings, 0 replies; 17+ messages in thread
From: Andrew Morton @ 2026-12-01 5:24 UTC (permalink / raw)
To: Zi Yan
Cc: daejun7.park, 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, linux-mm, cgroups, linux-kernel, stable
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
_
^ permalink raw reply [flat|nested] 17+ messages in thread
* + mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio.patch added to mm-new branch
2026-11-04 9:59 ` Daejun Park via B4 Relay
(?)
(?)
@ 2026-12-01 5:25 ` Andrew Morton
2026-12-01 10:38 ` David Hildenbrand (Arm)
-1 siblings, 1 reply; 17+ messages in thread
From: Andrew Morton @ 2026-12-01 5:25 UTC (permalink / raw)
To: mm-commits, ziy, willy, vbabka, usama.arif, surenb, stable,
shakeel.butt, ryan.roberts, roman.gushchin, nico.pache,
muchun.song, mhocko, liam, lance.yang, kas, hannes, escape,
dev.jain, david, brendan.jackman, baolin.wang, baohua,
daejun7.park, akpm
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 <daejun7.park@samsung.com>
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 <daejun7.park@samsung.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reported-by: Tao Yi <escape@deepseek.com>
Closes: https://lore.kernel.org/all/20260907124001.1544655-1-escape@deepseek.com/
Reviewed-by: Zi Yan <ziy@nvidia.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: David Hildenbrand <david@kernel.org>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Nico Pache <nico.pache@linux.dev>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Usama Arif <usama.arif@linux.dev>
Cc: Kiryl Shutsemau <kas@kernel.org>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Brendan Jackman <brendan.jackman@linux.dev>
Cc: <stable@vger.kernel.org>
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
^ permalink raw reply [flat|nested] 17+ messages in thread
* + mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio-fix.patch added to mm-new branch
2026-11-04 16:33 ` Zi Yan
2026-11-05 1:06 ` Daejun Park
2026-12-01 5:24 ` Andrew Morton
@ 2026-12-01 5:25 ` Andrew Morton
2026-12-01 15:07 ` Zi Yan
2 siblings, 1 reply; 17+ messages in thread
From: Andrew Morton @ 2026-12-01 5:25 UTC (permalink / raw)
To: mm-commits, ziy, willy, vbabka, usama.arif, surenb, shakeel.butt,
ryan.roberts, roman.gushchin, nico.pache, muchun.song, mhocko,
liam, lance.yang, kas, hannes, escape, dev.jain, david,
daejun7.park, brendan.jackman, baolin.wang, baohua, akpm
The patch titled
Subject: mm/huge_memory: explain memcg_data ordering during a folio split
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-fix.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-fix.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: Andrew Morton <akpm@linux-foundation.org>
Subject: mm/huge_memory: explain memcg_data ordering during a folio split
Date: Mon, 30 Nov 2026 21:14:59 -0800
update comment, per Zi
Link: https://lore.kernel.org/r/DMMKKOIGA9UJ.353PCUUMFLCCJ@nvidia.com
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Daejun Park <daejun7.park@samsung.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Brendan Jackman <brendan.jackman@linux.dev>
Cc: David Hildenbrand <david@kernel.org>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Kiryl Shutsemau <kas@kernel.org>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Nico Pache <nico.pache@linux.dev>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Tao Yi <escape@deepseek.com>
Cc: Usama Arif <usama.arif@linux.dev>
Cc: Vlastimil Babka <vbabka@kernel.org>
mm/huge_memory.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
--- a/mm/huge_memory.c~mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio-fix
+++ 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
_
Patches currently in -mm which might be from akpm@linux-foundation.org are
mm-vma-drop-mm-asynchronously-in-vma_start_read-fix.patch
mm-vma-drop-mm-asynchronously-in-vma_start_read-fix-2.patch
kselftest-mm-rename-read_pmd_pagesize-to-pmd_psize-fix.patch
selftests-mm-check-madv_cold-and-madv_pageout-on-partly-advised-thps-fix.patch
selftests-mm-add-uffdio_move-huge-zeropage-pmd-regression-test-fix.patch
selftests-mm-allocate-nr_pages-based-on-pmd-size-for-uffd-pmd_move-tests-fix.patch
selftests-mm-retain-move-pmd-coverage-and-verify-huge-pmds.patch
lib-test_xarray-check-unused-spare-node-after-range-creation.patch
mm-memory-failure-dont-unpoison-a-leaked-raw_hwp_unreliable-folio-fix.patch
mm-hugetlb-delay-anon-folio-rmap-removal-until-after-the-tlb-flush-fix.patch
mm-hugetlb-delay-anon-folio-rmap-removal-until-after-the-tlb-flush-fix-2.patch
mm-vmstat_kunit-add-synthetic-benchmark-for-mm-stats-fix.patch
mm-prevent-pre-content-bypass-through-mremap-and-remap_file_pages.patch
afs-do-not-put-error-pointer-after-address-lookup-failure.patch
selftests-mm-check-that-fsync-reports-hard-poisoned-dirty-page-cache.patch
selftests-mm-memory-failure-truncate-poisoned-fuse-page-cache-before-teardown.patch
selftests-mm-memory-failure-skip-poisoned-dirty-page-cache-on-nilfs2.patch
selftest-mm-memory-failure-keep-page-cache-files-linked-until-cleanup.patch
selftest-mm-memory-failure-keep-page-cache-files-linked-until-cleanup-fix.patch
selftests-mm-memory-failure-skip-hard-dirty-page-cache-test-on-cephfs.patch
selftests-mm-memory-failure-close-dirty-page-cache-files-before-unlinking-them.patch
selftests-mm-memory-failure-extend-page-cache-test-files-with-pwrite.patch
selftests-mm-memory-failure-write-the-whole-page-cache-test-file-for-omfs.patch
selftests-mm-memory-failure-accept-eio-from-close-after-poisoning-dirty-data.patch
alloc_tag-introduce-ioctls-to-toggle-allocation-tracepoints-fix-fix.patch
alloc_tag-introduce-ioctls-to-toggle-allocation-tracepoints-fix.patch
mm-vmscan-scope-freeze-writeback-skip-to-the-reclaim-target.patch
mm-vmscan-scope-freeze-writeback-skip-to-the-reclaim-target-fix.patch
mm-hmm-refuse-secretmem-vmas-in-hmm_range_fault-fix.patch
mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio-fix.patch
ocfs2-unregister-the-jbd2-shrinker-before-journal-shutdown.patch
ipc-msg-clamp-negative-msg_info-usage-counts.patch
squashfs-fix-leaked-page-locks-when-page-actor-allocation-fails-fix.patch
ocfs2-skip-network-flush-when-no-domain-handlers-are-registered.patch
selftests-ptrace-check-that-ptrace_set_syscall_info-rejects-invalid-error-values-fix.patch
lib-atomic64-separate-hashed-locks-by-smp-cache-line.patch
nvdimm-btt-separate-map-locks-by-smp-cache-line.patch
percpu_ref-replace-the-global-switch-lock-with-hashed-locks-fix.patch
kernfs-fix-a-race-on-the-count-of-mmapped-files.patch
kernfs-path-lookup-scalability-improvements.patch
kernfs-make-getattr-lockless.patch
fs-move-kernfs_mode_permission-into-the-vfs.patch
fs-share-the-dac-override-checks-of-generic_permission-and-generic_mode_permission.patch
kernfs-open-and-close-plain-files-without-the-open-file-mutex.patch
kernfs-open-and-close-files-with-release-without-the-open-file-mutex.patch
kernfs-take-kernfs_rwsem-once-per-batch-of-entries-in-readdir.patch
kernfs-cache-symlink-bodies-and-follow-symlinks-in-rcu-walk.patch
drivers-media-v4l2-core-v4l2-vp9c-reduce-inlining.patch
^ permalink raw reply [flat|nested] 17+ messages in thread
* + mm-page_owner-also-check-pagetail-before-reading-memcg_data.patch added to mm-new branch
2026-11-04 9:59 ` Daejun Park via B4 Relay
(?)
(?)
@ 2026-12-01 5:25 ` Andrew Morton
-1 siblings, 0 replies; 17+ messages in thread
From: Andrew Morton @ 2026-12-01 5:25 UTC (permalink / raw)
To: mm-commits, ziy, willy, vbabka, usama.arif, surenb, shakeel.butt,
ryan.roberts, roman.gushchin, nico.pache, muchun.song, mhocko,
liam, lance.yang, kas, hannes, escape, dev.jain, david,
brendan.jackman, baolin.wang, baohua, daejun7.park, akpm
The patch titled
Subject: mm/page_owner: also check PageTail before reading memcg_data
has been added to the -mm mm-new branch. Its filename is
mm-page_owner-also-check-pagetail-before-reading-memcg_data.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-page_owner-also-check-pagetail-before-reading-memcg_data.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 <daejun7.park@samsung.com>
Subject: mm/page_owner: also check PageTail before reading memcg_data
Date: Wed, 04 Nov 2026 18:59:09 +0900
print_page_owner_memcg() loads memcg_data before it tests PageTail(). In
the first tail page, memcg_data holds the folio's _nr_pages. A split can
make the page a folio between the two loads. The stale _nr_pages then
passes the PageTail() test and is used as an objcg pointer.
__split_folio_to_order() stores memcg_data before the smp_wmb() that
precedes clear_compound_head(). Also test PageTail() before the load,
with a paired smp_rmb(). Keep the test after the load for a page that
becomes a tail in between.
Link: https://patch.msgid.link/20261104-kpagecgroup-split-v1-2-f70e947fec85@samsung.com
Fixes: 4996fc547f5b ("mm: let _folio_nr_pages overlay memcg_data in first tail page")
Signed-off-by: Daejun Park <daejun7.park@samsung.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Cc: Tao Yi <escape@deepseek.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: David Hildenbrand <david@kernel.org>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Nico Pache <nico.pache@linux.dev>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Usama Arif <usama.arif@linux.dev>
Cc: Kiryl Shutsemau <kas@kernel.org>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Brendan Jackman <brendan.jackman@linux.dev>
mm/page_owner.c | 7 +++++++
1 file changed, 7 insertions(+)
--- a/mm/page_owner.c~mm-page_owner-also-check-pagetail-before-reading-memcg_data
+++ a/mm/page_owner.c
@@ -564,6 +564,13 @@ static inline int print_page_owner_memcg
char name[80];
rcu_read_lock();
+ if (PageTail(page))
+ goto out_unlock;
+ /*
+ * Order the memcg_data load after the PageTail() load. Pairs with
+ * smp_wmb() in __split_folio_to_order().
+ */
+ smp_rmb();
memcg_data = READ_ONCE(page->memcg_data);
if (!memcg_data || PageTail(page))
goto out_unlock;
_
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
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: + mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio.patch added to mm-new branch
2026-12-01 5:25 ` + mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio.patch " Andrew Morton
@ 2026-12-01 10:38 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 17+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-01 10:38 UTC (permalink / raw)
To: Andrew Morton, mm-commits, ziy, willy, vbabka, usama.arif, surenb,
stable, shakeel.butt, ryan.roberts, roman.gushchin, nico.pache,
muchun.song, mhocko, liam, lance.yang, kas, hannes, escape,
dev.jain, brendan.jackman, baolin.wang, baohua, daejun7.park
On 12/1/26 06:25, Andrew Morton wrote:
> 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 <daejun7.park@samsung.com>
> 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 <daejun7.park@samsung.com>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> Reported-by: Tao Yi <escape@deepseek.com>
> Closes: https://lore.kernel.org/all/20260907124001.1544655-1-escape@deepseek.com/
> Reviewed-by: Zi Yan <ziy@nvidia.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Michal Hocko <mhocko@kernel.org>
> Cc: Roman Gushchin <roman.gushchin@linux.dev>
> Cc: Shakeel Butt <shakeel.butt@linux.dev>
> Cc: Muchun Song <muchun.song@linux.dev>
> Cc: David Hildenbrand <david@kernel.org>
> Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
> Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
> Cc: Liam R. Howlett <liam@infradead.org>
> Cc: Nico Pache <nico.pache@linux.dev>
> Cc: Ryan Roberts <ryan.roberts@arm.com>
> Cc: Dev Jain <dev.jain@arm.com>
> Cc: Barry Song <baohua@kernel.org>
> Cc: Lance Yang <lance.yang@linux.dev>
> Cc: Usama Arif <usama.arif@linux.dev>
> Cc: Kiryl Shutsemau <kas@kernel.org>
> Cc: Vlastimil Babka <vbabka@kernel.org>
> Cc: Suren Baghdasaryan <surenb@google.com>
> Cc: Brendan Jackman <brendan.jackman@linux.dev>
> Cc: <stable@vger.kernel.org>
>
> mm/huge_memory.c | 17 +++++++++++++----
> mm/memcontrol.c | 9 ++++++++-
> 2 files changed, 21 insertions(+), 5 deletions(-)
>
Ack, let's take this through your tree.
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: + mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio-fix.patch added to mm-new branch
2026-12-01 5:25 ` + mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio-fix.patch added to mm-new branch Andrew Morton
@ 2026-12-01 15:07 ` Zi Yan
0 siblings, 0 replies; 17+ messages in thread
From: Zi Yan @ 2026-12-01 15:07 UTC (permalink / raw)
To: Andrew Morton
Cc: mm-commits, willy, vbabka, usama.arif, surenb, shakeel.butt,
ryan.roberts, roman.gushchin, nico.pache, muchun.song, mhocko,
liam, lance.yang, kas, hannes, escape, dev.jain, david,
daejun7.park, brendan.jackman, baolin.wang, baohua
On 1 Dec 2026, at 0:25, Andrew Morton wrote:
> The patch titled
> Subject: mm/huge_memory: explain memcg_data ordering during a folio split
> 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-fix.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-fix.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: Andrew Morton <akpm@linux-foundation.org>
> Subject: mm/huge_memory: explain memcg_data ordering during a folio split
> Date: Mon, 30 Nov 2026 21:14:59 -0800
>
> update comment, per Zi
>
> Link: https://lore.kernel.org/r/DMMKKOIGA9UJ.353PCUUMFLCCJ@nvidia.com
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> Cc: Daejun Park <daejun7.park@samsung.com>
> Cc: Zi Yan <ziy@nvidia.com>
> Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
> Cc: Barry Song <baohua@kernel.org>
> Cc: Brendan Jackman <brendan.jackman@linux.dev>
> Cc: David Hildenbrand <david@kernel.org>
> Cc: Dev Jain <dev.jain@arm.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Kiryl Shutsemau <kas@kernel.org>
> Cc: Lance Yang <lance.yang@linux.dev>
> Cc: Liam R. Howlett <liam@infradead.org>
> Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
> Cc: Michal Hocko <mhocko@kernel.org>
> Cc: Muchun Song <muchun.song@linux.dev>
> Cc: Nico Pache <nico.pache@linux.dev>
> Cc: Roman Gushchin <roman.gushchin@linux.dev>
> Cc: Ryan Roberts <ryan.roberts@arm.com>
> Cc: Shakeel Butt <shakeel.butt@linux.dev>
> Cc: Suren Baghdasaryan <surenb@google.com>
> Cc: Tao Yi <escape@deepseek.com>
> Cc: Usama Arif <usama.arif@linux.dev>
> Cc: Vlastimil Babka <vbabka@kernel.org>
>
> mm/huge_memory.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> --- a/mm/huge_memory.c~mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio-fix
> +++ 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
Thanks.
Reviewed-by: Zi Yan <ziy@nvidia.com>
Best Regards,
Yan, Zi
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 1/2] mm/huge_memory: set memcg_data before a split page leaves the folio
2026-11-04 9:59 ` Daejun Park via B4 Relay
` (2 preceding siblings ...)
(?)
@ 2026-12-01 18:03 ` David Hildenbrand (Arm)
-1 siblings, 0 replies; 17+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-01 18:03 UTC (permalink / raw)
To: daejun7.park, Andrew Morton
Cc: Tao Yi, Johannes Weiner, Michal Hocko, Roman Gushchin,
Shakeel Butt, Muchun Song, Zi Yan, 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, linux-mm, cgroups,
linux-kernel, stable
On 11/4/26 10:59, 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 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().
>
> Fixes: fa23a338de93 ("mm: separate folio_split_memcg_refs() from split_page_memcg()")
> Reported-by: Tao Yi <escape@deepseek.com>
> Closes: https://lore.kernel.org/all/20260907124001.1544655-1-escape@deepseek.com/
> Cc: stable@vger.kernel.org
> Signed-off-by: Daejun Park <daejun7.park@samsung.com>
> ---
> Tested on x86_64 with KASAN (7.3-rc7 and mm-hotfixes-unstable) in an
> 8-vCPU QEMU guest: six threads read /proc/kpagecgroup for page 1 of 64
> THPs that debugfs split_huge_pages splits to order 0. Base oopsed in 6
> of 6 runs, 4 of them within 1.5 s. With patch 1, 8 runs of 300 s had
> no oops.
>
> Before 7.4, page_cgroup_ino() and folio_memcg_check() take non-const
> pointers, so a stable backport needs "struct folio *folio" there. The
> hunk applies to those trees without a conflict, and the build then
> fails with CONFIG_WERROR=y (-Wdiscarded-qualifiers).
> ---
> mm/huge_memory.c | 17 +++++++++++++----
> mm/memcontrol.c | 9 ++++++++-
> 2 files changed, 21 insertions(+), 5 deletions(-)
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 14599d0fff..adc5a47ee7 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -3768,7 +3768,19 @@ static void __split_folio_to_order(struct folio *folio, int old_order,
> 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();
>
> /*
> @@ -3803,9 +3815,6 @@ static void __split_folio_to_order(struct folio *folio, int old_order,
> 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));
> }
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 84f4a8fd4d..c244d56446 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -375,12 +375,19 @@ struct cgroup_subsys_state *get_mem_cgroup_css_from_folio(const struct folio *fo
> */
> 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);
>
Looking at sashiko reports, we have something related (although less relevant
because /proc/kpagecgroup I assume):
In page_cgroup_ino() in mm/memcontrol.c, locklessly inspecting a struct
page via /proc/kpagecgroup races with concurrent compound page preparation
of order >= 3, causing folio_memcg_check() to misinterpret the compound
page count as an obj_cgroup pointer:
CPU 0 (/proc/kpagecgroup read) CPU 1 (compound page allocation)
------------------------------ --------------------------------
kpagecgroup_read()
page_cgroup_ino(page) // page = head + 1
folio = page_folio(page);
// sees non-tail page, returns (struct folio *)page
prep_compound_page(head, order)
prep_compound_tail(head + 1, ...)
prep_compound_head(head, order)
folio_set_order(head_folio, order)
head_folio->_nr_pages = 1U << order;
folio_memcg_check(folio)
memcg_data = READ_ONCE(folio->memcg_data);
// reads 1U << order from overlaid _nr_pages
objcg = (void *)(memcg_data & ~OBJEXTS_FLAGS_MASK);
obj_cgroup_memcg(objcg)
return objcg->memcg; // invalid pointer dereference
When page_cgroup_ino() inspects an unreferenced page at PFN head + 1
before prep_compound_tail() marks it as a tail page (or when prep_compound_tail()
and folio_set_order() are reordered), page_folio() returns the page itself
as a folio. If that page is concurrently initialized as the first tail
page of a compound folio via folio_set_order(), writing head_folio->_nr_pages
(1U << order) overwrites the memory overlaying folio->memcg_data in the
first tail page. Because page_cgroup_ino() does not revalidate that the
page is not a tail page after reading folio->memcg_data, and the low 3
flag bits (OBJEXTS_FLAGS_MASK) of 1U << order are zero for orders >= 3,
folio_memcg_check() casts the page count to a struct obj_cgroup pointer
and passes it to obj_cgroup_memcg(), resulting in a kernel oops when
dereferencing objcg->memcg.
Daejun,can you take care of this as well?
--
Cheers,
David
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2026-12-01 18:03 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-04 9:59 [PATCH 0/2] mm: fix memcg_data reads during a THP split Daejun Park
2026-11-04 9:59 ` 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
2026-11-04 9:59 ` 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
2026-12-01 5:25 ` + mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio-fix.patch added to mm-new branch Andrew Morton
2026-12-01 15:07 ` Zi Yan
2026-12-01 5:25 ` + mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio.patch " Andrew Morton
2026-12-01 10:38 ` David Hildenbrand (Arm)
2026-12-01 18:03 ` [PATCH 1/2] mm/huge_memory: set memcg_data before a split page leaves the folio David Hildenbrand (Arm)
2026-11-04 9:59 ` [PATCH 2/2] mm/page_owner: also check PageTail before reading memcg_data Daejun Park
2026-11-04 9:59 ` Daejun Park via B4 Relay
2026-11-04 16:38 ` Zi Yan
2026-12-01 5:25 ` + mm-page_owner-also-check-pagetail-before-reading-memcg_data.patch added to mm-new branch Andrew Morton
2026-11-06 8:57 ` [PATCH 0/2] mm: fix memcg_data reads during a THP split Tao Yi
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.