mm/ksm.c | 98 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 62 insertions(+), 36 deletions(-)
Currently, scan_get_next_rmap_item() has grown quite large and complex. When introducing new features, such as the only-merge-zero-page mode we are currently working on, we don't want to add more complexity to it and don't want to touch rmap_item structures to avoid unnecessary overhead, so we need to extract some common logic. With these changes, the entry of scan_get_next_rmap_item() becomes much cleaner and easier to follow, instead of being cluttered with unrelated boilerplate such as stale stable_node pruning and cycle initialization. Let's start by cleaning up these two parts at the beginning (where I think abstraction is necessary), and we can continue cleaning up further if needed later. Changes in v2: - Rename scan_begin_new_cycle() to scan_should_start_new_cycle() and keep it simple (David). - Keep lru_add_drain_all() in scan_get_next_rmap_item() (David). - Use scoped_guard(spinlock, &ksm_mmlist_lock) in scan_get_first_mm() (Lorenzo). - Collect Reviewed-by and Acked-by tags from v1. Xu Xin (vivo) (2): mm/ksm: extract helper functions for scan cycle cleanup mm/ksm: add initialization helpers for scan_get_next_rmap_item() mm/ksm.c | 98 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 62 insertions(+), 36 deletions(-) -- 2.34.1
syzbot ci has tested the following series [v2] mm/ksm: clean up scan_get_next_rmap_item() initialization https://lore.kernel.org/all/20261115075832.132109-1-xu.xin@linux.dev * [PATCH v2 1/2] mm/ksm: extract helper functions for scan cycle cleanup * [PATCH v2 2/2] mm/ksm: add initialization helpers for scan_get_next_rmap_item() and found the following issue: general protection fault in ksm_do_scan Full report is available here: https://ci.syzbot.org/series/cc51d824-2b5d-4c6d-bd56-c5bdb2bf5e12 *** general protection fault in ksm_do_scan tree: mm-new URL: https://kernel.googlesource.com/pub/scm/linux/kernel/git/akpm/mm.git base: 3dfc09a9493ddaa5e7722a29165d8450b55b4d3f arch: amd64 compiler: Debian clang version 22.1.8 (1~deb13u4), Debian LLD 22.1.8 config: https://ci.syzbot.org/builds/6f9c12e2-f68e-40ee-bbac-84e33b709dfb/config Oops: general protection fault, probably for non-canonical address 0xdffffc0000000004: 0000 [#1] SMP KASAN PTI KASAN: null-ptr-deref in range [0x0000000000000020-0x0000000000000027] CPU: 1 UID: 0 PID: 44 Comm: ksmd Not tainted syzkaller #0 PREEMPT(full) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 RIP: 0010:ksm_do_scan+0x5da/0x6f40 Code: c7 05 86 a2 b1 19 00 00 00 00 48 8d 43 28 48 89 05 9b a2 b1 19 48 89 4c 24 40 48 8d 59 20 48 89 d8 48 c1 e8 03 48 89 44 24 78 <42> 80 3c 28 00 74 08 48 89 df e8 47 3a 01 00 48 89 5c 24 30 48 8b RSP: 0018:ffffc90000b47a60 EFLAGS: 00010202 RAX: 0000000000000004 RBX: 0000000000000020 RCX: 0000000000000000 RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffc90000b47c08 RBP: ffffc90000b47cd0 R08: ffffc90000b47c07 R09: 0000000000000000 R10: ffffc90000b47bb0 R11: fffff52000168f81 R12: 1ffff92000168f68 R13: dffffc0000000000 R14: ffffea00046aca00 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff8882a77fd000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f15aa3f8c38 CR3: 0000000170aa2000 CR4: 00000000000006f0 Call Trace: <TASK> ksm_scan_thread+0x114/0x520 kthread+0x38b/0x480 ret_from_fork+0x514/0xb70 ret_from_fork_asm+0x1a/0x30 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:ksm_do_scan+0x5da/0x6f40 Code: c7 05 86 a2 b1 19 00 00 00 00 48 8d 43 28 48 89 05 9b a2 b1 19 48 89 4c 24 40 48 8d 59 20 48 89 d8 48 c1 e8 03 48 89 44 24 78 <42> 80 3c 28 00 74 08 48 89 df e8 47 3a 01 00 48 89 5c 24 30 48 8b RSP: 0018:ffffc90000b47a60 EFLAGS: 00010202 RAX: 0000000000000004 RBX: 0000000000000020 RCX: 0000000000000000 RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffc90000b47c08 RBP: ffffc90000b47cd0 R08: ffffc90000b47c07 R09: 0000000000000000 R10: ffffc90000b47bb0 R11: fffff52000168f81 R12: 1ffff92000168f68 R13: dffffc0000000000 R14: ffffea00046aca00 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff88818bdfd000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000000110c27b575 CR3: 000000010233e000 CR4: 00000000000006f0 *** If these findings have caused you to resend the series or submit a separate fix, please add the following tag to your commit message: Tested-by: syzbot@syzkaller.appspotmail.com --- This report is generated by a bot. It may contain errors. syzbot ci engineers can be reached at syzkaller@googlegroups.com.
On Wed, Nov 18, 2026 at 11:00:30PM -0800, syzbot ci wrote: > syzbot ci has tested the following series > > [v2] mm/ksm: clean up scan_get_next_rmap_item() initialization > https://lore.kernel.org/all/20261115075832.132109-1-xu.xin@linux.dev > * [PATCH v2 1/2] mm/ksm: extract helper functions for scan cycle cleanup > * [PATCH v2 2/2] mm/ksm: add initialization helpers for scan_get_next_rmap_item() > > and found the following issue: > general protection fault in ksm_do_scan > > Full report is available here: > https://ci.syzbot.org/series/cc51d824-2b5d-4c6d-bd56-c5bdb2bf5e12 I guess it didn't see the v3? Likely this is the sashiko thing, fixed there > > *** > > general protection fault in ksm_do_scan > > tree: mm-new > URL: https://kernel.googlesource.com/pub/scm/linux/kernel/git/akpm/mm.git > base: 3dfc09a9493ddaa5e7722a29165d8450b55b4d3f > arch: amd64 > compiler: Debian clang version 22.1.8 (1~deb13u4), Debian LLD 22.1.8 > config: https://ci.syzbot.org/builds/6f9c12e2-f68e-40ee-bbac-84e33b709dfb/config > > Oops: general protection fault, probably for non-canonical address 0xdffffc0000000004: 0000 [#1] SMP KASAN PTI > KASAN: null-ptr-deref in range [0x0000000000000020-0x0000000000000027] > CPU: 1 UID: 0 PID: 44 Comm: ksmd Not tainted syzkaller #0 PREEMPT(full) > Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 > RIP: 0010:ksm_do_scan+0x5da/0x6f40 > Code: c7 05 86 a2 b1 19 00 00 00 00 48 8d 43 28 48 89 05 9b a2 b1 19 48 89 4c 24 40 48 8d 59 20 48 89 d8 48 c1 e8 03 48 89 44 24 78 <42> 80 3c 28 00 74 08 48 89 df e8 47 3a 01 00 48 89 5c 24 30 48 8b > RSP: 0018:ffffc90000b47a60 EFLAGS: 00010202 > RAX: 0000000000000004 RBX: 0000000000000020 RCX: 0000000000000000 > RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffc90000b47c08 > RBP: ffffc90000b47cd0 R08: ffffc90000b47c07 R09: 0000000000000000 > R10: ffffc90000b47bb0 R11: fffff52000168f81 R12: 1ffff92000168f68 > R13: dffffc0000000000 R14: ffffea00046aca00 R15: 0000000000000000 > FS: 0000000000000000(0000) GS:ffff8882a77fd000(0000) knlGS:0000000000000000 > CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > CR2: 00007f15aa3f8c38 CR3: 0000000170aa2000 CR4: 00000000000006f0 > Call Trace: > <TASK> > ksm_scan_thread+0x114/0x520 > kthread+0x38b/0x480 > ret_from_fork+0x514/0xb70 > ret_from_fork_asm+0x1a/0x30 > </TASK> > Modules linked in: > ---[ end trace 0000000000000000 ]--- > RIP: 0010:ksm_do_scan+0x5da/0x6f40 > Code: c7 05 86 a2 b1 19 00 00 00 00 48 8d 43 28 48 89 05 9b a2 b1 19 48 89 4c 24 40 48 8d 59 20 48 89 d8 48 c1 e8 03 48 89 44 24 78 <42> 80 3c 28 00 74 08 48 89 df e8 47 3a 01 00 48 89 5c 24 30 48 8b > RSP: 0018:ffffc90000b47a60 EFLAGS: 00010202 > RAX: 0000000000000004 RBX: 0000000000000020 RCX: 0000000000000000 > RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffc90000b47c08 > RBP: ffffc90000b47cd0 R08: ffffc90000b47c07 R09: 0000000000000000 > R10: ffffc90000b47bb0 R11: fffff52000168f81 R12: 1ffff92000168f68 > R13: dffffc0000000000 R14: ffffea00046aca00 R15: 0000000000000000 > FS: 0000000000000000(0000) GS:ffff88818bdfd000(0000) knlGS:0000000000000000 > CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > CR2: 000000110c27b575 CR3: 000000010233e000 CR4: 00000000000006f0 > > > *** > > If these findings have caused you to resend the series or submit a > separate fix, please add the following tag to your commit message: > Tested-by: syzbot@syzkaller.appspotmail.com > > --- > This report is generated by a bot. It may contain errors. > syzbot ci engineers can be reached at syzkaller@googlegroups.com. -- Cheers, Lorenzo
© 2016 - 2026 Red Hat, Inc.