source
large_stringclasses
2 values
subject
large_stringclasses
112 values
code
large_stringclasses
112 values
critique
large_stringlengths
61
3.04M
metadata
dict
lkml
[syzbot] [hfs?] kernel BUG in may_open (3)
Hello, syzbot found the following issue on: HEAD commit: b6151c4e60e5 Merge tag 'erofs-for-6.19-rc5-fixes' of git:/.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=15d45922580000 kernel config: https://syzkaller.appspot.com/x/.config?x=7b058fb1d7dbe6b1 dashboard link: https://syzkaller.appspot.com/bug?extid=f98189ed18c1f5f32e00 compiler: Debian clang version 20.1.8 (++20250708063551+0c9f909b7976-1~exp1~20250708183702.136), Debian LLD 20.1.8 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14a7d19a580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=16a2f19a580000 Downloadable assets: disk image: https://storage.googleapis.com/syzbot-assets/6eb5179ada01/disk-b6151c4e.raw.xz vmlinux: https://storage.googleapis.com/syzbot-assets/bc48d1a68ed0/vmlinux-b6151c4e.xz kernel image: https://storage.googleapis.com/syzbot-assets/061d4fb696a7/bzImage-b6151c4e.xz mounted in repro: https://storage.googleapis.com/syzbot-assets/df739de73585/mount_0.gz IMPORTANT: if you fix the issue, please add the following tag to the commit: Reported-by: syzbot+f98189ed18c1f5f32e00@syzkaller.appspotmail.com loop0: detected capacity change from 0 to 1024 VFS_BUG_ON_INODE(!IS_ANON_FILE(inode)) encountered for inode ffff8880384b01e0 fs hfsplus mode 0 opflags 0x4 flags 0x0 state 0x70 count 2 ------------[ cut here ]------------ kernel BUG at fs/namei.c:4210! Oops: invalid opcode: 0000 [#1] SMP KASAN PTI CPU: 1 UID: 0 PID: 6062 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT_{RT,(full)} Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/25/2025 RIP: 0010:may_open+0x4b1/0x4c0 fs/namei.c:4210 Code: 38 c1 0f 8c 1e fd ff ff 4c 89 e7 e8 c9 ec ef ff e9 11 fd ff ff e8 df b3 8d ff 4c 89 f7 48 c7 c6 80 53 f9 8a e8 10 eb f5 fe 90 <0f> 0b 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 RSP: 0018:ffffc90003ba78e0 EFLAGS: 00010282 RAX: 0000000000000088 RBX: dffffc0000000000 RCX: b41eda36b1e3ff00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000008241 R08: 0000000000000000 R09: 0000000000000000 R10: dffffc0000000000 R11: fffff52000774ec1 R12: 0000000000000000 R13: ffffffff8d709d80 R14: ffff8880384b01e0 R15: 0000000000000002 FS: 000055557d7cd500(0000) GS:ffff888126def000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f01916a5890 CR3: 0000000040598000 CR4: 00000000003526f0 Call Trace: <TASK> do_open fs/namei.c:4635 [inline] path_openat+0x32a8/0x3df0 fs/namei.c:4796 do_filp_open+0x1fa/0x410 fs/namei.c:4823 do_sys_openat2+0x121/0x200 fs/open.c:1430 do_sys_open fs/open.c:1436 [inline] __do_sys_creat fs/open.c:1514 [inline] __se_sys_creat fs/open.c:1508 [inline] __x64_sys_creat+0x8f/0xc0 fs/open.c:1508 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xec/0xf80 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f739c0cf749 Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007ffd4aa21ce8 EFLAGS: 00000246 ORIG_RAX: 0000000000000055 RAX: ffffffffffffffda RBX: 00007f739c325fa0 RCX: 00007f739c0cf749 RDX: 0000000000000000 RSI: 0000000000000006 RDI: 0000200000000140 RBP: 00007f739c153f91 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f739c325fa0 R14: 00007f739c325fa0 R15: 0000000000000002 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:may_open+0x4b1/0x4c0 fs/namei.c:4210 Code: 38 c1 0f 8c 1e fd ff ff 4c 89 e7 e8 c9 ec ef ff e9 11 fd ff ff e8 df b3 8d ff 4c 89 f7 48 c7 c6 80 53 f9 8a e8 10 eb f5 fe 90 <0f> 0b 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 RSP: 0018:ffffc90003ba78e0 EFLAGS: 00010282 RAX: 0000000000000088 RBX: dffffc0000000000 RCX: b41eda36b1e3ff00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000008241 R08: 0000000000000000 R09: 0000000000000000 R10: dffffc0000000000 R11: fffff52000774ec1 R12: 0000000000000000 R13: ffffffff8d709d80 R14: ffff8880384b01e0 R15: 0000000000000002 FS: 000055557d7cd500(0000) GS:ffff888126def000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f01916a5890 CR3: 0000000040598000 CR4: 00000000003526f0 --- 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 syzkaller@googlegroups.com. 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
On Mon, 12 Jan 2026 at 10:27, 'Christian Brauner' via syzkaller-bugs <syzkaller-bugs@googlegroups.com> wrote: +hfsplus maintainers #syz set subsystems: hfs
{ "author": "Dmitry Vyukov <dvyukov@google.com>", "date": "Mon, 12 Jan 2026 11:35:54 +0100", "thread_id": "de541759cfa4d216e342bf15b07f93a21f46498b.camel@ibm.com.mbox.gz" }
lkml
[syzbot] [hfs?] kernel BUG in may_open (3)
Hello, syzbot found the following issue on: HEAD commit: b6151c4e60e5 Merge tag 'erofs-for-6.19-rc5-fixes' of git:/.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=15d45922580000 kernel config: https://syzkaller.appspot.com/x/.config?x=7b058fb1d7dbe6b1 dashboard link: https://syzkaller.appspot.com/bug?extid=f98189ed18c1f5f32e00 compiler: Debian clang version 20.1.8 (++20250708063551+0c9f909b7976-1~exp1~20250708183702.136), Debian LLD 20.1.8 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14a7d19a580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=16a2f19a580000 Downloadable assets: disk image: https://storage.googleapis.com/syzbot-assets/6eb5179ada01/disk-b6151c4e.raw.xz vmlinux: https://storage.googleapis.com/syzbot-assets/bc48d1a68ed0/vmlinux-b6151c4e.xz kernel image: https://storage.googleapis.com/syzbot-assets/061d4fb696a7/bzImage-b6151c4e.xz mounted in repro: https://storage.googleapis.com/syzbot-assets/df739de73585/mount_0.gz IMPORTANT: if you fix the issue, please add the following tag to the commit: Reported-by: syzbot+f98189ed18c1f5f32e00@syzkaller.appspotmail.com loop0: detected capacity change from 0 to 1024 VFS_BUG_ON_INODE(!IS_ANON_FILE(inode)) encountered for inode ffff8880384b01e0 fs hfsplus mode 0 opflags 0x4 flags 0x0 state 0x70 count 2 ------------[ cut here ]------------ kernel BUG at fs/namei.c:4210! Oops: invalid opcode: 0000 [#1] SMP KASAN PTI CPU: 1 UID: 0 PID: 6062 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT_{RT,(full)} Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/25/2025 RIP: 0010:may_open+0x4b1/0x4c0 fs/namei.c:4210 Code: 38 c1 0f 8c 1e fd ff ff 4c 89 e7 e8 c9 ec ef ff e9 11 fd ff ff e8 df b3 8d ff 4c 89 f7 48 c7 c6 80 53 f9 8a e8 10 eb f5 fe 90 <0f> 0b 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 RSP: 0018:ffffc90003ba78e0 EFLAGS: 00010282 RAX: 0000000000000088 RBX: dffffc0000000000 RCX: b41eda36b1e3ff00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000008241 R08: 0000000000000000 R09: 0000000000000000 R10: dffffc0000000000 R11: fffff52000774ec1 R12: 0000000000000000 R13: ffffffff8d709d80 R14: ffff8880384b01e0 R15: 0000000000000002 FS: 000055557d7cd500(0000) GS:ffff888126def000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f01916a5890 CR3: 0000000040598000 CR4: 00000000003526f0 Call Trace: <TASK> do_open fs/namei.c:4635 [inline] path_openat+0x32a8/0x3df0 fs/namei.c:4796 do_filp_open+0x1fa/0x410 fs/namei.c:4823 do_sys_openat2+0x121/0x200 fs/open.c:1430 do_sys_open fs/open.c:1436 [inline] __do_sys_creat fs/open.c:1514 [inline] __se_sys_creat fs/open.c:1508 [inline] __x64_sys_creat+0x8f/0xc0 fs/open.c:1508 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xec/0xf80 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f739c0cf749 Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007ffd4aa21ce8 EFLAGS: 00000246 ORIG_RAX: 0000000000000055 RAX: ffffffffffffffda RBX: 00007f739c325fa0 RCX: 00007f739c0cf749 RDX: 0000000000000000 RSI: 0000000000000006 RDI: 0000200000000140 RBP: 00007f739c153f91 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f739c325fa0 R14: 00007f739c325fa0 R15: 0000000000000002 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:may_open+0x4b1/0x4c0 fs/namei.c:4210 Code: 38 c1 0f 8c 1e fd ff ff 4c 89 e7 e8 c9 ec ef ff e9 11 fd ff ff e8 df b3 8d ff 4c 89 f7 48 c7 c6 80 53 f9 8a e8 10 eb f5 fe 90 <0f> 0b 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 RSP: 0018:ffffc90003ba78e0 EFLAGS: 00010282 RAX: 0000000000000088 RBX: dffffc0000000000 RCX: b41eda36b1e3ff00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000008241 R08: 0000000000000000 R09: 0000000000000000 R10: dffffc0000000000 R11: fffff52000774ec1 R12: 0000000000000000 R13: ffffffff8d709d80 R14: ffff8880384b01e0 R15: 0000000000000002 FS: 000055557d7cd500(0000) GS:ffff888126def000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f01916a5890 CR3: 0000000040598000 CR4: 00000000003526f0 --- 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 syzkaller@googlegroups.com. 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
On Mon, 12 Jan 2026 18:39:23 +0900, Tetsuo Handa wrote: Applied to the vfs-7.0.misc branch of the vfs/vfs.git tree. Patches in the vfs-7.0.misc branch should appear in linux-next soon. Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it. It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated. Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch. tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-7.0.misc [1/1] hfsplus: pretend special inodes as regular files https://git.kernel.org/vfs/vfs/c/68186fa198f1
{ "author": "Christian Brauner <brauner@kernel.org>", "date": "Tue, 13 Jan 2026 09:55:33 +0100", "thread_id": "de541759cfa4d216e342bf15b07f93a21f46498b.camel@ibm.com.mbox.gz" }
lkml
[syzbot] [hfs?] kernel BUG in may_open (3)
Hello, syzbot found the following issue on: HEAD commit: b6151c4e60e5 Merge tag 'erofs-for-6.19-rc5-fixes' of git:/.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=15d45922580000 kernel config: https://syzkaller.appspot.com/x/.config?x=7b058fb1d7dbe6b1 dashboard link: https://syzkaller.appspot.com/bug?extid=f98189ed18c1f5f32e00 compiler: Debian clang version 20.1.8 (++20250708063551+0c9f909b7976-1~exp1~20250708183702.136), Debian LLD 20.1.8 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14a7d19a580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=16a2f19a580000 Downloadable assets: disk image: https://storage.googleapis.com/syzbot-assets/6eb5179ada01/disk-b6151c4e.raw.xz vmlinux: https://storage.googleapis.com/syzbot-assets/bc48d1a68ed0/vmlinux-b6151c4e.xz kernel image: https://storage.googleapis.com/syzbot-assets/061d4fb696a7/bzImage-b6151c4e.xz mounted in repro: https://storage.googleapis.com/syzbot-assets/df739de73585/mount_0.gz IMPORTANT: if you fix the issue, please add the following tag to the commit: Reported-by: syzbot+f98189ed18c1f5f32e00@syzkaller.appspotmail.com loop0: detected capacity change from 0 to 1024 VFS_BUG_ON_INODE(!IS_ANON_FILE(inode)) encountered for inode ffff8880384b01e0 fs hfsplus mode 0 opflags 0x4 flags 0x0 state 0x70 count 2 ------------[ cut here ]------------ kernel BUG at fs/namei.c:4210! Oops: invalid opcode: 0000 [#1] SMP KASAN PTI CPU: 1 UID: 0 PID: 6062 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT_{RT,(full)} Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/25/2025 RIP: 0010:may_open+0x4b1/0x4c0 fs/namei.c:4210 Code: 38 c1 0f 8c 1e fd ff ff 4c 89 e7 e8 c9 ec ef ff e9 11 fd ff ff e8 df b3 8d ff 4c 89 f7 48 c7 c6 80 53 f9 8a e8 10 eb f5 fe 90 <0f> 0b 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 RSP: 0018:ffffc90003ba78e0 EFLAGS: 00010282 RAX: 0000000000000088 RBX: dffffc0000000000 RCX: b41eda36b1e3ff00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000008241 R08: 0000000000000000 R09: 0000000000000000 R10: dffffc0000000000 R11: fffff52000774ec1 R12: 0000000000000000 R13: ffffffff8d709d80 R14: ffff8880384b01e0 R15: 0000000000000002 FS: 000055557d7cd500(0000) GS:ffff888126def000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f01916a5890 CR3: 0000000040598000 CR4: 00000000003526f0 Call Trace: <TASK> do_open fs/namei.c:4635 [inline] path_openat+0x32a8/0x3df0 fs/namei.c:4796 do_filp_open+0x1fa/0x410 fs/namei.c:4823 do_sys_openat2+0x121/0x200 fs/open.c:1430 do_sys_open fs/open.c:1436 [inline] __do_sys_creat fs/open.c:1514 [inline] __se_sys_creat fs/open.c:1508 [inline] __x64_sys_creat+0x8f/0xc0 fs/open.c:1508 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xec/0xf80 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f739c0cf749 Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007ffd4aa21ce8 EFLAGS: 00000246 ORIG_RAX: 0000000000000055 RAX: ffffffffffffffda RBX: 00007f739c325fa0 RCX: 00007f739c0cf749 RDX: 0000000000000000 RSI: 0000000000000006 RDI: 0000200000000140 RBP: 00007f739c153f91 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f739c325fa0 R14: 00007f739c325fa0 R15: 0000000000000002 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:may_open+0x4b1/0x4c0 fs/namei.c:4210 Code: 38 c1 0f 8c 1e fd ff ff 4c 89 e7 e8 c9 ec ef ff e9 11 fd ff ff e8 df b3 8d ff 4c 89 f7 48 c7 c6 80 53 f9 8a e8 10 eb f5 fe 90 <0f> 0b 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 RSP: 0018:ffffc90003ba78e0 EFLAGS: 00010282 RAX: 0000000000000088 RBX: dffffc0000000000 RCX: b41eda36b1e3ff00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000008241 R08: 0000000000000000 R09: 0000000000000000 R10: dffffc0000000000 R11: fffff52000774ec1 R12: 0000000000000000 R13: ffffffff8d709d80 R14: ffff8880384b01e0 R15: 0000000000000002 FS: 000055557d7cd500(0000) GS:ffff888126def000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f01916a5890 CR3: 0000000040598000 CR4: 00000000003526f0 --- 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 syzkaller@googlegroups.com. 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
On Tue, 2026-01-13 at 09:55 +0100, Christian Brauner wrote: I've already taken this patch into HFS/HFS+ tree. :) Should I remove it from the tree? Thanks, Slava.
{ "author": "Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>", "date": "Tue, 13 Jan 2026 17:18:40 +0000", "thread_id": "de541759cfa4d216e342bf15b07f93a21f46498b.camel@ibm.com.mbox.gz" }
lkml
[syzbot] [hfs?] kernel BUG in may_open (3)
Hello, syzbot found the following issue on: HEAD commit: b6151c4e60e5 Merge tag 'erofs-for-6.19-rc5-fixes' of git:/.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=15d45922580000 kernel config: https://syzkaller.appspot.com/x/.config?x=7b058fb1d7dbe6b1 dashboard link: https://syzkaller.appspot.com/bug?extid=f98189ed18c1f5f32e00 compiler: Debian clang version 20.1.8 (++20250708063551+0c9f909b7976-1~exp1~20250708183702.136), Debian LLD 20.1.8 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14a7d19a580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=16a2f19a580000 Downloadable assets: disk image: https://storage.googleapis.com/syzbot-assets/6eb5179ada01/disk-b6151c4e.raw.xz vmlinux: https://storage.googleapis.com/syzbot-assets/bc48d1a68ed0/vmlinux-b6151c4e.xz kernel image: https://storage.googleapis.com/syzbot-assets/061d4fb696a7/bzImage-b6151c4e.xz mounted in repro: https://storage.googleapis.com/syzbot-assets/df739de73585/mount_0.gz IMPORTANT: if you fix the issue, please add the following tag to the commit: Reported-by: syzbot+f98189ed18c1f5f32e00@syzkaller.appspotmail.com loop0: detected capacity change from 0 to 1024 VFS_BUG_ON_INODE(!IS_ANON_FILE(inode)) encountered for inode ffff8880384b01e0 fs hfsplus mode 0 opflags 0x4 flags 0x0 state 0x70 count 2 ------------[ cut here ]------------ kernel BUG at fs/namei.c:4210! Oops: invalid opcode: 0000 [#1] SMP KASAN PTI CPU: 1 UID: 0 PID: 6062 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT_{RT,(full)} Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/25/2025 RIP: 0010:may_open+0x4b1/0x4c0 fs/namei.c:4210 Code: 38 c1 0f 8c 1e fd ff ff 4c 89 e7 e8 c9 ec ef ff e9 11 fd ff ff e8 df b3 8d ff 4c 89 f7 48 c7 c6 80 53 f9 8a e8 10 eb f5 fe 90 <0f> 0b 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 RSP: 0018:ffffc90003ba78e0 EFLAGS: 00010282 RAX: 0000000000000088 RBX: dffffc0000000000 RCX: b41eda36b1e3ff00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000008241 R08: 0000000000000000 R09: 0000000000000000 R10: dffffc0000000000 R11: fffff52000774ec1 R12: 0000000000000000 R13: ffffffff8d709d80 R14: ffff8880384b01e0 R15: 0000000000000002 FS: 000055557d7cd500(0000) GS:ffff888126def000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f01916a5890 CR3: 0000000040598000 CR4: 00000000003526f0 Call Trace: <TASK> do_open fs/namei.c:4635 [inline] path_openat+0x32a8/0x3df0 fs/namei.c:4796 do_filp_open+0x1fa/0x410 fs/namei.c:4823 do_sys_openat2+0x121/0x200 fs/open.c:1430 do_sys_open fs/open.c:1436 [inline] __do_sys_creat fs/open.c:1514 [inline] __se_sys_creat fs/open.c:1508 [inline] __x64_sys_creat+0x8f/0xc0 fs/open.c:1508 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xec/0xf80 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f739c0cf749 Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007ffd4aa21ce8 EFLAGS: 00000246 ORIG_RAX: 0000000000000055 RAX: ffffffffffffffda RBX: 00007f739c325fa0 RCX: 00007f739c0cf749 RDX: 0000000000000000 RSI: 0000000000000006 RDI: 0000200000000140 RBP: 00007f739c153f91 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f739c325fa0 R14: 00007f739c325fa0 R15: 0000000000000002 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:may_open+0x4b1/0x4c0 fs/namei.c:4210 Code: 38 c1 0f 8c 1e fd ff ff 4c 89 e7 e8 c9 ec ef ff e9 11 fd ff ff e8 df b3 8d ff 4c 89 f7 48 c7 c6 80 53 f9 8a e8 10 eb f5 fe 90 <0f> 0b 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 RSP: 0018:ffffc90003ba78e0 EFLAGS: 00010282 RAX: 0000000000000088 RBX: dffffc0000000000 RCX: b41eda36b1e3ff00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000008241 R08: 0000000000000000 R09: 0000000000000000 R10: dffffc0000000000 R11: fffff52000774ec1 R12: 0000000000000000 R13: ffffffff8d709d80 R14: ffff8880384b01e0 R15: 0000000000000002 FS: 000055557d7cd500(0000) GS:ffff888126def000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f01916a5890 CR3: 0000000040598000 CR4: 00000000003526f0 --- 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 syzkaller@googlegroups.com. 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
On Tue, Jan 13, 2026 at 05:18:40PM +0000, Viacheslav Dubeyko wrote: No, I'll drop it.
{ "author": "Christian Brauner <brauner@kernel.org>", "date": "Wed, 14 Jan 2026 17:05:04 +0100", "thread_id": "de541759cfa4d216e342bf15b07f93a21f46498b.camel@ibm.com.mbox.gz" }
lkml
[syzbot] [hfs?] kernel BUG in may_open (3)
Hello, syzbot found the following issue on: HEAD commit: b6151c4e60e5 Merge tag 'erofs-for-6.19-rc5-fixes' of git:/.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=15d45922580000 kernel config: https://syzkaller.appspot.com/x/.config?x=7b058fb1d7dbe6b1 dashboard link: https://syzkaller.appspot.com/bug?extid=f98189ed18c1f5f32e00 compiler: Debian clang version 20.1.8 (++20250708063551+0c9f909b7976-1~exp1~20250708183702.136), Debian LLD 20.1.8 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14a7d19a580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=16a2f19a580000 Downloadable assets: disk image: https://storage.googleapis.com/syzbot-assets/6eb5179ada01/disk-b6151c4e.raw.xz vmlinux: https://storage.googleapis.com/syzbot-assets/bc48d1a68ed0/vmlinux-b6151c4e.xz kernel image: https://storage.googleapis.com/syzbot-assets/061d4fb696a7/bzImage-b6151c4e.xz mounted in repro: https://storage.googleapis.com/syzbot-assets/df739de73585/mount_0.gz IMPORTANT: if you fix the issue, please add the following tag to the commit: Reported-by: syzbot+f98189ed18c1f5f32e00@syzkaller.appspotmail.com loop0: detected capacity change from 0 to 1024 VFS_BUG_ON_INODE(!IS_ANON_FILE(inode)) encountered for inode ffff8880384b01e0 fs hfsplus mode 0 opflags 0x4 flags 0x0 state 0x70 count 2 ------------[ cut here ]------------ kernel BUG at fs/namei.c:4210! Oops: invalid opcode: 0000 [#1] SMP KASAN PTI CPU: 1 UID: 0 PID: 6062 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT_{RT,(full)} Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/25/2025 RIP: 0010:may_open+0x4b1/0x4c0 fs/namei.c:4210 Code: 38 c1 0f 8c 1e fd ff ff 4c 89 e7 e8 c9 ec ef ff e9 11 fd ff ff e8 df b3 8d ff 4c 89 f7 48 c7 c6 80 53 f9 8a e8 10 eb f5 fe 90 <0f> 0b 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 RSP: 0018:ffffc90003ba78e0 EFLAGS: 00010282 RAX: 0000000000000088 RBX: dffffc0000000000 RCX: b41eda36b1e3ff00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000008241 R08: 0000000000000000 R09: 0000000000000000 R10: dffffc0000000000 R11: fffff52000774ec1 R12: 0000000000000000 R13: ffffffff8d709d80 R14: ffff8880384b01e0 R15: 0000000000000002 FS: 000055557d7cd500(0000) GS:ffff888126def000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f01916a5890 CR3: 0000000040598000 CR4: 00000000003526f0 Call Trace: <TASK> do_open fs/namei.c:4635 [inline] path_openat+0x32a8/0x3df0 fs/namei.c:4796 do_filp_open+0x1fa/0x410 fs/namei.c:4823 do_sys_openat2+0x121/0x200 fs/open.c:1430 do_sys_open fs/open.c:1436 [inline] __do_sys_creat fs/open.c:1514 [inline] __se_sys_creat fs/open.c:1508 [inline] __x64_sys_creat+0x8f/0xc0 fs/open.c:1508 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xec/0xf80 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f739c0cf749 Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007ffd4aa21ce8 EFLAGS: 00000246 ORIG_RAX: 0000000000000055 RAX: ffffffffffffffda RBX: 00007f739c325fa0 RCX: 00007f739c0cf749 RDX: 0000000000000000 RSI: 0000000000000006 RDI: 0000200000000140 RBP: 00007f739c153f91 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f739c325fa0 R14: 00007f739c325fa0 R15: 0000000000000002 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:may_open+0x4b1/0x4c0 fs/namei.c:4210 Code: 38 c1 0f 8c 1e fd ff ff 4c 89 e7 e8 c9 ec ef ff e9 11 fd ff ff e8 df b3 8d ff 4c 89 f7 48 c7 c6 80 53 f9 8a e8 10 eb f5 fe 90 <0f> 0b 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 RSP: 0018:ffffc90003ba78e0 EFLAGS: 00010282 RAX: 0000000000000088 RBX: dffffc0000000000 RCX: b41eda36b1e3ff00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000008241 R08: 0000000000000000 R09: 0000000000000000 R10: dffffc0000000000 R11: fffff52000774ec1 R12: 0000000000000000 R13: ffffffff8d709d80 R14: ffff8880384b01e0 R15: 0000000000000002 FS: 000055557d7cd500(0000) GS:ffff888126def000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f01916a5890 CR3: 0000000040598000 CR4: 00000000003526f0 --- 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 syzkaller@googlegroups.com. 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
On 2026/01/15 1:05, Christian Brauner wrote: I still can't see this patch in linux-next tree. What is happening?
{ "author": "Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>", "date": "Sun, 1 Feb 2026 13:03:36 +0900", "thread_id": "de541759cfa4d216e342bf15b07f93a21f46498b.camel@ibm.com.mbox.gz" }
lkml
[syzbot] [hfs?] kernel BUG in may_open (3)
Hello, syzbot found the following issue on: HEAD commit: b6151c4e60e5 Merge tag 'erofs-for-6.19-rc5-fixes' of git:/.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=15d45922580000 kernel config: https://syzkaller.appspot.com/x/.config?x=7b058fb1d7dbe6b1 dashboard link: https://syzkaller.appspot.com/bug?extid=f98189ed18c1f5f32e00 compiler: Debian clang version 20.1.8 (++20250708063551+0c9f909b7976-1~exp1~20250708183702.136), Debian LLD 20.1.8 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14a7d19a580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=16a2f19a580000 Downloadable assets: disk image: https://storage.googleapis.com/syzbot-assets/6eb5179ada01/disk-b6151c4e.raw.xz vmlinux: https://storage.googleapis.com/syzbot-assets/bc48d1a68ed0/vmlinux-b6151c4e.xz kernel image: https://storage.googleapis.com/syzbot-assets/061d4fb696a7/bzImage-b6151c4e.xz mounted in repro: https://storage.googleapis.com/syzbot-assets/df739de73585/mount_0.gz IMPORTANT: if you fix the issue, please add the following tag to the commit: Reported-by: syzbot+f98189ed18c1f5f32e00@syzkaller.appspotmail.com loop0: detected capacity change from 0 to 1024 VFS_BUG_ON_INODE(!IS_ANON_FILE(inode)) encountered for inode ffff8880384b01e0 fs hfsplus mode 0 opflags 0x4 flags 0x0 state 0x70 count 2 ------------[ cut here ]------------ kernel BUG at fs/namei.c:4210! Oops: invalid opcode: 0000 [#1] SMP KASAN PTI CPU: 1 UID: 0 PID: 6062 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT_{RT,(full)} Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/25/2025 RIP: 0010:may_open+0x4b1/0x4c0 fs/namei.c:4210 Code: 38 c1 0f 8c 1e fd ff ff 4c 89 e7 e8 c9 ec ef ff e9 11 fd ff ff e8 df b3 8d ff 4c 89 f7 48 c7 c6 80 53 f9 8a e8 10 eb f5 fe 90 <0f> 0b 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 RSP: 0018:ffffc90003ba78e0 EFLAGS: 00010282 RAX: 0000000000000088 RBX: dffffc0000000000 RCX: b41eda36b1e3ff00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000008241 R08: 0000000000000000 R09: 0000000000000000 R10: dffffc0000000000 R11: fffff52000774ec1 R12: 0000000000000000 R13: ffffffff8d709d80 R14: ffff8880384b01e0 R15: 0000000000000002 FS: 000055557d7cd500(0000) GS:ffff888126def000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f01916a5890 CR3: 0000000040598000 CR4: 00000000003526f0 Call Trace: <TASK> do_open fs/namei.c:4635 [inline] path_openat+0x32a8/0x3df0 fs/namei.c:4796 do_filp_open+0x1fa/0x410 fs/namei.c:4823 do_sys_openat2+0x121/0x200 fs/open.c:1430 do_sys_open fs/open.c:1436 [inline] __do_sys_creat fs/open.c:1514 [inline] __se_sys_creat fs/open.c:1508 [inline] __x64_sys_creat+0x8f/0xc0 fs/open.c:1508 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xec/0xf80 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f739c0cf749 Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007ffd4aa21ce8 EFLAGS: 00000246 ORIG_RAX: 0000000000000055 RAX: ffffffffffffffda RBX: 00007f739c325fa0 RCX: 00007f739c0cf749 RDX: 0000000000000000 RSI: 0000000000000006 RDI: 0000200000000140 RBP: 00007f739c153f91 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f739c325fa0 R14: 00007f739c325fa0 R15: 0000000000000002 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:may_open+0x4b1/0x4c0 fs/namei.c:4210 Code: 38 c1 0f 8c 1e fd ff ff 4c 89 e7 e8 c9 ec ef ff e9 11 fd ff ff e8 df b3 8d ff 4c 89 f7 48 c7 c6 80 53 f9 8a e8 10 eb f5 fe 90 <0f> 0b 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 RSP: 0018:ffffc90003ba78e0 EFLAGS: 00010282 RAX: 0000000000000088 RBX: dffffc0000000000 RCX: b41eda36b1e3ff00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000008241 R08: 0000000000000000 R09: 0000000000000000 R10: dffffc0000000000 R11: fffff52000774ec1 R12: 0000000000000000 R13: ffffffff8d709d80 R14: ffff8880384b01e0 R15: 0000000000000002 FS: 000055557d7cd500(0000) GS:ffff888126def000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f01916a5890 CR3: 0000000040598000 CR4: 00000000003526f0 --- 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 syzkaller@googlegroups.com. 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
On Sun, 2026-02-01 at 13:03 +0900, Tetsuo Handa wrote: The patch in HFS/HFS+ tree. I will send it in pull request for 6.20-rc1. Thanks, Slava.
{ "author": "Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>", "date": "Mon, 2 Feb 2026 17:30:56 +0000", "thread_id": "de541759cfa4d216e342bf15b07f93a21f46498b.camel@ibm.com.mbox.gz" }
lkml
[PATCH 0/2] arm64: dts: rockchip: fix Ethernet PHY on Theobroma PX30 devices
This removes the reliance on the bootloader setting up the Ethernet PHY for the Linux kernel to be able to use Ethernet. This is due to the HW default of the PHY reset line being active and the MDIO auto-detection mechanism not controlling a PHY's reset line such that we need to hardcode the PHY ID in the compatible property for it to be usable by the kernel, regardless of what the bootloader is doing. We only ever had one PHY (DP83825) for both devices, so it's fine to hardcode this way. Signed-off-by: Quentin Schulz <quentin.schulz@cherry.de> --- Quentin Schulz (2): arm64: dts: rockchip: fix Ethernet PHY not found on PX30 Cobra arm64: dts: rockchip: fix Ethernet PHY not found on PX30 Ringneck arch/arm64/boot/dts/rockchip/px30-cobra.dtsi | 2 +- arch/arm64/boot/dts/rockchip/px30-ringneck.dtsi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) --- base-commit: 4d310797262f0ddf129e76c2aad2b950adaf1fda change-id: 20260130-px30-eth-phy-676fa181e116 Best regards, -- Quentin Schulz <quentin.schulz@cherry.de>
From: Quentin Schulz <quentin.schulz@cherry.de> When not passing the PHY ID with an ethernet-phy-idX.Y compatible property, the MDIO bus will attempt to auto-detect the PHY by reading its registers and then probing the appropriate driver. For this to work, the PHY needs to be in a working state. Unfortunately, the net subsystem doesn't control the PHY reset GPIO when attempting to auto-detect the PHY. This means the PHY needs to be in a working state when entering the Linux kernel. This historically has been the case for this device, but only because the bootloader was taking care of initializing the Ethernet controller even when not using it. We're attempting to support the removal of the network stack in the bootloader, which means the Linux kernel will be entered with the PHY still in reset and now Ethernet doesn't work anymore. The devices in the field only ever had a TI DP83825, so let's simply bypass the auto-detection mechanism entirely by passing the appropriate PHY IDs via the compatible. Note that this is only an issue since commit e463625af7f9 ("arm64: dts: rockchip: move reset to dedicated eth-phy node on ringneck") as before that commit the reset was done by the MAC controller before starting the MDIO auto-detection mechanism, via the snps,reset-* properties. Cc: stable@vger.kernel.org Fixes: e463625af7f9 ("arm64: dts: rockchip: move reset to dedicated eth-phy node on ringneck") Signed-off-by: Quentin Schulz <quentin.schulz@cherry.de> --- arch/arm64/boot/dts/rockchip/px30-ringneck.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/rockchip/px30-ringneck.dtsi b/arch/arm64/boot/dts/rockchip/px30-ringneck.dtsi index 4203b335a2633..973b4c5880e24 100644 --- a/arch/arm64/boot/dts/rockchip/px30-ringneck.dtsi +++ b/arch/arm64/boot/dts/rockchip/px30-ringneck.dtsi @@ -344,7 +344,7 @@ &io_domains { &mdio { dp83825: ethernet-phy@0 { - compatible = "ethernet-phy-ieee802.3-c22"; + compatible = "ethernet-phy-id2000.a140"; reg = <0x0>; pinctrl-names = "default"; pinctrl-0 = <&phy_rst>; -- 2.52.0
{ "author": "Quentin Schulz <foss+kernel@0leil.net>", "date": "Mon, 02 Feb 2026 11:27:26 +0100", "thread_id": "20260202-px30-eth-phy-v1-0-ef365be64922@cherry.de.mbox.gz" }
lkml
[PATCH 0/2] arm64: dts: rockchip: fix Ethernet PHY on Theobroma PX30 devices
This removes the reliance on the bootloader setting up the Ethernet PHY for the Linux kernel to be able to use Ethernet. This is due to the HW default of the PHY reset line being active and the MDIO auto-detection mechanism not controlling a PHY's reset line such that we need to hardcode the PHY ID in the compatible property for it to be usable by the kernel, regardless of what the bootloader is doing. We only ever had one PHY (DP83825) for both devices, so it's fine to hardcode this way. Signed-off-by: Quentin Schulz <quentin.schulz@cherry.de> --- Quentin Schulz (2): arm64: dts: rockchip: fix Ethernet PHY not found on PX30 Cobra arm64: dts: rockchip: fix Ethernet PHY not found on PX30 Ringneck arch/arm64/boot/dts/rockchip/px30-cobra.dtsi | 2 +- arch/arm64/boot/dts/rockchip/px30-ringneck.dtsi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) --- base-commit: 4d310797262f0ddf129e76c2aad2b950adaf1fda change-id: 20260130-px30-eth-phy-676fa181e116 Best regards, -- Quentin Schulz <quentin.schulz@cherry.de>
From: Quentin Schulz <quentin.schulz@cherry.de> When not passing the PHY ID with an ethernet-phy-idX.Y compatible property, the MDIO bus will attempt to auto-detect the PHY by reading its registers and then probing the appropriate driver. For this to work, the PHY needs to be in a working state. Unfortunately, the net subsystem doesn't control the PHY reset GPIO when attempting to auto-detect the PHY. This means the PHY needs to be in a working state when entering the Linux kernel. This historically has been the case for this device, but only because the bootloader was taking care of initializing the Ethernet controller even when not using it. We're attempting to support the removal of the network stack in the bootloader, which means the Linux kernel will be entered with the PHY still in reset and now Ethernet doesn't work anymore. The devices in the field only ever had a TI DP83825, so let's simply bypass the auto-detection mechanism entirely by passing the appropriate PHY IDs via the compatible. Cc: stable@vger.kernel.org Fixes: bb510ddc9d3e ("arm64: dts: rockchip: add px30-cobra base dtsi and board variants") Signed-off-by: Quentin Schulz <quentin.schulz@cherry.de> --- arch/arm64/boot/dts/rockchip/px30-cobra.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/rockchip/px30-cobra.dtsi b/arch/arm64/boot/dts/rockchip/px30-cobra.dtsi index b7e669d8ba4d1..add917af5de78 100644 --- a/arch/arm64/boot/dts/rockchip/px30-cobra.dtsi +++ b/arch/arm64/boot/dts/rockchip/px30-cobra.dtsi @@ -397,7 +397,7 @@ &io_domains { &mdio { dp83825: ethernet-phy@0 { - compatible = "ethernet-phy-ieee802.3-c22"; + compatible = "ethernet-phy-id2000.a140"; reg = <0x0>; pinctrl-names = "default"; pinctrl-0 = <&phy_rst>; -- 2.52.0
{ "author": "Quentin Schulz <foss+kernel@0leil.net>", "date": "Mon, 02 Feb 2026 11:27:25 +0100", "thread_id": "20260202-px30-eth-phy-v1-0-ef365be64922@cherry.de.mbox.gz" }
lkml
[PATCH 0/2] arm64: dts: rockchip: fix Ethernet PHY on Theobroma PX30 devices
This removes the reliance on the bootloader setting up the Ethernet PHY for the Linux kernel to be able to use Ethernet. This is due to the HW default of the PHY reset line being active and the MDIO auto-detection mechanism not controlling a PHY's reset line such that we need to hardcode the PHY ID in the compatible property for it to be usable by the kernel, regardless of what the bootloader is doing. We only ever had one PHY (DP83825) for both devices, so it's fine to hardcode this way. Signed-off-by: Quentin Schulz <quentin.schulz@cherry.de> --- Quentin Schulz (2): arm64: dts: rockchip: fix Ethernet PHY not found on PX30 Cobra arm64: dts: rockchip: fix Ethernet PHY not found on PX30 Ringneck arch/arm64/boot/dts/rockchip/px30-cobra.dtsi | 2 +- arch/arm64/boot/dts/rockchip/px30-ringneck.dtsi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) --- base-commit: 4d310797262f0ddf129e76c2aad2b950adaf1fda change-id: 20260130-px30-eth-phy-676fa181e116 Best regards, -- Quentin Schulz <quentin.schulz@cherry.de>
On Mon, Feb 02, 2026 at 11:27:25AM +0100, Quentin Schulz wrote: What is the justification for stable? Andrew
{ "author": "Andrew Lunn <andrew@lunn.ch>", "date": "Mon, 2 Feb 2026 14:52:18 +0100", "thread_id": "20260202-px30-eth-phy-v1-0-ef365be64922@cherry.de.mbox.gz" }
lkml
[PATCH 0/2] arm64: dts: rockchip: fix Ethernet PHY on Theobroma PX30 devices
This removes the reliance on the bootloader setting up the Ethernet PHY for the Linux kernel to be able to use Ethernet. This is due to the HW default of the PHY reset line being active and the MDIO auto-detection mechanism not controlling a PHY's reset line such that we need to hardcode the PHY ID in the compatible property for it to be usable by the kernel, regardless of what the bootloader is doing. We only ever had one PHY (DP83825) for both devices, so it's fine to hardcode this way. Signed-off-by: Quentin Schulz <quentin.schulz@cherry.de> --- Quentin Schulz (2): arm64: dts: rockchip: fix Ethernet PHY not found on PX30 Cobra arm64: dts: rockchip: fix Ethernet PHY not found on PX30 Ringneck arch/arm64/boot/dts/rockchip/px30-cobra.dtsi | 2 +- arch/arm64/boot/dts/rockchip/px30-ringneck.dtsi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) --- base-commit: 4d310797262f0ddf129e76c2aad2b950adaf1fda change-id: 20260130-px30-eth-phy-676fa181e116 Best regards, -- Quentin Schulz <quentin.schulz@cherry.de>
Hi Andrew, On 2/2/26 2:52 PM, Andrew Lunn wrote: Bootloader without network stack = no network in Linux. Cheers, Quentin
{ "author": "Quentin Schulz <quentin.schulz@cherry.de>", "date": "Mon, 2 Feb 2026 15:02:08 +0100", "thread_id": "20260202-px30-eth-phy-v1-0-ef365be64922@cherry.de.mbox.gz" }
lkml
[PATCH 0/2] arm64: dts: rockchip: fix Ethernet PHY on Theobroma PX30 devices
This removes the reliance on the bootloader setting up the Ethernet PHY for the Linux kernel to be able to use Ethernet. This is due to the HW default of the PHY reset line being active and the MDIO auto-detection mechanism not controlling a PHY's reset line such that we need to hardcode the PHY ID in the compatible property for it to be usable by the kernel, regardless of what the bootloader is doing. We only ever had one PHY (DP83825) for both devices, so it's fine to hardcode this way. Signed-off-by: Quentin Schulz <quentin.schulz@cherry.de> --- Quentin Schulz (2): arm64: dts: rockchip: fix Ethernet PHY not found on PX30 Cobra arm64: dts: rockchip: fix Ethernet PHY not found on PX30 Ringneck arch/arm64/boot/dts/rockchip/px30-cobra.dtsi | 2 +- arch/arm64/boot/dts/rockchip/px30-ringneck.dtsi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) --- base-commit: 4d310797262f0ddf129e76c2aad2b950adaf1fda change-id: 20260130-px30-eth-phy-676fa181e116 Best regards, -- Quentin Schulz <quentin.schulz@cherry.de>
On Mon, Feb 02, 2026 at 03:02:08PM +0100, Quentin Schulz wrote: I can see this multiple ways.... Changing the bootloader introduces a regression. Hence you cannot change the bootloader. I personally also don't like boot loaders with basic functionality missing. Why cripple the bootloader by removing the network stack? But i also don't like Linux being dependent on the bootloader. Because some vendors ship boards with crippled bootloaders and you need to replace the bootloader. And then hidden vendor initialization is not in the mainline version of the bootloader, and something breaks in Linux. Making Linux more robust is generally ongoing development, not a bug fix. However, it bootloader developers decide to break the contract between the bootloader and the kernel, regressions have been reported, then it would make sense to backport the fix to work around the bootloader breakage. I don't know the internal of uboot too well. Can you remove the IP stack, but leave the drivers? Get the driver to probe and setup the PHY, so you keep the agreed contract with Linux, but you also get the crippled bootloader you want. For the commit message, i would like to see a reasoned argument, based on https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html why this should be in stable. Andrew
{ "author": "Andrew Lunn <andrew@lunn.ch>", "date": "Mon, 2 Feb 2026 15:55:56 +0100", "thread_id": "20260202-px30-eth-phy-v1-0-ef365be64922@cherry.de.mbox.gz" }
lkml
[PATCH 0/2] arm64: dts: rockchip: fix Ethernet PHY on Theobroma PX30 devices
This removes the reliance on the bootloader setting up the Ethernet PHY for the Linux kernel to be able to use Ethernet. This is due to the HW default of the PHY reset line being active and the MDIO auto-detection mechanism not controlling a PHY's reset line such that we need to hardcode the PHY ID in the compatible property for it to be usable by the kernel, regardless of what the bootloader is doing. We only ever had one PHY (DP83825) for both devices, so it's fine to hardcode this way. Signed-off-by: Quentin Schulz <quentin.schulz@cherry.de> --- Quentin Schulz (2): arm64: dts: rockchip: fix Ethernet PHY not found on PX30 Cobra arm64: dts: rockchip: fix Ethernet PHY not found on PX30 Ringneck arch/arm64/boot/dts/rockchip/px30-cobra.dtsi | 2 +- arch/arm64/boot/dts/rockchip/px30-ringneck.dtsi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) --- base-commit: 4d310797262f0ddf129e76c2aad2b950adaf1fda change-id: 20260130-px30-eth-phy-676fa181e116 Best regards, -- Quentin Schulz <quentin.schulz@cherry.de>
On 2/2/26 3:55 PM, Andrew Lunn wrote: Ringneck is a SoM (system-on-module), I don't control what the user wants to do with it. So they may never have the networking stack enabled in the first place (I provide a U-Boot defconfig to use with the devkit, but I don't control what they do with it; it's also supported upstream so if they want to use that, they can). The answer is pretty simple here, no network stack, no bug to exploit there, smaller binary, faster boot. On finished products with secure boot, a crippled bootloader is fine (and desired). It does what it's supposed to do, nothing else. I also don't control what our clients will do with our SoM in their product (and I don't necessarily have feedback either). That's my main concern and only reason for marking this a stable candidate. We shouldn't have to rely on the bootloader doing something. This issue is not related to an API between the bootloader and kernel, so there's no explicit contract. There would be no reason for U-Boot to support having networking drivers compiled in when there's no network stack so I would even go as far as saying if that's the case, it's a bug. If I were to enable a MAC controller and Ethernet PHY drivers with menuconfig, I'd expect them to be working in U-Boot. In any case, I'm not interested in doing that if that even is possible. Audit companies and certification authorities may look into what's compiled in and ask questions about those drivers or stacks. Not compiled in, don't need to argue about them (I have had to do this for every CVE in the kernel in the past, so it's not a theoretical). If I wanted to go this route, I can simply toggle the PHY reset GPIO in U-Boot and be done with it. I still cannot control whether our Ringneck users had the network stack enabled in their bootloader and cannot force them to patch it to either add the network stack or this PHY reset toggling. I want a clean solution if I can have one. Cobra support was upstreamed with this issue, so I could see this as not being a candidate for stable but an improvement according to the standard you stated. Ringneck on the other hand used to work without a network stack in U-Boot before https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e463625af7f92c4a9f097f7fb87f6baaad6e762a, so I think this is a regression (I don't control the bootloader of the final user, only the default one on our devkit but even then, I don't control what they flash on their setups). Also just to be clear, Theobroma (theobroma-systems.com domain name for mails, "tsd," prefix in compatibles) was acquired by CHERRY (cherry.de domain name for mails) in 2021, we're the manufacturer, vendor and developer of the boards in this patch series. (Not sure if it helps, but I can imagine some confusion with my mail address and the original name of the device manufacturer). Since you haven't answered on patch 2, I'm assuming that """ Note that this is only an issue since commit e463625af7f9 ("arm64: dts: rockchip: move reset to dedicated eth-phy node on ringneck") as before that commit the reset was done by the MAC controller before starting the MDIO auto-detection mechanism, via the snps,reset-* properties. """ is a reasoned argument for making that patch a stable candidate. I don't care too much about stable releases for Cobra as no third party is or will be involved in BSP development so I know for sure which version we're using and that it is appropriately patched (until we migrate to a newer kernel with this patch merged). Also, we're the only one able to change anything on that device due to secure boot so no need to care about hypothetical flashing. So Heiko, if you agree with Andrew here you can either drop the trailer when applying this patch or I can send a v2 dropping the Cc: stable trailer for the Cobra patch. For what it's worth, I agree with what you've said Andrew. I sympathize with the dilemma. Quentin
{ "author": "Quentin Schulz <quentin.schulz@cherry.de>", "date": "Mon, 2 Feb 2026 17:31:58 +0100", "thread_id": "20260202-px30-eth-phy-v1-0-ef365be64922@cherry.de.mbox.gz" }
lkml
[PATCH 5.15.y 1/3] wifi: cfg80211: add a work abstraction with special semantics
From: Johannes Berg <johannes.berg@intel.com> [ Upstream commit a3ee4dc84c4e9d14cb34dad095fd678127aca5b6 ] Add a work abstraction at the cfg80211 level that will always hold the wiphy_lock() for any work executed and therefore also can be canceled safely (without waiting) while holding that. This improves on what we do now as with the new wiphy works we don't have to worry about locking while cancelling them safely. Also, don't let such works run while the device is suspended, since they'll likely need to interact with the device. Flush them before suspend though. Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: Hanne-Lotta Mäenpää <hannelotta@gmail.com> --- include/net/cfg80211.h | 95 ++++++++++++++++++++++++++++++-- net/wireless/core.c | 121 +++++++++++++++++++++++++++++++++++++++++ net/wireless/core.h | 7 +++ net/wireless/sysfs.c | 8 ++- 4 files changed, 226 insertions(+), 5 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 66a75723f559..392576342661 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -5301,12 +5301,17 @@ struct cfg80211_cqm_config; * wiphy_lock - lock the wiphy * @wiphy: the wiphy to lock * - * This is mostly exposed so it can be done around registering and - * unregistering netdevs that aren't created through cfg80211 calls, - * since that requires locking in cfg80211 when the notifiers is - * called, but that cannot differentiate which way it's called. + * This is needed around registering and unregistering netdevs that + * aren't created through cfg80211 calls, since that requires locking + * in cfg80211 when the notifiers is called, but that cannot + * differentiate which way it's called. + * + * It can also be used by drivers for their own purposes. * * When cfg80211 ops are called, the wiphy is already locked. + * + * Note that this makes sure that no workers that have been queued + * with wiphy_queue_work() are running. */ static inline void wiphy_lock(struct wiphy *wiphy) __acquires(&wiphy->mtx) @@ -5326,6 +5331,88 @@ static inline void wiphy_unlock(struct wiphy *wiphy) mutex_unlock(&wiphy->mtx); } +struct wiphy_work; +typedef void (*wiphy_work_func_t)(struct wiphy *, struct wiphy_work *); + +struct wiphy_work { + struct list_head entry; + wiphy_work_func_t func; +}; + +static inline void wiphy_work_init(struct wiphy_work *work, + wiphy_work_func_t func) +{ + INIT_LIST_HEAD(&work->entry); + work->func = func; +} + +/** + * wiphy_work_queue - queue work for the wiphy + * @wiphy: the wiphy to queue for + * @work: the work item + * + * This is useful for work that must be done asynchronously, and work + * queued here has the special property that the wiphy mutex will be + * held as if wiphy_lock() was called, and that it cannot be running + * after wiphy_lock() was called. Therefore, wiphy_cancel_work() can + * use just cancel_work() instead of cancel_work_sync(), it requires + * being in a section protected by wiphy_lock(). + */ +void wiphy_work_queue(struct wiphy *wiphy, struct wiphy_work *work); + +/** + * wiphy_work_cancel - cancel previously queued work + * @wiphy: the wiphy, for debug purposes + * @work: the work to cancel + * + * Cancel the work *without* waiting for it, this assumes being + * called under the wiphy mutex acquired by wiphy_lock(). + */ +void wiphy_work_cancel(struct wiphy *wiphy, struct wiphy_work *work); + +struct wiphy_delayed_work { + struct wiphy_work work; + struct wiphy *wiphy; + struct timer_list timer; +}; + +void wiphy_delayed_work_timer(struct timer_list *t); + +static inline void wiphy_delayed_work_init(struct wiphy_delayed_work *dwork, + wiphy_work_func_t func) +{ + timer_setup(&dwork->timer, wiphy_delayed_work_timer, 0); + wiphy_work_init(&dwork->work, func); +} + +/** + * wiphy_delayed_work_queue - queue delayed work for the wiphy + * @wiphy: the wiphy to queue for + * @dwork: the delayable worker + * @delay: number of jiffies to wait before queueing + * + * This is useful for work that must be done asynchronously, and work + * queued here has the special property that the wiphy mutex will be + * held as if wiphy_lock() was called, and that it cannot be running + * after wiphy_lock() was called. Therefore, wiphy_cancel_work() can + * use just cancel_work() instead of cancel_work_sync(), it requires + * being in a section protected by wiphy_lock(). + */ +void wiphy_delayed_work_queue(struct wiphy *wiphy, + struct wiphy_delayed_work *dwork, + unsigned long delay); + +/** + * wiphy_delayed_work_cancel - cancel previously queued delayed work + * @wiphy: the wiphy, for debug purposes + * @dwork: the delayed work to cancel + * + * Cancel the work *without* waiting for it, this assumes being + * called under the wiphy mutex acquired by wiphy_lock(). + */ +void wiphy_delayed_work_cancel(struct wiphy *wiphy, + struct wiphy_delayed_work *dwork); + /** * struct wireless_dev - wireless device state * diff --git a/net/wireless/core.c b/net/wireless/core.c index d51d27ff3729..788ca1055d6a 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -410,6 +410,34 @@ static void cfg80211_propagate_cac_done_wk(struct work_struct *work) rtnl_unlock(); } +static void cfg80211_wiphy_work(struct work_struct *work) +{ + struct cfg80211_registered_device *rdev; + struct wiphy_work *wk; + + rdev = container_of(work, struct cfg80211_registered_device, wiphy_work); + + wiphy_lock(&rdev->wiphy); + if (rdev->suspended) + goto out; + + spin_lock_irq(&rdev->wiphy_work_lock); + wk = list_first_entry_or_null(&rdev->wiphy_work_list, + struct wiphy_work, entry); + if (wk) { + list_del_init(&wk->entry); + if (!list_empty(&rdev->wiphy_work_list)) + schedule_work(work); + spin_unlock_irq(&rdev->wiphy_work_lock); + + wk->func(&rdev->wiphy, wk); + } else { + spin_unlock_irq(&rdev->wiphy_work_lock); + } +out: + wiphy_unlock(&rdev->wiphy); +} + /* exported functions */ struct wiphy *wiphy_new_nm(const struct cfg80211_ops *ops, int sizeof_priv, @@ -535,6 +563,9 @@ struct wiphy *wiphy_new_nm(const struct cfg80211_ops *ops, int sizeof_priv, return NULL; } + INIT_WORK(&rdev->wiphy_work, cfg80211_wiphy_work); + INIT_LIST_HEAD(&rdev->wiphy_work_list); + spin_lock_init(&rdev->wiphy_work_lock); INIT_WORK(&rdev->rfkill_block, cfg80211_rfkill_block_work); INIT_WORK(&rdev->conn_work, cfg80211_conn_work); INIT_WORK(&rdev->event_work, cfg80211_event_work); @@ -1002,6 +1033,31 @@ void wiphy_rfkill_start_polling(struct wiphy *wiphy) } EXPORT_SYMBOL(wiphy_rfkill_start_polling); +void cfg80211_process_wiphy_works(struct cfg80211_registered_device *rdev) +{ + unsigned int runaway_limit = 100; + unsigned long flags; + + lockdep_assert_held(&rdev->wiphy.mtx); + + spin_lock_irqsave(&rdev->wiphy_work_lock, flags); + while (!list_empty(&rdev->wiphy_work_list)) { + struct wiphy_work *wk; + + wk = list_first_entry(&rdev->wiphy_work_list, + struct wiphy_work, entry); + list_del_init(&wk->entry); + spin_unlock_irqrestore(&rdev->wiphy_work_lock, flags); + + wk->func(&rdev->wiphy, wk); + + spin_lock_irqsave(&rdev->wiphy_work_lock, flags); + if (WARN_ON(--runaway_limit == 0)) + INIT_LIST_HEAD(&rdev->wiphy_work_list); + } + spin_unlock_irqrestore(&rdev->wiphy_work_lock, flags); +} + void wiphy_unregister(struct wiphy *wiphy) { struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); @@ -1040,9 +1096,14 @@ void wiphy_unregister(struct wiphy *wiphy) cfg80211_rdev_list_generation++; device_del(&rdev->wiphy.dev); + /* surely nothing is reachable now, clean up work */ + cfg80211_process_wiphy_works(rdev); wiphy_unlock(&rdev->wiphy); rtnl_unlock(); + /* this has nothing to do now but make sure it's gone */ + cancel_work_sync(&rdev->wiphy_work); + flush_work(&rdev->scan_done_wk); cancel_work_sync(&rdev->conn_work); flush_work(&rdev->event_work); @@ -1522,6 +1583,66 @@ static struct pernet_operations cfg80211_pernet_ops = { .exit = cfg80211_pernet_exit, }; +void wiphy_work_queue(struct wiphy *wiphy, struct wiphy_work *work) +{ + struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); + unsigned long flags; + + spin_lock_irqsave(&rdev->wiphy_work_lock, flags); + if (list_empty(&work->entry)) + list_add_tail(&work->entry, &rdev->wiphy_work_list); + spin_unlock_irqrestore(&rdev->wiphy_work_lock, flags); + + schedule_work(&rdev->wiphy_work); +} +EXPORT_SYMBOL_GPL(wiphy_work_queue); + +void wiphy_work_cancel(struct wiphy *wiphy, struct wiphy_work *work) +{ + struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); + unsigned long flags; + + lockdep_assert_held(&wiphy->mtx); + + spin_lock_irqsave(&rdev->wiphy_work_lock, flags); + if (!list_empty(&work->entry)) + list_del_init(&work->entry); + spin_unlock_irqrestore(&rdev->wiphy_work_lock, flags); +} +EXPORT_SYMBOL_GPL(wiphy_work_cancel); + +void wiphy_delayed_work_timer(struct timer_list *t) +{ + struct wiphy_delayed_work *dwork = from_timer(dwork, t, timer); + + wiphy_work_queue(dwork->wiphy, &dwork->work); +} +EXPORT_SYMBOL(wiphy_delayed_work_timer); + +void wiphy_delayed_work_queue(struct wiphy *wiphy, + struct wiphy_delayed_work *dwork, + unsigned long delay) +{ + if (!delay) { + wiphy_work_queue(wiphy, &dwork->work); + return; + } + + dwork->wiphy = wiphy; + mod_timer(&dwork->timer, jiffies + delay); +} +EXPORT_SYMBOL_GPL(wiphy_delayed_work_queue); + +void wiphy_delayed_work_cancel(struct wiphy *wiphy, + struct wiphy_delayed_work *dwork) +{ + lockdep_assert_held(&wiphy->mtx); + + del_timer_sync(&dwork->timer); + wiphy_work_cancel(wiphy, &dwork->work); +} +EXPORT_SYMBOL_GPL(wiphy_delayed_work_cancel); + static int __init cfg80211_init(void) { int err; diff --git a/net/wireless/core.h b/net/wireless/core.h index 1720abf36f92..18d30f6fa7ca 100644 --- a/net/wireless/core.h +++ b/net/wireless/core.h @@ -103,6 +103,12 @@ struct cfg80211_registered_device { /* lock for all wdev lists */ spinlock_t mgmt_registrations_lock; + struct work_struct wiphy_work; + struct list_head wiphy_work_list; + /* protects the list above */ + spinlock_t wiphy_work_lock; + bool suspended; + /* must be last because of the way we do wiphy_priv(), * and it should at least be aligned to NETDEV_ALIGN */ struct wiphy wiphy __aligned(NETDEV_ALIGN); @@ -457,6 +463,7 @@ int cfg80211_change_iface(struct cfg80211_registered_device *rdev, struct net_device *dev, enum nl80211_iftype ntype, struct vif_params *params); void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev); +void cfg80211_process_wiphy_works(struct cfg80211_registered_device *rdev); void cfg80211_process_wdev_events(struct wireless_dev *wdev); bool cfg80211_does_bw_fit_range(const struct ieee80211_freq_range *freq_range, diff --git a/net/wireless/sysfs.c b/net/wireless/sysfs.c index 0c3f05c9be27..4d3b65803010 100644 --- a/net/wireless/sysfs.c +++ b/net/wireless/sysfs.c @@ -5,7 +5,7 @@ * * Copyright 2005-2006 Jiri Benc <jbenc@suse.cz> * Copyright 2006 Johannes Berg <johannes@sipsolutions.net> - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2021, 2023 Intel Corporation */ #include <linux/device.h> @@ -105,14 +105,18 @@ static int wiphy_suspend(struct device *dev) cfg80211_leave_all(rdev); cfg80211_process_rdev_events(rdev); } + cfg80211_process_wiphy_works(rdev); if (rdev->ops->suspend) ret = rdev_suspend(rdev, rdev->wiphy.wowlan_config); if (ret == 1) { /* Driver refuse to configure wowlan */ cfg80211_leave_all(rdev); cfg80211_process_rdev_events(rdev); + cfg80211_process_wiphy_works(rdev); ret = rdev_suspend(rdev, NULL); } + if (ret == 0) + rdev->suspended = true; } wiphy_unlock(&rdev->wiphy); rtnl_unlock(); @@ -132,6 +136,8 @@ static int wiphy_resume(struct device *dev) wiphy_lock(&rdev->wiphy); if (rdev->wiphy.registered && rdev->ops->resume) ret = rdev_resume(rdev); + rdev->suspended = false; + schedule_work(&rdev->wiphy_work); wiphy_unlock(&rdev->wiphy); if (ret) -- 2.53.0.rc2.2.g2258446484
From: Johannes Berg <johannes.berg@intel.com> [ Upstream commit 16114496d684a3df4ce09f7c6b7557a8b2922795 ] We'll need this later to convert other works that might be cancelled from here, so convert this one first. Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: Hanne-Lotta Mäenpää <hannelotta@gmail.com> --- net/mac80211/ibss.c | 8 ++++---- net/mac80211/ieee80211_i.h | 2 +- net/mac80211/iface.c | 10 +++++----- net/mac80211/mesh.c | 10 +++++----- net/mac80211/mesh_hwmp.c | 6 +++--- net/mac80211/mlme.c | 6 +++--- net/mac80211/ocb.c | 6 +++--- net/mac80211/rx.c | 2 +- net/mac80211/scan.c | 2 +- net/mac80211/status.c | 5 +++-- net/mac80211/util.c | 2 +- 11 files changed, 30 insertions(+), 29 deletions(-) diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c index 48e0260f3424..ce927c16a915 100644 --- a/net/mac80211/ibss.c +++ b/net/mac80211/ibss.c @@ -746,7 +746,7 @@ static void ieee80211_csa_connection_drop_work(struct work_struct *work) skb_queue_purge(&sdata->skb_queue); /* trigger a scan to find another IBSS network to join */ - ieee80211_queue_work(&sdata->local->hw, &sdata->work); + wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work); sdata_unlock(sdata); } @@ -1245,7 +1245,7 @@ void ieee80211_ibss_rx_no_sta(struct ieee80211_sub_if_data *sdata, spin_lock(&ifibss->incomplete_lock); list_add(&sta->list, &ifibss->incomplete_stations); spin_unlock(&ifibss->incomplete_lock); - ieee80211_queue_work(&local->hw, &sdata->work); + wiphy_work_queue(local->hw.wiphy, &sdata->work); } static void ieee80211_ibss_sta_expire(struct ieee80211_sub_if_data *sdata) @@ -1726,7 +1726,7 @@ static void ieee80211_ibss_timer(struct timer_list *t) struct ieee80211_sub_if_data *sdata = from_timer(sdata, t, u.ibss.timer); - ieee80211_queue_work(&sdata->local->hw, &sdata->work); + wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work); } void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata) @@ -1861,7 +1861,7 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata, sdata->needed_rx_chains = local->rx_chains; sdata->control_port_over_nl80211 = params->control_port_over_nl80211; - ieee80211_queue_work(&local->hw, &sdata->work); + wiphy_work_queue(local->hw.wiphy, &sdata->work); return 0; } diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 3b5350cfc0ee..8d6616f646e7 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -966,7 +966,7 @@ struct ieee80211_sub_if_data { /* used to reconfigure hardware SM PS */ struct work_struct recalc_smps; - struct work_struct work; + struct wiphy_work work; struct sk_buff_head skb_queue; struct sk_buff_head status_queue; diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c index e437bcadf4a2..eb7de2d455e1 100644 --- a/net/mac80211/iface.c +++ b/net/mac80211/iface.c @@ -43,7 +43,7 @@ * by either the RTNL, the iflist_mtx or RCU. */ -static void ieee80211_iface_work(struct work_struct *work); +static void ieee80211_iface_work(struct wiphy *wiphy, struct wiphy_work *work); bool __ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata) { @@ -539,7 +539,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata, bool going_do RCU_INIT_POINTER(local->p2p_sdata, NULL); fallthrough; default: - cancel_work_sync(&sdata->work); + wiphy_work_cancel(sdata->local->hw.wiphy, &sdata->work); /* * When we get here, the interface is marked down. * Free the remaining keys, if there are any @@ -1005,7 +1005,7 @@ int ieee80211_add_virtual_monitor(struct ieee80211_local *local) skb_queue_head_init(&sdata->skb_queue); skb_queue_head_init(&sdata->status_queue); - INIT_WORK(&sdata->work, ieee80211_iface_work); + wiphy_work_init(&sdata->work, ieee80211_iface_work); return 0; } @@ -1487,7 +1487,7 @@ static void ieee80211_iface_process_status(struct ieee80211_sub_if_data *sdata, } } -static void ieee80211_iface_work(struct work_struct *work) +static void ieee80211_iface_work(struct wiphy *wiphy, struct wiphy_work *work) { struct ieee80211_sub_if_data *sdata = container_of(work, struct ieee80211_sub_if_data, work); @@ -1590,7 +1590,7 @@ static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata, skb_queue_head_init(&sdata->skb_queue); skb_queue_head_init(&sdata->status_queue); - INIT_WORK(&sdata->work, ieee80211_iface_work); + wiphy_work_init(&sdata->work, ieee80211_iface_work); INIT_WORK(&sdata->recalc_smps, ieee80211_recalc_smps_work); INIT_WORK(&sdata->csa_finalize_work, ieee80211_csa_finalize_work); INIT_WORK(&sdata->color_change_finalize_work, ieee80211_color_change_finalize_work); diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c index 6202157f467b..2f888cbe6e2b 100644 --- a/net/mac80211/mesh.c +++ b/net/mac80211/mesh.c @@ -44,7 +44,7 @@ static void ieee80211_mesh_housekeeping_timer(struct timer_list *t) set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags); - ieee80211_queue_work(&local->hw, &sdata->work); + wiphy_work_queue(local->hw.wiphy, &sdata->work); } /** @@ -642,7 +642,7 @@ static void ieee80211_mesh_path_timer(struct timer_list *t) struct ieee80211_sub_if_data *sdata = from_timer(sdata, t, u.mesh.mesh_path_timer); - ieee80211_queue_work(&sdata->local->hw, &sdata->work); + wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work); } static void ieee80211_mesh_path_root_timer(struct timer_list *t) @@ -653,7 +653,7 @@ static void ieee80211_mesh_path_root_timer(struct timer_list *t) set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags); - ieee80211_queue_work(&sdata->local->hw, &sdata->work); + wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work); } void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh) @@ -1018,7 +1018,7 @@ void ieee80211_mbss_info_change_notify(struct ieee80211_sub_if_data *sdata, for_each_set_bit(bit, &bits, sizeof(changed) * BITS_PER_BYTE) set_bit(bit, &ifmsh->mbss_changed); set_bit(MESH_WORK_MBSS_CHANGED, &ifmsh->wrkq_flags); - ieee80211_queue_work(&sdata->local->hw, &sdata->work); + wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work); } int ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata) @@ -1043,7 +1043,7 @@ int ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata) ifmsh->sync_offset_clockdrift_max = 0; set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags); ieee80211_mesh_root_setup(ifmsh); - ieee80211_queue_work(&local->hw, &sdata->work); + wiphy_work_queue(local->hw.wiphy, &sdata->work); sdata->vif.bss_conf.ht_operation_mode = ifmsh->mshcfg.ht_opmode; sdata->vif.bss_conf.enable_beacon = true; diff --git a/net/mac80211/mesh_hwmp.c b/net/mac80211/mesh_hwmp.c index 8bf238afb544..a3522b21803f 100644 --- a/net/mac80211/mesh_hwmp.c +++ b/net/mac80211/mesh_hwmp.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2008, 2009 open80211s Ltd. - * Copyright (C) 2019, 2021 Intel Corporation + * Copyright (C) 2019, 2021-2023 Intel Corporation * Author: Luis Carlos Cobo <luisca@cozybit.com> */ @@ -1020,14 +1020,14 @@ static void mesh_queue_preq(struct mesh_path *mpath, u8 flags) spin_unlock_bh(&ifmsh->mesh_preq_queue_lock); if (time_after(jiffies, ifmsh->last_preq + min_preq_int_jiff(sdata))) - ieee80211_queue_work(&sdata->local->hw, &sdata->work); + wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work); else if (time_before(jiffies, ifmsh->last_preq)) { /* avoid long wait if did not send preqs for a long time * and jiffies wrapped around */ ifmsh->last_preq = jiffies - min_preq_int_jiff(sdata) - 1; - ieee80211_queue_work(&sdata->local->hw, &sdata->work); + wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work); } else mod_timer(&ifmsh->mesh_path_timer, ifmsh->last_preq + min_preq_int_jiff(sdata)); diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c index 6e86a23c647d..d147760e8389 100644 --- a/net/mac80211/mlme.c +++ b/net/mac80211/mlme.c @@ -2509,7 +2509,7 @@ void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata, sdata->u.mgd.probe_send_count = 0; else sdata->u.mgd.nullfunc_failed = true; - ieee80211_queue_work(&sdata->local->hw, &sdata->work); + wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work); } static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata, @@ -4415,7 +4415,7 @@ static void ieee80211_sta_timer(struct timer_list *t) struct ieee80211_sub_if_data *sdata = from_timer(sdata, t, u.mgd.timer); - ieee80211_queue_work(&sdata->local->hw, &sdata->work); + wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work); } void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata, @@ -4559,7 +4559,7 @@ void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata, sdata->u.mgd.status_acked = acked; sdata->u.mgd.status_received = true; - ieee80211_queue_work(&local->hw, &sdata->work); + wiphy_work_queue(local->hw.wiphy, &sdata->work); } void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata) diff --git a/net/mac80211/ocb.c b/net/mac80211/ocb.c index 7c1a735b9eee..9713e53f11b1 100644 --- a/net/mac80211/ocb.c +++ b/net/mac80211/ocb.c @@ -80,7 +80,7 @@ void ieee80211_ocb_rx_no_sta(struct ieee80211_sub_if_data *sdata, spin_lock(&ifocb->incomplete_lock); list_add(&sta->list, &ifocb->incomplete_stations); spin_unlock(&ifocb->incomplete_lock); - ieee80211_queue_work(&local->hw, &sdata->work); + wiphy_work_queue(local->hw.wiphy, &sdata->work); } static struct sta_info *ieee80211_ocb_finish_sta(struct sta_info *sta) @@ -156,7 +156,7 @@ static void ieee80211_ocb_housekeeping_timer(struct timer_list *t) set_bit(OCB_WORK_HOUSEKEEPING, &ifocb->wrkq_flags); - ieee80211_queue_work(&local->hw, &sdata->work); + wiphy_work_queue(local->hw.wiphy, &sdata->work); } void ieee80211_ocb_setup_sdata(struct ieee80211_sub_if_data *sdata) @@ -196,7 +196,7 @@ int ieee80211_ocb_join(struct ieee80211_sub_if_data *sdata, ifocb->joined = true; set_bit(OCB_WORK_HOUSEKEEPING, &ifocb->wrkq_flags); - ieee80211_queue_work(&local->hw, &sdata->work); + wiphy_work_queue(local->hw.wiphy, &sdata->work); netif_carrier_on(sdata->dev); return 0; diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index 1c1660160787..15933e9abc9b 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c @@ -219,7 +219,7 @@ static void __ieee80211_queue_skb_to_iface(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb) { skb_queue_tail(&sdata->skb_queue, skb); - ieee80211_queue_work(&sdata->local->hw, &sdata->work); + wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work); if (sta) sta->rx_stats.packets++; } diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c index 3bf3dd4bafa5..fd77c707e65c 100644 --- a/net/mac80211/scan.c +++ b/net/mac80211/scan.c @@ -498,7 +498,7 @@ static void __ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted) */ list_for_each_entry_rcu(sdata, &local->interfaces, list) { if (ieee80211_sdata_running(sdata)) - ieee80211_queue_work(&sdata->local->hw, &sdata->work); + wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work); } if (was_scanning) diff --git a/net/mac80211/status.c b/net/mac80211/status.c index f6f63a0b1b72..017ea2d2f36f 100644 --- a/net/mac80211/status.c +++ b/net/mac80211/status.c @@ -5,6 +5,7 @@ * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> * Copyright 2008-2010 Johannes Berg <johannes@sipsolutions.net> * Copyright 2013-2014 Intel Mobile Communications GmbH + * Copyright 2021-2023 Intel Corporation */ #include <linux/export.h> @@ -716,8 +717,8 @@ static void ieee80211_report_used_skb(struct ieee80211_local *local, if (qskb) { skb_queue_tail(&sdata->status_queue, qskb); - ieee80211_queue_work(&local->hw, - &sdata->work); + wiphy_work_queue(local->hw.wiphy, + &sdata->work); } } } else { diff --git a/net/mac80211/util.c b/net/mac80211/util.c index 07512f0d5576..5b1799dfa675 100644 --- a/net/mac80211/util.c +++ b/net/mac80211/util.c @@ -2679,7 +2679,7 @@ int ieee80211_reconfig(struct ieee80211_local *local) /* Requeue all works */ list_for_each_entry(sdata, &local->interfaces, list) - ieee80211_queue_work(&local->hw, &sdata->work); + wiphy_work_queue(local->hw.wiphy, &sdata->work); } ieee80211_wake_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP, -- 2.53.0.rc2.2.g2258446484
{ "author": "=?UTF-8?q?Hanne-Lotta=20M=C3=A4enp=C3=A4=C3=A4?= <hannelotta@gmail.com>", "date": "Mon, 2 Feb 2026 18:50:37 +0200", "thread_id": "20260202165038.215693-2-hannelotta@gmail.com.mbox.gz" }
lkml
[PATCH 5.15.y 1/3] wifi: cfg80211: add a work abstraction with special semantics
From: Johannes Berg <johannes.berg@intel.com> [ Upstream commit a3ee4dc84c4e9d14cb34dad095fd678127aca5b6 ] Add a work abstraction at the cfg80211 level that will always hold the wiphy_lock() for any work executed and therefore also can be canceled safely (without waiting) while holding that. This improves on what we do now as with the new wiphy works we don't have to worry about locking while cancelling them safely. Also, don't let such works run while the device is suspended, since they'll likely need to interact with the device. Flush them before suspend though. Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: Hanne-Lotta Mäenpää <hannelotta@gmail.com> --- include/net/cfg80211.h | 95 ++++++++++++++++++++++++++++++-- net/wireless/core.c | 121 +++++++++++++++++++++++++++++++++++++++++ net/wireless/core.h | 7 +++ net/wireless/sysfs.c | 8 ++- 4 files changed, 226 insertions(+), 5 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 66a75723f559..392576342661 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -5301,12 +5301,17 @@ struct cfg80211_cqm_config; * wiphy_lock - lock the wiphy * @wiphy: the wiphy to lock * - * This is mostly exposed so it can be done around registering and - * unregistering netdevs that aren't created through cfg80211 calls, - * since that requires locking in cfg80211 when the notifiers is - * called, but that cannot differentiate which way it's called. + * This is needed around registering and unregistering netdevs that + * aren't created through cfg80211 calls, since that requires locking + * in cfg80211 when the notifiers is called, but that cannot + * differentiate which way it's called. + * + * It can also be used by drivers for their own purposes. * * When cfg80211 ops are called, the wiphy is already locked. + * + * Note that this makes sure that no workers that have been queued + * with wiphy_queue_work() are running. */ static inline void wiphy_lock(struct wiphy *wiphy) __acquires(&wiphy->mtx) @@ -5326,6 +5331,88 @@ static inline void wiphy_unlock(struct wiphy *wiphy) mutex_unlock(&wiphy->mtx); } +struct wiphy_work; +typedef void (*wiphy_work_func_t)(struct wiphy *, struct wiphy_work *); + +struct wiphy_work { + struct list_head entry; + wiphy_work_func_t func; +}; + +static inline void wiphy_work_init(struct wiphy_work *work, + wiphy_work_func_t func) +{ + INIT_LIST_HEAD(&work->entry); + work->func = func; +} + +/** + * wiphy_work_queue - queue work for the wiphy + * @wiphy: the wiphy to queue for + * @work: the work item + * + * This is useful for work that must be done asynchronously, and work + * queued here has the special property that the wiphy mutex will be + * held as if wiphy_lock() was called, and that it cannot be running + * after wiphy_lock() was called. Therefore, wiphy_cancel_work() can + * use just cancel_work() instead of cancel_work_sync(), it requires + * being in a section protected by wiphy_lock(). + */ +void wiphy_work_queue(struct wiphy *wiphy, struct wiphy_work *work); + +/** + * wiphy_work_cancel - cancel previously queued work + * @wiphy: the wiphy, for debug purposes + * @work: the work to cancel + * + * Cancel the work *without* waiting for it, this assumes being + * called under the wiphy mutex acquired by wiphy_lock(). + */ +void wiphy_work_cancel(struct wiphy *wiphy, struct wiphy_work *work); + +struct wiphy_delayed_work { + struct wiphy_work work; + struct wiphy *wiphy; + struct timer_list timer; +}; + +void wiphy_delayed_work_timer(struct timer_list *t); + +static inline void wiphy_delayed_work_init(struct wiphy_delayed_work *dwork, + wiphy_work_func_t func) +{ + timer_setup(&dwork->timer, wiphy_delayed_work_timer, 0); + wiphy_work_init(&dwork->work, func); +} + +/** + * wiphy_delayed_work_queue - queue delayed work for the wiphy + * @wiphy: the wiphy to queue for + * @dwork: the delayable worker + * @delay: number of jiffies to wait before queueing + * + * This is useful for work that must be done asynchronously, and work + * queued here has the special property that the wiphy mutex will be + * held as if wiphy_lock() was called, and that it cannot be running + * after wiphy_lock() was called. Therefore, wiphy_cancel_work() can + * use just cancel_work() instead of cancel_work_sync(), it requires + * being in a section protected by wiphy_lock(). + */ +void wiphy_delayed_work_queue(struct wiphy *wiphy, + struct wiphy_delayed_work *dwork, + unsigned long delay); + +/** + * wiphy_delayed_work_cancel - cancel previously queued delayed work + * @wiphy: the wiphy, for debug purposes + * @dwork: the delayed work to cancel + * + * Cancel the work *without* waiting for it, this assumes being + * called under the wiphy mutex acquired by wiphy_lock(). + */ +void wiphy_delayed_work_cancel(struct wiphy *wiphy, + struct wiphy_delayed_work *dwork); + /** * struct wireless_dev - wireless device state * diff --git a/net/wireless/core.c b/net/wireless/core.c index d51d27ff3729..788ca1055d6a 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -410,6 +410,34 @@ static void cfg80211_propagate_cac_done_wk(struct work_struct *work) rtnl_unlock(); } +static void cfg80211_wiphy_work(struct work_struct *work) +{ + struct cfg80211_registered_device *rdev; + struct wiphy_work *wk; + + rdev = container_of(work, struct cfg80211_registered_device, wiphy_work); + + wiphy_lock(&rdev->wiphy); + if (rdev->suspended) + goto out; + + spin_lock_irq(&rdev->wiphy_work_lock); + wk = list_first_entry_or_null(&rdev->wiphy_work_list, + struct wiphy_work, entry); + if (wk) { + list_del_init(&wk->entry); + if (!list_empty(&rdev->wiphy_work_list)) + schedule_work(work); + spin_unlock_irq(&rdev->wiphy_work_lock); + + wk->func(&rdev->wiphy, wk); + } else { + spin_unlock_irq(&rdev->wiphy_work_lock); + } +out: + wiphy_unlock(&rdev->wiphy); +} + /* exported functions */ struct wiphy *wiphy_new_nm(const struct cfg80211_ops *ops, int sizeof_priv, @@ -535,6 +563,9 @@ struct wiphy *wiphy_new_nm(const struct cfg80211_ops *ops, int sizeof_priv, return NULL; } + INIT_WORK(&rdev->wiphy_work, cfg80211_wiphy_work); + INIT_LIST_HEAD(&rdev->wiphy_work_list); + spin_lock_init(&rdev->wiphy_work_lock); INIT_WORK(&rdev->rfkill_block, cfg80211_rfkill_block_work); INIT_WORK(&rdev->conn_work, cfg80211_conn_work); INIT_WORK(&rdev->event_work, cfg80211_event_work); @@ -1002,6 +1033,31 @@ void wiphy_rfkill_start_polling(struct wiphy *wiphy) } EXPORT_SYMBOL(wiphy_rfkill_start_polling); +void cfg80211_process_wiphy_works(struct cfg80211_registered_device *rdev) +{ + unsigned int runaway_limit = 100; + unsigned long flags; + + lockdep_assert_held(&rdev->wiphy.mtx); + + spin_lock_irqsave(&rdev->wiphy_work_lock, flags); + while (!list_empty(&rdev->wiphy_work_list)) { + struct wiphy_work *wk; + + wk = list_first_entry(&rdev->wiphy_work_list, + struct wiphy_work, entry); + list_del_init(&wk->entry); + spin_unlock_irqrestore(&rdev->wiphy_work_lock, flags); + + wk->func(&rdev->wiphy, wk); + + spin_lock_irqsave(&rdev->wiphy_work_lock, flags); + if (WARN_ON(--runaway_limit == 0)) + INIT_LIST_HEAD(&rdev->wiphy_work_list); + } + spin_unlock_irqrestore(&rdev->wiphy_work_lock, flags); +} + void wiphy_unregister(struct wiphy *wiphy) { struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); @@ -1040,9 +1096,14 @@ void wiphy_unregister(struct wiphy *wiphy) cfg80211_rdev_list_generation++; device_del(&rdev->wiphy.dev); + /* surely nothing is reachable now, clean up work */ + cfg80211_process_wiphy_works(rdev); wiphy_unlock(&rdev->wiphy); rtnl_unlock(); + /* this has nothing to do now but make sure it's gone */ + cancel_work_sync(&rdev->wiphy_work); + flush_work(&rdev->scan_done_wk); cancel_work_sync(&rdev->conn_work); flush_work(&rdev->event_work); @@ -1522,6 +1583,66 @@ static struct pernet_operations cfg80211_pernet_ops = { .exit = cfg80211_pernet_exit, }; +void wiphy_work_queue(struct wiphy *wiphy, struct wiphy_work *work) +{ + struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); + unsigned long flags; + + spin_lock_irqsave(&rdev->wiphy_work_lock, flags); + if (list_empty(&work->entry)) + list_add_tail(&work->entry, &rdev->wiphy_work_list); + spin_unlock_irqrestore(&rdev->wiphy_work_lock, flags); + + schedule_work(&rdev->wiphy_work); +} +EXPORT_SYMBOL_GPL(wiphy_work_queue); + +void wiphy_work_cancel(struct wiphy *wiphy, struct wiphy_work *work) +{ + struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); + unsigned long flags; + + lockdep_assert_held(&wiphy->mtx); + + spin_lock_irqsave(&rdev->wiphy_work_lock, flags); + if (!list_empty(&work->entry)) + list_del_init(&work->entry); + spin_unlock_irqrestore(&rdev->wiphy_work_lock, flags); +} +EXPORT_SYMBOL_GPL(wiphy_work_cancel); + +void wiphy_delayed_work_timer(struct timer_list *t) +{ + struct wiphy_delayed_work *dwork = from_timer(dwork, t, timer); + + wiphy_work_queue(dwork->wiphy, &dwork->work); +} +EXPORT_SYMBOL(wiphy_delayed_work_timer); + +void wiphy_delayed_work_queue(struct wiphy *wiphy, + struct wiphy_delayed_work *dwork, + unsigned long delay) +{ + if (!delay) { + wiphy_work_queue(wiphy, &dwork->work); + return; + } + + dwork->wiphy = wiphy; + mod_timer(&dwork->timer, jiffies + delay); +} +EXPORT_SYMBOL_GPL(wiphy_delayed_work_queue); + +void wiphy_delayed_work_cancel(struct wiphy *wiphy, + struct wiphy_delayed_work *dwork) +{ + lockdep_assert_held(&wiphy->mtx); + + del_timer_sync(&dwork->timer); + wiphy_work_cancel(wiphy, &dwork->work); +} +EXPORT_SYMBOL_GPL(wiphy_delayed_work_cancel); + static int __init cfg80211_init(void) { int err; diff --git a/net/wireless/core.h b/net/wireless/core.h index 1720abf36f92..18d30f6fa7ca 100644 --- a/net/wireless/core.h +++ b/net/wireless/core.h @@ -103,6 +103,12 @@ struct cfg80211_registered_device { /* lock for all wdev lists */ spinlock_t mgmt_registrations_lock; + struct work_struct wiphy_work; + struct list_head wiphy_work_list; + /* protects the list above */ + spinlock_t wiphy_work_lock; + bool suspended; + /* must be last because of the way we do wiphy_priv(), * and it should at least be aligned to NETDEV_ALIGN */ struct wiphy wiphy __aligned(NETDEV_ALIGN); @@ -457,6 +463,7 @@ int cfg80211_change_iface(struct cfg80211_registered_device *rdev, struct net_device *dev, enum nl80211_iftype ntype, struct vif_params *params); void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev); +void cfg80211_process_wiphy_works(struct cfg80211_registered_device *rdev); void cfg80211_process_wdev_events(struct wireless_dev *wdev); bool cfg80211_does_bw_fit_range(const struct ieee80211_freq_range *freq_range, diff --git a/net/wireless/sysfs.c b/net/wireless/sysfs.c index 0c3f05c9be27..4d3b65803010 100644 --- a/net/wireless/sysfs.c +++ b/net/wireless/sysfs.c @@ -5,7 +5,7 @@ * * Copyright 2005-2006 Jiri Benc <jbenc@suse.cz> * Copyright 2006 Johannes Berg <johannes@sipsolutions.net> - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2021, 2023 Intel Corporation */ #include <linux/device.h> @@ -105,14 +105,18 @@ static int wiphy_suspend(struct device *dev) cfg80211_leave_all(rdev); cfg80211_process_rdev_events(rdev); } + cfg80211_process_wiphy_works(rdev); if (rdev->ops->suspend) ret = rdev_suspend(rdev, rdev->wiphy.wowlan_config); if (ret == 1) { /* Driver refuse to configure wowlan */ cfg80211_leave_all(rdev); cfg80211_process_rdev_events(rdev); + cfg80211_process_wiphy_works(rdev); ret = rdev_suspend(rdev, NULL); } + if (ret == 0) + rdev->suspended = true; } wiphy_unlock(&rdev->wiphy); rtnl_unlock(); @@ -132,6 +136,8 @@ static int wiphy_resume(struct device *dev) wiphy_lock(&rdev->wiphy); if (rdev->wiphy.registered && rdev->ops->resume) ret = rdev_resume(rdev); + rdev->suspended = false; + schedule_work(&rdev->wiphy_work); wiphy_unlock(&rdev->wiphy); if (ret) -- 2.53.0.rc2.2.g2258446484
From: Johannes Berg <johannes.berg@intel.com> [ Upstream commit 777b26002b73127e81643d9286fadf3d41e0e477 ] Again, to have the wiphy locked for it. Reviewed-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com> Signed-off-by: Johannes Berg <johannes.berg@intel.com> [ Summary of conflict resolutions: - In mlme.c, move only tdls_peer_del_work to wiphy work, and none the other works ] Signed-off-by: Hanne-Lotta Mäenpää <hannelotta@gmail.com> --- net/mac80211/ieee80211_i.h | 4 ++-- net/mac80211/mlme.c | 7 ++++--- net/mac80211/tdls.c | 11 ++++++----- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 8d6616f646e7..306359d43571 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -542,7 +542,7 @@ struct ieee80211_if_managed { /* TDLS support */ u8 tdls_peer[ETH_ALEN] __aligned(2); - struct delayed_work tdls_peer_del_work; + struct wiphy_delayed_work tdls_peer_del_work; struct sk_buff *orig_teardown_skb; /* The original teardown skb */ struct sk_buff *teardown_skb; /* A copy to send through the AP */ spinlock_t teardown_lock; /* To lock changing teardown_skb */ @@ -2494,7 +2494,7 @@ int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev, size_t extra_ies_len); int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev, const u8 *peer, enum nl80211_tdls_operation oper); -void ieee80211_tdls_peer_del_work(struct work_struct *wk); +void ieee80211_tdls_peer_del_work(struct wiphy *wiphy, struct wiphy_work *wk); int ieee80211_tdls_channel_switch(struct wiphy *wiphy, struct net_device *dev, const u8 *addr, u8 oper_class, struct cfg80211_chan_def *chandef); diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c index d147760e8389..25468d5e874a 100644 --- a/net/mac80211/mlme.c +++ b/net/mac80211/mlme.c @@ -4890,8 +4890,8 @@ void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata) INIT_WORK(&ifmgd->csa_connection_drop_work, ieee80211_csa_connection_drop_work); INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work); - INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work, - ieee80211_tdls_peer_del_work); + wiphy_delayed_work_init(&ifmgd->tdls_peer_del_work, + ieee80211_tdls_peer_del_work); timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0); timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0); timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0); @@ -6010,7 +6010,8 @@ void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata) cancel_work_sync(&ifmgd->request_smps_work); cancel_work_sync(&ifmgd->csa_connection_drop_work); cancel_work_sync(&ifmgd->chswitch_work); - cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work); + wiphy_delayed_work_cancel(sdata->local->hw.wiphy, + &ifmgd->tdls_peer_del_work); sdata_lock(sdata); if (ifmgd->assoc_data) { diff --git a/net/mac80211/tdls.c b/net/mac80211/tdls.c index 137be9ec94af..c2d7479c119a 100644 --- a/net/mac80211/tdls.c +++ b/net/mac80211/tdls.c @@ -21,7 +21,7 @@ /* give usermode some time for retries in setting up the TDLS session */ #define TDLS_PEER_SETUP_TIMEOUT (15 * HZ) -void ieee80211_tdls_peer_del_work(struct work_struct *wk) +void ieee80211_tdls_peer_del_work(struct wiphy *wiphy, struct wiphy_work *wk) { struct ieee80211_sub_if_data *sdata; struct ieee80211_local *local; @@ -1126,9 +1126,9 @@ ieee80211_tdls_mgmt_setup(struct wiphy *wiphy, struct net_device *dev, return ret; } - ieee80211_queue_delayed_work(&sdata->local->hw, - &sdata->u.mgd.tdls_peer_del_work, - TDLS_PEER_SETUP_TIMEOUT); + wiphy_delayed_work_queue(sdata->local->hw.wiphy, + &sdata->u.mgd.tdls_peer_del_work, + TDLS_PEER_SETUP_TIMEOUT); return 0; out_unlock: @@ -1425,7 +1425,8 @@ int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev, } if (ret == 0 && ether_addr_equal(sdata->u.mgd.tdls_peer, peer)) { - cancel_delayed_work(&sdata->u.mgd.tdls_peer_del_work); + wiphy_delayed_work_cancel(sdata->local->hw.wiphy, + &sdata->u.mgd.tdls_peer_del_work); eth_zero_addr(sdata->u.mgd.tdls_peer); } -- 2.53.0.rc2.2.g2258446484
{ "author": "=?UTF-8?q?Hanne-Lotta=20M=C3=A4enp=C3=A4=C3=A4?= <hannelotta@gmail.com>", "date": "Mon, 2 Feb 2026 18:50:38 +0200", "thread_id": "20260202165038.215693-2-hannelotta@gmail.com.mbox.gz" }
lkml
[PATCH v2 0/2] ARM64 support for doorbell and intercept SINTs
From: "Anirudh Rayabharam (Microsoft)" <anirudh@anirudhrb.com> On x86, the HYPERVISOR_CALLBACK_VECTOR is used to receive synthetic interrupts (SINTs) from the hypervisor for doorbells and intercepts. There is no such vector reserved for arm64. On arm64, the INTID for SINTs should be in the SGI or PPI range. The hypervisor exposes a virtual device in the ACPI that reserves a PPI for this use. Introduce a platform_driver that binds to this ACPI device and obtains the interrupt vector that can be used for SINTs. Changes in v2: Addressed review comments: - Moved more stuff into mshv_synic.c - Code simplifications - Removed unnecessary debug prints v1: https://lore.kernel.org/linux-hyperv/20260128160437.3342167-1-anirudh@anirudhrb.com/ Anirudh Rayabharam (Microsoft) (2): mshv: refactor synic init and cleanup mshv: add arm64 support for doorbell & intercept SINTs drivers/hv/mshv_root.h | 5 +- drivers/hv/mshv_root_main.c | 59 ++------- drivers/hv/mshv_synic.c | 232 ++++++++++++++++++++++++++++++++++-- 3 files changed, 230 insertions(+), 66 deletions(-) -- 2.34.1
From: Anirudh Rayabharam (Microsoft) <anirudh@anirudhrb.com> Rename mshv_synic_init() to mshv_synic_cpu_init() and mshv_synic_cleanup() to mshv_synic_cpu_exit() to better reflect that these functions handle per-cpu synic setup and teardown. Use mshv_synic_init/cleanup() to perform init/cleanup that is not per-cpu. Move all the synic related setup from mshv_parent_partition_init. Move the reboot notifier to mshv_synic.c because it currently only operates on the synic cpuhp state. Move out synic_pages from the global mshv_root since it's use is now completely local to mshv_synic.c. This is in preparation for the next patch which will add more stuff to mshv_synic_init(). No functional change. Signed-off-by: Anirudh Rayabharam (Microsoft) <anirudh@anirudhrb.com> --- drivers/hv/mshv_root.h | 5 ++- drivers/hv/mshv_root_main.c | 59 +++++------------------------- drivers/hv/mshv_synic.c | 71 +++++++++++++++++++++++++++++++++---- 3 files changed, 75 insertions(+), 60 deletions(-) diff --git a/drivers/hv/mshv_root.h b/drivers/hv/mshv_root.h index 3c1d88b36741..26e0320c8097 100644 --- a/drivers/hv/mshv_root.h +++ b/drivers/hv/mshv_root.h @@ -183,7 +183,6 @@ struct hv_synic_pages { }; struct mshv_root { - struct hv_synic_pages __percpu *synic_pages; spinlock_t pt_ht_lock; DECLARE_HASHTABLE(pt_htable, MSHV_PARTITIONS_HASH_BITS); struct hv_partition_property_vmm_capabilities vmm_caps; @@ -242,8 +241,8 @@ int mshv_register_doorbell(u64 partition_id, doorbell_cb_t doorbell_cb, void mshv_unregister_doorbell(u64 partition_id, int doorbell_portid); void mshv_isr(void); -int mshv_synic_init(unsigned int cpu); -int mshv_synic_cleanup(unsigned int cpu); +int mshv_synic_init(struct device *dev); +void mshv_synic_cleanup(void); static inline bool mshv_partition_encrypted(struct mshv_partition *partition) { diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c index 681b58154d5e..7c1666456e78 100644 --- a/drivers/hv/mshv_root_main.c +++ b/drivers/hv/mshv_root_main.c @@ -2035,7 +2035,6 @@ mshv_dev_release(struct inode *inode, struct file *filp) return 0; } -static int mshv_cpuhp_online; static int mshv_root_sched_online; static const char *scheduler_type_to_string(enum hv_scheduler_type type) @@ -2198,40 +2197,14 @@ root_scheduler_deinit(void) free_percpu(root_scheduler_output); } -static int mshv_reboot_notify(struct notifier_block *nb, - unsigned long code, void *unused) -{ - cpuhp_remove_state(mshv_cpuhp_online); - return 0; -} - -struct notifier_block mshv_reboot_nb = { - .notifier_call = mshv_reboot_notify, -}; - static void mshv_root_partition_exit(void) { - unregister_reboot_notifier(&mshv_reboot_nb); root_scheduler_deinit(); } static int __init mshv_root_partition_init(struct device *dev) { - int err; - - err = root_scheduler_init(dev); - if (err) - return err; - - err = register_reboot_notifier(&mshv_reboot_nb); - if (err) - goto root_sched_deinit; - - return 0; - -root_sched_deinit: - root_scheduler_deinit(); - return err; + return root_scheduler_init(dev); } static void mshv_init_vmm_caps(struct device *dev) @@ -2276,31 +2249,18 @@ static int __init mshv_parent_partition_init(void) MSHV_HV_MAX_VERSION); } - mshv_root.synic_pages = alloc_percpu(struct hv_synic_pages); - if (!mshv_root.synic_pages) { - dev_err(dev, "Failed to allocate percpu synic page\n"); - ret = -ENOMEM; + ret = mshv_synic_init(dev); + if (ret) goto device_deregister; - } - - ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "mshv_synic", - mshv_synic_init, - mshv_synic_cleanup); - if (ret < 0) { - dev_err(dev, "Failed to setup cpu hotplug state: %i\n", ret); - goto free_synic_pages; - } - - mshv_cpuhp_online = ret; ret = mshv_retrieve_scheduler_type(dev); if (ret) - goto remove_cpu_state; + goto synic_cleanup; if (hv_root_partition()) ret = mshv_root_partition_init(dev); if (ret) - goto remove_cpu_state; + goto synic_cleanup; mshv_init_vmm_caps(dev); @@ -2318,10 +2278,8 @@ static int __init mshv_parent_partition_init(void) exit_partition: if (hv_root_partition()) mshv_root_partition_exit(); -remove_cpu_state: - cpuhp_remove_state(mshv_cpuhp_online); -free_synic_pages: - free_percpu(mshv_root.synic_pages); +synic_cleanup: + mshv_synic_cleanup(); device_deregister: misc_deregister(&mshv_dev); return ret; @@ -2335,8 +2293,7 @@ static void __exit mshv_parent_partition_exit(void) mshv_irqfd_wq_cleanup(); if (hv_root_partition()) mshv_root_partition_exit(); - cpuhp_remove_state(mshv_cpuhp_online); - free_percpu(mshv_root.synic_pages); + mshv_synic_cleanup(); } module_init(mshv_parent_partition_init); diff --git a/drivers/hv/mshv_synic.c b/drivers/hv/mshv_synic.c index f8b0337cdc82..98c58755846d 100644 --- a/drivers/hv/mshv_synic.c +++ b/drivers/hv/mshv_synic.c @@ -12,11 +12,16 @@ #include <linux/mm.h> #include <linux/io.h> #include <linux/random.h> +#include <linux/cpuhotplug.h> +#include <linux/reboot.h> #include <asm/mshyperv.h> #include "mshv_eventfd.h" #include "mshv.h" +static int synic_cpuhp_online; +static struct hv_synic_pages __percpu *synic_pages; + static u32 synic_event_ring_get_queued_port(u32 sint_index) { struct hv_synic_event_ring_page **event_ring_page; @@ -26,7 +31,7 @@ static u32 synic_event_ring_get_queued_port(u32 sint_index) u32 message; u8 tail; - spages = this_cpu_ptr(mshv_root.synic_pages); + spages = this_cpu_ptr(synic_pages); event_ring_page = &spages->synic_event_ring_page; synic_eventring_tail = (u8 **)this_cpu_ptr(hv_synic_eventring_tail); @@ -393,7 +398,7 @@ mshv_intercept_isr(struct hv_message *msg) void mshv_isr(void) { - struct hv_synic_pages *spages = this_cpu_ptr(mshv_root.synic_pages); + struct hv_synic_pages *spages = this_cpu_ptr(synic_pages); struct hv_message_page **msg_page = &spages->hyp_synic_message_page; struct hv_message *msg; bool handled; @@ -446,7 +451,7 @@ void mshv_isr(void) } } -int mshv_synic_init(unsigned int cpu) +static int mshv_synic_cpu_init(unsigned int cpu) { union hv_synic_simp simp; union hv_synic_siefp siefp; @@ -455,7 +460,7 @@ int mshv_synic_init(unsigned int cpu) union hv_synic_sint sint; #endif union hv_synic_scontrol sctrl; - struct hv_synic_pages *spages = this_cpu_ptr(mshv_root.synic_pages); + struct hv_synic_pages *spages = this_cpu_ptr(synic_pages); struct hv_message_page **msg_page = &spages->hyp_synic_message_page; struct hv_synic_event_flags_page **event_flags_page = &spages->synic_event_flags_page; @@ -542,14 +547,14 @@ int mshv_synic_init(unsigned int cpu) return -EFAULT; } -int mshv_synic_cleanup(unsigned int cpu) +static int mshv_synic_cpu_exit(unsigned int cpu) { union hv_synic_sint sint; union hv_synic_simp simp; union hv_synic_siefp siefp; union hv_synic_sirbp sirbp; union hv_synic_scontrol sctrl; - struct hv_synic_pages *spages = this_cpu_ptr(mshv_root.synic_pages); + struct hv_synic_pages *spages = this_cpu_ptr(synic_pages); struct hv_message_page **msg_page = &spages->hyp_synic_message_page; struct hv_synic_event_flags_page **event_flags_page = &spages->synic_event_flags_page; @@ -663,3 +668,57 @@ mshv_unregister_doorbell(u64 partition_id, int doorbell_portid) mshv_portid_free(doorbell_portid); } + +static int mshv_synic_reboot_notify(struct notifier_block *nb, + unsigned long code, void *unused) +{ + cpuhp_remove_state(synic_cpuhp_online); + return 0; +} + +static struct notifier_block mshv_synic_reboot_nb = { + .notifier_call = mshv_synic_reboot_notify, +}; + +int __init mshv_synic_init(struct device *dev) +{ + int ret = 0; + + synic_pages = alloc_percpu(struct hv_synic_pages); + if (!synic_pages) { + dev_err(dev, "Failed to allocate percpu synic page\n"); + return -ENOMEM; + } + + ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "mshv_synic", + mshv_synic_cpu_init, + mshv_synic_cpu_exit); + if (ret < 0) { + dev_err(dev, "Failed to setup cpu hotplug state: %i\n", ret); + goto free_synic_pages; + } + + synic_cpuhp_online = ret; + + if (hv_root_partition()) { + ret = register_reboot_notifier(&mshv_synic_reboot_nb); + if (ret) + goto remove_cpuhp_state; + } + + return 0; + +remove_cpuhp_state: + cpuhp_remove_state(synic_cpuhp_online); +free_synic_pages: + free_percpu(synic_pages); + return ret; +} + +void mshv_synic_cleanup(void) +{ + if (hv_root_partition()) + unregister_reboot_notifier(&mshv_synic_reboot_nb); + cpuhp_remove_state(synic_cpuhp_online); + free_percpu(synic_pages); +} -- 2.34.1
{ "author": "Anirudh Rayabharam <anirudh@anirudhrb.com>", "date": "Mon, 2 Feb 2026 18:27:05 +0000", "thread_id": "20260202182706.648192-3-anirudh@anirudhrb.com.mbox.gz" }
lkml
[PATCH v2 0/2] ARM64 support for doorbell and intercept SINTs
From: "Anirudh Rayabharam (Microsoft)" <anirudh@anirudhrb.com> On x86, the HYPERVISOR_CALLBACK_VECTOR is used to receive synthetic interrupts (SINTs) from the hypervisor for doorbells and intercepts. There is no such vector reserved for arm64. On arm64, the INTID for SINTs should be in the SGI or PPI range. The hypervisor exposes a virtual device in the ACPI that reserves a PPI for this use. Introduce a platform_driver that binds to this ACPI device and obtains the interrupt vector that can be used for SINTs. Changes in v2: Addressed review comments: - Moved more stuff into mshv_synic.c - Code simplifications - Removed unnecessary debug prints v1: https://lore.kernel.org/linux-hyperv/20260128160437.3342167-1-anirudh@anirudhrb.com/ Anirudh Rayabharam (Microsoft) (2): mshv: refactor synic init and cleanup mshv: add arm64 support for doorbell & intercept SINTs drivers/hv/mshv_root.h | 5 +- drivers/hv/mshv_root_main.c | 59 ++------- drivers/hv/mshv_synic.c | 232 ++++++++++++++++++++++++++++++++++-- 3 files changed, 230 insertions(+), 66 deletions(-) -- 2.34.1
From: Anirudh Rayabharam (Microsoft) <anirudh@anirudhrb.com> On x86, the HYPERVISOR_CALLBACK_VECTOR is used to receive synthetic interrupts (SINTs) from the hypervisor for doorbells and intercepts. There is no such vector reserved for arm64. On arm64, the INTID for SINTs should be in the SGI or PPI range. The hypervisor exposes a virtual device in the ACPI that reserves a PPI for this use. Introduce a platform_driver that binds to this ACPI device and obtains the interrupt vector that can be used for SINTs. To better unify x86 and arm64 paths, introduce mshv_sint_vector_init() that either registers the platform_driver and obtains the INTID (arm64) or just uses HYPERVISOR_CALLBACK_VECTOR as the interrupt vector (x86). Signed-off-by: Anirudh Rayabharam (Microsoft) <anirudh@anirudhrb.com> --- drivers/hv/mshv_synic.c | 163 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 156 insertions(+), 7 deletions(-) diff --git a/drivers/hv/mshv_synic.c b/drivers/hv/mshv_synic.c index 98c58755846d..de5fee6e9f29 100644 --- a/drivers/hv/mshv_synic.c +++ b/drivers/hv/mshv_synic.c @@ -10,17 +10,24 @@ #include <linux/kernel.h> #include <linux/slab.h> #include <linux/mm.h> +#include <linux/interrupt.h> #include <linux/io.h> #include <linux/random.h> #include <linux/cpuhotplug.h> #include <linux/reboot.h> #include <asm/mshyperv.h> +#include <linux/platform_device.h> +#include <linux/acpi.h> #include "mshv_eventfd.h" #include "mshv.h" static int synic_cpuhp_online; static struct hv_synic_pages __percpu *synic_pages; +static int mshv_sint_vector = -1; /* hwirq for the SynIC SINTs */ +#ifndef HYPERVISOR_CALLBACK_VECTOR +static int mshv_sint_irq = -1; /* Linux IRQ for mshv_sint_vector */ +#endif static u32 synic_event_ring_get_queued_port(u32 sint_index) { @@ -456,9 +463,7 @@ static int mshv_synic_cpu_init(unsigned int cpu) union hv_synic_simp simp; union hv_synic_siefp siefp; union hv_synic_sirbp sirbp; -#ifdef HYPERVISOR_CALLBACK_VECTOR union hv_synic_sint sint; -#endif union hv_synic_scontrol sctrl; struct hv_synic_pages *spages = this_cpu_ptr(synic_pages); struct hv_message_page **msg_page = &spages->hyp_synic_message_page; @@ -501,10 +506,13 @@ static int mshv_synic_cpu_init(unsigned int cpu) hv_set_non_nested_msr(HV_MSR_SIRBP, sirbp.as_uint64); -#ifdef HYPERVISOR_CALLBACK_VECTOR +#ifndef HYPERVISOR_CALLBACK_VECTOR + enable_percpu_irq(mshv_sint_irq, 0); +#endif + /* Enable intercepts */ sint.as_uint64 = 0; - sint.vector = HYPERVISOR_CALLBACK_VECTOR; + sint.vector = mshv_sint_vector; sint.masked = false; sint.auto_eoi = hv_recommend_using_aeoi(); hv_set_non_nested_msr(HV_MSR_SINT0 + HV_SYNIC_INTERCEPTION_SINT_INDEX, @@ -512,13 +520,12 @@ static int mshv_synic_cpu_init(unsigned int cpu) /* Doorbell SINT */ sint.as_uint64 = 0; - sint.vector = HYPERVISOR_CALLBACK_VECTOR; + sint.vector = mshv_sint_vector; sint.masked = false; sint.as_intercept = 1; sint.auto_eoi = hv_recommend_using_aeoi(); hv_set_non_nested_msr(HV_MSR_SINT0 + HV_SYNIC_DOORBELL_SINT_INDEX, sint.as_uint64); -#endif /* Enable global synic bit */ sctrl.as_uint64 = hv_get_non_nested_msr(HV_MSR_SCONTROL); @@ -573,6 +580,10 @@ static int mshv_synic_cpu_exit(unsigned int cpu) hv_set_non_nested_msr(HV_MSR_SINT0 + HV_SYNIC_DOORBELL_SINT_INDEX, sint.as_uint64); +#ifndef HYPERVISOR_CALLBACK_VECTOR + disable_percpu_irq(mshv_sint_irq); +#endif + /* Disable Synic's event ring page */ sirbp.as_uint64 = hv_get_non_nested_msr(HV_MSR_SIRBP); sirbp.sirbp_enabled = false; @@ -680,14 +691,149 @@ static struct notifier_block mshv_synic_reboot_nb = { .notifier_call = mshv_synic_reboot_notify, }; +#ifndef HYPERVISOR_CALLBACK_VECTOR +#ifdef CONFIG_ACPI +static long __percpu *mshv_evt; + +static acpi_status mshv_walk_resources(struct acpi_resource *res, void *ctx) +{ + struct resource r; + + if (res->type == ACPI_RESOURCE_TYPE_EXTENDED_IRQ) { + if (!acpi_dev_resource_interrupt(res, 0, &r)) { + pr_err("Unable to parse MSHV ACPI interrupt\n"); + return AE_ERROR; + } + /* ARM64 INTID */ + mshv_sint_vector = res->data.extended_irq.interrupts[0]; + /* Linux IRQ number */ + mshv_sint_irq = r.start; + } + + return AE_OK; +} + +static irqreturn_t mshv_percpu_isr(int irq, void *dev_id) +{ + mshv_isr(); + return IRQ_HANDLED; +} + +static int mshv_sint_probe(struct platform_device *pdev) +{ + acpi_status result; + int ret; + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); + + result = acpi_walk_resources(device->handle, METHOD_NAME__CRS, + mshv_walk_resources, NULL); + if (ACPI_FAILURE(result)) { + ret = -ENODEV; + goto out_fail; + } + + mshv_evt = alloc_percpu(long); + if (!mshv_evt) { + ret = -ENOMEM; + goto out_fail; + } + + ret = request_percpu_irq(mshv_sint_irq, mshv_percpu_isr, "MSHV", + mshv_evt); + if (ret) + goto free_evt; + + return 0; + +free_evt: + free_percpu(mshv_evt); +out_fail: + mshv_sint_vector = -1; + mshv_sint_irq = -1; + return ret; +} + +static void mshv_sint_remove(struct platform_device *pdev) +{ + free_percpu_irq(mshv_sint_irq, mshv_evt); + free_percpu(mshv_evt); +} +#else +static int mshv_sint_probe(struct platform_device *pdev) +{ + return -ENODEV; +} + +static void mshv_sint_remove(struct platform_device *pdev) +{ +} +#endif + +static const __maybe_unused struct acpi_device_id mshv_sint_device_ids[] = { + {"MSFT1003", 0}, + {"", 0}, +}; + +static struct platform_driver mshv_sint_drv = { + .probe = mshv_sint_probe, + .remove = mshv_sint_remove, + .driver = { + .name = "mshv_sint", + .acpi_match_table = ACPI_PTR(mshv_sint_device_ids), + .probe_type = PROBE_FORCE_SYNCHRONOUS, + }, +}; + +static int __init mshv_sint_vector_init(void) +{ + int ret; + + if (acpi_disabled) + return -ENODEV; + + ret = platform_driver_register(&mshv_sint_drv); + if (ret) + return ret; + + if (mshv_sint_vector == -1 || mshv_sint_irq == -1) { + platform_driver_unregister(&mshv_sint_drv); + return -ENODEV; + } + + return 0; +} + +static void mshv_sint_vector_cleanup(void) +{ + platform_driver_unregister(&mshv_sint_drv); +} +#else /* HYPERVISOR_CALLBACK_VECTOR */ +static int __init mshv_sint_vector_init(void) +{ + mshv_sint_vector = HYPERVISOR_CALLBACK_VECTOR; + return 0; +} + +static void mshv_sint_vector_cleanup(void) +{ +} +#endif /* HYPERVISOR_CALLBACK_VECTOR */ + int __init mshv_synic_init(struct device *dev) { int ret = 0; + ret = mshv_sint_vector_init(); + if (ret) { + dev_err(dev, "Failed to get MSHV SINT vector: %i\n", ret); + return ret; + } + synic_pages = alloc_percpu(struct hv_synic_pages); if (!synic_pages) { dev_err(dev, "Failed to allocate percpu synic page\n"); - return -ENOMEM; + ret = -ENOMEM; + goto sint_vector_cleanup; } ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "mshv_synic", @@ -712,6 +858,8 @@ int __init mshv_synic_init(struct device *dev) cpuhp_remove_state(synic_cpuhp_online); free_synic_pages: free_percpu(synic_pages); +sint_vector_cleanup: + mshv_sint_vector_cleanup(); return ret; } @@ -721,4 +869,5 @@ void mshv_synic_cleanup(void) unregister_reboot_notifier(&mshv_synic_reboot_nb); cpuhp_remove_state(synic_cpuhp_online); free_percpu(synic_pages); + mshv_sint_vector_cleanup(); } -- 2.34.1
{ "author": "Anirudh Rayabharam <anirudh@anirudhrb.com>", "date": "Mon, 2 Feb 2026 18:27:06 +0000", "thread_id": "20260202182706.648192-3-anirudh@anirudhrb.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
Export liveupdate_enabled(), liveupdate_register_file_handler(), and liveupdate_unregister_file_handler(). All of these will be used by vfio-pci in a subsequent commit, which can be built as a module. Signed-off-by: David Matlack <dmatlack@google.com> --- kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/kernel/liveupdate/luo_core.c b/kernel/liveupdate/luo_core.c index dda7bb57d421..59d7793d9444 100644 --- a/kernel/liveupdate/luo_core.c +++ b/kernel/liveupdate/luo_core.c @@ -255,6 +255,7 @@ bool liveupdate_enabled(void) { return luo_global.enabled; } +EXPORT_SYMBOL_GPL(liveupdate_enabled); /** * DOC: LUO ioctl Interface diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c index 35d2a8b1a0df..32759e846bc9 100644 --- a/kernel/liveupdate/luo_file.c +++ b/kernel/liveupdate/luo_file.c @@ -872,6 +872,7 @@ int liveupdate_register_file_handler(struct liveupdate_file_handler *fh) luo_session_resume(); return err; } +EXPORT_SYMBOL_GPL(liveupdate_register_file_handler); /** * liveupdate_unregister_file_handler - Unregister a liveupdate file handler @@ -917,3 +918,4 @@ int liveupdate_unregister_file_handler(struct liveupdate_file_handler *fh) liveupdate_test_register(fh); return err; } +EXPORT_SYMBOL_GPL(liveupdate_unregister_file_handler); -- 2.53.0.rc1.225.gd81095ad13-goog
{ "author": "David Matlack <dmatlack@google.com>", "date": "Thu, 29 Jan 2026 21:24:48 +0000", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
Inherit bus numbers from the previous kernel during a Live Update when one or more PCI devices are being preserved. This is necessary so that preserved devices can DMA through the IOMMU during a Live Update (changing bus numbers would break IOMMU translation). Signed-off-by: David Matlack <dmatlack@google.com> --- drivers/pci/probe.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index af6356c5a156..ca6e5f79debb 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1351,6 +1351,20 @@ static bool pci_ea_fixed_busnrs(struct pci_dev *dev, u8 *sec, u8 *sub) return true; } +static bool pci_assign_all_busses(void) +{ + /* + * During a Live Update where devices are preserved by the previous + * kernel, inherit all bus numbers assigned by the previous kernel. Bus + * numbers must remain stable for preserved devices so that they can + * perform DMA during the Live Update uninterrupted. + */ + if (pci_liveupdate_incoming_nr_devices()) + return false; + + return pcibios_assign_all_busses(); +} + /* * pci_scan_bridge_extend() - Scan buses behind a bridge * @bus: Parent bus the bridge is on @@ -1378,6 +1392,7 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, int max, unsigned int available_buses, int pass) { + bool assign_all_busses = pci_assign_all_busses(); struct pci_bus *child; int is_cardbus = (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS); u32 buses, i, j = 0; @@ -1424,7 +1439,7 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, pci_write_config_word(dev, PCI_BRIDGE_CONTROL, bctl & ~PCI_BRIDGE_CTL_MASTER_ABORT); - if ((secondary || subordinate) && !pcibios_assign_all_busses() && + if ((secondary || subordinate) && !assign_all_busses && !is_cardbus && !broken) { unsigned int cmax, buses; @@ -1467,7 +1482,7 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, * do in the second pass. */ if (!pass) { - if (pcibios_assign_all_busses() || broken || is_cardbus) + if (assign_all_busses || broken || is_cardbus) /* * Temporarily disable forwarding of the @@ -1542,7 +1557,7 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, max+i+1)) break; while (parent->parent) { - if ((!pcibios_assign_all_busses()) && + if (!assign_all_busses && (parent->busn_res.end > max) && (parent->busn_res.end <= max+i)) { j = 1; -- 2.53.0.rc1.225.gd81095ad13-goog
{ "author": "David Matlack <dmatlack@google.com>", "date": "Thu, 29 Jan 2026 21:24:50 +0000", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
Add an API to enable the PCI subsystem to track all devices that are preserved across a Live Update, including both incoming devices (passed from the previous kernel) and outgoing devices (passed to the next kernel). Use PCI segment number and BDF to keep track of devices across Live Update. This means the kernel must keep both identifiers constant across a Live Update for any preserved device. VFs are not supported for now, since that requires preserving SR-IOV state on the device to ensure the same number of VFs appear after kexec and with the same BDFs. Drivers that preserve devices across Live Update can now register their struct liveupdate_file_handler with the PCI subsystem so that the PCI subsystem can allocate and manage File-Lifecycle-Bound (FLB) global data to track the list of incoming and outgoing preserved devices. pci_liveupdate_register_fh(driver_fh) pci_liveupdate_unregister_fh(driver_fh) Drivers can notify the PCI subsystem whenever a device is preserved and unpreserved with the following APIs: pci_liveupdate_outgoing_preserve(pci_dev) pci_liveupdate_outgoing_unpreserve(pci_dev) After a Live Update, the PCI subsystem fetches its FLB global data from the previous kernel from the Live Update Orchestrator (LUO) during device initialization to determine which devices were preserved. Drivers can check if a device was preserved before userspace retrieves the file for it via pci_dev->liveupdate_incoming. Once a driver has finished restoring an incoming preserved device, it can notify the PCI subsystem with the following call, which clears pci_dev->liveupdate_incoming. pci_liveupdate_incoming_finish(pci_dev) This API will be used in subsequent commits by the vfio-pci driver to preserve VFIO devices across Live Update and by the PCI subsystem. Signed-off-by: David Matlack <dmatlack@google.com> --- drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 ++++++++++++++++++++++++++++++++++++ drivers/pci/probe.c | 2 + include/linux/kho/abi/pci.h | 55 ++++++++++ include/linux/pci.h | 47 ++++++++ 5 files changed, 317 insertions(+) create mode 100644 drivers/pci/liveupdate.c create mode 100644 include/linux/kho/abi/pci.h diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile index 8c259a9a8796..a32f7658b9e5 100644 --- a/drivers/pci/Makefile +++ b/drivers/pci/Makefile @@ -16,6 +16,7 @@ obj-$(CONFIG_PROC_FS) += proc.o obj-$(CONFIG_SYSFS) += pci-sysfs.o slot.o obj-$(CONFIG_ACPI) += pci-acpi.o obj-$(CONFIG_GENERIC_PCI_IOMAP) += iomap.o +obj-$(CONFIG_LIVEUPDATE) += liveupdate.o endif obj-$(CONFIG_OF) += of.o diff --git a/drivers/pci/liveupdate.c b/drivers/pci/liveupdate.c new file mode 100644 index 000000000000..182cfc793b80 --- /dev/null +++ b/drivers/pci/liveupdate.c @@ -0,0 +1,212 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright (c) 2025, Google LLC. + * David Matlack <dmatlack@google.com> + */ + +#include <linux/bsearch.h> +#include <linux/io.h> +#include <linux/kexec_handover.h> +#include <linux/kho/abi/pci.h> +#include <linux/liveupdate.h> +#include <linux/mutex.h> +#include <linux/mm.h> +#include <linux/pci.h> +#include <linux/sort.h> + +static DEFINE_MUTEX(pci_flb_outgoing_lock); + +static int pci_flb_preserve(struct liveupdate_flb_op_args *args) +{ + struct pci_dev *dev = NULL; + int max_nr_devices = 0; + struct pci_ser *ser; + unsigned long size; + + for_each_pci_dev(dev) + max_nr_devices++; + + size = struct_size_t(struct pci_ser, devices, max_nr_devices); + + ser = kho_alloc_preserve(size); + if (IS_ERR(ser)) + return PTR_ERR(ser); + + ser->max_nr_devices = max_nr_devices; + + args->obj = ser; + args->data = virt_to_phys(ser); + return 0; +} + +static void pci_flb_unpreserve(struct liveupdate_flb_op_args *args) +{ + struct pci_ser *ser = args->obj; + + WARN_ON_ONCE(ser->nr_devices); + kho_unpreserve_free(ser); +} + +static int pci_flb_retrieve(struct liveupdate_flb_op_args *args) +{ + args->obj = phys_to_virt(args->data); + return 0; +} + +static void pci_flb_finish(struct liveupdate_flb_op_args *args) +{ + kho_restore_free(args->obj); +} + +static struct liveupdate_flb_ops pci_liveupdate_flb_ops = { + .preserve = pci_flb_preserve, + .unpreserve = pci_flb_unpreserve, + .retrieve = pci_flb_retrieve, + .finish = pci_flb_finish, + .owner = THIS_MODULE, +}; + +static struct liveupdate_flb pci_liveupdate_flb = { + .ops = &pci_liveupdate_flb_ops, + .compatible = PCI_LUO_FLB_COMPATIBLE, +}; + +#define INIT_PCI_DEV_SER(_dev) { \ + .domain = pci_domain_nr((_dev)->bus), \ + .bdf = pci_dev_id(_dev), \ +} + +static int pci_dev_ser_cmp(const void *__a, const void *__b) +{ + const struct pci_dev_ser *a = __a, *b = __b; + + return cmp_int(a->domain << 16 | a->bdf, b->domain << 16 | b->bdf); +} + +static struct pci_dev_ser *pci_ser_find(struct pci_ser *ser, + struct pci_dev *dev) +{ + const struct pci_dev_ser key = INIT_PCI_DEV_SER(dev); + + return bsearch(&key, ser->devices, ser->nr_devices, + sizeof(key), pci_dev_ser_cmp); +} + +static int pci_ser_delete(struct pci_ser *ser, struct pci_dev *dev) +{ + struct pci_dev_ser *dev_ser; + int i; + + dev_ser = pci_ser_find(ser, dev); + if (!dev_ser) + return -ENOENT; + + for (i = dev_ser - ser->devices; i < ser->nr_devices - 1; i++) + ser->devices[i] = ser->devices[i + 1]; + + ser->nr_devices--; + return 0; +} + +int pci_liveupdate_outgoing_preserve(struct pci_dev *dev) +{ + struct pci_dev_ser new = INIT_PCI_DEV_SER(dev); + struct pci_ser *ser; + int i, ret; + + /* Preserving VFs is not supported yet. */ + if (dev->is_virtfn) + return -EINVAL; + + guard(mutex)(&pci_flb_outgoing_lock); + + if (dev->liveupdate_outgoing) + return -EBUSY; + + ret = liveupdate_flb_get_outgoing(&pci_liveupdate_flb, (void **)&ser); + if (ret) + return ret; + + if (ser->nr_devices == ser->max_nr_devices) + return -E2BIG; + + for (i = ser->nr_devices; i > 0; i--) { + struct pci_dev_ser *prev = &ser->devices[i - 1]; + int cmp = pci_dev_ser_cmp(&new, prev); + + if (WARN_ON_ONCE(!cmp)) + return -EBUSY; + + if (cmp > 0) + break; + + ser->devices[i] = *prev; + } + + ser->devices[i] = new; + ser->nr_devices++; + dev->liveupdate_outgoing = true; + return 0; +} +EXPORT_SYMBOL_GPL(pci_liveupdate_outgoing_preserve); + +void pci_liveupdate_outgoing_unpreserve(struct pci_dev *dev) +{ + struct pci_ser *ser; + int ret; + + guard(mutex)(&pci_flb_outgoing_lock); + + ret = liveupdate_flb_get_outgoing(&pci_liveupdate_flb, (void **)&ser); + if (WARN_ON_ONCE(ret)) + return; + + WARN_ON_ONCE(pci_ser_delete(ser, dev)); + dev->liveupdate_outgoing = false; +} +EXPORT_SYMBOL_GPL(pci_liveupdate_outgoing_unpreserve); + +u32 pci_liveupdate_incoming_nr_devices(void) +{ + struct pci_ser *ser; + int ret; + + ret = liveupdate_flb_get_incoming(&pci_liveupdate_flb, (void **)&ser); + if (ret) + return 0; + + return ser->nr_devices; +} +EXPORT_SYMBOL_GPL(pci_liveupdate_incoming_nr_devices); + +void pci_liveupdate_setup_device(struct pci_dev *dev) +{ + struct pci_ser *ser; + int ret; + + ret = liveupdate_flb_get_incoming(&pci_liveupdate_flb, (void **)&ser); + if (ret) + return; + + dev->liveupdate_incoming = !!pci_ser_find(ser, dev); +} +EXPORT_SYMBOL_GPL(pci_liveupdate_setup_device); + +void pci_liveupdate_incoming_finish(struct pci_dev *dev) +{ + dev->liveupdate_incoming = false; +} +EXPORT_SYMBOL_GPL(pci_liveupdate_incoming_finish); + +int pci_liveupdate_register_fh(struct liveupdate_file_handler *fh) +{ + return liveupdate_register_flb(fh, &pci_liveupdate_flb); +} +EXPORT_SYMBOL_GPL(pci_liveupdate_register_fh); + +int pci_liveupdate_unregister_fh(struct liveupdate_file_handler *fh) +{ + return liveupdate_unregister_flb(fh, &pci_liveupdate_flb); +} +EXPORT_SYMBOL_GPL(pci_liveupdate_unregister_fh); diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 37329095e5fe..af6356c5a156 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2060,6 +2060,8 @@ int pci_setup_device(struct pci_dev *dev) if (pci_early_dump) early_dump_pci_device(dev); + pci_liveupdate_setup_device(dev); + /* Need to have dev->class ready */ dev->cfg_size = pci_cfg_space_size(dev); diff --git a/include/linux/kho/abi/pci.h b/include/linux/kho/abi/pci.h new file mode 100644 index 000000000000..6577767f8da6 --- /dev/null +++ b/include/linux/kho/abi/pci.h @@ -0,0 +1,55 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Copyright (c) 2025, Google LLC. + * David Matlack <dmatlack@google.com> + */ + +#ifndef _LINUX_KHO_ABI_PCI_H +#define _LINUX_KHO_ABI_PCI_H + +#include <linux/compiler.h> +#include <linux/types.h> + +/** + * DOC: PCI File-Lifecycle Bound (FLB) Live Update ABI + * + * This header defines the ABI for preserving core PCI state across kexec using + * Live Update File-Lifecycle Bound (FLB) data. + * + * This interface is a contract. Any modification to any of the serialization + * structs defined here constitutes a breaking change. Such changes require + * incrementing the version number in the PCI_LUO_FLB_COMPATIBLE string. + */ + +#define PCI_LUO_FLB_COMPATIBLE "pci-v1" + +/** + * struct pci_dev_ser - Serialized state about a single PCI device. + * + * @domain: The device's PCI domain number (segment). + * @bdf: The device's PCI bus, device, and function number. + */ +struct pci_dev_ser { + u16 domain; + u16 bdf; +} __packed; + +/** + * struct pci_ser - PCI Subsystem Live Update State + * + * This struct tracks state about all devices that are being preserved across + * a Live Update for the next kernel. + * + * @max_nr_devices: The length of the devices[] flexible array. + * @nr_devices: The number of devices that were preserved. + * @devices: Flexible array of pci_dev_ser structs for each device. Guaranteed + * to be sorted ascending by domain and bdf. + */ +struct pci_ser { + u64 max_nr_devices; + u64 nr_devices; + struct pci_dev_ser devices[]; +} __packed; + +#endif /* _LINUX_KHO_ABI_PCI_H */ diff --git a/include/linux/pci.h b/include/linux/pci.h index 7e36936bb37a..9ead6d84aef6 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -40,6 +40,7 @@ #include <linux/resource_ext.h> #include <linux/msi_api.h> #include <uapi/linux/pci.h> +#include <linux/liveupdate.h> #include <linux/pci_ids.h> @@ -582,6 +583,10 @@ struct pci_dev { u8 tph_mode; /* TPH mode */ u8 tph_req_type; /* TPH requester type */ #endif +#ifdef CONFIG_LIVEUPDATE + unsigned int liveupdate_incoming:1; /* Preserved by previous kernel */ + unsigned int liveupdate_outgoing:1; /* Preserved for next kernel */ +#endif }; static inline struct pci_dev *pci_physfn(struct pci_dev *dev) @@ -2854,4 +2859,46 @@ void pci_uevent_ers(struct pci_dev *pdev, enum pci_ers_result err_type); WARN_ONCE(condition, "%s %s: " fmt, \ dev_driver_string(&(pdev)->dev), pci_name(pdev), ##arg) +#ifdef CONFIG_LIVEUPDATE +int pci_liveupdate_outgoing_preserve(struct pci_dev *dev); +void pci_liveupdate_outgoing_unpreserve(struct pci_dev *dev); +void pci_liveupdate_setup_device(struct pci_dev *dev); +u32 pci_liveupdate_incoming_nr_devices(void); +void pci_liveupdate_incoming_finish(struct pci_dev *dev); +int pci_liveupdate_register_fh(struct liveupdate_file_handler *fh); +int pci_liveupdate_unregister_fh(struct liveupdate_file_handler *fh); +#else /* !CONFIG_LIVEUPDATE */ +static inline int pci_liveupdate_outgoing_preserve(struct pci_dev *dev) +{ + return -EOPNOTSUPP; +} + +static inline void pci_liveupdate_outgoing_unpreserve(struct pci_dev *dev) +{ +} + +static inline void pci_liveupdate_setup_device(struct pci_dev *dev) +{ +} + +static inline u32 pci_liveupdate_incoming_nr_devices(void) +{ + return 0; +} + +static inline void pci_liveupdate_incoming_finish(struct pci_dev *dev) +{ +} + +static inline int pci_liveupdate_register_fh(struct liveupdate_file_handler *fh) +{ + return -EOPNOTSUPP; +} + +static inline int pci_liveupdate_unregister_fh(struct liveupdate_file_handler *fh) +{ + return -EOPNOTSUPP; +} +#endif /* !CONFIG_LIVEUPDATE */ + #endif /* LINUX_PCI_H */ -- 2.53.0.rc1.225.gd81095ad13-goog
{ "author": "David Matlack <dmatlack@google.com>", "date": "Thu, 29 Jan 2026 21:24:49 +0000", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
From: Vipin Sharma <vipinsh@google.com> Register a live update file handler for vfio-pci device files. Add stub implementations of all required callbacks so that registration does not fail (i.e. to avoid breaking git-bisect). This file handler will be extended in subsequent commits to enable a device bound to vfio-pci to run without interruption while the host is going through a kexec Live Update. Signed-off-by: Vipin Sharma <vipinsh@google.com> Co-developed-by: David Matlack <dmatlack@google.com> Signed-off-by: David Matlack <dmatlack@google.com> --- MAINTAINERS | 1 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 9 +++- drivers/vfio/pci/vfio_pci_liveupdate.c | 69 ++++++++++++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 14 ++++++ include/linux/kho/abi/vfio_pci.h | 28 +++++++++++ 6 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/vfio_pci.h diff --git a/MAINTAINERS b/MAINTAINERS index a671e3d4e8be..7d6cdecedb05 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -27520,6 +27520,7 @@ F: Documentation/ABI/testing/debugfs-vfio F: Documentation/ABI/testing/sysfs-devices-vfio-dev F: Documentation/driver-api/vfio.rst F: drivers/vfio/ +F: include/linux/kho/abi/vfio_pci.h F: include/linux/vfio.h F: include/linux/vfio_pci_core.h F: include/uapi/linux/vfio.h diff --git a/drivers/vfio/pci/Makefile b/drivers/vfio/pci/Makefile index e0a0757dd1d2..23305ebc418b 100644 --- a/drivers/vfio/pci/Makefile +++ b/drivers/vfio/pci/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_VFIO_PCI_CORE) += vfio-pci-core.o vfio-pci-y := vfio_pci.o vfio-pci-$(CONFIG_VFIO_PCI_IGD) += vfio_pci_igd.o +vfio-pci-$(CONFIG_LIVEUPDATE) += vfio_pci_liveupdate.o obj-$(CONFIG_VFIO_PCI) += vfio-pci.o obj-$(CONFIG_MLX5_VFIO_PCI) += mlx5/ diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 0c771064c0b8..19e88322af2c 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -258,6 +258,10 @@ static int __init vfio_pci_init(void) int ret; bool is_disable_vga = true; + ret = vfio_pci_liveupdate_init(); + if (ret) + return ret; + #ifdef CONFIG_VFIO_PCI_VGA is_disable_vga = disable_vga; #endif @@ -266,8 +270,10 @@ static int __init vfio_pci_init(void) /* Register and scan for devices */ ret = pci_register_driver(&vfio_pci_driver); - if (ret) + if (ret) { + vfio_pci_liveupdate_cleanup(); return ret; + } vfio_pci_fill_ids(); @@ -281,6 +287,7 @@ module_init(vfio_pci_init); static void __exit vfio_pci_cleanup(void) { pci_unregister_driver(&vfio_pci_driver); + vfio_pci_liveupdate_cleanup(); } module_exit(vfio_pci_cleanup); diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio_pci_liveupdate.c new file mode 100644 index 000000000000..b84e63c0357b --- /dev/null +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -0,0 +1,69 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright (c) 2025, Google LLC. + * Vipin Sharma <vipinsh@google.com> + * David Matlack <dmatlack@google.com> + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include <linux/kho/abi/vfio_pci.h> +#include <linux/liveupdate.h> +#include <linux/errno.h> + +#include "vfio_pci_priv.h" + +static bool vfio_pci_liveupdate_can_preserve(struct liveupdate_file_handler *handler, + struct file *file) +{ + return false; +} + +static int vfio_pci_liveupdate_preserve(struct liveupdate_file_op_args *args) +{ + return -EOPNOTSUPP; +} + +static void vfio_pci_liveupdate_unpreserve(struct liveupdate_file_op_args *args) +{ +} + +static int vfio_pci_liveupdate_retrieve(struct liveupdate_file_op_args *args) +{ + return -EOPNOTSUPP; +} + +static void vfio_pci_liveupdate_finish(struct liveupdate_file_op_args *args) +{ +} + +static const struct liveupdate_file_ops vfio_pci_liveupdate_file_ops = { + .can_preserve = vfio_pci_liveupdate_can_preserve, + .preserve = vfio_pci_liveupdate_preserve, + .unpreserve = vfio_pci_liveupdate_unpreserve, + .retrieve = vfio_pci_liveupdate_retrieve, + .finish = vfio_pci_liveupdate_finish, + .owner = THIS_MODULE, +}; + +static struct liveupdate_file_handler vfio_pci_liveupdate_fh = { + .ops = &vfio_pci_liveupdate_file_ops, + .compatible = VFIO_PCI_LUO_FH_COMPATIBLE, +}; + +int __init vfio_pci_liveupdate_init(void) +{ + if (!liveupdate_enabled()) + return 0; + + return liveupdate_register_file_handler(&vfio_pci_liveupdate_fh); +} + +void vfio_pci_liveupdate_cleanup(void) +{ + if (!liveupdate_enabled()) + return; + + liveupdate_unregister_file_handler(&vfio_pci_liveupdate_fh); +} diff --git a/drivers/vfio/pci/vfio_pci_priv.h b/drivers/vfio/pci/vfio_pci_priv.h index 27ac280f00b9..68966ec64e51 100644 --- a/drivers/vfio/pci/vfio_pci_priv.h +++ b/drivers/vfio/pci/vfio_pci_priv.h @@ -133,4 +133,18 @@ static inline void vfio_pci_dma_buf_move(struct vfio_pci_core_device *vdev, } #endif +#ifdef CONFIG_LIVEUPDATE +int __init vfio_pci_liveupdate_init(void); +void vfio_pci_liveupdate_cleanup(void); +#else +static inline int vfio_pci_liveupdate_init(void) +{ + return 0; +} + +static inline void vfio_pci_liveupdate_cleanup(void) +{ +} +#endif /* CONFIG_LIVEUPDATE */ + #endif diff --git a/include/linux/kho/abi/vfio_pci.h b/include/linux/kho/abi/vfio_pci.h new file mode 100644 index 000000000000..37a845eed972 --- /dev/null +++ b/include/linux/kho/abi/vfio_pci.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Copyright (c) 2025, Google LLC. + * Vipin Sharma <vipinsh@google.com> + * David Matlack <dmatlack@google.com> + */ + +#ifndef _LINUX_LIVEUPDATE_ABI_VFIO_PCI_H +#define _LINUX_LIVEUPDATE_ABI_VFIO_PCI_H + +/** + * DOC: VFIO PCI Live Update ABI + * + * This header defines the ABI for preserving the state of a VFIO PCI device + * files across a kexec reboot using LUO. + * + * Device metadata is serialized into memory which is then handed to the next + * kernel via KHO. + * + * This interface is a contract. Any modification to any of the serialization + * structs defined here constitutes a breaking change. Such changes require + * incrementing the version number in the VFIO_PCI_LUO_FH_COMPATIBLE string. + */ + +#define VFIO_PCI_LUO_FH_COMPATIBLE "vfio-pci-v1" + +#endif /* _LINUX_LIVEUPDATE_ABI_VFIO_PCI_H */ -- 2.53.0.rc1.225.gd81095ad13-goog
{ "author": "David Matlack <dmatlack@google.com>", "date": "Thu, 29 Jan 2026 21:24:51 +0000", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
From: Vipin Sharma <vipinsh@google.com> Implement the live update file handler callbacks to preserve a vfio-pci device across a Live Update. Subsequent commits will enable userspace to then retrieve this file after the Live Update. Live Update support is scoped only to cdev files (i.e. not VFIO_GROUP_GET_DEVICE_FD files). State about each device is serialized into a new ABI struct vfio_pci_core_device_ser. The contents of this struct are preserved across the Live Update to the next kernel using a combination of Kexec-Handover (KHO) to preserve the page(s) holding the struct and the Live Update Orchestrator (LUO) to preserve the physical address of the struct. For now the only contents of struct vfio_pci_core_device_ser the device's PCI segment number and BDF, so that the device can be uniquely identified after the Live Update. Require that userspace disables interrupts on the device prior to freeze() so that the device does not send any interrupts until new interrupt handlers have been set up by the next kernel. Reset the device and restore its state in the freeze() callback. This ensures the device can be received by the next kernel in a consistent state. Eventually this will be dropped and the device can be preserved across in a running state, but that requires further work in VFIO and the core PCI layer. Note that LUO holds a reference to this file when it is preserved. So VFIO is guaranteed that vfio_df_device_last_close() will not be called on this device no matter what userspace does. Signed-off-by: Vipin Sharma <vipinsh@google.com> Co-developed-by: David Matlack <dmatlack@google.com> Signed-off-by: David Matlack <dmatlack@google.com> --- drivers/vfio/pci/vfio_pci.c | 2 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 84 +++++++++++++++++++++++++- drivers/vfio/pci/vfio_pci_priv.h | 2 + drivers/vfio/vfio.h | 13 ---- drivers/vfio/vfio_main.c | 10 +-- include/linux/kho/abi/vfio_pci.h | 15 +++++ include/linux/vfio.h | 28 +++++++++ 7 files changed, 129 insertions(+), 25 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 19e88322af2c..0260afb9492d 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -125,7 +125,7 @@ static int vfio_pci_open_device(struct vfio_device *core_vdev) return 0; } -static const struct vfio_device_ops vfio_pci_ops = { +const struct vfio_device_ops vfio_pci_ops = { .name = "vfio-pci", .init = vfio_pci_core_init_dev, .release = vfio_pci_core_release_dev, diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio_pci_liveupdate.c index b84e63c0357b..f01de98f1b75 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -8,25 +8,104 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include <linux/kexec_handover.h> #include <linux/kho/abi/vfio_pci.h> #include <linux/liveupdate.h> #include <linux/errno.h> +#include <linux/vfio.h> #include "vfio_pci_priv.h" static bool vfio_pci_liveupdate_can_preserve(struct liveupdate_file_handler *handler, struct file *file) { - return false; + struct vfio_device_file *df = to_vfio_device_file(file); + + if (!df) + return false; + + /* Live Update support is limited to cdev files. */ + if (df->group) + return false; + + return df->device->ops == &vfio_pci_ops; } static int vfio_pci_liveupdate_preserve(struct liveupdate_file_op_args *args) { - return -EOPNOTSUPP; + struct vfio_device *device = vfio_device_from_file(args->file); + struct vfio_pci_core_device_ser *ser; + struct vfio_pci_core_device *vdev; + struct pci_dev *pdev; + + vdev = container_of(device, struct vfio_pci_core_device, vdev); + pdev = vdev->pdev; + + if (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM)) + return -EINVAL; + + if (vfio_pci_is_intel_display(pdev)) + return -EINVAL; + + ser = kho_alloc_preserve(sizeof(*ser)); + if (IS_ERR(ser)) + return PTR_ERR(ser); + + ser->bdf = pci_dev_id(pdev); + ser->domain = pci_domain_nr(pdev->bus); + + args->serialized_data = virt_to_phys(ser); + return 0; } static void vfio_pci_liveupdate_unpreserve(struct liveupdate_file_op_args *args) { + kho_unpreserve_free(phys_to_virt(args->serialized_data)); +} + +static int vfio_pci_liveupdate_freeze(struct liveupdate_file_op_args *args) +{ + struct vfio_device *device = vfio_device_from_file(args->file); + struct vfio_pci_core_device *vdev; + struct pci_dev *pdev; + int ret; + + vdev = container_of(device, struct vfio_pci_core_device, vdev); + pdev = vdev->pdev; + + guard(mutex)(&device->dev_set->lock); + + /* + * Userspace must disable interrupts on the device prior to freeze so + * that the device does not send any interrupts until new interrupt + * handlers have been established by the next kernel. + */ + if (vdev->irq_type != VFIO_PCI_NUM_IRQS) { + pci_err(pdev, "Freeze failed! Interrupts are still enabled.\n"); + return -EINVAL; + } + + pci_dev_lock(pdev); + + ret = pci_load_saved_state(pdev, vdev->pci_saved_state); + if (ret) + goto out; + + /* + * Reset the device and restore it back to its original state before + * handing it to the next kernel. + * + * Eventually both of these should be dropped and the device should be + * kept running with its current state across the Live Update. + */ + if (vdev->reset_works) + ret = __pci_reset_function_locked(pdev); + + pci_restore_state(pdev); + +out: + pci_dev_unlock(pdev); + return ret; } static int vfio_pci_liveupdate_retrieve(struct liveupdate_file_op_args *args) @@ -42,6 +121,7 @@ static const struct liveupdate_file_ops vfio_pci_liveupdate_file_ops = { .can_preserve = vfio_pci_liveupdate_can_preserve, .preserve = vfio_pci_liveupdate_preserve, .unpreserve = vfio_pci_liveupdate_unpreserve, + .freeze = vfio_pci_liveupdate_freeze, .retrieve = vfio_pci_liveupdate_retrieve, .finish = vfio_pci_liveupdate_finish, .owner = THIS_MODULE, diff --git a/drivers/vfio/pci/vfio_pci_priv.h b/drivers/vfio/pci/vfio_pci_priv.h index 68966ec64e51..d3da79b7b03c 100644 --- a/drivers/vfio/pci/vfio_pci_priv.h +++ b/drivers/vfio/pci/vfio_pci_priv.h @@ -11,6 +11,8 @@ /* Cap maximum number of ioeventfds per device (arbitrary) */ #define VFIO_PCI_IOEVENTFD_MAX 1000 +extern const struct vfio_device_ops vfio_pci_ops; + struct vfio_pci_ioeventfd { struct list_head next; struct vfio_pci_core_device *vdev; diff --git a/drivers/vfio/vfio.h b/drivers/vfio/vfio.h index 50128da18bca..6b89edbbf174 100644 --- a/drivers/vfio/vfio.h +++ b/drivers/vfio/vfio.h @@ -16,17 +16,6 @@ struct iommufd_ctx; struct iommu_group; struct vfio_container; -struct vfio_device_file { - struct vfio_device *device; - struct vfio_group *group; - - u8 access_granted; - u32 devid; /* only valid when iommufd is valid */ - spinlock_t kvm_ref_lock; /* protect kvm field */ - struct kvm *kvm; - struct iommufd_ctx *iommufd; /* protected by struct vfio_device_set::lock */ -}; - void vfio_device_put_registration(struct vfio_device *device); bool vfio_device_try_get_registration(struct vfio_device *device); int vfio_df_open(struct vfio_device_file *df); @@ -34,8 +23,6 @@ void vfio_df_close(struct vfio_device_file *df); struct vfio_device_file * vfio_allocate_device_file(struct vfio_device *device); -extern const struct file_operations vfio_device_fops; - #ifdef CONFIG_VFIO_NOIOMMU extern bool vfio_noiommu __read_mostly; #else diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c index f7df90c423b4..276f615f0c28 100644 --- a/drivers/vfio/vfio_main.c +++ b/drivers/vfio/vfio_main.c @@ -1436,15 +1436,7 @@ const struct file_operations vfio_device_fops = { .show_fdinfo = vfio_device_show_fdinfo, #endif }; - -static struct vfio_device *vfio_device_from_file(struct file *file) -{ - struct vfio_device_file *df = file->private_data; - - if (file->f_op != &vfio_device_fops) - return NULL; - return df->device; -} +EXPORT_SYMBOL_GPL(vfio_device_fops); /** * vfio_file_is_valid - True if the file is valid vfio file diff --git a/include/linux/kho/abi/vfio_pci.h b/include/linux/kho/abi/vfio_pci.h index 37a845eed972..9bf58a2f3820 100644 --- a/include/linux/kho/abi/vfio_pci.h +++ b/include/linux/kho/abi/vfio_pci.h @@ -9,6 +9,9 @@ #ifndef _LINUX_LIVEUPDATE_ABI_VFIO_PCI_H #define _LINUX_LIVEUPDATE_ABI_VFIO_PCI_H +#include <linux/compiler.h> +#include <linux/types.h> + /** * DOC: VFIO PCI Live Update ABI * @@ -25,4 +28,16 @@ #define VFIO_PCI_LUO_FH_COMPATIBLE "vfio-pci-v1" +/** + * struct vfio_pci_core_device_ser - Serialized state of a single VFIO PCI + * device. + * + * @bdf: The device's PCI bus, device, and function number. + * @domain: The device's PCI domain number (segment). + */ +struct vfio_pci_core_device_ser { + u16 bdf; + u16 domain; +} __packed; + #endif /* _LINUX_LIVEUPDATE_ABI_VFIO_PCI_H */ diff --git a/include/linux/vfio.h b/include/linux/vfio.h index e90859956514..9aa1587fea19 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -81,6 +81,34 @@ struct vfio_device { #endif }; +struct vfio_device_file { + struct vfio_device *device; + struct vfio_group *group; + + u8 access_granted; + u32 devid; /* only valid when iommufd is valid */ + spinlock_t kvm_ref_lock; /* protect kvm field */ + struct kvm *kvm; + struct iommufd_ctx *iommufd; /* protected by struct vfio_device_set::lock */ +}; + +extern const struct file_operations vfio_device_fops; + +static inline struct vfio_device_file *to_vfio_device_file(struct file *file) +{ + if (file->f_op != &vfio_device_fops) + return NULL; + + return file->private_data; +} + +static inline struct vfio_device *vfio_device_from_file(struct file *file) +{ + struct vfio_device_file *df = to_vfio_device_file(file); + + return df ? df->device : NULL; +} + /** * struct vfio_device_ops - VFIO bus driver device callbacks * -- 2.53.0.rc1.225.gd81095ad13-goog
{ "author": "David Matlack <dmatlack@google.com>", "date": "Thu, 29 Jan 2026 21:24:52 +0000", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
From: Vipin Sharma <vipinsh@google.com> Enable userspace to retrieve preserved VFIO device files from VFIO after a Live Update by implementing the retrieve() and finish() file handler callbacks. Use an anonymous inode when creating the file, since the retrieved device file is not opened through any particular cdev inode, and the cdev inode does not matter in practice. For now the retrieved file is functionally equivalent a opening the corresponding VFIO cdev file. Subsequent commits will leverage the preserved state associated with the retrieved file to preserve bits of the device across Live Update. Signed-off-by: Vipin Sharma <vipinsh@google.com> Co-developed-by: David Matlack <dmatlack@google.com> Signed-off-by: David Matlack <dmatlack@google.com> --- drivers/vfio/device_cdev.c | 21 ++++++--- drivers/vfio/pci/vfio_pci_liveupdate.c | 60 +++++++++++++++++++++++++- drivers/vfio/vfio_main.c | 13 ++++++ include/linux/vfio.h | 12 ++++++ 4 files changed, 98 insertions(+), 8 deletions(-) diff --git a/drivers/vfio/device_cdev.c b/drivers/vfio/device_cdev.c index 8ceca24ac136..935f84a35875 100644 --- a/drivers/vfio/device_cdev.c +++ b/drivers/vfio/device_cdev.c @@ -16,14 +16,8 @@ void vfio_init_device_cdev(struct vfio_device *device) device->cdev.owner = THIS_MODULE; } -/* - * device access via the fd opened by this function is blocked until - * .open_device() is called successfully during BIND_IOMMUFD. - */ -int vfio_device_fops_cdev_open(struct inode *inode, struct file *filep) +int __vfio_device_fops_cdev_open(struct vfio_device *device, struct file *filep) { - struct vfio_device *device = container_of(inode->i_cdev, - struct vfio_device, cdev); struct vfio_device_file *df; int ret; @@ -52,6 +46,19 @@ int vfio_device_fops_cdev_open(struct inode *inode, struct file *filep) vfio_device_put_registration(device); return ret; } +EXPORT_SYMBOL_GPL(__vfio_device_fops_cdev_open); + +/* + * device access via the fd opened by this function is blocked until + * .open_device() is called successfully during BIND_IOMMUFD. + */ +int vfio_device_fops_cdev_open(struct inode *inode, struct file *filep) +{ + struct vfio_device *device = container_of(inode->i_cdev, + struct vfio_device, cdev); + + return __vfio_device_fops_cdev_open(device, filep); +} static void vfio_df_get_kvm_safe(struct vfio_device_file *df) { diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio_pci_liveupdate.c index f01de98f1b75..7f4117181fd0 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -8,6 +8,8 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include <linux/anon_inodes.h> +#include <linux/file.h> #include <linux/kexec_handover.h> #include <linux/kho/abi/vfio_pci.h> #include <linux/liveupdate.h> @@ -108,13 +110,68 @@ static int vfio_pci_liveupdate_freeze(struct liveupdate_file_op_args *args) return ret; } +static int match_device(struct device *dev, const void *arg) +{ + struct vfio_device *device = container_of(dev, struct vfio_device, device); + const struct vfio_pci_core_device_ser *ser = arg; + struct pci_dev *pdev; + + pdev = dev_is_pci(device->dev) ? to_pci_dev(device->dev) : NULL; + if (!pdev) + return false; + + return ser->bdf == pci_dev_id(pdev) && ser->domain == pci_domain_nr(pdev->bus); +} + static int vfio_pci_liveupdate_retrieve(struct liveupdate_file_op_args *args) { - return -EOPNOTSUPP; + struct vfio_pci_core_device_ser *ser; + struct vfio_device *device; + struct file *file; + int ret; + + ser = phys_to_virt(args->serialized_data); + + device = vfio_find_device(ser, match_device); + if (!device) + return -ENODEV; + + /* + * Simulate opening the character device using an anonymous inode. The + * returned file has the same properties as a cdev file (e.g. operations + * are blocked until BIND_IOMMUFD is called). + */ + file = anon_inode_getfile_fmode("[vfio-device-liveupdate]", + &vfio_device_fops, NULL, + O_RDWR, FMODE_PREAD | FMODE_PWRITE); + if (IS_ERR(file)) { + ret = PTR_ERR(file); + goto out; + } + + ret = __vfio_device_fops_cdev_open(device, file); + if (ret) { + fput(file); + goto out; + } + + args->file = file; + +out: + /* Drop the reference from vfio_find_device() */ + put_device(&device->device); + + return ret; +} + +static bool vfio_pci_liveupdate_can_finish(struct liveupdate_file_op_args *args) +{ + return args->retrieved; } static void vfio_pci_liveupdate_finish(struct liveupdate_file_op_args *args) { + kho_restore_free(phys_to_virt(args->serialized_data)); } static const struct liveupdate_file_ops vfio_pci_liveupdate_file_ops = { @@ -123,6 +180,7 @@ static const struct liveupdate_file_ops vfio_pci_liveupdate_file_ops = { .unpreserve = vfio_pci_liveupdate_unpreserve, .freeze = vfio_pci_liveupdate_freeze, .retrieve = vfio_pci_liveupdate_retrieve, + .can_finish = vfio_pci_liveupdate_can_finish, .finish = vfio_pci_liveupdate_finish, .owner = THIS_MODULE, }; diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c index 276f615f0c28..89c5feef75d5 100644 --- a/drivers/vfio/vfio_main.c +++ b/drivers/vfio/vfio_main.c @@ -13,6 +13,7 @@ #include <linux/cdev.h> #include <linux/compat.h> #include <linux/device.h> +#include <linux/device/class.h> #include <linux/fs.h> #include <linux/idr.h> #include <linux/iommu.h> @@ -1758,6 +1759,18 @@ int vfio_dma_rw(struct vfio_device *device, dma_addr_t iova, void *data, } EXPORT_SYMBOL(vfio_dma_rw); +struct vfio_device *vfio_find_device(const void *data, device_match_t match) +{ + struct device *device; + + device = class_find_device(vfio.device_class, NULL, data, match); + if (!device) + return NULL; + + return container_of(device, struct vfio_device, device); +} +EXPORT_SYMBOL_GPL(vfio_find_device); + /* * Module/class support */ diff --git a/include/linux/vfio.h b/include/linux/vfio.h index 9aa1587fea19..dc592dc00f89 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -419,4 +419,16 @@ int vfio_virqfd_enable(void *opaque, int (*handler)(void *, void *), void vfio_virqfd_disable(struct virqfd **pvirqfd); void vfio_virqfd_flush_thread(struct virqfd **pvirqfd); +#if IS_ENABLED(CONFIG_VFIO_DEVICE_CDEV) +int __vfio_device_fops_cdev_open(struct vfio_device *device, struct file *filep); +#else +static inline int __vfio_device_fops_cdev_open(struct vfio_device *device, + struct file *filep) +{ + return -EOPNOTSUPP; +} +#endif /* IS_ENABLED(CONFIG_VFIO_DEVICE_CDEV) */ + +struct vfio_device *vfio_find_device(const void *data, device_match_t match); + #endif /* VFIO_H */ -- 2.53.0.rc1.225.gd81095ad13-goog
{ "author": "David Matlack <dmatlack@google.com>", "date": "Thu, 29 Jan 2026 21:24:53 +0000", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
Notify the PCI subsystem about devices vfio-pci is preserving across Live Update by registering the vfio-pci liveupdate file handler with the PCI subsystem's FLB handler. Notably this will ensure that devices preserved through vfio-pci will have their PCI bus numbers preserved across Live Update, allowing VFIO to use BDF as a key to identify the device across the Live Update and (in the future) allow the device to continue DMA operations across the Live Update. This also enables VFIO to detect that a device was preserved before userspace first retrieves the file from it, which will be used in subsequent commits. Signed-off-by: David Matlack <dmatlack@google.com> --- drivers/vfio/pci/vfio_pci_liveupdate.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio_pci_liveupdate.c index 7f4117181fd0..ad915352303f 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -53,6 +53,8 @@ static int vfio_pci_liveupdate_preserve(struct liveupdate_file_op_args *args) if (IS_ERR(ser)) return PTR_ERR(ser); + pci_liveupdate_outgoing_preserve(pdev); + ser->bdf = pci_dev_id(pdev); ser->domain = pci_domain_nr(pdev->bus); @@ -62,6 +64,9 @@ static int vfio_pci_liveupdate_preserve(struct liveupdate_file_op_args *args) static void vfio_pci_liveupdate_unpreserve(struct liveupdate_file_op_args *args) { + struct vfio_device *device = vfio_device_from_file(args->file); + + pci_liveupdate_outgoing_unpreserve(to_pci_dev(device->dev)); kho_unpreserve_free(phys_to_virt(args->serialized_data)); } @@ -171,6 +176,9 @@ static bool vfio_pci_liveupdate_can_finish(struct liveupdate_file_op_args *args) static void vfio_pci_liveupdate_finish(struct liveupdate_file_op_args *args) { + struct vfio_device *device = vfio_device_from_file(args->file); + + pci_liveupdate_incoming_finish(to_pci_dev(device->dev)); kho_restore_free(phys_to_virt(args->serialized_data)); } @@ -192,10 +200,24 @@ static struct liveupdate_file_handler vfio_pci_liveupdate_fh = { int __init vfio_pci_liveupdate_init(void) { + int ret; + if (!liveupdate_enabled()) return 0; - return liveupdate_register_file_handler(&vfio_pci_liveupdate_fh); + ret = liveupdate_register_file_handler(&vfio_pci_liveupdate_fh); + if (ret) + return ret; + + ret = pci_liveupdate_register_fh(&vfio_pci_liveupdate_fh); + if (ret) + goto error; + + return 0; + +error: + liveupdate_unregister_file_handler(&vfio_pci_liveupdate_fh); + return ret; } void vfio_pci_liveupdate_cleanup(void) @@ -203,5 +225,6 @@ void vfio_pci_liveupdate_cleanup(void) if (!liveupdate_enabled()) return; + WARN_ON_ONCE(pci_liveupdate_unregister_fh(&vfio_pci_liveupdate_fh)); liveupdate_unregister_file_handler(&vfio_pci_liveupdate_fh); } -- 2.53.0.rc1.225.gd81095ad13-goog
{ "author": "David Matlack <dmatlack@google.com>", "date": "Thu, 29 Jan 2026 21:24:54 +0000", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
Enforce that files for incoming (preserved by previous kernel) VFIO devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD rather than by opening the corresponding VFIO character device or via VFIO_GROUP_GET_DEVICE_FD. Both of these methods would result in VFIO initializing the device without access to the preserved state of the device passed by the previous kernel. Signed-off-by: David Matlack <dmatlack@google.com> --- drivers/vfio/device_cdev.c | 4 ++++ drivers/vfio/group.c | 9 +++++++++ include/linux/vfio.h | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/drivers/vfio/device_cdev.c b/drivers/vfio/device_cdev.c index 935f84a35875..355447e2add3 100644 --- a/drivers/vfio/device_cdev.c +++ b/drivers/vfio/device_cdev.c @@ -57,6 +57,10 @@ int vfio_device_fops_cdev_open(struct inode *inode, struct file *filep) struct vfio_device *device = container_of(inode->i_cdev, struct vfio_device, cdev); + /* Device file must be retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD */ + if (vfio_liveupdate_incoming_is_preserved(device)) + return -EBUSY; + return __vfio_device_fops_cdev_open(device, filep); } diff --git a/drivers/vfio/group.c b/drivers/vfio/group.c index d47ffada6912..63fc4d656215 100644 --- a/drivers/vfio/group.c +++ b/drivers/vfio/group.c @@ -311,6 +311,15 @@ static int vfio_group_ioctl_get_device_fd(struct vfio_group *group, if (IS_ERR(device)) return PTR_ERR(device); + /* + * This device was preserved across a Live Update. Accessing it via + * VFIO_GROUP_GET_DEVICE_FD is not allowed. + */ + if (vfio_liveupdate_incoming_is_preserved(device)) { + vfio_device_put_registration(device); + return -EBUSY; + } + fd = FD_ADD(O_CLOEXEC, vfio_device_open_file(device)); if (fd < 0) vfio_device_put_registration(device); diff --git a/include/linux/vfio.h b/include/linux/vfio.h index dc592dc00f89..0921847b18b5 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -16,6 +16,7 @@ #include <linux/cdev.h> #include <uapi/linux/vfio.h> #include <linux/iova_bitmap.h> +#include <linux/pci.h> struct kvm; struct iommufd_ctx; @@ -431,4 +432,21 @@ static inline int __vfio_device_fops_cdev_open(struct vfio_device *device, struct vfio_device *vfio_find_device(const void *data, device_match_t match); +#ifdef CONFIG_LIVEUPDATE +static inline bool vfio_liveupdate_incoming_is_preserved(struct vfio_device *device) +{ + struct device *d = device->dev; + + if (dev_is_pci(d)) + return to_pci_dev(d)->liveupdate_incoming; + + return false; +} +#else +static inline bool vfio_liveupdate_incoming_is_preserved(struct vfio_device *device) +{ + return false; +} +#endif + #endif /* VFIO_H */ -- 2.53.0.rc1.225.gd81095ad13-goog
{ "author": "David Matlack <dmatlack@google.com>", "date": "Thu, 29 Jan 2026 21:24:55 +0000", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
Stash a pointer to a device's incoming Live Updated state in struct vfio_pci_core_device. This will enable subsequent commits to use the preserved state when initializing the device. To enable VFIO to safely access this pointer during device enablement, require that the device is fully enabled before returning true from can_finish(). This is synchronized by vfio_pci_core.c setting vdev->liveupdate_incoming_state to NULL under dev_set lock once it's done using it. Signed-off-by: David Matlack <dmatlack@google.com> --- drivers/vfio/pci/vfio_pci_core.c | 2 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 17 ++++++++++++++++- include/linux/vfio_pci_core.h | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index 3a11e6f450f7..b01b94d81e28 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -569,7 +569,7 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *vdev) if (!vfio_vga_disabled() && vfio_pci_is_vga(pdev)) vdev->has_vga = true; - + vdev->liveupdate_incoming_state = NULL; return 0; out_free_zdev: diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio_pci_liveupdate.c index ad915352303f..1ad7379c70c4 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -131,6 +131,7 @@ static int match_device(struct device *dev, const void *arg) static int vfio_pci_liveupdate_retrieve(struct liveupdate_file_op_args *args) { struct vfio_pci_core_device_ser *ser; + struct vfio_pci_core_device *vdev; struct vfio_device *device; struct file *file; int ret; @@ -160,6 +161,9 @@ static int vfio_pci_liveupdate_retrieve(struct liveupdate_file_op_args *args) goto out; } + vdev = container_of(device, struct vfio_pci_core_device, vdev); + vdev->liveupdate_incoming_state = ser; + args->file = file; out: @@ -171,7 +175,18 @@ static int vfio_pci_liveupdate_retrieve(struct liveupdate_file_op_args *args) static bool vfio_pci_liveupdate_can_finish(struct liveupdate_file_op_args *args) { - return args->retrieved; + struct vfio_pci_core_device *vdev; + struct vfio_device *device; + + if (!args->retrieved) + return false; + + device = vfio_device_from_file(args->file); + vdev = container_of(device, struct vfio_pci_core_device, vdev); + + /* Check that vdev->liveupdate_incoming_state is no longer in use. */ + guard(mutex)(&device->dev_set->lock); + return !vdev->liveupdate_incoming_state; } static void vfio_pci_liveupdate_finish(struct liveupdate_file_op_args *args) diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h index 1ac86896875c..350c30f84a13 100644 --- a/include/linux/vfio_pci_core.h +++ b/include/linux/vfio_pci_core.h @@ -143,6 +143,7 @@ struct vfio_pci_core_device { struct notifier_block nb; struct rw_semaphore memory_lock; struct list_head dmabufs; + struct vfio_pci_core_device_ser *liveupdate_incoming_state; }; enum vfio_pci_io_width { -- 2.53.0.rc1.225.gd81095ad13-goog
{ "author": "David Matlack <dmatlack@google.com>", "date": "Thu, 29 Jan 2026 21:24:56 +0000", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
From: Vipin Sharma <vipinsh@google.com> Do not reset the device when a Live Update preserved vfio-pci device is retrieved and first enabled. vfio_pci_liveupdate_freeze() guarantees the device is reset prior to Live Update, so there's no reason to reset it again after Live Update. Since VFIO normally uses the initial reset to detect if the device supports function resets, pass that from the previous kernel via struct vfio_pci_core_dev_ser. Signed-off-by: Vipin Sharma <vipinsh@google.com> Signed-off-by: David Matlack <dmatlack@google.com> --- drivers/vfio/pci/vfio_pci_core.c | 22 +++++++++++++++++----- drivers/vfio/pci/vfio_pci_liveupdate.c | 1 + include/linux/kho/abi/vfio_pci.h | 2 ++ include/linux/vfio_pci_core.h | 1 + 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index b01b94d81e28..c9f73f597797 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -515,12 +515,24 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *vdev) if (ret) goto out_power; - /* If reset fails because of the device lock, fail this path entirely */ - ret = pci_try_reset_function(pdev); - if (ret == -EAGAIN) - goto out_disable_device; + if (vdev->liveupdate_incoming_state) { + /* + * This device was preserved by the previous kernel across a + * Live Update, so it does not need to be reset. + */ + vdev->reset_works = vdev->liveupdate_incoming_state->reset_works; + } else { + /* + * If reset fails because of the device lock, fail this path + * entirely. + */ + ret = pci_try_reset_function(pdev); + if (ret == -EAGAIN) + goto out_disable_device; + + vdev->reset_works = !ret; + } - vdev->reset_works = !ret; pci_save_state(pdev); vdev->pci_saved_state = pci_store_saved_state(pdev); if (!vdev->pci_saved_state) diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio_pci_liveupdate.c index 1ad7379c70c4..c52d6bdb455f 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -57,6 +57,7 @@ static int vfio_pci_liveupdate_preserve(struct liveupdate_file_op_args *args) ser->bdf = pci_dev_id(pdev); ser->domain = pci_domain_nr(pdev->bus); + ser->reset_works = vdev->reset_works; args->serialized_data = virt_to_phys(ser); return 0; diff --git a/include/linux/kho/abi/vfio_pci.h b/include/linux/kho/abi/vfio_pci.h index 9bf58a2f3820..6c3d3c6dfc09 100644 --- a/include/linux/kho/abi/vfio_pci.h +++ b/include/linux/kho/abi/vfio_pci.h @@ -34,10 +34,12 @@ * * @bdf: The device's PCI bus, device, and function number. * @domain: The device's PCI domain number (segment). + * @reset_works: Non-zero if the device supports function resets. */ struct vfio_pci_core_device_ser { u16 bdf; u16 domain; + u8 reset_works; } __packed; #endif /* _LINUX_LIVEUPDATE_ABI_VFIO_PCI_H */ diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h index 350c30f84a13..95835298e29e 100644 --- a/include/linux/vfio_pci_core.h +++ b/include/linux/vfio_pci_core.h @@ -16,6 +16,7 @@ #include <linux/types.h> #include <linux/uuid.h> #include <linux/notifier.h> +#include <linux/kho/abi/vfio_pci.h> #ifndef VFIO_PCI_CORE_H #define VFIO_PCI_CORE_H -- 2.53.0.rc1.225.gd81095ad13-goog
{ "author": "David Matlack <dmatlack@google.com>", "date": "Thu, 29 Jan 2026 21:24:57 +0000", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
Add documentation for preserving VFIO device files across a Live Update, as well as some generic file preservation documentation. This documentation will be extended in the future as new types of files are supported and new dependency/ordering requirements are added. Signed-off-by: David Matlack <dmatlack@google.com> --- Documentation/userspace-api/liveupdate.rst | 144 +++++++++++++++++++++ 1 file changed, 144 insertions(+) diff --git a/Documentation/userspace-api/liveupdate.rst b/Documentation/userspace-api/liveupdate.rst index 41c0473e4f16..dbf1e4aeddd7 100644 --- a/Documentation/userspace-api/liveupdate.rst +++ b/Documentation/userspace-api/liveupdate.rst @@ -14,6 +14,150 @@ ioctl uAPI =========== .. kernel-doc:: include/uapi/linux/liveupdate.h +File Preservation +================= + +Files can be preserved across Live Update in sessions. Since only one process +can open /dev/liveupdate, sessions must be created by a centralized process +(e.g. "luod") and then passed via UDS to lower privilege processes (e.g. VMMs) +for them to preserve their own files. + +luod:: + + luo_fd = open("/dev/liveupdate", ...); + + ... + + // Create a new session with the given name. + struct liveupdate_ioctl_create_session arg = { + .size = sizeof(arg), + .name = SESSION_NAME, + }; + ioctl(luo_fd, LIVEUPDATE_IOCTL_CREATE_SESSION, &arg); + + // Send session_fd to the VMM over UDS. + send_session_fd(..., arg.fd); + +VMM:: + + // Receive the newly created session from luod over UDS + session_fd = create_session(SESSION_NAME); + + ... + + // Preserve a file with a unique token value in the session. + struct liveupdate_session_preserve_fd arg = { + .size = sizeof(arg), + .fd = fd, + .token = TOKEN, + } + ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg); + +Files can be unpreserved with the LIVEUPDATE_SESSION_UNPRESERVE_FD ioctl. They +are also unpreserved once the last reference to the session is dropped. To +carry preserved files across a Live Update, references must be kept on the +session files through the reboot(LINUX_REBOOT_CMD_KEXEC) syscall. + +While a file is preserved in a session, the kernel holds an extra reference +to it to prevent it from being destroyed. + +Only the following types of files support LIVEUPDATE_SESSION_PRESERVE_FD. More +types of files are expected to be added in the future. + + - memfd + - VFIO character device files (vfio-pci only) + +File Retrieval +============== + +Files that are preserved in a session retrieved after +reboot(LINUX_REBOOT_CMD_KEXEC). + +luod:: + + luo_fd = open("/dev/liveupdate", ...); + + ... + + struct liveupdate_ioctl_retrieve_session arg = { + .size = sizeof(arg), + .name = SESSION_NAME, + }; + ioctl(luo_fd, LIVEUPDATE_IOCTL_RETRIEVE_SESSION, &arg); + + // Send session_fd to VMM over UDS. + send_session_fd(..., arg.fd); + +VMM:: + + // Receive the retrieved session from luod over UDS + session_fd = retrieve_session(SESSION_NAME); + + ... + + // Retrieve the file associated with the token from the session. + struct liveupdate_session_retrieve_fd arg = { + .size = sizeof(arg), + .token = TOKEN, + }; + ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_FD, &arg); + + ... + + ioctl(session_fd, LIVEUPDATE_SESSION_FINISH, ...); + +A session can only be finished once all of the files within it have been +retrieved, and are fully restored from the kernel's perspective. The exact +requirements will vary by file type. + +VFIO Character Device (cdev) Files +================================== + +The kernel supports preserving VFIO character device files across Live Update +within a session:: + + device_fd = open("/dev/vfio/devices/X"); + + ... + + ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, { ..., device_fd, ...}); + +Attempting to preserve files acquired via VFIO_GROUP_GET_DEVICE_FD will fail. + +Since the kernel holds an extra reference to files preserved in sessions, there +is no way for the underlying PCI device to be unbound from vfio-pci while it +is being preserved. + +When a VFIO device file is preserved in a session, interrupts must be disabled +on the device prior to reboot(LINUX_REBOOT_CMD_KEXEC), or the kexec will fail. + +Preserved VFIO device files can be retrieved after a Live Update just like any +other preserved file:: + + ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_FD, &arg); + device_fd = arg.fd; + + ... + + ioctl(session_fd, LIVEUPDATE_SESSION_FINISH, ...); + +Prior to LIVEUPDATE_SESSION_FINISH, preserved devices must be retrieved from +the session and bound to an iommufd. Attempting to open the device through +its character device (/dev/vfio/devices/X) or VFIO_GROUP_GET_DEVICE_FD will +fail with -EBUSY. + +The eventual goal of these support is to preserve devices running uninterrupted +across a Live Update. However there are many steps still needed to achieve this +(see Future Work below). So for now, VFIO will reset and restore the device +back into an idle state during reboot(LINUX_REBOOT_CMD_KEXEC). + +Future work: + + - Preservation of iommufd files + - Preservation of IOMMU driver state + - Preservation of PCI state (BAR resources, device state, bridge state, ...) + - Preservation of vfio-pci driver state + See Also ======== -- 2.53.0.rc1.225.gd81095ad13-goog
{ "author": "David Matlack <dmatlack@google.com>", "date": "Thu, 29 Jan 2026 21:24:58 +0000", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
From: Vipin Sharma <vipinsh@google.com> Move luo_test_utils.[ch] into a lib/ directory and pull the rules to build them out into a separate make script. This will enable these utilities to be also built by and used within other selftests (such as VFIO) in subsequent commits. No functional change intended. Signed-off-by: Vipin Sharma <vipinsh@google.com> Co-developed-by: David Matlack <dmatlack@google.com> Signed-off-by: David Matlack <dmatlack@google.com> --- tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 ++++--------- .../include/libliveupdate.h} | 8 ++++---- .../selftests/liveupdate/lib/libliveupdate.mk | 20 +++++++++++++++++++ .../{luo_test_utils.c => lib/liveupdate.c} | 2 +- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- 7 files changed, 32 insertions(+), 17 deletions(-) rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (87%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (99%) diff --git a/tools/testing/selftests/liveupdate/.gitignore b/tools/testing/selftests/liveupdate/.gitignore index 661827083ab6..18a0c7036cf3 100644 --- a/tools/testing/selftests/liveupdate/.gitignore +++ b/tools/testing/selftests/liveupdate/.gitignore @@ -3,6 +3,7 @@ !/**/ !*.c !*.h +!*.mk !*.sh !.gitignore !config diff --git a/tools/testing/selftests/liveupdate/Makefile b/tools/testing/selftests/liveupdate/Makefile index 080754787ede..a060cc21f27f 100644 --- a/tools/testing/selftests/liveupdate/Makefile +++ b/tools/testing/selftests/liveupdate/Makefile @@ -1,7 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -LIB_C += luo_test_utils.c - TEST_GEN_PROGS += liveupdate TEST_GEN_PROGS_EXTENDED += luo_kexec_simple @@ -10,25 +8,21 @@ TEST_GEN_PROGS_EXTENDED += luo_multi_session TEST_FILES += do_kexec.sh include ../lib.mk +include lib/libliveupdate.mk CFLAGS += $(KHDR_INCLUDES) CFLAGS += -Wall -O2 -Wno-unused-function CFLAGS += -MD -LIB_O := $(patsubst %.c, $(OUTPUT)/%.o, $(LIB_C)) TEST_O := $(patsubst %, %.o, $(TEST_GEN_PROGS)) TEST_O += $(patsubst %, %.o, $(TEST_GEN_PROGS_EXTENDED)) -TEST_DEP_FILES := $(patsubst %.o, %.d, $(LIB_O)) +TEST_DEP_FILES := $(patsubst %.o, %.d, $(LIBLIVEUPDATE_O)) TEST_DEP_FILES += $(patsubst %.o, %.d, $(TEST_O)) -include $(TEST_DEP_FILES) -$(LIB_O): $(OUTPUT)/%.o: %.c - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@ - -$(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/%: %.o $(LIB_O) - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) $< $(LIB_O) $(LDLIBS) -o $@ +$(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/%: %.o $(LIBLIVEUPDATE_O) + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) $< $(LIBLIVEUPDATE_O) $(LDLIBS) -o $@ -EXTRA_CLEAN += $(LIB_O) EXTRA_CLEAN += $(TEST_O) EXTRA_CLEAN += $(TEST_DEP_FILES) diff --git a/tools/testing/selftests/liveupdate/luo_test_utils.h b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h similarity index 87% rename from tools/testing/selftests/liveupdate/luo_test_utils.h rename to tools/testing/selftests/liveupdate/lib/include/libliveupdate.h index 90099bf49577..4390a2737930 100644 --- a/tools/testing/selftests/liveupdate/luo_test_utils.h +++ b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h @@ -7,13 +7,13 @@ * Utility functions for LUO kselftests. */ -#ifndef LUO_TEST_UTILS_H -#define LUO_TEST_UTILS_H +#ifndef SELFTESTS_LIVEUPDATE_LIB_LIVEUPDATE_H +#define SELFTESTS_LIVEUPDATE_LIB_LIVEUPDATE_H #include <errno.h> #include <string.h> #include <linux/liveupdate.h> -#include "../kselftest.h" +#include "../../../kselftest.h" #define LUO_DEVICE "/dev/liveupdate" @@ -41,4 +41,4 @@ typedef void (*luo_test_stage2_fn)(int luo_fd, int state_session_fd); int luo_test(int argc, char *argv[], const char *state_session_name, luo_test_stage1_fn stage1, luo_test_stage2_fn stage2); -#endif /* LUO_TEST_UTILS_H */ +#endif /* SELFTESTS_LIVEUPDATE_LIB_LIVEUPDATE_H */ diff --git a/tools/testing/selftests/liveupdate/lib/libliveupdate.mk b/tools/testing/selftests/liveupdate/lib/libliveupdate.mk new file mode 100644 index 000000000000..fffd95b085b6 --- /dev/null +++ b/tools/testing/selftests/liveupdate/lib/libliveupdate.mk @@ -0,0 +1,20 @@ +include $(top_srcdir)/scripts/subarch.include +ARCH ?= $(SUBARCH) + +LIBLIVEUPDATE_SRCDIR := $(selfdir)/liveupdate/lib + +LIBLIVEUPDATE_C := liveupdate.c + +LIBLIVEUPDATE_OUTPUT := $(OUTPUT)/libliveupdate + +LIBLIVEUPDATE_O := $(patsubst %.c, $(LIBLIVEUPDATE_OUTPUT)/%.o, $(LIBLIVEUPDATE_C)) + +LIBLIVEUPDATE_O_DIRS := $(shell dirname $(LIBLIVEUPDATE_O) | uniq) +$(shell mkdir -p $(LIBLIVEUPDATE_O_DIRS)) + +CFLAGS += -I$(LIBLIVEUPDATE_SRCDIR)/include + +$(LIBLIVEUPDATE_O): $(LIBLIVEUPDATE_OUTPUT)/%.o : $(LIBLIVEUPDATE_SRCDIR)/%.c + $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@ + +EXTRA_CLEAN += $(LIBLIVEUPDATE_OUTPUT) diff --git a/tools/testing/selftests/liveupdate/luo_test_utils.c b/tools/testing/selftests/liveupdate/lib/liveupdate.c similarity index 99% rename from tools/testing/selftests/liveupdate/luo_test_utils.c rename to tools/testing/selftests/liveupdate/lib/liveupdate.c index 3c8721c505df..60121873f685 100644 --- a/tools/testing/selftests/liveupdate/luo_test_utils.c +++ b/tools/testing/selftests/liveupdate/lib/liveupdate.c @@ -21,7 +21,7 @@ #include <errno.h> #include <stdarg.h> -#include "luo_test_utils.h" +#include <libliveupdate.h> int luo_open_device(void) { diff --git a/tools/testing/selftests/liveupdate/luo_kexec_simple.c b/tools/testing/selftests/liveupdate/luo_kexec_simple.c index d7ac1f3dc4cb..786ac93b9ae3 100644 --- a/tools/testing/selftests/liveupdate/luo_kexec_simple.c +++ b/tools/testing/selftests/liveupdate/luo_kexec_simple.c @@ -8,7 +8,7 @@ * across a single kexec reboot. */ -#include "luo_test_utils.h" +#include <libliveupdate.h> #define TEST_SESSION_NAME "test-session" #define TEST_MEMFD_TOKEN 0x1A diff --git a/tools/testing/selftests/liveupdate/luo_multi_session.c b/tools/testing/selftests/liveupdate/luo_multi_session.c index 0ee2d795beef..aac24a5f5ce3 100644 --- a/tools/testing/selftests/liveupdate/luo_multi_session.c +++ b/tools/testing/selftests/liveupdate/luo_multi_session.c @@ -9,7 +9,7 @@ * files. */ -#include "luo_test_utils.h" +#include <libliveupdate.h> #define SESSION_EMPTY_1 "multi-test-empty-1" #define SESSION_EMPTY_2 "multi-test-empty-2" -- 2.53.0.rc1.225.gd81095ad13-goog
{ "author": "David Matlack <dmatlack@google.com>", "date": "Thu, 29 Jan 2026 21:24:59 +0000", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
From: Vipin Sharma <vipinsh@google.com> Add helper functions to preserve and retrieve file descriptors from an LUO session. These will be used be used in subsequent commits to preserve FDs other than memfd. No functional change intended. Signed-off-by: Vipin Sharma <vipinsh@google.com> Co-developed-by: David Matlack <dmatlack@google.com> Signed-off-by: David Matlack <dmatlack@google.com> --- .../liveupdate/lib/include/libliveupdate.h | 3 ++ .../selftests/liveupdate/lib/liveupdate.c | 41 +++++++++++++++---- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h index 4390a2737930..4c93d043d2b3 100644 --- a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h +++ b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h @@ -26,6 +26,9 @@ int luo_create_session(int luo_fd, const char *name); int luo_retrieve_session(int luo_fd, const char *name); int luo_session_finish(int session_fd); +int luo_session_preserve_fd(int session_fd, int fd, int token); +int luo_session_retrieve_fd(int session_fd, int token); + int create_and_preserve_memfd(int session_fd, int token, const char *data); int restore_and_verify_memfd(int session_fd, int token, const char *expected_data); diff --git a/tools/testing/selftests/liveupdate/lib/liveupdate.c b/tools/testing/selftests/liveupdate/lib/liveupdate.c index 60121873f685..9bf4f16ca0a4 100644 --- a/tools/testing/selftests/liveupdate/lib/liveupdate.c +++ b/tools/testing/selftests/liveupdate/lib/liveupdate.c @@ -54,9 +54,35 @@ int luo_retrieve_session(int luo_fd, const char *name) return arg.fd; } +int luo_session_preserve_fd(int session_fd, int fd, int token) +{ + struct liveupdate_session_preserve_fd arg = { + .size = sizeof(arg), + .fd = fd, + .token = token, + }; + + if (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg)) + return -errno; + + return 0; +} + +int luo_session_retrieve_fd(int session_fd, int token) +{ + struct liveupdate_session_retrieve_fd arg = { + .size = sizeof(arg), + .token = token, + }; + + if (ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_FD, &arg)) + return -errno; + + return arg.fd; +} + int create_and_preserve_memfd(int session_fd, int token, const char *data) { - struct liveupdate_session_preserve_fd arg = { .size = sizeof(arg) }; long page_size = sysconf(_SC_PAGE_SIZE); void *map = MAP_FAILED; int mfd = -1, ret = -1; @@ -75,9 +101,8 @@ int create_and_preserve_memfd(int session_fd, int token, const char *data) snprintf(map, page_size, "%s", data); munmap(map, page_size); - arg.fd = mfd; - arg.token = token; - if (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg) < 0) + ret = luo_session_preserve_fd(session_fd, mfd, token); + if (ret) goto out; ret = 0; @@ -92,15 +117,13 @@ int create_and_preserve_memfd(int session_fd, int token, const char *data) int restore_and_verify_memfd(int session_fd, int token, const char *expected_data) { - struct liveupdate_session_retrieve_fd arg = { .size = sizeof(arg) }; long page_size = sysconf(_SC_PAGE_SIZE); void *map = MAP_FAILED; int mfd = -1, ret = -1; - arg.token = token; - if (ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_FD, &arg) < 0) - return -errno; - mfd = arg.fd; + mfd = luo_session_retrieve_fd(session_fd, token); + if (mfd < 0) + return mfd; map = mmap(NULL, page_size, PROT_READ, MAP_SHARED, mfd, 0); if (map == MAP_FAILED) -- 2.53.0.rc1.225.gd81095ad13-goog
{ "author": "David Matlack <dmatlack@google.com>", "date": "Thu, 29 Jan 2026 21:25:00 +0000", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
Add a selftest to exercise preserving a various VFIO files through /dev/liveupdate. Ensure that VFIO cdev device files can be preserved and everything else (group-based device files, group files, and container files) all fail. Signed-off-by: David Matlack <dmatlack@google.com> --- tools/testing/selftests/vfio/Makefile | 1 + .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c diff --git a/tools/testing/selftests/vfio/Makefile b/tools/testing/selftests/vfio/Makefile index f9c040094d4a..666310872217 100644 --- a/tools/testing/selftests/vfio/Makefile +++ b/tools/testing/selftests/vfio/Makefile @@ -4,6 +4,7 @@ TEST_GEN_PROGS += vfio_iommufd_setup_test TEST_GEN_PROGS += vfio_pci_device_test TEST_GEN_PROGS += vfio_pci_device_init_perf_test TEST_GEN_PROGS += vfio_pci_driver_test +TEST_GEN_PROGS += vfio_pci_liveupdate_uapi_test TEST_FILES += scripts/cleanup.sh TEST_FILES += scripts/lib.sh diff --git a/tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c b/tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c new file mode 100644 index 000000000000..3b4276b2532c --- /dev/null +++ b/tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c @@ -0,0 +1,93 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include <libliveupdate.h> +#include <libvfio.h> +#include <kselftest_harness.h> + +static const char *device_bdf; + +FIXTURE(vfio_pci_liveupdate_uapi_test) { + int luo_fd; + int session_fd; + struct iommu *iommu; + struct vfio_pci_device *device; +}; + +FIXTURE_VARIANT(vfio_pci_liveupdate_uapi_test) { + const char *iommu_mode; +}; + +#define FIXTURE_VARIANT_ADD_IOMMU_MODE(_iommu_mode) \ +FIXTURE_VARIANT_ADD(vfio_pci_liveupdate_uapi_test, _iommu_mode) { \ + .iommu_mode = #_iommu_mode, \ +} + +FIXTURE_VARIANT_ADD_ALL_IOMMU_MODES(); +#undef FIXTURE_VARIANT_ADD_IOMMU_MODE + +FIXTURE_SETUP(vfio_pci_liveupdate_uapi_test) +{ + self->luo_fd = luo_open_device(); + ASSERT_GE(self->luo_fd, 0); + + self->session_fd = luo_create_session(self->luo_fd, "session"); + ASSERT_GE(self->session_fd, 0); + + self->iommu = iommu_init(variant->iommu_mode); + self->device = vfio_pci_device_init(device_bdf, self->iommu); +} + +FIXTURE_TEARDOWN(vfio_pci_liveupdate_uapi_test) +{ + vfio_pci_device_cleanup(self->device); + iommu_cleanup(self->iommu); + close(self->session_fd); + close(self->luo_fd); +} + +TEST_F(vfio_pci_liveupdate_uapi_test, preserve_device) +{ + int ret; + + ret = luo_session_preserve_fd(self->session_fd, self->device->fd, 0); + + /* Preservation should only be supported for VFIO cdev files. */ + ASSERT_EQ(ret, self->iommu->iommufd ? 0 : -ENOENT); +} + +TEST_F(vfio_pci_liveupdate_uapi_test, preserve_group_fails) +{ + int ret; + + if (self->iommu->iommufd) + return; + + ret = luo_session_preserve_fd(self->session_fd, self->device->group_fd, 0); + ASSERT_EQ(ret, -ENOENT); +} + +TEST_F(vfio_pci_liveupdate_uapi_test, preserve_container_fails) +{ + int ret; + + if (self->iommu->iommufd) + return; + + ret = luo_session_preserve_fd(self->session_fd, self->iommu->container_fd, 0); + ASSERT_EQ(ret, -ENOENT); +} + +int main(int argc, char *argv[]) +{ + int fd; + + fd = luo_open_device(); + if (fd < 0) { + printf("open(%s) failed: %s, skipping\n", LUO_DEVICE, strerror(errno)); + return KSFT_SKIP; + } + close(fd); + + device_bdf = vfio_selftests_get_bdf(&argc, argv); + return test_harness_run(argc, argv); +} -- 2.53.0.rc1.225.gd81095ad13-goog
{ "author": "David Matlack <dmatlack@google.com>", "date": "Thu, 29 Jan 2026 21:25:03 +0000", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
From: Vipin Sharma <vipinsh@google.com> Import and build liveupdate selftest library in VFIO selftests. It allows to use liveupdate ioctls in VFIO selftests Signed-off-by: Vipin Sharma <vipinsh@google.com> Signed-off-by: David Matlack <dmatlack@google.com> --- tools/testing/selftests/vfio/Makefile | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/vfio/Makefile b/tools/testing/selftests/vfio/Makefile index 3c796ca99a50..1e50998529fd 100644 --- a/tools/testing/selftests/vfio/Makefile +++ b/tools/testing/selftests/vfio/Makefile @@ -12,6 +12,7 @@ TEST_FILES += scripts/setup.sh include ../lib.mk include lib/libvfio.mk +include ../liveupdate/lib/libliveupdate.mk CFLAGS += -I$(top_srcdir)/tools/include CFLAGS += -MD @@ -19,11 +20,15 @@ CFLAGS += $(EXTRA_CFLAGS) LDFLAGS += -pthread -$(TEST_GEN_PROGS): %: %.o $(LIBVFIO_O) - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $< $(LIBVFIO_O) $(LDLIBS) -o $@ +LIBS_O := $(LIBVFIO_O) +LIBS_O += $(LIBLIVEUPDATE_O) + +$(TEST_GEN_PROGS): %: %.o $(LIBS_O) + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) $< $(LIBS_O) $(LDLIBS) -o $@ TEST_GEN_PROGS_O = $(patsubst %, %.o, $(TEST_GEN_PROGS)) -TEST_DEP_FILES = $(patsubst %.o, %.d, $(TEST_GEN_PROGS_O) $(LIBVFIO_O)) +TEST_DEP_FILES := $(patsubst %.o, %.d, $(TEST_GEN_PROGS_O)) +TEST_DEP_FILES += $(patsubst %.o, %.d, $(LIBS_O)) -include $(TEST_DEP_FILES) EXTRA_CLEAN += $(TEST_GEN_PROGS_O) $(TEST_DEP_FILES) -- 2.53.0.rc1.225.gd81095ad13-goog
{ "author": "David Matlack <dmatlack@google.com>", "date": "Thu, 29 Jan 2026 21:25:01 +0000", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
Add Makefile support for TEST_GEN_PROGS_EXTENDED targets. These tests are not run by default. TEST_GEN_PROGS_EXTENDED will be used for Live Update selftests in subsequent commits. These selftests must be run manually because they require the user/runner to perform additional actions, such as kexec, during the test. Signed-off-by: David Matlack <dmatlack@google.com> --- tools/testing/selftests/vfio/Makefile | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/vfio/Makefile b/tools/testing/selftests/vfio/Makefile index 1e50998529fd..f9c040094d4a 100644 --- a/tools/testing/selftests/vfio/Makefile +++ b/tools/testing/selftests/vfio/Makefile @@ -23,12 +23,15 @@ LDFLAGS += -pthread LIBS_O := $(LIBVFIO_O) LIBS_O += $(LIBLIVEUPDATE_O) -$(TEST_GEN_PROGS): %: %.o $(LIBS_O) +$(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): %: %.o $(LIBS_O) $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) $< $(LIBS_O) $(LDLIBS) -o $@ -TEST_GEN_PROGS_O = $(patsubst %, %.o, $(TEST_GEN_PROGS)) -TEST_DEP_FILES := $(patsubst %.o, %.d, $(TEST_GEN_PROGS_O)) +TESTS_O := $(patsubst %, %.o, $(TEST_GEN_PROGS)) +TESTS_O += $(patsubst %, %.o, $(TEST_GEN_PROGS_EXTENDED)) + +TEST_DEP_FILES := $(patsubst %.o, %.d, $(TESTS_O)) TEST_DEP_FILES += $(patsubst %.o, %.d, $(LIBS_O)) -include $(TEST_DEP_FILES) -EXTRA_CLEAN += $(TEST_GEN_PROGS_O) $(TEST_DEP_FILES) +EXTRA_CLEAN += $(TESTS_O) +EXTRA_CLEAN += $(TEST_DEP_FILES) -- 2.53.0.rc1.225.gd81095ad13-goog
{ "author": "David Matlack <dmatlack@google.com>", "date": "Thu, 29 Jan 2026 21:25:02 +0000", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
From: Vipin Sharma <vipinsh@google.com> Use the given VFIO cdev FD to initialize vfio_pci_device in VFIO selftests. Add the assertion to make sure that passed cdev FD is not used with legacy VFIO APIs. If VFIO cdev FD is provided then do not open the device instead use the FD for any interaction with the device. This API will allow to write selftests where VFIO device FD is preserved using liveupdate and retrieved later using liveupdate ioctl after kexec. Signed-off-by: Vipin Sharma <vipinsh@google.com> Co-developed-by: David Matlack <dmatlack@google.com> Signed-off-by: David Matlack <dmatlack@google.com> --- .../lib/include/libvfio/vfio_pci_device.h | 3 ++ .../selftests/vfio/lib/vfio_pci_device.c | 33 ++++++++++++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h b/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h index 2858885a89bb..896dfde88118 100644 --- a/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h +++ b/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h @@ -38,6 +38,9 @@ struct vfio_pci_device { #define dev_info(_dev, _fmt, ...) printf("%s: " _fmt, (_dev)->bdf, ##__VA_ARGS__) #define dev_err(_dev, _fmt, ...) fprintf(stderr, "%s: " _fmt, (_dev)->bdf, ##__VA_ARGS__) +struct vfio_pci_device *__vfio_pci_device_init(const char *bdf, + struct iommu *iommu, + int device_fd); struct vfio_pci_device *vfio_pci_device_init(const char *bdf, struct iommu *iommu); void vfio_pci_device_cleanup(struct vfio_pci_device *device); diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/testing/selftests/vfio/lib/vfio_pci_device.c index fac4c0ecadef..08bb582eaa8f 100644 --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c @@ -318,19 +318,27 @@ static void vfio_device_attach_iommufd_pt(int device_fd, u32 pt_id) ioctl_assert(device_fd, VFIO_DEVICE_ATTACH_IOMMUFD_PT, &args); } -static void vfio_pci_iommufd_setup(struct vfio_pci_device *device, const char *bdf) +static void vfio_pci_iommufd_setup(struct vfio_pci_device *device, + const char *bdf, int device_fd) { - const char *cdev_path = vfio_pci_get_cdev_path(bdf); + const char *cdev_path; - device->fd = open(cdev_path, O_RDWR); - VFIO_ASSERT_GE(device->fd, 0); - free((void *)cdev_path); + if (device_fd >= 0) { + device->fd = device_fd; + } else { + cdev_path = vfio_pci_get_cdev_path(bdf); + device->fd = open(cdev_path, O_RDWR); + VFIO_ASSERT_GE(device->fd, 0); + free((void *)cdev_path); + } vfio_device_bind_iommufd(device->fd, device->iommu->iommufd); vfio_device_attach_iommufd_pt(device->fd, device->iommu->ioas_id); } -struct vfio_pci_device *vfio_pci_device_init(const char *bdf, struct iommu *iommu) +struct vfio_pci_device *__vfio_pci_device_init(const char *bdf, + struct iommu *iommu, + int device_fd) { struct vfio_pci_device *device; @@ -341,10 +349,12 @@ struct vfio_pci_device *vfio_pci_device_init(const char *bdf, struct iommu *iomm device->iommu = iommu; device->bdf = bdf; - if (iommu->mode->container_path) + if (iommu->mode->container_path) { + VFIO_ASSERT_EQ(device_fd, -1); vfio_pci_container_setup(device, bdf); - else - vfio_pci_iommufd_setup(device, bdf); + } else { + vfio_pci_iommufd_setup(device, bdf, device_fd); + } vfio_pci_device_setup(device); vfio_pci_driver_probe(device); @@ -352,6 +362,11 @@ struct vfio_pci_device *vfio_pci_device_init(const char *bdf, struct iommu *iomm return device; } +struct vfio_pci_device *vfio_pci_device_init(const char *bdf, struct iommu *iommu) +{ + return __vfio_pci_device_init(bdf, iommu, /*device_fd=*/-1); +} + void vfio_pci_device_cleanup(struct vfio_pci_device *device) { int i; -- 2.53.0.rc1.225.gd81095ad13-goog
{ "author": "David Matlack <dmatlack@google.com>", "date": "Thu, 29 Jan 2026 21:25:04 +0000", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
Expose the list of iommu_modes to enable tests that want to iterate through all possible iommu modes. Signed-off-by: David Matlack <dmatlack@google.com> --- tools/testing/selftests/vfio/lib/include/libvfio/iommu.h | 2 ++ tools/testing/selftests/vfio/lib/iommu.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/vfio/lib/include/libvfio/iommu.h b/tools/testing/selftests/vfio/lib/include/libvfio/iommu.h index 5c9b9dc6d993..a03ff2281f11 100644 --- a/tools/testing/selftests/vfio/lib/include/libvfio/iommu.h +++ b/tools/testing/selftests/vfio/lib/include/libvfio/iommu.h @@ -15,6 +15,8 @@ struct iommu_mode { unsigned long iommu_type; }; +extern const struct iommu_mode iommu_modes[]; +extern const int nr_iommu_modes; extern const char *default_iommu_mode; struct dma_region { diff --git a/tools/testing/selftests/vfio/lib/iommu.c b/tools/testing/selftests/vfio/lib/iommu.c index 58b7fb7430d4..add35dbc83f8 100644 --- a/tools/testing/selftests/vfio/lib/iommu.c +++ b/tools/testing/selftests/vfio/lib/iommu.c @@ -23,7 +23,7 @@ const char *default_iommu_mode = "iommufd"; /* Reminder: Keep in sync with FIXTURE_VARIANT_ADD_ALL_IOMMU_MODES(). */ -static const struct iommu_mode iommu_modes[] = { +const struct iommu_mode iommu_modes[] = { { .name = "vfio_type1_iommu", .container_path = "/dev/vfio/vfio", @@ -49,6 +49,8 @@ static const struct iommu_mode iommu_modes[] = { }, }; +const int nr_iommu_modes = ARRAY_SIZE(iommu_modes); + static const struct iommu_mode *lookup_iommu_mode(const char *iommu_mode) { int i; -- 2.53.0.rc1.225.gd81095ad13-goog
{ "author": "David Matlack <dmatlack@google.com>", "date": "Thu, 29 Jan 2026 21:25:06 +0000", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
Expose a few low-level helper routings for setting up vfio_pci_device structs. These routines will be used in a subsequent commit to assert that VFIO_GROUP_GET_DEVICE_FD fails under certain conditions. Signed-off-by: David Matlack <dmatlack@google.com> --- .../lib/include/libvfio/vfio_pci_device.h | 5 +++ .../selftests/vfio/lib/vfio_pci_device.c | 33 +++++++++++++------ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h b/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h index 896dfde88118..2389c7698335 100644 --- a/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h +++ b/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h @@ -125,4 +125,9 @@ static inline bool vfio_pci_device_match(struct vfio_pci_device *device, const char *vfio_pci_get_cdev_path(const char *bdf); +/* Low-level routines for setting up a struct vfio_pci_device */ +struct vfio_pci_device *vfio_pci_device_alloc(const char *bdf, struct iommu *iommu); +void vfio_pci_group_setup(struct vfio_pci_device *device); +void vfio_pci_iommu_setup(struct vfio_pci_device *device); + #endif /* SELFTESTS_VFIO_LIB_INCLUDE_LIBVFIO_VFIO_PCI_DEVICE_H */ diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/testing/selftests/vfio/lib/vfio_pci_device.c index 08bb582eaa8f..76597c84e956 100644 --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c @@ -198,7 +198,7 @@ static unsigned int vfio_pci_get_group_from_dev(const char *bdf) return group; } -static void vfio_pci_group_setup(struct vfio_pci_device *device, const char *bdf) +void vfio_pci_group_setup(struct vfio_pci_device *device) { struct vfio_group_status group_status = { .argsz = sizeof(group_status), @@ -206,7 +206,7 @@ static void vfio_pci_group_setup(struct vfio_pci_device *device, const char *bdf char group_path[32]; int group; - group = vfio_pci_get_group_from_dev(bdf); + group = vfio_pci_get_group_from_dev(device->bdf); snprintf(group_path, sizeof(group_path), "/dev/vfio/%d", group); device->group_fd = open(group_path, O_RDWR); @@ -218,14 +218,12 @@ static void vfio_pci_group_setup(struct vfio_pci_device *device, const char *bdf ioctl_assert(device->group_fd, VFIO_GROUP_SET_CONTAINER, &device->iommu->container_fd); } -static void vfio_pci_container_setup(struct vfio_pci_device *device, const char *bdf) +void vfio_pci_iommu_setup(struct vfio_pci_device *device) { struct iommu *iommu = device->iommu; unsigned long iommu_type = iommu->mode->iommu_type; int ret; - vfio_pci_group_setup(device, bdf); - ret = ioctl(iommu->container_fd, VFIO_CHECK_EXTENSION, iommu_type); VFIO_ASSERT_GT(ret, 0, "VFIO IOMMU type %lu not supported\n", iommu_type); @@ -235,8 +233,14 @@ static void vfio_pci_container_setup(struct vfio_pci_device *device, const char * because the IOMMU type is already set. */ (void)ioctl(iommu->container_fd, VFIO_SET_IOMMU, (void *)iommu_type); +} - device->fd = ioctl(device->group_fd, VFIO_GROUP_GET_DEVICE_FD, bdf); +static void vfio_pci_container_setup(struct vfio_pci_device *device) +{ + vfio_pci_group_setup(device); + vfio_pci_iommu_setup(device); + + device->fd = ioctl(device->group_fd, VFIO_GROUP_GET_DEVICE_FD, device->bdf); VFIO_ASSERT_GE(device->fd, 0); } @@ -336,9 +340,7 @@ static void vfio_pci_iommufd_setup(struct vfio_pci_device *device, vfio_device_attach_iommufd_pt(device->fd, device->iommu->ioas_id); } -struct vfio_pci_device *__vfio_pci_device_init(const char *bdf, - struct iommu *iommu, - int device_fd) +struct vfio_pci_device *vfio_pci_device_alloc(const char *bdf, struct iommu *iommu) { struct vfio_pci_device *device; @@ -349,9 +351,20 @@ struct vfio_pci_device *__vfio_pci_device_init(const char *bdf, device->iommu = iommu; device->bdf = bdf; + return device; +} + +struct vfio_pci_device *__vfio_pci_device_init(const char *bdf, + struct iommu *iommu, + int device_fd) +{ + struct vfio_pci_device *device; + + device = vfio_pci_device_alloc(bdf, iommu); + if (iommu->mode->container_path) { VFIO_ASSERT_EQ(device_fd, -1); - vfio_pci_container_setup(device, bdf); + vfio_pci_container_setup(device); } else { vfio_pci_iommufd_setup(device, bdf, device_fd); } -- 2.53.0.rc1.225.gd81095ad13-goog
{ "author": "David Matlack <dmatlack@google.com>", "date": "Thu, 29 Jan 2026 21:25:07 +0000", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
Verify that opening a VFIO device through its cdev file and via VFIO_GROUP_GET_DEVICE_FD both fail with -EBUSY if the device was preserved across a Live Update. When a device file is preserve across a Live Update, the file must be retrieved from /dev/liveupdate, not from VFIO directly. Signed-off-by: David Matlack <dmatlack@google.com> --- .../vfio/vfio_pci_liveupdate_kexec_test.c | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c b/tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c index 15b3e3af91d1..65c48196e44e 100644 --- a/tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c +++ b/tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c @@ -36,6 +36,42 @@ static void before_kexec(int luo_fd) daemonize_and_wait(); } +static void check_open_vfio_device_fails(void) +{ + const char *cdev_path = vfio_pci_get_cdev_path(device_bdf); + struct vfio_pci_device *device; + struct iommu *iommu; + int ret, i; + + printf("Checking open(%s) fails\n", cdev_path); + ret = open(cdev_path, O_RDWR); + VFIO_ASSERT_EQ(ret, -1); + VFIO_ASSERT_EQ(errno, EBUSY); + free((void *)cdev_path); + + for (i = 0; i < nr_iommu_modes; i++) { + if (!iommu_modes[i].container_path) + continue; + + iommu = iommu_init(iommu_modes[i].name); + + device = vfio_pci_device_alloc(device_bdf, iommu); + vfio_pci_group_setup(device); + vfio_pci_iommu_setup(device); + + printf("Checking ioctl(group_fd, VFIO_GROUP_GET_DEVICE_FD, \"%s\") fails (%s)\n", + device_bdf, iommu_modes[i].name); + + ret = ioctl(device->group_fd, VFIO_GROUP_GET_DEVICE_FD, device->bdf); + VFIO_ASSERT_EQ(ret, -1); + VFIO_ASSERT_EQ(errno, EBUSY); + + close(device->group_fd); + free(device); + iommu_cleanup(iommu); + } +} + static void after_kexec(int luo_fd, int state_session_fd) { struct vfio_pci_device *device; @@ -44,6 +80,8 @@ static void after_kexec(int luo_fd, int state_session_fd) int device_fd; int stage; + check_open_vfio_device_fails(); + restore_and_read_stage(state_session_fd, STATE_TOKEN, &stage); VFIO_ASSERT_EQ(stage, 2); -- 2.53.0.rc1.225.gd81095ad13-goog
{ "author": "David Matlack <dmatlack@google.com>", "date": "Thu, 29 Jan 2026 21:25:08 +0000", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
Add a long-running DMA memcpy operation to vfio_pci_liveupdate_kexec_test so that the device attempts to perform DMAs continuously during the Live Update. At this point iommufd preservation is not supported and bus mastering is not kept enabled on the device during across the kexec, so most of these DMAs will be dropped. However this test ensures that the current device preservation support does not lead to system instability or crashes if the device is active. And once iommufd and bus mastering are preserved, this test can be relaxed to check that the DMA operations completed successfully. Signed-off-by: David Matlack <dmatlack@google.com> --- .../vfio/vfio_pci_liveupdate_kexec_test.c | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c b/tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c index 65c48196e44e..36bddfbb88ed 100644 --- a/tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c +++ b/tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c @@ -1,8 +1,16 @@ // SPDX-License-Identifier: GPL-2.0-only +#include <linux/sizes.h> +#include <sys/mman.h> + #include <libliveupdate.h> #include <libvfio.h> +#define MEMCPY_SIZE SZ_1G +#define DRIVER_SIZE SZ_1M +#define MEMFD_SIZE (MEMCPY_SIZE + DRIVER_SIZE) + +static struct dma_region memcpy_region; static const char *device_bdf; static char state_session[LIVEUPDATE_SESSION_NAME_LENGTH]; @@ -11,8 +19,89 @@ static char device_session[LIVEUPDATE_SESSION_NAME_LENGTH]; enum { STATE_TOKEN, DEVICE_TOKEN, + MEMFD_TOKEN, }; +static void dma_memcpy_one(struct vfio_pci_device *device) +{ + void *src = memcpy_region.vaddr, *dst; + u64 size; + + size = min_t(u64, memcpy_region.size / 2, device->driver.max_memcpy_size); + dst = src + size; + + memset(src, 1, size); + memset(dst, 0, size); + + printf("Kicking off 1 DMA memcpy operations of size 0x%lx...\n", size); + vfio_pci_driver_memcpy(device, + to_iova(device, src), + to_iova(device, dst), + size); + + VFIO_ASSERT_EQ(memcmp(src, dst, size), 0); +} + +static void dma_memcpy_start(struct vfio_pci_device *device) +{ + void *src = memcpy_region.vaddr, *dst; + u64 count, size; + + size = min_t(u64, memcpy_region.size / 2, device->driver.max_memcpy_size); + dst = src + size; + + /* + * Rough Math: If we assume the device will perform memcpy at a rate of + * 30GB/s then 7200GB of transfers will run for about 4 minutes. + */ + count = (u64)7200 * SZ_1G / size; + count = min_t(u64, count, device->driver.max_memcpy_count); + + memset(src, 1, size / 2); + memset(dst, 0, size / 2); + + printf("Kicking off %lu DMA memcpy operations of size 0x%lx...\n", count, size); + vfio_pci_driver_memcpy_start(device, + to_iova(device, src), + to_iova(device, dst), + size, count); +} + +static void dma_memfd_map(struct vfio_pci_device *device, int fd) +{ + void *vaddr; + + vaddr = mmap(NULL, MEMFD_SIZE, PROT_WRITE, MAP_SHARED, fd, 0); + VFIO_ASSERT_NE(vaddr, MAP_FAILED); + + memcpy_region.iova = SZ_4G; + memcpy_region.size = MEMCPY_SIZE; + memcpy_region.vaddr = vaddr; + iommu_map(device->iommu, &memcpy_region); + + device->driver.region.iova = memcpy_region.iova + memcpy_region.size; + device->driver.region.size = DRIVER_SIZE; + device->driver.region.vaddr = vaddr + memcpy_region.size; + iommu_map(device->iommu, &device->driver.region); +} + +static void dma_memfd_setup(struct vfio_pci_device *device, int session_fd) +{ + int fd, ret; + + fd = memfd_create("dma-buffer", 0); + VFIO_ASSERT_GE(fd, 0); + + ret = fallocate(fd, 0, 0, MEMFD_SIZE); + VFIO_ASSERT_EQ(ret, 0); + + printf("Preserving memfd of size 0x%x in session\n", MEMFD_SIZE); + ret = luo_session_preserve_fd(session_fd, fd, MEMFD_TOKEN); + VFIO_ASSERT_EQ(ret, 0); + + dma_memfd_map(device, fd); +} + static void before_kexec(int luo_fd) { struct vfio_pci_device *device; @@ -32,6 +121,27 @@ static void before_kexec(int luo_fd) ret = luo_session_preserve_fd(session_fd, device->fd, DEVICE_TOKEN); VFIO_ASSERT_EQ(ret, 0); + dma_memfd_setup(device, session_fd); + + /* + * If the device has a selftests driver, kick off a long-running DMA + * operation to exercise the device trying to DMA during a Live Update. + * Since iommufd preservation is not supported yet, these DMAs should be + * dropped. So this is just looking to verify that the system does not + * fall over and crash as a result of a busy device being preserved. + */ + if (device->driver.ops) { + vfio_pci_driver_init(device); + dma_memcpy_start(device); + + /* + * Disable interrupts on the device or freeze() will fail. + * Unfortunately there isn't a way to easily have a test for + * that here since the check happens during shutdown. + */ + vfio_pci_msix_disable(device); + } + close(luo_fd); daemonize_and_wait(); } @@ -78,6 +188,7 @@ static void after_kexec(int luo_fd, int state_session_fd) struct iommu *iommu; int session_fd; int device_fd; + int memfd; int stage; check_open_vfio_device_fails(); @@ -88,6 +199,10 @@ static void after_kexec(int luo_fd, int state_session_fd) session_fd = luo_retrieve_session(luo_fd, device_session); VFIO_ASSERT_GE(session_fd, 0); + printf("Retrieving memfd from LUO\n"); + memfd = luo_session_retrieve_fd(session_fd, MEMFD_TOKEN); + VFIO_ASSERT_GE(memfd, 0); + printf("Finishing the session before retrieving the device (should fail)\n"); VFIO_ASSERT_NE(luo_session_finish(session_fd), 0); @@ -109,9 +224,23 @@ static void after_kexec(int luo_fd, int state_session_fd) */ device = __vfio_pci_device_init(device_bdf, iommu, device_fd); + dma_memfd_map(device, memfd); + printf("Finishing the session\n"); VFIO_ASSERT_EQ(luo_session_finish(session_fd), 0); + /* + * Once iommufd preservation is supported and the device is kept fully + * running across the Live Update, this should wait for the long- + * running DMA memcpy operation kicked off in before_kexec() to + * complete. But for now we expect the device to be reset so just + * trigger a single memcpy to make sure it's still functional. + */ + if (device->driver.ops) { + vfio_pci_driver_init(device); + dma_memcpy_one(device); + } + vfio_pci_device_cleanup(device); iommu_cleanup(iommu); } -- 2.53.0.rc1.225.gd81095ad13-goog
{ "author": "David Matlack <dmatlack@google.com>", "date": "Thu, 29 Jan 2026 21:25:09 +0000", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
From: Vipin Sharma <vipinsh@google.com> Add a selftest to exercise preserving a vfio-pci device across a Live Update. For now the test is extremely simple and just verifies that the device file can be preserved and retrieved. In the future this test will be extended to verify more parts about device preservation as they are implemented. This test is added to TEST_GEN_PROGS_EXTENDED since it must be run manually along with a kexec. To run this test manually: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... # NOTE: Exact method will be distro-dependent $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 The second call to setup.sh is necessary because preserved devices are not bound to a driver after Live Update. Such devices must be manually bound by userspace after Live Update via driver_override. This test is considered passing if all commands exit with 0. Signed-off-by: Vipin Sharma <vipinsh@google.com> Co-developed-by: David Matlack <dmatlack@google.com> Signed-off-by: David Matlack <dmatlack@google.com> --- tools/testing/selftests/vfio/Makefile | 4 + .../vfio/vfio_pci_liveupdate_kexec_test.c | 89 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c diff --git a/tools/testing/selftests/vfio/Makefile b/tools/testing/selftests/vfio/Makefile index 666310872217..55d685f6e540 100644 --- a/tools/testing/selftests/vfio/Makefile +++ b/tools/testing/selftests/vfio/Makefile @@ -6,6 +6,10 @@ TEST_GEN_PROGS += vfio_pci_device_init_perf_test TEST_GEN_PROGS += vfio_pci_driver_test TEST_GEN_PROGS += vfio_pci_liveupdate_uapi_test +# This test must be run manually since it requires the user/automation to +# perform a kexec during the test. +TEST_GEN_PROGS_EXTENDED += vfio_pci_liveupdate_kexec_test + TEST_FILES += scripts/cleanup.sh TEST_FILES += scripts/lib.sh TEST_FILES += scripts/run.sh diff --git a/tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c b/tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c new file mode 100644 index 000000000000..15b3e3af91d1 --- /dev/null +++ b/tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include <libliveupdate.h> +#include <libvfio.h> + +static const char *device_bdf; + +static char state_session[LIVEUPDATE_SESSION_NAME_LENGTH]; +static char device_session[LIVEUPDATE_SESSION_NAME_LENGTH]; + +enum { + STATE_TOKEN, + DEVICE_TOKEN, +}; + +static void before_kexec(int luo_fd) +{ + struct vfio_pci_device *device; + struct iommu *iommu; + int session_fd; + int ret; + + iommu = iommu_init("iommufd"); + device = vfio_pci_device_init(device_bdf, iommu); + + create_state_file(luo_fd, state_session, STATE_TOKEN, /*next_stage=*/2); + + session_fd = luo_create_session(luo_fd, device_session); + VFIO_ASSERT_GE(session_fd, 0); + + printf("Preserving device in session\n"); + ret = luo_session_preserve_fd(session_fd, device->fd, DEVICE_TOKEN); + VFIO_ASSERT_EQ(ret, 0); + + close(luo_fd); + daemonize_and_wait(); +} + +static void after_kexec(int luo_fd, int state_session_fd) +{ + struct vfio_pci_device *device; + struct iommu *iommu; + int session_fd; + int device_fd; + int stage; + + restore_and_read_stage(state_session_fd, STATE_TOKEN, &stage); + VFIO_ASSERT_EQ(stage, 2); + + session_fd = luo_retrieve_session(luo_fd, device_session); + VFIO_ASSERT_GE(session_fd, 0); + + printf("Finishing the session before retrieving the device (should fail)\n"); + VFIO_ASSERT_NE(luo_session_finish(session_fd), 0); + + printf("Retrieving the device FD from LUO\n"); + device_fd = luo_session_retrieve_fd(session_fd, DEVICE_TOKEN); + VFIO_ASSERT_GE(device_fd, 0); + + printf("Finishing the session before binding to iommufd (should fail)\n"); + VFIO_ASSERT_NE(luo_session_finish(session_fd), 0); + + printf("Binding the device to an iommufd and setting it up\n"); + iommu = iommu_init("iommufd"); + + /* + * This will invoke various ioctls on device_fd such as + * VFIO_DEVICE_GET_INFO. So this is a decent sanity test + * that LUO actually handed us back a valid VFIO device + * file and not something else. + */ + device = __vfio_pci_device_init(device_bdf, iommu, device_fd); + + printf("Finishing the session\n"); + VFIO_ASSERT_EQ(luo_session_finish(session_fd), 0); + + vfio_pci_device_cleanup(device); + iommu_cleanup(iommu); +} + +int main(int argc, char *argv[]) +{ + device_bdf = vfio_selftests_get_bdf(&argc, argv); + + sprintf(device_session, "device-%s", device_bdf); + sprintf(state_session, "state-%s", device_bdf); + + return luo_test(argc, argv, state_session, before_kexec, after_kexec); +} -- 2.53.0.rc1.225.gd81095ad13-goog
{ "author": "David Matlack <dmatlack@google.com>", "date": "Thu, 29 Jan 2026 21:25:05 +0000", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
Hi David, On Thu, 29 Jan 2026 21:24:57 +0000 David Matlack <dmatlack@google.com> wrote: Just wondering what happened to skipping the bus master clearing. I understand this version does not preserve the device itself yet; I’m just curious whether there were specific difficulties that led to dropping the earlier patch which skipped clearing bus master.
{ "author": "Jacob Pan <jacob.pan@linux.microsoft.com>", "date": "Thu, 29 Jan 2026 14:21:58 -0800", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
On 2026-01-29 02:21 PM, Jacob Pan wrote: Hi Jacob, There's several places where bus master gets cleared that we need to eventually eliminate to fully preserve the device. 1. vfio_pci_liveupdate_freeze() clears it during shutdown when it restores vdev->pci_saved_state. 2. pci_device_shutdown() clears it during shutdown. 3. vfio_pci_core_enable() clears it when the preserved device file is bound to an iommufd after the Live Update (in vfio_pci_core_enable()). I think it would be safe to skip (3) in this series, since that's very similar to how this series skips resets during vfio_pci_core_enable() for preserved devices. But I don't think it would be safe to skip (1) or (2) until the attached iommufd is fully preserved. If you are just asking about (3) then I agree it could be skipped and I can include that in the next version.
{ "author": "David Matlack <dmatlack@google.com>", "date": "Thu, 29 Jan 2026 22:33:13 +0000", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
Hi David, On Thu, 29 Jan 2026 22:33:13 +0000 David Matlack <dmatlack@google.com> wrote: I was just asking about (3) and trying to understand the asymmetric handling compared to reset. I don’t have a strong preference since this is temporary—thanks for the explanation. I’ve been testing my noiommu cdev patches on top of yours, and so far they behave the same as with a real IOMMU. As you noted, however, final device preservation still depends on iommufd.
{ "author": "Jacob Pan <jacob.pan@linux.microsoft.com>", "date": "Thu, 29 Jan 2026 16:31:50 -0800", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
在 2026/1/29 13:24, David Matlack 写道: Can the above 2 functions support the virtual devices? For example, bonding, veth, iSWAP and RXE. These virtual devices do not have BDF. As such, I am not sure if your patches take these virtual devices in to account. Thanks a lot. Zhu Yanjun -- Best Regards, Yanjun.Zhu
{ "author": "Zhu Yanjun <yanjun.zhu@linux.dev>", "date": "Sat, 31 Jan 2026 22:38:18 -0800", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 00/22] vfio/pci: Base Live Update support for VFIO device files
This series can be found on GitHub: https://github.com/dmatlack/linux/tree/liveupdate/vfio/cdev/v2 This series adds the base support to preserve a VFIO device file across a Live Update. "Base support" means that this allows userspace to safely preserve a VFIO device file with LIVEUPDATE_SESSION_PRESERVE_FD and retrieve it with LIVEUPDATE_SESSION_RETRIEVE_FD, but the device itself is not preserved in a fully running state across Live Update. This series aims to provide a foundation on which to build the rest of the device preservation infrastructure, including: - Preservation of iommufd files [1] - Preservation of IOMMU driver state - Preservation of PCI state (BAR resources, device state, bridge state, ...) - Preservation of vfio-pci driver state Testing ------- The patches at the end of this series provide comprehensive selftests for the new code added by this series. The selftests have been validated in both a VM environment using a virtio-net PCIe device, and in a baremetal environment on an Intel EMR server with an Intel DSA PCIe device. Here is an example of how to run the new selftests: vfio_pci_liveupdate_uapi_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh vfio_pci_liveupdate_kexec_test: $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 1 0000:00:04.0 $ kexec ... $ tools/testing/selftests/vfio/scripts/setup.sh 0000:00:04.0 $ tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test --stage 2 0000:00:04.0 $ tools/testing/selftests/vfio/scripts/cleanup.sh It is also possible to run vfio_pci_liveupdate_kexec_test multiple times to preserve multiple devices simultaneously across a Live Update. This series has been tested with up to 8 devices concurrently preserved. Changelog --------- v2: - Rebase on top of linux-next (tag: next-20260115) - Add missing EXPORT_SYMBOL_GPLs in LUO (Zhu) - Add Missing EXPORT_SYMBOL_GPLs for vfio_device_fops (Zhu) - Fix circular dependency between vfio-pci-core and vfio-pci (Zhu) - Handle pci=assign-busses (Lukas) - Drop driver_override patch (Jason) - Use kho_alloc_preserve(), kho_unpreserve_free(), kho_restore_free() (Pasha) - Don't access PCI FLB after device initialization (Jason) - Fix folio leak in vfio_pci_liveupdate_retrieve() (Alex) - Add Documentation (Pasha) v1: https://lore.kernel.org/kvm/20251126193608.2678510-1-dmatlack@google.com/ rfc: https://lore.kernel.org/kvm/20251018000713.677779-1-vipinsh@google.com/ Cc: Saeed Mahameed <saeedm@nvidia.com> Cc: Adithya Jayachandran <ajayachandra@nvidia.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Leon Romanovsky <leonro@nvidia.com> Cc: William Tu <witu@nvidia.com> Cc: Jacob Pan <jacob.pan@linux.microsoft.com> Cc: Lukas Wunner <lukas@wunner.de> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pratyush Yadav <pratyush@kernel.org> Cc: Samiullah Khawaja <skhawaja@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Josh Hilke <jrhilke@google.com> Cc: David Rientjes <rientjes@google.com> [1] https://lore.kernel.org/linux-iommu/20251202230303.1017519-1-skhawaja@google.com/ David Matlack (13): liveupdate: Export symbols needed by modules PCI: Add API to track PCI devices preserved across Live Update PCI: Inherit bus numbers from previous kernel during Live Update vfio/pci: Notify PCI subsystem about devices preserved across Live Update vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device docs: liveupdate: Document VFIO device file preservation vfio: selftests: Add Makefile support for TEST_GEN_PROGS_EXTENDED vfio: selftests: Add vfio_pci_liveupdate_uapi_test vfio: selftests: Expose iommu_modes to tests vfio: selftests: Expose low-level helper routines for setting up struct vfio_pci_device vfio: selftests: Verify that opening VFIO device fails during Live Update vfio: selftests: Add continuous DMA to vfio_pci_liveupdate_kexec_test Vipin Sharma (9): vfio/pci: Register a file handler with Live Update Orchestrator vfio/pci: Preserve vfio-pci device files across Live Update vfio/pci: Retrieve preserved device files after Live Update vfio/pci: Skip reset of preserved device after Live Update selftests/liveupdate: Move luo_test_utils.* into a reusable library selftests/liveupdate: Add helpers to preserve/retrieve FDs vfio: selftests: Build liveupdate library in VFIO selftests vfio: selftests: Initialize vfio_pci_device using a VFIO cdev FD vfio: selftests: Add vfio_pci_liveupdate_kexec_test Documentation/userspace-api/liveupdate.rst | 144 ++++++++++ MAINTAINERS | 1 + drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 212 +++++++++++++++ drivers/pci/probe.c | 23 +- drivers/vfio/device_cdev.c | 25 +- drivers/vfio/group.c | 9 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +- drivers/vfio/pci/vfio_pci_core.c | 24 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 246 +++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 16 ++ drivers/vfio/vfio.h | 13 - drivers/vfio/vfio_main.c | 23 +- include/linux/kho/abi/pci.h | 55 ++++ include/linux/kho/abi/vfio_pci.h | 45 +++ include/linux/pci.h | 47 ++++ include/linux/vfio.h | 58 ++++ include/linux/vfio_pci_core.h | 2 + kernel/liveupdate/luo_core.c | 1 + kernel/liveupdate/luo_file.c | 2 + tools/testing/selftests/liveupdate/.gitignore | 1 + tools/testing/selftests/liveupdate/Makefile | 14 +- .../include/libliveupdate.h} | 11 +- .../selftests/liveupdate/lib/libliveupdate.mk | 20 ++ .../{luo_test_utils.c => lib/liveupdate.c} | 43 ++- .../selftests/liveupdate/luo_kexec_simple.c | 2 +- .../selftests/liveupdate/luo_multi_session.c | 2 +- tools/testing/selftests/vfio/Makefile | 23 +- .../vfio/lib/include/libvfio/iommu.h | 2 + .../lib/include/libvfio/vfio_pci_device.h | 8 + tools/testing/selftests/vfio/lib/iommu.c | 4 +- .../selftests/vfio/lib/vfio_pci_device.c | 60 ++-- .../vfio/vfio_pci_liveupdate_kexec_test.c | 256 ++++++++++++++++++ .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++ 35 files changed, 1410 insertions(+), 88 deletions(-) create mode 100644 drivers/pci/liveupdate.c create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/kho/abi/vfio_pci.h rename tools/testing/selftests/liveupdate/{luo_test_utils.h => lib/include/libliveupdate.h} (80%) create mode 100644 tools/testing/selftests/liveupdate/lib/libliveupdate.mk rename tools/testing/selftests/liveupdate/{luo_test_utils.c => lib/liveupdate.c} (89%) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c base-commit: 9b7977f9e39b7768c70c2aa497f04e7569fd3e00 -- 2.53.0.rc1.225.gd81095ad13-goog
On Sat, Jan 31, 2026 at 10:38 PM Zhu Yanjun <yanjun.zhu@linux.dev> wrote: No this patch series only supports PCI devices, since those are the only devices so far we've needed to support. I am not familiar with any of the devices that you mentioned. If they are virtual then does that mean it's all just software? In that case I would be curious to know what problem is solved by preserving them in the kernel, vs. tearing them down and rebuilding them across a Live Udpate.
{ "author": "David Matlack <dmatlack@google.com>", "date": "Mon, 2 Feb 2026 10:14:56 -0800", "thread_id": "CALzav=d1ZrHrWd-HhZJ8aY6aqxkBcLoet_5+-LL1mOakVTj6Ww@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2 2/6] hrtimer: Optimize __hrtimer_start_range_ns()
Much like hrtimer_reprogram(), skip programming if the cpu_base is running the hrtimer interrupt. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- kernel/time/hrtimer.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1261,6 +1261,14 @@ static int __hrtimer_start_range_ns(stru } first = enqueue_hrtimer(timer, new_base, mode); + + /* + * If the hrtimer interrupt is running, then it will reevaluate the + * clock bases and reprogram the clock event device. + */ + if (new_base->cpu_base->in_hrtirq) + return 0; + if (!force_local) { /* * If the current CPU base is online, then the timer is
Currently hrtimer_interrupt() runs expired timers, which can re-arm themselves, after which it computes the next expiration time and re-programs the hardware. However, things like HRTICK, a highres timer driving preemption, cannot re-arm itself at the point of running, since the next task has not been determined yet. The schedule() in the interrupt return path will switch to the next task, which then causes a new hrtimer to be programmed. This then results in reprogramming the hardware at least twice, once after running the timers, and once upon selecting the new task. Notably, *both* events happen in the interrupt. By pushing the hrtimer reprogram all the way into the interrupt return path, it runs after schedule() and this double reprogram can be avoided. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- include/asm-generic/thread_info_tif.h | 5 ++++- include/linux/hrtimer.h | 17 +++++++++++++++++ include/linux/irq-entry-common.h | 2 ++ kernel/entry/common.c | 13 +++++++++++++ kernel/sched/core.c | 10 ++++++++++ kernel/time/hrtimer.c | 28 ++++++++++++++++++++++++---- 6 files changed, 70 insertions(+), 5 deletions(-) --- a/include/asm-generic/thread_info_tif.h +++ b/include/asm-generic/thread_info_tif.h @@ -41,11 +41,14 @@ #define _TIF_PATCH_PENDING BIT(TIF_PATCH_PENDING) #ifdef HAVE_TIF_RESTORE_SIGMASK -# define TIF_RESTORE_SIGMASK 10 // Restore signal mask in do_signal() */ +# define TIF_RESTORE_SIGMASK 10 // Restore signal mask in do_signal() # define _TIF_RESTORE_SIGMASK BIT(TIF_RESTORE_SIGMASK) #endif #define TIF_RSEQ 11 // Run RSEQ fast path #define _TIF_RSEQ BIT(TIF_RSEQ) +#define TIF_HRTIMER_REARM 12 // re-arm the timer +#define _TIF_HRTIMER_REARM BIT(TIF_HRTIMER_REARM) + #endif /* _ASM_GENERIC_THREAD_INFO_TIF_H_ */ --- a/include/linux/hrtimer.h +++ b/include/linux/hrtimer.h @@ -175,10 +175,27 @@ extern void hrtimer_interrupt(struct clo extern unsigned int hrtimer_resolution; +#ifdef TIF_HRTIMER_REARM +extern void _hrtimer_rearm(void); +/* + * This is to be called on all irqentry_exit() paths that will enable + * interrupts; as well as in the context switch path before switch_to(). + */ +static inline void hrtimer_rearm(void) +{ + if (test_thread_flag(TIF_HRTIMER_REARM)) + _hrtimer_rearm(); +} +#else +static inline void hrtimer_rearm(void) { } +#endif /* TIF_HRTIMER_REARM */ + #else #define hrtimer_resolution (unsigned int)LOW_RES_NSEC +static inline void hrtimer_rearm(void) { } + #endif static inline ktime_t --- a/include/linux/irq-entry-common.h +++ b/include/linux/irq-entry-common.h @@ -224,6 +224,8 @@ static __always_inline void __exit_to_us ti_work = read_thread_flags(); if (unlikely(ti_work & EXIT_TO_USER_MODE_WORK)) ti_work = exit_to_user_mode_loop(regs, ti_work); + else + hrtimer_rearm(); arch_exit_to_user_mode_prepare(regs, ti_work); } --- a/kernel/entry/common.c +++ b/kernel/entry/common.c @@ -7,6 +7,7 @@ #include <linux/kmsan.h> #include <linux/livepatch.h> #include <linux/tick.h> +#include <linux/hrtimer.h> /* Workaround to allow gradual conversion of architecture code */ void __weak arch_do_signal_or_restart(struct pt_regs *regs) { } @@ -26,6 +27,16 @@ static __always_inline unsigned long __e */ while (ti_work & EXIT_TO_USER_MODE_WORK_LOOP) { + /* + * If hrtimer need re-arming, do so before enabling IRQs, + * except when a reschedule is needed, in that case schedule() + * will do this. + */ + if ((ti_work & (_TIF_NEED_RESCHED | + _TIF_NEED_RESCHED_LAZY | + _TIF_HRTIMER_REARM)) == _TIF_HRTIMER_REARM) + hrtimer_rearm(); + local_irq_enable_exit_to_user(ti_work); if (ti_work & (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY)) @@ -202,6 +213,7 @@ noinstr void irqentry_exit(struct pt_reg */ if (state.exit_rcu) { instrumentation_begin(); + hrtimer_rearm(); /* Tell the tracer that IRET will enable interrupts */ trace_hardirqs_on_prepare(); lockdep_hardirqs_on_prepare(); @@ -215,6 +227,7 @@ noinstr void irqentry_exit(struct pt_reg if (IS_ENABLED(CONFIG_PREEMPTION)) irqentry_exit_cond_resched(); + hrtimer_rearm(); /* Covers both tracing and lockdep */ trace_hardirqs_on(); instrumentation_end(); --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6814,6 +6814,16 @@ static void __sched notrace __schedule(i keep_resched: rq->last_seen_need_resched_ns = 0; + /* + * Notably, this must be called after pick_next_task() but before + * switch_to(), since the new task need not be on the return from + * interrupt path. Additionally, exit_to_user_mode_loop() relies on + * any schedule() call to imply this call, so do it unconditionally. + * + * We've just cleared TIF_NEED_RESCHED, TIF word should be in cache. + */ + hrtimer_rearm(); + is_switch = prev != next; if (likely(is_switch)) { rq->nr_switches++; --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1892,10 +1892,9 @@ static __latent_entropy void hrtimer_run * Very similar to hrtimer_force_reprogram(), except it deals with * in_hrirq and hang_detected. */ -static void __hrtimer_rearm(struct hrtimer_cpu_base *cpu_base, ktime_t now) +static void __hrtimer_rearm(struct hrtimer_cpu_base *cpu_base, + ktime_t now, ktime_t expires_next) { - ktime_t expires_next = hrtimer_update_next_event(cpu_base); - cpu_base->expires_next = expires_next; cpu_base->in_hrtirq = 0; @@ -1970,9 +1969,30 @@ void hrtimer_interrupt(struct clock_even cpu_base->hang_detected = 1; } - __hrtimer_rearm(cpu_base, now); +#ifdef TIF_HRTIMER_REARM + set_thread_flag(TIF_HRTIMER_REARM); +#else + __hrtimer_rearm(cpu_base, now, expires_next); +#endif raw_spin_unlock_irqrestore(&cpu_base->lock, flags); } + +#ifdef TIF_HRTIMER_REARM +void _hrtimer_rearm(void) +{ + struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases); + ktime_t now, expires_next; + + lockdep_assert_irqs_disabled(); + + scoped_guard (raw_spinlock, &cpu_base->lock) { + now = hrtimer_update_base(cpu_base); + expires_next = hrtimer_update_next_event(cpu_base); + __hrtimer_rearm(cpu_base, now, expires_next); + clear_thread_flag(TIF_HRTIMER_REARM); + } +} +#endif /* TIF_HRTIMER_REARM */ #endif /* !CONFIG_HIGH_RES_TIMERS */ /*
{ "author": "Peter Zijlstra <peterz@infradead.org>", "date": "Wed, 21 Jan 2026 17:20:15 +0100", "thread_id": "20260121162010.647043073@infradead.org.mbox.gz" }
lkml
[PATCH v2 2/6] hrtimer: Optimize __hrtimer_start_range_ns()
Much like hrtimer_reprogram(), skip programming if the cpu_base is running the hrtimer interrupt. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- kernel/time/hrtimer.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1261,6 +1261,14 @@ static int __hrtimer_start_range_ns(stru } first = enqueue_hrtimer(timer, new_base, mode); + + /* + * If the hrtimer interrupt is running, then it will reevaluate the + * clock bases and reprogram the clock event device. + */ + if (new_base->cpu_base->in_hrtirq) + return 0; + if (!force_local) { /* * If the current CPU base is online, then the timer is
Hi! At long last a new version of the hrtick rework! The previous version had a mysterious deadlock which has been resolved. So far (weeks) the 0-day robot has not found more issues with these patches. These patches aim to reduce the hrtick overhead to such an extent that it can be default enabled. Decoupling the preemption behaviour from CONFIG_HZ, leaving only load-balancing and time keeping dependent on HZ. Some (limited) performance runs from 0-day have also not found any regressions from enabling HRTICK, but it has not run the full suite yet (AFAIU). Patches also at: git://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git sched/hrtick
{ "author": "Peter Zijlstra <peterz@infradead.org>", "date": "Wed, 21 Jan 2026 17:20:10 +0100", "thread_id": "20260121162010.647043073@infradead.org.mbox.gz" }
lkml
[PATCH v2 2/6] hrtimer: Optimize __hrtimer_start_range_ns()
Much like hrtimer_reprogram(), skip programming if the cpu_base is running the hrtimer interrupt. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- kernel/time/hrtimer.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1261,6 +1261,14 @@ static int __hrtimer_start_range_ns(stru } first = enqueue_hrtimer(timer, new_base, mode); + + /* + * If the hrtimer interrupt is running, then it will reevaluate the + * clock bases and reprogram the clock event device. + */ + if (new_base->cpu_base->in_hrtirq) + return 0; + if (!force_local) { /* * If the current CPU base is online, then the timer is
Upon schedule() HRTICK will cancel the current timer, pick the next task and reprogram the timer. When schedule() consistently triggers due to blocking conditions instead of the timer, this leads to endless reprogramming without ever firing. Mitigate this with a new hrtimer mode: fuzzy (not really happy with that name); this mode does two things: - skip reprogramming the hardware on timer remove; - skip reprogramming the hardware when the new timer is after cpu_base->expires_next Both things are already possible; - removing a remote timer will leave the hardware programmed and cause a spurious interrupt. - this remote CPU adding a timer can skip the reprogramming when the timer's expiration is after the (spurious) expiration. This new timer mode simply causes more of this 'fuzzy' behaviour; it causes a few spurious interrupts, but similarly avoids endlessly reprogramming the timer. This makes the HRTICK match the NO_HRTICK hackbench runs -- the case where a task never runs until its slice is complete but always goes sleep early. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- include/linux/hrtimer.h | 1 + include/linux/hrtimer_types.h | 1 + kernel/sched/core.c | 3 ++- kernel/time/hrtimer.c | 16 +++++++++++++++- 4 files changed, 19 insertions(+), 2 deletions(-) --- a/include/linux/hrtimer.h +++ b/include/linux/hrtimer.h @@ -38,6 +38,7 @@ enum hrtimer_mode { HRTIMER_MODE_PINNED = 0x02, HRTIMER_MODE_SOFT = 0x04, HRTIMER_MODE_HARD = 0x08, + HRTIMER_MODE_FUZZY = 0x10, HRTIMER_MODE_ABS_PINNED = HRTIMER_MODE_ABS | HRTIMER_MODE_PINNED, HRTIMER_MODE_REL_PINNED = HRTIMER_MODE_REL | HRTIMER_MODE_PINNED, --- a/include/linux/hrtimer_types.h +++ b/include/linux/hrtimer_types.h @@ -45,6 +45,7 @@ struct hrtimer { u8 is_rel; u8 is_soft; u8 is_hard; + u8 is_fuzzy; }; #endif /* _LINUX_HRTIMER_TYPES_H */ --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -928,7 +928,8 @@ void hrtick_start(struct rq *rq, u64 del static void hrtick_rq_init(struct rq *rq) { INIT_CSD(&rq->hrtick_csd, __hrtick_start, rq); - hrtimer_setup(&rq->hrtick_timer, hrtick, CLOCK_MONOTONIC, HRTIMER_MODE_REL_HARD); + hrtimer_setup(&rq->hrtick_timer, hrtick, CLOCK_MONOTONIC, + HRTIMER_MODE_REL_HARD | HRTIMER_MODE_FUZZY); } #else /* !CONFIG_SCHED_HRTICK: */ static inline void hrtick_clear(struct rq *rq) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1122,7 +1122,7 @@ static void __remove_hrtimer(struct hrti * an superfluous call to hrtimer_force_reprogram() on the * remote cpu later on if the same timer gets enqueued again. */ - if (reprogram && timer == cpu_base->next_timer) + if (!timer->is_fuzzy && reprogram && timer == cpu_base->next_timer) hrtimer_force_reprogram(cpu_base, 1); } @@ -1269,6 +1269,19 @@ static int __hrtimer_start_range_ns(stru if (new_base->cpu_base->in_hrtirq) return 0; + if (timer->is_fuzzy) { + /* + * XXX fuzzy implies pinned! not sure how to deal with + * retrigger_next_event() for the !local case. + */ + WARN_ON_ONCE(!(mode & HRTIMER_MODE_PINNED)); + /* + * Notably, by going into hrtimer_reprogram(), it will + * not reprogram if cpu_base->expires_next is earlier. + */ + return first; + } + if (!force_local) { /* * If the current CPU base is online, then the timer is @@ -1645,6 +1658,7 @@ static void __hrtimer_setup(struct hrtim base += hrtimer_clockid_to_base(clock_id); timer->is_soft = softtimer; timer->is_hard = !!(mode & HRTIMER_MODE_HARD); + timer->is_fuzzy = !!(mode & HRTIMER_MODE_FUZZY); timer->base = &cpu_base->clock_base[base]; timerqueue_init(&timer->node);
{ "author": "Peter Zijlstra <peterz@infradead.org>", "date": "Wed, 21 Jan 2026 17:20:13 +0100", "thread_id": "20260121162010.647043073@infradead.org.mbox.gz" }
lkml
[PATCH v2 2/6] hrtimer: Optimize __hrtimer_start_range_ns()
Much like hrtimer_reprogram(), skip programming if the cpu_base is running the hrtimer interrupt. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- kernel/time/hrtimer.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1261,6 +1261,14 @@ static int __hrtimer_start_range_ns(stru } first = enqueue_hrtimer(timer, new_base, mode); + + /* + * If the hrtimer interrupt is running, then it will reevaluate the + * clock bases and reprogram the clock event device. + */ + if (new_base->cpu_base->in_hrtirq) + return 0; + if (!force_local) { /* * If the current CPU base is online, then the timer is
Rework hrtimer_interrupt() such that reprogramming is split out into an independent function at the end of the interrupt. This prepares for reprogramming getting delayed beyond the end of hrtimer_interrupt(). Notably, this changes the hang handling to always wait 100ms instead of trying to keep it proportional to the actual delay. This simplifies the state, also this really shouldn't be happening. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- kernel/time/hrtimer.c | 87 ++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 48 deletions(-) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1889,6 +1889,29 @@ static __latent_entropy void hrtimer_run #ifdef CONFIG_HIGH_RES_TIMERS /* + * Very similar to hrtimer_force_reprogram(), except it deals with + * in_hrirq and hang_detected. + */ +static void __hrtimer_rearm(struct hrtimer_cpu_base *cpu_base, ktime_t now) +{ + ktime_t expires_next = hrtimer_update_next_event(cpu_base); + + cpu_base->expires_next = expires_next; + cpu_base->in_hrtirq = 0; + + if (unlikely(cpu_base->hang_detected)) { + /* + * Give the system a chance to do something else than looping + * on hrtimer interrupts. + */ + expires_next = ktime_add_ns(now, 100 * NSEC_PER_MSEC); + cpu_base->hang_detected = 0; + } + + tick_program_event(expires_next, 1); +} + +/* * High resolution timer interrupt * Called with interrupts disabled */ @@ -1924,63 +1947,31 @@ void hrtimer_interrupt(struct clock_even __hrtimer_run_queues(cpu_base, now, flags, HRTIMER_ACTIVE_HARD); - /* Reevaluate the clock bases for the [soft] next expiry */ - expires_next = hrtimer_update_next_event(cpu_base); - /* - * Store the new expiry value so the migration code can verify - * against it. - */ - cpu_base->expires_next = expires_next; - cpu_base->in_hrtirq = 0; - raw_spin_unlock_irqrestore(&cpu_base->lock, flags); - - /* Reprogramming necessary ? */ - if (!tick_program_event(expires_next, 0)) { - cpu_base->hang_detected = 0; - return; - } - /* * The next timer was already expired due to: * - tracing * - long lasting callbacks * - being scheduled away when running in a VM * - * We need to prevent that we loop forever in the hrtimer - * interrupt routine. We give it 3 attempts to avoid - * overreacting on some spurious event. - * - * Acquire base lock for updating the offsets and retrieving - * the current time. + * We need to prevent that we loop forever in the hrtiner interrupt + * routine. We give it 3 attempts to avoid overreacting on some + * spurious event. */ - raw_spin_lock_irqsave(&cpu_base->lock, flags); + expires_next = hrtimer_update_next_event(cpu_base); now = hrtimer_update_base(cpu_base); - cpu_base->nr_retries++; - if (++retries < 3) - goto retry; - /* - * Give the system a chance to do something else than looping - * here. We stored the entry time, so we know exactly how long - * we spent here. We schedule the next event this amount of - * time away. - */ - cpu_base->nr_hangs++; - cpu_base->hang_detected = 1; - raw_spin_unlock_irqrestore(&cpu_base->lock, flags); + if (expires_next < now) { + if (++retries < 3) + goto retry; + + delta = ktime_sub(now, entry_time); + cpu_base->max_hang_time = max_t(unsigned int, + cpu_base->max_hang_time, delta); + cpu_base->nr_hangs++; + cpu_base->hang_detected = 1; + } - delta = ktime_sub(now, entry_time); - if ((unsigned int)delta > cpu_base->max_hang_time) - cpu_base->max_hang_time = (unsigned int) delta; - /* - * Limit it to a sensible value as we enforce a longer - * delay. Give the CPU at least 100ms to catch up. - */ - if (delta > 100 * NSEC_PER_MSEC) - expires_next = ktime_add_ns(now, 100 * NSEC_PER_MSEC); - else - expires_next = ktime_add(now, delta); - tick_program_event(expires_next, 1); - pr_warn_once("hrtimer: interrupt took %llu ns\n", ktime_to_ns(delta)); + __hrtimer_rearm(cpu_base, now); + raw_spin_unlock_irqrestore(&cpu_base->lock, flags); } #endif /* !CONFIG_HIGH_RES_TIMERS */
{ "author": "Peter Zijlstra <peterz@infradead.org>", "date": "Wed, 21 Jan 2026 17:20:14 +0100", "thread_id": "20260121162010.647043073@infradead.org.mbox.gz" }
lkml
[PATCH v2 2/6] hrtimer: Optimize __hrtimer_start_range_ns()
Much like hrtimer_reprogram(), skip programming if the cpu_base is running the hrtimer interrupt. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- kernel/time/hrtimer.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1261,6 +1261,14 @@ static int __hrtimer_start_range_ns(stru } first = enqueue_hrtimer(timer, new_base, mode); + + /* + * If the hrtimer interrupt is running, then it will reevaluate the + * clock bases and reprogram the clock event device. + */ + if (new_base->cpu_base->in_hrtirq) + return 0; + if (!force_local) { /* * If the current CPU base is online, then the timer is
The nominal duration for an EEVDF task to run is until its deadline. At which point the deadline is moved ahead and a new task selection is done. Try and predict the time 'lost' to higher scheduling classes. Since this is an estimate, the timer can be both early or late. In case it is early task_tick_fair() will take the !need_resched() path and restarts the timer. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- kernel/sched/fair.c | 55 +++++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 24 deletions(-) --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -5511,7 +5511,7 @@ static void put_prev_entity(struct cfs_r } static void -entity_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr, int queued) +entity_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr) { /* * Update run-time statistics of the 'current'. @@ -5523,17 +5523,6 @@ entity_tick(struct cfs_rq *cfs_rq, struc */ update_load_avg(cfs_rq, curr, UPDATE_TG); update_cfs_group(curr); - -#ifdef CONFIG_SCHED_HRTICK - /* - * queued ticks are scheduled to match the slice, so don't bother - * validating it and just reschedule. - */ - if (queued) { - resched_curr_lazy(rq_of(cfs_rq)); - return; - } -#endif } @@ -6735,21 +6724,39 @@ static inline void sched_fair_update_sto static void hrtick_start_fair(struct rq *rq, struct task_struct *p) { struct sched_entity *se = &p->se; + unsigned long scale = 1024; + unsigned long util = 0; + u64 vdelta; + u64 delta; WARN_ON_ONCE(task_rq(p) != rq); - if (rq->cfs.h_nr_queued > 1) { - u64 ran = se->sum_exec_runtime - se->prev_sum_exec_runtime; - u64 slice = se->slice; - s64 delta = slice - ran; - - if (delta < 0) { - if (task_current_donor(rq, p)) - resched_curr(rq); - return; - } - hrtick_start(rq, delta); + if (rq->cfs.h_nr_queued <= 1) + return; + + /* + * Compute time until virtual deadline + */ + vdelta = se->deadline - se->vruntime; + if ((s64)vdelta < 0) { + if (task_current_donor(rq, p)) + resched_curr(rq); + return; + } + delta = (se->load.weight * vdelta) / NICE_0_LOAD; + + /* + * Correct for instantaneous load of other classes. + */ + util += cpu_util_dl(rq); + util += cpu_util_rt(rq); + util += cpu_util_irq(rq); + if (util && util < 1024) { + scale *= 1024; + scale /= (1024 - util); } + + hrtick_start(rq, (scale * delta) / 1024); } /* @@ -13373,7 +13380,7 @@ static void task_tick_fair(struct rq *rq for_each_sched_entity(se) { cfs_rq = cfs_rq_of(se); - entity_tick(cfs_rq, se, queued); + entity_tick(cfs_rq, se); } if (queued) {
{ "author": "Peter Zijlstra <peterz@infradead.org>", "date": "Wed, 21 Jan 2026 17:20:11 +0100", "thread_id": "20260121162010.647043073@infradead.org.mbox.gz" }
lkml
[PATCH v2 2/6] hrtimer: Optimize __hrtimer_start_range_ns()
Much like hrtimer_reprogram(), skip programming if the cpu_base is running the hrtimer interrupt. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- kernel/time/hrtimer.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1261,6 +1261,14 @@ static int __hrtimer_start_range_ns(stru } first = enqueue_hrtimer(timer, new_base, mode); + + /* + * If the hrtimer interrupt is running, then it will reevaluate the + * clock bases and reprogram the clock event device. + */ + if (new_base->cpu_base->in_hrtirq) + return 0; + if (!force_local) { /* * If the current CPU base is online, then the timer is
... for generic entry architectures. This decouples preemption from CONFIG_HZ, leaving only the periodic load-balancer and various accounting things relying on the tick. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- kernel/sched/features.h | 5 +++++ 1 file changed, 5 insertions(+) --- a/kernel/sched/features.h +++ b/kernel/sched/features.h @@ -63,8 +63,13 @@ SCHED_FEAT(DELAY_ZERO, true) */ SCHED_FEAT(WAKEUP_PREEMPTION, true) +#ifdef TIF_HRTIMER_REARM +SCHED_FEAT(HRTICK, true) +SCHED_FEAT(HRTICK_DL, true) +#else SCHED_FEAT(HRTICK, false) SCHED_FEAT(HRTICK_DL, false) +#endif /* * Decrement CPU capacity based on time not spent running tasks
{ "author": "Peter Zijlstra <peterz@infradead.org>", "date": "Wed, 21 Jan 2026 17:20:16 +0100", "thread_id": "20260121162010.647043073@infradead.org.mbox.gz" }
lkml
[PATCH v2 2/6] hrtimer: Optimize __hrtimer_start_range_ns()
Much like hrtimer_reprogram(), skip programming if the cpu_base is running the hrtimer interrupt. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- kernel/time/hrtimer.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1261,6 +1261,14 @@ static int __hrtimer_start_range_ns(stru } first = enqueue_hrtimer(timer, new_base, mode); + + /* + * If the hrtimer interrupt is running, then it will reevaluate the + * clock bases and reprogram the clock event device. + */ + if (new_base->cpu_base->in_hrtirq) + return 0; + if (!force_local) { /* * If the current CPU base is online, then the timer is
Hi Peter, On Wed, Jan 21, 2026 at 05:20:16PM +0100 Peter Zijlstra wrote: I maybe be missing something. But the title of this patch and the above code do not seem to match. Cheers, Phil --
{ "author": "Phil Auld <pauld@redhat.com>", "date": "Wed, 21 Jan 2026 17:24:44 -0500", "thread_id": "20260121162010.647043073@infradead.org.mbox.gz" }
lkml
[PATCH v2 2/6] hrtimer: Optimize __hrtimer_start_range_ns()
Much like hrtimer_reprogram(), skip programming if the cpu_base is running the hrtimer interrupt. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- kernel/time/hrtimer.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1261,6 +1261,14 @@ static int __hrtimer_start_range_ns(stru } first = enqueue_hrtimer(timer, new_base, mode); + + /* + * If the hrtimer interrupt is running, then it will reevaluate the + * clock bases and reprogram the clock event device. + */ + if (new_base->cpu_base->in_hrtirq) + return 0; + if (!force_local) { /* * If the current CPU base is online, then the timer is
Hello, On 21/01/26 17:20, Peter Zijlstra wrote: ... Nit.. guess we don't fear overflow since vdelta should be bounded anyway. Reviewed-by: Juri Lelli <juri.lelli@redhat.com> Thanks, Juri
{ "author": "Juri Lelli <juri.lelli@redhat.com>", "date": "Thu, 22 Jan 2026 11:53:34 +0100", "thread_id": "20260121162010.647043073@infradead.org.mbox.gz" }
lkml
[PATCH v2 2/6] hrtimer: Optimize __hrtimer_start_range_ns()
Much like hrtimer_reprogram(), skip programming if the cpu_base is running the hrtimer interrupt. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- kernel/time/hrtimer.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1261,6 +1261,14 @@ static int __hrtimer_start_range_ns(stru } first = enqueue_hrtimer(timer, new_base, mode); + + /* + * If the hrtimer interrupt is running, then it will reevaluate the + * clock bases and reprogram the clock event device. + */ + if (new_base->cpu_base->in_hrtirq) + return 0; + if (!force_local) { /* * If the current CPU base is online, then the timer is
Hello, On 21/01/26 17:20, Peter Zijlstra wrote: Reviewed-by: Juri Lelli <juri.lelli@redhat.com> Thanks, Juri
{ "author": "Juri Lelli <juri.lelli@redhat.com>", "date": "Thu, 22 Jan 2026 12:00:14 +0100", "thread_id": "20260121162010.647043073@infradead.org.mbox.gz" }
lkml
[PATCH v2 2/6] hrtimer: Optimize __hrtimer_start_range_ns()
Much like hrtimer_reprogram(), skip programming if the cpu_base is running the hrtimer interrupt. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- kernel/time/hrtimer.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1261,6 +1261,14 @@ static int __hrtimer_start_range_ns(stru } first = enqueue_hrtimer(timer, new_base, mode); + + /* + * If the hrtimer interrupt is running, then it will reevaluate the + * clock bases and reprogram the clock event device. + */ + if (new_base->cpu_base->in_hrtirq) + return 0; + if (!force_local) { /* * If the current CPU base is online, then the timer is
On Wed, Jan 21, 2026 at 05:24:44PM -0500, Phil Auld wrote: Arguably this should be CONFIG_GENERIC_ENTRY I suppose You mean it only default enables it for a subset of architectures?
{ "author": "Peter Zijlstra <peterz@infradead.org>", "date": "Thu, 22 Jan 2026 12:40:54 +0100", "thread_id": "20260121162010.647043073@infradead.org.mbox.gz" }
lkml
[PATCH v2 2/6] hrtimer: Optimize __hrtimer_start_range_ns()
Much like hrtimer_reprogram(), skip programming if the cpu_base is running the hrtimer interrupt. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- kernel/time/hrtimer.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1261,6 +1261,14 @@ static int __hrtimer_start_range_ns(stru } first = enqueue_hrtimer(timer, new_base, mode); + + /* + * If the hrtimer interrupt is running, then it will reevaluate the + * clock bases and reprogram the clock event device. + */ + if (new_base->cpu_base->in_hrtirq) + return 0; + if (!force_local) { /* * If the current CPU base is online, then the timer is
On Thu, Jan 22, 2026 at 12:40:54PM +0100 Peter Zijlstra wrote: Nope, I mean I can't read... nevermind. Cheers, Phil --
{ "author": "Phil Auld <pauld@redhat.com>", "date": "Thu, 22 Jan 2026 07:31:17 -0500", "thread_id": "20260121162010.647043073@infradead.org.mbox.gz" }
lkml
[PATCH v2 2/6] hrtimer: Optimize __hrtimer_start_range_ns()
Much like hrtimer_reprogram(), skip programming if the cpu_base is running the hrtimer interrupt. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- kernel/time/hrtimer.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1261,6 +1261,14 @@ static int __hrtimer_start_range_ns(stru } first = enqueue_hrtimer(timer, new_base, mode); + + /* + * If the hrtimer interrupt is running, then it will reevaluate the + * clock bases and reprogram the clock event device. + */ + if (new_base->cpu_base->in_hrtirq) + return 0; + if (!force_local) { /* * If the current CPU base is online, then the timer is
Hello, On 21/01/26 17:20, Peter Zijlstra wrote: Does the more common (lazier :) 'lazy' work better? ... Not sure either, but since it's improving things for local already, maybe it's an acceptable first step? Reviewed-by: Juri Lelli <juri.lelli@redhat.com> Thanks, Juri
{ "author": "Juri Lelli <juri.lelli@redhat.com>", "date": "Thu, 22 Jan 2026 14:12:28 +0100", "thread_id": "20260121162010.647043073@infradead.org.mbox.gz" }
lkml
[PATCH v2 2/6] hrtimer: Optimize __hrtimer_start_range_ns()
Much like hrtimer_reprogram(), skip programming if the cpu_base is running the hrtimer interrupt. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- kernel/time/hrtimer.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1261,6 +1261,14 @@ static int __hrtimer_start_range_ns(stru } first = enqueue_hrtimer(timer, new_base, mode); + + /* + * If the hrtimer interrupt is running, then it will reevaluate the + * clock bases and reprogram the clock event device. + */ + if (new_base->cpu_base->in_hrtirq) + return 0; + if (!force_local) { /* * If the current CPU base is online, then the timer is
On Thu, 22 Jan 2026 14:12:28 +0100 Juri Lelli <juri.lelli@redhat.com> wrote: I don't like either fuzzy or lazy. Fuzzy makes me think of just random entries (for fuzz testing and such). Lazy is to postpone things to do things less often. What about "speculative"? Like branch prediction and such. Where a timer is expected to be used at a certain time but it may not be? -- Steve
{ "author": "Steven Rostedt <rostedt@goodmis.org>", "date": "Fri, 23 Jan 2026 15:04:50 -0500", "thread_id": "20260121162010.647043073@infradead.org.mbox.gz" }
lkml
[PATCH v2 2/6] hrtimer: Optimize __hrtimer_start_range_ns()
Much like hrtimer_reprogram(), skip programming if the cpu_base is running the hrtimer interrupt. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- kernel/time/hrtimer.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1261,6 +1261,14 @@ static int __hrtimer_start_range_ns(stru } first = enqueue_hrtimer(timer, new_base, mode); + + /* + * If the hrtimer interrupt is running, then it will reevaluate the + * clock bases and reprogram the clock event device. + */ + if (new_base->cpu_base->in_hrtirq) + return 0; + if (!force_local) { /* * If the current CPU base is online, then the timer is
On Wed, 21 Jan 2026 17:20:15 +0100 Peter Zijlstra <peterz@infradead.org> wrote: I'm curious to why you decided to use scoped_guard() here and not just guard() and not add the extra indentation? The function is small enough where everything is expected to be protected by the spinlock. -- Steve
{ "author": "Steven Rostedt <rostedt@goodmis.org>", "date": "Fri, 23 Jan 2026 15:08:43 -0500", "thread_id": "20260121162010.647043073@infradead.org.mbox.gz" }
lkml
[PATCH v2 2/6] hrtimer: Optimize __hrtimer_start_range_ns()
Much like hrtimer_reprogram(), skip programming if the cpu_base is running the hrtimer interrupt. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- kernel/time/hrtimer.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1261,6 +1261,14 @@ static int __hrtimer_start_range_ns(stru } first = enqueue_hrtimer(timer, new_base, mode); + + /* + * If the hrtimer interrupt is running, then it will reevaluate the + * clock bases and reprogram the clock event device. + */ + if (new_base->cpu_base->in_hrtirq) + return 0; + if (!force_local) { /* * If the current CPU base is online, then the timer is
On Fri, Jan 23, 2026 at 03:08:43PM -0500, Steven Rostedt wrote: Yeah, I'm not entirely sure... its been over 6 months since I wrote this code :-/
{ "author": "Peter Zijlstra <peterz@infradead.org>", "date": "Fri, 23 Jan 2026 22:04:33 +0100", "thread_id": "20260121162010.647043073@infradead.org.mbox.gz" }
lkml
[PATCH v2 2/6] hrtimer: Optimize __hrtimer_start_range_ns()
Much like hrtimer_reprogram(), skip programming if the cpu_base is running the hrtimer interrupt. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- kernel/time/hrtimer.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1261,6 +1261,14 @@ static int __hrtimer_start_range_ns(stru } first = enqueue_hrtimer(timer, new_base, mode); + + /* + * If the hrtimer interrupt is running, then it will reevaluate the + * clock bases and reprogram the clock event device. + */ + if (new_base->cpu_base->in_hrtirq) + return 0; + if (!force_local) { /* * If the current CPU base is online, then the timer is
On Wed, Jan 21 2026 at 17:20, Peter Zijlstra wrote: Reviewed-by: Thomas Gleixner <tglx@kernel.org>
{ "author": "Thomas Gleixner <tglx@linutronix.de>", "date": "Mon, 02 Feb 2026 13:28:12 +0100", "thread_id": "20260121162010.647043073@infradead.org.mbox.gz" }
lkml
[PATCH v2 2/6] hrtimer: Optimize __hrtimer_start_range_ns()
Much like hrtimer_reprogram(), skip programming if the cpu_base is running the hrtimer interrupt. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- kernel/time/hrtimer.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1261,6 +1261,14 @@ static int __hrtimer_start_range_ns(stru } first = enqueue_hrtimer(timer, new_base, mode); + + /* + * If the hrtimer interrupt is running, then it will reevaluate the + * clock bases and reprogram the clock event device. + */ + if (new_base->cpu_base->in_hrtirq) + return 0; + if (!force_local) { /* * If the current CPU base is online, then the timer is
On Wed, Jan 21 2026 at 17:20, Peter Zijlstra wrote: SHouldn't this be HRTIMER_MODE_REL_PINNED_HARD? I know it's set when starting the timer, but I had to double check it. I'd rather say: Fuzzy requires pinned as the lazy reprogramming only works for CPU local timers. Other than that: Reviewed-by: Thomas Gleixner <tglx@kernel.org> Thanks, tglx
{ "author": "Thomas Gleixner <tglx@linutronix.de>", "date": "Mon, 02 Feb 2026 15:02:26 +0100", "thread_id": "20260121162010.647043073@infradead.org.mbox.gz" }
lkml
[PATCH v2 2/6] hrtimer: Optimize __hrtimer_start_range_ns()
Much like hrtimer_reprogram(), skip programming if the cpu_base is running the hrtimer interrupt. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- kernel/time/hrtimer.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1261,6 +1261,14 @@ static int __hrtimer_start_range_ns(stru } first = enqueue_hrtimer(timer, new_base, mode); + + /* + * If the hrtimer interrupt is running, then it will reevaluate the + * clock bases and reprogram the clock event device. + */ + if (new_base->cpu_base->in_hrtirq) + return 0; + if (!force_local) { /* * If the current CPU base is online, then the timer is
On Wed, Jan 21 2026 at 17:20, Peter Zijlstra wrote: Indeed. in_hrtirq Reviewed-by: Thomas Gleixner <tglx@kernel.org>
{ "author": "Thomas Gleixner <tglx@linutronix.de>", "date": "Mon, 02 Feb 2026 15:05:14 +0100", "thread_id": "20260121162010.647043073@infradead.org.mbox.gz" }
lkml
[PATCH v2 2/6] hrtimer: Optimize __hrtimer_start_range_ns()
Much like hrtimer_reprogram(), skip programming if the cpu_base is running the hrtimer interrupt. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- kernel/time/hrtimer.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1261,6 +1261,14 @@ static int __hrtimer_start_range_ns(stru } first = enqueue_hrtimer(timer, new_base, mode); + + /* + * If the hrtimer interrupt is running, then it will reevaluate the + * clock bases and reprogram the clock event device. + */ + if (new_base->cpu_base->in_hrtirq) + return 0; + if (!force_local) { /* * If the current CPU base is online, then the timer is
On Wed, Jan 21 2026 at 17:20, Peter Zijlstra wrote: Two things I'm not convinced that they are handled correctly: 1) Interrupts After reenabling interrupts and before reaching schedule() an interrupt comes in and runs soft interrupt processing for a while on the way back, which delays the update until that processing completes. 2) Time slice extension When the time slice is granted this will not rearm the clockevent device unless the slice hrtimer becomes the first expiring timer on that CPU, but even then that misses the full reevaluation of the next timer event. in hrtimer.h where you already have the #ifdef TIF_HRTIMER_REARM section: static inline bool hrtimer_set_rearm_delayed() { set_thread_flag(TIF_HRTIMER_REARM); return true; } and a empty stub returning false for the other case then this becomes: if (!hrtimer_set_rearm_delayed()) hrtimer_rearm(...); and the ugly ifdef in the code goes away. Grr. I had to read this five times to figure out that we now have hrtimer_rearm() _hrtimer_rearm() __hrtimer_rearm() You clearly ran out of characters to make that obvious: hrtimer_rearm_delayed() hrtimer_rearm() hrtimer_do_rearm() or something like that. Thanks, tglx
{ "author": "Thomas Gleixner <tglx@linutronix.de>", "date": "Mon, 02 Feb 2026 15:37:13 +0100", "thread_id": "20260121162010.647043073@infradead.org.mbox.gz" }
lkml
[PATCH v2 2/6] hrtimer: Optimize __hrtimer_start_range_ns()
Much like hrtimer_reprogram(), skip programming if the cpu_base is running the hrtimer interrupt. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> --- kernel/time/hrtimer.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1261,6 +1261,14 @@ static int __hrtimer_start_range_ns(stru } first = enqueue_hrtimer(timer, new_base, mode); + + /* + * If the hrtimer interrupt is running, then it will reevaluate the + * clock bases and reprogram the clock event device. + */ + if (new_base->cpu_base->in_hrtirq) + return 0; + if (!force_local) { /* * If the current CPU base is online, then the timer is
On Mon, Feb 02, 2026 at 03:37:13PM +0100, Thomas Gleixner wrote: So the basic thing looks like: <USER-MODE> irqentry_enter() run_irq_on_irqstack_cond() if (user_mode() || hardirq_stack_inuse) irq_enter_rcu(); func_c(); irq_exit_rcu() __irq_exit_rcu() invoke_softirq() irqentry_exit() irqentry_exit_to_user_mode() irqentry_exit_to_user_mode_prepare() __exit_to_user_mode_prepare() exit_to_user_mode_loop() ...here... So a nested IRQ at this point will have !user_mode(), but I think it can still end up in softirqs due to that hardirq_stack_inuse. Should we perhaps make sure only user_mode() ends up in softirqs? Oh crud yes, that should be something like: if (!rseq_grant_slice_extension(ti_work & TIF_SLICE_EXT_DENY)) schedule(); else hrtimer_rearm();
{ "author": "Peter Zijlstra <peterz@infradead.org>", "date": "Mon, 2 Feb 2026 17:33:55 +0100", "thread_id": "20260121162010.647043073@infradead.org.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
Modify online_memory_block() to accept the online type through its arg parameter rather than calling mhp_get_default_online_type() internally. This prepares for allowing callers to specify explicit online types. Update the caller in add_memory_resource() to pass the default online type via a local variable. No functional change. Cc: Oscar Salvador <osalvador@suse.de> Cc: Andrew Morton <akpm@linux-foundation.org> Acked-by: David Hildenbrand (Red Hat) <david@kernel.org> Signed-off-by: Gregory Price <gourry@gourry.net> --- mm/memory_hotplug.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index bc805029da51..87796b617d9e 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1337,7 +1337,9 @@ static int check_hotplug_memory_range(u64 start, u64 size) static int online_memory_block(struct memory_block *mem, void *arg) { - mem->online_type = mhp_get_default_online_type(); + int *online_type = arg; + + mem->online_type = *online_type; return device_online(&mem->dev); } @@ -1578,8 +1580,12 @@ int add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) merge_system_ram_resource(res); /* online pages if requested */ - if (mhp_get_default_online_type() != MMOP_OFFLINE) - walk_memory_blocks(start, size, NULL, online_memory_block); + if (mhp_get_default_online_type() != MMOP_OFFLINE) { + int online_type = mhp_get_default_online_type(); + + walk_memory_blocks(start, size, &online_type, + online_memory_block); + } return ret; error: -- 2.52.0
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Thu, 29 Jan 2026 16:04:34 -0500", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
Enable dax kmem driver to select how to online the memory rather than implicitly depending on the system default. This will allow users of dax to plumb through a preferred auto-online policy for their region. Refactor and new interface: Add __add_memory_driver_managed() which accepts an explicit online_type and export mhp_get_default_online_type() so callers can pass it when they want the default behavior. Refactor: Extract __add_memory_resource() to take an explicit online_type parameter, and update add_memory_resource() to pass the system default. No functional change for existing users. Cc: David Hildenbrand <david@kernel.org> Cc: Oscar Salvador <osalvador@suse.de> Cc: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Gregory Price <gourry@gourry.net> --- include/linux/memory_hotplug.h | 3 ++ mm/memory_hotplug.c | 91 ++++++++++++++++++++++++---------- 2 files changed, 67 insertions(+), 27 deletions(-) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index f2f16cdd73ee..1eb63d1a247d 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -293,6 +293,9 @@ extern int __add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags); extern int add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags); extern int add_memory_resource(int nid, struct resource *resource, mhp_t mhp_flags); +int __add_memory_driver_managed(int nid, u64 start, u64 size, + const char *resource_name, mhp_t mhp_flags, + int online_type); extern int add_memory_driver_managed(int nid, u64 start, u64 size, const char *resource_name, mhp_t mhp_flags); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 87796b617d9e..d3ca95b872bd 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -239,6 +239,7 @@ int mhp_get_default_online_type(void) return mhp_default_online_type; } +EXPORT_SYMBOL_GPL(mhp_get_default_online_type); void mhp_set_default_online_type(int online_type) { @@ -1490,7 +1491,8 @@ static int create_altmaps_and_memory_blocks(int nid, struct memory_group *group, * * we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ -int add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) +static int __add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags, + int online_type) { struct mhp_params params = { .pgprot = pgprot_mhp(PAGE_KERNEL) }; enum memblock_flags memblock_flags = MEMBLOCK_NONE; @@ -1580,12 +1582,9 @@ int add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) merge_system_ram_resource(res); /* online pages if requested */ - if (mhp_get_default_online_type() != MMOP_OFFLINE) { - int online_type = mhp_get_default_online_type(); - + if (online_type != MMOP_OFFLINE) walk_memory_blocks(start, size, &online_type, online_memory_block); - } return ret; error: @@ -1601,7 +1600,13 @@ int add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) return ret; } -/* requires device_hotplug_lock, see add_memory_resource() */ +int add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) +{ + return __add_memory_resource(nid, res, mhp_flags, + mhp_get_default_online_type()); +} + +/* requires device_hotplug_lock, see __add_memory_resource() */ int __add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags) { struct resource *res; @@ -1629,29 +1634,24 @@ int add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags) } EXPORT_SYMBOL_GPL(add_memory); -/* - * Add special, driver-managed memory to the system as system RAM. Such - * memory is not exposed via the raw firmware-provided memmap as system - * RAM, instead, it is detected and added by a driver - during cold boot, - * after a reboot, and after kexec. - * - * Reasons why this memory should not be used for the initial memmap of a - * kexec kernel or for placing kexec images: - * - The booting kernel is in charge of determining how this memory will be - * used (e.g., use persistent memory as system RAM) - * - Coordination with a hypervisor is required before this memory - * can be used (e.g., inaccessible parts). +/** + * __add_memory_driver_managed - add driver-managed memory with explicit online_type + * @nid: NUMA node ID where the memory will be added + * @start: Start physical address of the memory range + * @size: Size of the memory range in bytes + * @resource_name: Resource name in format "System RAM ($DRIVER)" + * @mhp_flags: Memory hotplug flags + * @online_type: Online behavior (MMOP_ONLINE, MMOP_ONLINE_KERNEL, + * MMOP_ONLINE_MOVABLE, or MMOP_OFFLINE) * - * For this memory, no entries in /sys/firmware/memmap ("raw firmware-provided - * memory map") are created. Also, the created memory resource is flagged - * with IORESOURCE_SYSRAM_DRIVER_MANAGED, so in-kernel users can special-case - * this memory as well (esp., not place kexec images onto it). + * Add driver-managed memory with explicit online_type specification. + * The resource_name must have the format "System RAM ($DRIVER)". * - * The resource_name (visible via /proc/iomem) has to have the format - * "System RAM ($DRIVER)". + * Return: 0 on success, negative error code on failure. */ -int add_memory_driver_managed(int nid, u64 start, u64 size, - const char *resource_name, mhp_t mhp_flags) +int __add_memory_driver_managed(int nid, u64 start, u64 size, + const char *resource_name, mhp_t mhp_flags, + int online_type) { struct resource *res; int rc; @@ -1661,6 +1661,9 @@ int add_memory_driver_managed(int nid, u64 start, u64 size, resource_name[strlen(resource_name) - 1] != ')') return -EINVAL; + if (online_type < 0 || online_type > MMOP_ONLINE_MOVABLE) + return -EINVAL; + lock_device_hotplug(); res = register_memory_resource(start, size, resource_name); @@ -1669,7 +1672,7 @@ int add_memory_driver_managed(int nid, u64 start, u64 size, goto out_unlock; } - rc = add_memory_resource(nid, res, mhp_flags); + rc = __add_memory_resource(nid, res, mhp_flags, online_type); if (rc < 0) release_memory_resource(res); @@ -1677,6 +1680,40 @@ int add_memory_driver_managed(int nid, u64 start, u64 size, unlock_device_hotplug(); return rc; } +EXPORT_SYMBOL_FOR_MODULES(__add_memory_driver_managed, "kmem"); + +/* + * Add special, driver-managed memory to the system as system RAM. Such + * memory is not exposed via the raw firmware-provided memmap as system + * RAM, instead, it is detected and added by a driver - during cold boot, + * after a reboot, and after kexec. + * + * Reasons why this memory should not be used for the initial memmap of a + * kexec kernel or for placing kexec images: + * - The booting kernel is in charge of determining how this memory will be + * used (e.g., use persistent memory as system RAM) + * - Coordination with a hypervisor is required before this memory + * can be used (e.g., inaccessible parts). + * + * For this memory, no entries in /sys/firmware/memmap ("raw firmware-provided + * memory map") are created. Also, the created memory resource is flagged + * with IORESOURCE_SYSRAM_DRIVER_MANAGED, so in-kernel users can special-case + * this memory as well (esp., not place kexec images onto it). + * + * The resource_name (visible via /proc/iomem) has to have the format + * "System RAM ($DRIVER)". + * + * Memory will be onlined using the system default online type. + * + * Returns 0 on success, negative error code on failure. + */ +int add_memory_driver_managed(int nid, u64 start, u64 size, + const char *resource_name, mhp_t mhp_flags) +{ + return __add_memory_driver_managed(nid, start, size, resource_name, + mhp_flags, + mhp_get_default_online_type()); +} EXPORT_SYMBOL_GPL(add_memory_driver_managed); /* -- 2.52.0
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Thu, 29 Jan 2026 16:04:35 -0500", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
There is no way for drivers leveraging dax_kmem to plumb through a preferred auto-online policy - the system default policy is forced. Add online_type field to DAX device creation path to allow drivers to specify an auto-online policy when using the kmem driver. Current callers initialize online_type to mhp_get_default_online_type() which resolves to the system default (memhp_default_online_type). No functional change to existing drivers. Cc:David Hildenbrand <david@kernel.org> Signed-off-by: Gregory Price <gourry@gourry.net> --- drivers/cxl/core/region.c | 2 ++ drivers/cxl/cxl.h | 1 + drivers/dax/bus.c | 3 +++ drivers/dax/bus.h | 1 + drivers/dax/cxl.c | 1 + drivers/dax/dax-private.h | 2 ++ drivers/dax/hmem/hmem.c | 2 ++ drivers/dax/kmem.c | 13 +++++++++++-- drivers/dax/pmem.c | 2 ++ 9 files changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 5bd1213737fa..eef5d5fe3f95 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* Copyright(c) 2022 Intel Corporation. All rights reserved. */ #include <linux/memregion.h> +#include <linux/memory_hotplug.h> #include <linux/genalloc.h> #include <linux/debugfs.h> #include <linux/device.h> @@ -3459,6 +3460,7 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr) if (IS_ERR(cxlr_dax)) return PTR_ERR(cxlr_dax); + cxlr_dax->online_type = mhp_get_default_online_type(); dev = &cxlr_dax->dev; rc = dev_set_name(dev, "dax_region%d", cxlr->id); if (rc) diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index ba17fa86d249..07d57d13f4c7 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -591,6 +591,7 @@ struct cxl_dax_region { struct device dev; struct cxl_region *cxlr; struct range hpa_range; + int online_type; /* MMOP_ value for kmem driver */ }; /** diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index fde29e0ad68b..121a6dd0afe7 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright(c) 2017-2018 Intel Corporation. All rights reserved. */ #include <linux/memremap.h> +#include <linux/memory_hotplug.h> #include <linux/device.h> #include <linux/mutex.h> #include <linux/list.h> @@ -395,6 +396,7 @@ static ssize_t create_store(struct device *dev, struct device_attribute *attr, .size = 0, .id = -1, .memmap_on_memory = false, + .online_type = mhp_get_default_online_type(), }; struct dev_dax *dev_dax = __devm_create_dev_dax(&data); @@ -1494,6 +1496,7 @@ static struct dev_dax *__devm_create_dev_dax(struct dev_dax_data *data) ida_init(&dev_dax->ida); dev_dax->memmap_on_memory = data->memmap_on_memory; + dev_dax->online_type = data->online_type; inode = dax_inode(dax_dev); dev->devt = inode->i_rdev; diff --git a/drivers/dax/bus.h b/drivers/dax/bus.h index cbbf64443098..4ac92a4edfe7 100644 --- a/drivers/dax/bus.h +++ b/drivers/dax/bus.h @@ -24,6 +24,7 @@ struct dev_dax_data { resource_size_t size; int id; bool memmap_on_memory; + int online_type; /* MMOP_ value for kmem driver */ }; struct dev_dax *devm_create_dev_dax(struct dev_dax_data *data); diff --git a/drivers/dax/cxl.c b/drivers/dax/cxl.c index 13cd94d32ff7..856a0cd24f3b 100644 --- a/drivers/dax/cxl.c +++ b/drivers/dax/cxl.c @@ -27,6 +27,7 @@ static int cxl_dax_region_probe(struct device *dev) .id = -1, .size = range_len(&cxlr_dax->hpa_range), .memmap_on_memory = true, + .online_type = cxlr_dax->online_type, }; return PTR_ERR_OR_ZERO(devm_create_dev_dax(&data)); diff --git a/drivers/dax/dax-private.h b/drivers/dax/dax-private.h index c6ae27c982f4..9559718cc988 100644 --- a/drivers/dax/dax-private.h +++ b/drivers/dax/dax-private.h @@ -77,6 +77,7 @@ struct dev_dax_range { * @dev: device core * @pgmap: pgmap for memmap setup / lifetime (driver owned) * @memmap_on_memory: allow kmem to put the memmap in the memory + * @online_type: MMOP_* online type for memory hotplug * @nr_range: size of @ranges * @ranges: range tuples of memory used */ @@ -91,6 +92,7 @@ struct dev_dax { struct device dev; struct dev_pagemap *pgmap; bool memmap_on_memory; + int online_type; int nr_range; struct dev_dax_range *ranges; }; diff --git a/drivers/dax/hmem/hmem.c b/drivers/dax/hmem/hmem.c index c18451a37e4f..119914b08fd9 100644 --- a/drivers/dax/hmem/hmem.c +++ b/drivers/dax/hmem/hmem.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include <linux/platform_device.h> +#include <linux/memory_hotplug.h> #include <linux/memregion.h> #include <linux/module.h> #include <linux/dax.h> @@ -36,6 +37,7 @@ static int dax_hmem_probe(struct platform_device *pdev) .id = -1, .size = region_idle ? 0 : range_len(&mri->range), .memmap_on_memory = false, + .online_type = mhp_get_default_online_type(), }; return PTR_ERR_OR_ZERO(devm_create_dev_dax(&data)); diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c index c036e4d0b610..550dc605229e 100644 --- a/drivers/dax/kmem.c +++ b/drivers/dax/kmem.c @@ -16,6 +16,11 @@ #include "dax-private.h" #include "bus.h" +/* Internal function exported only to kmem module */ +extern int __add_memory_driver_managed(int nid, u64 start, u64 size, + const char *resource_name, + mhp_t mhp_flags, int online_type); + /* * Default abstract distance assigned to the NUMA node onlined * by DAX/kmem if the low level platform driver didn't initialize @@ -72,6 +77,7 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) struct dax_kmem_data *data; struct memory_dev_type *mtype; int i, rc, mapped = 0; + int online_type; mhp_t mhp_flags; int numa_node; int adist = MEMTIER_DEFAULT_DAX_ADISTANCE; @@ -134,6 +140,8 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) goto err_reg_mgid; data->mgid = rc; + online_type = dev_dax->online_type; + for (i = 0; i < dev_dax->nr_range; i++) { struct resource *res; struct range range; @@ -174,8 +182,9 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) * Ensure that future kexec'd kernels will not treat * this as RAM automatically. */ - rc = add_memory_driver_managed(data->mgid, range.start, - range_len(&range), kmem_name, mhp_flags); + rc = __add_memory_driver_managed(data->mgid, range.start, + range_len(&range), kmem_name, mhp_flags, + online_type); if (rc) { dev_warn(dev, "mapping%d: %#llx-%#llx memory add failed\n", diff --git a/drivers/dax/pmem.c b/drivers/dax/pmem.c index bee93066a849..a5925146b09f 100644 --- a/drivers/dax/pmem.c +++ b/drivers/dax/pmem.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright(c) 2016 - 2018 Intel Corporation. All rights reserved. */ +#include <linux/memory_hotplug.h> #include <linux/memremap.h> #include <linux/module.h> #include "../nvdimm/pfn.h" @@ -63,6 +64,7 @@ static struct dev_dax *__dax_pmem_probe(struct device *dev) .pgmap = &pgmap, .size = range_len(&range), .memmap_on_memory = false, + .online_type = mhp_get_default_online_type(), }; return devm_create_dev_dax(&data); -- 2.52.0
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Thu, 29 Jan 2026 16:04:36 -0500", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
Move the pmem region driver logic from region.c into pmem_region.c. No functional changes. Signed-off-by: Gregory Price <gourry@gourry.net> --- drivers/cxl/core/Makefile | 1 + drivers/cxl/core/core.h | 1 + drivers/cxl/core/pmem_region.c | 191 +++++++++++++++++++++++++++++++++ drivers/cxl/core/region.c | 184 ------------------------------- 4 files changed, 193 insertions(+), 184 deletions(-) create mode 100644 drivers/cxl/core/pmem_region.c diff --git a/drivers/cxl/core/Makefile b/drivers/cxl/core/Makefile index 5ad8fef210b5..23269c81fd44 100644 --- a/drivers/cxl/core/Makefile +++ b/drivers/cxl/core/Makefile @@ -17,6 +17,7 @@ cxl_core-y += cdat.o cxl_core-y += ras.o cxl_core-$(CONFIG_TRACING) += trace.o cxl_core-$(CONFIG_CXL_REGION) += region.o +cxl_core-$(CONFIG_CXL_REGION) += pmem_region.o cxl_core-$(CONFIG_CXL_MCE) += mce.o cxl_core-$(CONFIG_CXL_FEATURES) += features.o cxl_core-$(CONFIG_CXL_EDAC_MEM_FEATURES) += edac.o diff --git a/drivers/cxl/core/core.h b/drivers/cxl/core/core.h index dd987ef2def5..26991de12d76 100644 --- a/drivers/cxl/core/core.h +++ b/drivers/cxl/core/core.h @@ -43,6 +43,7 @@ int cxl_get_poison_by_endpoint(struct cxl_port *port); struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa); u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd, u64 dpa); +int devm_cxl_add_pmem_region(struct cxl_region *cxlr); #else static inline u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, diff --git a/drivers/cxl/core/pmem_region.c b/drivers/cxl/core/pmem_region.c new file mode 100644 index 000000000000..81b66e548bb5 --- /dev/null +++ b/drivers/cxl/core/pmem_region.c @@ -0,0 +1,191 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright(c) 2022 Intel Corporation. All rights reserved. */ +#include <linux/device.h> +#include <linux/slab.h> +#include <cxlmem.h> +#include <cxl.h> +#include "core.h" + +static void cxl_pmem_region_release(struct device *dev) +{ + struct cxl_pmem_region *cxlr_pmem = to_cxl_pmem_region(dev); + int i; + + for (i = 0; i < cxlr_pmem->nr_mappings; i++) { + struct cxl_memdev *cxlmd = cxlr_pmem->mapping[i].cxlmd; + + put_device(&cxlmd->dev); + } + + kfree(cxlr_pmem); +} + +static const struct attribute_group *cxl_pmem_region_attribute_groups[] = { + &cxl_base_attribute_group, + NULL, +}; + +const struct device_type cxl_pmem_region_type = { + .name = "cxl_pmem_region", + .release = cxl_pmem_region_release, + .groups = cxl_pmem_region_attribute_groups, +}; +bool is_cxl_pmem_region(struct device *dev) +{ + return dev->type == &cxl_pmem_region_type; +} +EXPORT_SYMBOL_NS_GPL(is_cxl_pmem_region, "CXL"); + +struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev) +{ + if (dev_WARN_ONCE(dev, !is_cxl_pmem_region(dev), + "not a cxl_pmem_region device\n")) + return NULL; + return container_of(dev, struct cxl_pmem_region, dev); +} +EXPORT_SYMBOL_NS_GPL(to_cxl_pmem_region, "CXL"); +static struct lock_class_key cxl_pmem_region_key; + +static int cxl_pmem_region_alloc(struct cxl_region *cxlr) +{ + struct cxl_region_params *p = &cxlr->params; + struct cxl_nvdimm_bridge *cxl_nvb; + struct device *dev; + int i; + + guard(rwsem_read)(&cxl_rwsem.region); + if (p->state != CXL_CONFIG_COMMIT) + return -ENXIO; + + struct cxl_pmem_region *cxlr_pmem __free(kfree) = + kzalloc(struct_size(cxlr_pmem, mapping, p->nr_targets), GFP_KERNEL); + if (!cxlr_pmem) + return -ENOMEM; + + cxlr_pmem->hpa_range.start = p->res->start; + cxlr_pmem->hpa_range.end = p->res->end; + + /* Snapshot the region configuration underneath the cxl_rwsem.region */ + cxlr_pmem->nr_mappings = p->nr_targets; + for (i = 0; i < p->nr_targets; i++) { + struct cxl_endpoint_decoder *cxled = p->targets[i]; + struct cxl_memdev *cxlmd = cxled_to_memdev(cxled); + struct cxl_pmem_region_mapping *m = &cxlr_pmem->mapping[i]; + + /* + * Regions never span CXL root devices, so by definition the + * bridge for one device is the same for all. + */ + if (i == 0) { + cxl_nvb = cxl_find_nvdimm_bridge(cxlmd->endpoint); + if (!cxl_nvb) + return -ENODEV; + cxlr->cxl_nvb = cxl_nvb; + } + m->cxlmd = cxlmd; + get_device(&cxlmd->dev); + m->start = cxled->dpa_res->start; + m->size = resource_size(cxled->dpa_res); + m->position = i; + } + + dev = &cxlr_pmem->dev; + device_initialize(dev); + lockdep_set_class(&dev->mutex, &cxl_pmem_region_key); + device_set_pm_not_required(dev); + dev->parent = &cxlr->dev; + dev->bus = &cxl_bus_type; + dev->type = &cxl_pmem_region_type; + cxlr_pmem->cxlr = cxlr; + cxlr->cxlr_pmem = no_free_ptr(cxlr_pmem); + + return 0; +} + +static void cxlr_pmem_unregister(void *_cxlr_pmem) +{ + struct cxl_pmem_region *cxlr_pmem = _cxlr_pmem; + struct cxl_region *cxlr = cxlr_pmem->cxlr; + struct cxl_nvdimm_bridge *cxl_nvb = cxlr->cxl_nvb; + + /* + * Either the bridge is in ->remove() context under the device_lock(), + * or cxlr_release_nvdimm() is cancelling the bridge's release action + * for @cxlr_pmem and doing it itself (while manually holding the bridge + * lock). + */ + device_lock_assert(&cxl_nvb->dev); + cxlr->cxlr_pmem = NULL; + cxlr_pmem->cxlr = NULL; + device_unregister(&cxlr_pmem->dev); +} + +static void cxlr_release_nvdimm(void *_cxlr) +{ + struct cxl_region *cxlr = _cxlr; + struct cxl_nvdimm_bridge *cxl_nvb = cxlr->cxl_nvb; + + scoped_guard(device, &cxl_nvb->dev) { + if (cxlr->cxlr_pmem) + devm_release_action(&cxl_nvb->dev, cxlr_pmem_unregister, + cxlr->cxlr_pmem); + } + cxlr->cxl_nvb = NULL; + put_device(&cxl_nvb->dev); +} + +/** + * devm_cxl_add_pmem_region() - add a cxl_region-to-nd_region bridge + * @cxlr: parent CXL region for this pmem region bridge device + * + * Return: 0 on success negative error code on failure. + */ +int devm_cxl_add_pmem_region(struct cxl_region *cxlr) +{ + struct cxl_pmem_region *cxlr_pmem; + struct cxl_nvdimm_bridge *cxl_nvb; + struct device *dev; + int rc; + + rc = cxl_pmem_region_alloc(cxlr); + if (rc) + return rc; + cxlr_pmem = cxlr->cxlr_pmem; + cxl_nvb = cxlr->cxl_nvb; + + dev = &cxlr_pmem->dev; + rc = dev_set_name(dev, "pmem_region%d", cxlr->id); + if (rc) + goto err; + + rc = device_add(dev); + if (rc) + goto err; + + dev_dbg(&cxlr->dev, "%s: register %s\n", dev_name(dev->parent), + dev_name(dev)); + + scoped_guard(device, &cxl_nvb->dev) { + if (cxl_nvb->dev.driver) + rc = devm_add_action_or_reset(&cxl_nvb->dev, + cxlr_pmem_unregister, + cxlr_pmem); + else + rc = -ENXIO; + } + + if (rc) + goto err_bridge; + + /* @cxlr carries a reference on @cxl_nvb until cxlr_release_nvdimm */ + return devm_add_action_or_reset(&cxlr->dev, cxlr_release_nvdimm, cxlr); + +err: + put_device(dev); +err_bridge: + put_device(&cxl_nvb->dev); + cxlr->cxl_nvb = NULL; + return rc; +} + + diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index e4097c464ed3..fc56f8f03805 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -2747,46 +2747,6 @@ static ssize_t delete_region_store(struct device *dev, } DEVICE_ATTR_WO(delete_region); -static void cxl_pmem_region_release(struct device *dev) -{ - struct cxl_pmem_region *cxlr_pmem = to_cxl_pmem_region(dev); - int i; - - for (i = 0; i < cxlr_pmem->nr_mappings; i++) { - struct cxl_memdev *cxlmd = cxlr_pmem->mapping[i].cxlmd; - - put_device(&cxlmd->dev); - } - - kfree(cxlr_pmem); -} - -static const struct attribute_group *cxl_pmem_region_attribute_groups[] = { - &cxl_base_attribute_group, - NULL, -}; - -const struct device_type cxl_pmem_region_type = { - .name = "cxl_pmem_region", - .release = cxl_pmem_region_release, - .groups = cxl_pmem_region_attribute_groups, -}; - -bool is_cxl_pmem_region(struct device *dev) -{ - return dev->type == &cxl_pmem_region_type; -} -EXPORT_SYMBOL_NS_GPL(is_cxl_pmem_region, "CXL"); - -struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev) -{ - if (dev_WARN_ONCE(dev, !is_cxl_pmem_region(dev), - "not a cxl_pmem_region device\n")) - return NULL; - return container_of(dev, struct cxl_pmem_region, dev); -} -EXPORT_SYMBOL_NS_GPL(to_cxl_pmem_region, "CXL"); - struct cxl_poison_context { struct cxl_port *port; int part; @@ -3236,64 +3196,6 @@ static int region_offset_to_dpa_result(struct cxl_region *cxlr, u64 offset, return -ENXIO; } -static struct lock_class_key cxl_pmem_region_key; - -static int cxl_pmem_region_alloc(struct cxl_region *cxlr) -{ - struct cxl_region_params *p = &cxlr->params; - struct cxl_nvdimm_bridge *cxl_nvb; - struct device *dev; - int i; - - guard(rwsem_read)(&cxl_rwsem.region); - if (p->state != CXL_CONFIG_COMMIT) - return -ENXIO; - - struct cxl_pmem_region *cxlr_pmem __free(kfree) = - kzalloc(struct_size(cxlr_pmem, mapping, p->nr_targets), GFP_KERNEL); - if (!cxlr_pmem) - return -ENOMEM; - - cxlr_pmem->hpa_range.start = p->res->start; - cxlr_pmem->hpa_range.end = p->res->end; - - /* Snapshot the region configuration underneath the cxl_rwsem.region */ - cxlr_pmem->nr_mappings = p->nr_targets; - for (i = 0; i < p->nr_targets; i++) { - struct cxl_endpoint_decoder *cxled = p->targets[i]; - struct cxl_memdev *cxlmd = cxled_to_memdev(cxled); - struct cxl_pmem_region_mapping *m = &cxlr_pmem->mapping[i]; - - /* - * Regions never span CXL root devices, so by definition the - * bridge for one device is the same for all. - */ - if (i == 0) { - cxl_nvb = cxl_find_nvdimm_bridge(cxlmd->endpoint); - if (!cxl_nvb) - return -ENODEV; - cxlr->cxl_nvb = cxl_nvb; - } - m->cxlmd = cxlmd; - get_device(&cxlmd->dev); - m->start = cxled->dpa_res->start; - m->size = resource_size(cxled->dpa_res); - m->position = i; - } - - dev = &cxlr_pmem->dev; - device_initialize(dev); - lockdep_set_class(&dev->mutex, &cxl_pmem_region_key); - device_set_pm_not_required(dev); - dev->parent = &cxlr->dev; - dev->bus = &cxl_bus_type; - dev->type = &cxl_pmem_region_type; - cxlr_pmem->cxlr = cxlr; - cxlr->cxlr_pmem = no_free_ptr(cxlr_pmem); - - return 0; -} - static void cxl_dax_region_release(struct device *dev) { struct cxl_dax_region *cxlr_dax = to_cxl_dax_region(dev); @@ -3357,92 +3259,6 @@ static struct cxl_dax_region *cxl_dax_region_alloc(struct cxl_region *cxlr) return cxlr_dax; } -static void cxlr_pmem_unregister(void *_cxlr_pmem) -{ - struct cxl_pmem_region *cxlr_pmem = _cxlr_pmem; - struct cxl_region *cxlr = cxlr_pmem->cxlr; - struct cxl_nvdimm_bridge *cxl_nvb = cxlr->cxl_nvb; - - /* - * Either the bridge is in ->remove() context under the device_lock(), - * or cxlr_release_nvdimm() is cancelling the bridge's release action - * for @cxlr_pmem and doing it itself (while manually holding the bridge - * lock). - */ - device_lock_assert(&cxl_nvb->dev); - cxlr->cxlr_pmem = NULL; - cxlr_pmem->cxlr = NULL; - device_unregister(&cxlr_pmem->dev); -} - -static void cxlr_release_nvdimm(void *_cxlr) -{ - struct cxl_region *cxlr = _cxlr; - struct cxl_nvdimm_bridge *cxl_nvb = cxlr->cxl_nvb; - - scoped_guard(device, &cxl_nvb->dev) { - if (cxlr->cxlr_pmem) - devm_release_action(&cxl_nvb->dev, cxlr_pmem_unregister, - cxlr->cxlr_pmem); - } - cxlr->cxl_nvb = NULL; - put_device(&cxl_nvb->dev); -} - -/** - * devm_cxl_add_pmem_region() - add a cxl_region-to-nd_region bridge - * @cxlr: parent CXL region for this pmem region bridge device - * - * Return: 0 on success negative error code on failure. - */ -static int devm_cxl_add_pmem_region(struct cxl_region *cxlr) -{ - struct cxl_pmem_region *cxlr_pmem; - struct cxl_nvdimm_bridge *cxl_nvb; - struct device *dev; - int rc; - - rc = cxl_pmem_region_alloc(cxlr); - if (rc) - return rc; - cxlr_pmem = cxlr->cxlr_pmem; - cxl_nvb = cxlr->cxl_nvb; - - dev = &cxlr_pmem->dev; - rc = dev_set_name(dev, "pmem_region%d", cxlr->id); - if (rc) - goto err; - - rc = device_add(dev); - if (rc) - goto err; - - dev_dbg(&cxlr->dev, "%s: register %s\n", dev_name(dev->parent), - dev_name(dev)); - - scoped_guard(device, &cxl_nvb->dev) { - if (cxl_nvb->dev.driver) - rc = devm_add_action_or_reset(&cxl_nvb->dev, - cxlr_pmem_unregister, - cxlr_pmem); - else - rc = -ENXIO; - } - - if (rc) - goto err_bridge; - - /* @cxlr carries a reference on @cxl_nvb until cxlr_release_nvdimm */ - return devm_add_action_or_reset(&cxlr->dev, cxlr_release_nvdimm, cxlr); - -err: - put_device(dev); -err_bridge: - put_device(&cxl_nvb->dev); - cxlr->cxl_nvb = NULL; - return rc; -} - static void cxlr_dax_unregister(void *_cxlr_dax) { struct cxl_dax_region *cxlr_dax = _cxlr_dax; -- 2.52.0
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Thu, 29 Jan 2026 16:04:38 -0500", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
Move the CXL DAX region device infrastructure from region.c into a new dax_region.c file. No functional changes. Signed-off-by: Gregory Price <gourry@gourry.net> --- drivers/cxl/core/Makefile | 1 + drivers/cxl/core/core.h | 1 + drivers/cxl/core/dax_region.c | 113 ++++++++++++++++++++++++++++++++++ drivers/cxl/core/region.c | 102 ------------------------------ 4 files changed, 115 insertions(+), 102 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c diff --git a/drivers/cxl/core/Makefile b/drivers/cxl/core/Makefile index 23269c81fd44..36f284d7c500 100644 --- a/drivers/cxl/core/Makefile +++ b/drivers/cxl/core/Makefile @@ -17,6 +17,7 @@ cxl_core-y += cdat.o cxl_core-y += ras.o cxl_core-$(CONFIG_TRACING) += trace.o cxl_core-$(CONFIG_CXL_REGION) += region.o +cxl_core-$(CONFIG_CXL_REGION) += dax_region.o cxl_core-$(CONFIG_CXL_REGION) += pmem_region.o cxl_core-$(CONFIG_CXL_MCE) += mce.o cxl_core-$(CONFIG_CXL_FEATURES) += features.o diff --git a/drivers/cxl/core/core.h b/drivers/cxl/core/core.h index 26991de12d76..217dd708a2a6 100644 --- a/drivers/cxl/core/core.h +++ b/drivers/cxl/core/core.h @@ -43,6 +43,7 @@ int cxl_get_poison_by_endpoint(struct cxl_port *port); struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa); u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd, u64 dpa); +int devm_cxl_add_dax_region(struct cxl_region *cxlr, enum dax_driver_type); int devm_cxl_add_pmem_region(struct cxl_region *cxlr); #else diff --git a/drivers/cxl/core/dax_region.c b/drivers/cxl/core/dax_region.c new file mode 100644 index 000000000000..0602db5f7248 --- /dev/null +++ b/drivers/cxl/core/dax_region.c @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright(c) 2022 Intel Corporation. All rights reserved. + * Copyright(c) 2026 Meta Technologies Inc. All rights reserved. + */ +#include <linux/memory_hotplug.h> +#include <linux/device.h> +#include <linux/slab.h> +#include <cxlmem.h> +#include <cxl.h> +#include "core.h" + +static void cxl_dax_region_release(struct device *dev) +{ + struct cxl_dax_region *cxlr_dax = to_cxl_dax_region(dev); + + kfree(cxlr_dax); +} + +static const struct attribute_group *cxl_dax_region_attribute_groups[] = { + &cxl_base_attribute_group, + NULL, +}; + +const struct device_type cxl_dax_region_type = { + .name = "cxl_dax_region", + .release = cxl_dax_region_release, + .groups = cxl_dax_region_attribute_groups, +}; + +static bool is_cxl_dax_region(struct device *dev) +{ + return dev->type == &cxl_dax_region_type; +} + +struct cxl_dax_region *to_cxl_dax_region(struct device *dev) +{ + if (dev_WARN_ONCE(dev, !is_cxl_dax_region(dev), + "not a cxl_dax_region device\n")) + return NULL; + return container_of(dev, struct cxl_dax_region, dev); +} +EXPORT_SYMBOL_NS_GPL(to_cxl_dax_region, "CXL"); + +static struct lock_class_key cxl_dax_region_key; + +static struct cxl_dax_region *cxl_dax_region_alloc(struct cxl_region *cxlr) +{ + struct cxl_region_params *p = &cxlr->params; + struct cxl_dax_region *cxlr_dax; + struct device *dev; + + guard(rwsem_read)(&cxl_rwsem.region); + if (p->state != CXL_CONFIG_COMMIT) + return ERR_PTR(-ENXIO); + + cxlr_dax = kzalloc(sizeof(*cxlr_dax), GFP_KERNEL); + if (!cxlr_dax) + return ERR_PTR(-ENOMEM); + + cxlr_dax->hpa_range.start = p->res->start; + cxlr_dax->hpa_range.end = p->res->end; + + dev = &cxlr_dax->dev; + cxlr_dax->cxlr = cxlr; + device_initialize(dev); + lockdep_set_class(&dev->mutex, &cxl_dax_region_key); + device_set_pm_not_required(dev); + dev->parent = &cxlr->dev; + dev->bus = &cxl_bus_type; + dev->type = &cxl_dax_region_type; + + return cxlr_dax; +} + +static void cxlr_dax_unregister(void *_cxlr_dax) +{ + struct cxl_dax_region *cxlr_dax = _cxlr_dax; + + device_unregister(&cxlr_dax->dev); +} + +int devm_cxl_add_dax_region(struct cxl_region *cxlr, + enum dax_driver_type dax_driver) +{ + struct cxl_dax_region *cxlr_dax; + struct device *dev; + int rc; + + cxlr_dax = cxl_dax_region_alloc(cxlr); + if (IS_ERR(cxlr_dax)) + return PTR_ERR(cxlr_dax); + + cxlr_dax->online_type = mhp_get_default_online_type(); + cxlr_dax->dax_driver = dax_driver; + dev = &cxlr_dax->dev; + rc = dev_set_name(dev, "dax_region%d", cxlr->id); + if (rc) + goto err; + + rc = device_add(dev); + if (rc) + goto err; + + dev_dbg(&cxlr->dev, "%s: register %s\n", dev_name(dev->parent), + dev_name(dev)); + + return devm_add_action_or_reset(&cxlr->dev, cxlr_dax_unregister, + cxlr_dax); +err: + put_device(dev); + return rc; +} diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index fc56f8f03805..61ec939c1462 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3196,108 +3196,6 @@ static int region_offset_to_dpa_result(struct cxl_region *cxlr, u64 offset, return -ENXIO; } -static void cxl_dax_region_release(struct device *dev) -{ - struct cxl_dax_region *cxlr_dax = to_cxl_dax_region(dev); - - kfree(cxlr_dax); -} - -static const struct attribute_group *cxl_dax_region_attribute_groups[] = { - &cxl_base_attribute_group, - NULL, -}; - -const struct device_type cxl_dax_region_type = { - .name = "cxl_dax_region", - .release = cxl_dax_region_release, - .groups = cxl_dax_region_attribute_groups, -}; - -static bool is_cxl_dax_region(struct device *dev) -{ - return dev->type == &cxl_dax_region_type; -} - -struct cxl_dax_region *to_cxl_dax_region(struct device *dev) -{ - if (dev_WARN_ONCE(dev, !is_cxl_dax_region(dev), - "not a cxl_dax_region device\n")) - return NULL; - return container_of(dev, struct cxl_dax_region, dev); -} -EXPORT_SYMBOL_NS_GPL(to_cxl_dax_region, "CXL"); - -static struct lock_class_key cxl_dax_region_key; - -static struct cxl_dax_region *cxl_dax_region_alloc(struct cxl_region *cxlr) -{ - struct cxl_region_params *p = &cxlr->params; - struct cxl_dax_region *cxlr_dax; - struct device *dev; - - guard(rwsem_read)(&cxl_rwsem.region); - if (p->state != CXL_CONFIG_COMMIT) - return ERR_PTR(-ENXIO); - - cxlr_dax = kzalloc(sizeof(*cxlr_dax), GFP_KERNEL); - if (!cxlr_dax) - return ERR_PTR(-ENOMEM); - - cxlr_dax->hpa_range.start = p->res->start; - cxlr_dax->hpa_range.end = p->res->end; - - dev = &cxlr_dax->dev; - cxlr_dax->cxlr = cxlr; - device_initialize(dev); - lockdep_set_class(&dev->mutex, &cxl_dax_region_key); - device_set_pm_not_required(dev); - dev->parent = &cxlr->dev; - dev->bus = &cxl_bus_type; - dev->type = &cxl_dax_region_type; - - return cxlr_dax; -} - -static void cxlr_dax_unregister(void *_cxlr_dax) -{ - struct cxl_dax_region *cxlr_dax = _cxlr_dax; - - device_unregister(&cxlr_dax->dev); -} - -static int devm_cxl_add_dax_region(struct cxl_region *cxlr, - enum dax_driver_type dax_driver) -{ - struct cxl_dax_region *cxlr_dax; - struct device *dev; - int rc; - - cxlr_dax = cxl_dax_region_alloc(cxlr); - if (IS_ERR(cxlr_dax)) - return PTR_ERR(cxlr_dax); - - cxlr_dax->online_type = mhp_get_default_online_type(); - cxlr_dax->dax_driver = dax_driver; - dev = &cxlr_dax->dev; - rc = dev_set_name(dev, "dax_region%d", cxlr->id); - if (rc) - goto err; - - rc = device_add(dev); - if (rc) - goto err; - - dev_dbg(&cxlr->dev, "%s: register %s\n", dev_name(dev->parent), - dev_name(dev)); - - return devm_add_action_or_reset(&cxlr->dev, cxlr_dax_unregister, - cxlr_dax); -err: - put_device(dev); - return rc; -} - static int match_decoder_by_range(struct device *dev, const void *data) { const struct range *r1, *r2 = data; -- 2.52.0
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Thu, 29 Jan 2026 16:04:39 -0500", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
Add a new cxl_devdax_region driver that probes CXL regions in device dax mode and creates dax_region devices. This allows explicit binding to the device_dax dax driver instead of the kmem driver. Exports to_cxl_region() to core.h so it can be used by the driver. Signed-off-by: Gregory Price <gourry@gourry.net> --- drivers/cxl/core/core.h | 2 ++ drivers/cxl/core/dax_region.c | 16 ++++++++++++++++ drivers/cxl/core/region.c | 21 +++++++++++++++++---- drivers/cxl/cxl.h | 1 + 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/drivers/cxl/core/core.h b/drivers/cxl/core/core.h index 217dd708a2a6..ea4df8abc2ad 100644 --- a/drivers/cxl/core/core.h +++ b/drivers/cxl/core/core.h @@ -46,6 +46,8 @@ u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd, int devm_cxl_add_dax_region(struct cxl_region *cxlr, enum dax_driver_type); int devm_cxl_add_pmem_region(struct cxl_region *cxlr); +extern struct cxl_driver cxl_devdax_region_driver; + #else static inline u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd, u64 dpa) diff --git a/drivers/cxl/core/dax_region.c b/drivers/cxl/core/dax_region.c index 0602db5f7248..391d51e5ec37 100644 --- a/drivers/cxl/core/dax_region.c +++ b/drivers/cxl/core/dax_region.c @@ -111,3 +111,19 @@ int devm_cxl_add_dax_region(struct cxl_region *cxlr, put_device(dev); return rc; } + +static int cxl_devdax_region_driver_probe(struct device *dev) +{ + struct cxl_region *cxlr = to_cxl_region(dev); + + if (cxlr->mode != CXL_PARTMODE_RAM) + return -ENODEV; + + return devm_cxl_add_dax_region(cxlr, DAXDRV_DEVICE_TYPE); +} + +struct cxl_driver cxl_devdax_region_driver = { + .name = "cxl_devdax_region", + .probe = cxl_devdax_region_driver_probe, + .id = CXL_DEVICE_REGION, +}; diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 61ec939c1462..6200ca1cc2dd 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -39,8 +39,6 @@ */ static nodemask_t nodemask_region_seen = NODE_MASK_NONE; -static struct cxl_region *to_cxl_region(struct device *dev); - #define __ACCESS_ATTR_RO(_level, _name) { \ .attr = { .name = __stringify(_name), .mode = 0444 }, \ .show = _name##_access##_level##_show, \ @@ -2430,7 +2428,7 @@ bool is_cxl_region(struct device *dev) } EXPORT_SYMBOL_NS_GPL(is_cxl_region, "CXL"); -static struct cxl_region *to_cxl_region(struct device *dev) +struct cxl_region *to_cxl_region(struct device *dev) { if (dev_WARN_ONCE(dev, dev->type != &cxl_region_type, "not a cxl_region device\n")) @@ -3726,11 +3724,26 @@ static struct cxl_driver cxl_region_driver = { int cxl_region_init(void) { - return cxl_driver_register(&cxl_region_driver); + int rc; + + rc = cxl_driver_register(&cxl_region_driver); + if (rc) + return rc; + + rc = cxl_driver_register(&cxl_devdax_region_driver); + if (rc) + goto err_dax; + + return 0; + +err_dax: + cxl_driver_unregister(&cxl_region_driver); + return rc; } void cxl_region_exit(void) { + cxl_driver_unregister(&cxl_devdax_region_driver); cxl_driver_unregister(&cxl_region_driver); } diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index c06a239c0008..674d5f870c70 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -859,6 +859,7 @@ int cxl_dvsec_rr_decode(struct cxl_dev_state *cxlds, struct cxl_endpoint_dvsec_info *info); bool is_cxl_region(struct device *dev); +struct cxl_region *to_cxl_region(struct device *dev); extern const struct bus_type cxl_bus_type; -- 2.52.0
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Thu, 29 Jan 2026 16:04:40 -0500", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
CXL regions may wish not to auto-configure their memory as dax kmem, but the current plumbing defaults all cxl-created dax devices to the kmem driver. This exposes them to hotplug policy, even if the user intends to use the memory as a dax device. Add plumbing to allow CXL drivers to select whether a DAX region should default to kmem (DAXDRV_KMEM_TYPE) or device (DAXDRV_DEVICE_TYPE). Add a 'dax_driver' field to struct cxl_dax_region and update devm_cxl_add_dax_region() to take a dax_driver_type parameter. In drivers/dax/cxl.c, the IORESOURCE_DAX_KMEM flag used by dax driver matching code is now set conditionally based on dax_region->dax_driver. Exports `enum dax_driver_type` to linux/dax.h for use in the cxl driver. All current callers pass DAXDRV_KMEM_TYPE for backward compatibility. Cc: John Groves <john@jagalactic.com> Signed-off-by: Gregory Price <gourry@gourry.net> --- drivers/cxl/core/core.h | 1 + drivers/cxl/core/region.c | 6 ++++-- drivers/cxl/cxl.h | 2 ++ drivers/dax/bus.h | 6 +----- drivers/dax/cxl.c | 6 +++++- include/linux/dax.h | 5 +++++ 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/cxl/core/core.h b/drivers/cxl/core/core.h index 1fb66132b777..dd987ef2def5 100644 --- a/drivers/cxl/core/core.h +++ b/drivers/cxl/core/core.h @@ -6,6 +6,7 @@ #include <cxl/mailbox.h> #include <linux/rwsem.h> +#include <linux/dax.h> extern const struct device_type cxl_nvdimm_bridge_type; extern const struct device_type cxl_nvdimm_type; diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index eef5d5fe3f95..e4097c464ed3 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3450,7 +3450,8 @@ static void cxlr_dax_unregister(void *_cxlr_dax) device_unregister(&cxlr_dax->dev); } -static int devm_cxl_add_dax_region(struct cxl_region *cxlr) +static int devm_cxl_add_dax_region(struct cxl_region *cxlr, + enum dax_driver_type dax_driver) { struct cxl_dax_region *cxlr_dax; struct device *dev; @@ -3461,6 +3462,7 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr) return PTR_ERR(cxlr_dax); cxlr_dax->online_type = mhp_get_default_online_type(); + cxlr_dax->dax_driver = dax_driver; dev = &cxlr_dax->dev; rc = dev_set_name(dev, "dax_region%d", cxlr->id); if (rc) @@ -3994,7 +3996,7 @@ static int cxl_region_probe(struct device *dev) p->res->start, p->res->end, cxlr, is_system_ram) > 0) return 0; - return devm_cxl_add_dax_region(cxlr); + return devm_cxl_add_dax_region(cxlr, DAXDRV_KMEM_TYPE); default: dev_dbg(&cxlr->dev, "unsupported region mode: %d\n", cxlr->mode); diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 07d57d13f4c7..c06a239c0008 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -12,6 +12,7 @@ #include <linux/node.h> #include <linux/io.h> #include <linux/range.h> +#include <linux/dax.h> extern const struct nvdimm_security_ops *cxl_security_ops; @@ -592,6 +593,7 @@ struct cxl_dax_region { struct cxl_region *cxlr; struct range hpa_range; int online_type; /* MMOP_ value for kmem driver */ + enum dax_driver_type dax_driver; }; /** diff --git a/drivers/dax/bus.h b/drivers/dax/bus.h index 4ac92a4edfe7..9144593b4029 100644 --- a/drivers/dax/bus.h +++ b/drivers/dax/bus.h @@ -2,6 +2,7 @@ /* Copyright(c) 2016 - 2018 Intel Corporation. All rights reserved. */ #ifndef __DAX_BUS_H__ #define __DAX_BUS_H__ +#include <linux/dax.h> #include <linux/device.h> #include <linux/range.h> @@ -29,11 +30,6 @@ struct dev_dax_data { struct dev_dax *devm_create_dev_dax(struct dev_dax_data *data); -enum dax_driver_type { - DAXDRV_KMEM_TYPE, - DAXDRV_DEVICE_TYPE, -}; - struct dax_device_driver { struct device_driver drv; struct list_head ids; diff --git a/drivers/dax/cxl.c b/drivers/dax/cxl.c index 856a0cd24f3b..b13ecc2f9806 100644 --- a/drivers/dax/cxl.c +++ b/drivers/dax/cxl.c @@ -11,14 +11,18 @@ static int cxl_dax_region_probe(struct device *dev) struct cxl_dax_region *cxlr_dax = to_cxl_dax_region(dev); int nid = phys_to_target_node(cxlr_dax->hpa_range.start); struct cxl_region *cxlr = cxlr_dax->cxlr; + unsigned long flags = 0; struct dax_region *dax_region; struct dev_dax_data data; + if (cxlr_dax->dax_driver == DAXDRV_KMEM_TYPE) + flags |= IORESOURCE_DAX_KMEM; + if (nid == NUMA_NO_NODE) nid = memory_add_physaddr_to_nid(cxlr_dax->hpa_range.start); dax_region = alloc_dax_region(dev, cxlr->id, &cxlr_dax->hpa_range, nid, - PMD_SIZE, IORESOURCE_DAX_KMEM); + PMD_SIZE, flags); if (!dax_region) return -ENOMEM; diff --git a/include/linux/dax.h b/include/linux/dax.h index bf103f317cac..e62f92d0ace1 100644 --- a/include/linux/dax.h +++ b/include/linux/dax.h @@ -19,6 +19,11 @@ enum dax_access_mode { DAX_RECOVERY_WRITE, }; +enum dax_driver_type { + DAXDRV_KMEM_TYPE, + DAXDRV_DEVICE_TYPE, +}; + struct dax_operations { /* * direct_access: translate a device-relative -- 2.52.0
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Thu, 29 Jan 2026 16:04:37 -0500", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
Explain the binding process for sysram and daxdev regions which are explicit about which dax driver to use during region creation. Jonathan Corbet <corbet@lwn.net> Signed-off-by: Gregory Price <gourry@gourry.net> --- .../driver-api/cxl/linux/cxl-driver.rst | 43 +++++++++++++++++++ .../driver-api/cxl/linux/dax-driver.rst | 29 +++++++++++++ 2 files changed, 72 insertions(+) diff --git a/Documentation/driver-api/cxl/linux/cxl-driver.rst b/Documentation/driver-api/cxl/linux/cxl-driver.rst index dd6dd17dc536..1f857345e896 100644 --- a/Documentation/driver-api/cxl/linux/cxl-driver.rst +++ b/Documentation/driver-api/cxl/linux/cxl-driver.rst @@ -445,6 +445,49 @@ for more details. :: dax0.0 devtype modalias uevent dax_region driver subsystem +DAX regions are created when a CXL RAM region is bound to one of the +following drivers: + +* :code:`cxl_devdax_region` - Creates a dax_region for device_dax mode. + The resulting DAX device provides direct userspace access via + :code:`/dev/daxN.Y`. + +* :code:`cxl_dax_kmem_region` - Creates a dax_region for kmem mode via a + sysram_region intermediate device. See `Sysram Region`_ below. + +Sysram Region +~~~~~~~~~~~~~ +A `Sysram Region` is an intermediate device between a CXL `Memory Region` +and a `DAX Region` for kmem mode. It is created when a CXL RAM region is +bound to the :code:`cxl_sysram_region` driver. + +The sysram_region device provides an interposition point where users can +configure memory hotplug policy before the underlying dax_region is created +and memory is hotplugged to the system. + +The device hierarchy for kmem mode is:: + + regionX -> sysram_regionX -> dax_regionX -> daxX.Y + +The sysram_region exposes an :code:`online_type` attribute that controls +how memory will be onlined when the dax_kmem driver binds: + +* :code:`invalid` - Not configured (default). Blocks driver binding. +* :code:`offline` - Memory will not be onlined automatically. +* :code:`online` - Memory will be onlined in ZONE_NORMAL. +* :code:`online_movable` - Memory will be onlined in ZONE_MOVABLE. + +Example two-stage binding process:: + + # Bind region to sysram_region driver + echo region0 > /sys/bus/cxl/drivers/cxl_sysram_region/bind + + # Configure memory online type + echo online_movable > /sys/bus/cxl/devices/sysram_region0/online_type + + # Bind sysram_region to dax_kmem_region driver + echo sysram_region0 > /sys/bus/cxl/drivers/cxl_dax_kmem_region/bind + Mailbox Interfaces ------------------ A mailbox command interface for each device is exposed in :: diff --git a/Documentation/driver-api/cxl/linux/dax-driver.rst b/Documentation/driver-api/cxl/linux/dax-driver.rst index 10d953a2167b..2b8e21736292 100644 --- a/Documentation/driver-api/cxl/linux/dax-driver.rst +++ b/Documentation/driver-api/cxl/linux/dax-driver.rst @@ -17,6 +17,35 @@ The DAX subsystem exposes this ability through the `cxl_dax_region` driver. A `dax_region` provides the translation between a CXL `memory_region` and a `DAX Device`. +CXL DAX Region Drivers +====================== +CXL provides multiple drivers for creating DAX regions, each suited for +different use cases: + +cxl_devdax_region +----------------- +The :code:`cxl_devdax_region` driver creates a dax_region configured for +device_dax mode. When a CXL RAM region is bound to this driver, the +resulting DAX device provides direct userspace access via :code:`/dev/daxN.Y`. + +Device hierarchy:: + + regionX -> dax_regionX -> daxX.Y + +This is the simplest path for applications that want to manage CXL memory +directly from userspace. + +cxl_dax_kmem_region +------------------- +For kmem mode, CXL provides a two-stage binding process that allows users +to configure memory hotplug policy before memory is added to the system. + +The :code:`cxl_dax_kmem_region` driver then binds a sysram_region +device and creates a dax_region configured for kmem mode. + +The :code:`online_type` policy will be passed from sysram_region to +the dax kmem driver for use when hotplugging the memory. + DAX Device ========== A `DAX Device` is a file-like interface exposed in :code:`/dev/daxN.Y`. A -- 2.52.0
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Thu, 29 Jan 2026 16:04:42 -0500", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
In the current kmem driver binding process, the only way for users to define hotplug policy is via a build-time option, or by not onlining memory by default and setting each individual memory block online after hotplug occurs. We can solve this with a configuration step between region-probe and dax-probe. Add the infrastructure for a two-stage driver binding for kmem-mode dax regions. The cxl_dax_kmem_region driver probes cxl_sysram_region devices and creates cxl_dax_region with dax_driver=kmem. This creates an interposition step where users can configure policy. Device hierarchy: region0 -> sysram_region0 -> dax_region0 -> dax0.0 The sysram_region device exposes a sysfs 'online_type' attribute that allows users to configure the memory online type before the underlying dax_region is created and memory is hotplugged. sysram_region0/online_type: invalid: not configured, blocks probe offline: memory will not be onlined automatically online: memory will be onlined in ZONE_NORMAL online_movable: memory will be onlined in ZONE_MMOVABLE The device initializes with online_type=invalid which prevents the cxl_dax_kmem_region driver from binding until the user explicitly configures a valid online_type. This enables a two-step binding process: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind Signed-off-by: Gregory Price <gourry@gourry.net> --- Documentation/ABI/testing/sysfs-bus-cxl | 21 +++ drivers/cxl/core/Makefile | 1 + drivers/cxl/core/core.h | 6 + drivers/cxl/core/dax_region.c | 50 +++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 14 ++ drivers/cxl/core/sysram_region.c | 180 ++++++++++++++++++++++++ drivers/cxl/cxl.h | 25 ++++ 8 files changed, 299 insertions(+) create mode 100644 drivers/cxl/core/sysram_region.c diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/testing/sysfs-bus-cxl index c80a1b5a03db..a051cb86bdfc 100644 --- a/Documentation/ABI/testing/sysfs-bus-cxl +++ b/Documentation/ABI/testing/sysfs-bus-cxl @@ -624,3 +624,24 @@ Description: The count is persistent across power loss and wraps back to 0 upon overflow. If this file is not present, the device does not have the necessary support for dirty tracking. + + +What: /sys/bus/cxl/devices/sysram_regionZ/online_type +Date: January, 2026 +KernelVersion: v7.1 +Contact: linux-cxl@vger.kernel.org +Description: + (RW) This attribute allows users to configure the memory online + type before the underlying dax_region engages in hotplug. + + Valid values: + 'invalid': Not configured (default). Blocks probe. + 'offline': Memory will not be onlined automatically. + 'online' : Memory will be onlined in ZONE_NORMAL. + 'online_movable': Memory will be onlined in ZONE_MOVABLE. + + The device initializes with online_type='invalid' which prevents + the cxl_dax_kmem_region driver from binding until the user + explicitly configures a valid online_type. This enables a + two-step binding process that gives users control over memory + hotplug policy before memory is added to the system. diff --git a/drivers/cxl/core/Makefile b/drivers/cxl/core/Makefile index 36f284d7c500..faf662c7d88b 100644 --- a/drivers/cxl/core/Makefile +++ b/drivers/cxl/core/Makefile @@ -18,6 +18,7 @@ cxl_core-y += ras.o cxl_core-$(CONFIG_TRACING) += trace.o cxl_core-$(CONFIG_CXL_REGION) += region.o cxl_core-$(CONFIG_CXL_REGION) += dax_region.o +cxl_core-$(CONFIG_CXL_REGION) += sysram_region.o cxl_core-$(CONFIG_CXL_REGION) += pmem_region.o cxl_core-$(CONFIG_CXL_MCE) += mce.o cxl_core-$(CONFIG_CXL_FEATURES) += features.o diff --git a/drivers/cxl/core/core.h b/drivers/cxl/core/core.h index ea4df8abc2ad..04b32015e9b1 100644 --- a/drivers/cxl/core/core.h +++ b/drivers/cxl/core/core.h @@ -26,6 +26,7 @@ extern struct device_attribute dev_attr_delete_region; extern struct device_attribute dev_attr_region; extern const struct device_type cxl_pmem_region_type; extern const struct device_type cxl_dax_region_type; +extern const struct device_type cxl_sysram_region_type; extern const struct device_type cxl_region_type; int cxl_decoder_detach(struct cxl_region *cxlr, @@ -37,6 +38,7 @@ int cxl_decoder_detach(struct cxl_region *cxlr, #define SET_CXL_REGION_ATTR(x) (&dev_attr_##x.attr), #define CXL_PMEM_REGION_TYPE(x) (&cxl_pmem_region_type) #define CXL_DAX_REGION_TYPE(x) (&cxl_dax_region_type) +#define CXL_SYSRAM_REGION_TYPE(x) (&cxl_sysram_region_type) int cxl_region_init(void); void cxl_region_exit(void); int cxl_get_poison_by_endpoint(struct cxl_port *port); @@ -44,9 +46,12 @@ struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa); u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd, u64 dpa); int devm_cxl_add_dax_region(struct cxl_region *cxlr, enum dax_driver_type); +int devm_cxl_add_sysram_region(struct cxl_region *cxlr); int devm_cxl_add_pmem_region(struct cxl_region *cxlr); extern struct cxl_driver cxl_devdax_region_driver; +extern struct cxl_driver cxl_dax_kmem_region_driver; +extern struct cxl_driver cxl_sysram_region_driver; #else static inline u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, @@ -81,6 +86,7 @@ static inline void cxl_region_exit(void) #define SET_CXL_REGION_ATTR(x) #define CXL_PMEM_REGION_TYPE(x) NULL #define CXL_DAX_REGION_TYPE(x) NULL +#define CXL_SYSRAM_REGION_TYPE(x) NULL #endif struct cxl_send_command; diff --git a/drivers/cxl/core/dax_region.c b/drivers/cxl/core/dax_region.c index 391d51e5ec37..a379f5b85e3d 100644 --- a/drivers/cxl/core/dax_region.c +++ b/drivers/cxl/core/dax_region.c @@ -127,3 +127,53 @@ struct cxl_driver cxl_devdax_region_driver = { .probe = cxl_devdax_region_driver_probe, .id = CXL_DEVICE_REGION, }; + +static int cxl_dax_kmem_region_driver_probe(struct device *dev) +{ + struct cxl_sysram_region *cxlr_sysram = to_cxl_sysram_region(dev); + struct cxl_dax_region *cxlr_dax; + struct cxl_region *cxlr; + int rc; + + if (!cxlr_sysram) + return -ENODEV; + + /* Require explicit online_type configuration before binding */ + if (cxlr_sysram->online_type == -1) + return -ENODEV; + + cxlr = cxlr_sysram->cxlr; + + cxlr_dax = cxl_dax_region_alloc(cxlr); + if (IS_ERR(cxlr_dax)) + return PTR_ERR(cxlr_dax); + + /* Inherit online_type from parent sysram_region */ + cxlr_dax->online_type = cxlr_sysram->online_type; + cxlr_dax->dax_driver = DAXDRV_KMEM_TYPE; + + /* Parent is the sysram_region device */ + cxlr_dax->dev.parent = dev; + + rc = dev_set_name(&cxlr_dax->dev, "dax_region%d", cxlr->id); + if (rc) + goto err; + + rc = device_add(&cxlr_dax->dev); + if (rc) + goto err; + + dev_dbg(dev, "%s: register %s\n", dev_name(dev), + dev_name(&cxlr_dax->dev)); + + return devm_add_action_or_reset(dev, cxlr_dax_unregister, cxlr_dax); +err: + put_device(&cxlr_dax->dev); + return rc; +} + +struct cxl_driver cxl_dax_kmem_region_driver = { + .name = "cxl_dax_kmem_region", + .probe = cxl_dax_kmem_region_driver_probe, + .id = CXL_DEVICE_SYSRAM_REGION, +}; diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c index 3310dbfae9d6..dc7262a5efd6 100644 --- a/drivers/cxl/core/port.c +++ b/drivers/cxl/core/port.c @@ -66,6 +66,8 @@ static int cxl_device_id(const struct device *dev) return CXL_DEVICE_PMEM_REGION; if (dev->type == CXL_DAX_REGION_TYPE()) return CXL_DEVICE_DAX_REGION; + if (dev->type == CXL_SYSRAM_REGION_TYPE()) + return CXL_DEVICE_SYSRAM_REGION; if (is_cxl_port(dev)) { if (is_cxl_root(to_cxl_port(dev))) return CXL_DEVICE_ROOT; diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 6200ca1cc2dd..8bef91dc726c 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3734,8 +3734,20 @@ int cxl_region_init(void) if (rc) goto err_dax; + rc = cxl_driver_register(&cxl_sysram_region_driver); + if (rc) + goto err_sysram; + + rc = cxl_driver_register(&cxl_dax_kmem_region_driver); + if (rc) + goto err_dax_kmem; + return 0; +err_dax_kmem: + cxl_driver_unregister(&cxl_sysram_region_driver); +err_sysram: + cxl_driver_unregister(&cxl_devdax_region_driver); err_dax: cxl_driver_unregister(&cxl_region_driver); return rc; @@ -3743,6 +3755,8 @@ int cxl_region_init(void) void cxl_region_exit(void) { + cxl_driver_unregister(&cxl_dax_kmem_region_driver); + cxl_driver_unregister(&cxl_sysram_region_driver); cxl_driver_unregister(&cxl_devdax_region_driver); cxl_driver_unregister(&cxl_region_driver); } diff --git a/drivers/cxl/core/sysram_region.c b/drivers/cxl/core/sysram_region.c new file mode 100644 index 000000000000..5665db238d0f --- /dev/null +++ b/drivers/cxl/core/sysram_region.c @@ -0,0 +1,180 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright(c) 2026 Meta Platforms, Inc. All rights reserved. */ +/* + * CXL Sysram Region - Intermediate device for kmem hotplug configuration + * + * This provides an intermediate device between cxl_region and cxl_dax_region + * that allows users to configure memory hotplug parameters (like online_type) + * before the underlying dax_region is created and memory is hotplugged. + */ + +#include <linux/memory_hotplug.h> +#include <linux/device.h> +#include <linux/slab.h> +#include <cxlmem.h> +#include <cxl.h> +#include "core.h" + +static void cxl_sysram_region_release(struct device *dev) +{ + struct cxl_sysram_region *cxlr_sysram = to_cxl_sysram_region(dev); + + kfree(cxlr_sysram); +} + +static ssize_t online_type_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct cxl_sysram_region *cxlr_sysram = to_cxl_sysram_region(dev); + + switch (cxlr_sysram->online_type) { + case MMOP_OFFLINE: + return sysfs_emit(buf, "offline\n"); + case MMOP_ONLINE: + return sysfs_emit(buf, "online\n"); + case MMOP_ONLINE_MOVABLE: + return sysfs_emit(buf, "online_movable\n"); + default: + return sysfs_emit(buf, "invalid\n"); + } +} + +static ssize_t online_type_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct cxl_sysram_region *cxlr_sysram = to_cxl_sysram_region(dev); + + if (sysfs_streq(buf, "offline")) + cxlr_sysram->online_type = MMOP_OFFLINE; + else if (sysfs_streq(buf, "online")) + cxlr_sysram->online_type = MMOP_ONLINE; + else if (sysfs_streq(buf, "online_movable")) + cxlr_sysram->online_type = MMOP_ONLINE_MOVABLE; + else + return -EINVAL; + + return len; +} + +static DEVICE_ATTR_RW(online_type); + +static struct attribute *cxl_sysram_region_attrs[] = { + &dev_attr_online_type.attr, + NULL, +}; + +static const struct attribute_group cxl_sysram_region_attribute_group = { + .attrs = cxl_sysram_region_attrs, +}; + +static const struct attribute_group *cxl_sysram_region_attribute_groups[] = { + &cxl_base_attribute_group, + &cxl_sysram_region_attribute_group, + NULL, +}; + +const struct device_type cxl_sysram_region_type = { + .name = "cxl_sysram_region", + .release = cxl_sysram_region_release, + .groups = cxl_sysram_region_attribute_groups, +}; + +static bool is_cxl_sysram_region(struct device *dev) +{ + return dev->type == &cxl_sysram_region_type; +} + +struct cxl_sysram_region *to_cxl_sysram_region(struct device *dev) +{ + if (dev_WARN_ONCE(dev, !is_cxl_sysram_region(dev), + "not a cxl_sysram_region device\n")) + return NULL; + return container_of(dev, struct cxl_sysram_region, dev); +} +EXPORT_SYMBOL_NS_GPL(to_cxl_sysram_region, "CXL"); + +static struct lock_class_key cxl_sysram_region_key; + +static struct cxl_sysram_region *cxl_sysram_region_alloc(struct cxl_region *cxlr) +{ + struct cxl_region_params *p = &cxlr->params; + struct cxl_sysram_region *cxlr_sysram; + struct device *dev; + + guard(rwsem_read)(&cxl_rwsem.region); + if (p->state != CXL_CONFIG_COMMIT) + return ERR_PTR(-ENXIO); + + cxlr_sysram = kzalloc(sizeof(*cxlr_sysram), GFP_KERNEL); + if (!cxlr_sysram) + return ERR_PTR(-ENOMEM); + + cxlr_sysram->hpa_range.start = p->res->start; + cxlr_sysram->hpa_range.end = p->res->end; + cxlr_sysram->online_type = -1; /* Require explicit configuration */ + + dev = &cxlr_sysram->dev; + cxlr_sysram->cxlr = cxlr; + device_initialize(dev); + lockdep_set_class(&dev->mutex, &cxl_sysram_region_key); + device_set_pm_not_required(dev); + dev->parent = &cxlr->dev; + dev->bus = &cxl_bus_type; + dev->type = &cxl_sysram_region_type; + + return cxlr_sysram; +} + +static void cxlr_sysram_unregister(void *_cxlr_sysram) +{ + struct cxl_sysram_region *cxlr_sysram = _cxlr_sysram; + + device_unregister(&cxlr_sysram->dev); +} + +int devm_cxl_add_sysram_region(struct cxl_region *cxlr) +{ + struct cxl_sysram_region *cxlr_sysram; + struct device *dev; + int rc; + + cxlr_sysram = cxl_sysram_region_alloc(cxlr); + if (IS_ERR(cxlr_sysram)) + return PTR_ERR(cxlr_sysram); + + dev = &cxlr_sysram->dev; + rc = dev_set_name(dev, "sysram_region%d", cxlr->id); + if (rc) + goto err; + + rc = device_add(dev); + if (rc) + goto err; + + dev_dbg(&cxlr->dev, "%s: register %s\n", dev_name(dev->parent), + dev_name(dev)); + + return devm_add_action_or_reset(&cxlr->dev, cxlr_sysram_unregister, + cxlr_sysram); +err: + put_device(dev); + return rc; +} + +static int cxl_sysram_region_driver_probe(struct device *dev) +{ + struct cxl_region *cxlr = to_cxl_region(dev); + + /* Only handle RAM regions */ + if (cxlr->mode != CXL_PARTMODE_RAM) + return -ENODEV; + + return devm_cxl_add_sysram_region(cxlr); +} + +struct cxl_driver cxl_sysram_region_driver = { + .name = "cxl_sysram_region", + .probe = cxl_sysram_region_driver_probe, + .id = CXL_DEVICE_REGION, +}; diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 674d5f870c70..1544c27e9c89 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -596,6 +596,25 @@ struct cxl_dax_region { enum dax_driver_type dax_driver; }; +/** + * struct cxl_sysram_region - CXL RAM region for system memory hotplug + * @dev: device for this sysram_region + * @cxlr: parent cxl_region + * @hpa_range: Host physical address range for the region + * @online_type: Memory online type (MMOP_* 0-3, or -1 if not configured) + * + * Intermediate device that allows configuration of memory hotplug + * parameters before the underlying dax_region is created. The device + * starts with online_type=-1 which prevents the cxl_dax_kmem_region + * driver from binding until the user explicitly sets online_type. + */ +struct cxl_sysram_region { + struct device dev; + struct cxl_region *cxlr; + struct range hpa_range; + int online_type; +}; + /** * struct cxl_port - logical collection of upstream port devices and * downstream port devices to construct a CXL memory @@ -890,6 +909,7 @@ void cxl_driver_unregister(struct cxl_driver *cxl_drv); #define CXL_DEVICE_PMEM_REGION 7 #define CXL_DEVICE_DAX_REGION 8 #define CXL_DEVICE_PMU 9 +#define CXL_DEVICE_SYSRAM_REGION 10 #define MODULE_ALIAS_CXL(type) MODULE_ALIAS("cxl:t" __stringify(type) "*") #define CXL_MODALIAS_FMT "cxl:t%d" @@ -907,6 +927,7 @@ bool is_cxl_pmem_region(struct device *dev); struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev); int cxl_add_to_region(struct cxl_endpoint_decoder *cxled); struct cxl_dax_region *to_cxl_dax_region(struct device *dev); +struct cxl_sysram_region *to_cxl_sysram_region(struct device *dev); u64 cxl_port_get_spa_cache_alias(struct cxl_port *endpoint, u64 spa); #else static inline bool is_cxl_pmem_region(struct device *dev) @@ -925,6 +946,10 @@ static inline struct cxl_dax_region *to_cxl_dax_region(struct device *dev) { return NULL; } +static inline struct cxl_sysram_region *to_cxl_sysram_region(struct device *dev) +{ + return NULL; +} static inline u64 cxl_port_get_spa_cache_alias(struct cxl_port *endpoint, u64 spa) { -- 2.52.0
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Thu, 29 Jan 2026 16:04:41 -0500", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
Annoyingly, my email client has been truncating my titles: cxl: explicit DAX driver selection and hotplug policy for CXL regions ~Gregory
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Thu, 29 Jan 2026 16:17:55 -0500", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Thu, Jan 29, 2026 at 04:04:33PM -0500, Gregory Price wrote: Looks like build regression on configs without hotplug MMOP_ defines and mhp_get_default_online_type() undefined Will let this version sit for a bit before spinning a v2 ~Gregory
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Fri, 30 Jan 2026 12:34:33 -0500", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On 1/29/2026 3:04 PM, Gregory Price wrote: This technically comes up in the devdax_region driver patch first, but I noticed it here so this is where I'm putting it: I like the idea here, but the implementation is all off. Firstly, devm_cxl_add_sysram_region() is never called outside of sysram_region_driver::probe(), so I'm not sure how they ever get added to the system (same with devdax regions). Second, there's this weird pattern of adding sub-region (sysram, devdax, etc.) devices being added inside of the sub-region driver probe. I would expect the devices are added then the probe function is called. What I think should be going on here (and correct me if I'm wrong) is: 1. a cxl_region device is added to the system 2. cxl_region::probe() is called on said device (one in cxl/core/region.c) 3. Said probe function figures out the device is a dax_region or whatever else and creates that type of region device (i.e. cxl_region::probe() -> device_add(&cxl_sysram_device)) 4. if the device's dax driver type is DAXDRV_DEVICE_TYPE it gets sent to the daxdev_region driver 5a. if the device's dax driver type is DAXDRV_KMEM_TYPE it gets sent to the sysram_region driver which holds it until the online_type is set 5b. Once the online_type is set, the device is forwarded to the dax_kmem_region driver? Not sure on this part What seems to be happening is that the cxl_region is added, all of these region drivers try to bind to it since they all use the same device id (CXL_DEVICE_REGION) and the correct one is figured out by magic? I'm somewhat confused at this point :/. This should be removed from the valid values section since it's not a valid value to write to the attribute. The mention of the default in the paragraph below should be enough. You can use cleanup.h here to remove the goto's (I think). Following should work: #DEFINE_FREE(cxlr_dax_region_put, struct cxl_dax_region *, if (!IS_ERR_OR_NULL(_T)) put_device(&cxlr_dax->dev)) static int cxl_dax_kmem_region_driver_probe(struct device *dev) { ... struct cxl_dax_region *cxlr_dax __free(cxlr_dax_region_put) = cxl_dax_region_alloc(cxlr); if (IS_ERR(cxlr_dax)) return PTR_ERR(cxlr_dax); ... rc = dev_set_name(&cxlr_dax->dev, "dax_region%d", cxlr->id); if (rc) return rc; rc = device_add(&cxlr_dax->dev); if (rc) return rc; dev_dbg(dev, "%s: register %s\n", dev_name(dev), dev_name(&cxlr_dax->dev)); return devm_add_action_or_reset(dev, cxlr_dax_unregister, no_free_ptr(cxlr_dax)); } Same thing as above Thanks, Ben
{ "author": "\"Cheatham, Benjamin\" <benjamin.cheatham@amd.com>", "date": "Fri, 30 Jan 2026 15:27:12 -0600", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Fri, Jan 30, 2026 at 03:27:12PM -0600, Cheatham, Benjamin wrote: I originally tried doing with region0/region_driver, but that design pattern is also confusing - and it creates differently bad patterns. echo region0 > decoder0.0/create_ram_region -> creates region0 # Current pattern echo region > driver/region/probe /* auto-region behavior */ # region_driver attribute pattern echo "sysram" > region0/region_driver echo region0 > driver/region/probe /* uses sysram region driver */ https://lore.kernel.org/linux-cxl/20260113202138.3021093-1-gourry@gourry.net/ Ira pointed out that this design makes the "implicit" design of the driver worse. The user doesn't actually know what driver is being used under the hood - it just knows something is being used. This at least makes it explicit which driver is being used - and splits the uses-case logic up into discrete drivers (dax users don't have to worry about sysram users breaking their stuff). If it makes more sense, you could swap the ordering of the names echo region0 > region/bind echo region0 > region_sysram/bind echo region0 > region_daxdev/bind echo region0 > region_dax_kmem/bind echo region0 > region_pony/bind --- The underlying issue is that region::probe() is trying to be a god-function for every possible use case, and hiding the use case behind an attribute vs a driver is not good. (also the default behavior for region::probe() in an otherwise unconfigured region is required for backwards compatibility) For auto-regions: region_probe() eats it and you get the default behavior. For non-auto regions: create_x_region generates an un-configured region and fails to probe until the user commits it and probes it. auto-regions are evil and should be discouraged. ~Gregory
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Fri, 30 Jan 2026 17:12:50 -0500", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On 1/30/2026 4:12 PM, Gregory Price wrote: Ok, that makes sense. I think I just got lost in the sauce while looking at this last week and this explanation helped a lot.> I think this was the source of my misunderstanding. I was trying to understand how it works for auto regions when it's never meant to apply to them. Sorry if this is a stupid question, but what stops auto regions from binding to the sysram/dax region drivers? They all bind to region devices, so I assume there's something keeping them from binding before the core region driver gets a chance. Thanks, Ben
{ "author": "\"Cheatham, Benjamin\" <benjamin.cheatham@amd.com>", "date": "Mon, 2 Feb 2026 11:02:37 -0600", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Thu, 29 Jan 2026 16:04:34 -0500 Gregory Price <gourry@gourry.net> wrote: Trivial comment inline. I don't really care either way. Pushing the policy up to the caller and ensuring it's explicitly constant for all the memory blocks (as opposed to relying on locks) seems sensible to me even without anything else. Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Maybe move the local variable outside the loop to avoid the double call.
{ "author": "Jonathan Cameron <jonathan.cameron@huawei.com>", "date": "Mon, 2 Feb 2026 17:10:29 +0000", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Thu, 29 Jan 2026 16:04:35 -0500 Gregory Price <gourry@gourry.net> wrote: Hi Gregory, I think maybe I'd have left the export for the first user outside of memory_hotplug.c. Not particularly important however. Maybe talk about why a caller of __add_memory_driver_managed() might want the default? Feels like that's for the people who don't... Or is this all a dance to avoid an if (special mode) __add_memory_driver_managed(); else add_memory_driver_managed(); ? Other comments are mostly about using a named enum. I'm not sure if there is some existing reason why that doesn't work? -Errno pushed through this variable or anything like that? Given online_type values are from an enum anyway, maybe we can name that enum and use it explicitly? Ah. Fair enough, ignore comment in previous patch. I should have read on... It's a little odd to add nice kernel-doc formatted documentation when the non __ variant has free form docs. Maybe tidy that up first if we want to go kernel-doc in this file? (I'm in favor, but no idea on general feelings...) Given that's currently the full set, seems like enum wins out here over an int. This is where using an enum would help compiler know what is going on and maybe warn if anyone writes something that isn't defined.
{ "author": "Jonathan Cameron <jonathan.cameron@huawei.com>", "date": "Mon, 2 Feb 2026 17:25:24 +0000", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Mon, Feb 02, 2026 at 11:02:37AM -0600, Cheatham, Benjamin wrote: Auto regions explicitly use the dax_kmem path (all existing code, unchanged)- which auto-plugs into dax/hotplug. I do get what you're saying that everything binds on a region type, I will look a little closer at this and see if there's something more reasonable we can do. I think i can update `region/bind` to use the sysram driver with online_type=mhp_default_online_type so you'd end up with effective the auto-region logic: cxlcli create-region -m ram ... existing argument set ------ echo region0 > create_ram_region /* program decoders */ echo region0 > region/bind /* * region_bind(): * 1) alloc sysram_region object * 2) sysram_regionN->online_type=mhp_default_online_type() * 3) add device to bus * 4) device auto-probes all the way down to dax * 5) dax auto-onlines with system default setting */ ------ and Non-auto-region logic (approximation) cxlcli creation-region -m ram --type sysram --online-type=movable ----- echo region0 > create_ram_region /* program decoders */ echo region0 > sysram/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > dax_kmem/bind ----- I want to retain the dax_kmem driver because there may be multiple users other than sysram. For example, a compressed memory region wants to utilize dax_kmem, but has its own complex policy (via N_MEMORY_PRIVATE) so it doesn't want to abstract through sysram_region, but it does want to abstract through dax_kmem. weeeee "software defined memory" weeeee ~Gregory
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Mon, 2 Feb 2026 12:41:31 -0500", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Mon, Feb 02, 2026 at 05:10:29PM +0000, Jonathan Cameron wrote: ack. will update for next version w/ Ben's notes and the build fix. Thanks! ~Gregory
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Mon, 2 Feb 2026 12:46:25 -0500", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Thu, 29 Jan 2026 16:04:37 -0500 Gregory Price <gourry@gourry.net> wrote: LGTM Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
{ "author": "Jonathan Cameron <jonathan.cameron@huawei.com>", "date": "Mon, 2 Feb 2026 17:54:17 +0000", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Thu, 29 Jan 2026 16:04:38 -0500 Gregory Price <gourry@gourry.net> wrote: Needs to answer the question: Why? Minor stuff inline. Maybe sneak in dropping that trailing comma whilst you are moving it. ... Bonus line...
{ "author": "Jonathan Cameron <jonathan.cameron@huawei.com>", "date": "Mon, 2 Feb 2026 17:56:40 +0000", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Thu, 29 Jan 2026 16:04:39 -0500 Gregory Price <gourry@gourry.net> wrote: Likewise. Why?
{ "author": "Jonathan Cameron <jonathan.cameron@huawei.com>", "date": "Mon, 2 Feb 2026 17:57:11 +0000", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Mon, Feb 02, 2026 at 05:25:24PM +0000, Jonathan Cameron wrote: Less about why they want the default, more about maintaining backward compatibility. In the cxl driver, Ben pointed out something that made me realize we can change `region/bind()` to actually use the new `sysram/bind` path by just adding a one line `sysram_regionN->online_type = default()` I can add this detail to the changelog. I can add a cleanup-patch prior to use the enum, but i don't think this actually enables the compiler to do anything new at the moment? An enum just resolves to an int, and setting `enum thing val = -1` when the enum definition doesn't include -1 doesn't actually fire any errors (at least IIRC - maybe i'm just wrong). Same with function(enum) -> function(-1) wouldn't fire a compilation error It might actually be worth adding `MMOP_NOT_CONFIGURED = -1` so that the cxl-sysram driver can set this explicitly rather than just setting -1 as an implicit version of this - but then why would memory_hotplug.c ever want to expose a NOT_CONFIGURED option lol. So, yeah, the enum looks nicer, but not sure how much it buys us beyond that. ack. Can add some more cleanups early in the series. I think you still have to sanity check this, but maybe the code looks cleaner, so will do. ~Gregory
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Mon, 2 Feb 2026 13:02:10 -0500", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Thu, 29 Jan 2026 16:04:41 -0500 Gregory Price <gourry@gourry.net> wrote: ZONE_MOVABLE Trivial stuff. Will mull over this series as a whole... My first instinctive reaction is positive - I'm just wondering where additional drivers fit into this and whether it has the right degree of flexibility. This smells like a loop over an array of drivers is becoming sensible. As below. Trivial, but don't want a comma on that NULL. Ah. An there's our reason for an int. Can we just add a MMOP enum value for not configured yet and so let us use it as an enum? Or have a separate bool for that and ignore the online_type until it's set.
{ "author": "Jonathan Cameron <jonathan.cameron@huawei.com>", "date": "Mon, 2 Feb 2026 18:20:15 +0000", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Mon, Feb 02, 2026 at 06:20:15PM +0000, Jonathan Cameron wrote: I think the latter is more reasonably, MMOP_UNCONFIGURED doesn't much make sense for memory_hotplug.c ack. ~Gregory
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Mon, 2 Feb 2026 13:23:37 -0500", "thread_id": "aYDrqVEOwkGfv2JG@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH v11 0/3] rust: leds: add led classdev abstractions
This patch series has previously been contained in https://lore.kernel.org/rust-for-linux/20251008181027.662616-1-markus.probst@posteo.de/T/#t which added a rust written led driver for a microcontroller via i2c. As the reading and writing to the i2c client via the register! macro has not been implemented yet [1], the patch series will only contain the additional abstractions required. [1] https://lore.kernel.org/rust-for-linux/DDDS2V0V2NVJ.16ZKXCKUA1HUV@kernel.org/ The following changes were made: * add basic led classdev abstractions to register and unregister leds * add basic led classdev abstractions to register and unregister multicolor leds Changes since v10: * allow in-place initialization of `LedOps` * run rustfmt for code inside `try_pin_init!` Changes since v9: * add missing periods in documentation * duplicate `led::Device` and `led::Adapter` instead of using a complex trait * fix imports not using prelude * adapt to CStr change * documented `led::Color::Multi` and `led::Color::Rgb` Changes since v8: * accept `Option<ARef<Fwnode>>` in `led::InitData::fwnode()` * make functions in `MultiColorSubLed` const * drop the "rust: Add trait to convert a device reference to a bus device reference" patch, as it has been picked into driver-core Changes since v7: * adjusted import style * added classdev parameter to callback functions in `LedOps` * implement `led::Color` * extend `led::InitData` with - initial_brightness - default_trigger - default_color * split generic and normal led classdev abstractions up (see patch 3/4) * add multicolor led class device abstractions (see patch 4/4) * added MAINTAINERS entry Changes since v6: * fixed typos * improved documentation Changes since v5: * rename `IntoBusDevice` trait into `AsBusDevice` * fix documentation about `LedOps::BLOCKING` * removed dependency on i2c bindings * added `AsBusDevice` implementation for `platform::Device` * removed `device::Device` fallback implementation * document that `AsBusDevice` must not be used by drivers and is intended for bus and class device abstractions only. Changes since v4: * add abstraction to convert a device reference to a bus device reference * require the bus device as parent device and provide it in class device callbacks * remove Pin<Vec<_>> abstraction (as not relevant for the led abstractions) * fixed formatting in `led::Device::new` * fixed `LedOps::BLOCKING` did the inverse effect Changes since v3: * fixed kunit tests failing because of example in documentation Changes since v2: * return `Devres` on `led::Device` creation * replace KBox<T> with T in struct definition * increment and decrement reference-count of fwnode * make a device parent mandatory for led classdev creation * rename `led::Handler` to `led::LedOps` * add optional `brightness_get` function to `led::LedOps` * use `#[vtable]` instead of `const BLINK: bool` * use `Opaque::cast_from` instead of casting a pointer * improve documentation * improve support for older rust versions * use `&Device<Bound>` for parent Changes since v1: * fixed typos noticed by Onur Özkan Signed-off-by: Markus Probst <markus.probst@posteo.de> --- Markus Probst (3): rust: leds: add basic led classdev abstractions rust: leds: split generic and normal led classdev abstractions up rust: leds: add multicolor classdev abstractions MAINTAINERS | 8 + rust/bindings/bindings_helper.h | 1 + rust/kernel/led.rs | 300 +++++++++++++++++++++++++++++++ rust/kernel/led/multicolor.rs | 382 ++++++++++++++++++++++++++++++++++++++++ rust/kernel/led/normal.rs | 226 ++++++++++++++++++++++++ rust/kernel/lib.rs | 1 + 6 files changed, 918 insertions(+) --- base-commit: 18f7fcd5e69a04df57b563360b88be72471d6b62 change-id: 20251114-rust_leds-a959f7c2f7f9
Implement the core abstractions needed for led class devices, including: * `led::LedOps` - the trait for handling leds, including `brightness_set`, `brightness_get` and `blink_set` * `led::InitData` - data set for the led class device * `led::Device` - a safe wrapper around `led_classdev` Signed-off-by: Markus Probst <markus.probst@posteo.de> --- MAINTAINERS | 7 + rust/kernel/led.rs | 453 +++++++++++++++++++++++++++++++++++++++++++++++++++++ rust/kernel/lib.rs | 1 + 3 files changed, 461 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 0efa8cc6775b..26765fecb9a9 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14279,6 +14279,13 @@ F: drivers/leds/ F: include/dt-bindings/leds/ F: include/linux/leds.h +LED SUBSYSTEM [RUST] +M: Markus Probst <markus.probst@posteo.de> +L: linux-leds@vger.kernel.org +L: rust-for-linux@vger.kernel.org +S: Maintained +F: rust/kernel/led.rs + LEGO MINDSTORMS EV3 R: David Lechner <david@lechnology.com> S: Maintained diff --git a/rust/kernel/led.rs b/rust/kernel/led.rs new file mode 100644 index 000000000000..9acb6946f3da --- /dev/null +++ b/rust/kernel/led.rs @@ -0,0 +1,453 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Abstractions for the leds driver model. +//! +//! C header: [`include/linux/leds.h`](srctree/include/linux/leds.h) + +use core::{ + marker::PhantomData, + mem::transmute, + ptr::NonNull, // +}; + +use crate::{ + container_of, + device::{ + self, + property::FwNode, + AsBusDevice, + Bound, // + }, + devres::Devres, + error::{ + from_result, + to_result, + VTABLE_DEFAULT_ERROR, // + }, + macros::vtable, + prelude::*, + str::CStrExt, + types::{ + ARef, + Opaque, // + }, // +}; + +/// The led class device representation. +/// +/// This structure represents the Rust abstraction for a C `struct led_classdev`. +#[pin_data(PinnedDrop)] +pub struct Device<T: LedOps> { + #[pin] + ops: T, + #[pin] + classdev: Opaque<bindings::led_classdev>, +} + +/// The led init data representation. +/// +/// This structure represents the Rust abstraction for a C `struct led_init_data` with additional +/// fields from `struct led_classdev`. +#[derive(Default)] +pub struct InitData<'a> { + fwnode: Option<ARef<FwNode>>, + devicename: Option<&'a CStr>, + devname_mandatory: bool, + initial_brightness: u32, + default_trigger: Option<&'a CStr>, + color: Color, +} + +impl InitData<'static> { + /// Creates a new [`InitData`]. + pub fn new() -> Self { + Self::default() + } +} + +impl<'a> InitData<'a> { + /// Sets the firmware node. + pub fn fwnode(self, fwnode: Option<ARef<FwNode>>) -> Self { + Self { fwnode, ..self } + } + + /// Sets the device name. + pub fn devicename(self, devicename: &'a CStr) -> Self { + Self { + devicename: Some(devicename), + ..self + } + } + + /// Sets if a device name is mandatory. + pub fn devicename_mandatory(self, mandatory: bool) -> Self { + Self { + devname_mandatory: mandatory, + ..self + } + } + + /// Sets the initial brightness value for the led. + /// + /// The default brightness is 0. + /// If [`LedOps::brightness_get`] is implemented, this value will be ignored. + pub fn initial_brightness(self, brightness: u32) -> Self { + Self { + initial_brightness: brightness, + ..self + } + } + + /// Set the default led trigger. + /// + /// This value can be overwritten by the "linux,default-trigger" fwnode property. + pub fn default_trigger(self, trigger: &'a CStr) -> Self { + Self { + default_trigger: Some(trigger), + ..self + } + } + + /// Sets the color of the led. + /// + /// This value can be overwritten by the "color" fwnode property. + pub fn color(self, color: Color) -> Self { + Self { color, ..self } + } +} + +/// Trait defining the operations for a LED driver. +/// +/// # Examples +/// ``` +/// use kernel::{ +/// device, +/// devres::Devres, +/// led, +/// macros::vtable, +/// platform, +/// prelude::*, // +/// }; +/// +/// struct MyLedOps; +/// +/// +/// #[vtable] +/// impl led::LedOps for MyLedOps { +/// type Bus = platform::Device<device::Bound>; +/// const BLOCKING: bool = false; +/// const MAX_BRIGHTNESS: u32 = 255; +/// +/// fn brightness_set( +/// &self, +/// _dev: &platform::Device<device::Bound>, +/// _classdev: &led::Device<Self>, +/// _brightness: u32 +/// ) -> Result<()> { +/// // Set the brightness for the led here +/// Ok(()) +/// } +/// } +/// +/// fn register_my_led( +/// parent: &platform::Device<device::Bound>, +/// ) -> Result<Pin<KBox<Devres<led::Device<MyLedOps>>>>> { +/// KBox::pin_init(led::Device::new( +/// parent, +/// led::InitData::new(), +/// Ok(MyLedOps), +/// ), GFP_KERNEL) +/// } +/// ``` +/// Led drivers must implement this trait in order to register and handle a [`Device`]. +#[vtable] +pub trait LedOps: Send + 'static + Sized { + /// The bus device required by the implementation. + #[allow(private_bounds)] + type Bus: AsBusDevice<Bound>; + /// If set true, [`LedOps::brightness_set`] and [`LedOps::blink_set`] must perform the + /// operation immediately. If set false, they must not sleep. + const BLOCKING: bool; + /// The max brightness level. + const MAX_BRIGHTNESS: u32; + + /// Sets the brightness level. + /// + /// See also [`LedOps::BLOCKING`]. + fn brightness_set( + &self, + dev: &Self::Bus, + classdev: &Device<Self>, + brightness: u32, + ) -> Result<()>; + + /// Gets the current brightness level. + fn brightness_get(&self, _dev: &Self::Bus, _classdev: &Device<Self>) -> u32 { + build_error!(VTABLE_DEFAULT_ERROR) + } + + /// Activates hardware accelerated blinking. + /// + /// delays are in milliseconds. If both are zero, a sensible default should be chosen. + /// The caller should adjust the timings in that case and if it can't match the values + /// specified exactly. Setting the brightness to 0 will disable the hardware accelerated + /// blinking. + /// + /// See also [`LedOps::BLOCKING`]. + fn blink_set( + &self, + _dev: &Self::Bus, + _classdev: &Device<Self>, + _delay_on: &mut usize, + _delay_off: &mut usize, + ) -> Result<()> { + build_error!(VTABLE_DEFAULT_ERROR) + } +} + +/// Led colors. +#[derive(Copy, Clone, Debug, Default)] +#[repr(u32)] +#[non_exhaustive] +#[expect( + missing_docs, + reason = "it shouldn't be necessary to document each color" +)] +pub enum Color { + #[default] + White = bindings::LED_COLOR_ID_WHITE, + Red = bindings::LED_COLOR_ID_RED, + Green = bindings::LED_COLOR_ID_GREEN, + Blue = bindings::LED_COLOR_ID_BLUE, + Amber = bindings::LED_COLOR_ID_AMBER, + Violet = bindings::LED_COLOR_ID_VIOLET, + Yellow = bindings::LED_COLOR_ID_YELLOW, + Ir = bindings::LED_COLOR_ID_IR, + Multi = bindings::LED_COLOR_ID_MULTI, + Rgb = bindings::LED_COLOR_ID_RGB, + Purple = bindings::LED_COLOR_ID_PURPLE, + Orange = bindings::LED_COLOR_ID_ORANGE, + Pink = bindings::LED_COLOR_ID_PINK, + Cyan = bindings::LED_COLOR_ID_CYAN, + Lime = bindings::LED_COLOR_ID_LIME, +} + +impl TryFrom<u32> for Color { + type Error = Error; + + fn try_from(value: u32) -> core::result::Result<Self, Self::Error> { + const _: () = { + assert!(bindings::LED_COLOR_ID_MAX == 15); + }; + if value < bindings::LED_COLOR_ID_MAX { + // SAFETY: + // - `Color` is represented as `u32` + // - the const block above guarantees that no additional color has been added + // - `value` is guaranteed to be in the color id range + Ok(unsafe { transmute::<u32, Color>(value) }) + } else { + Err(EINVAL) + } + } +} + +// SAFETY: A `led::Device` can be unregistered from any thread. +unsafe impl<T: LedOps + Send> Send for Device<T> {} + +// SAFETY: `led::Device` can be shared among threads because all methods of `led::Device` +// are thread safe. +unsafe impl<T: LedOps + Sync> Sync for Device<T> {} + +impl<T: LedOps> Device<T> { + /// Registers a new led classdev. + /// + /// The [`Device`] will be unregistered on drop. + pub fn new<'a>( + parent: &'a T::Bus, + init_data: InitData<'a>, + ops: impl PinInit<T, Error> + 'a, + ) -> impl PinInit<Devres<Self>, Error> + 'a { + Devres::new( + parent.as_ref(), + try_pin_init!(Self { + ops <- ops, + classdev <- Opaque::try_ffi_init(|ptr: *mut bindings::led_classdev| { + // SAFETY: `try_ffi_init` guarantees that `ptr` is valid for write. + // `led_classdev` gets fully initialized in-place by + // `led_classdev_register_ext` including `mutex` and `list_head`. + unsafe { + ptr.write(bindings::led_classdev { + brightness_set: (!T::BLOCKING) + .then_some(Adapter::<T>::brightness_set_callback), + brightness_set_blocking: T::BLOCKING + .then_some(Adapter::<T>::brightness_set_blocking_callback), + brightness_get: T::HAS_BRIGHTNESS_GET + .then_some(Adapter::<T>::brightness_get_callback), + blink_set: T::HAS_BLINK_SET.then_some(Adapter::<T>::blink_set_callback), + max_brightness: T::MAX_BRIGHTNESS, + brightness: init_data.initial_brightness, + default_trigger: init_data + .default_trigger + .map_or(core::ptr::null(), CStrExt::as_char_ptr), + color: init_data.color as u32, + ..bindings::led_classdev::default() + }) + }; + + let mut init_data_raw = bindings::led_init_data { + fwnode: init_data + .fwnode + .as_ref() + .map_or(core::ptr::null_mut(), |fwnode| fwnode.as_raw()), + default_label: core::ptr::null(), + devicename: init_data + .devicename + .map_or(core::ptr::null(), CStrExt::as_char_ptr), + devname_mandatory: init_data.devname_mandatory, + }; + + // SAFETY: + // - `parent.as_raw()` is guaranteed to be a pointer to a valid `device` + // or a null pointer. + // - `ptr` is guaranteed to be a pointer to an initialized `led_classdev`. + to_result(unsafe { + bindings::led_classdev_register_ext( + parent.as_ref().as_raw(), + ptr, + &raw mut init_data_raw, + ) + })?; + + core::mem::forget(init_data.fwnode); // keep the reference count incremented + + Ok::<_, Error>(()) + }), + }), + ) + } + + /// # Safety + /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a + /// `led::Device`. + unsafe fn from_raw<'a>(led_cdev: *mut bindings::led_classdev) -> &'a Self { + // SAFETY: The function's contract guarantees that `led_cdev` points to a `led_classdev` + // field embedded within a valid `led::Device`. `container_of!` can therefore + // safely calculate the address of the containing struct. + unsafe { &*container_of!(Opaque::cast_from(led_cdev), Self, classdev) } + } + + fn parent(&self) -> &device::Device<Bound> { + // SAFETY: + // - `self.classdev.get()` is guaranteed to be a valid pointer to `led_classdev`. + unsafe { device::Device::from_raw((*(*self.classdev.get()).dev).parent) } + } +} + +struct Adapter<T: LedOps> { + _p: PhantomData<T>, +} + +impl<T: LedOps> Adapter<T> { + /// # Safety + /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a + /// `led::Device`. + /// This function is called on setting the brightness of a led. + unsafe extern "C" fn brightness_set_callback( + led_cdev: *mut bindings::led_classdev, + brightness: u32, + ) { + // SAFETY: The function's contract guarantees that `led_cdev` is a valid pointer to a + // `led_classdev` embedded within a `led::Device`. + let classdev = unsafe { Device::<T>::from_raw(led_cdev) }; + // SAFETY: `classdev.parent()` is guaranteed to be contained in `T::Bus`. + let parent = unsafe { T::Bus::from_device(classdev.parent()) }; + + let _ = classdev.ops.brightness_set(parent, classdev, brightness); + } + + /// # Safety + /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a + /// `led::Device`. + /// This function is called on setting the brightness of a led immediately. + unsafe extern "C" fn brightness_set_blocking_callback( + led_cdev: *mut bindings::led_classdev, + brightness: u32, + ) -> i32 { + from_result(|| { + // SAFETY: The function's contract guarantees that `led_cdev` is a valid pointer to a + // `led_classdev` embedded within a `led::Device`. + let classdev = unsafe { Device::<T>::from_raw(led_cdev) }; + // SAFETY: `classdev.parent()` is guaranteed to be contained in `T::Bus`. + let parent = unsafe { T::Bus::from_device(classdev.parent()) }; + + classdev.ops.brightness_set(parent, classdev, brightness)?; + Ok(0) + }) + } + + /// # Safety + /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a + /// `led::Device`. + /// This function is called on getting the brightness of a led. + unsafe extern "C" fn brightness_get_callback(led_cdev: *mut bindings::led_classdev) -> u32 { + // SAFETY: The function's contract guarantees that `led_cdev` is a valid pointer to a + // `led_classdev` embedded within a `led::Device`. + let classdev = unsafe { Device::<T>::from_raw(led_cdev) }; + // SAFETY: `classdev.parent()` is guaranteed to be contained in `T::Bus`. + let parent = unsafe { T::Bus::from_device(classdev.parent()) }; + + classdev.ops.brightness_get(parent, classdev) + } + + /// # Safety + /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a + /// `led::Device`. + /// `delay_on` and `delay_off` must be valid pointers to `usize` and have + /// exclusive access for the period of this function. + /// This function is called on enabling hardware accelerated blinking. + unsafe extern "C" fn blink_set_callback( + led_cdev: *mut bindings::led_classdev, + delay_on: *mut usize, + delay_off: *mut usize, + ) -> i32 { + from_result(|| { + // SAFETY: The function's contract guarantees that `led_cdev` is a valid pointer to a + // `led_classdev` embedded within a `led::Device`. + let classdev = unsafe { Device::<T>::from_raw(led_cdev) }; + // SAFETY: `classdev.parent()` is guaranteed to be contained in `T::Bus`. + let parent = unsafe { T::Bus::from_device(classdev.parent()) }; + + classdev.ops.blink_set( + parent, + classdev, + // SAFETY: The function's contract guarantees that `delay_on` points to a `usize` + // and is exclusive for the period of this function. + unsafe { &mut *delay_on }, + // SAFETY: The function's contract guarantees that `delay_off` points to a `usize` + // and is exclusive for the period of this function. + unsafe { &mut *delay_off }, + )?; + Ok(0) + }) + } +} + +#[pinned_drop] +impl<T: LedOps> PinnedDrop for Device<T> { + fn drop(self: Pin<&mut Self>) { + let raw = self.classdev.get(); + // SAFETY: The existence of `self` guarantees that `self.classdev.get()` is a pointer to a + // valid `struct led_classdev`. + let dev: &device::Device = unsafe { device::Device::from_raw((*raw).dev) }; + + let _fwnode = dev + .fwnode() + // SAFETY: the reference count of `fwnode` has previously been + // incremented in `led::Device::new`. + .map(|fwnode| unsafe { ARef::from_raw(NonNull::from(fwnode)) }); + + // SAFETY: The existence of `self` guarantees that `self.classdev` has previously been + // successfully registered with `led_classdev_register_ext`. + unsafe { bindings::led_classdev_unregister(self.classdev.get()) }; + } +} diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index f812cf120042..231818e0614b 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -108,6 +108,7 @@ pub mod jump_label; #[cfg(CONFIG_KUNIT)] pub mod kunit; +pub mod led; pub mod list; pub mod maple_tree; pub mod miscdevice; -- 2.52.0
{ "author": "Markus Probst <markus.probst@posteo.de>", "date": "Mon, 02 Feb 2026 13:52:20 +0000", "thread_id": "20260202-rust_leds-v11-0-585d1c8be20c@posteo.de.mbox.gz" }
lkml
[PATCH v11 0/3] rust: leds: add led classdev abstractions
This patch series has previously been contained in https://lore.kernel.org/rust-for-linux/20251008181027.662616-1-markus.probst@posteo.de/T/#t which added a rust written led driver for a microcontroller via i2c. As the reading and writing to the i2c client via the register! macro has not been implemented yet [1], the patch series will only contain the additional abstractions required. [1] https://lore.kernel.org/rust-for-linux/DDDS2V0V2NVJ.16ZKXCKUA1HUV@kernel.org/ The following changes were made: * add basic led classdev abstractions to register and unregister leds * add basic led classdev abstractions to register and unregister multicolor leds Changes since v10: * allow in-place initialization of `LedOps` * run rustfmt for code inside `try_pin_init!` Changes since v9: * add missing periods in documentation * duplicate `led::Device` and `led::Adapter` instead of using a complex trait * fix imports not using prelude * adapt to CStr change * documented `led::Color::Multi` and `led::Color::Rgb` Changes since v8: * accept `Option<ARef<Fwnode>>` in `led::InitData::fwnode()` * make functions in `MultiColorSubLed` const * drop the "rust: Add trait to convert a device reference to a bus device reference" patch, as it has been picked into driver-core Changes since v7: * adjusted import style * added classdev parameter to callback functions in `LedOps` * implement `led::Color` * extend `led::InitData` with - initial_brightness - default_trigger - default_color * split generic and normal led classdev abstractions up (see patch 3/4) * add multicolor led class device abstractions (see patch 4/4) * added MAINTAINERS entry Changes since v6: * fixed typos * improved documentation Changes since v5: * rename `IntoBusDevice` trait into `AsBusDevice` * fix documentation about `LedOps::BLOCKING` * removed dependency on i2c bindings * added `AsBusDevice` implementation for `platform::Device` * removed `device::Device` fallback implementation * document that `AsBusDevice` must not be used by drivers and is intended for bus and class device abstractions only. Changes since v4: * add abstraction to convert a device reference to a bus device reference * require the bus device as parent device and provide it in class device callbacks * remove Pin<Vec<_>> abstraction (as not relevant for the led abstractions) * fixed formatting in `led::Device::new` * fixed `LedOps::BLOCKING` did the inverse effect Changes since v3: * fixed kunit tests failing because of example in documentation Changes since v2: * return `Devres` on `led::Device` creation * replace KBox<T> with T in struct definition * increment and decrement reference-count of fwnode * make a device parent mandatory for led classdev creation * rename `led::Handler` to `led::LedOps` * add optional `brightness_get` function to `led::LedOps` * use `#[vtable]` instead of `const BLINK: bool` * use `Opaque::cast_from` instead of casting a pointer * improve documentation * improve support for older rust versions * use `&Device<Bound>` for parent Changes since v1: * fixed typos noticed by Onur Özkan Signed-off-by: Markus Probst <markus.probst@posteo.de> --- Markus Probst (3): rust: leds: add basic led classdev abstractions rust: leds: split generic and normal led classdev abstractions up rust: leds: add multicolor classdev abstractions MAINTAINERS | 8 + rust/bindings/bindings_helper.h | 1 + rust/kernel/led.rs | 300 +++++++++++++++++++++++++++++++ rust/kernel/led/multicolor.rs | 382 ++++++++++++++++++++++++++++++++++++++++ rust/kernel/led/normal.rs | 226 ++++++++++++++++++++++++ rust/kernel/lib.rs | 1 + 6 files changed, 918 insertions(+) --- base-commit: 18f7fcd5e69a04df57b563360b88be72471d6b62 change-id: 20251114-rust_leds-a959f7c2f7f9
Move code specific to normal led class devices into a separate file and introduce the `led::Mode` trait to allow for other types of led class devices in `led::LedOps`. Signed-off-by: Markus Probst <markus.probst@posteo.de> --- MAINTAINERS | 1 + rust/kernel/led.rs | 245 ++++++---------------------------------------- rust/kernel/led/normal.rs | 226 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 259 insertions(+), 213 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 26765fecb9a9..5f8b59678785 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14285,6 +14285,7 @@ L: linux-leds@vger.kernel.org L: rust-for-linux@vger.kernel.org S: Maintained F: rust/kernel/led.rs +F: rust/kernel/led/ LEGO MINDSTORMS EV3 R: David Lechner <david@lechnology.com> diff --git a/rust/kernel/led.rs b/rust/kernel/led.rs index 9acb6946f3da..a32473d61c61 100644 --- a/rust/kernel/led.rs +++ b/rust/kernel/led.rs @@ -33,16 +33,9 @@ }, // }; -/// The led class device representation. -/// -/// This structure represents the Rust abstraction for a C `struct led_classdev`. -#[pin_data(PinnedDrop)] -pub struct Device<T: LedOps> { - #[pin] - ops: T, - #[pin] - classdev: Opaque<bindings::led_classdev>, -} +mod normal; + +pub use normal::{Device, Normal}; /// The led init data representation. /// @@ -135,6 +128,7 @@ pub fn color(self, color: Color) -> Self { /// #[vtable] /// impl led::LedOps for MyLedOps { /// type Bus = platform::Device<device::Bound>; +/// type Mode = led::Normal; /// const BLOCKING: bool = false; /// const MAX_BRIGHTNESS: u32 = 255; /// @@ -165,6 +159,12 @@ pub trait LedOps: Send + 'static + Sized { /// The bus device required by the implementation. #[allow(private_bounds)] type Bus: AsBusDevice<Bound>; + + /// The led mode to use. + /// + /// See [`Mode`]. + type Mode: Mode; + /// If set true, [`LedOps::brightness_set`] and [`LedOps::blink_set`] must perform the /// operation immediately. If set false, they must not sleep. const BLOCKING: bool; @@ -177,12 +177,17 @@ pub trait LedOps: Send + 'static + Sized { fn brightness_set( &self, dev: &Self::Bus, - classdev: &Device<Self>, + classdev: &<Self::Mode as Mode>::Device<Self>, brightness: u32, ) -> Result<()>; /// Gets the current brightness level. - fn brightness_get(&self, _dev: &Self::Bus, _classdev: &Device<Self>) -> u32 { + fn brightness_get( + &self, + dev: &Self::Bus, + classdev: &<Self::Mode as Mode>::Device<Self>, + ) -> u32 { + let _ = (dev, classdev); build_error!(VTABLE_DEFAULT_ERROR) } @@ -196,11 +201,12 @@ fn brightness_get(&self, _dev: &Self::Bus, _classdev: &Device<Self>) -> u32 { /// See also [`LedOps::BLOCKING`]. fn blink_set( &self, - _dev: &Self::Bus, - _classdev: &Device<Self>, - _delay_on: &mut usize, - _delay_off: &mut usize, + dev: &Self::Bus, + classdev: &<Self::Mode as Mode>::Device<Self>, + delay_on: &mut usize, + delay_off: &mut usize, ) -> Result<()> { + let _ = (dev, classdev, delay_on, delay_off); build_error!(VTABLE_DEFAULT_ERROR) } } @@ -251,203 +257,16 @@ fn try_from(value: u32) -> core::result::Result<Self, Self::Error> { } } -// SAFETY: A `led::Device` can be unregistered from any thread. -unsafe impl<T: LedOps + Send> Send for Device<T> {} - -// SAFETY: `led::Device` can be shared among threads because all methods of `led::Device` -// are thread safe. -unsafe impl<T: LedOps + Sync> Sync for Device<T> {} - -impl<T: LedOps> Device<T> { - /// Registers a new led classdev. - /// - /// The [`Device`] will be unregistered on drop. - pub fn new<'a>( - parent: &'a T::Bus, - init_data: InitData<'a>, - ops: impl PinInit<T, Error> + 'a, - ) -> impl PinInit<Devres<Self>, Error> + 'a { - Devres::new( - parent.as_ref(), - try_pin_init!(Self { - ops <- ops, - classdev <- Opaque::try_ffi_init(|ptr: *mut bindings::led_classdev| { - // SAFETY: `try_ffi_init` guarantees that `ptr` is valid for write. - // `led_classdev` gets fully initialized in-place by - // `led_classdev_register_ext` including `mutex` and `list_head`. - unsafe { - ptr.write(bindings::led_classdev { - brightness_set: (!T::BLOCKING) - .then_some(Adapter::<T>::brightness_set_callback), - brightness_set_blocking: T::BLOCKING - .then_some(Adapter::<T>::brightness_set_blocking_callback), - brightness_get: T::HAS_BRIGHTNESS_GET - .then_some(Adapter::<T>::brightness_get_callback), - blink_set: T::HAS_BLINK_SET.then_some(Adapter::<T>::blink_set_callback), - max_brightness: T::MAX_BRIGHTNESS, - brightness: init_data.initial_brightness, - default_trigger: init_data - .default_trigger - .map_or(core::ptr::null(), CStrExt::as_char_ptr), - color: init_data.color as u32, - ..bindings::led_classdev::default() - }) - }; - - let mut init_data_raw = bindings::led_init_data { - fwnode: init_data - .fwnode - .as_ref() - .map_or(core::ptr::null_mut(), |fwnode| fwnode.as_raw()), - default_label: core::ptr::null(), - devicename: init_data - .devicename - .map_or(core::ptr::null(), CStrExt::as_char_ptr), - devname_mandatory: init_data.devname_mandatory, - }; - - // SAFETY: - // - `parent.as_raw()` is guaranteed to be a pointer to a valid `device` - // or a null pointer. - // - `ptr` is guaranteed to be a pointer to an initialized `led_classdev`. - to_result(unsafe { - bindings::led_classdev_register_ext( - parent.as_ref().as_raw(), - ptr, - &raw mut init_data_raw, - ) - })?; - - core::mem::forget(init_data.fwnode); // keep the reference count incremented - - Ok::<_, Error>(()) - }), - }), - ) - } - - /// # Safety - /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a - /// `led::Device`. - unsafe fn from_raw<'a>(led_cdev: *mut bindings::led_classdev) -> &'a Self { - // SAFETY: The function's contract guarantees that `led_cdev` points to a `led_classdev` - // field embedded within a valid `led::Device`. `container_of!` can therefore - // safely calculate the address of the containing struct. - unsafe { &*container_of!(Opaque::cast_from(led_cdev), Self, classdev) } - } - - fn parent(&self) -> &device::Device<Bound> { - // SAFETY: - // - `self.classdev.get()` is guaranteed to be a valid pointer to `led_classdev`. - unsafe { device::Device::from_raw((*(*self.classdev.get()).dev).parent) } - } -} - -struct Adapter<T: LedOps> { - _p: PhantomData<T>, -} - -impl<T: LedOps> Adapter<T> { - /// # Safety - /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a - /// `led::Device`. - /// This function is called on setting the brightness of a led. - unsafe extern "C" fn brightness_set_callback( - led_cdev: *mut bindings::led_classdev, - brightness: u32, - ) { - // SAFETY: The function's contract guarantees that `led_cdev` is a valid pointer to a - // `led_classdev` embedded within a `led::Device`. - let classdev = unsafe { Device::<T>::from_raw(led_cdev) }; - // SAFETY: `classdev.parent()` is guaranteed to be contained in `T::Bus`. - let parent = unsafe { T::Bus::from_device(classdev.parent()) }; - - let _ = classdev.ops.brightness_set(parent, classdev, brightness); - } - - /// # Safety - /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a - /// `led::Device`. - /// This function is called on setting the brightness of a led immediately. - unsafe extern "C" fn brightness_set_blocking_callback( - led_cdev: *mut bindings::led_classdev, - brightness: u32, - ) -> i32 { - from_result(|| { - // SAFETY: The function's contract guarantees that `led_cdev` is a valid pointer to a - // `led_classdev` embedded within a `led::Device`. - let classdev = unsafe { Device::<T>::from_raw(led_cdev) }; - // SAFETY: `classdev.parent()` is guaranteed to be contained in `T::Bus`. - let parent = unsafe { T::Bus::from_device(classdev.parent()) }; - - classdev.ops.brightness_set(parent, classdev, brightness)?; - Ok(0) - }) - } - - /// # Safety - /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a - /// `led::Device`. - /// This function is called on getting the brightness of a led. - unsafe extern "C" fn brightness_get_callback(led_cdev: *mut bindings::led_classdev) -> u32 { - // SAFETY: The function's contract guarantees that `led_cdev` is a valid pointer to a - // `led_classdev` embedded within a `led::Device`. - let classdev = unsafe { Device::<T>::from_raw(led_cdev) }; - // SAFETY: `classdev.parent()` is guaranteed to be contained in `T::Bus`. - let parent = unsafe { T::Bus::from_device(classdev.parent()) }; - - classdev.ops.brightness_get(parent, classdev) - } - - /// # Safety - /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a - /// `led::Device`. - /// `delay_on` and `delay_off` must be valid pointers to `usize` and have - /// exclusive access for the period of this function. - /// This function is called on enabling hardware accelerated blinking. - unsafe extern "C" fn blink_set_callback( - led_cdev: *mut bindings::led_classdev, - delay_on: *mut usize, - delay_off: *mut usize, - ) -> i32 { - from_result(|| { - // SAFETY: The function's contract guarantees that `led_cdev` is a valid pointer to a - // `led_classdev` embedded within a `led::Device`. - let classdev = unsafe { Device::<T>::from_raw(led_cdev) }; - // SAFETY: `classdev.parent()` is guaranteed to be contained in `T::Bus`. - let parent = unsafe { T::Bus::from_device(classdev.parent()) }; - - classdev.ops.blink_set( - parent, - classdev, - // SAFETY: The function's contract guarantees that `delay_on` points to a `usize` - // and is exclusive for the period of this function. - unsafe { &mut *delay_on }, - // SAFETY: The function's contract guarantees that `delay_off` points to a `usize` - // and is exclusive for the period of this function. - unsafe { &mut *delay_off }, - )?; - Ok(0) - }) - } +/// The led mode. +/// +/// Each led mode has its own led class device type with different capabilities. +/// +/// See [`Normal`]. +pub trait Mode: private::Sealed { + /// The class device for the led mode. + type Device<T: LedOps<Mode = Self>>; } -#[pinned_drop] -impl<T: LedOps> PinnedDrop for Device<T> { - fn drop(self: Pin<&mut Self>) { - let raw = self.classdev.get(); - // SAFETY: The existence of `self` guarantees that `self.classdev.get()` is a pointer to a - // valid `struct led_classdev`. - let dev: &device::Device = unsafe { device::Device::from_raw((*raw).dev) }; - - let _fwnode = dev - .fwnode() - // SAFETY: the reference count of `fwnode` has previously been - // incremented in `led::Device::new`. - .map(|fwnode| unsafe { ARef::from_raw(NonNull::from(fwnode)) }); - - // SAFETY: The existence of `self` guarantees that `self.classdev` has previously been - // successfully registered with `led_classdev_register_ext`. - unsafe { bindings::led_classdev_unregister(self.classdev.get()) }; - } +mod private { + pub trait Sealed {} } diff --git a/rust/kernel/led/normal.rs b/rust/kernel/led/normal.rs new file mode 100644 index 000000000000..1a17bb2a6d97 --- /dev/null +++ b/rust/kernel/led/normal.rs @@ -0,0 +1,226 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Led mode for the `struct led_classdev`. +//! +//! C header: [`include/linux/leds.h`](srctree/include/linux/leds.h) + +use super::*; + +/// The led mode for the `struct led_classdev`. Leds with this mode can only have a fixed color. +pub enum Normal {} + +impl Mode for Normal { + type Device<T: LedOps<Mode = Self>> = Device<T>; +} +impl private::Sealed for Normal {} + +/// The led class device representation. +/// +/// This structure represents the Rust abstraction for a led class device. +#[pin_data(PinnedDrop)] +pub struct Device<T: LedOps<Mode = Normal>> { + #[pin] + ops: T, + #[pin] + classdev: Opaque<bindings::led_classdev>, +} + +impl<T: LedOps<Mode = Normal>> Device<T> { + /// Registers a new led classdev. + /// + /// The [`Device`] will be unregistered on drop. + pub fn new<'a>( + parent: &'a T::Bus, + init_data: InitData<'a>, + ops: impl PinInit<T, Error> + 'a, + ) -> impl PinInit<Devres<Self>, Error> + 'a { + Devres::new( + parent.as_ref(), + try_pin_init!(Self { + ops <- ops, + classdev <- Opaque::try_ffi_init(|ptr: *mut bindings::led_classdev| { + // SAFETY: `try_ffi_init` guarantees that `ptr` is valid for write. + // `led_classdev` gets fully initialized in-place by + // `led_classdev_register_ext` including `mutex` and `list_head`. + unsafe { + ptr.write(bindings::led_classdev { + brightness_set: (!T::BLOCKING) + .then_some(Adapter::<T>::brightness_set_callback), + brightness_set_blocking: T::BLOCKING + .then_some(Adapter::<T>::brightness_set_blocking_callback), + brightness_get: T::HAS_BRIGHTNESS_GET + .then_some(Adapter::<T>::brightness_get_callback), + blink_set: T::HAS_BLINK_SET.then_some(Adapter::<T>::blink_set_callback), + max_brightness: T::MAX_BRIGHTNESS, + brightness: init_data.initial_brightness, + default_trigger: init_data + .default_trigger + .map_or(core::ptr::null(), CStrExt::as_char_ptr), + color: init_data.color as u32, + ..bindings::led_classdev::default() + }) + }; + + let mut init_data_raw = bindings::led_init_data { + fwnode: init_data + .fwnode + .as_ref() + .map_or(core::ptr::null_mut(), |fwnode| fwnode.as_raw()), + default_label: core::ptr::null(), + devicename: init_data + .devicename + .map_or(core::ptr::null(), CStrExt::as_char_ptr), + devname_mandatory: init_data.devname_mandatory, + }; + + // SAFETY: + // - `parent.as_ref().as_raw()` is guaranteed to be a pointer to a valid + // `device`. + // - `ptr` is guaranteed to be a pointer to an initialized `led_classdev`. + to_result(unsafe { + bindings::led_classdev_register_ext( + parent.as_ref().as_raw(), + ptr, + &raw mut init_data_raw, + ) + })?; + + core::mem::forget(init_data.fwnode); // keep the reference count incremented + + Ok::<_, Error>(()) + }), + }), + ) + } + + /// # Safety + /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a + /// `led::Device`. + unsafe fn from_raw<'a>(led_cdev: *mut bindings::led_classdev) -> &'a Self { + // SAFETY: The function's contract guarantees that `led_cdev` points to a `led_classdev` + // field embedded within a valid `led::Device`. `container_of!` can therefore + // safely calculate the address of the containing struct. + unsafe { &*container_of!(Opaque::cast_from(led_cdev), Self, classdev) } + } + + fn parent(&self) -> &device::Device<Bound> { + // SAFETY: `self.classdev.get()` is guaranteed to be a valid pointer to `led_classdev`. + unsafe { device::Device::from_raw((*(*self.classdev.get()).dev).parent) } + } +} + +// SAFETY: A `led::Device` can be unregistered from any thread. +unsafe impl<T: LedOps<Mode = Normal> + Send> Send for Device<T> {} + +// SAFETY: `led::Device` can be shared among threads because all methods of `led::Device` +// are thread safe. +unsafe impl<T: LedOps<Mode = Normal> + Sync> Sync for Device<T> {} + +struct Adapter<T: LedOps<Mode = Normal>> { + _p: PhantomData<T>, +} + +impl<T: LedOps<Mode = Normal>> Adapter<T> { + /// # Safety + /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a + /// `led::Device`. + /// This function is called on setting the brightness of a led. + unsafe extern "C" fn brightness_set_callback( + led_cdev: *mut bindings::led_classdev, + brightness: u32, + ) { + // SAFETY: The function's contract guarantees that `led_cdev` is a valid pointer to a + // `led_classdev` embedded within a `led::Device`. + let classdev = unsafe { Device::<T>::from_raw(led_cdev) }; + // SAFETY: `classdev.parent()` is guaranteed to be contained in `T::Bus`. + let parent = unsafe { T::Bus::from_device(classdev.parent()) }; + + let _ = classdev.ops.brightness_set(parent, classdev, brightness); + } + + /// # Safety + /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a + /// `led::Device`. + /// This function is called on setting the brightness of a led immediately. + unsafe extern "C" fn brightness_set_blocking_callback( + led_cdev: *mut bindings::led_classdev, + brightness: u32, + ) -> i32 { + from_result(|| { + // SAFETY: The function's contract guarantees that `led_cdev` is a valid pointer to a + // `led_classdev` embedded within a `led::Device`. + let classdev = unsafe { Device::<T>::from_raw(led_cdev) }; + // SAFETY: `classdev.parent()` is guaranteed to be contained in `T::Bus`. + let parent = unsafe { T::Bus::from_device(classdev.parent()) }; + + classdev.ops.brightness_set(parent, classdev, brightness)?; + Ok(0) + }) + } + + /// # Safety + /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a + /// `led::Device`. + /// This function is called on getting the brightness of a led. + unsafe extern "C" fn brightness_get_callback(led_cdev: *mut bindings::led_classdev) -> u32 { + // SAFETY: The function's contract guarantees that `led_cdev` is a valid pointer to a + // `led_classdev` embedded within a `led::Device`. + let classdev = unsafe { Device::<T>::from_raw(led_cdev) }; + // SAFETY: `classdev.parent()` is guaranteed to be contained in `T::Bus`. + let parent = unsafe { T::Bus::from_device(classdev.parent()) }; + + classdev.ops.brightness_get(parent, classdev) + } + + /// # Safety + /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a + /// `led::Device`. + /// `delay_on` and `delay_off` must be valid pointers to `usize` and have + /// exclusive access for the period of this function. + /// This function is called on enabling hardware accelerated blinking. + unsafe extern "C" fn blink_set_callback( + led_cdev: *mut bindings::led_classdev, + delay_on: *mut usize, + delay_off: *mut usize, + ) -> i32 { + from_result(|| { + // SAFETY: The function's contract guarantees that `led_cdev` is a valid pointer to a + // `led_classdev` embedded within a `led::Device`. + let classdev = unsafe { Device::<T>::from_raw(led_cdev) }; + // SAFETY: `classdev.parent()` is guaranteed to be contained in `T::Bus`. + let parent = unsafe { T::Bus::from_device(classdev.parent()) }; + + classdev.ops.blink_set( + parent, + classdev, + // SAFETY: The function's contract guarantees that `delay_on` points to a `usize` + // and is exclusive for the period of this function. + unsafe { &mut *delay_on }, + // SAFETY: The function's contract guarantees that `delay_off` points to a `usize` + // and is exclusive for the period of this function. + unsafe { &mut *delay_off }, + )?; + Ok(0) + }) + } +} + +#[pinned_drop] +impl<T: LedOps<Mode = Normal>> PinnedDrop for Device<T> { + fn drop(self: Pin<&mut Self>) { + let raw = self.classdev.get(); + // SAFETY: The existence of `self` guarantees that `self.classdev.get()` is a pointer to a + // valid `led_classdev`. + let dev: &device::Device = unsafe { device::Device::from_raw((*raw).dev) }; + + let _fwnode = dev + .fwnode() + // SAFETY: the reference count of `fwnode` has previously been + // incremented in `led::Device::new`. + .map(|fwnode| unsafe { ARef::from_raw(NonNull::from(fwnode)) }); + + // SAFETY: The existence of `self` guarantees that `self.classdev` has previously been + // successfully registered with `led_classdev_register_ext`. + unsafe { bindings::led_classdev_unregister(raw) }; + } +} -- 2.52.0
{ "author": "Markus Probst <markus.probst@posteo.de>", "date": "Mon, 02 Feb 2026 13:52:22 +0000", "thread_id": "20260202-rust_leds-v11-0-585d1c8be20c@posteo.de.mbox.gz" }
lkml
[PATCH v11 0/3] rust: leds: add led classdev abstractions
This patch series has previously been contained in https://lore.kernel.org/rust-for-linux/20251008181027.662616-1-markus.probst@posteo.de/T/#t which added a rust written led driver for a microcontroller via i2c. As the reading and writing to the i2c client via the register! macro has not been implemented yet [1], the patch series will only contain the additional abstractions required. [1] https://lore.kernel.org/rust-for-linux/DDDS2V0V2NVJ.16ZKXCKUA1HUV@kernel.org/ The following changes were made: * add basic led classdev abstractions to register and unregister leds * add basic led classdev abstractions to register and unregister multicolor leds Changes since v10: * allow in-place initialization of `LedOps` * run rustfmt for code inside `try_pin_init!` Changes since v9: * add missing periods in documentation * duplicate `led::Device` and `led::Adapter` instead of using a complex trait * fix imports not using prelude * adapt to CStr change * documented `led::Color::Multi` and `led::Color::Rgb` Changes since v8: * accept `Option<ARef<Fwnode>>` in `led::InitData::fwnode()` * make functions in `MultiColorSubLed` const * drop the "rust: Add trait to convert a device reference to a bus device reference" patch, as it has been picked into driver-core Changes since v7: * adjusted import style * added classdev parameter to callback functions in `LedOps` * implement `led::Color` * extend `led::InitData` with - initial_brightness - default_trigger - default_color * split generic and normal led classdev abstractions up (see patch 3/4) * add multicolor led class device abstractions (see patch 4/4) * added MAINTAINERS entry Changes since v6: * fixed typos * improved documentation Changes since v5: * rename `IntoBusDevice` trait into `AsBusDevice` * fix documentation about `LedOps::BLOCKING` * removed dependency on i2c bindings * added `AsBusDevice` implementation for `platform::Device` * removed `device::Device` fallback implementation * document that `AsBusDevice` must not be used by drivers and is intended for bus and class device abstractions only. Changes since v4: * add abstraction to convert a device reference to a bus device reference * require the bus device as parent device and provide it in class device callbacks * remove Pin<Vec<_>> abstraction (as not relevant for the led abstractions) * fixed formatting in `led::Device::new` * fixed `LedOps::BLOCKING` did the inverse effect Changes since v3: * fixed kunit tests failing because of example in documentation Changes since v2: * return `Devres` on `led::Device` creation * replace KBox<T> with T in struct definition * increment and decrement reference-count of fwnode * make a device parent mandatory for led classdev creation * rename `led::Handler` to `led::LedOps` * add optional `brightness_get` function to `led::LedOps` * use `#[vtable]` instead of `const BLINK: bool` * use `Opaque::cast_from` instead of casting a pointer * improve documentation * improve support for older rust versions * use `&Device<Bound>` for parent Changes since v1: * fixed typos noticed by Onur Özkan Signed-off-by: Markus Probst <markus.probst@posteo.de> --- Markus Probst (3): rust: leds: add basic led classdev abstractions rust: leds: split generic and normal led classdev abstractions up rust: leds: add multicolor classdev abstractions MAINTAINERS | 8 + rust/bindings/bindings_helper.h | 1 + rust/kernel/led.rs | 300 +++++++++++++++++++++++++++++++ rust/kernel/led/multicolor.rs | 382 ++++++++++++++++++++++++++++++++++++++++ rust/kernel/led/normal.rs | 226 ++++++++++++++++++++++++ rust/kernel/lib.rs | 1 + 6 files changed, 918 insertions(+) --- base-commit: 18f7fcd5e69a04df57b563360b88be72471d6b62 change-id: 20251114-rust_leds-a959f7c2f7f9
Implement the abstractions needed for multicolor led class devices, including: * `led::MultiColor` - the led mode implementation * `MultiColorSubLed` - a safe wrapper arround `mc_subled` * `led::MultiColorDevice` - a safe wrapper around `led_classdev_mc` Signed-off-by: Markus Probst <markus.probst@posteo.de> --- rust/bindings/bindings_helper.h | 1 + rust/kernel/led.rs | 30 +++- rust/kernel/led/multicolor.rs | 382 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 412 insertions(+), 1 deletion(-) diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h index a067038b4b42..765a4198b85d 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -62,6 +62,7 @@ #include <linux/ioport.h> #include <linux/jiffies.h> #include <linux/jump_label.h> +#include <linux/led-class-multicolor.h> #include <linux/mdio.h> #include <linux/mm.h> #include <linux/miscdevice.h> diff --git a/rust/kernel/led.rs b/rust/kernel/led.rs index a32473d61c61..464e100ab3db 100644 --- a/rust/kernel/led.rs +++ b/rust/kernel/led.rs @@ -33,8 +33,12 @@ }, // }; +#[cfg(CONFIG_LEDS_CLASS_MULTICOLOR)] +mod multicolor; mod normal; +#[cfg(CONFIG_LEDS_CLASS_MULTICOLOR)] +pub use multicolor::{MultiColor, MultiColorDevice, MultiColorSubLed}; pub use normal::{Device, Normal}; /// The led init data representation. @@ -229,7 +233,24 @@ pub enum Color { Violet = bindings::LED_COLOR_ID_VIOLET, Yellow = bindings::LED_COLOR_ID_YELLOW, Ir = bindings::LED_COLOR_ID_IR, + #[cfg_attr( + CONFIG_LEDS_CLASS_MULTICOLOR, + doc = "Use this color for a [`MultiColor`] led." + )] + #[cfg_attr( + not(CONFIG_LEDS_CLASS_MULTICOLOR), + doc = "Use this color for a `MultiColor` led." + )] + /// If the led supports RGB, use [`Color::Rgb`] instead. Multi = bindings::LED_COLOR_ID_MULTI, + #[cfg_attr( + CONFIG_LEDS_CLASS_MULTICOLOR, + doc = "Use this color for a [`MultiColor`] led with rgb support." + )] + #[cfg_attr( + not(CONFIG_LEDS_CLASS_MULTICOLOR), + doc = "Use this color for a `MultiColor` led with rgb support." + )] Rgb = bindings::LED_COLOR_ID_RGB, Purple = bindings::LED_COLOR_ID_PURPLE, Orange = bindings::LED_COLOR_ID_ORANGE, @@ -261,7 +282,14 @@ fn try_from(value: u32) -> core::result::Result<Self, Self::Error> { /// /// Each led mode has its own led class device type with different capabilities. /// -/// See [`Normal`]. +#[cfg_attr( + CONFIG_LEDS_CLASS_MULTICOLOR, + doc = "See [`Normal`] and [`MultiColor`]." +)] +#[cfg_attr( + not(CONFIG_LEDS_CLASS_MULTICOLOR), + doc = "See [`Normal`] and `MultiColor`." +)] pub trait Mode: private::Sealed { /// The class device for the led mode. type Device<T: LedOps<Mode = Self>>; diff --git a/rust/kernel/led/multicolor.rs b/rust/kernel/led/multicolor.rs new file mode 100644 index 000000000000..7bd143d0646e --- /dev/null +++ b/rust/kernel/led/multicolor.rs @@ -0,0 +1,382 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Led mode for the `struct led_classdev_mc`. +//! +//! C header: [`include/linux/led-class-multicolor.h`](srctree/include/linux/led-class-multicolor.h) + +use crate::alloc::KVec; + +use super::*; + +/// The led mode for the `struct led_classdev_mc`. Leds with this mode can have multiple colors. +pub enum MultiColor {} +impl Mode for MultiColor { + type Device<T: LedOps<Mode = Self>> = MultiColorDevice<T>; +} +impl private::Sealed for MultiColor {} + +/// The multicolor sub led info representation. +/// +/// This structure represents the Rust abstraction for a C `struct mc_subled`. +#[repr(C)] +#[derive(Copy, Clone, Debug)] +#[non_exhaustive] +pub struct MultiColorSubLed { + /// the color of the sub led + pub color: Color, + /// the brightness of the sub led. + /// + /// The value will be automatically calculated. + /// See `MultiColor::pre_brightness_set`. + pub brightness: u32, + /// the intensity of the sub led. + pub intensity: u32, + /// arbitrary data for the driver to store. + pub channel: u32, +} + +// We directly pass a reference to the `subled_info` field in `led_classdev_mc` to the driver via +// `Device::subleds()`. +// We need safeguards to ensure `MultiColorSubLed` and `mc_subled` stay identical. +const _: () = { + use core::mem::offset_of; + + const fn assert_same_type<T>(_: &T, _: &T) {} + + let rust_zeroed = MultiColorSubLed { + color: Color::White, + brightness: 0, + intensity: 0, + channel: 0, + }; + let c_zeroed = bindings::mc_subled { + color_index: 0, + brightness: 0, + intensity: 0, + channel: 0, + }; + + assert!(offset_of!(MultiColorSubLed, color) == offset_of!(bindings::mc_subled, color_index)); + assert_same_type(&0u32, &c_zeroed.color_index); + + assert!( + offset_of!(MultiColorSubLed, brightness) == offset_of!(bindings::mc_subled, brightness) + ); + assert_same_type(&rust_zeroed.brightness, &c_zeroed.brightness); + + assert!(offset_of!(MultiColorSubLed, intensity) == offset_of!(bindings::mc_subled, intensity)); + assert_same_type(&rust_zeroed.intensity, &c_zeroed.intensity); + + assert!(offset_of!(MultiColorSubLed, channel) == offset_of!(bindings::mc_subled, channel)); + assert_same_type(&rust_zeroed.channel, &c_zeroed.channel); + + assert!(size_of::<MultiColorSubLed>() == size_of::<bindings::mc_subled>()); +}; + +impl MultiColorSubLed { + /// Create a new multicolor sub led info. + pub const fn new(color: Color) -> Self { + Self { + color, + brightness: 0, + intensity: 0, + channel: 0, + } + } + + /// Set arbitrary data for the driver. + pub const fn channel(mut self, channel: u32) -> Self { + self.channel = channel; + self + } + + /// Set the initial intensity of the subled. + pub const fn initial_intensity(mut self, intensity: u32) -> Self { + self.intensity = intensity; + self + } +} + +/// The multicolor led class device representation. +/// +/// This structure represents the Rust abstraction for a multicolor led class device. +#[pin_data(PinnedDrop)] +pub struct MultiColorDevice<T: LedOps<Mode = MultiColor>> { + #[pin] + ops: T, + #[pin] + classdev: Opaque<bindings::led_classdev_mc>, +} + +impl<T: LedOps<Mode = MultiColor>> MultiColorDevice<T> { + /// Registers a new led classdev. + /// + /// The [`MultiColorDevice`] will be unregistered on drop. + pub fn new<'a>( + parent: &'a T::Bus, + init_data: InitData<'a>, + ops: impl PinInit<T, Error> + 'a, + subleds: &'a [MultiColorSubLed], + ) -> impl PinInit<Devres<Self>, Error> + 'a { + Devres::new( + parent.as_ref(), + try_pin_init!(Self { + ops <- ops, + classdev <- Opaque::try_ffi_init(|ptr: *mut bindings::led_classdev_mc| { + let mut used = 0; + if subleds.iter().any(|subled| { + let bit = 1 << (subled.color as u32); + if (used & bit) != 0 { + true + } else { + used |= bit; + false + } + }) { + dev_err!(parent.as_ref(), "duplicate color in multicolor led\n"); + return Err(EINVAL); + } + let mut subleds_vec = KVec::new(); + subleds_vec.extend_from_slice(subleds, GFP_KERNEL)?; + let (subled_info, num_colors, capacity) = subleds_vec.into_raw_parts(); + debug_assert_eq!(num_colors, capacity); + + // SAFETY: `try_ffi_init` guarantees that `ptr` is valid for write. + // `led_classdev_mc` gets fully initialized in-place by + // `led_classdev_multicolor_register_ext` including `mutex` and `list_head`. + unsafe { + ptr.write(bindings::led_classdev_mc { + led_cdev: bindings::led_classdev { + brightness_set: (!T::BLOCKING) + .then_some(Adapter::<T>::brightness_set_callback), + brightness_set_blocking: T::BLOCKING + .then_some(Adapter::<T>::brightness_set_blocking_callback), + brightness_get: T::HAS_BRIGHTNESS_GET + .then_some(Adapter::<T>::brightness_get_callback), + blink_set: T::HAS_BLINK_SET + .then_some(Adapter::<T>::blink_set_callback), + max_brightness: T::MAX_BRIGHTNESS, + brightness: init_data.initial_brightness, + default_trigger: init_data + .default_trigger + .map_or(core::ptr::null(), CStrExt::as_char_ptr), + color: init_data.color as u32, + ..bindings::led_classdev::default() + }, + num_colors: u32::try_from(num_colors)?, + // CAST: The safeguards in the const block ensure that + // `MultiColorSubLed` has an identical layout to `mc_subled`. + subled_info: subled_info.cast::<bindings::mc_subled>(), + }) + }; + + let mut init_data_raw = bindings::led_init_data { + fwnode: init_data + .fwnode + .as_ref() + .map_or(core::ptr::null_mut(), |fwnode| fwnode.as_raw()), + default_label: core::ptr::null(), + devicename: init_data + .devicename + .map_or(core::ptr::null(), CStrExt::as_char_ptr), + devname_mandatory: init_data.devname_mandatory, + }; + + // SAFETY: + // - `parent.as_ref().as_raw()` is guaranteed to be a pointer to a valid + // `device`. + // - `ptr` is guaranteed to be a pointer to an initialized `led_classdev_mc`. + to_result(unsafe { + bindings::led_classdev_multicolor_register_ext( + parent.as_ref().as_raw(), + ptr, + &raw mut init_data_raw, + ) + }) + .inspect_err(|_err| { + // SAFETY: `subled_info` is guaranteed to be a valid array pointer to + // `mc_subled` with the length and capacity of `num_colors`. + drop(unsafe { KVec::from_raw_parts(subled_info, num_colors, num_colors) }); + })?; + + core::mem::forget(init_data.fwnode); // keep the reference count incremented + + Ok::<_, Error>(()) + }), + }), + ) + } + + /// # Safety + /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a + /// `led::MultiColorDevice`. + unsafe fn from_raw<'a>(led_cdev: *mut bindings::led_classdev) -> &'a Self { + // SAFETY: The function's contract guarantees that `led_cdev` points to a `led_classdev` + // field embedded within a valid `led::MultiColorDevice`. `container_of!` can therefore + // safely calculate the address of the containing struct. + let led_mc_cdev = unsafe { container_of!(led_cdev, bindings::led_classdev_mc, led_cdev) }; + + // SAFETY: It is guaranteed that `led_mc_cdev` points to a `led_classdev_mc` + // field embedded within a valid `led::MultiColorDevice`. `container_of!` can therefore + // safely calculate the address of the containing struct. + unsafe { &*container_of!(Opaque::cast_from(led_mc_cdev), Self, classdev) } + } + + fn parent(&self) -> &device::Device<Bound> { + // SAFETY: `self.classdev.get()` is guaranteed to be a valid pointer to `led_classdev_mc`. + unsafe { device::Device::from_raw((*(*self.classdev.get()).led_cdev.dev).parent) } + } + + /// Returns the subleds passed to [`Device::new_multicolor`]. + pub fn subleds(&self) -> &[MultiColorSubLed] { + // SAFETY: The existence of `self` guarantees that `self.classdev.get()` is a pointer to a + // valid `led_classdev_mc`. + let raw = unsafe { &*self.classdev.get() }; + // SAFETY: `raw.subled_info` is a valid pointer to `mc_subled[num_colors]`. + // CAST: The safeguards in the const block ensure that `MultiColorSubLed` has an identical + // layout to `mc_subled`. + unsafe { + core::slice::from_raw_parts( + raw.subled_info.cast::<MultiColorSubLed>(), + raw.num_colors as usize, + ) + } + } +} + +// SAFETY: A `led::MultiColorDevice` can be unregistered from any thread. +unsafe impl<T: LedOps<Mode = MultiColor> + Send> Send for MultiColorDevice<T> {} + +// SAFETY: `led::MultiColorDevice` can be shared among threads because all methods of `led::Device` +// are thread safe. +unsafe impl<T: LedOps<Mode = MultiColor> + Sync> Sync for MultiColorDevice<T> {} + +struct Adapter<T: LedOps<Mode = MultiColor>> { + _p: PhantomData<T>, +} + +impl<T: LedOps<Mode = MultiColor>> Adapter<T> { + /// # Safety + /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a + /// `led::MultiColorDevice`. + /// This function is called on setting the brightness of a led. + unsafe extern "C" fn brightness_set_callback( + led_cdev: *mut bindings::led_classdev, + brightness: u32, + ) { + // SAFETY: The function's contract guarantees that `led_cdev` is a valid pointer to a + // `led_classdev` embedded within a `led::MultiColorDevice`. + let classdev = unsafe { MultiColorDevice::<T>::from_raw(led_cdev) }; + // SAFETY: `classdev.parent()` is guaranteed to be contained in `T::Bus`. + let parent = unsafe { T::Bus::from_device(classdev.parent()) }; + + // SAFETY: `classdev.classdev.get()` is guaranteed to be a pointer to a valid + // `led_classdev_mc`. + unsafe { bindings::led_mc_calc_color_components(classdev.classdev.get(), brightness) }; + + let _ = classdev.ops.brightness_set(parent, classdev, brightness); + } + + /// # Safety + /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a + /// `led::MultiColorDevice`. + /// This function is called on setting the brightness of a led immediately. + unsafe extern "C" fn brightness_set_blocking_callback( + led_cdev: *mut bindings::led_classdev, + brightness: u32, + ) -> i32 { + from_result(|| { + // SAFETY: The function's contract guarantees that `led_cdev` is a valid pointer to a + // `led_classdev` embedded within a `led::MultiColorDevice`. + let classdev = unsafe { MultiColorDevice::<T>::from_raw(led_cdev) }; + // SAFETY: `classdev.parent()` is guaranteed to be contained in `T::Bus`. + let parent = unsafe { T::Bus::from_device(classdev.parent()) }; + + // SAFETY: `classdev.classdev.get()` is guaranteed to be a pointer to a valid + // `led_classdev_mc`. + unsafe { bindings::led_mc_calc_color_components(classdev.classdev.get(), brightness) }; + + classdev.ops.brightness_set(parent, classdev, brightness)?; + Ok(0) + }) + } + + /// # Safety + /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a + /// `led::MultiColorDevice`. + /// This function is called on getting the brightness of a led. + unsafe extern "C" fn brightness_get_callback(led_cdev: *mut bindings::led_classdev) -> u32 { + // SAFETY: The function's contract guarantees that `led_cdev` is a valid pointer to a + // `led_classdev` embedded within a `led::MultiColorDevice`. + let classdev = unsafe { MultiColorDevice::<T>::from_raw(led_cdev) }; + // SAFETY: `classdev.parent()` is guaranteed to be contained in `T::Bus`. + let parent = unsafe { T::Bus::from_device(classdev.parent()) }; + + classdev.ops.brightness_get(parent, classdev) + } + + /// # Safety + /// `led_cdev` must be a valid pointer to a `led_classdev` embedded within a + /// `led::MultiColorDevice`. + /// `delay_on` and `delay_off` must be valid pointers to `usize` and have + /// exclusive access for the period of this function. + /// This function is called on enabling hardware accelerated blinking. + unsafe extern "C" fn blink_set_callback( + led_cdev: *mut bindings::led_classdev, + delay_on: *mut usize, + delay_off: *mut usize, + ) -> i32 { + from_result(|| { + // SAFETY: The function's contract guarantees that `led_cdev` is a valid pointer to a + // `led_classdev` embedded within a `led::MultiColorDevice`. + let classdev = unsafe { MultiColorDevice::<T>::from_raw(led_cdev) }; + // SAFETY: `classdev.parent()` is guaranteed to be contained in `T::Bus`. + let parent = unsafe { T::Bus::from_device(classdev.parent()) }; + + classdev.ops.blink_set( + parent, + classdev, + // SAFETY: The function's contract guarantees that `delay_on` points to a `usize` + // and is exclusive for the period of this function. + unsafe { &mut *delay_on }, + // SAFETY: The function's contract guarantees that `delay_off` points to a `usize` + // and is exclusive for the period of this function. + unsafe { &mut *delay_off }, + )?; + Ok(0) + }) + } +} + +#[pinned_drop] +impl<T: LedOps<Mode = MultiColor>> PinnedDrop for MultiColorDevice<T> { + fn drop(self: Pin<&mut Self>) { + let raw = self.classdev.get(); + // SAFETY: The existence of `self` guarantees that `self.classdev.get()` is a pointer to a + // valid `led_classdev_mc`. + let dev: &device::Device = unsafe { device::Device::from_raw((*raw).led_cdev.dev) }; + + let _fwnode = dev + .fwnode() + // SAFETY: the reference count of `fwnode` has previously been + // incremented in `led::Device::new`. + .map(|fwnode| unsafe { ARef::from_raw(NonNull::from(fwnode)) }); + + // SAFETY: The existence of `self` guarantees that `self.classdev` has previously been + // successfully registered with `led_classdev_multicolor_register_ext`. + unsafe { bindings::led_classdev_multicolor_unregister(raw) }; + + // SAFETY: `raw` is guaranteed to be a valid pointer to `led_classdev_mc`. + let led_cdev = unsafe { &*raw }; + + // SAFETY: `subled_info` is guaranteed to be a valid array pointer to `mc_subled` with the + // length and capacity of `led_cdev.num_colors`. See `led::MulticolorDevice::new`. + drop(unsafe { + KVec::from_raw_parts( + led_cdev.subled_info, + led_cdev.num_colors as usize, + led_cdev.num_colors as usize, + ) + }); + } +} -- 2.52.0
{ "author": "Markus Probst <markus.probst@posteo.de>", "date": "Mon, 02 Feb 2026 13:52:25 +0000", "thread_id": "20260202-rust_leds-v11-0-585d1c8be20c@posteo.de.mbox.gz" }
lkml
[PATCH v11 0/3] rust: leds: add led classdev abstractions
This patch series has previously been contained in https://lore.kernel.org/rust-for-linux/20251008181027.662616-1-markus.probst@posteo.de/T/#t which added a rust written led driver for a microcontroller via i2c. As the reading and writing to the i2c client via the register! macro has not been implemented yet [1], the patch series will only contain the additional abstractions required. [1] https://lore.kernel.org/rust-for-linux/DDDS2V0V2NVJ.16ZKXCKUA1HUV@kernel.org/ The following changes were made: * add basic led classdev abstractions to register and unregister leds * add basic led classdev abstractions to register and unregister multicolor leds Changes since v10: * allow in-place initialization of `LedOps` * run rustfmt for code inside `try_pin_init!` Changes since v9: * add missing periods in documentation * duplicate `led::Device` and `led::Adapter` instead of using a complex trait * fix imports not using prelude * adapt to CStr change * documented `led::Color::Multi` and `led::Color::Rgb` Changes since v8: * accept `Option<ARef<Fwnode>>` in `led::InitData::fwnode()` * make functions in `MultiColorSubLed` const * drop the "rust: Add trait to convert a device reference to a bus device reference" patch, as it has been picked into driver-core Changes since v7: * adjusted import style * added classdev parameter to callback functions in `LedOps` * implement `led::Color` * extend `led::InitData` with - initial_brightness - default_trigger - default_color * split generic and normal led classdev abstractions up (see patch 3/4) * add multicolor led class device abstractions (see patch 4/4) * added MAINTAINERS entry Changes since v6: * fixed typos * improved documentation Changes since v5: * rename `IntoBusDevice` trait into `AsBusDevice` * fix documentation about `LedOps::BLOCKING` * removed dependency on i2c bindings * added `AsBusDevice` implementation for `platform::Device` * removed `device::Device` fallback implementation * document that `AsBusDevice` must not be used by drivers and is intended for bus and class device abstractions only. Changes since v4: * add abstraction to convert a device reference to a bus device reference * require the bus device as parent device and provide it in class device callbacks * remove Pin<Vec<_>> abstraction (as not relevant for the led abstractions) * fixed formatting in `led::Device::new` * fixed `LedOps::BLOCKING` did the inverse effect Changes since v3: * fixed kunit tests failing because of example in documentation Changes since v2: * return `Devres` on `led::Device` creation * replace KBox<T> with T in struct definition * increment and decrement reference-count of fwnode * make a device parent mandatory for led classdev creation * rename `led::Handler` to `led::LedOps` * add optional `brightness_get` function to `led::LedOps` * use `#[vtable]` instead of `const BLINK: bool` * use `Opaque::cast_from` instead of casting a pointer * improve documentation * improve support for older rust versions * use `&Device<Bound>` for parent Changes since v1: * fixed typos noticed by Onur Özkan Signed-off-by: Markus Probst <markus.probst@posteo.de> --- Markus Probst (3): rust: leds: add basic led classdev abstractions rust: leds: split generic and normal led classdev abstractions up rust: leds: add multicolor classdev abstractions MAINTAINERS | 8 + rust/bindings/bindings_helper.h | 1 + rust/kernel/led.rs | 300 +++++++++++++++++++++++++++++++ rust/kernel/led/multicolor.rs | 382 ++++++++++++++++++++++++++++++++++++++++ rust/kernel/led/normal.rs | 226 ++++++++++++++++++++++++ rust/kernel/lib.rs | 1 + 6 files changed, 918 insertions(+) --- base-commit: 18f7fcd5e69a04df57b563360b88be72471d6b62 change-id: 20251114-rust_leds-a959f7c2f7f9
On Mon Feb 2, 2026 at 1:52 PM GMT, Markus Probst wrote: It appears to me that while this reflects on the C API, on the Rust side this is more commonly known as the builder pattern. I think this should properly be name `led::DeviceBuilder`, as it does more than what `led_init_data` does on the C side (e.g. initial_brightness). Perhaps the device creation can be part of this too, e.g. LedDeviceBuilder::new() .fwnode(...) .devicename(...) .initial_brightness(...) .build(parent, ops) ? `static_assert!()` and move this out from the impl. This should be `fwnode.into_raw()` which directly takes the ownership for `ARef`, rather than `as_raw()` and forget the `ARef` later. Best, Gary
{ "author": "\"Gary Guo\" <gary@garyguo.net>", "date": "Mon, 02 Feb 2026 15:41:56 +0000", "thread_id": "20260202-rust_leds-v11-0-585d1c8be20c@posteo.de.mbox.gz" }
lkml
[PATCH v11 0/3] rust: leds: add led classdev abstractions
This patch series has previously been contained in https://lore.kernel.org/rust-for-linux/20251008181027.662616-1-markus.probst@posteo.de/T/#t which added a rust written led driver for a microcontroller via i2c. As the reading and writing to the i2c client via the register! macro has not been implemented yet [1], the patch series will only contain the additional abstractions required. [1] https://lore.kernel.org/rust-for-linux/DDDS2V0V2NVJ.16ZKXCKUA1HUV@kernel.org/ The following changes were made: * add basic led classdev abstractions to register and unregister leds * add basic led classdev abstractions to register and unregister multicolor leds Changes since v10: * allow in-place initialization of `LedOps` * run rustfmt for code inside `try_pin_init!` Changes since v9: * add missing periods in documentation * duplicate `led::Device` and `led::Adapter` instead of using a complex trait * fix imports not using prelude * adapt to CStr change * documented `led::Color::Multi` and `led::Color::Rgb` Changes since v8: * accept `Option<ARef<Fwnode>>` in `led::InitData::fwnode()` * make functions in `MultiColorSubLed` const * drop the "rust: Add trait to convert a device reference to a bus device reference" patch, as it has been picked into driver-core Changes since v7: * adjusted import style * added classdev parameter to callback functions in `LedOps` * implement `led::Color` * extend `led::InitData` with - initial_brightness - default_trigger - default_color * split generic and normal led classdev abstractions up (see patch 3/4) * add multicolor led class device abstractions (see patch 4/4) * added MAINTAINERS entry Changes since v6: * fixed typos * improved documentation Changes since v5: * rename `IntoBusDevice` trait into `AsBusDevice` * fix documentation about `LedOps::BLOCKING` * removed dependency on i2c bindings * added `AsBusDevice` implementation for `platform::Device` * removed `device::Device` fallback implementation * document that `AsBusDevice` must not be used by drivers and is intended for bus and class device abstractions only. Changes since v4: * add abstraction to convert a device reference to a bus device reference * require the bus device as parent device and provide it in class device callbacks * remove Pin<Vec<_>> abstraction (as not relevant for the led abstractions) * fixed formatting in `led::Device::new` * fixed `LedOps::BLOCKING` did the inverse effect Changes since v3: * fixed kunit tests failing because of example in documentation Changes since v2: * return `Devres` on `led::Device` creation * replace KBox<T> with T in struct definition * increment and decrement reference-count of fwnode * make a device parent mandatory for led classdev creation * rename `led::Handler` to `led::LedOps` * add optional `brightness_get` function to `led::LedOps` * use `#[vtable]` instead of `const BLINK: bool` * use `Opaque::cast_from` instead of casting a pointer * improve documentation * improve support for older rust versions * use `&Device<Bound>` for parent Changes since v1: * fixed typos noticed by Onur Özkan Signed-off-by: Markus Probst <markus.probst@posteo.de> --- Markus Probst (3): rust: leds: add basic led classdev abstractions rust: leds: split generic and normal led classdev abstractions up rust: leds: add multicolor classdev abstractions MAINTAINERS | 8 + rust/bindings/bindings_helper.h | 1 + rust/kernel/led.rs | 300 +++++++++++++++++++++++++++++++ rust/kernel/led/multicolor.rs | 382 ++++++++++++++++++++++++++++++++++++++++ rust/kernel/led/normal.rs | 226 ++++++++++++++++++++++++ rust/kernel/lib.rs | 1 + 6 files changed, 918 insertions(+) --- base-commit: 18f7fcd5e69a04df57b563360b88be72471d6b62 change-id: 20251114-rust_leds-a959f7c2f7f9
On Mon Feb 2, 2026 at 1:52 PM GMT, Markus Probst wrote: This patch deleted a lot of code that's added in the previous one. Could you structure it in a way without doing this? Best, Gary
{ "author": "\"Gary Guo\" <gary@garyguo.net>", "date": "Mon, 02 Feb 2026 15:43:37 +0000", "thread_id": "20260202-rust_leds-v11-0-585d1c8be20c@posteo.de.mbox.gz" }
lkml
[PATCH v11 0/3] rust: leds: add led classdev abstractions
This patch series has previously been contained in https://lore.kernel.org/rust-for-linux/20251008181027.662616-1-markus.probst@posteo.de/T/#t which added a rust written led driver for a microcontroller via i2c. As the reading and writing to the i2c client via the register! macro has not been implemented yet [1], the patch series will only contain the additional abstractions required. [1] https://lore.kernel.org/rust-for-linux/DDDS2V0V2NVJ.16ZKXCKUA1HUV@kernel.org/ The following changes were made: * add basic led classdev abstractions to register and unregister leds * add basic led classdev abstractions to register and unregister multicolor leds Changes since v10: * allow in-place initialization of `LedOps` * run rustfmt for code inside `try_pin_init!` Changes since v9: * add missing periods in documentation * duplicate `led::Device` and `led::Adapter` instead of using a complex trait * fix imports not using prelude * adapt to CStr change * documented `led::Color::Multi` and `led::Color::Rgb` Changes since v8: * accept `Option<ARef<Fwnode>>` in `led::InitData::fwnode()` * make functions in `MultiColorSubLed` const * drop the "rust: Add trait to convert a device reference to a bus device reference" patch, as it has been picked into driver-core Changes since v7: * adjusted import style * added classdev parameter to callback functions in `LedOps` * implement `led::Color` * extend `led::InitData` with - initial_brightness - default_trigger - default_color * split generic and normal led classdev abstractions up (see patch 3/4) * add multicolor led class device abstractions (see patch 4/4) * added MAINTAINERS entry Changes since v6: * fixed typos * improved documentation Changes since v5: * rename `IntoBusDevice` trait into `AsBusDevice` * fix documentation about `LedOps::BLOCKING` * removed dependency on i2c bindings * added `AsBusDevice` implementation for `platform::Device` * removed `device::Device` fallback implementation * document that `AsBusDevice` must not be used by drivers and is intended for bus and class device abstractions only. Changes since v4: * add abstraction to convert a device reference to a bus device reference * require the bus device as parent device and provide it in class device callbacks * remove Pin<Vec<_>> abstraction (as not relevant for the led abstractions) * fixed formatting in `led::Device::new` * fixed `LedOps::BLOCKING` did the inverse effect Changes since v3: * fixed kunit tests failing because of example in documentation Changes since v2: * return `Devres` on `led::Device` creation * replace KBox<T> with T in struct definition * increment and decrement reference-count of fwnode * make a device parent mandatory for led classdev creation * rename `led::Handler` to `led::LedOps` * add optional `brightness_get` function to `led::LedOps` * use `#[vtable]` instead of `const BLINK: bool` * use `Opaque::cast_from` instead of casting a pointer * improve documentation * improve support for older rust versions * use `&Device<Bound>` for parent Changes since v1: * fixed typos noticed by Onur Özkan Signed-off-by: Markus Probst <markus.probst@posteo.de> --- Markus Probst (3): rust: leds: add basic led classdev abstractions rust: leds: split generic and normal led classdev abstractions up rust: leds: add multicolor classdev abstractions MAINTAINERS | 8 + rust/bindings/bindings_helper.h | 1 + rust/kernel/led.rs | 300 +++++++++++++++++++++++++++++++ rust/kernel/led/multicolor.rs | 382 ++++++++++++++++++++++++++++++++++++++++ rust/kernel/led/normal.rs | 226 ++++++++++++++++++++++++ rust/kernel/lib.rs | 1 + 6 files changed, 918 insertions(+) --- base-commit: 18f7fcd5e69a04df57b563360b88be72471d6b62 change-id: 20251114-rust_leds-a959f7c2f7f9
On Mon, 2026-02-02 at 15:41 +0000, Gary Guo wrote: With into_raw(), the reference count of fwnode would not decrement if the registration fails. Thanks - Markus Probst
{ "author": "Markus Probst <markus.probst@posteo.de>", "date": "Mon, 02 Feb 2026 16:53:09 +0000", "thread_id": "20260202-rust_leds-v11-0-585d1c8be20c@posteo.de.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
The update_isolation_cpumasks() function can be called either directly from regular cpuset control file write with cpuset_full_lock() called or via the CPU hotplug path with cpus_write_lock and cpuset_mutex held. As we are going to enable dynamic update to the nozh_full housekeeping cpumask (HK_TYPE_KERNEL_NOISE) soon with the help of CPU hotplug, allowing the CPU hotplug path to call into housekeeping_update() directly from update_isolation_cpumasks() will likely cause deadlock. So we have to defer any call to housekeeping_update() after the CPU hotplug operation has finished. This is now done via the workqueue where the actual housekeeping_update() call, if needed, will happen after cpus_write_lock is released. We can't use the synchronous task_work API as call from CPU hotplug path happen in the per-cpu kthread of the CPU that is being shut down or brought up. Because of the asynchronous nature of workqueue, the HK_TYPE_DOMAIN housekeeping cpumask will be updated a bit later than the "cpuset.cpus.isolated" control file in this case. Also add a check in test_cpuset_prs.sh and modify some existing test cases to confirm that "cpuset.cpus.isolated" and HK_TYPE_DOMAIN housekeeping cpumask will both be updated. Signed-off-by: Waiman Long <longman@redhat.com> --- kernel/cgroup/cpuset.c | 37 +++++++++++++++++-- .../selftests/cgroup/test_cpuset_prs.sh | 13 +++++-- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 7b7d12ab1006..0b0eb1df09d5 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -84,6 +84,9 @@ static cpumask_var_t isolated_cpus; */ static bool isolated_cpus_updating; +/* Both cpuset_mutex and cpus_read_locked acquired */ +static bool cpuset_locked; + /* * A flag to force sched domain rebuild at the end of an operation. * It can be set in @@ -285,10 +288,12 @@ void cpuset_full_lock(void) { cpus_read_lock(); mutex_lock(&cpuset_mutex); + cpuset_locked = true; } void cpuset_full_unlock(void) { + cpuset_locked = false; mutex_unlock(&cpuset_mutex); cpus_read_unlock(); } @@ -1285,6 +1290,16 @@ static bool prstate_housekeeping_conflict(int prstate, struct cpumask *new_cpus) return false; } +static void isolcpus_workfn(struct work_struct *work) +{ + cpuset_full_lock(); + if (isolated_cpus_updating) { + WARN_ON_ONCE(housekeeping_update(isolated_cpus) < 0); + isolated_cpus_updating = false; + } + cpuset_full_unlock(); +} + /* * update_isolation_cpumasks - Update external isolation related CPU masks * @@ -1293,14 +1308,30 @@ static bool prstate_housekeeping_conflict(int prstate, struct cpumask *new_cpus) */ static void update_isolation_cpumasks(void) { - int ret; + static DECLARE_WORK(isolcpus_work, isolcpus_workfn); if (!isolated_cpus_updating) return; - ret = housekeeping_update(isolated_cpus); - WARN_ON_ONCE(ret < 0); + /* + * This function can be reached either directly from regular cpuset + * control file write (cpuset_locked) or via hotplug (cpus_write_lock + * && cpuset_mutex held). In the later case, we defer the + * housekeeping_update() call to the system_unbound_wq to avoid the + * possibility of deadlock. This also means that there will be a short + * period of time where HK_TYPE_DOMAIN housekeeping cpumask will lag + * behind isolated_cpus. + */ + if (!cpuset_locked) { + /* + * We rely on WORK_STRUCT_PENDING_BIT to not requeue a work + * item that is still pending. + */ + queue_work(system_unbound_wq, &isolcpus_work); + return; + } + WARN_ON_ONCE(housekeeping_update(isolated_cpus) < 0); isolated_cpus_updating = false; } diff --git a/tools/testing/selftests/cgroup/test_cpuset_prs.sh b/tools/testing/selftests/cgroup/test_cpuset_prs.sh index 5dff3ad53867..0502b156582b 100755 --- a/tools/testing/selftests/cgroup/test_cpuset_prs.sh +++ b/tools/testing/selftests/cgroup/test_cpuset_prs.sh @@ -245,8 +245,9 @@ TEST_MATRIX=( "C2-3:P1:S+ C3:P2 . . O2=0 O2=1 . . 0 A1:2|A2:3 A1:P1|A2:P2" "C2-3:P1:S+ C3:P1 . . O2=0 . . . 0 A1:|A2:3 A1:P1|A2:P1" "C2-3:P1:S+ C3:P1 . . O3=0 . . . 0 A1:2|A2: A1:P1|A2:P1" - "C2-3:P1:S+ C3:P1 . . T:O2=0 . . . 0 A1:3|A2:3 A1:P1|A2:P-1" - "C2-3:P1:S+ C3:P1 . . . T:O3=0 . . 0 A1:2|A2:2 A1:P1|A2:P-1" + "C2-3:P1:S+ C3:P2 . . T:O2=0 . . . 0 A1:3|A2:3 A1:P1|A2:P-2" + "C1-3:P1:S+ C3:P2 . . . T:O3=0 . . 0 A1:1-2|A2:1-2 A1:P1|A2:P-2 3|" + "C1-3:P1:S+ C3:P2 . . . T:O3=0 O3=1 . 0 A1:1-2|A2:3 A1:P1|A2:P2 3" "$SETUP_A123_PARTITIONS . O1=0 . . . 0 A1:|A2:2|A3:3 A1:P1|A2:P1|A3:P1" "$SETUP_A123_PARTITIONS . O2=0 . . . 0 A1:1|A2:|A3:3 A1:P1|A2:P1|A3:P1" "$SETUP_A123_PARTITIONS . O3=0 . . . 0 A1:1|A2:2|A3: A1:P1|A2:P1|A3:P1" @@ -764,7 +765,7 @@ check_cgroup_states() # only CPUs in isolated partitions as well as those that are isolated at # boot time. # -# $1 - expected isolated cpu list(s) <isolcpus1>{,<isolcpus2>} +# $1 - expected isolated cpu list(s) <isolcpus1>{|<isolcpus2>} # <isolcpus1> - expected sched/domains value # <isolcpus2> - cpuset.cpus.isolated value = <isolcpus1> if not defined # @@ -773,6 +774,7 @@ check_isolcpus() EXPECTED_ISOLCPUS=$1 ISCPUS=${CGROUP2}/cpuset.cpus.isolated ISOLCPUS=$(cat $ISCPUS) + HKICPUS=$(cat /sys/devices/system/cpu/isolated) LASTISOLCPU= SCHED_DOMAINS=/sys/kernel/debug/sched/domains if [[ $EXPECTED_ISOLCPUS = . ]] @@ -810,6 +812,11 @@ check_isolcpus() ISOLCPUS= EXPECTED_ISOLCPUS=$EXPECTED_SDOMAIN + # + # The inverse of HK_TYPE_DOMAIN cpumask in $HKICPUS should match $ISOLCPUS + # + [[ "$ISOLCPUS" != "$HKICPUS" ]] && return 1 + # # Use the sched domain in debugfs to check isolated CPUs, if available # -- 2.52.0
{ "author": "Waiman Long <longman@redhat.com>", "date": "Fri, 30 Jan 2026 10:42:53 -0500", "thread_id": "20260130154254.1422113-1-longman@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
The current cpuset partition code is able to dynamically update the sched domains of a running system and the corresponding HK_TYPE_DOMAIN housekeeping cpumask to perform what is essentally the "isolcpus=domain,..." boot command line feature at run time. The housekeeping cpumask update requires flushing a number of different workqueues which may not be safe with cpus_read_lock() held as the workqueue flushing code may acquire cpus_read_lock() or acquiring locks which have locking dependency with cpus_read_lock() down the chain. Below is an example of such circular locking problem. ====================================================== WARNING: possible circular locking dependency detected 6.18.0-test+ #2 Tainted: G S ------------------------------------------------------ test_cpuset_prs/10971 is trying to acquire lock: ffff888112ba4958 ((wq_completion)sync_wq){+.+.}-{0:0}, at: touch_wq_lockdep_map+0x7a/0x180 but task is already holding lock: ffffffffae47f450 (cpuset_mutex){+.+.}-{4:4}, at: cpuset_partition_write+0x85/0x130 which lock already depends on the new lock. the existing dependency chain (in reverse order) is: -> #4 (cpuset_mutex){+.+.}-{4:4}: -> #3 (cpu_hotplug_lock){++++}-{0:0}: -> #2 (rtnl_mutex){+.+.}-{4:4}: -> #1 ((work_completion)(&arg.work)){+.+.}-{0:0}: -> #0 ((wq_completion)sync_wq){+.+.}-{0:0}: Chain exists of: (wq_completion)sync_wq --> cpu_hotplug_lock --> cpuset_mutex 5 locks held by test_cpuset_prs/10971: #0: ffff88816810e440 (sb_writers#7){.+.+}-{0:0}, at: ksys_write+0xf9/0x1d0 #1: ffff8891ab620890 (&of->mutex#2){+.+.}-{4:4}, at: kernfs_fop_write_iter+0x260/0x5f0 #2: ffff8890a78b83e8 (kn->active#187){.+.+}-{0:0}, at: kernfs_fop_write_iter+0x2b6/0x5f0 #3: ffffffffadf32900 (cpu_hotplug_lock){++++}-{0:0}, at: cpuset_partition_write+0x77/0x130 #4: ffffffffae47f450 (cpuset_mutex){+.+.}-{4:4}, at: cpuset_partition_write+0x85/0x130 Call Trace: <TASK> : touch_wq_lockdep_map+0x93/0x180 __flush_workqueue+0x111/0x10b0 housekeeping_update+0x12d/0x2d0 update_parent_effective_cpumask+0x595/0x2440 update_prstate+0x89d/0xce0 cpuset_partition_write+0xc5/0x130 cgroup_file_write+0x1a5/0x680 kernfs_fop_write_iter+0x3df/0x5f0 vfs_write+0x525/0xfd0 ksys_write+0xf9/0x1d0 do_syscall_64+0x95/0x520 entry_SYSCALL_64_after_hwframe+0x76/0x7e To avoid such a circular locking dependency problem, we have to call housekeeping_update() without holding the cpus_read_lock() and cpuset_mutex. The current set of wq's flushed by housekeeping_update() may not have work functions that call cpus_read_lock() directly, but we are likely to extend the list of wq's that are flushed in the future. Moreover, the current set of work functions may hold locks that may have cpu_hotplug_lock down the dependency chain. One way to do that is to introduce a new top level cpuset_top_mutex which will be acquired first. This new cpuset_top_mutex will provide the need mutual exclusion without the need to hold cpus_read_lock(). As cpus_read_lock() is now no longer held when tmigr_isolated_exclude_cpumask() is called, it needs to acquire it directly. The lockdep_is_cpuset_held() is also updated to check the new cpuset_top_mutex. Signed-off-by: Waiman Long <longman@redhat.com> --- kernel/cgroup/cpuset.c | 101 +++++++++++++++++++++++----------- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- 3 files changed, 70 insertions(+), 38 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 0b0eb1df09d5..edccfa2df9da 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -78,13 +78,13 @@ static cpumask_var_t subpartitions_cpus; static cpumask_var_t isolated_cpus; /* - * isolated_cpus updating flag (protected by cpuset_mutex) + * isolated_cpus updating flag (protected by cpuset_top_mutex) * Set if isolated_cpus is going to be updated in the current * cpuset_mutex crtical section. */ static bool isolated_cpus_updating; -/* Both cpuset_mutex and cpus_read_locked acquired */ +/* cpuset_top_mutex acquired */ static bool cpuset_locked; /* @@ -222,29 +222,44 @@ struct cpuset top_cpuset = { }; /* - * There are two global locks guarding cpuset structures - cpuset_mutex and - * callback_lock. The cpuset code uses only cpuset_mutex. Other kernel - * subsystems can use cpuset_lock()/cpuset_unlock() to prevent change to cpuset - * structures. Note that cpuset_mutex needs to be a mutex as it is used in - * paths that rely on priority inheritance (e.g. scheduler - on RT) for - * correctness. + * CPUSET Locking Convention + * ------------------------- * - * A task must hold both locks to modify cpusets. If a task holds - * cpuset_mutex, it blocks others, ensuring that it is the only task able to - * also acquire callback_lock and be able to modify cpusets. It can perform - * various checks on the cpuset structure first, knowing nothing will change. - * It can also allocate memory while just holding cpuset_mutex. While it is - * performing these checks, various callback routines can briefly acquire - * callback_lock to query cpusets. Once it is ready to make the changes, it - * takes callback_lock, blocking everyone else. + * Below are the four global locks guarding cpuset structures in lock + * acquisition order: + * - cpuset_top_mutex + * - cpu_hotplug_lock (cpus_read_lock/cpus_write_lock) + * - cpuset_mutex + * - callback_lock (raw spinlock) * - * Calls to the kernel memory allocator can not be made while holding - * callback_lock, as that would risk double tripping on callback_lock - * from one of the callbacks into the cpuset code from within - * __alloc_pages(). + * The first cpuset_top_mutex will be held except when calling into + * cpuset_handle_hotplug() from the CPU hotplug code where cpus_write_lock + * and cpuset_mutex will be held instead. * - * If a task is only holding callback_lock, then it has read-only - * access to cpusets. + * As cpuset will now indirectly flush a number of different workqueues in + * housekeeping_update() when the set of isolated CPUs is going to be changed, + * it may not be safe from the circular locking perspective to hold the + * cpus_read_lock. So cpus_read_lock and cpuset_mutex will be released before + * calling housekeeping_update() and re-acquired afterward. + * + * A task must hold all the remaining three locks to modify externally visible + * or used fields of cpusets, though some of the internally used cpuset fields + * can be modified without holding callback_lock. If only reliable read access + * of the externally used fields are needed, a task can hold either + * cpuset_mutex or callback_lock which are exposed to other subsystems. + * + * If a task holds cpu_hotplug_lock and cpuset_mutex, it blocks others, + * ensuring that it is the only task able to also acquire callback_lock and + * be able to modify cpusets. It can perform various checks on the cpuset + * structure first, knowing nothing will change. It can also allocate memory + * without holding callback_lock. While it is performing these checks, various + * callback routines can briefly acquire callback_lock to query cpusets. Once + * it is ready to make the changes, it takes callback_lock, blocking everyone + * else. + * + * Calls to the kernel memory allocator cannot be made while holding + * callback_lock which is a spinlock, as the memory allocator may sleep or + * call back into cpuset code and acquire callback_lock. * * Now, the task_struct fields mems_allowed and mempolicy may be changed * by other task, we use alloc_lock in the task_struct fields to protect @@ -255,6 +270,7 @@ struct cpuset top_cpuset = { * cpumasks and nodemasks. */ +static DEFINE_MUTEX(cpuset_top_mutex); static DEFINE_MUTEX(cpuset_mutex); /** @@ -278,6 +294,18 @@ void lockdep_assert_cpuset_lock_held(void) lockdep_assert_held(&cpuset_mutex); } +static void cpuset_partial_lock(void) +{ + cpus_read_lock(); + mutex_lock(&cpuset_mutex); +} + +static void cpuset_partial_unlock(void) +{ + mutex_unlock(&cpuset_mutex); + cpus_read_unlock(); +} + /** * cpuset_full_lock - Acquire full protection for cpuset modification * @@ -286,22 +314,22 @@ void lockdep_assert_cpuset_lock_held(void) */ void cpuset_full_lock(void) { - cpus_read_lock(); - mutex_lock(&cpuset_mutex); + mutex_lock(&cpuset_top_mutex); + cpuset_partial_lock(); cpuset_locked = true; } void cpuset_full_unlock(void) { cpuset_locked = false; - mutex_unlock(&cpuset_mutex); - cpus_read_unlock(); + cpuset_partial_unlock(); + mutex_unlock(&cpuset_top_mutex); } #ifdef CONFIG_LOCKDEP bool lockdep_is_cpuset_held(void) { - return lockdep_is_held(&cpuset_mutex); + return lockdep_is_held(&cpuset_top_mutex); } #endif @@ -1292,12 +1320,12 @@ static bool prstate_housekeeping_conflict(int prstate, struct cpumask *new_cpus) static void isolcpus_workfn(struct work_struct *work) { - cpuset_full_lock(); - if (isolated_cpus_updating) { - WARN_ON_ONCE(housekeeping_update(isolated_cpus) < 0); - isolated_cpus_updating = false; - } - cpuset_full_unlock(); + guard(mutex)(&cpuset_top_mutex); + if (!isolated_cpus_updating) + return; + + WARN_ON_ONCE(housekeeping_update(isolated_cpus) < 0); + isolated_cpus_updating = false; } /* @@ -1331,8 +1359,15 @@ static void update_isolation_cpumasks(void) return; } + lockdep_assert_held(&cpuset_top_mutex); + /* + * Release cpus_read_lock & cpuset_mutex before calling + * housekeeping_update() and re-acquiring them afterward. + */ + cpuset_partial_unlock(); WARN_ON_ONCE(housekeeping_update(isolated_cpus) < 0); isolated_cpus_updating = false; + cpuset_partial_lock(); } /** diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c index 3b725d39c06e..ef152d401fe2 100644 --- a/kernel/sched/isolation.c +++ b/kernel/sched/isolation.c @@ -123,8 +123,6 @@ int housekeeping_update(struct cpumask *isol_mask) struct cpumask *trial, *old = NULL; int err; - lockdep_assert_cpus_held(); - trial = kmalloc(cpumask_size(), GFP_KERNEL); if (!trial) return -ENOMEM; @@ -136,7 +134,7 @@ int housekeeping_update(struct cpumask *isol_mask) } if (!housekeeping.flags) - static_branch_enable_cpuslocked(&housekeeping_overridden); + static_branch_enable(&housekeeping_overridden); if (housekeeping.flags & HK_FLAG_DOMAIN) old = housekeeping_cpumask_dereference(HK_TYPE_DOMAIN); diff --git a/kernel/time/timer_migration.c b/kernel/time/timer_migration.c index 6da9cd562b20..244a8d025e78 100644 --- a/kernel/time/timer_migration.c +++ b/kernel/time/timer_migration.c @@ -1559,8 +1559,6 @@ int tmigr_isolated_exclude_cpumask(struct cpumask *exclude_cpumask) cpumask_var_t cpumask __free(free_cpumask_var) = CPUMASK_VAR_NULL; int cpu; - lockdep_assert_cpus_held(); - if (!works) return -ENOMEM; if (!alloc_cpumask_var(&cpumask, GFP_KERNEL)) @@ -1570,6 +1568,7 @@ int tmigr_isolated_exclude_cpumask(struct cpumask *exclude_cpumask) * First set previously isolated CPUs as available (unisolate). * This cpumask contains only CPUs that switched to available now. */ + guard(cpus_read_lock)(); cpumask_andnot(cpumask, cpu_online_mask, exclude_cpumask); cpumask_andnot(cpumask, cpumask, tmigr_available_cpumask); -- 2.52.0
{ "author": "Waiman Long <longman@redhat.com>", "date": "Fri, 30 Jan 2026 10:42:54 -0500", "thread_id": "20260130154254.1422113-1-longman@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 2026/1/30 23:42, Waiman Long wrote: Can this happen? cpu0 cpu1 [...] isolated_cpus_updating = true; ... // 'full_lock' is not acquired update_isolation_cpumasks // exec worker concurrently isolcpus_workfn cpuset_full_lock isolated_cpus_updating = false; cpuset_full_unlock(); // This returns uncorrectly if (!isolated_cpus_updating) return; -- Best regards, Ridong
{ "author": "Chen Ridong <chenridong@huaweicloud.com>", "date": "Sat, 31 Jan 2026 08:47:37 +0800", "thread_id": "20260130154254.1422113-1-longman@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 2026/1/30 23:42, Waiman Long wrote: Adding a global variable makes this difficult to handle, especially in concurrent scenarios, since we could read it outside of a critical region. I suggest removing cpuset_locked and adding async_update_isolation_cpumasks instead, which can indicate to the caller it should call without holding the full lock. -- Best regards, Ridong
{ "author": "Chen Ridong <chenridong@huaweicloud.com>", "date": "Sat, 31 Jan 2026 08:58:40 +0800", "thread_id": "20260130154254.1422113-1-longman@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 1/30/26 7:47 PM, Chen Ridong wrote: Note this statement. That is not true. Either cpus_read_lock or cpus_write_lock and cpuset_mutex are held when update_isolation_cpumasks() is called. So there is mutual exclusion. Cheers, Longman
{ "author": "Waiman Long <llong@redhat.com>", "date": "Fri, 30 Jan 2026 20:06:33 -0500", "thread_id": "20260130154254.1422113-1-longman@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 2026/1/31 9:06, Waiman Long wrote: Thank you for reminder. Eh, we currently assume that it can only be called from existing scenarios, so it's okay for now. But I'm concerned that if we later use update_isolation_cpumasks without realizing that we need to hold either cpus_write_lock or (cpus_read_lock && cpuset_mutex) , we could run into concurrency issues. Maybe I'm worrying too much. And maybe we shuold add 'lockdep_assert_held' inside the update_isolation_cpumasks. -- Best regards, Ridong
{ "author": "Chen Ridong <chenridong@huaweicloud.com>", "date": "Sat, 31 Jan 2026 09:43:07 +0800", "thread_id": "20260130154254.1422113-1-longman@redhat.com.mbox.gz" }
lkml
[PATCH/for-next v2 0/2] cgroup/cpuset: Fix partition related locking issues
v2: - Change patch 1 to use workqueue instead of task run as it is a per-cpu kthread that performs the cpuset shutdown and bringup work. - Simplify and streamline some of the code. After booting the latest cgroup for-next debug kernel with the latest cgroup changes as well as Federic's "cpuset/isolation: Honour kthreads preferred affinity" patch series [1] merged on top and running the test-cpuset-prs.sh test, a circular locking dependency lockdep splat was reported. See patch 2 for details. The following changes are made to resolve this locking problem. 1) Deferring calling housekeeping_update() from CPU hotplug to workqueue 2) Release cpus_read_lock before calling housekeeping_update() With these changes, the cpuset test ran to completion with no failure and no lockdep splat. [1] https://lore.kernel.org/lkml/20260125224541.50226-1-frederic@kernel.org/ Waiman Long (2): cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to workqueue cgroup/cpuset: Introduce a new top level cpuset_top_mutex kernel/cgroup/cpuset.c | 124 ++++++++++++++---- kernel/sched/isolation.c | 4 +- kernel/time/timer_migration.c | 3 +- .../selftests/cgroup/test_cpuset_prs.sh | 13 +- 4 files changed, 107 insertions(+), 37 deletions(-) -- 2.52.0
On 1/30/26 7:58 PM, Chen Ridong wrote: No, cpuset_locked is always read from or written into inside a critical section. It is under cpuset_mutex up to this point and then with the cpuset_top_mutex with the next patch. The point of this global variable is to distinguish between calling from CPU hotplug and the other regular cpuset code paths. The only difference between these two are having cpus_read_lock or cpus_write_lock held. That is why I think adding a global variable in cpuset_full_lock() is the easy way. Otherwise, we will to add extra argument to some of the functions to distinguish these two cases. Cheers, Longman
{ "author": "Waiman Long <llong@redhat.com>", "date": "Fri, 30 Jan 2026 20:45:52 -0500", "thread_id": "20260130154254.1422113-1-longman@redhat.com.mbox.gz" }