Skip to contentSkip to conversation

WARNING in __mod_zone_page_state

syzbot syzbot 4 participants 9 messages Aug 29 – Aug 31

Subsystems (2)
lore
Share & tools
lore

syzbot

author syzbot
#0 lore raw

Hello,

syzbot found the following issue on:

HEAD commit:    818bebeb63dd drm/xe: Don't hand out the flat CCS storage a..
git tree:       git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=10286d79580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=ccca94d2c01b9e78
dashboard link: https://syzkaller.appspot.com/bug?extid=cd2073ee6d958a8d0fcd
compiler:       gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=13cf7625580000

IMPORTANT: if you fix the issue, please add the following tag to the commit:

Reported-by [email protected]

smpboot: CPU 1 is now offline

------------[ cut here ]------------
IS_ENABLED(CONFIG_PREEMPT_COUNT) && __lockdep_enabled && (preempt_count() == 0 && this_cpu_read(hardirqs_enabled))
WARNING: mm/vmstat.c:361 at __mod_zone_page_state+0x96/0x190 mm/vmstat.c:361, CPU#2: syz-executor412/6040
Modules linked in:
CPU: 2 UID: 0 PID: 6040 Comm: syz-executor412 Not tainted syzkaller #0 PREEMPT(full) 
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:__mod_zone_page_state+0x96/0x190 mm/vmstat.c:361
Code: d0 00 00 00 8b 05 3e 44 ea 0e 85 c0 74 1f 65 8b 05 87 e0 2e 12 65 0b 05 d0 99 2e 12 75 0f 65 8b 05 d3 db 2e 12 85 c0 74 04 90 <0f> 0b 90 48 c7 c7 c0 e7 ff 8b e8 3b b3 6d 09 65 48 0f be 5d 00 48
RSP: 0018:ffffc9000627f8e0 EFLAGS: 00010202
RAX: 0000000000000001 RBX: 0000000000000000 RCX: 1ffffffff2287150
RDX: 0000000000000000 RSI: 0000000000000008 RDI: ffff88807ffd79b8
RBP: ffffffff9489f448 R08: 0000000000000001 R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000000 R12: ffffffffffffffff
R13: 0000000000000008 R14: ffff88807ffd7940 R15: ffffffff9489f440
FS:  00005555785ce400(0000) GS:ffff8880d5da2000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00005608d531ffb8 CR3: 000000002cb7c000 CR4: 0000000000352ef0
Call Trace:
 <TASK>
 __zone_stat_mod_folio include/linux/vmstat.h:410 [inline]
 __munlock_folio mm/mlock.c:144 [inline]
 mlock_folio_batch+0xf97/0x36e0 mm/mlock.c:204
 mlock_drain_remote+0xe5/0x140 mm/mlock.c:230
 page_alloc_cpu_dead+0x16/0x130 mm/page_alloc.c:6468
 cpuhp_invoke_callback+0x3b4/0x9a0 kernel/cpu.c:194
 __cpuhp_invoke_callback_range+0x158/0x1d0 kernel/cpu.c:972
 cpuhp_invoke_callback_range kernel/cpu.c:996 [inline]
 cpuhp_down_callbacks kernel/cpu.c:1386 [inline]
 _cpu_down+0x523/0x1020 kernel/cpu.c:1457
 cpu_down_maps_locked kernel/cpu.c:1483 [inline]
 cpu_down kernel/cpu.c:1491 [inline]
 cpu_device_down+0x82/0xc0 kernel/cpu.c:1508
 device_offline drivers/base/core.c:4283 [inline]
 device_offline+0x2f4/0x400 drivers/base/core.c:4267
 online_store+0xd1/0x180 drivers/base/core.c:2883
 dev_attr_store+0x58/0x80 drivers/base/core.c:2509
 sysfs_kf_write+0xf2/0x150 fs/sysfs/file.c:145
 kernfs_fop_write_iter+0x3e0/0x5f0 fs/kernfs/file.c:345
 new_sync_write fs/read_write.c:595 [inline]
 vfs_write+0x6af/0x1050 fs/read_write.c:687
 ksys_write+0x12a/0x250 fs/read_write.c:739
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x123/0x790 arch/x86/entry/syscall_64.c:84
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f90996d005e
Code: 08 0f 85 f5 e2 ff ff 49 89 fb 48 89 f0 48 89 d7 48 89 ce 4c 89 c2 4d 89 ca 4c 8b 44 24 08 4c 8b 4c 24 10 4c 89 5c 24 08 0f 05 <c3> 90 41 57 41 56 4d 89 c6 41 55 4d 89 cd 41 54 55 53 48 83 ec 08
RSP: 002b:00007ffd7eb94578 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00005555785ce400 RCX: 00007f90996d005e
RDX: 0000000000000002 RSI: 00007f90997150ff RDI: 0000000000000003
RBP: 00007f90997175e0 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007f9099717578
R13: 00007f909971509a R14: 00007f90997150b9 R15: 0000000000000002
 </TASK>

---
This report is generated by a bot. It may contain errors. See https://goo.gl/tpsmEJ for more information about syzbot. syzbot engineers can be reached at [email protected].

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.

If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup

#1 lore raw
Quoted 31 lines · syzbot

Hello,

syzbot found the following issue on:

HEAD commit:    818bebeb63dd drm/xe: Don't hand out the flat CCS storage a..
git tree:       git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=10286d79580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=ccca94d2c01b9e78
dashboard link: https://syzkaller.appspot.com/bug?extid=cd2073ee6d958a8d0fcd
compiler:       gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=13cf7625580000

IMPORTANT: if you fix the issue, please add the following tag to the commit:

Reported-by [email protected]

smpboot: CPU 1 is now offline

------------[ cut here ]------------
IS_ENABLED(CONFIG_PREEMPT_COUNT) && __lockdep_enabled && (preempt_count() == 0 && this_cpu_read(hardirqs_enabled))
WARNING: mm/vmstat.c:361 at __mod_zone_page_state+0x96/0x190 mm/vmstat.c:361, CPU#2: syz-executor412/6040
Modules linked in:
CPU: 2 UID: 0 PID: 6040 Comm: syz-executor412 Not tainted syzkaller #0 PREEMPT(full) 
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:__mod_zone_page_state+0x96/0x190 mm/vmstat.c:361
Code: d0 00 00 00 8b 05 3e 44 ea 0e 85 c0 74 1f 65 8b 05 87 e0 2e 12 65 0b 05 d0 99 2e 12 75 0f 65 8b 05 d3 db 2e 12 85 c0 74 04 90 <0f> 0b 90 48 c7 c7 c0 e7 ff 8b e8 3b b3 6d 09 65 48 0f be 5d 00 48
RSP: 0018:ffffc9000627f8e0 EFLAGS: 00010202
RAX: 0000000000000001 RBX: 0000000000000000 RCX: 1ffffffff2287150
RDX: 0000000000000000 RSI: 0000000000000008 RDI: ffff88807ffd79b8
RBP: ffffffff9489f448 R08: 0000000000000001 R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000000 R12: ffffffffffffffff
R13: 0000000000000008 R14: ffff88807ffd7940 R15: ffffffff9489f440
FS:  00005555785ce400(0000) GS:ffff8880d5da2000(0000) knlGS:0000000000000000
Quoted 8 lines
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00005608d531ffb8 CR3: 000000002cb7c000 CR4: 0000000000352ef0
Call Trace:
 <TASK>
 __zone_stat_mod_folio include/linux/vmstat.h:410 [inline]
 __munlock_folio mm/mlock.c:144 [inline]
 mlock_folio_batch+0xf97/0x36e0 mm/mlock.c:204
 mlock_drain_remote+0xe5/0x140 mm/mlock.c:230

So, we are calling stat update functions which requires preemption disabled (because they access per cpu data) an offlined CPU which is fine but we have warning that preemption is not disabled.

Let see if syzbot comes up with a reproducer. We can just simply take the local locks like neighboring functions or something else.

Quoted 56 lines
 page_alloc_cpu_dead+0x16/0x130 mm/page_alloc.c:6468
 cpuhp_invoke_callback+0x3b4/0x9a0 kernel/cpu.c:194
 __cpuhp_invoke_callback_range+0x158/0x1d0 kernel/cpu.c:972
 cpuhp_invoke_callback_range kernel/cpu.c:996 [inline]
 cpuhp_down_callbacks kernel/cpu.c:1386 [inline]
 _cpu_down+0x523/0x1020 kernel/cpu.c:1457
 cpu_down_maps_locked kernel/cpu.c:1483 [inline]
 cpu_down kernel/cpu.c:1491 [inline]
 cpu_device_down+0x82/0xc0 kernel/cpu.c:1508
 device_offline drivers/base/core.c:4283 [inline]
 device_offline+0x2f4/0x400 drivers/base/core.c:4267
 online_store+0xd1/0x180 drivers/base/core.c:2883
 dev_attr_store+0x58/0x80 drivers/base/core.c:2509
 sysfs_kf_write+0xf2/0x150 fs/sysfs/file.c:145
 kernfs_fop_write_iter+0x3e0/0x5f0 fs/kernfs/file.c:345
 new_sync_write fs/read_write.c:595 [inline]
 vfs_write+0x6af/0x1050 fs/read_write.c:687
 ksys_write+0x12a/0x250 fs/read_write.c:739
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x123/0x790 arch/x86/entry/syscall_64.c:84
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f90996d005e
Code: 08 0f 85 f5 e2 ff ff 49 89 fb 48 89 f0 48 89 d7 48 89 ce 4c 89 c2 4d 89 ca 4c 8b 44 24 08 4c 8b 4c 24 10 4c 89 5c 24 08 0f 05 <c3> 90 41 57 41 56 4d 89 c6 41 55 4d 89 cd 41 54 55 53 48 83 ec 08
RSP: 002b:00007ffd7eb94578 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00005555785ce400 RCX: 00007f90996d005e
RDX: 0000000000000002 RSI: 00007f90997150ff RDI: 0000000000000003
RBP: 00007f90997175e0 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007f9099717578
R13: 00007f909971509a R14: 00007f90997150b9 R15: 0000000000000002
 </TASK>

---
This report is generated by a bot. It may contain errors. See https://goo.gl/tpsmEJ for more information about syzbot. syzbot engineers can be reached at [email protected].

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.

If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup

#2 lore raw

+hugh

Quoted 41 lines · Shakeel Butt
Quoted 31 lines · syzbot

Hello,

syzbot found the following issue on:

HEAD commit:    818bebeb63dd drm/xe: Don't hand out the flat CCS storage a..
git tree:       git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=10286d79580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=ccca94d2c01b9e78
dashboard link: https://syzkaller.appspot.com/bug?extid=cd2073ee6d958a8d0fcd
compiler:       gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=13cf7625580000

IMPORTANT: if you fix the issue, please add the following tag to the commit:

Reported-by [email protected]

smpboot: CPU 1 is now offline

------------[ cut here ]------------
IS_ENABLED(CONFIG_PREEMPT_COUNT) && __lockdep_enabled && (preempt_count() == 0 && this_cpu_read(hardirqs_enabled))
WARNING: mm/vmstat.c:361 at __mod_zone_page_state+0x96/0x190 mm/vmstat.c:361, CPU#2: syz-executor412/6040
Modules linked in:
CPU: 2 UID: 0 PID: 6040 Comm: syz-executor412 Not tainted syzkaller #0 PREEMPT(full) 
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:__mod_zone_page_state+0x96/0x190 mm/vmstat.c:361
Code: d0 00 00 00 8b 05 3e 44 ea 0e 85 c0 74 1f 65 8b 05 87 e0 2e 12 65 0b 05 d0 99 2e 12 75 0f 65 8b 05 d3 db 2e 12 85 c0 74 04 90 <0f> 0b 90 48 c7 c7 c0 e7 ff 8b e8 3b b3 6d 09 65 48 0f be 5d 00 48
RSP: 0018:ffffc9000627f8e0 EFLAGS: 00010202
RAX: 0000000000000001 RBX: 0000000000000000 RCX: 1ffffffff2287150
RDX: 0000000000000000 RSI: 0000000000000008 RDI: ffff88807ffd79b8
RBP: ffffffff9489f448 R08: 0000000000000001 R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000000 R12: ffffffffffffffff
R13: 0000000000000008 R14: ffff88807ffd7940 R15: ffffffff9489f440
FS:  00005555785ce400(0000) GS:ffff8880d5da2000(0000) knlGS:0000000000000000
Quoted 8 lines
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00005608d531ffb8 CR3: 000000002cb7c000 CR4: 0000000000352ef0
Call Trace:
 <TASK>
 __zone_stat_mod_folio include/linux/vmstat.h:410 [inline]
 __munlock_folio mm/mlock.c:144 [inline]
 mlock_folio_batch+0xf97/0x36e0 mm/mlock.c:204
 mlock_drain_remote+0xe5/0x140 mm/mlock.c:230
Quoted 6 lines

So, we are calling stat update functions which requires preemption disabled (because they access per cpu data) an offlined CPU which is fine but we have warning that preemption is not disabled.

Let see if syzbot comes up with a reproducer. We can just simply take the local locks like neighboring functions or something else.

After looking deeper and it seems like __munlock_folio is the only one which have a code path where lru lock with irq disabled is not done before call __zone_stat_mod_folio. I think we can easily fix __munlock_folio without acquiring local_locks here.

Something like below. I will run some tests before proposing a formal patch.

mm/mlock.c +12 -3
index efa6716e4dfb..9ab8042671f1 100644
@@ -141,11 +141,20 @@ static struct lruvec *__munlock_folio(struct folio *folio, struct lruvec *lruvec
 
 munlock:
 	if (folio_test_clear_mlocked(folio)) {
-		__zone_stat_mod_folio(folio, NR_MLOCK, -nr_pages);
+		enum vm_event_item item;
+
 		if (isolated || !folio_test_unevictable(folio))
-			__count_vm_events(UNEVICTABLE_PGMUNLOCKED, nr_pages);
+			item = UNEVICTABLE_PGMUNLOCKED;
 		else
-			__count_vm_events(UNEVICTABLE_PGSTRANDED, nr_pages);
+			item = UNEVICTABLE_PGSTRANDED;
+
+		if (isolated) {
+			__zone_stat_mod_folio(folio, NR_MLOCK, -nr_pages);
+			__count_vm_events(item, nr_pages);
+		} else {
+			zone_stat_mod_folio(folio, NR_MLOCK, -nr_pages);
+			count_vm_events(item, nr_pages);
+		}
 	}
 
 	/* folio_evictable() has to be checked *after* clearing Mlocked */
#3 lore raw
Quoted 51 lines · Shakeel Butt

+hugh

Quoted 41 lines · Shakeel Butt
Quoted 31 lines · syzbot

Hello,

syzbot found the following issue on:

HEAD commit:    818bebeb63dd drm/xe: Don't hand out the flat CCS storage a..
git tree:       git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=10286d79580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=ccca94d2c01b9e78
dashboard link: https://syzkaller.appspot.com/bug?extid=cd2073ee6d958a8d0fcd
compiler:       gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=13cf7625580000

IMPORTANT: if you fix the issue, please add the following tag to the commit:

Reported-by [email protected]

smpboot: CPU 1 is now offline

------------[ cut here ]------------
IS_ENABLED(CONFIG_PREEMPT_COUNT) && __lockdep_enabled && (preempt_count() == 0 && this_cpu_read(hardirqs_enabled))
WARNING: mm/vmstat.c:361 at __mod_zone_page_state+0x96/0x190 mm/vmstat.c:361, CPU#2: syz-executor412/6040
Modules linked in:
CPU: 2 UID: 0 PID: 6040 Comm: syz-executor412 Not tainted syzkaller #0 PREEMPT(full) 
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:__mod_zone_page_state+0x96/0x190 mm/vmstat.c:361
Code: d0 00 00 00 8b 05 3e 44 ea 0e 85 c0 74 1f 65 8b 05 87 e0 2e 12 65 0b 05 d0 99 2e 12 75 0f 65 8b 05 d3 db 2e 12 85 c0 74 04 90 <0f> 0b 90 48 c7 c7 c0 e7 ff 8b e8 3b b3 6d 09 65 48 0f be 5d 00 48
RSP: 0018:ffffc9000627f8e0 EFLAGS: 00010202
RAX: 0000000000000001 RBX: 0000000000000000 RCX: 1ffffffff2287150
RDX: 0000000000000000 RSI: 0000000000000008 RDI: ffff88807ffd79b8
RBP: ffffffff9489f448 R08: 0000000000000001 R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000000 R12: ffffffffffffffff
R13: 0000000000000008 R14: ffff88807ffd7940 R15: ffffffff9489f440
FS:  00005555785ce400(0000) GS:ffff8880d5da2000(0000) knlGS:0000000000000000
Quoted 8 lines
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00005608d531ffb8 CR3: 000000002cb7c000 CR4: 0000000000352ef0
Call Trace:
 <TASK>
 __zone_stat_mod_folio include/linux/vmstat.h:410 [inline]
 __munlock_folio mm/mlock.c:144 [inline]
 mlock_folio_batch+0xf97/0x36e0 mm/mlock.c:204
 mlock_drain_remote+0xe5/0x140 mm/mlock.c:230
Quoted 6 lines

So, we are calling stat update functions which requires preemption disabled (because they access per cpu data) an offlined CPU which is fine but we have warning that preemption is not disabled.

Let see if syzbot comes up with a reproducer. We can just simply take the local locks like neighboring functions or something else.

Quoted 6 lines

After looking deeper and it seems like __munlock_folio is the only one which have a code path where lru lock with irq disabled is not done before call __zone_stat_mod_folio. I think we can easily fix __munlock_folio without acquiring local_locks here.

Something like below. I will run some tests before proposing a formal patch.

Thanks for looking into this, Shakeel, but I don't think complicating __munlock_folio() is at all the right fix. This is peculiar to the use by mlock_drain_remote(), isn't it? Which is not taking the usual local_lock because the CPU is going offline. I would say, just take the local_lock in mlock_drain_remote(), but (I haven't read the history) for all I know, there may be PREEMPT_RT reasons why that would be completely wrong.

Hugh

Quoted 29 lines
mm/mlock.c +12 -3
index efa6716e4dfb..9ab8042671f1 100644
@@ -141,11 +141,20 @@ static struct lruvec *__munlock_folio(struct folio *folio, struct lruvec *lruvec
 
 munlock:
 	if (folio_test_clear_mlocked(folio)) {
-		__zone_stat_mod_folio(folio, NR_MLOCK, -nr_pages);
+		enum vm_event_item item;
+
 		if (isolated || !folio_test_unevictable(folio))
-			__count_vm_events(UNEVICTABLE_PGMUNLOCKED, nr_pages);
+			item = UNEVICTABLE_PGMUNLOCKED;
 		else
-			__count_vm_events(UNEVICTABLE_PGSTRANDED, nr_pages);
+			item = UNEVICTABLE_PGSTRANDED;
+
+		if (isolated) {
+			__zone_stat_mod_folio(folio, NR_MLOCK, -nr_pages);
+			__count_vm_events(item, nr_pages);
+		} else {
+			zone_stat_mod_folio(folio, NR_MLOCK, -nr_pages);
+			count_vm_events(item, nr_pages);
+		}
 	}
 
 	/* folio_evictable() has to be checked *after* clearing Mlocked */
#4 lore raw
Quoted 60 lines · Hugh Dickins
Quoted 51 lines · Shakeel Butt

+hugh

Quoted 41 lines · Shakeel Butt
Quoted 31 lines · syzbot

Hello,

syzbot found the following issue on:

HEAD commit:    818bebeb63dd drm/xe: Don't hand out the flat CCS storage a..
git tree:       git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=10286d79580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=ccca94d2c01b9e78
dashboard link: https://syzkaller.appspot.com/bug?extid=cd2073ee6d958a8d0fcd
compiler:       gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=13cf7625580000

IMPORTANT: if you fix the issue, please add the following tag to the commit:

Reported-by [email protected]

smpboot: CPU 1 is now offline

------------[ cut here ]------------
IS_ENABLED(CONFIG_PREEMPT_COUNT) && __lockdep_enabled && (preempt_count() == 0 && this_cpu_read(hardirqs_enabled))
WARNING: mm/vmstat.c:361 at __mod_zone_page_state+0x96/0x190 mm/vmstat.c:361, CPU#2: syz-executor412/6040
Modules linked in:
CPU: 2 UID: 0 PID: 6040 Comm: syz-executor412 Not tainted syzkaller #0 PREEMPT(full) 
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:__mod_zone_page_state+0x96/0x190 mm/vmstat.c:361
Code: d0 00 00 00 8b 05 3e 44 ea 0e 85 c0 74 1f 65 8b 05 87 e0 2e 12 65 0b 05 d0 99 2e 12 75 0f 65 8b 05 d3 db 2e 12 85 c0 74 04 90 <0f> 0b 90 48 c7 c7 c0 e7 ff 8b e8 3b b3 6d 09 65 48 0f be 5d 00 48
RSP: 0018:ffffc9000627f8e0 EFLAGS: 00010202
RAX: 0000000000000001 RBX: 0000000000000000 RCX: 1ffffffff2287150
RDX: 0000000000000000 RSI: 0000000000000008 RDI: ffff88807ffd79b8
RBP: ffffffff9489f448 R08: 0000000000000001 R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000000 R12: ffffffffffffffff
R13: 0000000000000008 R14: ffff88807ffd7940 R15: ffffffff9489f440
FS:  00005555785ce400(0000) GS:ffff8880d5da2000(0000) knlGS:0000000000000000
Quoted 8 lines
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00005608d531ffb8 CR3: 000000002cb7c000 CR4: 0000000000352ef0
Call Trace:
 <TASK>
 __zone_stat_mod_folio include/linux/vmstat.h:410 [inline]
 __munlock_folio mm/mlock.c:144 [inline]
 mlock_folio_batch+0xf97/0x36e0 mm/mlock.c:204
 mlock_drain_remote+0xe5/0x140 mm/mlock.c:230
Quoted 6 lines

So, we are calling stat update functions which requires preemption disabled (because they access per cpu data) an offlined CPU which is fine but we have warning that preemption is not disabled.

Let see if syzbot comes up with a reproducer. We can just simply take the local locks like neighboring functions or something else.

Quoted 6 lines

After looking deeper and it seems like __munlock_folio is the only one which have a code path where lru lock with irq disabled is not done before call __zone_stat_mod_folio. I think we can easily fix __munlock_folio without acquiring local_locks here.

Something like below. I will run some tests before proposing a formal patch.

Quoted 8 lines

Thanks for looking into this, Shakeel, but I don't think complicating __munlock_folio() is at all the right fix. This is peculiar to the use by mlock_drain_remote(), isn't it? Which is not taking the usual local_lock because the CPU is going offline. I would say, just take the local_lock in mlock_drain_remote(), but (I haven't read the history) for all I know, there may be PREEMPT_RT reasons why that would be completely wrong.

Hugh

Thanks Hugh, I will explore the local_lock approach. BTW I simplified the fix to the following. is this still making things more complicated?

mm/mlock.c +8 -3
index efa6716e4dfb..fa30ffed76ab 100644
@@ -141,11 +141,16 @@ static struct lruvec *__munlock_folio(struct folio *folio, struct lruvec *lruvec
 
 munlock:
 	if (folio_test_clear_mlocked(folio)) {
-		__zone_stat_mod_folio(folio, NR_MLOCK, -nr_pages);
+		/*
+		 * This runs both with and without the lruvec lock held, and
+		 * mlock_drain_remote() reaches it fully preemptible, so use
+		 * the accessors that serialize themselves.
+		 */
+		zone_stat_mod_folio(folio, NR_MLOCK, -nr_pages);
 		if (isolated || !folio_test_unevictable(folio))
-			__count_vm_events(UNEVICTABLE_PGMUNLOCKED, nr_pages);
+			count_vm_events(UNEVICTABLE_PGMUNLOCKED, nr_pages);
 		else
-			__count_vm_events(UNEVICTABLE_PGSTRANDED, nr_pages);
+			count_vm_events(UNEVICTABLE_PGSTRANDED, nr_pages);
 	}
 
 	/* folio_evictable() has to be checked *after* clearing Mlocked */
#5 lore raw
Quoted 1 line · Shakeel Butt

On Sat, Aug 29, 2026 at 08:26:02PM -0700, Hugh Dickins wrote:

...

Quoted 11 lines
Quoted 9 lines

Thanks for looking into this, Shakeel, but I don't think complicating __munlock_folio() is at all the right fix. This is peculiar to the use by mlock_drain_remote(), isn't it? Which is not taking the usual local_lock because the CPU is going offline. I would say, just take the local_lock in mlock_drain_remote(), but (I haven't read the history) for all I know, there may be PREEMPT_RT reasons why that would be completely wrong.

Hugh

Thanks Hugh, I will explore the local_lock approach.

Please do. But we may need input from Sebastian. So far as I can see, page_alloc_cpu_dead()'s neighbouring use of lru_add_drain_cpu(cpu) would suffer from the exact same issue, there are __counts there too. Maybe syzbot has not discovered that yet, or maybe I'm confused.

(But you'll understand that I don't particularly welcome a reorg of the local_locking around the lru_add_drains at the moment; and there's at least one among them which takes advantage of the fbatch local_lock to lock something else too.)

Oh for the good old days when we were allowed to say preempt_disable()!

Quoted 2 lines

BTW I simplified the
fix to the following. is this still making things more complicated?

That is less distracting than your first one, but it's still not the right fix: the right fix is to have the function called under the proper conditions in all cases.

Quoted 6 lines
mm/mlock.c +0 -0
index efa6716e4dfb..fa30ffed76ab 100644

mm/mlock.c static struct lruvec *__munlock_folio(struct folio *folio, struct lruvec *lruvec · line 147

Quoted 8 lines
mm/mlock.c +4 -1
@@ -141,11 +141,16 @@ static struct lruvec *__munlock_folio(struct folio *folio, struct lruvec *lruvec
 
 munlock:
 	if (folio_test_clear_mlocked(folio)) {
-		__zone_stat_mod_folio(folio, NR_MLOCK, -nr_pages);
+		/*
+		 * This runs both with and without the lruvec lock held, and
+		 * mlock_drain_remote() reaches it fully preemptible, so use
+		 * the accessors that serialize themselves.

I'm very far from being a good advisor on PREEMPT_RT, but I think that comment about lruvec lock would be wrong there.

Hugh

Quoted 12 lines
mm/mlock.c +4 -2
+		 */
+		zone_stat_mod_folio(folio, NR_MLOCK, -nr_pages);
 		if (isolated || !folio_test_unevictable(folio))
-			__count_vm_events(UNEVICTABLE_PGMUNLOCKED, nr_pages);
+			count_vm_events(UNEVICTABLE_PGMUNLOCKED, nr_pages);
 		else
-			__count_vm_events(UNEVICTABLE_PGSTRANDED, nr_pages);
+			count_vm_events(UNEVICTABLE_PGSTRANDED, nr_pages);
 	}
 
 	/* folio_evictable() has to be checked *after* clearing Mlocked */
#6 lore raw
Quoted 1 line · Hugh Dickins

Oh for the good old days when we were allowed to say preempt_disable()!

I'm sorry for taking this away from you.

Quoted 4 lines
Quoted 4 lines
mm/mlock.c +0 -0
@@ -141,11 +141,16 @@ static struct lruvec *__munlock_folio(struct folio *folio, struct lruvec *lruvec
 
Quoted 10 lines

mm/mlock.c static struct lruvec *__munlock_folio(struct folio *folio, struct lruvec *lruvec · line 147

Quoted 7 lines
mm/mlock.c +4 -1
 munlock:
 	if (folio_test_clear_mlocked(folio)) {
-		__zone_stat_mod_folio(folio, NR_MLOCK, -nr_pages);
+		/*
+		 * This runs both with and without the lruvec lock held, and
+		 * mlock_drain_remote() reaches it fully preemptible, so use
+		 * the accessors that serialize themselves.

I'm very far from being a good advisor on PREEMPT_RT, but I think that comment about lruvec lock would be wrong there.

This change would eliminate the warning on !PREEMPT_RT and not cause any further trouble for PREEMPT_RT.

Given that this it might mandate for

    WARN_ON_ONCE(IS_ENABLED(CONFIG_DEBUG_VM) &&
		!IS_ENABLED(CONFIG_PREEMPT_RT) &&
		!!irqs_disabled());

in __mod_zone_page_state() and other places where preempt_disable_nested() was added. The counters do rely on disabled interrupts not preemption.

Quoted 1 line

Hugh

Sebastian

#7 lore raw
In reply to Hugh Dickins
Quoted 41 lines · Hugh Dickins
Quoted 1 line · Shakeel Butt

On Sat, Aug 29, 2026 at 08:26:02PM -0700, Hugh Dickins wrote:

...

Quoted 11 lines
Quoted 9 lines

Thanks for looking into this, Shakeel, but I don't think complicating __munlock_folio() is at all the right fix. This is peculiar to the use by mlock_drain_remote(), isn't it? Which is not taking the usual local_lock because the CPU is going offline. I would say, just take the local_lock in mlock_drain_remote(), but (I haven't read the history) for all I know, there may be PREEMPT_RT reasons why that would be completely wrong.

Hugh

Thanks Hugh, I will explore the local_lock approach.

Please do. But we may need input from Sebastian. So far as I can see, page_alloc_cpu_dead()'s neighbouring use of lru_add_drain_cpu(cpu) would suffer from the exact same issue, there are __counts there too. Maybe syzbot has not discovered that yet, or maybe I'm confused.

(But you'll understand that I don't particularly welcome a reorg of the local_locking around the lru_add_drains at the moment; and there's at least one among them which takes advantage of the fbatch local_lock to lock something else too.)

Oh for the good old days when we were allowed to say preempt_disable()!

Quoted 2 lines

BTW I simplified the
fix to the following. is this still making things more complicated?

That is less distracting than your first one, but it's still not the right fix: the right fix is to have the function called under the proper conditions in all cases.

Quoted 7 lines
mm/mlock.c +0 -0
index efa6716e4dfb..fa30ffed76ab 100644
@@ -141,11 +141,16 @@ static struct lruvec *__munlock_folio(struct folio *folio, struct lruvec *lruvec
 
Quoted 11 lines

mm/mlock.c static struct lruvec *__munlock_folio(struct folio *folio, struct lruvec *lruvec · line 147

Quoted 7 lines
mm/mlock.c +4 -1
 munlock:
 	if (folio_test_clear_mlocked(folio)) {
-		__zone_stat_mod_folio(folio, NR_MLOCK, -nr_pages);
+		/*
+		 * This runs both with and without the lruvec lock held, and
+		 * mlock_drain_remote() reaches it fully preemptible, so use
+		 * the accessors that serialize themselves.

I'm very far from being a good advisor on PREEMPT_RT, but I think that comment about lruvec lock would be wrong there.

(Let me appologize upfront on dumping a lot of text)

I think I have a more important question:

I see other than __munlock_folio, we always update NR_MLOCK with irq-safe variant of zone stat update function i.e. zone_stat_mod_folio(). This led me to a rabbit hole of proving or disproving that NR_MLOCK can be updated from irq context.

Disclaimer: I took full benefit of AI/LLM to create reproducers.

First scenario I gave AI to create reproducer was for a mlocked region, initiate a direct IO (DIO) from it and then madvise(MADV_DONTNEED_LOCKED) on it. I was hoping that I will see last folio reference in IO completion context and NR_MLOCK getting updated then but AI came up with code paths on why it is possible:

MADV_DONTNEED_LOCKED -> NR_MLOCK decrement:

madvise(MADV_DONTNEED_LOCKED)
madvise_dontneed_free() mm/madvise.c (VM_LOCKED not in forbidden)
madvise_dontneed_single_vma()
zap_vma_range_batched() -> zap_pte_range() -> zap_present_folio_ptes()
folio_remove_rmap_ptes() mm/memory.c (or via tlb_flush_rmaps() if delay_rmap)
__folio_remove_rmap()
munlock_vma_folio(folio, vma) mm/rmap.c -> mm/internal.h
if (vma->vm_flags & VM_LOCKED) <-- STILL SET
munlock_folio(folio) mm/mlock.c
folio_get(folio) <-- reference taken
folio_batch_add(&mlock_fbatch.fbatch, folio)

... later, process context ...
mlock_folio_batch() mm/mlock.c
__munlock_folio()
folio_test_clear_mlocked(folio) <-- PG_mlocked cleared
zone_stat_mod_folio(folio, NR_MLOCK, -nr) <-- the decrement
folios_put(fbatch) <-- that reference dropped

However AI came up with a different scenario where NR_MLOCK can be decremented in the irq context through free path. Just replace madvise(MADV_DONTNEED_LOCKED) with munlock()+truncate. There is a race where munlock() resets VM_LOCKED from vma and then table table traversal to call munlock_folio() on individual folios and fallocate(PUNCH_HOLE) jumping in between that window and calling try_to_unmap_one() and not able to call munlock_folio() due to lack of VM_LOCKED in the vma.

AI was able to get the reproducer as well and the full stack traces are below:

Path A — the one the WARN caught

blk completion softirq:

blk_done_softirq() block/blk-mq.c:1225 (open_softirq(BLOCK_SOFTIRQ,...))
blk_complete_reqs(this_cpu_ptr(&blk_cpu_done))
blk_mq_end_request() block/blk-mq.c
blk_update_request()
bio_endio(bio)
iomap_dio_bio_end_io() fs/iomap/direct-io.c:278
__iomap_dio_bio_end_io() fs/iomap/direct-io.c:241
bio_release_pages(bio, false) fs/iomap/direct-io.c:255
__bio_release_pages() block/bio.c:1165
bio_for_each_folio_all(fi, bio)
unpin_user_folio(fi.folio, nr_pages) mm/gup.c:434
gup_put_folio(folio, npages, FOLL_PIN) mm/gup.c:102
folio_put_refs(folio, refs) include/linux/mm.h:2177
folio_ref_sub_and_test() -> true <-- LAST REFERENCE
__folio_put(folio) mm/folio.c:100
free_frozen_pages() mm/page_alloc.c:2997
__free_pages_ok() (order > PAGE_ALLOC_COSTLY_ORDER: ext4 large folio)
__free_pages_prepare() mm/page_alloc.c
if (unlikely(folio_test_mlocked(folio))) {
__folio_clear_mlocked(folio);
zone_stat_mod_folio(folio, NR_MLOCK, -nr_pages); <-- HERE
count_vm_events(UNEVICTABLE_PGCLEARED, nr_pages);
}

The precondition — why PG_mlocked is still set when it gets there

task 1: mmap(MAP_SHARED, victim) ; mlock() -> page cache folios get PG_mlocked
task 1: pwrite(O_DIRECT_fd, region, len) -> iov_iter_extract_pages() FOLL_PIN
pins those same mlocked folios
task 2: munlock(region)
mlock_fixup() mm/mlock.c
mlock_vma_pages_range() mm/mlock.c:428
vma_flags_reset_once(vma, ...) line 451 <-- VM_LOCKED CLEARED
walk_page_range_vma(mlock_walk_ops) line 454 <-- per-folio munlock walk
(holds mmap_lock for WRITE)
task 3: fallocate(PUNCH_HOLE) on the same range <-- reaches the folio via i_mmap_rwsem,
truncate_inode_pages_range() NOT mmap_lock, so it is not excluded
truncate_cleanup_folio() -> unmap_mapping_folio()
try_to_unmap_one() -> folio_remove_rmap_pte()
__folio_remove_rmap() mm/rmap.c:1889
munlock_vma_folio(folio, vma) mm/internal.h:983
if (vma->vm_flags & VM_LOCKED) <-- FALSE, window at line 451..454
munlock_folio(folio); <-- NOT taken: nothing queued,
no folio_get() reference
filemap_remove_folio() <-- page cache reference dropped

The bio's pin is now the only reference, PG_mlocked is still set, and it is released by Path A in softirq.

The reason I am sharing this information is that a simple lock_lock is not sufficient and we definitely need to change __zone_stat_mod_folio(NR_MLOCK) to zone_stat_mod_folio(NR_MLOCK) in __munlock_folio.

#8 lore raw
In reply to Hugh Dickins
Quoted 8 lines · Hugh Dickins
Quoted 1 line

Something like below. I will run some tests before proposing a formal patch.

Thanks for looking into this, Shakeel, but I don't think complicating __munlock_folio() is at all the right fix. This is peculiar to the use by mlock_drain_remote(), isn't it? Which is not taking the usual local_lock because the CPU is going offline. I would say, just take the local_lock in mlock_drain_remote(), but (I haven't read the history) for all I know, there may be PREEMPT_RT reasons why that would be completely wrong.

PREEMPT_RT does local_lock() as a replacement for various preempt_disable()/ local_irq_save() usage in mm aiming for the same sort of synchronisation.

On !RT __mod_zone_page_state() is usually invoked under an IRQ lock or within an local_irq_save() section which ensures the per-CPU counter can be updated safely without racing against another counter update due preemption in the critical section.
The counter update does the not share the same local_lock() so for PREEMPT_RT reasons the preempt_disable_nested() got added to ensure preemption is disabled on RT, avoiding the race window since there can not be any in-IRQ updates.

If this warning triggers on !PREEMPT_RT I would say you missed disabling interrupts somewhere. Unless __mod_zone_page_state() relies on disabled preemption, too if there are no longer any in-IRQ updates.

Quoted 1 line

Hugh

Sebastian