* + mm-mglru-splice-all-generations-when-reparenting-a-memcg.patch added to mm-hotfixes-unstable branch
@ 2026-11-11 19:03 Andrew Morton
0 siblings, 0 replies; only message in thread
From: Andrew Morton @ 2026-11-11 19:03 UTC (permalink / raw)
To: mm-commits, stable, ryncsn, qi.zheng, noah, kasong, hannes, david,
baohua, shakeel.butt, akpm
The patch titled
Subject: mm: mglru: splice all generations when reparenting a memcg
has been added to the -mm mm-hotfixes-unstable branch. Its filename is
mm-mglru-splice-all-generations-when-reparenting-a-memcg.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-mglru-splice-all-generations-when-reparenting-a-memcg.patch
This patch will later appear in the mm-hotfixes-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
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: Shakeel Butt <shakeel.butt@linux.dev>
Subject: mm: mglru: splice all generations when reparenting a memcg
Date: Tue, 10 Nov 2026 16:09:13 -0800
Noah reported list_del corruption on single-node hosts running 7.2.11,
which already has commit bf4ade7dbd76 ("memcg: keep folio's objcg same as
its node"). The bad pointer is an MGLRU list head in a freed
mem_cgroup_per_node:
slab mem_cgroup_per_node start ff31bfa36a3c9e00 pointer offset 528 size 1920
list_del corruption. next->prev should be ffacf881ccc70e08, but was ff31bfa36a3ca010. (next=ff31bfa36a3ca010)
When a memcg goes offline, __lru_gen_reparent_memcg() moves its MGLRU
lists to the parent. It moves only the generations (gens) from min_seq to
max_seq, and it puts each list at the same index in the parent.
A folio's gen in folio->flags can be ahead of the list it is on. In the
parent, the same index can stand for an older gen, so the folio's gen can
end up older than its list. Once the parent's min_seq passes that gen,
sort_folio() puts the folio on the list for max_seq + 1, where it stays
until the next aging.
If the parent goes offline before that aging, the folio is not moved to
the grandparent. It stays on the parent's list after the parent is freed,
and the next list_del() on it touches freed memory. This needs two
cgroups on one branch to go offline one after the other, such as a
container and then its pod.
The parent always has MAX_NR_GENS gens at this point, so every index is
valid in it. Move all MAX_NR_GENS lists, not only the gens from min_seq
to max_seq.
A reproducer that drives these steps through the lru_gen debugfs file gets
a KASAN use-after-free on the freed mem_cgroup_per_node without this
patch, and no report with it.
Link: https://lore.kernel.org/20261111000913.22943-1-shakeel.butt@linux.dev
Fixes: f304652609ea ("mm: vmscan: prepare for reparenting MGLRU folios")
Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reported-by: Noah Feldt <noah@feldt.systems>
Closes: https://lore.kernel.org/all/20261110132853.71228-1-noah@feldt.systems/
Reviewed-by: Kairui Song <kasong@tencent.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Qi Zheng <qi.zheng@linux.dev>
Cc: Barry Song <baohua@kernel.org>
Cc: Kairui Song <ryncsn@gmail.com>
Cc: <stable@vger.kernel.org>
---
mm/vmscan.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
--- a/mm/vmscan.c~mm-mglru-splice-all-generations-when-reparenting-a-memcg
+++ a/mm/vmscan.c
@@ -4752,19 +4752,25 @@ void max_lru_gen_memcg(struct mem_cgroup
* The same generation has different meanings in the parent and child memcg,
* so this compromise method will cause the LRU inversion problem. But as the
* system runs, this problem will be fixed automatically.
+ *
+ * Move all MAX_NR_GENS lists, not only the gens from min_seq to max_seq.
+ * An earlier reparenting can leave a folio whose gen is older than the list
+ * it is on. Once min_seq passes that gen, sort_folio() puts the folio on the
+ * list for max_seq + 1, where it stays until the next aging. If that list
+ * were skipped, the folio would stay behind on a memcg that is about to be
+ * freed. The parent has MAX_NR_GENS gens here, so every index is valid in it.
*/
static void __lru_gen_reparent_memcg(struct lruvec *child_lruvec, struct lruvec *parent_lruvec,
int zone, int type)
{
struct lru_gen_folio *child_lrugen, *parent_lrugen;
enum lru_list lru = type * LRU_INACTIVE_FILE;
- int i;
+ int gen;
child_lrugen = &child_lruvec->lrugen;
parent_lrugen = &parent_lruvec->lrugen;
- for (i = 0; i < get_nr_gens(child_lruvec, type); i++) {
- int gen = lru_gen_from_seq(child_lrugen->max_seq - i);
+ for (gen = 0; gen < MAX_NR_GENS; gen++) {
long nr_pages = child_lrugen->nr_pages[gen][type][zone];
int child_lru_active = lru_gen_is_active(child_lruvec, gen) ? LRU_ACTIVE : 0;
int parent_lru_active = lru_gen_is_active(parent_lruvec, gen) ? LRU_ACTIVE : 0;
_
Patches currently in -mm which might be from shakeel.butt@linux.dev are
mm-mglru-splice-all-generations-when-reparenting-a-memcg.patch
memcg-move-memoryhigh-enforcement-out-of-try_charge_memcg.patch
memcg-force-charges-from-reclaim-before-trying-the-limits.patch
memcg-use-high_work-for-kernel-threads.patch
memcg-use-high_work-for-remote-charges.patch
memcg-simplify-high-limit-handling-after-a-charge.patch
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-11 19:03 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-11 19:03 + mm-mglru-splice-all-generations-when-reparenting-a-memcg.patch added to mm-hotfixes-unstable branch Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox