[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20260118125311.e1894f598e2a8ef626f47f25@linux-foundation.org>
Date: Sun, 18 Jan 2026 12:53:11 -0800
From: Andrew Morton <akpm@...ux-foundation.org>
To: Deepanshu Kartikey <kartikey406@...il.com>
Cc: syzbot <syzbot+079a3b213add54dd18a7@...kaller.appspotmail.com>,
cgroups@...r.kernel.org, linux-kernel@...r.kernel.org, linux-mm@...ck.org,
mhocko@...nel.org, roman.gushchin@...ux.dev, shakeel.butt@...ux.dev,
syzkaller-bugs@...glegroups.com, Johannes Weiner <hannes@...xchg.org>,
Muchun Song <muchun.song@...ux.dev>, Minchan Kim <minchan@...nel.org>
Subject: Re: [syzbot] [cgroups?] [mm?] WARNING in memcg1_swapout
On Sun, 18 Jan 2026 12:31:43 +0530 Deepanshu Kartikey <kartikey406@...il.com> wrote:
> > >
> > > That's
> > >
> > > VM_WARN_ON_ONCE(oldid != 0);
> > >
> > > which was added by Deepanshu's "mm/swap_cgroup: fix kernel BUG in
> > > swap_cgroup_record".
> > >
> > > This patch has Fixes: 1a4e58cce84e ("mm: introduce MADV_PAGEOUT"),
> > > which is six years old. For some reason it has no cc:stable.
> > >
> > > Deepanshu's patch has no reviews.
> > >
> > > So can I please do the memcg maintainer summoning dance here? We have a
> > > repeatable BUG happening in mainline Linux.
> > >
> >
> > Hi Andrew,
> >
> > I checked the git blame output for commit 0f853ca2a798:
> >
> > Line 763: memcg1_swapout(folio, swap);
> > Line 764: __swap_cache_del_folio(ci, folio, swap, shadow);
> > (d7a7b2f91f36b - Kairui Song, 2026-01-13 02:33:36 +0800)
> >
> > Kairui's reordering patch appears to have been merged on Jan 13.
Eek, there are many patches, it helps to identify them carefully.
I think you're referring to
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-swap-use-swap-cache-as-the-swap-in-synchronize-layer-fix.patch
> > The syzbot report is also from Jan 13, likely from earlier in the
> > day before the reordering patch was merged.
> >
> > So this report is from before the fix. The warning should not appear
> > in linux-next builds after Jan 13.
> >
> > Thanks,
> >
> > Deepanshu
>
> Hi Andrew,
>
> I tested with the latest linux-next in sysbot. It is working fine
Great, thanks. But we still don't have review for this one.
For some reason I don't have cc:stable on this - could people
make a recommendation?
From: Deepanshu Kartikey <kartikey406@...il.com>
Subject: mm/swap_cgroup: fix kernel BUG in swap_cgroup_record
Date: Sat, 10 Jan 2026 12:16:13 +0530
When using MADV_PAGEOUT, pages can remain in swapcache with their swap
entries assigned. If MADV_PAGEOUT is called again on these pages, they
reuse the same swap entries, causing memcg1_swapout() to call
swap_cgroup_record() with an already-recorded entry.
The existing code assumes swap entries are always being recorded for the
first time (oldid == 0), triggering VM_BUG_ON when it encounters an
already-recorded entry:
------------[ cut here ]------------
kernel BUG at mm/swap_cgroup.c:78!
Oops: invalid opcode: 0000 [#1] SMP KASAN PTI
CPU: 0 UID: 0 PID: 6176 Comm: syz.0.30 Not tainted
RIP: 0010:swap_cgroup_record+0x19c/0x1c0 mm/swap_cgroup.c:78
Call Trace:
memcg1_swapout+0x2fa/0x830 mm/memcontrol-v1.c:623
__remove_mapping+0xac5/0xe30 mm/vmscan.c:773
shrink_folio_list+0x2786/0x4f40 mm/vmscan.c:1528
reclaim_folio_list+0xeb/0x4e0 mm/vmscan.c:2208
reclaim_pages+0x454/0x520 mm/vmscan.c:2245
madvise_cold_or_pageout_pte_range+0x19a0/0x1ce0 mm/madvise.c:563
...
do_madvise+0x1bc/0x270 mm/madvise.c:2030
__do_sys_madvise mm/madvise.c:2039
This bug occurs because pages in swapcache can be targeted by MADV_PAGEOUT
multiple times without being swapped in between. Each time, the same swap
entry is reused, but swap_cgroup_record() expects to only record new,
unused entries.
Fix this by checking if the swap entry already has the correct cgroup ID
recorded before attempting to record it. Use the existing
lookup_swap_cgroup_id() to read the current cgroup ID, and return early
from memcg1_swapout() if the entry is already correctly recorded. Only
call swap_cgroup_record() when the entry needs to be set or updated.
This approach avoids unnecessary atomic operations, reference count
manipulations, and statistics updates when the entry is already correct.
Link: https://syzkaller.appspot.com/bug?extid=d97580a8cceb9b03c13e
Link: https://lkml.kernel.org/r/20260110064613.606532-1-kartikey406@gmail.com
Fixes: 1a4e58cce84e ("mm: introduce MADV_PAGEOUT")
Signed-off-by: Deepanshu Kartikey <kartikey406@...il.com>
Reported-by: syzbot+d97580a8cceb9b03c13e@...kaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=d97580a8cceb9b03c13e
Tested-by: syzbot+d97580a8cceb9b03c13e@...kaller.appspotmail.com
Cc: Johannes Weiner <hannes@...xchg.org>
Cc: Michal Hocko <mhocko@...nel.org>
Cc: Muchun Song <muchun.song@...ux.dev>
Cc: Roman Gushchin <roman.gushchin@...ux.dev>
Cc: Shakeel Butt <shakeel.butt@...ux.dev>
Signed-off-by: Andrew Morton <akpm@...ux-foundation.org>
---
mm/memcontrol-v1.c | 11 +++++++++++
1 file changed, 11 insertions(+)
--- a/mm/memcontrol-v1.c~mm-swap_cgroup-fix-kernel-bug-in-swap_cgroup_record
+++ a/mm/memcontrol-v1.c
@@ -592,6 +592,7 @@ void memcg1_swapout(struct folio *folio,
{
struct mem_cgroup *memcg, *swap_memcg;
unsigned int nr_entries;
+ unsigned short oldid;
VM_BUG_ON_FOLIO(folio_test_lru(folio), folio);
VM_BUG_ON_FOLIO(folio_ref_count(folio), folio);
@@ -609,6 +610,16 @@ void memcg1_swapout(struct folio *folio,
return;
/*
+ * Check if this swap entry is already recorded. This can happen
+ * when MADV_PAGEOUT is called multiple times on pages that remain
+ * in swapcache, reusing the same swap entries.
+ */
+ oldid = lookup_swap_cgroup_id(entry);
+ if (oldid == mem_cgroup_id(memcg))
+ return;
+ VM_WARN_ON_ONCE(oldid != 0);
+
+ /*
* In case the memcg owning these pages has been offlined and doesn't
* have an ID allocated to it anymore, charge the closest online
* ancestor for the swap instead and transfer the memory+swap charge.
_
Powered by blists - more mailing lists