source
large_stringclasses
2 values
subject
large_stringclasses
112 values
code
large_stringclasses
112 values
critique
large_stringlengths
61
3.04M
metadata
dict
lkml
[PATCH v4 00/10] x86/entry/vdso: clean up the vdso build, vdso updates
This patchset cleans up the vdso build by building the 32- and 64-bit vdsos in separate directories, moving the vdso2c tool to arch/x86/tools, and by merging common code and especially Makefile rules between the 32- and 64-bit vdsos to the greatest extent possible. Be more strict about sanitizing and standardizing the vdso build options. Disable CFI for the vdso until the kernel adds user space IBT support. Modernize the DWARF generation vdso32/sigreturn.S. Add macros to cleanly call system calls from vdso source code. Add the GNU_PROPERTY and GNU_STACK PHDRs to the vdso. When using int $0x80 (old 32-bit hardware or FRED-capable 64-bit hardware) skip the stack stuff in the 32-bit kernel entry code and call int $0x80 directly when used from C code. Changes from v3 to v4: - Improved description of patch 01/10. - Split out the move of vdso2c to tools into a separate patch. - Remove unrelated formatting changes from vdso-layout.lds.S. - Fix *-x32.o being missing from "targets". - Rebased onto v6.19-rc1. Changes from v2 to v3: In arch/x86/include/asm/vdso/sys_call.h: - remove stray comment from prototyping (Uros Biszjak) - remove VDSO_SYSCALL6() since it would require special handling on 32 bits with frame pointers and is currently unused. (Uros Biszjak) - indent nested preprocessor directives. Changes from v1 to v2: Too many to count - much of the patchset has been reworked Patches: x86/entry/vdso: rename vdso_image_* to vdso*_image x86/entry/vdso: move vdso2c to arch/x86/tools x86/entry/vdso: refactor the vdso build x86/entry/vdso32: don't rely on int80_landing_pad for adjusting ip x86/entry/vdso32: remove SYSCALL_ENTER_KERNEL macro in sigreturn.S x86/entry/vdso32: remove open-coded DWARF in sigreturn.S x86/entry/vdso: include GNU_PROPERTY and GNU_STACK PHDRs x86/vdso: abstract out vdso system call internals x86/cpufeature: replace X86_FEATURE_SYSENTER32 with X86_FEATURE_SYSFAST32 x86/entry/vdso32: when using int $0x80, use it directly --- arch/x86/Kconfig.cpufeatures | 8 + arch/x86/Makefile | 2 +- arch/x86/entry/syscall_32.c | 2 +- arch/x86/entry/vdso/.gitignore | 11 +- arch/x86/entry/vdso/Makefile | 162 +-------------------- arch/x86/entry/vdso/common/Makefile.include | 89 +++++++++++ arch/x86/entry/vdso/{vdso-note.S => common/note.S} | 5 +- arch/x86/entry/vdso/{ => common}/vclock_gettime.c | 0 arch/x86/entry/vdso/{ => common}/vdso-layout.lds.S | 38 +++-- arch/x86/entry/vdso/{ => common}/vgetcpu.c | 0 arch/x86/entry/vdso/vdso32/Makefile | 24 +++ arch/x86/entry/vdso/vdso32/note.S | 19 +-- arch/x86/entry/vdso/vdso32/sigreturn.S | 152 +++++-------------- arch/x86/entry/vdso/vdso32/system_call.S | 22 ++- arch/x86/entry/vdso/vdso32/vclock_gettime.c | 5 +- arch/x86/entry/vdso/vdso32/vdso32.lds.S | 2 +- arch/x86/entry/vdso/vdso32/vgetcpu.c | 4 +- arch/x86/entry/vdso/vdso64/Makefile | 46 ++++++ arch/x86/entry/vdso/vdso64/note.S | 1 + arch/x86/entry/vdso/vdso64/vclock_gettime.c | 1 + .../entry/vdso/{vdso.lds.S => vdso64/vdso64.lds.S} | 2 +- arch/x86/entry/vdso/{ => vdso64}/vdsox32.lds.S | 2 +- arch/x86/entry/vdso/vdso64/vgetcpu.c | 1 + .../entry/vdso/{ => vdso64}/vgetrandom-chacha.S | 0 arch/x86/entry/vdso/{ => vdso64}/vgetrandom.c | 2 +- arch/x86/entry/vdso/{ => vdso64}/vsgx.S | 0 arch/x86/entry/vdso/vma.c | 24 ++- arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/include/asm/dwarf2.h | 1 + arch/x86/include/asm/elf.h | 2 +- arch/x86/include/asm/vdso.h | 6 +- arch/x86/include/asm/vdso/gettimeofday.h | 108 +------------- arch/x86/include/asm/vdso/sys_call.h | 105 +++++++++++++ arch/x86/kernel/asm-offsets.c | 6 + arch/x86/kernel/cpu/centaur.c | 3 - arch/x86/kernel/cpu/common.c | 8 + arch/x86/kernel/cpu/intel.c | 4 +- arch/x86/kernel/cpu/zhaoxin.c | 4 +- arch/x86/kernel/fred.c | 2 +- arch/x86/kernel/process_64.c | 6 +- arch/x86/kernel/signal_32.c | 4 +- arch/x86/tools/Makefile | 15 +- arch/x86/{entry/vdso => tools}/vdso2c.c | 0 arch/x86/{entry/vdso => tools}/vdso2c.h | 0 arch/x86/xen/setup.c | 28 ++-- arch/x86/xen/smp_pv.c | 5 +- arch/x86/xen/xen-ops.h | 1 - 47 files changed, 444 insertions(+), 490 deletions(-)
The following commit has been merged into the x86/entry branch of tip: Commit-ID: 36d83c249e0395a915144eceeb528ddc19b1fbe6 Gitweb: https://git.kernel.org/tip/36d83c249e0395a915144eceeb528ddc19b1fbe6 Author: H. Peter Anvin <hpa@zytor.com> AuthorDate: Tue, 16 Dec 2025 13:26:04 -08:00 Committer: Dave Hansen <dave.hansen@linux.intel.com> CommitterDate: Tue, 13 Jan 2026 16:37:58 -08:00 x86/entry/vdso32: When using int $0x80, use it directly When neither sysenter32 nor syscall32 is available (on either FRED-capable 64-bit hardware or old 32-bit hardware), there is no reason to do a bunch of stack shuffling in __kernel_vsyscall. Unfortunately, just overwriting the initial "push" instructions will mess up the CFI annotations, so suffer the 3-byte NOP if not applicable. Similarly, inline the int $0x80 when doing inline system calls in the vdso instead of calling __kernel_vsyscall. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Link: https://patch.msgid.link/20251216212606.1325678-11-hpa@zytor.com --- arch/x86/entry/vdso/vdso32/system_call.S | 18 ++++++++++++++---- arch/x86/include/asm/vdso/sys_call.h | 4 +++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/arch/x86/entry/vdso/vdso32/system_call.S b/arch/x86/entry/vdso/vdso32/system_call.S index 7b1c0f1..9157cf9 100644 --- a/arch/x86/entry/vdso/vdso32/system_call.S +++ b/arch/x86/entry/vdso/vdso32/system_call.S @@ -14,6 +14,18 @@ ALIGN __kernel_vsyscall: CFI_STARTPROC + + /* + * If using int $0x80, there is no reason to muck about with the + * stack here. Unfortunately just overwriting the push instructions + * would mess up the CFI annotations, but it is only a 3-byte + * NOP in that case. This could be avoided by patching the + * vdso symbol table (not the code) and entry point, but that + * would a fair bit of tooling work or by simply compiling + * two different vDSO images, but that doesn't seem worth it. + */ + ALTERNATIVE "int $0x80; ret", "", X86_FEATURE_SYSFAST32 + /* * Reshuffle regs so that all of any of the entry instructions * will preserve enough state. @@ -52,11 +64,9 @@ __kernel_vsyscall: #define SYSENTER_SEQUENCE "movl %esp, %ebp; sysenter" #define SYSCALL_SEQUENCE "movl %ecx, %ebp; syscall" - /* If SYSENTER (Intel) or SYSCALL32 (AMD) is available, use it. */ - ALTERNATIVE_2 "", SYSENTER_SEQUENCE, X86_FEATURE_SYSFAST32, \ - SYSCALL_SEQUENCE, X86_FEATURE_SYSCALL32 + ALTERNATIVE SYSENTER_SEQUENCE, SYSCALL_SEQUENCE, X86_FEATURE_SYSCALL32 - /* Enter using int $0x80 */ + /* Re-enter using int $0x80 */ int $0x80 SYM_INNER_LABEL(int80_landing_pad, SYM_L_GLOBAL) diff --git a/arch/x86/include/asm/vdso/sys_call.h b/arch/x86/include/asm/vdso/sys_call.h index dcfd17c..5806b1c 100644 --- a/arch/x86/include/asm/vdso/sys_call.h +++ b/arch/x86/include/asm/vdso/sys_call.h @@ -20,7 +20,9 @@ # define __sys_reg4 "r10" # define __sys_reg5 "r8" #else -# define __sys_instr "call __kernel_vsyscall" +# define __sys_instr ALTERNATIVE("ds;ds;ds;int $0x80", \ + "call __kernel_vsyscall", \ + X86_FEATURE_SYSFAST32) # define __sys_clobber "memory" # define __sys_nr(x,y) __NR_ ## x ## y # define __sys_reg1 "ebx"
{ "author": "\"tip-bot2 for H. Peter Anvin\" <tip-bot2@linutronix.de>", "date": "Wed, 14 Jan 2026 00:44:45 -0000", "thread_id": "223707e2-3231-4037-bd1f-490ddf6aeeb6@linux.ibm.com.mbox.gz" }
lkml
[PATCH v4 00/10] x86/entry/vdso: clean up the vdso build, vdso updates
This patchset cleans up the vdso build by building the 32- and 64-bit vdsos in separate directories, moving the vdso2c tool to arch/x86/tools, and by merging common code and especially Makefile rules between the 32- and 64-bit vdsos to the greatest extent possible. Be more strict about sanitizing and standardizing the vdso build options. Disable CFI for the vdso until the kernel adds user space IBT support. Modernize the DWARF generation vdso32/sigreturn.S. Add macros to cleanly call system calls from vdso source code. Add the GNU_PROPERTY and GNU_STACK PHDRs to the vdso. When using int $0x80 (old 32-bit hardware or FRED-capable 64-bit hardware) skip the stack stuff in the 32-bit kernel entry code and call int $0x80 directly when used from C code. Changes from v3 to v4: - Improved description of patch 01/10. - Split out the move of vdso2c to tools into a separate patch. - Remove unrelated formatting changes from vdso-layout.lds.S. - Fix *-x32.o being missing from "targets". - Rebased onto v6.19-rc1. Changes from v2 to v3: In arch/x86/include/asm/vdso/sys_call.h: - remove stray comment from prototyping (Uros Biszjak) - remove VDSO_SYSCALL6() since it would require special handling on 32 bits with frame pointers and is currently unused. (Uros Biszjak) - indent nested preprocessor directives. Changes from v1 to v2: Too many to count - much of the patchset has been reworked Patches: x86/entry/vdso: rename vdso_image_* to vdso*_image x86/entry/vdso: move vdso2c to arch/x86/tools x86/entry/vdso: refactor the vdso build x86/entry/vdso32: don't rely on int80_landing_pad for adjusting ip x86/entry/vdso32: remove SYSCALL_ENTER_KERNEL macro in sigreturn.S x86/entry/vdso32: remove open-coded DWARF in sigreturn.S x86/entry/vdso: include GNU_PROPERTY and GNU_STACK PHDRs x86/vdso: abstract out vdso system call internals x86/cpufeature: replace X86_FEATURE_SYSENTER32 with X86_FEATURE_SYSFAST32 x86/entry/vdso32: when using int $0x80, use it directly --- arch/x86/Kconfig.cpufeatures | 8 + arch/x86/Makefile | 2 +- arch/x86/entry/syscall_32.c | 2 +- arch/x86/entry/vdso/.gitignore | 11 +- arch/x86/entry/vdso/Makefile | 162 +-------------------- arch/x86/entry/vdso/common/Makefile.include | 89 +++++++++++ arch/x86/entry/vdso/{vdso-note.S => common/note.S} | 5 +- arch/x86/entry/vdso/{ => common}/vclock_gettime.c | 0 arch/x86/entry/vdso/{ => common}/vdso-layout.lds.S | 38 +++-- arch/x86/entry/vdso/{ => common}/vgetcpu.c | 0 arch/x86/entry/vdso/vdso32/Makefile | 24 +++ arch/x86/entry/vdso/vdso32/note.S | 19 +-- arch/x86/entry/vdso/vdso32/sigreturn.S | 152 +++++-------------- arch/x86/entry/vdso/vdso32/system_call.S | 22 ++- arch/x86/entry/vdso/vdso32/vclock_gettime.c | 5 +- arch/x86/entry/vdso/vdso32/vdso32.lds.S | 2 +- arch/x86/entry/vdso/vdso32/vgetcpu.c | 4 +- arch/x86/entry/vdso/vdso64/Makefile | 46 ++++++ arch/x86/entry/vdso/vdso64/note.S | 1 + arch/x86/entry/vdso/vdso64/vclock_gettime.c | 1 + .../entry/vdso/{vdso.lds.S => vdso64/vdso64.lds.S} | 2 +- arch/x86/entry/vdso/{ => vdso64}/vdsox32.lds.S | 2 +- arch/x86/entry/vdso/vdso64/vgetcpu.c | 1 + .../entry/vdso/{ => vdso64}/vgetrandom-chacha.S | 0 arch/x86/entry/vdso/{ => vdso64}/vgetrandom.c | 2 +- arch/x86/entry/vdso/{ => vdso64}/vsgx.S | 0 arch/x86/entry/vdso/vma.c | 24 ++- arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/include/asm/dwarf2.h | 1 + arch/x86/include/asm/elf.h | 2 +- arch/x86/include/asm/vdso.h | 6 +- arch/x86/include/asm/vdso/gettimeofday.h | 108 +------------- arch/x86/include/asm/vdso/sys_call.h | 105 +++++++++++++ arch/x86/kernel/asm-offsets.c | 6 + arch/x86/kernel/cpu/centaur.c | 3 - arch/x86/kernel/cpu/common.c | 8 + arch/x86/kernel/cpu/intel.c | 4 +- arch/x86/kernel/cpu/zhaoxin.c | 4 +- arch/x86/kernel/fred.c | 2 +- arch/x86/kernel/process_64.c | 6 +- arch/x86/kernel/signal_32.c | 4 +- arch/x86/tools/Makefile | 15 +- arch/x86/{entry/vdso => tools}/vdso2c.c | 0 arch/x86/{entry/vdso => tools}/vdso2c.h | 0 arch/x86/xen/setup.c | 28 ++-- arch/x86/xen/smp_pv.c | 5 +- arch/x86/xen/xen-ops.h | 1 - 47 files changed, 444 insertions(+), 490 deletions(-)
The following commit has been merged into the x86/entry branch of tip: Commit-ID: f49ecf5e110ab0ed255ddea5e321689faf4e50e6 Gitweb: https://git.kernel.org/tip/f49ecf5e110ab0ed255ddea5e321689faf4e50e6 Author: H. Peter Anvin <hpa@zytor.com> AuthorDate: Tue, 16 Dec 2025 13:26:03 -08:00 Committer: Dave Hansen <dave.hansen@linux.intel.com> CommitterDate: Tue, 13 Jan 2026 16:37:58 -08:00 x86/cpufeature: Replace X86_FEATURE_SYSENTER32 with X86_FEATURE_SYSFAST32 In most cases, the use of "fast 32-bit system call" depends either on X86_FEATURE_SEP or X86_FEATURE_SYSENTER32 || X86_FEATURE_SYSCALL32. However, nearly all the logic for both is identical. Define X86_FEATURE_SYSFAST32 which indicates that *either* SYSENTER32 or SYSCALL32 should be used, for either 32- or 64-bit kernels. This defaults to SYSENTER; use SYSCALL if the SYSCALL32 bit is also set. As this removes ALL existing uses of X86_FEATURE_SYSENTER32, which is a kernel-only synthetic feature bit, simply remove it and replace it with X86_FEATURE_SYSFAST32. This leaves an unused alternative for a true 32-bit kernel, but that should really not matter in any way. The clearing of X86_FEATURE_SYSCALL32 can be removed once the patches for automatically clearing disabled features has been merged. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Link: https://patch.msgid.link/20251216212606.1325678-10-hpa@zytor.com --- arch/x86/Kconfig.cpufeatures | 8 +++++++- arch/x86/entry/vdso/vdso32/system_call.S | 8 +------ arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/kernel/cpu/centaur.c | 3 +-- arch/x86/kernel/cpu/common.c | 8 +++++++- arch/x86/kernel/cpu/intel.c | 4 +--- arch/x86/kernel/cpu/zhaoxin.c | 4 +--- arch/x86/kernel/fred.c | 2 +- arch/x86/xen/setup.c | 28 ++++++++++++++--------- arch/x86/xen/smp_pv.c | 5 +--- arch/x86/xen/xen-ops.h | 1 +- 11 files changed, 42 insertions(+), 31 deletions(-) diff --git a/arch/x86/Kconfig.cpufeatures b/arch/x86/Kconfig.cpufeatures index 733d5af..423ac79 100644 --- a/arch/x86/Kconfig.cpufeatures +++ b/arch/x86/Kconfig.cpufeatures @@ -56,6 +56,10 @@ config X86_REQUIRED_FEATURE_MOVBE def_bool y depends on MATOM +config X86_REQUIRED_FEATURE_SYSFAST32 + def_bool y + depends on X86_64 && !X86_FRED + config X86_REQUIRED_FEATURE_CPUID def_bool y depends on X86_64 @@ -120,6 +124,10 @@ config X86_DISABLED_FEATURE_CENTAUR_MCR def_bool y depends on X86_64 +config X86_DISABLED_FEATURE_SYSCALL32 + def_bool y + depends on !X86_64 + config X86_DISABLED_FEATURE_PCID def_bool y depends on !X86_64 diff --git a/arch/x86/entry/vdso/vdso32/system_call.S b/arch/x86/entry/vdso/vdso32/system_call.S index 2a15634..7b1c0f1 100644 --- a/arch/x86/entry/vdso/vdso32/system_call.S +++ b/arch/x86/entry/vdso/vdso32/system_call.S @@ -52,13 +52,9 @@ __kernel_vsyscall: #define SYSENTER_SEQUENCE "movl %esp, %ebp; sysenter" #define SYSCALL_SEQUENCE "movl %ecx, %ebp; syscall" -#ifdef BUILD_VDSO32_64 /* If SYSENTER (Intel) or SYSCALL32 (AMD) is available, use it. */ - ALTERNATIVE_2 "", SYSENTER_SEQUENCE, X86_FEATURE_SYSENTER32, \ - SYSCALL_SEQUENCE, X86_FEATURE_SYSCALL32 -#else - ALTERNATIVE "", SYSENTER_SEQUENCE, X86_FEATURE_SEP -#endif + ALTERNATIVE_2 "", SYSENTER_SEQUENCE, X86_FEATURE_SYSFAST32, \ + SYSCALL_SEQUENCE, X86_FEATURE_SYSCALL32 /* Enter using int $0x80 */ int $0x80 diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index c3b53be..63b0f9a 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -84,7 +84,7 @@ #define X86_FEATURE_PEBS ( 3*32+12) /* "pebs" Precise-Event Based Sampling */ #define X86_FEATURE_BTS ( 3*32+13) /* "bts" Branch Trace Store */ #define X86_FEATURE_SYSCALL32 ( 3*32+14) /* syscall in IA32 userspace */ -#define X86_FEATURE_SYSENTER32 ( 3*32+15) /* sysenter in IA32 userspace */ +#define X86_FEATURE_SYSFAST32 ( 3*32+15) /* sysenter/syscall in IA32 userspace */ #define X86_FEATURE_REP_GOOD ( 3*32+16) /* "rep_good" REP microcode works well */ #define X86_FEATURE_AMD_LBR_V2 ( 3*32+17) /* "amd_lbr_v2" AMD Last Branch Record Extension Version 2 */ #define X86_FEATURE_CLEAR_CPU_BUF ( 3*32+18) /* Clear CPU buffers using VERW */ diff --git a/arch/x86/kernel/cpu/centaur.c b/arch/x86/kernel/cpu/centaur.c index a3b55db..9833f83 100644 --- a/arch/x86/kernel/cpu/centaur.c +++ b/arch/x86/kernel/cpu/centaur.c @@ -102,9 +102,6 @@ static void early_init_centaur(struct cpuinfo_x86 *c) (c->x86 >= 7)) set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); -#ifdef CONFIG_X86_64 - set_cpu_cap(c, X86_FEATURE_SYSENTER32); -#endif if (c->x86_power & (1 << 8)) { set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC); diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index e7ab22f..1c3261c 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1068,6 +1068,9 @@ void get_cpu_cap(struct cpuinfo_x86 *c) init_scattered_cpuid_features(c); init_speculation_control(c); + if (IS_ENABLED(CONFIG_X86_64) || cpu_has(c, X86_FEATURE_SEP)) + set_cpu_cap(c, X86_FEATURE_SYSFAST32); + /* * Clear/Set all flags overridden by options, after probe. * This needs to happen each time we re-probe, which may happen @@ -1813,6 +1816,11 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c) * that it can't be enabled in 32-bit mode. */ setup_clear_cpu_cap(X86_FEATURE_PCID); + + /* + * Never use SYSCALL on a 32-bit kernel + */ + setup_clear_cpu_cap(X86_FEATURE_SYSCALL32); #endif /* diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index 98ae4c3..646ff33 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -236,9 +236,7 @@ static void early_init_intel(struct cpuinfo_x86 *c) clear_cpu_cap(c, X86_FEATURE_PSE); } -#ifdef CONFIG_X86_64 - set_cpu_cap(c, X86_FEATURE_SYSENTER32); -#else +#ifndef CONFIG_X86_64 /* Netburst reports 64 bytes clflush size, but does IO in 128 bytes */ if (c->x86 == 15 && c->x86_cache_alignment == 64) c->x86_cache_alignment = 128; diff --git a/arch/x86/kernel/cpu/zhaoxin.c b/arch/x86/kernel/cpu/zhaoxin.c index 89b1c8a..031379b 100644 --- a/arch/x86/kernel/cpu/zhaoxin.c +++ b/arch/x86/kernel/cpu/zhaoxin.c @@ -59,9 +59,7 @@ static void early_init_zhaoxin(struct cpuinfo_x86 *c) { if (c->x86 >= 0x6) set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); -#ifdef CONFIG_X86_64 - set_cpu_cap(c, X86_FEATURE_SYSENTER32); -#endif + if (c->x86_power & (1 << 8)) { set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC); diff --git a/arch/x86/kernel/fred.c b/arch/x86/kernel/fred.c index 816187d..e736b19 100644 --- a/arch/x86/kernel/fred.c +++ b/arch/x86/kernel/fred.c @@ -68,7 +68,7 @@ void cpu_init_fred_exceptions(void) idt_invalidate(); /* Use int $0x80 for 32-bit system calls in FRED mode */ - setup_clear_cpu_cap(X86_FEATURE_SYSENTER32); + setup_clear_cpu_cap(X86_FEATURE_SYSFAST32); setup_clear_cpu_cap(X86_FEATURE_SYSCALL32); } diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c index 3823e52..ac8021c 100644 --- a/arch/x86/xen/setup.c +++ b/arch/x86/xen/setup.c @@ -990,13 +990,6 @@ static int register_callback(unsigned type, const void *func) return HYPERVISOR_callback_op(CALLBACKOP_register, &callback); } -void xen_enable_sysenter(void) -{ - if (cpu_feature_enabled(X86_FEATURE_SYSENTER32) && - register_callback(CALLBACKTYPE_sysenter, xen_entry_SYSENTER_compat)) - setup_clear_cpu_cap(X86_FEATURE_SYSENTER32); -} - void xen_enable_syscall(void) { int ret; @@ -1008,11 +1001,27 @@ void xen_enable_syscall(void) mechanism for syscalls. */ } - if (cpu_feature_enabled(X86_FEATURE_SYSCALL32) && - register_callback(CALLBACKTYPE_syscall32, xen_entry_SYSCALL_compat)) + if (!cpu_feature_enabled(X86_FEATURE_SYSFAST32)) + return; + + if (cpu_feature_enabled(X86_FEATURE_SYSCALL32)) { + /* Use SYSCALL32 */ + ret = register_callback(CALLBACKTYPE_syscall32, + xen_entry_SYSCALL_compat); + + } else { + /* Use SYSENTER32 */ + ret = register_callback(CALLBACKTYPE_sysenter, + xen_entry_SYSENTER_compat); + } + + if (ret) { setup_clear_cpu_cap(X86_FEATURE_SYSCALL32); + setup_clear_cpu_cap(X86_FEATURE_SYSFAST32); + } } + static void __init xen_pvmmu_arch_setup(void) { HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_writable_pagetables); @@ -1022,7 +1031,6 @@ static void __init xen_pvmmu_arch_setup(void) register_callback(CALLBACKTYPE_failsafe, xen_failsafe_callback)) BUG(); - xen_enable_sysenter(); xen_enable_syscall(); } diff --git a/arch/x86/xen/smp_pv.c b/arch/x86/xen/smp_pv.c index 9bb8ff8..c40f326 100644 --- a/arch/x86/xen/smp_pv.c +++ b/arch/x86/xen/smp_pv.c @@ -65,10 +65,9 @@ static void cpu_bringup(void) touch_softlockup_watchdog(); /* PVH runs in ring 0 and allows us to do native syscalls. Yay! */ - if (!xen_feature(XENFEAT_supervisor_mode_kernel)) { - xen_enable_sysenter(); + if (!xen_feature(XENFEAT_supervisor_mode_kernel)) xen_enable_syscall(); - } + cpu = smp_processor_id(); identify_secondary_cpu(cpu); set_cpu_sibling_map(cpu); diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h index 090349b..f6c331b 100644 --- a/arch/x86/xen/xen-ops.h +++ b/arch/x86/xen/xen-ops.h @@ -60,7 +60,6 @@ phys_addr_t __init xen_find_free_area(phys_addr_t size); char * __init xen_memory_setup(void); void __init xen_arch_setup(void); void xen_banner(void); -void xen_enable_sysenter(void); void xen_enable_syscall(void); void xen_vcpu_restore(void);
{ "author": "\"tip-bot2 for H. Peter Anvin\" <tip-bot2@linutronix.de>", "date": "Wed, 14 Jan 2026 00:44:49 -0000", "thread_id": "223707e2-3231-4037-bd1f-490ddf6aeeb6@linux.ibm.com.mbox.gz" }
lkml
[PATCH v4 00/10] x86/entry/vdso: clean up the vdso build, vdso updates
This patchset cleans up the vdso build by building the 32- and 64-bit vdsos in separate directories, moving the vdso2c tool to arch/x86/tools, and by merging common code and especially Makefile rules between the 32- and 64-bit vdsos to the greatest extent possible. Be more strict about sanitizing and standardizing the vdso build options. Disable CFI for the vdso until the kernel adds user space IBT support. Modernize the DWARF generation vdso32/sigreturn.S. Add macros to cleanly call system calls from vdso source code. Add the GNU_PROPERTY and GNU_STACK PHDRs to the vdso. When using int $0x80 (old 32-bit hardware or FRED-capable 64-bit hardware) skip the stack stuff in the 32-bit kernel entry code and call int $0x80 directly when used from C code. Changes from v3 to v4: - Improved description of patch 01/10. - Split out the move of vdso2c to tools into a separate patch. - Remove unrelated formatting changes from vdso-layout.lds.S. - Fix *-x32.o being missing from "targets". - Rebased onto v6.19-rc1. Changes from v2 to v3: In arch/x86/include/asm/vdso/sys_call.h: - remove stray comment from prototyping (Uros Biszjak) - remove VDSO_SYSCALL6() since it would require special handling on 32 bits with frame pointers and is currently unused. (Uros Biszjak) - indent nested preprocessor directives. Changes from v1 to v2: Too many to count - much of the patchset has been reworked Patches: x86/entry/vdso: rename vdso_image_* to vdso*_image x86/entry/vdso: move vdso2c to arch/x86/tools x86/entry/vdso: refactor the vdso build x86/entry/vdso32: don't rely on int80_landing_pad for adjusting ip x86/entry/vdso32: remove SYSCALL_ENTER_KERNEL macro in sigreturn.S x86/entry/vdso32: remove open-coded DWARF in sigreturn.S x86/entry/vdso: include GNU_PROPERTY and GNU_STACK PHDRs x86/vdso: abstract out vdso system call internals x86/cpufeature: replace X86_FEATURE_SYSENTER32 with X86_FEATURE_SYSFAST32 x86/entry/vdso32: when using int $0x80, use it directly --- arch/x86/Kconfig.cpufeatures | 8 + arch/x86/Makefile | 2 +- arch/x86/entry/syscall_32.c | 2 +- arch/x86/entry/vdso/.gitignore | 11 +- arch/x86/entry/vdso/Makefile | 162 +-------------------- arch/x86/entry/vdso/common/Makefile.include | 89 +++++++++++ arch/x86/entry/vdso/{vdso-note.S => common/note.S} | 5 +- arch/x86/entry/vdso/{ => common}/vclock_gettime.c | 0 arch/x86/entry/vdso/{ => common}/vdso-layout.lds.S | 38 +++-- arch/x86/entry/vdso/{ => common}/vgetcpu.c | 0 arch/x86/entry/vdso/vdso32/Makefile | 24 +++ arch/x86/entry/vdso/vdso32/note.S | 19 +-- arch/x86/entry/vdso/vdso32/sigreturn.S | 152 +++++-------------- arch/x86/entry/vdso/vdso32/system_call.S | 22 ++- arch/x86/entry/vdso/vdso32/vclock_gettime.c | 5 +- arch/x86/entry/vdso/vdso32/vdso32.lds.S | 2 +- arch/x86/entry/vdso/vdso32/vgetcpu.c | 4 +- arch/x86/entry/vdso/vdso64/Makefile | 46 ++++++ arch/x86/entry/vdso/vdso64/note.S | 1 + arch/x86/entry/vdso/vdso64/vclock_gettime.c | 1 + .../entry/vdso/{vdso.lds.S => vdso64/vdso64.lds.S} | 2 +- arch/x86/entry/vdso/{ => vdso64}/vdsox32.lds.S | 2 +- arch/x86/entry/vdso/vdso64/vgetcpu.c | 1 + .../entry/vdso/{ => vdso64}/vgetrandom-chacha.S | 0 arch/x86/entry/vdso/{ => vdso64}/vgetrandom.c | 2 +- arch/x86/entry/vdso/{ => vdso64}/vsgx.S | 0 arch/x86/entry/vdso/vma.c | 24 ++- arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/include/asm/dwarf2.h | 1 + arch/x86/include/asm/elf.h | 2 +- arch/x86/include/asm/vdso.h | 6 +- arch/x86/include/asm/vdso/gettimeofday.h | 108 +------------- arch/x86/include/asm/vdso/sys_call.h | 105 +++++++++++++ arch/x86/kernel/asm-offsets.c | 6 + arch/x86/kernel/cpu/centaur.c | 3 - arch/x86/kernel/cpu/common.c | 8 + arch/x86/kernel/cpu/intel.c | 4 +- arch/x86/kernel/cpu/zhaoxin.c | 4 +- arch/x86/kernel/fred.c | 2 +- arch/x86/kernel/process_64.c | 6 +- arch/x86/kernel/signal_32.c | 4 +- arch/x86/tools/Makefile | 15 +- arch/x86/{entry/vdso => tools}/vdso2c.c | 0 arch/x86/{entry/vdso => tools}/vdso2c.h | 0 arch/x86/xen/setup.c | 28 ++-- arch/x86/xen/smp_pv.c | 5 +- arch/x86/xen/xen-ops.h | 1 - 47 files changed, 444 insertions(+), 490 deletions(-)
The following commit has been merged into the x86/entry branch of tip: Commit-ID: 98d3e996513ad00b7824ea3bece506fc645547dd Gitweb: https://git.kernel.org/tip/98d3e996513ad00b7824ea3bece506fc645547dd Author: H. Peter Anvin <hpa@zytor.com> AuthorDate: Tue, 16 Dec 2025 13:25:59 -08:00 Committer: Dave Hansen <dave.hansen@linux.intel.com> CommitterDate: Tue, 13 Jan 2026 16:37:58 -08:00 x86/entry/vdso32: Remove SYSCALL_ENTER_KERNEL macro in sigreturn.S A macro SYSCALL_ENTER_KERNEL was defined in sigreturn.S, with the ability of overriding it. The override capability, however, is not used anywhere, and the macro name is potentially confusing because it seems to imply that sysenter/syscall could be used here, which is NOT true: the sigreturn system calls MUST use int $0x80. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Link: https://patch.msgid.link/20251216212606.1325678-6-hpa@zytor.com --- arch/x86/entry/vdso/vdso32/sigreturn.S | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/arch/x86/entry/vdso/vdso32/sigreturn.S b/arch/x86/entry/vdso/vdso32/sigreturn.S index 1bd068f..965900c 100644 --- a/arch/x86/entry/vdso/vdso32/sigreturn.S +++ b/arch/x86/entry/vdso/vdso32/sigreturn.S @@ -3,10 +3,6 @@ #include <asm/unistd_32.h> #include <asm/asm-offsets.h> -#ifndef SYSCALL_ENTER_KERNEL -#define SYSCALL_ENTER_KERNEL int $0x80 -#endif - .text .globl __kernel_sigreturn .type __kernel_sigreturn,@function @@ -16,7 +12,7 @@ __kernel_sigreturn: .LSTART_sigreturn: popl %eax /* XXX does this mean it needs unwind info? */ movl $__NR_sigreturn, %eax - SYSCALL_ENTER_KERNEL + int $0x80 .LEND_sigreturn: SYM_INNER_LABEL(vdso32_sigreturn_landing_pad, SYM_L_GLOBAL) nop @@ -28,7 +24,7 @@ SYM_INNER_LABEL(vdso32_sigreturn_landing_pad, SYM_L_GLOBAL) __kernel_rt_sigreturn: .LSTART_rt_sigreturn: movl $__NR_rt_sigreturn, %eax - SYSCALL_ENTER_KERNEL + int $0x80 .LEND_rt_sigreturn: SYM_INNER_LABEL(vdso32_rt_sigreturn_landing_pad, SYM_L_GLOBAL) nop
{ "author": "\"tip-bot2 for H. Peter Anvin\" <tip-bot2@linutronix.de>", "date": "Wed, 14 Jan 2026 00:44:54 -0000", "thread_id": "223707e2-3231-4037-bd1f-490ddf6aeeb6@linux.ibm.com.mbox.gz" }
lkml
[PATCH v4 00/10] x86/entry/vdso: clean up the vdso build, vdso updates
This patchset cleans up the vdso build by building the 32- and 64-bit vdsos in separate directories, moving the vdso2c tool to arch/x86/tools, and by merging common code and especially Makefile rules between the 32- and 64-bit vdsos to the greatest extent possible. Be more strict about sanitizing and standardizing the vdso build options. Disable CFI for the vdso until the kernel adds user space IBT support. Modernize the DWARF generation vdso32/sigreturn.S. Add macros to cleanly call system calls from vdso source code. Add the GNU_PROPERTY and GNU_STACK PHDRs to the vdso. When using int $0x80 (old 32-bit hardware or FRED-capable 64-bit hardware) skip the stack stuff in the 32-bit kernel entry code and call int $0x80 directly when used from C code. Changes from v3 to v4: - Improved description of patch 01/10. - Split out the move of vdso2c to tools into a separate patch. - Remove unrelated formatting changes from vdso-layout.lds.S. - Fix *-x32.o being missing from "targets". - Rebased onto v6.19-rc1. Changes from v2 to v3: In arch/x86/include/asm/vdso/sys_call.h: - remove stray comment from prototyping (Uros Biszjak) - remove VDSO_SYSCALL6() since it would require special handling on 32 bits with frame pointers and is currently unused. (Uros Biszjak) - indent nested preprocessor directives. Changes from v1 to v2: Too many to count - much of the patchset has been reworked Patches: x86/entry/vdso: rename vdso_image_* to vdso*_image x86/entry/vdso: move vdso2c to arch/x86/tools x86/entry/vdso: refactor the vdso build x86/entry/vdso32: don't rely on int80_landing_pad for adjusting ip x86/entry/vdso32: remove SYSCALL_ENTER_KERNEL macro in sigreturn.S x86/entry/vdso32: remove open-coded DWARF in sigreturn.S x86/entry/vdso: include GNU_PROPERTY and GNU_STACK PHDRs x86/vdso: abstract out vdso system call internals x86/cpufeature: replace X86_FEATURE_SYSENTER32 with X86_FEATURE_SYSFAST32 x86/entry/vdso32: when using int $0x80, use it directly --- arch/x86/Kconfig.cpufeatures | 8 + arch/x86/Makefile | 2 +- arch/x86/entry/syscall_32.c | 2 +- arch/x86/entry/vdso/.gitignore | 11 +- arch/x86/entry/vdso/Makefile | 162 +-------------------- arch/x86/entry/vdso/common/Makefile.include | 89 +++++++++++ arch/x86/entry/vdso/{vdso-note.S => common/note.S} | 5 +- arch/x86/entry/vdso/{ => common}/vclock_gettime.c | 0 arch/x86/entry/vdso/{ => common}/vdso-layout.lds.S | 38 +++-- arch/x86/entry/vdso/{ => common}/vgetcpu.c | 0 arch/x86/entry/vdso/vdso32/Makefile | 24 +++ arch/x86/entry/vdso/vdso32/note.S | 19 +-- arch/x86/entry/vdso/vdso32/sigreturn.S | 152 +++++-------------- arch/x86/entry/vdso/vdso32/system_call.S | 22 ++- arch/x86/entry/vdso/vdso32/vclock_gettime.c | 5 +- arch/x86/entry/vdso/vdso32/vdso32.lds.S | 2 +- arch/x86/entry/vdso/vdso32/vgetcpu.c | 4 +- arch/x86/entry/vdso/vdso64/Makefile | 46 ++++++ arch/x86/entry/vdso/vdso64/note.S | 1 + arch/x86/entry/vdso/vdso64/vclock_gettime.c | 1 + .../entry/vdso/{vdso.lds.S => vdso64/vdso64.lds.S} | 2 +- arch/x86/entry/vdso/{ => vdso64}/vdsox32.lds.S | 2 +- arch/x86/entry/vdso/vdso64/vgetcpu.c | 1 + .../entry/vdso/{ => vdso64}/vgetrandom-chacha.S | 0 arch/x86/entry/vdso/{ => vdso64}/vgetrandom.c | 2 +- arch/x86/entry/vdso/{ => vdso64}/vsgx.S | 0 arch/x86/entry/vdso/vma.c | 24 ++- arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/include/asm/dwarf2.h | 1 + arch/x86/include/asm/elf.h | 2 +- arch/x86/include/asm/vdso.h | 6 +- arch/x86/include/asm/vdso/gettimeofday.h | 108 +------------- arch/x86/include/asm/vdso/sys_call.h | 105 +++++++++++++ arch/x86/kernel/asm-offsets.c | 6 + arch/x86/kernel/cpu/centaur.c | 3 - arch/x86/kernel/cpu/common.c | 8 + arch/x86/kernel/cpu/intel.c | 4 +- arch/x86/kernel/cpu/zhaoxin.c | 4 +- arch/x86/kernel/fred.c | 2 +- arch/x86/kernel/process_64.c | 6 +- arch/x86/kernel/signal_32.c | 4 +- arch/x86/tools/Makefile | 15 +- arch/x86/{entry/vdso => tools}/vdso2c.c | 0 arch/x86/{entry/vdso => tools}/vdso2c.h | 0 arch/x86/xen/setup.c | 28 ++-- arch/x86/xen/smp_pv.c | 5 +- arch/x86/xen/xen-ops.h | 1 - 47 files changed, 444 insertions(+), 490 deletions(-)
The following commit has been merged into the x86/entry branch of tip: Commit-ID: 8717b02b8c030dc0c4b55781b59e88def0a1a92f Gitweb: https://git.kernel.org/tip/8717b02b8c030dc0c4b55781b59e88def0a1a92f Author: H. Peter Anvin <hpa@zytor.com> AuthorDate: Tue, 16 Dec 2025 13:26:01 -08:00 Committer: Dave Hansen <dave.hansen@linux.intel.com> CommitterDate: Tue, 13 Jan 2026 16:37:58 -08:00 x86/entry/vdso: Include GNU_PROPERTY and GNU_STACK PHDRs Currently the vdso doesn't include .note.gnu.property or a GNU noexec stack annotation (the -z noexecstack in the linker script is ineffective because we specify PHDRs explicitly.) The motivation is that the dynamic linker currently do not check these. However, this is a weak excuse: the vdso*.so are also supposed to be usable at link libraries, and there is no reason why the dynamic linker might not want or need to check these in the future, so add them back in -- it is trivial enough. Use symbolic constants for the PHDR permission flags. [ v4: drop unrelated formatting changes ] Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Link: https://patch.msgid.link/20251216212606.1325678-8-hpa@zytor.com --- arch/x86/entry/vdso/common/vdso-layout.lds.S | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/arch/x86/entry/vdso/common/vdso-layout.lds.S b/arch/x86/entry/vdso/common/vdso-layout.lds.S index ec1ac19..a1e30be 100644 --- a/arch/x86/entry/vdso/common/vdso-layout.lds.S +++ b/arch/x86/entry/vdso/common/vdso-layout.lds.S @@ -47,18 +47,18 @@ SECTIONS *(.gnu.linkonce.b.*) } :text - /* - * Discard .note.gnu.property sections which are unused and have - * different alignment requirement from vDSO note sections. - */ - /DISCARD/ : { + .note.gnu.property : { *(.note.gnu.property) - } - .note : { *(.note.*) } :text :note - - .eh_frame_hdr : { *(.eh_frame_hdr) } :text :eh_frame_hdr - .eh_frame : { KEEP (*(.eh_frame)) } :text + } :text :note :gnu_property + .note : { + *(.note*) + } :text :note + .eh_frame_hdr : { *(.eh_frame_hdr) } :text :eh_frame_hdr + .eh_frame : { + KEEP (*(.eh_frame)) + *(.eh_frame.*) + } :text /* * Text is well-separated from actual data: there's plenty of @@ -87,15 +87,23 @@ SECTIONS * Very old versions of ld do not recognize this name token; use the constant. */ #define PT_GNU_EH_FRAME 0x6474e550 +#define PT_GNU_STACK 0x6474e551 +#define PT_GNU_PROPERTY 0x6474e553 /* * We must supply the ELF program headers explicitly to get just one * PT_LOAD segment, and set the flags explicitly to make segments read-only. - */ +*/ +#define PF_R FLAGS(4) +#define PF_RW FLAGS(6) +#define PF_RX FLAGS(5) + PHDRS { - text PT_LOAD FLAGS(5) FILEHDR PHDRS; /* PF_R|PF_X */ - dynamic PT_DYNAMIC FLAGS(4); /* PF_R */ - note PT_NOTE FLAGS(4); /* PF_R */ - eh_frame_hdr PT_GNU_EH_FRAME; + text PT_LOAD PF_RX FILEHDR PHDRS; + dynamic PT_DYNAMIC PF_R; + note PT_NOTE PF_R; + eh_frame_hdr PT_GNU_EH_FRAME PF_R; + gnu_stack PT_GNU_STACK PF_RW; + gnu_property PT_GNU_PROPERTY PF_R; }
{ "author": "\"tip-bot2 for H. Peter Anvin\" <tip-bot2@linutronix.de>", "date": "Wed, 14 Jan 2026 00:44:52 -0000", "thread_id": "223707e2-3231-4037-bd1f-490ddf6aeeb6@linux.ibm.com.mbox.gz" }
lkml
[PATCH v4 00/10] x86/entry/vdso: clean up the vdso build, vdso updates
This patchset cleans up the vdso build by building the 32- and 64-bit vdsos in separate directories, moving the vdso2c tool to arch/x86/tools, and by merging common code and especially Makefile rules between the 32- and 64-bit vdsos to the greatest extent possible. Be more strict about sanitizing and standardizing the vdso build options. Disable CFI for the vdso until the kernel adds user space IBT support. Modernize the DWARF generation vdso32/sigreturn.S. Add macros to cleanly call system calls from vdso source code. Add the GNU_PROPERTY and GNU_STACK PHDRs to the vdso. When using int $0x80 (old 32-bit hardware or FRED-capable 64-bit hardware) skip the stack stuff in the 32-bit kernel entry code and call int $0x80 directly when used from C code. Changes from v3 to v4: - Improved description of patch 01/10. - Split out the move of vdso2c to tools into a separate patch. - Remove unrelated formatting changes from vdso-layout.lds.S. - Fix *-x32.o being missing from "targets". - Rebased onto v6.19-rc1. Changes from v2 to v3: In arch/x86/include/asm/vdso/sys_call.h: - remove stray comment from prototyping (Uros Biszjak) - remove VDSO_SYSCALL6() since it would require special handling on 32 bits with frame pointers and is currently unused. (Uros Biszjak) - indent nested preprocessor directives. Changes from v1 to v2: Too many to count - much of the patchset has been reworked Patches: x86/entry/vdso: rename vdso_image_* to vdso*_image x86/entry/vdso: move vdso2c to arch/x86/tools x86/entry/vdso: refactor the vdso build x86/entry/vdso32: don't rely on int80_landing_pad for adjusting ip x86/entry/vdso32: remove SYSCALL_ENTER_KERNEL macro in sigreturn.S x86/entry/vdso32: remove open-coded DWARF in sigreturn.S x86/entry/vdso: include GNU_PROPERTY and GNU_STACK PHDRs x86/vdso: abstract out vdso system call internals x86/cpufeature: replace X86_FEATURE_SYSENTER32 with X86_FEATURE_SYSFAST32 x86/entry/vdso32: when using int $0x80, use it directly --- arch/x86/Kconfig.cpufeatures | 8 + arch/x86/Makefile | 2 +- arch/x86/entry/syscall_32.c | 2 +- arch/x86/entry/vdso/.gitignore | 11 +- arch/x86/entry/vdso/Makefile | 162 +-------------------- arch/x86/entry/vdso/common/Makefile.include | 89 +++++++++++ arch/x86/entry/vdso/{vdso-note.S => common/note.S} | 5 +- arch/x86/entry/vdso/{ => common}/vclock_gettime.c | 0 arch/x86/entry/vdso/{ => common}/vdso-layout.lds.S | 38 +++-- arch/x86/entry/vdso/{ => common}/vgetcpu.c | 0 arch/x86/entry/vdso/vdso32/Makefile | 24 +++ arch/x86/entry/vdso/vdso32/note.S | 19 +-- arch/x86/entry/vdso/vdso32/sigreturn.S | 152 +++++-------------- arch/x86/entry/vdso/vdso32/system_call.S | 22 ++- arch/x86/entry/vdso/vdso32/vclock_gettime.c | 5 +- arch/x86/entry/vdso/vdso32/vdso32.lds.S | 2 +- arch/x86/entry/vdso/vdso32/vgetcpu.c | 4 +- arch/x86/entry/vdso/vdso64/Makefile | 46 ++++++ arch/x86/entry/vdso/vdso64/note.S | 1 + arch/x86/entry/vdso/vdso64/vclock_gettime.c | 1 + .../entry/vdso/{vdso.lds.S => vdso64/vdso64.lds.S} | 2 +- arch/x86/entry/vdso/{ => vdso64}/vdsox32.lds.S | 2 +- arch/x86/entry/vdso/vdso64/vgetcpu.c | 1 + .../entry/vdso/{ => vdso64}/vgetrandom-chacha.S | 0 arch/x86/entry/vdso/{ => vdso64}/vgetrandom.c | 2 +- arch/x86/entry/vdso/{ => vdso64}/vsgx.S | 0 arch/x86/entry/vdso/vma.c | 24 ++- arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/include/asm/dwarf2.h | 1 + arch/x86/include/asm/elf.h | 2 +- arch/x86/include/asm/vdso.h | 6 +- arch/x86/include/asm/vdso/gettimeofday.h | 108 +------------- arch/x86/include/asm/vdso/sys_call.h | 105 +++++++++++++ arch/x86/kernel/asm-offsets.c | 6 + arch/x86/kernel/cpu/centaur.c | 3 - arch/x86/kernel/cpu/common.c | 8 + arch/x86/kernel/cpu/intel.c | 4 +- arch/x86/kernel/cpu/zhaoxin.c | 4 +- arch/x86/kernel/fred.c | 2 +- arch/x86/kernel/process_64.c | 6 +- arch/x86/kernel/signal_32.c | 4 +- arch/x86/tools/Makefile | 15 +- arch/x86/{entry/vdso => tools}/vdso2c.c | 0 arch/x86/{entry/vdso => tools}/vdso2c.h | 0 arch/x86/xen/setup.c | 28 ++-- arch/x86/xen/smp_pv.c | 5 +- arch/x86/xen/xen-ops.h | 1 - 47 files changed, 444 insertions(+), 490 deletions(-)
The following commit has been merged into the x86/entry branch of tip: Commit-ID: a0636d4c3ad0da0cd6069eb6fef5d2b7d3449378 Gitweb: https://git.kernel.org/tip/a0636d4c3ad0da0cd6069eb6fef5d2b7d3449378 Author: H. Peter Anvin <hpa@zytor.com> AuthorDate: Tue, 16 Dec 2025 13:26:02 -08:00 Committer: Dave Hansen <dave.hansen@linux.intel.com> CommitterDate: Tue, 13 Jan 2026 16:37:58 -08:00 x86/vdso: Abstract out vdso system call internals Abstract out the calling of true system calls from the vdso into macros. It has been a very long time since gcc did not allow %ebx or %ebp in inline asm in 32-bit PIC mode; remove the corresponding hacks. Remove the use of memory output constraints in gettimeofday.h in favor of "memory" clobbers. The resulting code is identical for the current use cases, as the system call is usually a terminal fallback anyway, and it merely complicates the macroization. This patch adds only a handful of more lines of code than it removes, and in fact could be made substantially smaller by removing the macros for the argument counts that aren't currently used, however, it seems better to be general from the start. [ v3: remove stray comment from prototyping; remove VDSO_SYSCALL6() since it would require special handling on 32 bits and is currently unused. (Uros Biszjak) Indent nested preprocessor directives. ] Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Acked-by: Uros Bizjak <ubizjak@gmail.com> Link: https://patch.msgid.link/20251216212606.1325678-9-hpa@zytor.com --- arch/x86/include/asm/vdso/gettimeofday.h | 108 +--------------------- arch/x86/include/asm/vdso/sys_call.h | 103 +++++++++++++++++++++- 2 files changed, 111 insertions(+), 100 deletions(-) create mode 100644 arch/x86/include/asm/vdso/sys_call.h diff --git a/arch/x86/include/asm/vdso/gettimeofday.h b/arch/x86/include/asm/vdso/gettimeofday.h index 73b2e7e..3cf214c 100644 --- a/arch/x86/include/asm/vdso/gettimeofday.h +++ b/arch/x86/include/asm/vdso/gettimeofday.h @@ -18,6 +18,7 @@ #include <asm/msr.h> #include <asm/pvclock.h> #include <clocksource/hyperv_timer.h> +#include <asm/vdso/sys_call.h> #define VDSO_HAS_TIME 1 @@ -53,130 +54,37 @@ extern struct ms_hyperv_tsc_page hvclock_page __attribute__((visibility("hidden"))); #endif -#ifndef BUILD_VDSO32 - static __always_inline long clock_gettime_fallback(clockid_t _clkid, struct __kernel_timespec *_ts) { - long ret; - - asm ("syscall" : "=a" (ret), "=m" (*_ts) : - "0" (__NR_clock_gettime), "D" (_clkid), "S" (_ts) : - "rcx", "r11"); - - return ret; + return VDSO_SYSCALL2(clock_gettime,64,_clkid,_ts); } static __always_inline long gettimeofday_fallback(struct __kernel_old_timeval *_tv, struct timezone *_tz) { - long ret; - - asm("syscall" : "=a" (ret) : - "0" (__NR_gettimeofday), "D" (_tv), "S" (_tz) : "memory"); - - return ret; + return VDSO_SYSCALL2(gettimeofday,,_tv,_tz); } static __always_inline long clock_getres_fallback(clockid_t _clkid, struct __kernel_timespec *_ts) { - long ret; - - asm ("syscall" : "=a" (ret), "=m" (*_ts) : - "0" (__NR_clock_getres), "D" (_clkid), "S" (_ts) : - "rcx", "r11"); - - return ret; + return VDSO_SYSCALL2(clock_getres,_time64,_clkid,_ts); } -#else - -static __always_inline -long clock_gettime_fallback(clockid_t _clkid, struct __kernel_timespec *_ts) -{ - long ret; - - asm ( - "mov %%ebx, %%edx \n" - "mov %[clock], %%ebx \n" - "call __kernel_vsyscall \n" - "mov %%edx, %%ebx \n" - : "=a" (ret), "=m" (*_ts) - : "0" (__NR_clock_gettime64), [clock] "g" (_clkid), "c" (_ts) - : "edx"); - - return ret; -} +#ifndef CONFIG_X86_64 static __always_inline long clock_gettime32_fallback(clockid_t _clkid, struct old_timespec32 *_ts) { - long ret; - - asm ( - "mov %%ebx, %%edx \n" - "mov %[clock], %%ebx \n" - "call __kernel_vsyscall \n" - "mov %%edx, %%ebx \n" - : "=a" (ret), "=m" (*_ts) - : "0" (__NR_clock_gettime), [clock] "g" (_clkid), "c" (_ts) - : "edx"); - - return ret; -} - -static __always_inline -long gettimeofday_fallback(struct __kernel_old_timeval *_tv, - struct timezone *_tz) -{ - long ret; - - asm( - "mov %%ebx, %%edx \n" - "mov %2, %%ebx \n" - "call __kernel_vsyscall \n" - "mov %%edx, %%ebx \n" - : "=a" (ret) - : "0" (__NR_gettimeofday), "g" (_tv), "c" (_tz) - : "memory", "edx"); - - return ret; + return VDSO_SYSCALL2(clock_gettime,,_clkid,_ts); } static __always_inline long -clock_getres_fallback(clockid_t _clkid, struct __kernel_timespec *_ts) -{ - long ret; - - asm ( - "mov %%ebx, %%edx \n" - "mov %[clock], %%ebx \n" - "call __kernel_vsyscall \n" - "mov %%edx, %%ebx \n" - : "=a" (ret), "=m" (*_ts) - : "0" (__NR_clock_getres_time64), [clock] "g" (_clkid), "c" (_ts) - : "edx"); - - return ret; -} - -static __always_inline -long clock_getres32_fallback(clockid_t _clkid, struct old_timespec32 *_ts) +clock_getres32_fallback(clockid_t _clkid, struct old_timespec32 *_ts) { - long ret; - - asm ( - "mov %%ebx, %%edx \n" - "mov %[clock], %%ebx \n" - "call __kernel_vsyscall \n" - "mov %%edx, %%ebx \n" - : "=a" (ret), "=m" (*_ts) - : "0" (__NR_clock_getres), [clock] "g" (_clkid), "c" (_ts) - : "edx"); - - return ret; + return VDSO_SYSCALL2(clock_getres,,_clkid,_ts); } #endif diff --git a/arch/x86/include/asm/vdso/sys_call.h b/arch/x86/include/asm/vdso/sys_call.h new file mode 100644 index 0000000..dcfd17c --- /dev/null +++ b/arch/x86/include/asm/vdso/sys_call.h @@ -0,0 +1,103 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Macros for issuing an inline system call from the vDSO. + */ + +#ifndef X86_ASM_VDSO_SYS_CALL_H +#define X86_ASM_VDSO_SYS_CALL_H + +#include <linux/compiler.h> +#include <asm/cpufeatures.h> +#include <asm/alternative.h> + +#ifdef CONFIG_X86_64 +# define __sys_instr "syscall" +# define __sys_clobber "rcx", "r11", "memory" +# define __sys_nr(x,y) __NR_ ## x +# define __sys_reg1 "rdi" +# define __sys_reg2 "rsi" +# define __sys_reg3 "rdx" +# define __sys_reg4 "r10" +# define __sys_reg5 "r8" +#else +# define __sys_instr "call __kernel_vsyscall" +# define __sys_clobber "memory" +# define __sys_nr(x,y) __NR_ ## x ## y +# define __sys_reg1 "ebx" +# define __sys_reg2 "ecx" +# define __sys_reg3 "edx" +# define __sys_reg4 "esi" +# define __sys_reg5 "edi" +#endif + +/* + * Example usage: + * + * result = VDSO_SYSCALL3(foo,64,x,y,z); + * + * ... calls foo(x,y,z) on 64 bits, and foo64(x,y,z) on 32 bits. + * + * VDSO_SYSCALL6() is currently missing, because it would require + * special handling for %ebp on 32 bits when the vdso is compiled with + * frame pointers enabled (the default on 32 bits.) Add it as a special + * case when and if it becomes necessary. + */ +#define _VDSO_SYSCALL(name,suf32,...) \ + ({ \ + long _sys_num_ret = __sys_nr(name,suf32); \ + asm_inline volatile( \ + __sys_instr \ + : "+a" (_sys_num_ret) \ + : __VA_ARGS__ \ + : __sys_clobber); \ + _sys_num_ret; \ + }) + +#define VDSO_SYSCALL0(name,suf32) \ + _VDSO_SYSCALL(name,suf32) +#define VDSO_SYSCALL1(name,suf32,a1) \ + ({ \ + register long _sys_arg1 asm(__sys_reg1) = (long)(a1); \ + _VDSO_SYSCALL(name,suf32, \ + "r" (_sys_arg1)); \ + }) +#define VDSO_SYSCALL2(name,suf32,a1,a2) \ + ({ \ + register long _sys_arg1 asm(__sys_reg1) = (long)(a1); \ + register long _sys_arg2 asm(__sys_reg2) = (long)(a2); \ + _VDSO_SYSCALL(name,suf32, \ + "r" (_sys_arg1), "r" (_sys_arg2)); \ + }) +#define VDSO_SYSCALL3(name,suf32,a1,a2,a3) \ + ({ \ + register long _sys_arg1 asm(__sys_reg1) = (long)(a1); \ + register long _sys_arg2 asm(__sys_reg2) = (long)(a2); \ + register long _sys_arg3 asm(__sys_reg3) = (long)(a3); \ + _VDSO_SYSCALL(name,suf32, \ + "r" (_sys_arg1), "r" (_sys_arg2), \ + "r" (_sys_arg3)); \ + }) +#define VDSO_SYSCALL4(name,suf32,a1,a2,a3,a4) \ + ({ \ + register long _sys_arg1 asm(__sys_reg1) = (long)(a1); \ + register long _sys_arg2 asm(__sys_reg2) = (long)(a2); \ + register long _sys_arg3 asm(__sys_reg3) = (long)(a3); \ + register long _sys_arg4 asm(__sys_reg4) = (long)(a4); \ + _VDSO_SYSCALL(name,suf32, \ + "r" (_sys_arg1), "r" (_sys_arg2), \ + "r" (_sys_arg3), "r" (_sys_arg4)); \ + }) +#define VDSO_SYSCALL5(name,suf32,a1,a2,a3,a4,a5) \ + ({ \ + register long _sys_arg1 asm(__sys_reg1) = (long)(a1); \ + register long _sys_arg2 asm(__sys_reg2) = (long)(a2); \ + register long _sys_arg3 asm(__sys_reg3) = (long)(a3); \ + register long _sys_arg4 asm(__sys_reg4) = (long)(a4); \ + register long _sys_arg5 asm(__sys_reg5) = (long)(a5); \ + _VDSO_SYSCALL(name,suf32, \ + "r" (_sys_arg1), "r" (_sys_arg2), \ + "r" (_sys_arg3), "r" (_sys_arg4), \ + "r" (_sys_arg5)); \ + }) + +#endif /* X86_VDSO_SYS_CALL_H */
{ "author": "\"tip-bot2 for H. Peter Anvin\" <tip-bot2@linutronix.de>", "date": "Wed, 14 Jan 2026 00:44:51 -0000", "thread_id": "223707e2-3231-4037-bd1f-490ddf6aeeb6@linux.ibm.com.mbox.gz" }
lkml
[PATCH v4 00/10] x86/entry/vdso: clean up the vdso build, vdso updates
This patchset cleans up the vdso build by building the 32- and 64-bit vdsos in separate directories, moving the vdso2c tool to arch/x86/tools, and by merging common code and especially Makefile rules between the 32- and 64-bit vdsos to the greatest extent possible. Be more strict about sanitizing and standardizing the vdso build options. Disable CFI for the vdso until the kernel adds user space IBT support. Modernize the DWARF generation vdso32/sigreturn.S. Add macros to cleanly call system calls from vdso source code. Add the GNU_PROPERTY and GNU_STACK PHDRs to the vdso. When using int $0x80 (old 32-bit hardware or FRED-capable 64-bit hardware) skip the stack stuff in the 32-bit kernel entry code and call int $0x80 directly when used from C code. Changes from v3 to v4: - Improved description of patch 01/10. - Split out the move of vdso2c to tools into a separate patch. - Remove unrelated formatting changes from vdso-layout.lds.S. - Fix *-x32.o being missing from "targets". - Rebased onto v6.19-rc1. Changes from v2 to v3: In arch/x86/include/asm/vdso/sys_call.h: - remove stray comment from prototyping (Uros Biszjak) - remove VDSO_SYSCALL6() since it would require special handling on 32 bits with frame pointers and is currently unused. (Uros Biszjak) - indent nested preprocessor directives. Changes from v1 to v2: Too many to count - much of the patchset has been reworked Patches: x86/entry/vdso: rename vdso_image_* to vdso*_image x86/entry/vdso: move vdso2c to arch/x86/tools x86/entry/vdso: refactor the vdso build x86/entry/vdso32: don't rely on int80_landing_pad for adjusting ip x86/entry/vdso32: remove SYSCALL_ENTER_KERNEL macro in sigreturn.S x86/entry/vdso32: remove open-coded DWARF in sigreturn.S x86/entry/vdso: include GNU_PROPERTY and GNU_STACK PHDRs x86/vdso: abstract out vdso system call internals x86/cpufeature: replace X86_FEATURE_SYSENTER32 with X86_FEATURE_SYSFAST32 x86/entry/vdso32: when using int $0x80, use it directly --- arch/x86/Kconfig.cpufeatures | 8 + arch/x86/Makefile | 2 +- arch/x86/entry/syscall_32.c | 2 +- arch/x86/entry/vdso/.gitignore | 11 +- arch/x86/entry/vdso/Makefile | 162 +-------------------- arch/x86/entry/vdso/common/Makefile.include | 89 +++++++++++ arch/x86/entry/vdso/{vdso-note.S => common/note.S} | 5 +- arch/x86/entry/vdso/{ => common}/vclock_gettime.c | 0 arch/x86/entry/vdso/{ => common}/vdso-layout.lds.S | 38 +++-- arch/x86/entry/vdso/{ => common}/vgetcpu.c | 0 arch/x86/entry/vdso/vdso32/Makefile | 24 +++ arch/x86/entry/vdso/vdso32/note.S | 19 +-- arch/x86/entry/vdso/vdso32/sigreturn.S | 152 +++++-------------- arch/x86/entry/vdso/vdso32/system_call.S | 22 ++- arch/x86/entry/vdso/vdso32/vclock_gettime.c | 5 +- arch/x86/entry/vdso/vdso32/vdso32.lds.S | 2 +- arch/x86/entry/vdso/vdso32/vgetcpu.c | 4 +- arch/x86/entry/vdso/vdso64/Makefile | 46 ++++++ arch/x86/entry/vdso/vdso64/note.S | 1 + arch/x86/entry/vdso/vdso64/vclock_gettime.c | 1 + .../entry/vdso/{vdso.lds.S => vdso64/vdso64.lds.S} | 2 +- arch/x86/entry/vdso/{ => vdso64}/vdsox32.lds.S | 2 +- arch/x86/entry/vdso/vdso64/vgetcpu.c | 1 + .../entry/vdso/{ => vdso64}/vgetrandom-chacha.S | 0 arch/x86/entry/vdso/{ => vdso64}/vgetrandom.c | 2 +- arch/x86/entry/vdso/{ => vdso64}/vsgx.S | 0 arch/x86/entry/vdso/vma.c | 24 ++- arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/include/asm/dwarf2.h | 1 + arch/x86/include/asm/elf.h | 2 +- arch/x86/include/asm/vdso.h | 6 +- arch/x86/include/asm/vdso/gettimeofday.h | 108 +------------- arch/x86/include/asm/vdso/sys_call.h | 105 +++++++++++++ arch/x86/kernel/asm-offsets.c | 6 + arch/x86/kernel/cpu/centaur.c | 3 - arch/x86/kernel/cpu/common.c | 8 + arch/x86/kernel/cpu/intel.c | 4 +- arch/x86/kernel/cpu/zhaoxin.c | 4 +- arch/x86/kernel/fred.c | 2 +- arch/x86/kernel/process_64.c | 6 +- arch/x86/kernel/signal_32.c | 4 +- arch/x86/tools/Makefile | 15 +- arch/x86/{entry/vdso => tools}/vdso2c.c | 0 arch/x86/{entry/vdso => tools}/vdso2c.h | 0 arch/x86/xen/setup.c | 28 ++-- arch/x86/xen/smp_pv.c | 5 +- arch/x86/xen/xen-ops.h | 1 - 47 files changed, 444 insertions(+), 490 deletions(-)
The following commit has been merged into the x86/entry branch of tip: Commit-ID: 6e150b71019f386a021004fafea9ef7189bc6aea Gitweb: https://git.kernel.org/tip/6e150b71019f386a021004fafea9ef7189bc6aea Author: H. Peter Anvin <hpa@zytor.com> AuthorDate: Tue, 16 Dec 2025 13:25:58 -08:00 Committer: Dave Hansen <dave.hansen@linux.intel.com> CommitterDate: Tue, 13 Jan 2026 16:37:58 -08:00 x86/entry/vdso32: Don't rely on int80_landing_pad for adjusting ip There is no fundamental reason to use the int80_landing_pad symbol to adjust ip when moving the vdso. If ip falls within the vdso, and the vdso is moved, we should change the ip accordingly, regardless of mode or location within the vdso. This *currently* can only happen on 32 bits, but there isn't any reason not to do so generically. Note that if this is ever possible from a vdso-internal call, then the user space stack will also needed to be adjusted (as well as the shadow stack, if enabled.) Fortunately this is not currently the case. At the moment, we don't even consider other threads when moving the vdso. The assumption is that it is only used by process freeze/thaw for migration, where this is not an issue. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Link: https://patch.msgid.link/20251216212606.1325678-5-hpa@zytor.com --- arch/x86/entry/vdso/vma.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c index 8f98c2d..e7fd751 100644 --- a/arch/x86/entry/vdso/vma.c +++ b/arch/x86/entry/vdso/vma.c @@ -65,16 +65,12 @@ static vm_fault_t vdso_fault(const struct vm_special_mapping *sm, static void vdso_fix_landing(const struct vdso_image *image, struct vm_area_struct *new_vma) { - if (in_ia32_syscall() && image == &vdso32_image) { - struct pt_regs *regs = current_pt_regs(); - unsigned long vdso_land = image->sym_int80_landing_pad; - unsigned long old_land_addr = vdso_land + - (unsigned long)current->mm->context.vdso; - - /* Fixing userspace landing - look at do_fast_syscall_32 */ - if (regs->ip == old_land_addr) - regs->ip = new_vma->vm_start + vdso_land; - } + struct pt_regs *regs = current_pt_regs(); + unsigned long ipoffset = regs->ip - + (unsigned long)current->mm->context.vdso; + + if (ipoffset < image->size) + regs->ip = new_vma->vm_start + ipoffset; } static int vdso_mremap(const struct vm_special_mapping *sm,
{ "author": "\"tip-bot2 for H. Peter Anvin\" <tip-bot2@linutronix.de>", "date": "Wed, 14 Jan 2026 00:44:55 -0000", "thread_id": "223707e2-3231-4037-bd1f-490ddf6aeeb6@linux.ibm.com.mbox.gz" }
lkml
[PATCH v4 00/10] x86/entry/vdso: clean up the vdso build, vdso updates
This patchset cleans up the vdso build by building the 32- and 64-bit vdsos in separate directories, moving the vdso2c tool to arch/x86/tools, and by merging common code and especially Makefile rules between the 32- and 64-bit vdsos to the greatest extent possible. Be more strict about sanitizing and standardizing the vdso build options. Disable CFI for the vdso until the kernel adds user space IBT support. Modernize the DWARF generation vdso32/sigreturn.S. Add macros to cleanly call system calls from vdso source code. Add the GNU_PROPERTY and GNU_STACK PHDRs to the vdso. When using int $0x80 (old 32-bit hardware or FRED-capable 64-bit hardware) skip the stack stuff in the 32-bit kernel entry code and call int $0x80 directly when used from C code. Changes from v3 to v4: - Improved description of patch 01/10. - Split out the move of vdso2c to tools into a separate patch. - Remove unrelated formatting changes from vdso-layout.lds.S. - Fix *-x32.o being missing from "targets". - Rebased onto v6.19-rc1. Changes from v2 to v3: In arch/x86/include/asm/vdso/sys_call.h: - remove stray comment from prototyping (Uros Biszjak) - remove VDSO_SYSCALL6() since it would require special handling on 32 bits with frame pointers and is currently unused. (Uros Biszjak) - indent nested preprocessor directives. Changes from v1 to v2: Too many to count - much of the patchset has been reworked Patches: x86/entry/vdso: rename vdso_image_* to vdso*_image x86/entry/vdso: move vdso2c to arch/x86/tools x86/entry/vdso: refactor the vdso build x86/entry/vdso32: don't rely on int80_landing_pad for adjusting ip x86/entry/vdso32: remove SYSCALL_ENTER_KERNEL macro in sigreturn.S x86/entry/vdso32: remove open-coded DWARF in sigreturn.S x86/entry/vdso: include GNU_PROPERTY and GNU_STACK PHDRs x86/vdso: abstract out vdso system call internals x86/cpufeature: replace X86_FEATURE_SYSENTER32 with X86_FEATURE_SYSFAST32 x86/entry/vdso32: when using int $0x80, use it directly --- arch/x86/Kconfig.cpufeatures | 8 + arch/x86/Makefile | 2 +- arch/x86/entry/syscall_32.c | 2 +- arch/x86/entry/vdso/.gitignore | 11 +- arch/x86/entry/vdso/Makefile | 162 +-------------------- arch/x86/entry/vdso/common/Makefile.include | 89 +++++++++++ arch/x86/entry/vdso/{vdso-note.S => common/note.S} | 5 +- arch/x86/entry/vdso/{ => common}/vclock_gettime.c | 0 arch/x86/entry/vdso/{ => common}/vdso-layout.lds.S | 38 +++-- arch/x86/entry/vdso/{ => common}/vgetcpu.c | 0 arch/x86/entry/vdso/vdso32/Makefile | 24 +++ arch/x86/entry/vdso/vdso32/note.S | 19 +-- arch/x86/entry/vdso/vdso32/sigreturn.S | 152 +++++-------------- arch/x86/entry/vdso/vdso32/system_call.S | 22 ++- arch/x86/entry/vdso/vdso32/vclock_gettime.c | 5 +- arch/x86/entry/vdso/vdso32/vdso32.lds.S | 2 +- arch/x86/entry/vdso/vdso32/vgetcpu.c | 4 +- arch/x86/entry/vdso/vdso64/Makefile | 46 ++++++ arch/x86/entry/vdso/vdso64/note.S | 1 + arch/x86/entry/vdso/vdso64/vclock_gettime.c | 1 + .../entry/vdso/{vdso.lds.S => vdso64/vdso64.lds.S} | 2 +- arch/x86/entry/vdso/{ => vdso64}/vdsox32.lds.S | 2 +- arch/x86/entry/vdso/vdso64/vgetcpu.c | 1 + .../entry/vdso/{ => vdso64}/vgetrandom-chacha.S | 0 arch/x86/entry/vdso/{ => vdso64}/vgetrandom.c | 2 +- arch/x86/entry/vdso/{ => vdso64}/vsgx.S | 0 arch/x86/entry/vdso/vma.c | 24 ++- arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/include/asm/dwarf2.h | 1 + arch/x86/include/asm/elf.h | 2 +- arch/x86/include/asm/vdso.h | 6 +- arch/x86/include/asm/vdso/gettimeofday.h | 108 +------------- arch/x86/include/asm/vdso/sys_call.h | 105 +++++++++++++ arch/x86/kernel/asm-offsets.c | 6 + arch/x86/kernel/cpu/centaur.c | 3 - arch/x86/kernel/cpu/common.c | 8 + arch/x86/kernel/cpu/intel.c | 4 +- arch/x86/kernel/cpu/zhaoxin.c | 4 +- arch/x86/kernel/fred.c | 2 +- arch/x86/kernel/process_64.c | 6 +- arch/x86/kernel/signal_32.c | 4 +- arch/x86/tools/Makefile | 15 +- arch/x86/{entry/vdso => tools}/vdso2c.c | 0 arch/x86/{entry/vdso => tools}/vdso2c.h | 0 arch/x86/xen/setup.c | 28 ++-- arch/x86/xen/smp_pv.c | 5 +- arch/x86/xen/xen-ops.h | 1 - 47 files changed, 444 insertions(+), 490 deletions(-)
The following commit has been merged into the x86/entry branch of tip: Commit-ID: 884961618ee51307cc63ab620a0bdd710fa0b0af Gitweb: https://git.kernel.org/tip/884961618ee51307cc63ab620a0bdd710fa0b0af Author: H. Peter Anvin <hpa@zytor.com> AuthorDate: Tue, 16 Dec 2025 13:26:00 -08:00 Committer: Dave Hansen <dave.hansen@linux.intel.com> CommitterDate: Tue, 13 Jan 2026 16:37:58 -08:00 x86/entry/vdso32: Remove open-coded DWARF in sigreturn.S The vdso32 sigreturn.S contains open-coded DWARF bytecode, which includes a hack for gdb to not try to step back to a previous call instruction when backtracing from a signal handler. Neither of those are necessary anymore: the backtracing issue is handled by ".cfi_entry simple" and ".cfi_signal_frame", both of which have been supported for a very long time now, which allows the remaining frame to be built using regular .cfi annotations. Add a few more register offsets to the signal frame just for good measure. Replace the nop on fallthrough of the system call (which should never, ever happen) with a ud2a trap. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Link: https://patch.msgid.link/20251216212606.1325678-7-hpa@zytor.com --- arch/x86/entry/vdso/vdso32/sigreturn.S | 146 +++++------------------- arch/x86/include/asm/dwarf2.h | 1 +- arch/x86/kernel/asm-offsets.c | 6 +- 3 files changed, 39 insertions(+), 114 deletions(-) diff --git a/arch/x86/entry/vdso/vdso32/sigreturn.S b/arch/x86/entry/vdso/vdso32/sigreturn.S index 965900c..25b0ac4 100644 --- a/arch/x86/entry/vdso/vdso32/sigreturn.S +++ b/arch/x86/entry/vdso/vdso32/sigreturn.S @@ -1,136 +1,54 @@ /* SPDX-License-Identifier: GPL-2.0 */ #include <linux/linkage.h> #include <asm/unistd_32.h> +#include <asm/dwarf2.h> #include <asm/asm-offsets.h> +.macro STARTPROC_SIGNAL_FRAME sc + CFI_STARTPROC simple + CFI_SIGNAL_FRAME + /* -4 as pretcode has already been popped */ + CFI_DEF_CFA esp, \sc - 4 + CFI_OFFSET eip, IA32_SIGCONTEXT_ip + CFI_OFFSET eax, IA32_SIGCONTEXT_ax + CFI_OFFSET ebx, IA32_SIGCONTEXT_bx + CFI_OFFSET ecx, IA32_SIGCONTEXT_cx + CFI_OFFSET edx, IA32_SIGCONTEXT_dx + CFI_OFFSET esp, IA32_SIGCONTEXT_sp + CFI_OFFSET ebp, IA32_SIGCONTEXT_bp + CFI_OFFSET esi, IA32_SIGCONTEXT_si + CFI_OFFSET edi, IA32_SIGCONTEXT_di + CFI_OFFSET es, IA32_SIGCONTEXT_es + CFI_OFFSET cs, IA32_SIGCONTEXT_cs + CFI_OFFSET ss, IA32_SIGCONTEXT_ss + CFI_OFFSET ds, IA32_SIGCONTEXT_ds + CFI_OFFSET eflags, IA32_SIGCONTEXT_flags +.endm + .text .globl __kernel_sigreturn .type __kernel_sigreturn,@function - nop /* this guy is needed for .LSTARTFDEDLSI1 below (watch for HACK) */ ALIGN __kernel_sigreturn: -.LSTART_sigreturn: - popl %eax /* XXX does this mean it needs unwind info? */ + STARTPROC_SIGNAL_FRAME IA32_SIGFRAME_sigcontext + popl %eax + CFI_ADJUST_CFA_OFFSET -4 movl $__NR_sigreturn, %eax int $0x80 -.LEND_sigreturn: SYM_INNER_LABEL(vdso32_sigreturn_landing_pad, SYM_L_GLOBAL) - nop - .size __kernel_sigreturn,.-.LSTART_sigreturn + ud2a + CFI_ENDPROC + .size __kernel_sigreturn,.-__kernel_sigreturn .globl __kernel_rt_sigreturn .type __kernel_rt_sigreturn,@function ALIGN __kernel_rt_sigreturn: -.LSTART_rt_sigreturn: + STARTPROC_SIGNAL_FRAME IA32_RT_SIGFRAME_sigcontext movl $__NR_rt_sigreturn, %eax int $0x80 -.LEND_rt_sigreturn: SYM_INNER_LABEL(vdso32_rt_sigreturn_landing_pad, SYM_L_GLOBAL) - nop - .size __kernel_rt_sigreturn,.-.LSTART_rt_sigreturn - .previous - - .section .eh_frame,"a",@progbits -.LSTARTFRAMEDLSI1: - .long .LENDCIEDLSI1-.LSTARTCIEDLSI1 -.LSTARTCIEDLSI1: - .long 0 /* CIE ID */ - .byte 1 /* Version number */ - .string "zRS" /* NUL-terminated augmentation string */ - .uleb128 1 /* Code alignment factor */ - .sleb128 -4 /* Data alignment factor */ - .byte 8 /* Return address register column */ - .uleb128 1 /* Augmentation value length */ - .byte 0x1b /* DW_EH_PE_pcrel|DW_EH_PE_sdata4. */ - .byte 0 /* DW_CFA_nop */ - .align 4 -.LENDCIEDLSI1: - .long .LENDFDEDLSI1-.LSTARTFDEDLSI1 /* Length FDE */ -.LSTARTFDEDLSI1: - .long .LSTARTFDEDLSI1-.LSTARTFRAMEDLSI1 /* CIE pointer */ - /* HACK: The dwarf2 unwind routines will subtract 1 from the - return address to get an address in the middle of the - presumed call instruction. Since we didn't get here via - a call, we need to include the nop before the real start - to make up for it. */ - .long .LSTART_sigreturn-1-. /* PC-relative start address */ - .long .LEND_sigreturn-.LSTART_sigreturn+1 - .uleb128 0 /* Augmentation */ - /* What follows are the instructions for the table generation. - We record the locations of each register saved. This is - complicated by the fact that the "CFA" is always assumed to - be the value of the stack pointer in the caller. This means - that we must define the CFA of this body of code to be the - saved value of the stack pointer in the sigcontext. Which - also means that there is no fixed relation to the other - saved registers, which means that we must use DW_CFA_expression - to compute their addresses. It also means that when we - adjust the stack with the popl, we have to do it all over again. */ - -#define do_cfa_expr(offset) \ - .byte 0x0f; /* DW_CFA_def_cfa_expression */ \ - .uleb128 1f-0f; /* length */ \ -0: .byte 0x74; /* DW_OP_breg4 */ \ - .sleb128 offset; /* offset */ \ - .byte 0x06; /* DW_OP_deref */ \ -1: - -#define do_expr(regno, offset) \ - .byte 0x10; /* DW_CFA_expression */ \ - .uleb128 regno; /* regno */ \ - .uleb128 1f-0f; /* length */ \ -0: .byte 0x74; /* DW_OP_breg4 */ \ - .sleb128 offset; /* offset */ \ -1: - - do_cfa_expr(IA32_SIGCONTEXT_sp+4) - do_expr(0, IA32_SIGCONTEXT_ax+4) - do_expr(1, IA32_SIGCONTEXT_cx+4) - do_expr(2, IA32_SIGCONTEXT_dx+4) - do_expr(3, IA32_SIGCONTEXT_bx+4) - do_expr(5, IA32_SIGCONTEXT_bp+4) - do_expr(6, IA32_SIGCONTEXT_si+4) - do_expr(7, IA32_SIGCONTEXT_di+4) - do_expr(8, IA32_SIGCONTEXT_ip+4) - - .byte 0x42 /* DW_CFA_advance_loc 2 -- nop; popl eax. */ - - do_cfa_expr(IA32_SIGCONTEXT_sp) - do_expr(0, IA32_SIGCONTEXT_ax) - do_expr(1, IA32_SIGCONTEXT_cx) - do_expr(2, IA32_SIGCONTEXT_dx) - do_expr(3, IA32_SIGCONTEXT_bx) - do_expr(5, IA32_SIGCONTEXT_bp) - do_expr(6, IA32_SIGCONTEXT_si) - do_expr(7, IA32_SIGCONTEXT_di) - do_expr(8, IA32_SIGCONTEXT_ip) - - .align 4 -.LENDFDEDLSI1: - - .long .LENDFDEDLSI2-.LSTARTFDEDLSI2 /* Length FDE */ -.LSTARTFDEDLSI2: - .long .LSTARTFDEDLSI2-.LSTARTFRAMEDLSI1 /* CIE pointer */ - /* HACK: See above wrt unwind library assumptions. */ - .long .LSTART_rt_sigreturn-1-. /* PC-relative start address */ - .long .LEND_rt_sigreturn-.LSTART_rt_sigreturn+1 - .uleb128 0 /* Augmentation */ - /* What follows are the instructions for the table generation. - We record the locations of each register saved. This is - slightly less complicated than the above, since we don't - modify the stack pointer in the process. */ - - do_cfa_expr(IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_sp) - do_expr(0, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_ax) - do_expr(1, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_cx) - do_expr(2, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_dx) - do_expr(3, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_bx) - do_expr(5, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_bp) - do_expr(6, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_si) - do_expr(7, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_di) - do_expr(8, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_ip) - - .align 4 -.LENDFDEDLSI2: + ud2a + CFI_ENDPROC + .size __kernel_rt_sigreturn,.-__kernel_rt_sigreturn .previous diff --git a/arch/x86/include/asm/dwarf2.h b/arch/x86/include/asm/dwarf2.h index 302e11b..09c9684 100644 --- a/arch/x86/include/asm/dwarf2.h +++ b/arch/x86/include/asm/dwarf2.h @@ -20,6 +20,7 @@ #define CFI_RESTORE_STATE .cfi_restore_state #define CFI_UNDEFINED .cfi_undefined #define CFI_ESCAPE .cfi_escape +#define CFI_SIGNAL_FRAME .cfi_signal_frame #ifndef BUILD_VDSO /* diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c index 25fcde5..0818168 100644 --- a/arch/x86/kernel/asm-offsets.c +++ b/arch/x86/kernel/asm-offsets.c @@ -63,8 +63,14 @@ static void __used common(void) OFFSET(IA32_SIGCONTEXT_bp, sigcontext_32, bp); OFFSET(IA32_SIGCONTEXT_sp, sigcontext_32, sp); OFFSET(IA32_SIGCONTEXT_ip, sigcontext_32, ip); + OFFSET(IA32_SIGCONTEXT_es, sigcontext_32, es); + OFFSET(IA32_SIGCONTEXT_cs, sigcontext_32, cs); + OFFSET(IA32_SIGCONTEXT_ss, sigcontext_32, ss); + OFFSET(IA32_SIGCONTEXT_ds, sigcontext_32, ds); + OFFSET(IA32_SIGCONTEXT_flags, sigcontext_32, flags); BLANK(); + OFFSET(IA32_SIGFRAME_sigcontext, sigframe_ia32, sc); OFFSET(IA32_RT_SIGFRAME_sigcontext, rt_sigframe_ia32, uc.uc_mcontext); #endif
{ "author": "\"tip-bot2 for H. Peter Anvin\" <tip-bot2@linutronix.de>", "date": "Wed, 14 Jan 2026 00:44:53 -0000", "thread_id": "223707e2-3231-4037-bd1f-490ddf6aeeb6@linux.ibm.com.mbox.gz" }
lkml
[PATCH v4 00/10] x86/entry/vdso: clean up the vdso build, vdso updates
This patchset cleans up the vdso build by building the 32- and 64-bit vdsos in separate directories, moving the vdso2c tool to arch/x86/tools, and by merging common code and especially Makefile rules between the 32- and 64-bit vdsos to the greatest extent possible. Be more strict about sanitizing and standardizing the vdso build options. Disable CFI for the vdso until the kernel adds user space IBT support. Modernize the DWARF generation vdso32/sigreturn.S. Add macros to cleanly call system calls from vdso source code. Add the GNU_PROPERTY and GNU_STACK PHDRs to the vdso. When using int $0x80 (old 32-bit hardware or FRED-capable 64-bit hardware) skip the stack stuff in the 32-bit kernel entry code and call int $0x80 directly when used from C code. Changes from v3 to v4: - Improved description of patch 01/10. - Split out the move of vdso2c to tools into a separate patch. - Remove unrelated formatting changes from vdso-layout.lds.S. - Fix *-x32.o being missing from "targets". - Rebased onto v6.19-rc1. Changes from v2 to v3: In arch/x86/include/asm/vdso/sys_call.h: - remove stray comment from prototyping (Uros Biszjak) - remove VDSO_SYSCALL6() since it would require special handling on 32 bits with frame pointers and is currently unused. (Uros Biszjak) - indent nested preprocessor directives. Changes from v1 to v2: Too many to count - much of the patchset has been reworked Patches: x86/entry/vdso: rename vdso_image_* to vdso*_image x86/entry/vdso: move vdso2c to arch/x86/tools x86/entry/vdso: refactor the vdso build x86/entry/vdso32: don't rely on int80_landing_pad for adjusting ip x86/entry/vdso32: remove SYSCALL_ENTER_KERNEL macro in sigreturn.S x86/entry/vdso32: remove open-coded DWARF in sigreturn.S x86/entry/vdso: include GNU_PROPERTY and GNU_STACK PHDRs x86/vdso: abstract out vdso system call internals x86/cpufeature: replace X86_FEATURE_SYSENTER32 with X86_FEATURE_SYSFAST32 x86/entry/vdso32: when using int $0x80, use it directly --- arch/x86/Kconfig.cpufeatures | 8 + arch/x86/Makefile | 2 +- arch/x86/entry/syscall_32.c | 2 +- arch/x86/entry/vdso/.gitignore | 11 +- arch/x86/entry/vdso/Makefile | 162 +-------------------- arch/x86/entry/vdso/common/Makefile.include | 89 +++++++++++ arch/x86/entry/vdso/{vdso-note.S => common/note.S} | 5 +- arch/x86/entry/vdso/{ => common}/vclock_gettime.c | 0 arch/x86/entry/vdso/{ => common}/vdso-layout.lds.S | 38 +++-- arch/x86/entry/vdso/{ => common}/vgetcpu.c | 0 arch/x86/entry/vdso/vdso32/Makefile | 24 +++ arch/x86/entry/vdso/vdso32/note.S | 19 +-- arch/x86/entry/vdso/vdso32/sigreturn.S | 152 +++++-------------- arch/x86/entry/vdso/vdso32/system_call.S | 22 ++- arch/x86/entry/vdso/vdso32/vclock_gettime.c | 5 +- arch/x86/entry/vdso/vdso32/vdso32.lds.S | 2 +- arch/x86/entry/vdso/vdso32/vgetcpu.c | 4 +- arch/x86/entry/vdso/vdso64/Makefile | 46 ++++++ arch/x86/entry/vdso/vdso64/note.S | 1 + arch/x86/entry/vdso/vdso64/vclock_gettime.c | 1 + .../entry/vdso/{vdso.lds.S => vdso64/vdso64.lds.S} | 2 +- arch/x86/entry/vdso/{ => vdso64}/vdsox32.lds.S | 2 +- arch/x86/entry/vdso/vdso64/vgetcpu.c | 1 + .../entry/vdso/{ => vdso64}/vgetrandom-chacha.S | 0 arch/x86/entry/vdso/{ => vdso64}/vgetrandom.c | 2 +- arch/x86/entry/vdso/{ => vdso64}/vsgx.S | 0 arch/x86/entry/vdso/vma.c | 24 ++- arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/include/asm/dwarf2.h | 1 + arch/x86/include/asm/elf.h | 2 +- arch/x86/include/asm/vdso.h | 6 +- arch/x86/include/asm/vdso/gettimeofday.h | 108 +------------- arch/x86/include/asm/vdso/sys_call.h | 105 +++++++++++++ arch/x86/kernel/asm-offsets.c | 6 + arch/x86/kernel/cpu/centaur.c | 3 - arch/x86/kernel/cpu/common.c | 8 + arch/x86/kernel/cpu/intel.c | 4 +- arch/x86/kernel/cpu/zhaoxin.c | 4 +- arch/x86/kernel/fred.c | 2 +- arch/x86/kernel/process_64.c | 6 +- arch/x86/kernel/signal_32.c | 4 +- arch/x86/tools/Makefile | 15 +- arch/x86/{entry/vdso => tools}/vdso2c.c | 0 arch/x86/{entry/vdso => tools}/vdso2c.h | 0 arch/x86/xen/setup.c | 28 ++-- arch/x86/xen/smp_pv.c | 5 +- arch/x86/xen/xen-ops.h | 1 - 47 files changed, 444 insertions(+), 490 deletions(-)
[stripped down the list of recipients quite a bit] On 1/6/26 22:18, H. Peter Anvin wrote: Lo! My daily -next builds for Fedora failed on x86_64 (other archs worked fine). Haven't checked, but from the error message I wonder if this might be due to the changes from this patch-set that showed up in -next today: + /usr/bin/make -s 'HOSTCFLAGS=-O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -mtls-dialect=gnu2 ' 'HOSTLDFLAGS=-Wl,-z,relro -Wl,--as-needed -Wl,-z,pack-relative-relocs -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-hardened-ld-errors -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -specs=/usr/lib/rpm/redhat/redhat-package-notes ' ARCH=x86_64 INSTALL_MOD_PATH=/builddir/build/BUILD/kernel-6.19.0-build/BUILDROOT vdso_install KERNELRELEASE=6.19.0-0.0.next.20260115.439.vanilla.fc44.x86_64+rt readelf: Error: 'arch/x86/entry/vdso/vdso32.so.dbg': No such file readelf: Error: 'arch/x86/entry/vdso/vdso64.so.dbg': No such file scripts/Makefile.vdsoinst:33: warning: overriding recipe for target '/builddir/build/BUILD/kernel-6.19.0-build/BUILDROOT/lib/modules/6.19.0-0.0.next.20260115.439.vanilla.fc44.x86_64+rt/vdso/.build-id/.debug' scripts/Makefile.vdsoinst:33: warning: ignoring old recipe for target '/builddir/build/BUILD/kernel-6.19.0-build/BUILDROOT/lib/modules/6.19.0-0.0.next.20260115.439.vanilla.fc44.x86_64+rt/vdso/.build-id/.debug' make[2]: *** No rule to make target 'arch/x86/entry/vdso/vdso32.so.dbg', needed by '/builddir/build/BUILD/kernel-6.19.0-build/BUILDROOT/lib/modules/6.19.0-0.0.next.20260115.439.vanilla.fc44.x86_64+rt/vdso/vdso32.so'. Stop. make[1]: *** [/builddir/build/BUILD/kernel-6.19.0-build/kernel-next-20260115/linux-6.19.0-0.0.next.20260115.439.vanilla.fc44.x86_64/Makefile:1459: vdso_install] Error 2 make: *** [Makefile:256: __sub-make] Error 2 Full log: https://download.copr.fedorainfracloud.org/results/@kernel-vanilla/next/fedora-rawhide-x86_64/10010857-next-next-all/builder-live.log.gz Ciao, Thorsten
{ "author": "Thorsten Leemhuis <linux@leemhuis.info>", "date": "Thu, 15 Jan 2026 08:00:55 +0100", "thread_id": "223707e2-3231-4037-bd1f-490ddf6aeeb6@linux.ibm.com.mbox.gz" }
lkml
[PATCH v4 00/10] x86/entry/vdso: clean up the vdso build, vdso updates
This patchset cleans up the vdso build by building the 32- and 64-bit vdsos in separate directories, moving the vdso2c tool to arch/x86/tools, and by merging common code and especially Makefile rules between the 32- and 64-bit vdsos to the greatest extent possible. Be more strict about sanitizing and standardizing the vdso build options. Disable CFI for the vdso until the kernel adds user space IBT support. Modernize the DWARF generation vdso32/sigreturn.S. Add macros to cleanly call system calls from vdso source code. Add the GNU_PROPERTY and GNU_STACK PHDRs to the vdso. When using int $0x80 (old 32-bit hardware or FRED-capable 64-bit hardware) skip the stack stuff in the 32-bit kernel entry code and call int $0x80 directly when used from C code. Changes from v3 to v4: - Improved description of patch 01/10. - Split out the move of vdso2c to tools into a separate patch. - Remove unrelated formatting changes from vdso-layout.lds.S. - Fix *-x32.o being missing from "targets". - Rebased onto v6.19-rc1. Changes from v2 to v3: In arch/x86/include/asm/vdso/sys_call.h: - remove stray comment from prototyping (Uros Biszjak) - remove VDSO_SYSCALL6() since it would require special handling on 32 bits with frame pointers and is currently unused. (Uros Biszjak) - indent nested preprocessor directives. Changes from v1 to v2: Too many to count - much of the patchset has been reworked Patches: x86/entry/vdso: rename vdso_image_* to vdso*_image x86/entry/vdso: move vdso2c to arch/x86/tools x86/entry/vdso: refactor the vdso build x86/entry/vdso32: don't rely on int80_landing_pad for adjusting ip x86/entry/vdso32: remove SYSCALL_ENTER_KERNEL macro in sigreturn.S x86/entry/vdso32: remove open-coded DWARF in sigreturn.S x86/entry/vdso: include GNU_PROPERTY and GNU_STACK PHDRs x86/vdso: abstract out vdso system call internals x86/cpufeature: replace X86_FEATURE_SYSENTER32 with X86_FEATURE_SYSFAST32 x86/entry/vdso32: when using int $0x80, use it directly --- arch/x86/Kconfig.cpufeatures | 8 + arch/x86/Makefile | 2 +- arch/x86/entry/syscall_32.c | 2 +- arch/x86/entry/vdso/.gitignore | 11 +- arch/x86/entry/vdso/Makefile | 162 +-------------------- arch/x86/entry/vdso/common/Makefile.include | 89 +++++++++++ arch/x86/entry/vdso/{vdso-note.S => common/note.S} | 5 +- arch/x86/entry/vdso/{ => common}/vclock_gettime.c | 0 arch/x86/entry/vdso/{ => common}/vdso-layout.lds.S | 38 +++-- arch/x86/entry/vdso/{ => common}/vgetcpu.c | 0 arch/x86/entry/vdso/vdso32/Makefile | 24 +++ arch/x86/entry/vdso/vdso32/note.S | 19 +-- arch/x86/entry/vdso/vdso32/sigreturn.S | 152 +++++-------------- arch/x86/entry/vdso/vdso32/system_call.S | 22 ++- arch/x86/entry/vdso/vdso32/vclock_gettime.c | 5 +- arch/x86/entry/vdso/vdso32/vdso32.lds.S | 2 +- arch/x86/entry/vdso/vdso32/vgetcpu.c | 4 +- arch/x86/entry/vdso/vdso64/Makefile | 46 ++++++ arch/x86/entry/vdso/vdso64/note.S | 1 + arch/x86/entry/vdso/vdso64/vclock_gettime.c | 1 + .../entry/vdso/{vdso.lds.S => vdso64/vdso64.lds.S} | 2 +- arch/x86/entry/vdso/{ => vdso64}/vdsox32.lds.S | 2 +- arch/x86/entry/vdso/vdso64/vgetcpu.c | 1 + .../entry/vdso/{ => vdso64}/vgetrandom-chacha.S | 0 arch/x86/entry/vdso/{ => vdso64}/vgetrandom.c | 2 +- arch/x86/entry/vdso/{ => vdso64}/vsgx.S | 0 arch/x86/entry/vdso/vma.c | 24 ++- arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/include/asm/dwarf2.h | 1 + arch/x86/include/asm/elf.h | 2 +- arch/x86/include/asm/vdso.h | 6 +- arch/x86/include/asm/vdso/gettimeofday.h | 108 +------------- arch/x86/include/asm/vdso/sys_call.h | 105 +++++++++++++ arch/x86/kernel/asm-offsets.c | 6 + arch/x86/kernel/cpu/centaur.c | 3 - arch/x86/kernel/cpu/common.c | 8 + arch/x86/kernel/cpu/intel.c | 4 +- arch/x86/kernel/cpu/zhaoxin.c | 4 +- arch/x86/kernel/fred.c | 2 +- arch/x86/kernel/process_64.c | 6 +- arch/x86/kernel/signal_32.c | 4 +- arch/x86/tools/Makefile | 15 +- arch/x86/{entry/vdso => tools}/vdso2c.c | 0 arch/x86/{entry/vdso => tools}/vdso2c.h | 0 arch/x86/xen/setup.c | 28 ++-- arch/x86/xen/smp_pv.c | 5 +- arch/x86/xen/xen-ops.h | 1 - 47 files changed, 444 insertions(+), 490 deletions(-)
On January 14, 2026 11:00:55 PM PST, Thorsten Leemhuis <linux@leemhuis.info> wrote: Looks like it. Specifically it looks like it needs a tweak to make vdso_install. I'll look at it in a few hours.
{ "author": "\"H. Peter Anvin\" <hpa@zytor.com>", "date": "Thu, 15 Jan 2026 07:00:47 -0800", "thread_id": "223707e2-3231-4037-bd1f-490ddf6aeeb6@linux.ibm.com.mbox.gz" }
lkml
[PATCH v4 00/10] x86/entry/vdso: clean up the vdso build, vdso updates
This patchset cleans up the vdso build by building the 32- and 64-bit vdsos in separate directories, moving the vdso2c tool to arch/x86/tools, and by merging common code and especially Makefile rules between the 32- and 64-bit vdsos to the greatest extent possible. Be more strict about sanitizing and standardizing the vdso build options. Disable CFI for the vdso until the kernel adds user space IBT support. Modernize the DWARF generation vdso32/sigreturn.S. Add macros to cleanly call system calls from vdso source code. Add the GNU_PROPERTY and GNU_STACK PHDRs to the vdso. When using int $0x80 (old 32-bit hardware or FRED-capable 64-bit hardware) skip the stack stuff in the 32-bit kernel entry code and call int $0x80 directly when used from C code. Changes from v3 to v4: - Improved description of patch 01/10. - Split out the move of vdso2c to tools into a separate patch. - Remove unrelated formatting changes from vdso-layout.lds.S. - Fix *-x32.o being missing from "targets". - Rebased onto v6.19-rc1. Changes from v2 to v3: In arch/x86/include/asm/vdso/sys_call.h: - remove stray comment from prototyping (Uros Biszjak) - remove VDSO_SYSCALL6() since it would require special handling on 32 bits with frame pointers and is currently unused. (Uros Biszjak) - indent nested preprocessor directives. Changes from v1 to v2: Too many to count - much of the patchset has been reworked Patches: x86/entry/vdso: rename vdso_image_* to vdso*_image x86/entry/vdso: move vdso2c to arch/x86/tools x86/entry/vdso: refactor the vdso build x86/entry/vdso32: don't rely on int80_landing_pad for adjusting ip x86/entry/vdso32: remove SYSCALL_ENTER_KERNEL macro in sigreturn.S x86/entry/vdso32: remove open-coded DWARF in sigreturn.S x86/entry/vdso: include GNU_PROPERTY and GNU_STACK PHDRs x86/vdso: abstract out vdso system call internals x86/cpufeature: replace X86_FEATURE_SYSENTER32 with X86_FEATURE_SYSFAST32 x86/entry/vdso32: when using int $0x80, use it directly --- arch/x86/Kconfig.cpufeatures | 8 + arch/x86/Makefile | 2 +- arch/x86/entry/syscall_32.c | 2 +- arch/x86/entry/vdso/.gitignore | 11 +- arch/x86/entry/vdso/Makefile | 162 +-------------------- arch/x86/entry/vdso/common/Makefile.include | 89 +++++++++++ arch/x86/entry/vdso/{vdso-note.S => common/note.S} | 5 +- arch/x86/entry/vdso/{ => common}/vclock_gettime.c | 0 arch/x86/entry/vdso/{ => common}/vdso-layout.lds.S | 38 +++-- arch/x86/entry/vdso/{ => common}/vgetcpu.c | 0 arch/x86/entry/vdso/vdso32/Makefile | 24 +++ arch/x86/entry/vdso/vdso32/note.S | 19 +-- arch/x86/entry/vdso/vdso32/sigreturn.S | 152 +++++-------------- arch/x86/entry/vdso/vdso32/system_call.S | 22 ++- arch/x86/entry/vdso/vdso32/vclock_gettime.c | 5 +- arch/x86/entry/vdso/vdso32/vdso32.lds.S | 2 +- arch/x86/entry/vdso/vdso32/vgetcpu.c | 4 +- arch/x86/entry/vdso/vdso64/Makefile | 46 ++++++ arch/x86/entry/vdso/vdso64/note.S | 1 + arch/x86/entry/vdso/vdso64/vclock_gettime.c | 1 + .../entry/vdso/{vdso.lds.S => vdso64/vdso64.lds.S} | 2 +- arch/x86/entry/vdso/{ => vdso64}/vdsox32.lds.S | 2 +- arch/x86/entry/vdso/vdso64/vgetcpu.c | 1 + .../entry/vdso/{ => vdso64}/vgetrandom-chacha.S | 0 arch/x86/entry/vdso/{ => vdso64}/vgetrandom.c | 2 +- arch/x86/entry/vdso/{ => vdso64}/vsgx.S | 0 arch/x86/entry/vdso/vma.c | 24 ++- arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/include/asm/dwarf2.h | 1 + arch/x86/include/asm/elf.h | 2 +- arch/x86/include/asm/vdso.h | 6 +- arch/x86/include/asm/vdso/gettimeofday.h | 108 +------------- arch/x86/include/asm/vdso/sys_call.h | 105 +++++++++++++ arch/x86/kernel/asm-offsets.c | 6 + arch/x86/kernel/cpu/centaur.c | 3 - arch/x86/kernel/cpu/common.c | 8 + arch/x86/kernel/cpu/intel.c | 4 +- arch/x86/kernel/cpu/zhaoxin.c | 4 +- arch/x86/kernel/fred.c | 2 +- arch/x86/kernel/process_64.c | 6 +- arch/x86/kernel/signal_32.c | 4 +- arch/x86/tools/Makefile | 15 +- arch/x86/{entry/vdso => tools}/vdso2c.c | 0 arch/x86/{entry/vdso => tools}/vdso2c.h | 0 arch/x86/xen/setup.c | 28 ++-- arch/x86/xen/smp_pv.c | 5 +- arch/x86/xen/xen-ops.h | 1 - 47 files changed, 444 insertions(+), 490 deletions(-)
On Tue, 6 Jan 2026 13:18:36 -0800 "H. Peter Anvin" <hpa@zytor.com> wrote: Hi everyone, I ran the tip master branch through my AI review prompts and this one was flagged. These look right to me, apologies if it's noise: [ ... ] ^^^^^^^ Should this be "-fno-PIE" with the leading dash? The other flags in this line all have the dash prefix, but "fno-PIE" is missing it. Without the dash, filter-out won't match the actual compiler flag. ^^^^^^^^^^^^^^^^^ Is GCC_PLUGIN_CFLAGS the right variable name here? The kbuild system defines GCC_PLUGINS_CFLAGS (with an 's') in scripts/Makefile.gcc-plugins. Other vDSO Makefiles (arm64, sparc, arm) use GCC_PLUGINS_CFLAGS. Without the fix, gcc plugin flags won't be filtered out when CONFIG_GCC_PLUGINS=y. [ ... ] ^^^^^^^^^^^^^^^^^^^^^ Should this be CONFIG_X86_USER_SHADOW_STACK? The Kconfig symbol is defined as "config X86_USER_SHADOW_STACK" and kbuild exposes it as a CONFIG_ prefixed variable. The next lines show the pattern: Both of these correctly use the CONFIG_ prefix. Without it, the shadow stack cf-protection flag will never be added to vDSO builds even when CONFIG_X86_USER_SHADOW_STACK=y.
{ "author": "Chris Mason <clm@meta.com>", "date": "Thu, 15 Jan 2026 19:58:02 -0800", "thread_id": "223707e2-3231-4037-bd1f-490ddf6aeeb6@linux.ibm.com.mbox.gz" }
lkml
[PATCH v4 00/10] x86/entry/vdso: clean up the vdso build, vdso updates
This patchset cleans up the vdso build by building the 32- and 64-bit vdsos in separate directories, moving the vdso2c tool to arch/x86/tools, and by merging common code and especially Makefile rules between the 32- and 64-bit vdsos to the greatest extent possible. Be more strict about sanitizing and standardizing the vdso build options. Disable CFI for the vdso until the kernel adds user space IBT support. Modernize the DWARF generation vdso32/sigreturn.S. Add macros to cleanly call system calls from vdso source code. Add the GNU_PROPERTY and GNU_STACK PHDRs to the vdso. When using int $0x80 (old 32-bit hardware or FRED-capable 64-bit hardware) skip the stack stuff in the 32-bit kernel entry code and call int $0x80 directly when used from C code. Changes from v3 to v4: - Improved description of patch 01/10. - Split out the move of vdso2c to tools into a separate patch. - Remove unrelated formatting changes from vdso-layout.lds.S. - Fix *-x32.o being missing from "targets". - Rebased onto v6.19-rc1. Changes from v2 to v3: In arch/x86/include/asm/vdso/sys_call.h: - remove stray comment from prototyping (Uros Biszjak) - remove VDSO_SYSCALL6() since it would require special handling on 32 bits with frame pointers and is currently unused. (Uros Biszjak) - indent nested preprocessor directives. Changes from v1 to v2: Too many to count - much of the patchset has been reworked Patches: x86/entry/vdso: rename vdso_image_* to vdso*_image x86/entry/vdso: move vdso2c to arch/x86/tools x86/entry/vdso: refactor the vdso build x86/entry/vdso32: don't rely on int80_landing_pad for adjusting ip x86/entry/vdso32: remove SYSCALL_ENTER_KERNEL macro in sigreturn.S x86/entry/vdso32: remove open-coded DWARF in sigreturn.S x86/entry/vdso: include GNU_PROPERTY and GNU_STACK PHDRs x86/vdso: abstract out vdso system call internals x86/cpufeature: replace X86_FEATURE_SYSENTER32 with X86_FEATURE_SYSFAST32 x86/entry/vdso32: when using int $0x80, use it directly --- arch/x86/Kconfig.cpufeatures | 8 + arch/x86/Makefile | 2 +- arch/x86/entry/syscall_32.c | 2 +- arch/x86/entry/vdso/.gitignore | 11 +- arch/x86/entry/vdso/Makefile | 162 +-------------------- arch/x86/entry/vdso/common/Makefile.include | 89 +++++++++++ arch/x86/entry/vdso/{vdso-note.S => common/note.S} | 5 +- arch/x86/entry/vdso/{ => common}/vclock_gettime.c | 0 arch/x86/entry/vdso/{ => common}/vdso-layout.lds.S | 38 +++-- arch/x86/entry/vdso/{ => common}/vgetcpu.c | 0 arch/x86/entry/vdso/vdso32/Makefile | 24 +++ arch/x86/entry/vdso/vdso32/note.S | 19 +-- arch/x86/entry/vdso/vdso32/sigreturn.S | 152 +++++-------------- arch/x86/entry/vdso/vdso32/system_call.S | 22 ++- arch/x86/entry/vdso/vdso32/vclock_gettime.c | 5 +- arch/x86/entry/vdso/vdso32/vdso32.lds.S | 2 +- arch/x86/entry/vdso/vdso32/vgetcpu.c | 4 +- arch/x86/entry/vdso/vdso64/Makefile | 46 ++++++ arch/x86/entry/vdso/vdso64/note.S | 1 + arch/x86/entry/vdso/vdso64/vclock_gettime.c | 1 + .../entry/vdso/{vdso.lds.S => vdso64/vdso64.lds.S} | 2 +- arch/x86/entry/vdso/{ => vdso64}/vdsox32.lds.S | 2 +- arch/x86/entry/vdso/vdso64/vgetcpu.c | 1 + .../entry/vdso/{ => vdso64}/vgetrandom-chacha.S | 0 arch/x86/entry/vdso/{ => vdso64}/vgetrandom.c | 2 +- arch/x86/entry/vdso/{ => vdso64}/vsgx.S | 0 arch/x86/entry/vdso/vma.c | 24 ++- arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/include/asm/dwarf2.h | 1 + arch/x86/include/asm/elf.h | 2 +- arch/x86/include/asm/vdso.h | 6 +- arch/x86/include/asm/vdso/gettimeofday.h | 108 +------------- arch/x86/include/asm/vdso/sys_call.h | 105 +++++++++++++ arch/x86/kernel/asm-offsets.c | 6 + arch/x86/kernel/cpu/centaur.c | 3 - arch/x86/kernel/cpu/common.c | 8 + arch/x86/kernel/cpu/intel.c | 4 +- arch/x86/kernel/cpu/zhaoxin.c | 4 +- arch/x86/kernel/fred.c | 2 +- arch/x86/kernel/process_64.c | 6 +- arch/x86/kernel/signal_32.c | 4 +- arch/x86/tools/Makefile | 15 +- arch/x86/{entry/vdso => tools}/vdso2c.c | 0 arch/x86/{entry/vdso => tools}/vdso2c.h | 0 arch/x86/xen/setup.c | 28 ++-- arch/x86/xen/smp_pv.c | 5 +- arch/x86/xen/xen-ops.h | 1 - 47 files changed, 444 insertions(+), 490 deletions(-)
From: "Borislav Petkov (AMD)" <bp@alien8.de> Date: Tue, 27 Jan 2026 23:09:13 +0100 The commit a76108d05ee1 ("x86/entry/vdso: Move vdso2c to arch/x86/tools") moved vdso2c to arch/x86/tools/ and commit 93d73005bff4 ("x86/entry/vdso: Rename vdso_image_* to vdso*_image") renamed .so files but also dropped vdso2c from arch/x86/entry/vdso/.gitignore. It should've moved it to arch/x86/tools/.gitignore instead. Do that. Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> --- arch/x86/tools/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/tools/.gitignore b/arch/x86/tools/.gitignore index d36dc7cf9115..51d5c22b38d7 100644 --- a/arch/x86/tools/.gitignore +++ b/arch/x86/tools/.gitignore @@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only relocs +vdso2c -- 2.51.0 -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette
{ "author": "Borislav Petkov <bp@alien8.de>", "date": "Tue, 27 Jan 2026 23:16:33 +0100", "thread_id": "223707e2-3231-4037-bd1f-490ddf6aeeb6@linux.ibm.com.mbox.gz" }
lkml
[PATCH v4 00/10] x86/entry/vdso: clean up the vdso build, vdso updates
This patchset cleans up the vdso build by building the 32- and 64-bit vdsos in separate directories, moving the vdso2c tool to arch/x86/tools, and by merging common code and especially Makefile rules between the 32- and 64-bit vdsos to the greatest extent possible. Be more strict about sanitizing and standardizing the vdso build options. Disable CFI for the vdso until the kernel adds user space IBT support. Modernize the DWARF generation vdso32/sigreturn.S. Add macros to cleanly call system calls from vdso source code. Add the GNU_PROPERTY and GNU_STACK PHDRs to the vdso. When using int $0x80 (old 32-bit hardware or FRED-capable 64-bit hardware) skip the stack stuff in the 32-bit kernel entry code and call int $0x80 directly when used from C code. Changes from v3 to v4: - Improved description of patch 01/10. - Split out the move of vdso2c to tools into a separate patch. - Remove unrelated formatting changes from vdso-layout.lds.S. - Fix *-x32.o being missing from "targets". - Rebased onto v6.19-rc1. Changes from v2 to v3: In arch/x86/include/asm/vdso/sys_call.h: - remove stray comment from prototyping (Uros Biszjak) - remove VDSO_SYSCALL6() since it would require special handling on 32 bits with frame pointers and is currently unused. (Uros Biszjak) - indent nested preprocessor directives. Changes from v1 to v2: Too many to count - much of the patchset has been reworked Patches: x86/entry/vdso: rename vdso_image_* to vdso*_image x86/entry/vdso: move vdso2c to arch/x86/tools x86/entry/vdso: refactor the vdso build x86/entry/vdso32: don't rely on int80_landing_pad for adjusting ip x86/entry/vdso32: remove SYSCALL_ENTER_KERNEL macro in sigreturn.S x86/entry/vdso32: remove open-coded DWARF in sigreturn.S x86/entry/vdso: include GNU_PROPERTY and GNU_STACK PHDRs x86/vdso: abstract out vdso system call internals x86/cpufeature: replace X86_FEATURE_SYSENTER32 with X86_FEATURE_SYSFAST32 x86/entry/vdso32: when using int $0x80, use it directly --- arch/x86/Kconfig.cpufeatures | 8 + arch/x86/Makefile | 2 +- arch/x86/entry/syscall_32.c | 2 +- arch/x86/entry/vdso/.gitignore | 11 +- arch/x86/entry/vdso/Makefile | 162 +-------------------- arch/x86/entry/vdso/common/Makefile.include | 89 +++++++++++ arch/x86/entry/vdso/{vdso-note.S => common/note.S} | 5 +- arch/x86/entry/vdso/{ => common}/vclock_gettime.c | 0 arch/x86/entry/vdso/{ => common}/vdso-layout.lds.S | 38 +++-- arch/x86/entry/vdso/{ => common}/vgetcpu.c | 0 arch/x86/entry/vdso/vdso32/Makefile | 24 +++ arch/x86/entry/vdso/vdso32/note.S | 19 +-- arch/x86/entry/vdso/vdso32/sigreturn.S | 152 +++++-------------- arch/x86/entry/vdso/vdso32/system_call.S | 22 ++- arch/x86/entry/vdso/vdso32/vclock_gettime.c | 5 +- arch/x86/entry/vdso/vdso32/vdso32.lds.S | 2 +- arch/x86/entry/vdso/vdso32/vgetcpu.c | 4 +- arch/x86/entry/vdso/vdso64/Makefile | 46 ++++++ arch/x86/entry/vdso/vdso64/note.S | 1 + arch/x86/entry/vdso/vdso64/vclock_gettime.c | 1 + .../entry/vdso/{vdso.lds.S => vdso64/vdso64.lds.S} | 2 +- arch/x86/entry/vdso/{ => vdso64}/vdsox32.lds.S | 2 +- arch/x86/entry/vdso/vdso64/vgetcpu.c | 1 + .../entry/vdso/{ => vdso64}/vgetrandom-chacha.S | 0 arch/x86/entry/vdso/{ => vdso64}/vgetrandom.c | 2 +- arch/x86/entry/vdso/{ => vdso64}/vsgx.S | 0 arch/x86/entry/vdso/vma.c | 24 ++- arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/include/asm/dwarf2.h | 1 + arch/x86/include/asm/elf.h | 2 +- arch/x86/include/asm/vdso.h | 6 +- arch/x86/include/asm/vdso/gettimeofday.h | 108 +------------- arch/x86/include/asm/vdso/sys_call.h | 105 +++++++++++++ arch/x86/kernel/asm-offsets.c | 6 + arch/x86/kernel/cpu/centaur.c | 3 - arch/x86/kernel/cpu/common.c | 8 + arch/x86/kernel/cpu/intel.c | 4 +- arch/x86/kernel/cpu/zhaoxin.c | 4 +- arch/x86/kernel/fred.c | 2 +- arch/x86/kernel/process_64.c | 6 +- arch/x86/kernel/signal_32.c | 4 +- arch/x86/tools/Makefile | 15 +- arch/x86/{entry/vdso => tools}/vdso2c.c | 0 arch/x86/{entry/vdso => tools}/vdso2c.h | 0 arch/x86/xen/setup.c | 28 ++-- arch/x86/xen/smp_pv.c | 5 +- arch/x86/xen/xen-ops.h | 1 - 47 files changed, 444 insertions(+), 490 deletions(-)
The following commit has been merged into the x86/entry branch of tip: Commit-ID: ce9b1c10c3f1c723c3cc7b63aa8331fdb6c57a04 Gitweb: https://git.kernel.org/tip/ce9b1c10c3f1c723c3cc7b63aa8331fdb6c57a04 Author: Borislav Petkov (AMD) <bp@alien8.de> AuthorDate: Tue, 27 Jan 2026 23:09:13 +01:00 Committer: Borislav Petkov (AMD) <bp@alien8.de> CommitterDate: Tue, 27 Jan 2026 23:27:51 +01:00 x86/entry/vdso: Add vdso2c to .gitignore The commit a76108d05ee1 ("x86/entry/vdso: Move vdso2c to arch/x86/tools") moved vdso2c to arch/x86/tools/ and commit 93d73005bff4 ("x86/entry/vdso: Rename vdso_image_* to vdso*_image") renamed .so files but also dropped vdso2c from arch/x86/entry/vdso/.gitignore. It should've moved it to arch/x86/tools/.gitignore instead. Do that. Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://patch.msgid.link/20260127221633.GAaXk5QcG8ILa1VWYR@fat_crate.local --- arch/x86/tools/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/tools/.gitignore b/arch/x86/tools/.gitignore index d36dc7c..51d5c22 100644 --- a/arch/x86/tools/.gitignore +++ b/arch/x86/tools/.gitignore @@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only relocs +vdso2c
{ "author": "\"tip-bot2 for Borislav Petkov (AMD)\" <tip-bot2@linutronix.de>", "date": "Tue, 27 Jan 2026 22:33:30 -0000", "thread_id": "223707e2-3231-4037-bd1f-490ddf6aeeb6@linux.ibm.com.mbox.gz" }
lkml
[PATCH v4 00/10] x86/entry/vdso: clean up the vdso build, vdso updates
This patchset cleans up the vdso build by building the 32- and 64-bit vdsos in separate directories, moving the vdso2c tool to arch/x86/tools, and by merging common code and especially Makefile rules between the 32- and 64-bit vdsos to the greatest extent possible. Be more strict about sanitizing and standardizing the vdso build options. Disable CFI for the vdso until the kernel adds user space IBT support. Modernize the DWARF generation vdso32/sigreturn.S. Add macros to cleanly call system calls from vdso source code. Add the GNU_PROPERTY and GNU_STACK PHDRs to the vdso. When using int $0x80 (old 32-bit hardware or FRED-capable 64-bit hardware) skip the stack stuff in the 32-bit kernel entry code and call int $0x80 directly when used from C code. Changes from v3 to v4: - Improved description of patch 01/10. - Split out the move of vdso2c to tools into a separate patch. - Remove unrelated formatting changes from vdso-layout.lds.S. - Fix *-x32.o being missing from "targets". - Rebased onto v6.19-rc1. Changes from v2 to v3: In arch/x86/include/asm/vdso/sys_call.h: - remove stray comment from prototyping (Uros Biszjak) - remove VDSO_SYSCALL6() since it would require special handling on 32 bits with frame pointers and is currently unused. (Uros Biszjak) - indent nested preprocessor directives. Changes from v1 to v2: Too many to count - much of the patchset has been reworked Patches: x86/entry/vdso: rename vdso_image_* to vdso*_image x86/entry/vdso: move vdso2c to arch/x86/tools x86/entry/vdso: refactor the vdso build x86/entry/vdso32: don't rely on int80_landing_pad for adjusting ip x86/entry/vdso32: remove SYSCALL_ENTER_KERNEL macro in sigreturn.S x86/entry/vdso32: remove open-coded DWARF in sigreturn.S x86/entry/vdso: include GNU_PROPERTY and GNU_STACK PHDRs x86/vdso: abstract out vdso system call internals x86/cpufeature: replace X86_FEATURE_SYSENTER32 with X86_FEATURE_SYSFAST32 x86/entry/vdso32: when using int $0x80, use it directly --- arch/x86/Kconfig.cpufeatures | 8 + arch/x86/Makefile | 2 +- arch/x86/entry/syscall_32.c | 2 +- arch/x86/entry/vdso/.gitignore | 11 +- arch/x86/entry/vdso/Makefile | 162 +-------------------- arch/x86/entry/vdso/common/Makefile.include | 89 +++++++++++ arch/x86/entry/vdso/{vdso-note.S => common/note.S} | 5 +- arch/x86/entry/vdso/{ => common}/vclock_gettime.c | 0 arch/x86/entry/vdso/{ => common}/vdso-layout.lds.S | 38 +++-- arch/x86/entry/vdso/{ => common}/vgetcpu.c | 0 arch/x86/entry/vdso/vdso32/Makefile | 24 +++ arch/x86/entry/vdso/vdso32/note.S | 19 +-- arch/x86/entry/vdso/vdso32/sigreturn.S | 152 +++++-------------- arch/x86/entry/vdso/vdso32/system_call.S | 22 ++- arch/x86/entry/vdso/vdso32/vclock_gettime.c | 5 +- arch/x86/entry/vdso/vdso32/vdso32.lds.S | 2 +- arch/x86/entry/vdso/vdso32/vgetcpu.c | 4 +- arch/x86/entry/vdso/vdso64/Makefile | 46 ++++++ arch/x86/entry/vdso/vdso64/note.S | 1 + arch/x86/entry/vdso/vdso64/vclock_gettime.c | 1 + .../entry/vdso/{vdso.lds.S => vdso64/vdso64.lds.S} | 2 +- arch/x86/entry/vdso/{ => vdso64}/vdsox32.lds.S | 2 +- arch/x86/entry/vdso/vdso64/vgetcpu.c | 1 + .../entry/vdso/{ => vdso64}/vgetrandom-chacha.S | 0 arch/x86/entry/vdso/{ => vdso64}/vgetrandom.c | 2 +- arch/x86/entry/vdso/{ => vdso64}/vsgx.S | 0 arch/x86/entry/vdso/vma.c | 24 ++- arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/include/asm/dwarf2.h | 1 + arch/x86/include/asm/elf.h | 2 +- arch/x86/include/asm/vdso.h | 6 +- arch/x86/include/asm/vdso/gettimeofday.h | 108 +------------- arch/x86/include/asm/vdso/sys_call.h | 105 +++++++++++++ arch/x86/kernel/asm-offsets.c | 6 + arch/x86/kernel/cpu/centaur.c | 3 - arch/x86/kernel/cpu/common.c | 8 + arch/x86/kernel/cpu/intel.c | 4 +- arch/x86/kernel/cpu/zhaoxin.c | 4 +- arch/x86/kernel/fred.c | 2 +- arch/x86/kernel/process_64.c | 6 +- arch/x86/kernel/signal_32.c | 4 +- arch/x86/tools/Makefile | 15 +- arch/x86/{entry/vdso => tools}/vdso2c.c | 0 arch/x86/{entry/vdso => tools}/vdso2c.h | 0 arch/x86/xen/setup.c | 28 ++-- arch/x86/xen/smp_pv.c | 5 +- arch/x86/xen/xen-ops.h | 1 - 47 files changed, 444 insertions(+), 490 deletions(-)
Hello Peter! On 1/6/2026 10:18 PM, H. Peter Anvin wrote: Hopefully Glibc developers will do something similar for x86-64 __restore_rt() in Glibc sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c. ... ... Note that the "S" in "zRS" is the signal frame indication. Your version does no longer have this nop nor does the FDE start one byte earlier. Isn't that required for unwinders any longer? See excerpt from dumped DWARF and disassembly for __kernel_sigreturn() below. ... Ditto. Excerpt from dump of DWARF and disassembly with your patch: $ objdump -d -Wf arch/x86/entry/vdso/vdso32/vdso32.so.dbg ... 000001cc 0000003c 00000000 CIE <-- CIE for __kernel_sigreturn Version: 1 Augmentation: "zRS" Code alignment factor: 1 Data alignment factor: -4 Return address column: 8 Augmentation data: 1b DW_CFA_def_cfa: r4 (esp) ofs 4 DW_CFA_offset_extended_sf: r8 (eip) at cfa+56 DW_CFA_offset_extended_sf: r0 (eax) at cfa+44 DW_CFA_offset_extended_sf: r3 (ebx) at cfa+32 DW_CFA_offset_extended_sf: r1 (ecx) at cfa+40 DW_CFA_offset_extended_sf: r2 (edx) at cfa+36 DW_CFA_offset_extended_sf: r4 (esp) at cfa+28 DW_CFA_offset_extended_sf: r5 (ebp) at cfa+24 DW_CFA_offset_extended_sf: r6 (esi) at cfa+20 DW_CFA_offset_extended_sf: r7 (edi) at cfa+16 DW_CFA_offset_extended_sf: r40 (es) at cfa+8 DW_CFA_offset_extended_sf: r41 (cs) at cfa+60 DW_CFA_offset_extended_sf: r42 (ss) at cfa+72 DW_CFA_offset_extended_sf: r43 (ds) at cfa+12 DW_CFA_offset_extended_sf: r9 (eflags) at cfa+64 DW_CFA_nop 0000020c 00000010 00000044 FDE cie=000001cc pc=00001a40..00001a4a <-- FDE for __kernel_sigreturn DW_CFA_advance_loc: 1 to 00001a41 DW_CFA_def_cfa_offset: 0 [ The FDE covers the range [1a40..1a4a[. Previously it would have started one byte earlier (at the nop), so that the range would have been [1a3f..1a4a[. This is/was required for unwinders that always subtract one from the unwound return address, so that it points into the instruction that invoked the function (e.g. call) instead of behind it, in case it was invoked by a non-returning function. Such an unwinder would now lookup IP=1a3f as belonging to int80_landing_pad (and use the DWARF rules applicable to its last instruction) instead of __kernel_sigreturn (and its rules). Likewise for __kernel_rt_sigreturn. ] ... 00001a3c <int80_landing_pad>: 1a3c: 5d pop %ebp 1a3d: 5a pop %edx 1a3e: 59 pop %ecx 1a3f: c3 ret 00001a40 <__kernel_sigreturn>: 1a40: 58 pop %eax 1a41: b8 77 00 00 00 mov $0x77,%eax 1a46: cd 80 int $0x80 00001a48 <vdso32_sigreturn_landing_pad>: 1a48: 0f 0b ud2 1a4a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi Excerpt without your patch: $ objdump -d -Wf arch/x86/entry/vdso/vdso32/vdso32.so.dbg ... 000001cc 00000010 00000000 CIE <-- CIE for __kernel_sigreturn and __kernel_rt_sigreturn Version: 1 Augmentation: "zRS" Code alignment factor: 1 Data alignment factor: -4 Return address column: 8 Augmentation data: 1b DW_CFA_nop DW_CFA_nop 000001e0 00000068 00000018 FDE cie=000001cc pc=00001a6f..00001a78 <-- FDE for __kernel_sigreturn DW_CFA_def_cfa_expression (DW_OP_breg4 (esp): 32; DW_OP_deref) DW_CFA_expression: r0 (eax) (DW_OP_breg4 (esp): 48) DW_CFA_expression: r1 (ecx) (DW_OP_breg4 (esp): 44) DW_CFA_expression: r2 (edx) (DW_OP_breg4 (esp): 40) DW_CFA_expression: r3 (ebx) (DW_OP_breg4 (esp): 36) DW_CFA_expression: r5 (ebp) (DW_OP_breg4 (esp): 28) DW_CFA_expression: r6 (esi) (DW_OP_breg4 (esp): 24) DW_CFA_expression: r7 (edi) (DW_OP_breg4 (esp): 20) DW_CFA_expression: r8 (eip) (DW_OP_breg4 (esp): 60) DW_CFA_advance_loc: 2 to 00001a71 DW_CFA_def_cfa_expression (DW_OP_breg4 (esp): 28; DW_OP_deref) DW_CFA_expression: r0 (eax) (DW_OP_breg4 (esp): 44) DW_CFA_expression: r1 (ecx) (DW_OP_breg4 (esp): 40) DW_CFA_expression: r2 (edx) (DW_OP_breg4 (esp): 36) DW_CFA_expression: r3 (ebx) (DW_OP_breg4 (esp): 32) DW_CFA_expression: r5 (ebp) (DW_OP_breg4 (esp): 24) DW_CFA_expression: r6 (esi) (DW_OP_breg4 (esp): 20) DW_CFA_expression: r7 (edi) (DW_OP_breg4 (esp): 16) DW_CFA_expression: r8 (eip) (DW_OP_breg4 (esp): 56) [ See how the FDE for __kernel_sigreturn covers the range [1a6f..1a78[. An unwinder that always subtracts one from the return address would lookup IP=1a6f as belonging to __kernel_sigreturn (and use the DWARF rules applicable to the nop preceeding its symbol). Likewise for __kernel_rt_sigreturn. Or is that no longer true? ] ... 00001a5c <int80_landing_pad>: 1a5c: 5d pop %ebp 1a5d: 5a pop %edx 1a5e: 59 pop %ecx 1a5f: c3 ret 1a60: 90 nop 1a61: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 1a68: 2e 8d b4 26 00 00 00 lea %cs:0x0(%esi,%eiz,1),%esi 1a6f: 00 00001a70 <__kernel_sigreturn>: 1a70: 58 pop %eax 1a71: b8 77 00 00 00 mov $0x77,%eax 1a76: cd 80 int $0x80 Thanks and regards, Jens -- Jens Remus Linux on Z Development (D3303) jremus@de.ibm.com / jremus@linux.ibm.com IBM Deutschland Research & Development GmbH; Vorsitzender des Aufsichtsrats: Wolfgang Wendt; Geschäftsführung: David Faller; Sitz der Gesellschaft: Ehningen; Registergericht: Amtsgericht Stuttgart, HRB 243294 IBM Data Privacy Statement: https://www.ibm.com/privacy/
{ "author": "Jens Remus <jremus@linux.ibm.com>", "date": "Mon, 2 Feb 2026 18:02:48 +0100", "thread_id": "223707e2-3231-4037-bd1f-490ddf6aeeb6@linux.ibm.com.mbox.gz" }
lkml
[PATCH] nvdimm: virtio_pmem: serialize flush requests
Under heavy concurrent flush traffic, virtio-pmem can overflow its request virtqueue (req_vq): virtqueue_add_sgs() starts returning -ENOSPC and the driver logs "no free slots in the virtqueue". Shortly after that the device enters VIRTIO_CONFIG_S_NEEDS_RESET and flush requests fail with "virtio pmem device needs a reset". Serialize virtio_pmem_flush() with a per-device mutex so only one flush request is in-flight at a time. This prevents req_vq descriptor overflow under high concurrency. Reproducer (guest with virtio-pmem): - mkfs.ext4 -F /dev/pmem0 - mount -t ext4 -o dax,noatime /dev/pmem0 /mnt/bench - fio: ioengine=io_uring rw=randwrite bs=4k iodepth=64 numjobs=64 direct=1 fsync=1 runtime=30s time_based=1 - dmesg: "no free slots in the virtqueue" "virtio pmem device needs a reset" Fixes: 6e84200c0a29 ("virtio-pmem: Add virtio pmem driver") Signed-off-by: Li Chen <me@linux.beauty> --- drivers/nvdimm/nd_virtio.c | 15 +++++++++++---- drivers/nvdimm/virtio_pmem.c | 1 + drivers/nvdimm/virtio_pmem.h | 4 ++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/nvdimm/nd_virtio.c b/drivers/nvdimm/nd_virtio.c index c3f07be4aa22..827a17fe7c71 100644 --- a/drivers/nvdimm/nd_virtio.c +++ b/drivers/nvdimm/nd_virtio.c @@ -44,19 +44,24 @@ static int virtio_pmem_flush(struct nd_region *nd_region) unsigned long flags; int err, err1; + might_sleep(); + mutex_lock(&vpmem->flush_lock); + /* * Don't bother to submit the request to the device if the device is * not activated. */ if (vdev->config->get_status(vdev) & VIRTIO_CONFIG_S_NEEDS_RESET) { dev_info(&vdev->dev, "virtio pmem device needs a reset\n"); - return -EIO; + err = -EIO; + goto out_unlock; } - might_sleep(); req_data = kmalloc(sizeof(*req_data), GFP_KERNEL); - if (!req_data) - return -ENOMEM; + if (!req_data) { + err = -ENOMEM; + goto out_unlock; + } req_data->done = false; init_waitqueue_head(&req_data->host_acked); @@ -103,6 +108,8 @@ static int virtio_pmem_flush(struct nd_region *nd_region) } kfree(req_data); +out_unlock: + mutex_unlock(&vpmem->flush_lock); return err; }; diff --git a/drivers/nvdimm/virtio_pmem.c b/drivers/nvdimm/virtio_pmem.c index 2396d19ce549..77b196661905 100644 --- a/drivers/nvdimm/virtio_pmem.c +++ b/drivers/nvdimm/virtio_pmem.c @@ -64,6 +64,7 @@ static int virtio_pmem_probe(struct virtio_device *vdev) goto out_err; } + mutex_init(&vpmem->flush_lock); vpmem->vdev = vdev; vdev->priv = vpmem; err = init_vq(vpmem); diff --git a/drivers/nvdimm/virtio_pmem.h b/drivers/nvdimm/virtio_pmem.h index 0dddefe594c4..f72cf17f9518 100644 --- a/drivers/nvdimm/virtio_pmem.h +++ b/drivers/nvdimm/virtio_pmem.h @@ -13,6 +13,7 @@ #include <linux/module.h> #include <uapi/linux/virtio_pmem.h> #include <linux/libnvdimm.h> +#include <linux/mutex.h> #include <linux/spinlock.h> struct virtio_pmem_request { @@ -35,6 +36,9 @@ struct virtio_pmem { /* Virtio pmem request queue */ struct virtqueue *req_vq; + /* Serialize flush requests to the device. */ + struct mutex flush_lock; + /* nvdimm bus registers virtio pmem device */ struct nvdimm_bus *nvdimm_bus; struct nvdimm_bus_descriptor nd_desc; -- 2.52.0
Li Chen wrote: I don't see this error. <file> 13:28:50 > cat foo.fio # test http://lore.kernel.org/20260113034552.62805-1-me@linux.beauty [global] filename=/mnt/bench/foo ioengine=io_uring size=1G bs=4K iodepth=64 numjobs=64 direct=1 fsync=1 runtime=30s time_based=1 [rand-write] rw=randwrite </file> It's possible I'm doing something wrong. Can you share your qemu cmdline or more details on the bug yall see. Assuming this does fix a bug I'd rather use guard here. guard(mutex)(&vpmem->flush_lock); Then skip all the gotos and out_unlock stuff. Also, does this affect performance at all? Ira [snip]
{ "author": "Ira Weiny <ira.weiny@intel.com>", "date": "Fri, 30 Jan 2026 14:52:12 -0600", "thread_id": "6980dc5569d5a_3430210092@iweiny-mobl.notmuch.mbox.gz" }
lkml
[PATCH] nvdimm: virtio_pmem: serialize flush requests
Under heavy concurrent flush traffic, virtio-pmem can overflow its request virtqueue (req_vq): virtqueue_add_sgs() starts returning -ENOSPC and the driver logs "no free slots in the virtqueue". Shortly after that the device enters VIRTIO_CONFIG_S_NEEDS_RESET and flush requests fail with "virtio pmem device needs a reset". Serialize virtio_pmem_flush() with a per-device mutex so only one flush request is in-flight at a time. This prevents req_vq descriptor overflow under high concurrency. Reproducer (guest with virtio-pmem): - mkfs.ext4 -F /dev/pmem0 - mount -t ext4 -o dax,noatime /dev/pmem0 /mnt/bench - fio: ioengine=io_uring rw=randwrite bs=4k iodepth=64 numjobs=64 direct=1 fsync=1 runtime=30s time_based=1 - dmesg: "no free slots in the virtqueue" "virtio pmem device needs a reset" Fixes: 6e84200c0a29 ("virtio-pmem: Add virtio pmem driver") Signed-off-by: Li Chen <me@linux.beauty> --- drivers/nvdimm/nd_virtio.c | 15 +++++++++++---- drivers/nvdimm/virtio_pmem.c | 1 + drivers/nvdimm/virtio_pmem.h | 4 ++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/nvdimm/nd_virtio.c b/drivers/nvdimm/nd_virtio.c index c3f07be4aa22..827a17fe7c71 100644 --- a/drivers/nvdimm/nd_virtio.c +++ b/drivers/nvdimm/nd_virtio.c @@ -44,19 +44,24 @@ static int virtio_pmem_flush(struct nd_region *nd_region) unsigned long flags; int err, err1; + might_sleep(); + mutex_lock(&vpmem->flush_lock); + /* * Don't bother to submit the request to the device if the device is * not activated. */ if (vdev->config->get_status(vdev) & VIRTIO_CONFIG_S_NEEDS_RESET) { dev_info(&vdev->dev, "virtio pmem device needs a reset\n"); - return -EIO; + err = -EIO; + goto out_unlock; } - might_sleep(); req_data = kmalloc(sizeof(*req_data), GFP_KERNEL); - if (!req_data) - return -ENOMEM; + if (!req_data) { + err = -ENOMEM; + goto out_unlock; + } req_data->done = false; init_waitqueue_head(&req_data->host_acked); @@ -103,6 +108,8 @@ static int virtio_pmem_flush(struct nd_region *nd_region) } kfree(req_data); +out_unlock: + mutex_unlock(&vpmem->flush_lock); return err; }; diff --git a/drivers/nvdimm/virtio_pmem.c b/drivers/nvdimm/virtio_pmem.c index 2396d19ce549..77b196661905 100644 --- a/drivers/nvdimm/virtio_pmem.c +++ b/drivers/nvdimm/virtio_pmem.c @@ -64,6 +64,7 @@ static int virtio_pmem_probe(struct virtio_device *vdev) goto out_err; } + mutex_init(&vpmem->flush_lock); vpmem->vdev = vdev; vdev->priv = vpmem; err = init_vq(vpmem); diff --git a/drivers/nvdimm/virtio_pmem.h b/drivers/nvdimm/virtio_pmem.h index 0dddefe594c4..f72cf17f9518 100644 --- a/drivers/nvdimm/virtio_pmem.h +++ b/drivers/nvdimm/virtio_pmem.h @@ -13,6 +13,7 @@ #include <linux/module.h> #include <uapi/linux/virtio_pmem.h> #include <linux/libnvdimm.h> +#include <linux/mutex.h> #include <linux/spinlock.h> struct virtio_pmem_request { @@ -35,6 +36,9 @@ struct virtio_pmem { /* Virtio pmem request queue */ struct virtqueue *req_vq; + /* Serialize flush requests to the device. */ + struct mutex flush_lock; + /* nvdimm bus registers virtio pmem device */ struct nvdimm_bus *nvdimm_bus; struct nvdimm_bus_descriptor nd_desc; -- 2.52.0
On Fri, Jan 30, 2026 at 02:52:12PM -0600, Ira Weiny wrote: for that matter might_sleep not really needed near mutex_lock.
{ "author": "\"Michael S. Tsirkin\" <mst@redhat.com>", "date": "Sat, 31 Jan 2026 12:46:19 -0500", "thread_id": "6980dc5569d5a_3430210092@iweiny-mobl.notmuch.mbox.gz" }
lkml
[PATCH] nvdimm: virtio_pmem: serialize flush requests
Under heavy concurrent flush traffic, virtio-pmem can overflow its request virtqueue (req_vq): virtqueue_add_sgs() starts returning -ENOSPC and the driver logs "no free slots in the virtqueue". Shortly after that the device enters VIRTIO_CONFIG_S_NEEDS_RESET and flush requests fail with "virtio pmem device needs a reset". Serialize virtio_pmem_flush() with a per-device mutex so only one flush request is in-flight at a time. This prevents req_vq descriptor overflow under high concurrency. Reproducer (guest with virtio-pmem): - mkfs.ext4 -F /dev/pmem0 - mount -t ext4 -o dax,noatime /dev/pmem0 /mnt/bench - fio: ioengine=io_uring rw=randwrite bs=4k iodepth=64 numjobs=64 direct=1 fsync=1 runtime=30s time_based=1 - dmesg: "no free slots in the virtqueue" "virtio pmem device needs a reset" Fixes: 6e84200c0a29 ("virtio-pmem: Add virtio pmem driver") Signed-off-by: Li Chen <me@linux.beauty> --- drivers/nvdimm/nd_virtio.c | 15 +++++++++++---- drivers/nvdimm/virtio_pmem.c | 1 + drivers/nvdimm/virtio_pmem.h | 4 ++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/nvdimm/nd_virtio.c b/drivers/nvdimm/nd_virtio.c index c3f07be4aa22..827a17fe7c71 100644 --- a/drivers/nvdimm/nd_virtio.c +++ b/drivers/nvdimm/nd_virtio.c @@ -44,19 +44,24 @@ static int virtio_pmem_flush(struct nd_region *nd_region) unsigned long flags; int err, err1; + might_sleep(); + mutex_lock(&vpmem->flush_lock); + /* * Don't bother to submit the request to the device if the device is * not activated. */ if (vdev->config->get_status(vdev) & VIRTIO_CONFIG_S_NEEDS_RESET) { dev_info(&vdev->dev, "virtio pmem device needs a reset\n"); - return -EIO; + err = -EIO; + goto out_unlock; } - might_sleep(); req_data = kmalloc(sizeof(*req_data), GFP_KERNEL); - if (!req_data) - return -ENOMEM; + if (!req_data) { + err = -ENOMEM; + goto out_unlock; + } req_data->done = false; init_waitqueue_head(&req_data->host_acked); @@ -103,6 +108,8 @@ static int virtio_pmem_flush(struct nd_region *nd_region) } kfree(req_data); +out_unlock: + mutex_unlock(&vpmem->flush_lock); return err; }; diff --git a/drivers/nvdimm/virtio_pmem.c b/drivers/nvdimm/virtio_pmem.c index 2396d19ce549..77b196661905 100644 --- a/drivers/nvdimm/virtio_pmem.c +++ b/drivers/nvdimm/virtio_pmem.c @@ -64,6 +64,7 @@ static int virtio_pmem_probe(struct virtio_device *vdev) goto out_err; } + mutex_init(&vpmem->flush_lock); vpmem->vdev = vdev; vdev->priv = vpmem; err = init_vq(vpmem); diff --git a/drivers/nvdimm/virtio_pmem.h b/drivers/nvdimm/virtio_pmem.h index 0dddefe594c4..f72cf17f9518 100644 --- a/drivers/nvdimm/virtio_pmem.h +++ b/drivers/nvdimm/virtio_pmem.h @@ -13,6 +13,7 @@ #include <linux/module.h> #include <uapi/linux/virtio_pmem.h> #include <linux/libnvdimm.h> +#include <linux/mutex.h> #include <linux/spinlock.h> struct virtio_pmem_request { @@ -35,6 +36,9 @@ struct virtio_pmem { /* Virtio pmem request queue */ struct virtqueue *req_vq; + /* Serialize flush requests to the device. */ + struct mutex flush_lock; + /* nvdimm bus registers virtio pmem device */ struct nvdimm_bus *nvdimm_bus; struct nvdimm_bus_descriptor nd_desc; -- 2.52.0
On Fri, Jan 30, 2026 at 02:52:12PM -0600, Ira Weiny wrote: Do you, from code review, agree with the logic that it's racy right now? Whether the bug is reproducible isn't really the question.
{ "author": "\"Michael S. Tsirkin\" <mst@redhat.com>", "date": "Sat, 31 Jan 2026 12:47:15 -0500", "thread_id": "6980dc5569d5a_3430210092@iweiny-mobl.notmuch.mbox.gz" }
lkml
[PATCH] nvdimm: virtio_pmem: serialize flush requests
Under heavy concurrent flush traffic, virtio-pmem can overflow its request virtqueue (req_vq): virtqueue_add_sgs() starts returning -ENOSPC and the driver logs "no free slots in the virtqueue". Shortly after that the device enters VIRTIO_CONFIG_S_NEEDS_RESET and flush requests fail with "virtio pmem device needs a reset". Serialize virtio_pmem_flush() with a per-device mutex so only one flush request is in-flight at a time. This prevents req_vq descriptor overflow under high concurrency. Reproducer (guest with virtio-pmem): - mkfs.ext4 -F /dev/pmem0 - mount -t ext4 -o dax,noatime /dev/pmem0 /mnt/bench - fio: ioengine=io_uring rw=randwrite bs=4k iodepth=64 numjobs=64 direct=1 fsync=1 runtime=30s time_based=1 - dmesg: "no free slots in the virtqueue" "virtio pmem device needs a reset" Fixes: 6e84200c0a29 ("virtio-pmem: Add virtio pmem driver") Signed-off-by: Li Chen <me@linux.beauty> --- drivers/nvdimm/nd_virtio.c | 15 +++++++++++---- drivers/nvdimm/virtio_pmem.c | 1 + drivers/nvdimm/virtio_pmem.h | 4 ++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/nvdimm/nd_virtio.c b/drivers/nvdimm/nd_virtio.c index c3f07be4aa22..827a17fe7c71 100644 --- a/drivers/nvdimm/nd_virtio.c +++ b/drivers/nvdimm/nd_virtio.c @@ -44,19 +44,24 @@ static int virtio_pmem_flush(struct nd_region *nd_region) unsigned long flags; int err, err1; + might_sleep(); + mutex_lock(&vpmem->flush_lock); + /* * Don't bother to submit the request to the device if the device is * not activated. */ if (vdev->config->get_status(vdev) & VIRTIO_CONFIG_S_NEEDS_RESET) { dev_info(&vdev->dev, "virtio pmem device needs a reset\n"); - return -EIO; + err = -EIO; + goto out_unlock; } - might_sleep(); req_data = kmalloc(sizeof(*req_data), GFP_KERNEL); - if (!req_data) - return -ENOMEM; + if (!req_data) { + err = -ENOMEM; + goto out_unlock; + } req_data->done = false; init_waitqueue_head(&req_data->host_acked); @@ -103,6 +108,8 @@ static int virtio_pmem_flush(struct nd_region *nd_region) } kfree(req_data); +out_unlock: + mutex_unlock(&vpmem->flush_lock); return err; }; diff --git a/drivers/nvdimm/virtio_pmem.c b/drivers/nvdimm/virtio_pmem.c index 2396d19ce549..77b196661905 100644 --- a/drivers/nvdimm/virtio_pmem.c +++ b/drivers/nvdimm/virtio_pmem.c @@ -64,6 +64,7 @@ static int virtio_pmem_probe(struct virtio_device *vdev) goto out_err; } + mutex_init(&vpmem->flush_lock); vpmem->vdev = vdev; vdev->priv = vpmem; err = init_vq(vpmem); diff --git a/drivers/nvdimm/virtio_pmem.h b/drivers/nvdimm/virtio_pmem.h index 0dddefe594c4..f72cf17f9518 100644 --- a/drivers/nvdimm/virtio_pmem.h +++ b/drivers/nvdimm/virtio_pmem.h @@ -13,6 +13,7 @@ #include <linux/module.h> #include <uapi/linux/virtio_pmem.h> #include <linux/libnvdimm.h> +#include <linux/mutex.h> #include <linux/spinlock.h> struct virtio_pmem_request { @@ -35,6 +36,9 @@ struct virtio_pmem { /* Virtio pmem request queue */ struct virtqueue *req_vq; + /* Serialize flush requests to the device. */ + struct mutex flush_lock; + /* nvdimm bus registers virtio pmem device */ struct nvdimm_bus *nvdimm_bus; struct nvdimm_bus_descriptor nd_desc; -- 2.52.0
Hi Ira, On Sat, 31 Jan 2026 04:52:12 +0800, Ira Weiny wrote: Thanks for taking a look. I can reproduce the issue here, but it is timing dependent. A single fio run does not always hit it, so I suspect that's why you're not seeing the dmesg messages. Environment: QEMU: 10.1.2 virtio-pmem backend: memory-backend-ram (shared) The virtio-pmem relevant QEMU bits: -object memory-backend-ram,id=pmem0,size=10G,share=on -device virtio-pmem-pci,id=virtio-pmem0,memdev=pmem0 For completeness, this is the full QEMU command line I used (paths replaced with placeholders): qemu-system-x86_64 -enable-kvm -cpu host -smp 16 -m 10G,maxmem=20G \\ -netdev user,id=net0,hostfwd=tcp::<ssh_port>-:22 \\ -device virtio-net,netdev=net0 \\ -drive file=<guest.qcow2>,if=none,id=boot0,format=qcow2 \\ -device virtio-blk-pci,drive=boot0,num-queues=4 \\ -object memory-backend-ram,id=pmem0,size=10G,share=on \\ -device virtio-pmem-pci,id=virtio-pmem0,memdev=pmem0 \\ -nographic -kernel <bzImage> -append "<cmdline>" Kernel under test (baseline, no patch): v6.18-764-g7aa104c7e8e9 I used the same fio parameters from the cover letter. The only difference is that I run it in a loop so it has multiple chances to trigger. Each iteration does a fresh mkfs + mount and clears dmesg before running fio: This should be equivalent to the foo.fio you posted. for i in $(seq 1 10); do umount -l /mnt/bench 2>/dev/null || true mkfs.ext4 -F /dev/pmem0 mkdir -p /mnt/bench dmesg -C mount -t ext4 -o dax,noatime /dev/pmem0 /mnt/bench fio --name=randwrite_fsync --filename=/mnt/bench/foo --size=1G \\ --ioengine=io_uring --rw=randwrite --bs=4k --iodepth=64 --numjobs=64 \\ --direct=1 --fsync=1 --runtime=30 --time_based=1 dmesg | egrep -i \\ -e "no free slots in the virtqueue" \\ -e "virtio pmem device needs a reset" && break done If it does not trigger in 10 iterations, reboot the guest and repeat. On the baseline kernel, I see: "failed to send command to virtio pmem device, no free slots in the virtqueue" and "virtio pmem device needs a reset" Typically within a few iterations (often on the first one). With the fix applied, I ran 10 iterations back-to-back and did not see the above messages. Agreed. I'll use guard in v2. I did a quick sanity check. With a smaller numjobs value (numjobs=16, iodepth=64, fsync=1, bs=4k, runtime=30s), I did not see a regression on this setup. At numjobs=64 the baseline frequently hits NEEDS_RESET, so correctness is the primary motivation here. Regards, Li​
{ "author": "Li Chen <me@linux.beauty>", "date": "Sun, 01 Feb 2026 12:21:42 +0800", "thread_id": "6980dc5569d5a_3430210092@iweiny-mobl.notmuch.mbox.gz" }
lkml
[PATCH] nvdimm: virtio_pmem: serialize flush requests
Under heavy concurrent flush traffic, virtio-pmem can overflow its request virtqueue (req_vq): virtqueue_add_sgs() starts returning -ENOSPC and the driver logs "no free slots in the virtqueue". Shortly after that the device enters VIRTIO_CONFIG_S_NEEDS_RESET and flush requests fail with "virtio pmem device needs a reset". Serialize virtio_pmem_flush() with a per-device mutex so only one flush request is in-flight at a time. This prevents req_vq descriptor overflow under high concurrency. Reproducer (guest with virtio-pmem): - mkfs.ext4 -F /dev/pmem0 - mount -t ext4 -o dax,noatime /dev/pmem0 /mnt/bench - fio: ioengine=io_uring rw=randwrite bs=4k iodepth=64 numjobs=64 direct=1 fsync=1 runtime=30s time_based=1 - dmesg: "no free slots in the virtqueue" "virtio pmem device needs a reset" Fixes: 6e84200c0a29 ("virtio-pmem: Add virtio pmem driver") Signed-off-by: Li Chen <me@linux.beauty> --- drivers/nvdimm/nd_virtio.c | 15 +++++++++++---- drivers/nvdimm/virtio_pmem.c | 1 + drivers/nvdimm/virtio_pmem.h | 4 ++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/nvdimm/nd_virtio.c b/drivers/nvdimm/nd_virtio.c index c3f07be4aa22..827a17fe7c71 100644 --- a/drivers/nvdimm/nd_virtio.c +++ b/drivers/nvdimm/nd_virtio.c @@ -44,19 +44,24 @@ static int virtio_pmem_flush(struct nd_region *nd_region) unsigned long flags; int err, err1; + might_sleep(); + mutex_lock(&vpmem->flush_lock); + /* * Don't bother to submit the request to the device if the device is * not activated. */ if (vdev->config->get_status(vdev) & VIRTIO_CONFIG_S_NEEDS_RESET) { dev_info(&vdev->dev, "virtio pmem device needs a reset\n"); - return -EIO; + err = -EIO; + goto out_unlock; } - might_sleep(); req_data = kmalloc(sizeof(*req_data), GFP_KERNEL); - if (!req_data) - return -ENOMEM; + if (!req_data) { + err = -ENOMEM; + goto out_unlock; + } req_data->done = false; init_waitqueue_head(&req_data->host_acked); @@ -103,6 +108,8 @@ static int virtio_pmem_flush(struct nd_region *nd_region) } kfree(req_data); +out_unlock: + mutex_unlock(&vpmem->flush_lock); return err; }; diff --git a/drivers/nvdimm/virtio_pmem.c b/drivers/nvdimm/virtio_pmem.c index 2396d19ce549..77b196661905 100644 --- a/drivers/nvdimm/virtio_pmem.c +++ b/drivers/nvdimm/virtio_pmem.c @@ -64,6 +64,7 @@ static int virtio_pmem_probe(struct virtio_device *vdev) goto out_err; } + mutex_init(&vpmem->flush_lock); vpmem->vdev = vdev; vdev->priv = vpmem; err = init_vq(vpmem); diff --git a/drivers/nvdimm/virtio_pmem.h b/drivers/nvdimm/virtio_pmem.h index 0dddefe594c4..f72cf17f9518 100644 --- a/drivers/nvdimm/virtio_pmem.h +++ b/drivers/nvdimm/virtio_pmem.h @@ -13,6 +13,7 @@ #include <linux/module.h> #include <uapi/linux/virtio_pmem.h> #include <linux/libnvdimm.h> +#include <linux/mutex.h> #include <linux/spinlock.h> struct virtio_pmem_request { @@ -35,6 +36,9 @@ struct virtio_pmem { /* Virtio pmem request queue */ struct virtqueue *req_vq; + /* Serialize flush requests to the device. */ + struct mutex flush_lock; + /* nvdimm bus registers virtio pmem device */ struct nvdimm_bus *nvdimm_bus; struct nvdimm_bus_descriptor nd_desc; -- 2.52.0
Hi Michael, On Sun, 01 Feb 2026 01:46:19 +0800, Michael S. Tsirkin wrote: Good point. mutex_lock() already does might_sleep(), so the explicit might_sleep() next to the lock is redundant. I'll drop it in v2 (which also switches to guard(mutex) as Ira suggested). Regards, Li
{ "author": "Li Chen <me@linux.beauty>", "date": "Sun, 01 Feb 2026 12:40:15 +0800", "thread_id": "6980dc5569d5a_3430210092@iweiny-mobl.notmuch.mbox.gz" }
lkml
[PATCH] nvdimm: virtio_pmem: serialize flush requests
Under heavy concurrent flush traffic, virtio-pmem can overflow its request virtqueue (req_vq): virtqueue_add_sgs() starts returning -ENOSPC and the driver logs "no free slots in the virtqueue". Shortly after that the device enters VIRTIO_CONFIG_S_NEEDS_RESET and flush requests fail with "virtio pmem device needs a reset". Serialize virtio_pmem_flush() with a per-device mutex so only one flush request is in-flight at a time. This prevents req_vq descriptor overflow under high concurrency. Reproducer (guest with virtio-pmem): - mkfs.ext4 -F /dev/pmem0 - mount -t ext4 -o dax,noatime /dev/pmem0 /mnt/bench - fio: ioengine=io_uring rw=randwrite bs=4k iodepth=64 numjobs=64 direct=1 fsync=1 runtime=30s time_based=1 - dmesg: "no free slots in the virtqueue" "virtio pmem device needs a reset" Fixes: 6e84200c0a29 ("virtio-pmem: Add virtio pmem driver") Signed-off-by: Li Chen <me@linux.beauty> --- drivers/nvdimm/nd_virtio.c | 15 +++++++++++---- drivers/nvdimm/virtio_pmem.c | 1 + drivers/nvdimm/virtio_pmem.h | 4 ++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/nvdimm/nd_virtio.c b/drivers/nvdimm/nd_virtio.c index c3f07be4aa22..827a17fe7c71 100644 --- a/drivers/nvdimm/nd_virtio.c +++ b/drivers/nvdimm/nd_virtio.c @@ -44,19 +44,24 @@ static int virtio_pmem_flush(struct nd_region *nd_region) unsigned long flags; int err, err1; + might_sleep(); + mutex_lock(&vpmem->flush_lock); + /* * Don't bother to submit the request to the device if the device is * not activated. */ if (vdev->config->get_status(vdev) & VIRTIO_CONFIG_S_NEEDS_RESET) { dev_info(&vdev->dev, "virtio pmem device needs a reset\n"); - return -EIO; + err = -EIO; + goto out_unlock; } - might_sleep(); req_data = kmalloc(sizeof(*req_data), GFP_KERNEL); - if (!req_data) - return -ENOMEM; + if (!req_data) { + err = -ENOMEM; + goto out_unlock; + } req_data->done = false; init_waitqueue_head(&req_data->host_acked); @@ -103,6 +108,8 @@ static int virtio_pmem_flush(struct nd_region *nd_region) } kfree(req_data); +out_unlock: + mutex_unlock(&vpmem->flush_lock); return err; }; diff --git a/drivers/nvdimm/virtio_pmem.c b/drivers/nvdimm/virtio_pmem.c index 2396d19ce549..77b196661905 100644 --- a/drivers/nvdimm/virtio_pmem.c +++ b/drivers/nvdimm/virtio_pmem.c @@ -64,6 +64,7 @@ static int virtio_pmem_probe(struct virtio_device *vdev) goto out_err; } + mutex_init(&vpmem->flush_lock); vpmem->vdev = vdev; vdev->priv = vpmem; err = init_vq(vpmem); diff --git a/drivers/nvdimm/virtio_pmem.h b/drivers/nvdimm/virtio_pmem.h index 0dddefe594c4..f72cf17f9518 100644 --- a/drivers/nvdimm/virtio_pmem.h +++ b/drivers/nvdimm/virtio_pmem.h @@ -13,6 +13,7 @@ #include <linux/module.h> #include <uapi/linux/virtio_pmem.h> #include <linux/libnvdimm.h> +#include <linux/mutex.h> #include <linux/spinlock.h> struct virtio_pmem_request { @@ -35,6 +36,9 @@ struct virtio_pmem { /* Virtio pmem request queue */ struct virtqueue *req_vq; + /* Serialize flush requests to the device. */ + struct mutex flush_lock; + /* nvdimm bus registers virtio pmem device */ struct nvdimm_bus *nvdimm_bus; struct nvdimm_bus_descriptor nd_desc; -- 2.52.0
Michael S. Tsirkin wrote: [snip] I do now. I was hoping to understand the test being run. The additional detail that it takes multiple runs helps. True. But we should still use guard(). I'll look for v2. Ira
{ "author": "Ira Weiny <ira.weiny@intel.com>", "date": "Mon, 2 Feb 2026 11:18:13 -0600", "thread_id": "6980dc5569d5a_3430210092@iweiny-mobl.notmuch.mbox.gz" }
lkml
[PATCH 0/4] ASoC: ti: davinci-mcasp: Add asynchronous mode support for McASP
This series adds asynchronous mode support to the McASP driver, which enables independent configuration of bitclocks, frame sync, and audio configurations between tx(playback) and rx(record). And achieves simultaneous playback & record using different audio configurations. It also adds two clean up patches to the McASP driver that disambiguate and simplifies the logic which avoids the async enhancement from being too convoluted to review and analyze. The implementation is based on vendor documentation and patches tested in both SK-AM62P-LP (sync mode, McASP slave) and AM62D-EVM (async mode, McASP master, rx & tx has different TDM configs). Testing verifies async mode functionality while maintaining backward compatibility with the default sync mode. Bootlog and Async mode tests on AM62D-EVM: [0] [0]: https://gist.github.com/SenWang125/f31f9172b186d414695e37c8b9ef127d Signed-off-by: Sen Wang <sen@ti.com> Sen Wang (4): dt-bindings: sound: davinci-mcasp: Add optional properties for asynchronous mode ASoC: ti: davinci-mcasp: Disambiguate mcasp_is_synchronous function ASoC: ti: davinci-mcasp: Streamline pdir behavior across rx & tx streams ASoC: ti: davinci-mcasp: Add asynchronous mode support .../bindings/sound/davinci-mcasp-audio.yaml | 71 ++- include/linux/platform_data/davinci_asp.h | 3 +- sound/soc/ti/davinci-mcasp.c | 510 ++++++++++++++---- sound/soc/ti/davinci-mcasp.h | 10 + 4 files changed, 479 insertions(+), 115 deletions(-) base-commit: dbf8fe85a16a33d6b6bd01f2bc606fc017771465 -- 2.43.0
Simplify the mcasp_set_clk_pdir caller convention in start/stop stream function, to make it so that set_clk_pdir gets called regardless when stream starts and also disables when stream ends. Functionality-wise, everything remains the same as the previously skipped calls are now either correctly configured (when McASP is SND_SOC_DAIFMT_BP_FC - pdir needs to be enabled) or called with a bitmask of zero (when McASP is SND_SOC_DAIFMT_BC_FC - pdir gets disabled). On brief regarding McASP Clock and Frame sync configurations, refer to [0]. [0]:TRM Section 12.1.1.4.2 https://www.ti.com/lit/ug/sprujd4a/sprujd4a.pdf Signed-off-by: Sen Wang <sen@ti.com> --- sound/soc/ti/davinci-mcasp.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sound/soc/ti/davinci-mcasp.c b/sound/soc/ti/davinci-mcasp.c index aa14fc1c8011..4f8a2ce6ce78 100644 --- a/sound/soc/ti/davinci-mcasp.c +++ b/sound/soc/ti/davinci-mcasp.c @@ -235,8 +235,8 @@ static void mcasp_start_rx(struct davinci_mcasp *mcasp) if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp)) { mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXHCLKRST); mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST); - mcasp_set_clk_pdir(mcasp, true); } + mcasp_set_clk_pdir(mcasp, true); /* Activate serializer(s) */ mcasp_set_reg(mcasp, DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF); @@ -311,10 +311,10 @@ static void mcasp_stop_rx(struct davinci_mcasp *mcasp) * In synchronous mode stop the TX clocks if no other stream is * running */ - if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp) && !mcasp->streams) { - mcasp_set_clk_pdir(mcasp, false); + if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp) && !mcasp->streams) mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, 0); - } + if (!mcasp->streams) + mcasp_set_clk_pdir(mcasp, false); mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, 0); mcasp_set_reg(mcasp, DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF); @@ -340,7 +340,7 @@ static void mcasp_stop_tx(struct davinci_mcasp *mcasp) */ if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp) && mcasp->streams) val = TXHCLKRST | TXCLKRST | TXFSRST; - else + if (!mcasp->streams) mcasp_set_clk_pdir(mcasp, false); -- 2.43.0
{ "author": "Sen Wang <sen@ti.com>", "date": "Thu, 29 Jan 2026 23:10:43 -0600", "thread_id": "20260130051045.1898892-1-sen@ti.com.mbox.gz" }
lkml
[PATCH 0/4] ASoC: ti: davinci-mcasp: Add asynchronous mode support for McASP
This series adds asynchronous mode support to the McASP driver, which enables independent configuration of bitclocks, frame sync, and audio configurations between tx(playback) and rx(record). And achieves simultaneous playback & record using different audio configurations. It also adds two clean up patches to the McASP driver that disambiguate and simplifies the logic which avoids the async enhancement from being too convoluted to review and analyze. The implementation is based on vendor documentation and patches tested in both SK-AM62P-LP (sync mode, McASP slave) and AM62D-EVM (async mode, McASP master, rx & tx has different TDM configs). Testing verifies async mode functionality while maintaining backward compatibility with the default sync mode. Bootlog and Async mode tests on AM62D-EVM: [0] [0]: https://gist.github.com/SenWang125/f31f9172b186d414695e37c8b9ef127d Signed-off-by: Sen Wang <sen@ti.com> Sen Wang (4): dt-bindings: sound: davinci-mcasp: Add optional properties for asynchronous mode ASoC: ti: davinci-mcasp: Disambiguate mcasp_is_synchronous function ASoC: ti: davinci-mcasp: Streamline pdir behavior across rx & tx streams ASoC: ti: davinci-mcasp: Add asynchronous mode support .../bindings/sound/davinci-mcasp-audio.yaml | 71 ++- include/linux/platform_data/davinci_asp.h | 3 +- sound/soc/ti/davinci-mcasp.c | 510 ++++++++++++++---- sound/soc/ti/davinci-mcasp.h | 10 + 4 files changed, 479 insertions(+), 115 deletions(-) base-commit: dbf8fe85a16a33d6b6bd01f2bc606fc017771465 -- 2.43.0
The current mcasp_is_synchronous() function does more than what it proclaims, it also checks if McASP is a frame producer. Therefore split the original function into two separate ones and replace all occurrences with the new equivalent logic. So the functions can be re-used when checking async/sync status in light of async mode enhancements. Signed-off-by: Sen Wang <sen@ti.com> --- sound/soc/ti/davinci-mcasp.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/sound/soc/ti/davinci-mcasp.c b/sound/soc/ti/davinci-mcasp.c index 621a9d5f9377..aa14fc1c8011 100644 --- a/sound/soc/ti/davinci-mcasp.c +++ b/sound/soc/ti/davinci-mcasp.c @@ -179,10 +179,16 @@ static void mcasp_set_ctl_reg(struct davinci_mcasp *mcasp, u32 ctl_reg, u32 val) static bool mcasp_is_synchronous(struct davinci_mcasp *mcasp) { - u32 rxfmctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_RXFMCTL_REG); u32 aclkxctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_ACLKXCTL_REG); - return !(aclkxctl & TX_ASYNC) && rxfmctl & AFSRE; + return !(aclkxctl & TX_ASYNC); +} + +static bool mcasp_is_frame_producer(struct davinci_mcasp *mcasp) +{ + u32 rxfmctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_RXFMCTL_REG); + + return rxfmctl & AFSRE; } static inline void mcasp_set_clk_pdir(struct davinci_mcasp *mcasp, bool enable) @@ -226,7 +232,7 @@ static void mcasp_start_rx(struct davinci_mcasp *mcasp) * synchronously from the transmit clock and frame sync. We need to make * sure that the TX signlas are enabled when starting reception. */ - if (mcasp_is_synchronous(mcasp)) { + if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp)) { mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXHCLKRST); mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST); mcasp_set_clk_pdir(mcasp, true); @@ -239,7 +245,7 @@ static void mcasp_start_rx(struct davinci_mcasp *mcasp) mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXSMRST); /* Release Frame Sync generator */ mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXFSRST); - if (mcasp_is_synchronous(mcasp)) + if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp)) mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXFSRST); /* enable receive IRQs */ @@ -305,7 +311,7 @@ static void mcasp_stop_rx(struct davinci_mcasp *mcasp) * In synchronous mode stop the TX clocks if no other stream is * running */ - if (mcasp_is_synchronous(mcasp) && !mcasp->streams) { + if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp) && !mcasp->streams) { mcasp_set_clk_pdir(mcasp, false); mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, 0); } @@ -332,7 +338,7 @@ static void mcasp_stop_tx(struct davinci_mcasp *mcasp) * In synchronous mode keep TX clocks running if the capture stream is * still running. */ - if (mcasp_is_synchronous(mcasp) && mcasp->streams) + if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp) && mcasp->streams) val = TXHCLKRST | TXCLKRST | TXFSRST; else mcasp_set_clk_pdir(mcasp, false); @@ -1041,7 +1047,8 @@ static int mcasp_i2s_hw_param(struct davinci_mcasp *mcasp, int stream, * not running already we need to configure the TX slots in * order to have correct FSX on the bus */ - if (mcasp_is_synchronous(mcasp) && !mcasp->channels) + if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp) && + !mcasp->channels) mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, FSXMOD(total_slots), FSXMOD(0x1FF)); } -- 2.43.0
{ "author": "Sen Wang <sen@ti.com>", "date": "Thu, 29 Jan 2026 23:10:42 -0600", "thread_id": "20260130051045.1898892-1-sen@ti.com.mbox.gz" }
lkml
[PATCH 0/4] ASoC: ti: davinci-mcasp: Add asynchronous mode support for McASP
This series adds asynchronous mode support to the McASP driver, which enables independent configuration of bitclocks, frame sync, and audio configurations between tx(playback) and rx(record). And achieves simultaneous playback & record using different audio configurations. It also adds two clean up patches to the McASP driver that disambiguate and simplifies the logic which avoids the async enhancement from being too convoluted to review and analyze. The implementation is based on vendor documentation and patches tested in both SK-AM62P-LP (sync mode, McASP slave) and AM62D-EVM (async mode, McASP master, rx & tx has different TDM configs). Testing verifies async mode functionality while maintaining backward compatibility with the default sync mode. Bootlog and Async mode tests on AM62D-EVM: [0] [0]: https://gist.github.com/SenWang125/f31f9172b186d414695e37c8b9ef127d Signed-off-by: Sen Wang <sen@ti.com> Sen Wang (4): dt-bindings: sound: davinci-mcasp: Add optional properties for asynchronous mode ASoC: ti: davinci-mcasp: Disambiguate mcasp_is_synchronous function ASoC: ti: davinci-mcasp: Streamline pdir behavior across rx & tx streams ASoC: ti: davinci-mcasp: Add asynchronous mode support .../bindings/sound/davinci-mcasp-audio.yaml | 71 ++- include/linux/platform_data/davinci_asp.h | 3 +- sound/soc/ti/davinci-mcasp.c | 510 ++++++++++++++---- sound/soc/ti/davinci-mcasp.h | 10 + 4 files changed, 479 insertions(+), 115 deletions(-) base-commit: dbf8fe85a16a33d6b6bd01f2bc606fc017771465 -- 2.43.0
McASP supports the independent configuration of TX & RX clk and frame sync registers. By default, the driver is configured in synchronous mode where RX clock generator is disabled and it uses transmit clock signals as bit clock and frame sync. Therefore add optional properties needed for asynchronous mode. Add ti,async-mode boolean binding to provide a way to decouple the default behavior and allows for independent TX & RX clocking. Add tdm-slots-rx uint32 binding to provide an alternative hardware specifier stating the number of RX serializers. The existing property tdm-slots will still dictate number of TX serializers, and RX if tdm-slots-rx isn't given for backwards compatibility. Add auxclk-fs-ratio-rx which allows to specify the ratio just for RX. The driver can be supplied with two different ratios (auxclk-fs-ratio and auxclk-fs-ratio-rx in tandem) and achieve two different sampling rates for tx & rx. Signed-off-by: Sen Wang <sen@ti.com> --- .../bindings/sound/davinci-mcasp-audio.yaml | 71 +++++++++++++++++-- 1 file changed, 66 insertions(+), 5 deletions(-) diff --git a/Documentation/devicetree/bindings/sound/davinci-mcasp-audio.yaml b/Documentation/devicetree/bindings/sound/davinci-mcasp-audio.yaml index beef193aaaeb..87559d0d079a 100644 --- a/Documentation/devicetree/bindings/sound/davinci-mcasp-audio.yaml +++ b/Documentation/devicetree/bindings/sound/davinci-mcasp-audio.yaml @@ -40,11 +40,33 @@ properties: tdm-slots: $ref: /schemas/types.yaml#/definitions/uint32 description: - number of channels over one serializer - the property is ignored in DIT mode + Number of channels over one serializer. This property + specifies the TX playback TDM slot count, along with default RX slot count + if tdm-slots-rx is not specified. + The property is ignored in DIT mode. minimum: 2 maximum: 32 + tdm-slots-rx: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Number of RX capture channels over one serializer. If specified, + allows independent RX TDM slot count separate from TX. Requires + ti,async-mode to be enabled for independent TX/RX clock rates. + The property is ignored in DIT mode. + minimum: 2 + maximum: 32 + + ti,async-mode: + description: + Specify to allow independent TX & RX clocking, + to enable audio playback & record with different sampling rate, + and different number of bits per frame. + if property is omitted, TX and RX will share same bit clock and frame clock signals, + thus RX need to use same bits per frame and sampling rate as TX in synchronous mode. + the property is ignored in DIT mode (as DIT is TX-only) + type: boolean + serial-dir: description: A list of serializer configuration @@ -125,7 +147,21 @@ properties: auxclk-fs-ratio: $ref: /schemas/types.yaml#/definitions/uint32 - description: ratio of AUCLK and FS rate if applicable + description: + Ratio of AUCLK and FS rate if applicable. This property specifies + the TX ratio, along with default RX ratio if auxclk-fs-ratio-rx + is not specified. + When not specified, the inputted system clock frequency via set_sysclk + callback by the machine driver is used for divider calculation. + + auxclk-fs-ratio-rx: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Ratio of AUCLK and FS rate for RX. If specified, allows + for a different RX ratio. Requires ti,async-mode to be + enabled when the ratio differs from auxclk-fs-ratio. + When not specified, it defaults to the value of auxclk-fs-ratio. + The property is ignored in DIT mode. gpio-controller: true @@ -170,14 +206,38 @@ allOf: - $ref: dai-common.yaml# - if: properties: - opmode: + op-mode: enum: - 0 - then: required: - tdm-slots + - if: + properties: + op-mode: + const: 1 + then: + properties: + tdm-slots: false + tdm-slots-rx: false + ti,async-mode: false + auxclk-fs-ratio-rx: false + + - if: + required: + - tdm-slots-rx + then: + required: + - ti,async-mode + + - if: + required: + - auxclk-fs-ratio-rx + then: + required: + - ti,async-mode + unevaluatedProperties: false examples: @@ -190,6 +250,7 @@ examples: interrupt-names = "tx", "rx"; op-mode = <0>; /* MCASP_IIS_MODE */ tdm-slots = <2>; + ti,async-mode; dmas = <&main_udmap 0xc400>, <&main_udmap 0x4400>; dma-names = "tx", "rx"; serial-dir = < -- 2.43.0
{ "author": "Sen Wang <sen@ti.com>", "date": "Thu, 29 Jan 2026 23:10:41 -0600", "thread_id": "20260130051045.1898892-1-sen@ti.com.mbox.gz" }
lkml
[PATCH 0/4] ASoC: ti: davinci-mcasp: Add asynchronous mode support for McASP
This series adds asynchronous mode support to the McASP driver, which enables independent configuration of bitclocks, frame sync, and audio configurations between tx(playback) and rx(record). And achieves simultaneous playback & record using different audio configurations. It also adds two clean up patches to the McASP driver that disambiguate and simplifies the logic which avoids the async enhancement from being too convoluted to review and analyze. The implementation is based on vendor documentation and patches tested in both SK-AM62P-LP (sync mode, McASP slave) and AM62D-EVM (async mode, McASP master, rx & tx has different TDM configs). Testing verifies async mode functionality while maintaining backward compatibility with the default sync mode. Bootlog and Async mode tests on AM62D-EVM: [0] [0]: https://gist.github.com/SenWang125/f31f9172b186d414695e37c8b9ef127d Signed-off-by: Sen Wang <sen@ti.com> Sen Wang (4): dt-bindings: sound: davinci-mcasp: Add optional properties for asynchronous mode ASoC: ti: davinci-mcasp: Disambiguate mcasp_is_synchronous function ASoC: ti: davinci-mcasp: Streamline pdir behavior across rx & tx streams ASoC: ti: davinci-mcasp: Add asynchronous mode support .../bindings/sound/davinci-mcasp-audio.yaml | 71 ++- include/linux/platform_data/davinci_asp.h | 3 +- sound/soc/ti/davinci-mcasp.c | 510 ++++++++++++++---- sound/soc/ti/davinci-mcasp.h | 10 + 4 files changed, 479 insertions(+), 115 deletions(-) base-commit: dbf8fe85a16a33d6b6bd01f2bc606fc017771465 -- 2.43.0
McASP has dedicated clock & frame sync registers for both transmit and receive. Currently McASP driver only supports synchronous behavior and couples both TX & RX settings. Add logic that enables asynchronous mode via ti,async-mode property. In async mode, playback & record can be done simultaneously with different audio configurations (tdm slots, tdm width, audio bit depth). Note the ability to have different tx/rx DSP formats (i2s, dsp_a, etc.), while possible in hardware, remains to be a gap as it require changes to the corresponding machine driver interface. Existing IIS (sync mode) and DIT mode logic remains mostly unchanged. Exceptions are IIS mode logic that previously assumed sync mode, which has now been made aware of the distinction. And shared logic across all modes also now checks for McASP tx/rx-specific driver attributes. Those attributes have been populated according to the original extent, ensuring no divergence in functionality. Constraints no longer applicable for async mode are skipped. Clock selection options have also been added to include rx/tx-only clk_ids, exposing independent configuration via the machine driver as well. Note that asynchronous mode is not applicable for McASP in DIT mode, which is a transmitter-only mode to interface w/ self-clocking formats. Signed-off-by: Sen Wang <sen@ti.com> --- include/linux/platform_data/davinci_asp.h | 3 +- sound/soc/ti/davinci-mcasp.c | 487 +++++++++++++++++----- sound/soc/ti/davinci-mcasp.h | 10 + 3 files changed, 398 insertions(+), 102 deletions(-) diff --git a/include/linux/platform_data/davinci_asp.h b/include/linux/platform_data/davinci_asp.h index b9c8520b4bd3..509c5592aab0 100644 --- a/include/linux/platform_data/davinci_asp.h +++ b/include/linux/platform_data/davinci_asp.h @@ -59,7 +59,8 @@ struct davinci_mcasp_pdata { bool i2s_accurate_sck; /* McASP specific fields */ - int tdm_slots; + int tdm_slots_tx; + int tdm_slots_rx; u8 op_mode; u8 dismod; u8 num_serializer; diff --git a/sound/soc/ti/davinci-mcasp.c b/sound/soc/ti/davinci-mcasp.c index 4f8a2ce6ce78..ef7fa23d30bf 100644 --- a/sound/soc/ti/davinci-mcasp.c +++ b/sound/soc/ti/davinci-mcasp.c @@ -70,6 +70,7 @@ struct davinci_mcasp_context { struct davinci_mcasp_ruledata { struct davinci_mcasp *mcasp; int serializers; + int stream; }; struct davinci_mcasp { @@ -87,21 +88,27 @@ struct davinci_mcasp { bool missing_audio_param; /* McASP specific data */ - int tdm_slots; + int tdm_slots_tx; + int tdm_slots_rx; u32 tdm_mask[2]; - int slot_width; + int slot_width_tx; + int slot_width_rx; u8 op_mode; u8 dismod; u8 num_serializer; u8 *serial_dir; u8 version; - u8 bclk_div; + u8 bclk_div_tx; + u8 bclk_div_rx; int streams; u32 irq_request[2]; - int sysclk_freq; + unsigned int sysclk_freq_tx; + unsigned int sysclk_freq_rx; bool bclk_master; - u32 auxclk_fs_ratio; + bool async_mode; + u32 auxclk_fs_ratio_tx; + u32 auxclk_fs_ratio_rx; unsigned long pdir; /* Pin direction bitfield */ @@ -203,6 +210,27 @@ static inline void mcasp_set_clk_pdir(struct davinci_mcasp *mcasp, bool enable) } } +static inline void mcasp_set_clk_pdir_stream(struct davinci_mcasp *mcasp, + int stream, bool enable) +{ + u32 bit, bit_end; + + if (stream == SNDRV_PCM_STREAM_PLAYBACK) { + bit = PIN_BIT_ACLKX; + bit_end = PIN_BIT_AFSX + 1; + } else { + bit = PIN_BIT_ACLKR; + bit_end = PIN_BIT_AFSR + 1; + } + + for_each_set_bit_from(bit, &mcasp->pdir, bit_end) { + if (enable) + mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, BIT(bit)); + else + mcasp_clr_bits(mcasp, DAVINCI_MCASP_PDIR_REG, BIT(bit)); + } +} + static inline void mcasp_set_axr_pdir(struct davinci_mcasp *mcasp, bool enable) { u32 bit; @@ -215,6 +243,36 @@ static inline void mcasp_set_axr_pdir(struct davinci_mcasp *mcasp, bool enable) } } +static inline int mcasp_get_tdm_slots(struct davinci_mcasp *mcasp, int stream) +{ + return (stream == SNDRV_PCM_STREAM_PLAYBACK) ? + mcasp->tdm_slots_tx : mcasp->tdm_slots_rx; +} + +static inline int mcasp_get_slot_width(struct davinci_mcasp *mcasp, int stream) +{ + return (stream == SNDRV_PCM_STREAM_PLAYBACK) ? + mcasp->slot_width_tx : mcasp->slot_width_rx; +} + +static inline unsigned int mcasp_get_sysclk_freq(struct davinci_mcasp *mcasp, int stream) +{ + return (stream == SNDRV_PCM_STREAM_PLAYBACK) ? + mcasp->sysclk_freq_tx : mcasp->sysclk_freq_rx; +} + +static inline unsigned int mcasp_get_bclk_div(struct davinci_mcasp *mcasp, int stream) +{ + return (stream == SNDRV_PCM_STREAM_PLAYBACK) ? + mcasp->bclk_div_tx : mcasp->bclk_div_rx; +} + +static inline unsigned int mcasp_get_auxclk_fs_ratio(struct davinci_mcasp *mcasp, int stream) +{ + return (stream == SNDRV_PCM_STREAM_PLAYBACK) ? + mcasp->auxclk_fs_ratio_tx : mcasp->auxclk_fs_ratio_rx; +} + static void mcasp_start_rx(struct davinci_mcasp *mcasp) { if (mcasp->rxnumevt) { /* enable FIFO */ @@ -230,13 +288,17 @@ static void mcasp_start_rx(struct davinci_mcasp *mcasp) /* * When ASYNC == 0 the transmit and receive sections operate * synchronously from the transmit clock and frame sync. We need to make - * sure that the TX signlas are enabled when starting reception. + * sure that the TX signals are enabled when starting reception. + * Else set pin to be output when McASP is the master */ if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp)) { mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXHCLKRST); mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST); } - mcasp_set_clk_pdir(mcasp, true); + if (mcasp_is_synchronous(mcasp)) + mcasp_set_clk_pdir(mcasp, true); + else + mcasp_set_clk_pdir_stream(mcasp, SNDRV_PCM_STREAM_CAPTURE, true); /* Activate serializer(s) */ mcasp_set_reg(mcasp, DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF); @@ -267,7 +329,10 @@ static void mcasp_start_tx(struct davinci_mcasp *mcasp) /* Start clocks */ mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXHCLKRST); mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST); - mcasp_set_clk_pdir(mcasp, true); + if (mcasp_is_synchronous(mcasp)) + mcasp_set_clk_pdir(mcasp, true); + else + mcasp_set_clk_pdir_stream(mcasp, SNDRV_PCM_STREAM_PLAYBACK, true); /* Activate serializer(s) */ mcasp_set_reg(mcasp, DAVINCI_MCASP_TXSTAT_REG, 0xFFFFFFFF); @@ -310,11 +375,14 @@ static void mcasp_stop_rx(struct davinci_mcasp *mcasp) /* * In synchronous mode stop the TX clocks if no other stream is * running + * Otherwise in async mode only stop RX clocks */ if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp) && !mcasp->streams) mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, 0); - if (!mcasp->streams) + if (mcasp_is_synchronous(mcasp) && !mcasp->streams) mcasp_set_clk_pdir(mcasp, false); + else if (!mcasp_is_synchronous(mcasp)) + mcasp_set_clk_pdir_stream(mcasp, SNDRV_PCM_STREAM_CAPTURE, false); mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, 0); mcasp_set_reg(mcasp, DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF); @@ -337,11 +405,14 @@ static void mcasp_stop_tx(struct davinci_mcasp *mcasp) /* * In synchronous mode keep TX clocks running if the capture stream is * still running. + * Otherwise in async mode only stop TX clocks */ if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp) && mcasp->streams) val = TXHCLKRST | TXCLKRST | TXFSRST; - if (!mcasp->streams) + if (mcasp_is_synchronous(mcasp) && !mcasp->streams) mcasp_set_clk_pdir(mcasp, false); + else if (!mcasp_is_synchronous(mcasp)) + mcasp_set_clk_pdir_stream(mcasp, SNDRV_PCM_STREAM_PLAYBACK, false); mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, val); @@ -353,7 +424,8 @@ static void mcasp_stop_tx(struct davinci_mcasp *mcasp) mcasp_clr_bits(mcasp, reg, FIFO_ENABLE); } - mcasp_set_axr_pdir(mcasp, false); + if (!mcasp->streams) + mcasp_set_axr_pdir(mcasp, false); } static void davinci_mcasp_stop(struct davinci_mcasp *mcasp, int stream) @@ -625,13 +697,39 @@ static int __davinci_mcasp_set_clkdiv(struct davinci_mcasp *mcasp, int div_id, AHCLKRDIV(div - 1), AHCLKRDIV_MASK); break; + case MCASP_CLKDIV_AUXCLK_TXONLY: /* MCLK divider for TX only */ + mcasp_mod_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, + AHCLKXDIV(div - 1), AHCLKXDIV_MASK); + break; + + case MCASP_CLKDIV_AUXCLK_RXONLY: /* MCLK divider for RX only */ + mcasp_mod_bits(mcasp, DAVINCI_MCASP_AHCLKRCTL_REG, + AHCLKRDIV(div - 1), AHCLKRDIV_MASK); + break; + case MCASP_CLKDIV_BCLK: /* BCLK divider */ mcasp_mod_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXDIV(div - 1), ACLKXDIV_MASK); + mcasp_mod_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, + ACLKRDIV(div - 1), ACLKRDIV_MASK); + if (explicit) { + mcasp->bclk_div_tx = div; + mcasp->bclk_div_rx = div; + } + break; + + case MCASP_CLKDIV_BCLK_TXONLY: /* BCLK divider for TX only */ + mcasp_mod_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, + ACLKXDIV(div - 1), ACLKXDIV_MASK); + if (explicit) + mcasp->bclk_div_tx = div; + break; + + case MCASP_CLKDIV_BCLK_RXONLY: /* BCLK divider for RX only */ mcasp_mod_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, ACLKRDIV(div - 1), ACLKRDIV_MASK); if (explicit) - mcasp->bclk_div = div; + mcasp->bclk_div_rx = div; break; case MCASP_CLKDIV_BCLK_FS_RATIO: @@ -645,11 +743,33 @@ static int __davinci_mcasp_set_clkdiv(struct davinci_mcasp *mcasp, int div_id, * tdm_slot width by dividing the ratio by the * number of configured tdm slots. */ - mcasp->slot_width = div / mcasp->tdm_slots; - if (div % mcasp->tdm_slots) + mcasp->slot_width_tx = div / mcasp->tdm_slots_tx; + if (div % mcasp->tdm_slots_tx) + dev_warn(mcasp->dev, + "%s(): BCLK/LRCLK %d is not divisible by %d tx tdm slots", + __func__, div, mcasp->tdm_slots_tx); + + mcasp->slot_width_rx = div / mcasp->tdm_slots_rx; + if (div % mcasp->tdm_slots_rx) + dev_warn(mcasp->dev, + "%s(): BCLK/LRCLK %d is not divisible by %d rx tdm slots", + __func__, div, mcasp->tdm_slots_rx); + break; + + case MCASP_CLKDIV_BCLK_FS_RATIO_TXONLY: + mcasp->slot_width_tx = div / mcasp->tdm_slots_tx; + if (div % mcasp->tdm_slots_tx) + dev_warn(mcasp->dev, + "%s(): BCLK/LRCLK %d is not divisible by %d tx tdm slots", + __func__, div, mcasp->tdm_slots_tx); + break; + + case MCASP_CLKDIV_BCLK_FS_RATIO_RXONLY: + mcasp->slot_width_rx = div / mcasp->tdm_slots_rx; + if (div % mcasp->tdm_slots_rx) dev_warn(mcasp->dev, - "%s(): BCLK/LRCLK %d is not divisible by %d tdm slots", - __func__, div, mcasp->tdm_slots); + "%s(): BCLK/LRCLK %d is not divisible by %d rx tdm slots", + __func__, div, mcasp->tdm_slots_rx); break; default: @@ -683,6 +803,20 @@ static int davinci_mcasp_set_sysclk(struct snd_soc_dai *dai, int clk_id, mcasp_clr_bits(mcasp, DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE); clear_bit(PIN_BIT_AHCLKX, &mcasp->pdir); + mcasp->sysclk_freq_tx = freq; + mcasp->sysclk_freq_rx = freq; + break; + case MCASP_CLK_HCLK_AHCLK_TXONLY: + mcasp_clr_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, + AHCLKXE); + clear_bit(PIN_BIT_AHCLKX, &mcasp->pdir); + mcasp->sysclk_freq_tx = freq; + break; + case MCASP_CLK_HCLK_AHCLK_RXONLY: + mcasp_clr_bits(mcasp, DAVINCI_MCASP_AHCLKRCTL_REG, + AHCLKRE); + clear_bit(PIN_BIT_AHCLKR, &mcasp->pdir); + mcasp->sysclk_freq_rx = freq; break; case MCASP_CLK_HCLK_AUXCLK: mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, @@ -690,22 +824,56 @@ static int davinci_mcasp_set_sysclk(struct snd_soc_dai *dai, int clk_id, mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE); set_bit(PIN_BIT_AHCLKX, &mcasp->pdir); + mcasp->sysclk_freq_tx = freq; + mcasp->sysclk_freq_rx = freq; + break; + case MCASP_CLK_HCLK_AUXCLK_TXONLY: + mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, + AHCLKXE); + set_bit(PIN_BIT_AHCLKX, &mcasp->pdir); + mcasp->sysclk_freq_tx = freq; + break; + case MCASP_CLK_HCLK_AUXCLK_RXONLY: + mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKRCTL_REG, + AHCLKRE); + set_bit(PIN_BIT_AHCLKR, &mcasp->pdir); + mcasp->sysclk_freq_rx = freq; break; default: dev_err(mcasp->dev, "Invalid clk id: %d\n", clk_id); goto out; } } else { - /* Select AUXCLK as HCLK */ - mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE); - mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE); - set_bit(PIN_BIT_AHCLKX, &mcasp->pdir); + /* McASP is clock master, select AUXCLK as HCLK */ + switch (clk_id) { + case MCASP_CLK_HCLK_AUXCLK_TXONLY: + mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, + AHCLKXE); + set_bit(PIN_BIT_AHCLKX, &mcasp->pdir); + mcasp->sysclk_freq_tx = freq; + break; + case MCASP_CLK_HCLK_AUXCLK_RXONLY: + mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKRCTL_REG, + AHCLKRE); + set_bit(PIN_BIT_AHCLKR, &mcasp->pdir); + mcasp->sysclk_freq_rx = freq; + break; + default: + mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, + AHCLKXE); + mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKRCTL_REG, + AHCLKRE); + set_bit(PIN_BIT_AHCLKX, &mcasp->pdir); + set_bit(PIN_BIT_AHCLKR, &mcasp->pdir); + mcasp->sysclk_freq_tx = freq; + mcasp->sysclk_freq_rx = freq; + break; + } } /* * When AHCLK X/R is selected to be output it means that the HCLK is * the same clock - coming via AUXCLK. */ - mcasp->sysclk_freq = freq; out: pm_runtime_put(mcasp->dev); return 0; @@ -717,9 +885,11 @@ static int davinci_mcasp_ch_constraint(struct davinci_mcasp *mcasp, int stream, { struct snd_pcm_hw_constraint_list *cl = &mcasp->chconstr[stream]; unsigned int *list = (unsigned int *) cl->list; - int slots = mcasp->tdm_slots; + int slots; int i, count = 0; + slots = mcasp_get_tdm_slots(mcasp, stream); + if (mcasp->tdm_mask[stream]) slots = hweight32(mcasp->tdm_mask[stream]); @@ -784,27 +954,42 @@ static int davinci_mcasp_set_tdm_slot(struct snd_soc_dai *dai, return -EINVAL; } - mcasp->tdm_slots = slots; + if (mcasp->async_mode) { + if (tx_mask) { + mcasp->tdm_slots_tx = slots; + mcasp->slot_width_tx = slot_width; + } + if (rx_mask) { + mcasp->tdm_slots_rx = slots; + mcasp->slot_width_rx = slot_width; + } + } else { + mcasp->tdm_slots_tx = slots; + mcasp->tdm_slots_rx = slots; + mcasp->slot_width_tx = slot_width; + mcasp->slot_width_rx = slot_width; + } + mcasp->tdm_mask[SNDRV_PCM_STREAM_PLAYBACK] = tx_mask; mcasp->tdm_mask[SNDRV_PCM_STREAM_CAPTURE] = rx_mask; - mcasp->slot_width = slot_width; return davinci_mcasp_set_ch_constraints(mcasp); } static int davinci_config_channel_size(struct davinci_mcasp *mcasp, - int sample_width) + int sample_width, int stream) { u32 fmt; u32 tx_rotate, rx_rotate, slot_width; u32 mask = (1ULL << sample_width) - 1; - if (mcasp->slot_width) - slot_width = mcasp->slot_width; - else if (mcasp->max_format_width) - slot_width = mcasp->max_format_width; - else - slot_width = sample_width; + slot_width = mcasp_get_slot_width(mcasp, stream); + if (!slot_width) { + if (mcasp->max_format_width) + slot_width = mcasp->max_format_width; + else + slot_width = sample_width; + } /* * TX rotation: * right aligned formats: rotate w/ slot_width @@ -827,17 +1012,23 @@ static int davinci_config_channel_size(struct davinci_mcasp *mcasp, fmt = (slot_width >> 1) - 1; if (mcasp->op_mode != DAVINCI_MCASP_DIT_MODE) { - mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, RXSSZ(fmt), - RXSSZ(0x0F)); - mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, TXSSZ(fmt), - TXSSZ(0x0F)); - mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, TXROT(tx_rotate), - TXROT(7)); - mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, RXROT(rx_rotate), - RXROT(7)); - mcasp_set_reg(mcasp, DAVINCI_MCASP_RXMASK_REG, mask); + if (!mcasp->async_mode || stream == SNDRV_PCM_STREAM_PLAYBACK) { + mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, TXSSZ(fmt), + TXSSZ(0x0F)); + mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, TXROT(tx_rotate), + TXROT(7)); + mcasp_set_reg(mcasp, DAVINCI_MCASP_TXMASK_REG, mask); + } + if (!mcasp->async_mode || stream == SNDRV_PCM_STREAM_CAPTURE) { + mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, RXSSZ(fmt), + RXSSZ(0x0F)); + mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, RXROT(rx_rotate), + RXROT(7)); + mcasp_set_reg(mcasp, DAVINCI_MCASP_RXMASK_REG, mask); + } } else { /* + * DIT mode only use TX serializers * according to the TRM it should be TXROT=0, this one works: * 16 bit to 23-8 (TXROT=6, rotate 24 bits) * 24 bit to 23-0 (TXROT=0, rotate 0 bits) @@ -850,10 +1041,9 @@ static int davinci_config_channel_size(struct davinci_mcasp *mcasp, TXROT(7)); mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, TXSSZ(15), TXSSZ(0x0F)); + mcasp_set_reg(mcasp, DAVINCI_MCASP_TXMASK_REG, mask); } - mcasp_set_reg(mcasp, DAVINCI_MCASP_TXMASK_REG, mask); - return 0; } @@ -864,11 +1054,13 @@ static int mcasp_common_hw_param(struct davinci_mcasp *mcasp, int stream, int i; u8 tx_ser = 0; u8 rx_ser = 0; - u8 slots = mcasp->tdm_slots; + int slots; u8 max_active_serializers, max_rx_serializers, max_tx_serializers; int active_serializers, numevt; u32 reg; + slots = mcasp_get_tdm_slots(mcasp, stream); + /* In DIT mode we only allow maximum of one serializers for now */ if (mcasp->op_mode == DAVINCI_MCASP_DIT_MODE) max_active_serializers = 1; @@ -996,7 +1188,7 @@ static int mcasp_i2s_hw_param(struct davinci_mcasp *mcasp, int stream, u32 mask = 0; u32 busel = 0; - total_slots = mcasp->tdm_slots; + total_slots = mcasp_get_tdm_slots(mcasp, stream); /* * If more than one serializer is needed, then use them with @@ -1027,7 +1219,10 @@ static int mcasp_i2s_hw_param(struct davinci_mcasp *mcasp, int stream, mask |= (1 << i); } - mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, TX_ASYNC); + if (mcasp->async_mode) + mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, TX_ASYNC); + else + mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, TX_ASYNC); if (!mcasp->dat_port) busel = TXSEL; @@ -1126,16 +1321,33 @@ static int mcasp_dit_hw_param(struct davinci_mcasp *mcasp, static int davinci_mcasp_calc_clk_div(struct davinci_mcasp *mcasp, unsigned int sysclk_freq, - unsigned int bclk_freq, bool set) + unsigned int bclk_freq, + int stream, + bool set) { - u32 reg = mcasp_get_reg(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG); int div = sysclk_freq / bclk_freq; int rem = sysclk_freq % bclk_freq; int error_ppm; int aux_div = 1; + int bclk_div_id, auxclk_div_id; + bool auxclk_enabled; + + if (mcasp->async_mode && stream == SNDRV_PCM_STREAM_CAPTURE) { + auxclk_enabled = mcasp_get_reg(mcasp, DAVINCI_MCASP_AHCLKRCTL_REG) & AHCLKRE; + bclk_div_id = MCASP_CLKDIV_BCLK_RXONLY; + auxclk_div_id = MCASP_CLKDIV_AUXCLK_RXONLY; + } else if (mcasp->async_mode && stream == SNDRV_PCM_STREAM_PLAYBACK) { + auxclk_enabled = mcasp_get_reg(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG) & AHCLKXE; + bclk_div_id = MCASP_CLKDIV_BCLK_TXONLY; + auxclk_div_id = MCASP_CLKDIV_AUXCLK_TXONLY; + } else { + auxclk_enabled = mcasp_get_reg(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG) & AHCLKXE; + bclk_div_id = MCASP_CLKDIV_BCLK; + auxclk_div_id = MCASP_CLKDIV_AUXCLK; + } if (div > (ACLKXDIV_MASK + 1)) { - if (reg & AHCLKXE) { + if (auxclk_enabled) { aux_div = div / (ACLKXDIV_MASK + 1); if (div % (ACLKXDIV_MASK + 1)) aux_div++; @@ -1165,10 +1377,10 @@ static int davinci_mcasp_calc_clk_div(struct davinci_mcasp *mcasp, dev_info(mcasp->dev, "Sample-rate is off by %d PPM\n", error_ppm); - __davinci_mcasp_set_clkdiv(mcasp, MCASP_CLKDIV_BCLK, div, 0); - if (reg & AHCLKXE) - __davinci_mcasp_set_clkdiv(mcasp, MCASP_CLKDIV_AUXCLK, - aux_div, 0); + __davinci_mcasp_set_clkdiv(mcasp, bclk_div_id, div, false); + if (auxclk_enabled) + __davinci_mcasp_set_clkdiv(mcasp, auxclk_div_id, + aux_div, false); } return error_ppm; @@ -1219,6 +1431,7 @@ static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream, int channels = params_channels(params); int period_size = params_period_size(params); int ret; + unsigned int sysclk_freq = mcasp_get_sysclk_freq(mcasp, substream->stream); switch (params_format(params)) { case SNDRV_PCM_FORMAT_U8: @@ -1259,22 +1472,26 @@ static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream, * If mcasp is BCLK master, and a BCLK divider was not provided by * the machine driver, we need to calculate the ratio. */ - if (mcasp->bclk_master && mcasp->bclk_div == 0 && mcasp->sysclk_freq) { - int slots = mcasp->tdm_slots; + if (mcasp->bclk_master && mcasp_get_bclk_div(mcasp, substream->stream) == 0 && + sysclk_freq) { + int slots, slot_width; int rate = params_rate(params); int sbits = params_width(params); unsigned int bclk_target; - if (mcasp->slot_width) - sbits = mcasp->slot_width; + slots = mcasp_get_tdm_slots(mcasp, substream->stream); + + slot_width = mcasp_get_slot_width(mcasp, substream->stream); + if (slot_width) + sbits = slot_width; if (mcasp->op_mode == DAVINCI_MCASP_IIS_MODE) bclk_target = rate * sbits * slots; else bclk_target = rate * 128; - davinci_mcasp_calc_clk_div(mcasp, mcasp->sysclk_freq, - bclk_target, true); + davinci_mcasp_calc_clk_div(mcasp, sysclk_freq, + bclk_target, substream->stream, true); } ret = mcasp_common_hw_param(mcasp, substream->stream, @@ -1291,9 +1508,10 @@ static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream, if (ret) return ret; - davinci_config_channel_size(mcasp, word_length); + davinci_config_channel_size(mcasp, word_length, substream->stream); - if (mcasp->op_mode == DAVINCI_MCASP_IIS_MODE) { + /* Channel constraints are disabled for async mode */ + if (mcasp->op_mode == DAVINCI_MCASP_IIS_MODE && !mcasp->async_mode) { mcasp->channels = channels; if (!mcasp->max_format_width) mcasp->max_format_width = word_length; @@ -1337,7 +1555,7 @@ static int davinci_mcasp_hw_rule_slot_width(struct snd_pcm_hw_params *params, snd_pcm_format_t i; snd_mask_none(&nfmt); - slot_width = rd->mcasp->slot_width; + slot_width = mcasp_get_slot_width(rd->mcasp, rd->stream); pcm_for_each_format(i) { if (snd_mask_test_format(fmt, i)) { @@ -1387,12 +1605,15 @@ static int davinci_mcasp_hw_rule_rate(struct snd_pcm_hw_params *params, struct snd_interval *ri = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); int sbits = params_width(params); - int slots = rd->mcasp->tdm_slots; + int slots, slot_width; struct snd_interval range; int i; - if (rd->mcasp->slot_width) - sbits = rd->mcasp->slot_width; + slots = mcasp_get_tdm_slots(rd->mcasp, rd->stream); + + slot_width = mcasp_get_slot_width(rd->mcasp, rd->stream); + if (slot_width) + sbits = slot_width; snd_interval_any(&range); range.empty = 1; @@ -1402,16 +1623,17 @@ static int davinci_mcasp_hw_rule_rate(struct snd_pcm_hw_params *params, uint bclk_freq = sbits * slots * davinci_mcasp_dai_rates[i]; unsigned int sysclk_freq; + unsigned int ratio; int ppm; - if (rd->mcasp->auxclk_fs_ratio) - sysclk_freq = davinci_mcasp_dai_rates[i] * - rd->mcasp->auxclk_fs_ratio; + ratio = mcasp_get_auxclk_fs_ratio(rd->mcasp, rd->stream); + if (ratio) + sysclk_freq = davinci_mcasp_dai_rates[i] * ratio; else - sysclk_freq = rd->mcasp->sysclk_freq; + sysclk_freq = mcasp_get_sysclk_freq(rd->mcasp, rd->stream); ppm = davinci_mcasp_calc_clk_div(rd->mcasp, sysclk_freq, - bclk_freq, false); + bclk_freq, rd->stream, false); if (abs(ppm) < DAVINCI_MAX_RATE_ERROR_PPM) { if (range.empty) { range.min = davinci_mcasp_dai_rates[i]; @@ -1437,30 +1659,34 @@ static int davinci_mcasp_hw_rule_format(struct snd_pcm_hw_params *params, struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); struct snd_mask nfmt; int rate = params_rate(params); - int slots = rd->mcasp->tdm_slots; + int slots; int count = 0; snd_pcm_format_t i; + slots = mcasp_get_tdm_slots(rd->mcasp, rd->stream); + snd_mask_none(&nfmt); pcm_for_each_format(i) { if (snd_mask_test_format(fmt, i)) { uint sbits = snd_pcm_format_width(i); unsigned int sysclk_freq; - int ppm; + unsigned int ratio; + int ppm, slot_width; - if (rd->mcasp->auxclk_fs_ratio) - sysclk_freq = rate * - rd->mcasp->auxclk_fs_ratio; + ratio = mcasp_get_auxclk_fs_ratio(rd->mcasp, rd->stream); + if (ratio) + sysclk_freq = rate * ratio; else - sysclk_freq = rd->mcasp->sysclk_freq; + sysclk_freq = mcasp_get_sysclk_freq(rd->mcasp, rd->stream); - if (rd->mcasp->slot_width) - sbits = rd->mcasp->slot_width; + slot_width = mcasp_get_slot_width(rd->mcasp, rd->stream); + if (slot_width) + sbits = slot_width; ppm = davinci_mcasp_calc_clk_div(rd->mcasp, sysclk_freq, sbits * slots * rate, - false); + rd->stream, false); if (abs(ppm) < DAVINCI_MAX_RATE_ERROR_PPM) { snd_mask_set_format(&nfmt, i); count++; @@ -1497,7 +1723,7 @@ static int davinci_mcasp_startup(struct snd_pcm_substream *substream, &mcasp->ruledata[substream->stream]; u32 max_channels = 0; int i, dir, ret; - int tdm_slots = mcasp->tdm_slots; + int tdm_slots; u8 *numevt; /* Do not allow more then one stream per direction */ @@ -1506,6 +1732,8 @@ static int davinci_mcasp_startup(struct snd_pcm_substream *substream, mcasp->substreams[substream->stream] = substream; + tdm_slots = mcasp_get_tdm_slots(mcasp, substream->stream); + if (mcasp->tdm_mask[substream->stream]) tdm_slots = hweight32(mcasp->tdm_mask[substream->stream]); @@ -1527,6 +1755,7 @@ static int davinci_mcasp_startup(struct snd_pcm_substream *substream, } ruledata->serializers = max_channels; ruledata->mcasp = mcasp; + ruledata->stream = substream->stream; max_channels *= tdm_slots; /* * If the already active stream has less channels than the calculated @@ -1534,9 +1763,13 @@ static int davinci_mcasp_startup(struct snd_pcm_substream *substream, * is in use we need to use that as a constraint for the second stream. * Otherwise (first stream or less allowed channels or more than one * serializer in use) we use the calculated constraint. + * + * However, in async mode, TX and RX have independent clocks and can + * use different configurations, so don't apply the constraint. */ if (mcasp->channels && mcasp->channels < max_channels && - ruledata->serializers == 1) + ruledata->serializers == 1 && + !mcasp->async_mode) max_channels = mcasp->channels; /* * But we can always allow channels upto the amount of @@ -1553,10 +1786,10 @@ static int davinci_mcasp_startup(struct snd_pcm_substream *substream, 0, SNDRV_PCM_HW_PARAM_CHANNELS, &mcasp->chconstr[substream->stream]); - if (mcasp->max_format_width) { + if (mcasp->max_format_width && !mcasp->async_mode) { /* * Only allow formats which require same amount of bits on the - * bus as the currently running stream + * bus as the currently running stream to ensure sync mode */ ret = snd_pcm_hw_rule_add(substream->runtime, 0, SNDRV_PCM_HW_PARAM_FORMAT, @@ -1565,8 +1798,7 @@ static int davinci_mcasp_startup(struct snd_pcm_substream *substream, SNDRV_PCM_HW_PARAM_FORMAT, -1); if (ret) return ret; - } - else if (mcasp->slot_width) { + } else if (mcasp_get_slot_width(mcasp, substream->stream)) { /* Only allow formats require <= slot_width bits on the bus */ ret = snd_pcm_hw_rule_add(substream->runtime, 0, SNDRV_PCM_HW_PARAM_FORMAT, @@ -1581,7 +1813,8 @@ static int davinci_mcasp_startup(struct snd_pcm_substream *substream, * If we rely on implicit BCLK divider setting we should * set constraints based on what we can provide. */ - if (mcasp->bclk_master && mcasp->bclk_div == 0 && mcasp->sysclk_freq) { + if (mcasp->bclk_master && mcasp_get_bclk_div(mcasp, substream->stream) == 0 && + mcasp_get_sysclk_freq(mcasp, substream->stream)) { ret = snd_pcm_hw_rule_add(substream->runtime, 0, SNDRV_PCM_HW_PARAM_RATE, davinci_mcasp_hw_rule_rate, @@ -1758,8 +1991,6 @@ static struct snd_soc_dai_driver davinci_mcasp_dai[] = { .formats = DAVINCI_MCASP_PCM_FMTS, }, .ops = &davinci_mcasp_dai_ops, - - .symmetric_rate = 1, }, { .name = "davinci-mcasp.1", @@ -1921,18 +2152,33 @@ static int davinci_mcasp_get_config(struct davinci_mcasp *mcasp, goto out; } + /* Parse TX-specific TDM slot and use it as default for RX */ if (of_property_read_u32(np, "tdm-slots", &val) == 0) { if (val < 2 || val > 32) { - dev_err(&pdev->dev, "tdm-slots must be in rage [2-32]\n"); + dev_err(&pdev->dev, "tdm-slots must be in range [2-32]\n"); return -EINVAL; } - pdata->tdm_slots = val; + pdata->tdm_slots_tx = val; + pdata->tdm_slots_rx = val; } else if (pdata->op_mode == DAVINCI_MCASP_IIS_MODE) { mcasp->missing_audio_param = true; goto out; } + /* Parse RX-specific TDM slot count if provided */ + if (of_property_read_u32(np, "tdm-slots-rx", &val) == 0) { + if (val < 2 || val > 32) { + dev_err(&pdev->dev, "tdm-slots-rx must be in range [2-32]\n"); + return -EINVAL; + } + + pdata->tdm_slots_rx = val; + } + + if (pdata->op_mode != DAVINCI_MCASP_DIT_MODE) + mcasp->async_mode = of_property_read_bool(np, "ti,async-mode"); + of_serial_dir32 = of_get_property(np, "serial-dir", &val); val /= sizeof(u32); if (of_serial_dir32) { @@ -1958,8 +2204,15 @@ static int davinci_mcasp_get_config(struct davinci_mcasp *mcasp, if (of_property_read_u32(np, "rx-num-evt", &val) == 0) pdata->rxnumevt = val; - if (of_property_read_u32(np, "auxclk-fs-ratio", &val) == 0) - mcasp->auxclk_fs_ratio = val; + /* Parse TX-specific auxclk/fs ratio and use it as default for RX */ + if (of_property_read_u32(np, "auxclk-fs-ratio", &val) == 0) { + mcasp->auxclk_fs_ratio_tx = val; + mcasp->auxclk_fs_ratio_rx = val; + } + + /* Parse RX-specific auxclk/fs ratio if provided */ + if (of_property_read_u32(np, "auxclk-fs-ratio-rx", &val) == 0) + mcasp->auxclk_fs_ratio_rx = val; if (of_property_read_u32(np, "dismod", &val) == 0) { if (val == 0 || val == 2 || val == 3) { @@ -1988,19 +2241,51 @@ static int davinci_mcasp_get_config(struct davinci_mcasp *mcasp, mcasp->op_mode = pdata->op_mode; /* sanity check for tdm slots parameter */ if (mcasp->op_mode == DAVINCI_MCASP_IIS_MODE) { - if (pdata->tdm_slots < 2) { - dev_warn(&pdev->dev, "invalid tdm slots: %d\n", - pdata->tdm_slots); - mcasp->tdm_slots = 2; - } else if (pdata->tdm_slots > 32) { - dev_warn(&pdev->dev, "invalid tdm slots: %d\n", - pdata->tdm_slots); - mcasp->tdm_slots = 32; + if (pdata->tdm_slots_tx < 2) { + dev_warn(&pdev->dev, "invalid tdm tx slots: %d\n", + pdata->tdm_slots_tx); + mcasp->tdm_slots_tx = 2; + } else if (pdata->tdm_slots_tx > 32) { + dev_warn(&pdev->dev, "invalid tdm tx slots: %d\n", + pdata->tdm_slots_tx); + mcasp->tdm_slots_tx = 32; } else { - mcasp->tdm_slots = pdata->tdm_slots; + mcasp->tdm_slots_tx = pdata->tdm_slots_tx; + } + + if (pdata->tdm_slots_rx < 2) { + dev_warn(&pdev->dev, "invalid tdm rx slots: %d\n", + pdata->tdm_slots_rx); + mcasp->tdm_slots_rx = 2; + } else if (pdata->tdm_slots_rx > 32) { + dev_warn(&pdev->dev, "invalid tdm rx slots: %d\n", + pdata->tdm_slots_rx); + mcasp->tdm_slots_rx = 32; + } else { + mcasp->tdm_slots_rx = pdata->tdm_slots_rx; } } else { - mcasp->tdm_slots = 32; + mcasp->tdm_slots_tx = 32; + mcasp->tdm_slots_rx = 32; + } + + /* Different TX/RX slot counts require async mode */ + if (pdata->op_mode != DAVINCI_MCASP_DIT_MODE && + mcasp->tdm_slots_tx != mcasp->tdm_slots_rx && !mcasp->async_mode) { + dev_err(&pdev->dev, + "Different TX (%d) and RX (%d) TDM slots require ti,async-mode\n", + mcasp->tdm_slots_tx, mcasp->tdm_slots_rx); + return -EINVAL; + } + + /* Different TX/RX auxclk-fs-ratio require async mode */ + if (pdata->op_mode != DAVINCI_MCASP_DIT_MODE && + mcasp->auxclk_fs_ratio_tx && mcasp->auxclk_fs_ratio_rx && + mcasp->auxclk_fs_ratio_tx != mcasp->auxclk_fs_ratio_rx && !mcasp->async_mode) { + dev_err(&pdev->dev, + "Different TX (%d) and RX (%d) auxclk-fs-ratio require ti,async-mode\n", + mcasp->auxclk_fs_ratio_tx, mcasp->auxclk_fs_ratio_rx); + return -EINVAL; } mcasp->num_serializer = pdata->num_serializer; diff --git a/sound/soc/ti/davinci-mcasp.h b/sound/soc/ti/davinci-mcasp.h index 5de2b8a31061..4eba8c918c5f 100644 --- a/sound/soc/ti/davinci-mcasp.h +++ b/sound/soc/ti/davinci-mcasp.h @@ -298,10 +298,20 @@ /* Source of High-frequency transmit/receive clock */ #define MCASP_CLK_HCLK_AHCLK 0 /* AHCLKX/R */ #define MCASP_CLK_HCLK_AUXCLK 1 /* Internal functional clock */ +#define MCASP_CLK_HCLK_AHCLK_TXONLY 2 /* AHCLKX for TX only */ +#define MCASP_CLK_HCLK_AHCLK_RXONLY 3 /* AHCLKR for RX only */ +#define MCASP_CLK_HCLK_AUXCLK_TXONLY 4 /* AUXCLK for TX only */ +#define MCASP_CLK_HCLK_AUXCLK_RXONLY 5 /* AUXCLK for RX only */ /* clock divider IDs */ #define MCASP_CLKDIV_AUXCLK 0 /* HCLK divider from AUXCLK */ #define MCASP_CLKDIV_BCLK 1 /* BCLK divider from HCLK */ #define MCASP_CLKDIV_BCLK_FS_RATIO 2 /* to set BCLK FS ration */ +#define MCASP_CLKDIV_AUXCLK_TXONLY 3 /* AUXCLK divider for TX only */ +#define MCASP_CLKDIV_AUXCLK_RXONLY 4 /* AUXCLK divider for RX only */ +#define MCASP_CLKDIV_BCLK_TXONLY 5 /* BCLK divider for TX only */ +#define MCASP_CLKDIV_BCLK_RXONLY 6 /* BCLK divider for RX only */ +#define MCASP_CLKDIV_BCLK_FS_RATIO_TXONLY 7 /* BCLK/FS ratio for TX only */ +#define MCASP_CLKDIV_BCLK_FS_RATIO_RXONLY 8 /* BCLK/FS ratio for RX only */ #endif /* DAVINCI_MCASP_H */ -- 2.43.0
{ "author": "Sen Wang <sen@ti.com>", "date": "Thu, 29 Jan 2026 23:10:44 -0600", "thread_id": "20260130051045.1898892-1-sen@ti.com.mbox.gz" }
lkml
[PATCH 0/4] ASoC: ti: davinci-mcasp: Add asynchronous mode support for McASP
This series adds asynchronous mode support to the McASP driver, which enables independent configuration of bitclocks, frame sync, and audio configurations between tx(playback) and rx(record). And achieves simultaneous playback & record using different audio configurations. It also adds two clean up patches to the McASP driver that disambiguate and simplifies the logic which avoids the async enhancement from being too convoluted to review and analyze. The implementation is based on vendor documentation and patches tested in both SK-AM62P-LP (sync mode, McASP slave) and AM62D-EVM (async mode, McASP master, rx & tx has different TDM configs). Testing verifies async mode functionality while maintaining backward compatibility with the default sync mode. Bootlog and Async mode tests on AM62D-EVM: [0] [0]: https://gist.github.com/SenWang125/f31f9172b186d414695e37c8b9ef127d Signed-off-by: Sen Wang <sen@ti.com> Sen Wang (4): dt-bindings: sound: davinci-mcasp: Add optional properties for asynchronous mode ASoC: ti: davinci-mcasp: Disambiguate mcasp_is_synchronous function ASoC: ti: davinci-mcasp: Streamline pdir behavior across rx & tx streams ASoC: ti: davinci-mcasp: Add asynchronous mode support .../bindings/sound/davinci-mcasp-audio.yaml | 71 ++- include/linux/platform_data/davinci_asp.h | 3 +- sound/soc/ti/davinci-mcasp.c | 510 ++++++++++++++---- sound/soc/ti/davinci-mcasp.h | 10 + 4 files changed, 479 insertions(+), 115 deletions(-) base-commit: dbf8fe85a16a33d6b6bd01f2bc606fc017771465 -- 2.43.0
On Thu, Jan 29, 2026 at 11:10:41PM -0600, Sen Wang wrote: Please submit patches using subject lines reflecting the style for the subsystem, this makes it easier for people to identify relevant patches. Look at what existing commits in the area you're changing are doing and make sure your subject lines visually resemble what they're doing. There's no need to resubmit to fix this alone.
{ "author": "Mark Brown <broonie@kernel.org>", "date": "Mon, 2 Feb 2026 12:44:32 +0000", "thread_id": "20260130051045.1898892-1-sen@ti.com.mbox.gz" }
lkml
[PATCH 0/4] ASoC: ti: davinci-mcasp: Add asynchronous mode support for McASP
This series adds asynchronous mode support to the McASP driver, which enables independent configuration of bitclocks, frame sync, and audio configurations between tx(playback) and rx(record). And achieves simultaneous playback & record using different audio configurations. It also adds two clean up patches to the McASP driver that disambiguate and simplifies the logic which avoids the async enhancement from being too convoluted to review and analyze. The implementation is based on vendor documentation and patches tested in both SK-AM62P-LP (sync mode, McASP slave) and AM62D-EVM (async mode, McASP master, rx & tx has different TDM configs). Testing verifies async mode functionality while maintaining backward compatibility with the default sync mode. Bootlog and Async mode tests on AM62D-EVM: [0] [0]: https://gist.github.com/SenWang125/f31f9172b186d414695e37c8b9ef127d Signed-off-by: Sen Wang <sen@ti.com> Sen Wang (4): dt-bindings: sound: davinci-mcasp: Add optional properties for asynchronous mode ASoC: ti: davinci-mcasp: Disambiguate mcasp_is_synchronous function ASoC: ti: davinci-mcasp: Streamline pdir behavior across rx & tx streams ASoC: ti: davinci-mcasp: Add asynchronous mode support .../bindings/sound/davinci-mcasp-audio.yaml | 71 ++- include/linux/platform_data/davinci_asp.h | 3 +- sound/soc/ti/davinci-mcasp.c | 510 ++++++++++++++---- sound/soc/ti/davinci-mcasp.h | 10 + 4 files changed, 479 insertions(+), 115 deletions(-) base-commit: dbf8fe85a16a33d6b6bd01f2bc606fc017771465 -- 2.43.0
On 30/01/2026 07:10, Sen Wang wrote: True, the naming was not too precise. It is tasked to decide if the TX clock needs to be enabled for RX operation, which precisely when McASP is in synchronous mode _and_ it is clock provider. Acked-by: Peter Ujfalusi <peter.ujfalusi@gmail.com> davinci_mcasp *mcasp, u32 ctl_reg, u32 val) bool enable) *mcasp) *mcasp) !mcasp->streams) { mcasp->streams) davinci_mcasp *mcasp, int stream, -- Péter
{ "author": "=?UTF-8?Q?P=C3=A9ter_Ujfalusi?= <peter.ujfalusi@gmail.com>", "date": "Mon, 2 Feb 2026 18:42:20 +0200", "thread_id": "20260130051045.1898892-1-sen@ti.com.mbox.gz" }
lkml
[PATCH 0/4] ASoC: ti: davinci-mcasp: Add asynchronous mode support for McASP
This series adds asynchronous mode support to the McASP driver, which enables independent configuration of bitclocks, frame sync, and audio configurations between tx(playback) and rx(record). And achieves simultaneous playback & record using different audio configurations. It also adds two clean up patches to the McASP driver that disambiguate and simplifies the logic which avoids the async enhancement from being too convoluted to review and analyze. The implementation is based on vendor documentation and patches tested in both SK-AM62P-LP (sync mode, McASP slave) and AM62D-EVM (async mode, McASP master, rx & tx has different TDM configs). Testing verifies async mode functionality while maintaining backward compatibility with the default sync mode. Bootlog and Async mode tests on AM62D-EVM: [0] [0]: https://gist.github.com/SenWang125/f31f9172b186d414695e37c8b9ef127d Signed-off-by: Sen Wang <sen@ti.com> Sen Wang (4): dt-bindings: sound: davinci-mcasp: Add optional properties for asynchronous mode ASoC: ti: davinci-mcasp: Disambiguate mcasp_is_synchronous function ASoC: ti: davinci-mcasp: Streamline pdir behavior across rx & tx streams ASoC: ti: davinci-mcasp: Add asynchronous mode support .../bindings/sound/davinci-mcasp-audio.yaml | 71 ++- include/linux/platform_data/davinci_asp.h | 3 +- sound/soc/ti/davinci-mcasp.c | 510 ++++++++++++++---- sound/soc/ti/davinci-mcasp.h | 10 + 4 files changed, 479 insertions(+), 115 deletions(-) base-commit: dbf8fe85a16a33d6b6bd01f2bc606fc017771465 -- 2.43.0
On 30/01/2026 07:10, Sen Wang wrote: I'm not sure about this, but the sequence should be preserved, PDIR change first. -- Péter
{ "author": "=?UTF-8?Q?P=C3=A9ter_Ujfalusi?= <peter.ujfalusi@gmail.com>", "date": "Mon, 2 Feb 2026 18:49:40 +0200", "thread_id": "20260130051045.1898892-1-sen@ti.com.mbox.gz" }
lkml
[PATCH 0/4] ASoC: ti: davinci-mcasp: Add asynchronous mode support for McASP
This series adds asynchronous mode support to the McASP driver, which enables independent configuration of bitclocks, frame sync, and audio configurations between tx(playback) and rx(record). And achieves simultaneous playback & record using different audio configurations. It also adds two clean up patches to the McASP driver that disambiguate and simplifies the logic which avoids the async enhancement from being too convoluted to review and analyze. The implementation is based on vendor documentation and patches tested in both SK-AM62P-LP (sync mode, McASP slave) and AM62D-EVM (async mode, McASP master, rx & tx has different TDM configs). Testing verifies async mode functionality while maintaining backward compatibility with the default sync mode. Bootlog and Async mode tests on AM62D-EVM: [0] [0]: https://gist.github.com/SenWang125/f31f9172b186d414695e37c8b9ef127d Signed-off-by: Sen Wang <sen@ti.com> Sen Wang (4): dt-bindings: sound: davinci-mcasp: Add optional properties for asynchronous mode ASoC: ti: davinci-mcasp: Disambiguate mcasp_is_synchronous function ASoC: ti: davinci-mcasp: Streamline pdir behavior across rx & tx streams ASoC: ti: davinci-mcasp: Add asynchronous mode support .../bindings/sound/davinci-mcasp-audio.yaml | 71 ++- include/linux/platform_data/davinci_asp.h | 3 +- sound/soc/ti/davinci-mcasp.c | 510 ++++++++++++++---- sound/soc/ti/davinci-mcasp.h | 10 + 4 files changed, 479 insertions(+), 115 deletions(-) base-commit: dbf8fe85a16a33d6b6bd01f2bc606fc017771465 -- 2.43.0
On 30/01/2026 07:10, Sen Wang wrote: static void mcasp_start_rx(struct davinci_mcasp *mcasp) In new code - while it might not match with old code - use producer instead of master. Otherwise it looks nice, I trust you have tested the sync and DIT mode. With this nitpick addressed: Acked-by: Peter Ujfalusi <peter.ujfalusi@gmail.com> -- Péter
{ "author": "=?UTF-8?Q?P=C3=A9ter_Ujfalusi?= <peter.ujfalusi@gmail.com>", "date": "Mon, 2 Feb 2026 19:02:31 +0200", "thread_id": "20260130051045.1898892-1-sen@ti.com.mbox.gz" }
lkml
[PATCH V1] nvme-pci: Fix NULL pointer dereference in nvme_pci_prp_iter_next
Fix a NULL pointer dereference that occurs in nvme_pci_prp_iter_next() when SWIOTLB bounce buffering becomes active during runtime. The issue occurs when SWIOTLB activation changes the device's DMA mapping requirements at runtime, creating a mismatch between iod->dma_vecs allocation and access logic. The problem manifests when: 1. Device initially operates with dma_skip_sync=true (coherent DMA assumed) 2. First SWIOTLB mapping occurs due to DMA address limitations, memory encryption, or IOMMU bounce buffering requirements 3. SWIOTLB calls dma_reset_need_sync(), permanently setting dma_skip_sync=false 4. Subsequent I/Os now have dma_need_unmap()=true, requiring iod->dma_vecs The issue arises from the timing of allocation versus access: - nvme_pci_setup_data_prp() allocates iod->dma_vecs only when both (!dma_use_iova() && dma_need_unmap()) conditions are met - nvme_pci_prp_iter_next() assumes iod->dma_vecs is valid whenever the same conditions are true, without NULL checking - This creates a race where the device's DMA requirements change dynamically after the initial allocation decision, leading to NULL pointer access Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 pc : nvme_pci_prp_iter_next+0xe4/0x128 [nvme] Call trace: nvme_pci_prp_iter_next+0xe4/0x128 [nvme] nvme_prep_rq+0x5f4/0xa6c [nvme] nvme_queue_rqs+0xa8/0x18c [nvme] blk_mq_dispatch_queue_requests.constprop.0+0x108/0x120 blk_mq_flush_plug_list+0x8c/0x174 __blk_flush_plug+0xe4/0x140 blk_finish_plug+0x38/0x4c read_pages+0x184/0x288 page_cache_ra_order+0x1e0/0x3a4 filemap_fault+0x518/0xa90 __do_fault+0x3c/0x22c __handle_mm_fault+0x10ec/0x19b8 handle_mm_fault+0xb4/0x294 Fix this by: 1. Initialize iod->dma_vecs to NULL in nvme_prep_rq() 2. Add NULL pointer check before accessing iod->dma_vecs in nvme_pci_prp_iter_next() 3. Set iod->dma_vecs to NULL after freeing for defensive programming Fixes: b8b7570a7ec8 ("nvme-pci: fix dma unmapping when using PRPs and not using the IOVA mapping") Co-developed-by: Nitin Rawat <nitin.rawat@oss.qualcomm.com> Signed-off-by: Nitin Rawat <nitin.rawat@oss.qualcomm.com> Signed-off-by: Pradeep P V K <pradeep.pragallapati@oss.qualcomm.com> --- drivers/nvme/host/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 2a52cf46d960..e235654e7ee0 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -720,6 +720,7 @@ static void nvme_free_prps(struct request *req, unsigned int attrs) dma_unmap_phys(nvmeq->dev->dev, iod->dma_vecs[i].addr, iod->dma_vecs[i].len, rq_dma_dir(req), attrs); mempool_free(iod->dma_vecs, nvmeq->dev->dmavec_mempool); + iod->dma_vecs = NULL; } static void nvme_free_sgls(struct request *req, struct nvme_sgl_desc *sge, @@ -825,7 +826,7 @@ static bool nvme_pci_prp_iter_next(struct request *req, struct device *dma_dev, return true; if (!blk_rq_dma_map_iter_next(req, dma_dev, iter)) return false; - if (!dma_use_iova(&iod->dma_state) && dma_need_unmap(dma_dev)) { + if (iod->dma_vecs && !dma_use_iova(&iod->dma_state) && dma_need_unmap(dma_dev)) { iod->dma_vecs[iod->nr_dma_vecs].addr = iter->addr; iod->dma_vecs[iod->nr_dma_vecs].len = iter->len; iod->nr_dma_vecs++; @@ -1218,6 +1219,7 @@ static blk_status_t nvme_prep_rq(struct request *req) iod->nr_descriptors = 0; iod->total_len = 0; iod->meta_total_len = 0; + iod->dma_vecs = NULL; ret = nvme_setup_cmd(req->q->queuedata, req); if (ret) -- 2.34.1
On Mon, Feb 02, 2026 at 06:27:38PM +0530, Pradeep P V K wrote: I think this patch just papers over the bug. If dma_need_unmap can't be trusted before the dma_map_* call, we've not saved the unmap information and the unmap won't work properly. So we'll need to extend the core code to tell if a mapping will set dma_skip_sync=false before doing the mapping.
{ "author": "Christoph Hellwig <hch@lst.de>", "date": "Mon, 2 Feb 2026 15:35:48 +0100", "thread_id": "5a3f03e8-89bc-4b46-b125-e08f8297647f@arm.com.mbox.gz" }
lkml
[PATCH V1] nvme-pci: Fix NULL pointer dereference in nvme_pci_prp_iter_next
Fix a NULL pointer dereference that occurs in nvme_pci_prp_iter_next() when SWIOTLB bounce buffering becomes active during runtime. The issue occurs when SWIOTLB activation changes the device's DMA mapping requirements at runtime, creating a mismatch between iod->dma_vecs allocation and access logic. The problem manifests when: 1. Device initially operates with dma_skip_sync=true (coherent DMA assumed) 2. First SWIOTLB mapping occurs due to DMA address limitations, memory encryption, or IOMMU bounce buffering requirements 3. SWIOTLB calls dma_reset_need_sync(), permanently setting dma_skip_sync=false 4. Subsequent I/Os now have dma_need_unmap()=true, requiring iod->dma_vecs The issue arises from the timing of allocation versus access: - nvme_pci_setup_data_prp() allocates iod->dma_vecs only when both (!dma_use_iova() && dma_need_unmap()) conditions are met - nvme_pci_prp_iter_next() assumes iod->dma_vecs is valid whenever the same conditions are true, without NULL checking - This creates a race where the device's DMA requirements change dynamically after the initial allocation decision, leading to NULL pointer access Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 pc : nvme_pci_prp_iter_next+0xe4/0x128 [nvme] Call trace: nvme_pci_prp_iter_next+0xe4/0x128 [nvme] nvme_prep_rq+0x5f4/0xa6c [nvme] nvme_queue_rqs+0xa8/0x18c [nvme] blk_mq_dispatch_queue_requests.constprop.0+0x108/0x120 blk_mq_flush_plug_list+0x8c/0x174 __blk_flush_plug+0xe4/0x140 blk_finish_plug+0x38/0x4c read_pages+0x184/0x288 page_cache_ra_order+0x1e0/0x3a4 filemap_fault+0x518/0xa90 __do_fault+0x3c/0x22c __handle_mm_fault+0x10ec/0x19b8 handle_mm_fault+0xb4/0x294 Fix this by: 1. Initialize iod->dma_vecs to NULL in nvme_prep_rq() 2. Add NULL pointer check before accessing iod->dma_vecs in nvme_pci_prp_iter_next() 3. Set iod->dma_vecs to NULL after freeing for defensive programming Fixes: b8b7570a7ec8 ("nvme-pci: fix dma unmapping when using PRPs and not using the IOVA mapping") Co-developed-by: Nitin Rawat <nitin.rawat@oss.qualcomm.com> Signed-off-by: Nitin Rawat <nitin.rawat@oss.qualcomm.com> Signed-off-by: Pradeep P V K <pradeep.pragallapati@oss.qualcomm.com> --- drivers/nvme/host/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 2a52cf46d960..e235654e7ee0 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -720,6 +720,7 @@ static void nvme_free_prps(struct request *req, unsigned int attrs) dma_unmap_phys(nvmeq->dev->dev, iod->dma_vecs[i].addr, iod->dma_vecs[i].len, rq_dma_dir(req), attrs); mempool_free(iod->dma_vecs, nvmeq->dev->dmavec_mempool); + iod->dma_vecs = NULL; } static void nvme_free_sgls(struct request *req, struct nvme_sgl_desc *sge, @@ -825,7 +826,7 @@ static bool nvme_pci_prp_iter_next(struct request *req, struct device *dma_dev, return true; if (!blk_rq_dma_map_iter_next(req, dma_dev, iter)) return false; - if (!dma_use_iova(&iod->dma_state) && dma_need_unmap(dma_dev)) { + if (iod->dma_vecs && !dma_use_iova(&iod->dma_state) && dma_need_unmap(dma_dev)) { iod->dma_vecs[iod->nr_dma_vecs].addr = iter->addr; iod->dma_vecs[iod->nr_dma_vecs].len = iter->len; iod->nr_dma_vecs++; @@ -1218,6 +1219,7 @@ static blk_status_t nvme_prep_rq(struct request *req) iod->nr_descriptors = 0; iod->total_len = 0; iod->meta_total_len = 0; + iod->dma_vecs = NULL; ret = nvme_setup_cmd(req->q->queuedata, req); if (ret) -- 2.34.1
On 2026-02-02 2:35 pm, Christoph Hellwig wrote: The dma_need_unmap() kerneldoc says: "This function must be called after all mappings that might need to be unmapped have been performed." Trying to infer anything from it beforehand is definitely a bug in the caller. I don't see that being possible - at best we could reasonably infer that a fully-coherent system with no sync ops, no SWIOTLB and no DMA_DEBUG shouldn't ever set it to true, but as for the other way round, by the time you've run through all the SWIOTLB logic to guess whether a particular mapping would be bounced or not, you've basically performed the mapping anyway. Thus at best, such an API to potentially do a whole dry-run mapping before every actual mapping would seem like a pretty pointless anti-optimisation. Thanks, Robin.
{ "author": "Robin Murphy <robin.murphy@arm.com>", "date": "Mon, 2 Feb 2026 15:16:50 +0000", "thread_id": "5a3f03e8-89bc-4b46-b125-e08f8297647f@arm.com.mbox.gz" }
lkml
[PATCH V1] nvme-pci: Fix NULL pointer dereference in nvme_pci_prp_iter_next
Fix a NULL pointer dereference that occurs in nvme_pci_prp_iter_next() when SWIOTLB bounce buffering becomes active during runtime. The issue occurs when SWIOTLB activation changes the device's DMA mapping requirements at runtime, creating a mismatch between iod->dma_vecs allocation and access logic. The problem manifests when: 1. Device initially operates with dma_skip_sync=true (coherent DMA assumed) 2. First SWIOTLB mapping occurs due to DMA address limitations, memory encryption, or IOMMU bounce buffering requirements 3. SWIOTLB calls dma_reset_need_sync(), permanently setting dma_skip_sync=false 4. Subsequent I/Os now have dma_need_unmap()=true, requiring iod->dma_vecs The issue arises from the timing of allocation versus access: - nvme_pci_setup_data_prp() allocates iod->dma_vecs only when both (!dma_use_iova() && dma_need_unmap()) conditions are met - nvme_pci_prp_iter_next() assumes iod->dma_vecs is valid whenever the same conditions are true, without NULL checking - This creates a race where the device's DMA requirements change dynamically after the initial allocation decision, leading to NULL pointer access Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 pc : nvme_pci_prp_iter_next+0xe4/0x128 [nvme] Call trace: nvme_pci_prp_iter_next+0xe4/0x128 [nvme] nvme_prep_rq+0x5f4/0xa6c [nvme] nvme_queue_rqs+0xa8/0x18c [nvme] blk_mq_dispatch_queue_requests.constprop.0+0x108/0x120 blk_mq_flush_plug_list+0x8c/0x174 __blk_flush_plug+0xe4/0x140 blk_finish_plug+0x38/0x4c read_pages+0x184/0x288 page_cache_ra_order+0x1e0/0x3a4 filemap_fault+0x518/0xa90 __do_fault+0x3c/0x22c __handle_mm_fault+0x10ec/0x19b8 handle_mm_fault+0xb4/0x294 Fix this by: 1. Initialize iod->dma_vecs to NULL in nvme_prep_rq() 2. Add NULL pointer check before accessing iod->dma_vecs in nvme_pci_prp_iter_next() 3. Set iod->dma_vecs to NULL after freeing for defensive programming Fixes: b8b7570a7ec8 ("nvme-pci: fix dma unmapping when using PRPs and not using the IOVA mapping") Co-developed-by: Nitin Rawat <nitin.rawat@oss.qualcomm.com> Signed-off-by: Nitin Rawat <nitin.rawat@oss.qualcomm.com> Signed-off-by: Pradeep P V K <pradeep.pragallapati@oss.qualcomm.com> --- drivers/nvme/host/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 2a52cf46d960..e235654e7ee0 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -720,6 +720,7 @@ static void nvme_free_prps(struct request *req, unsigned int attrs) dma_unmap_phys(nvmeq->dev->dev, iod->dma_vecs[i].addr, iod->dma_vecs[i].len, rq_dma_dir(req), attrs); mempool_free(iod->dma_vecs, nvmeq->dev->dmavec_mempool); + iod->dma_vecs = NULL; } static void nvme_free_sgls(struct request *req, struct nvme_sgl_desc *sge, @@ -825,7 +826,7 @@ static bool nvme_pci_prp_iter_next(struct request *req, struct device *dma_dev, return true; if (!blk_rq_dma_map_iter_next(req, dma_dev, iter)) return false; - if (!dma_use_iova(&iod->dma_state) && dma_need_unmap(dma_dev)) { + if (iod->dma_vecs && !dma_use_iova(&iod->dma_state) && dma_need_unmap(dma_dev)) { iod->dma_vecs[iod->nr_dma_vecs].addr = iter->addr; iod->dma_vecs[iod->nr_dma_vecs].len = iter->len; iod->nr_dma_vecs++; @@ -1218,6 +1219,7 @@ static blk_status_t nvme_prep_rq(struct request *req) iod->nr_descriptors = 0; iod->total_len = 0; iod->meta_total_len = 0; + iod->dma_vecs = NULL; ret = nvme_setup_cmd(req->q->queuedata, req); if (ret) -- 2.34.1
On Mon, Feb 02, 2026 at 03:35:48PM +0100, Christoph Hellwig wrote: Agree There are two paths that lead to SWIOTLB in dma_direct_map_phys(). The first is is_swiotlb_force_bounce(dev), which dma_need_unmap() can easily evaluate. The second is more problematic, as it depends on dma_addr and size, neither of which is available in dma_need_unmap(): 102 if (unlikely(!dma_capable(dev, dma_addr, size, true)) || 103 dma_kmalloc_needs_bounce(dev, size, dir)) { 104 if (is_swiotlb_active(dev)) What about the following change? diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c index 37163eb49f9f..1510b93a8791 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -461,6 +461,8 @@ bool dma_need_unmap(struct device *dev) { if (!dma_map_direct(dev, get_dma_ops(dev))) return true; + if (is_swiotlb_force_bounce(dev) || is_swiotlb_active(dev)) + return true; if (!dev->dma_skip_sync) return true; return IS_ENABLED(CONFIG_DMA_API_DEBUG);
{ "author": "Leon Romanovsky <leon@kernel.org>", "date": "Mon, 2 Feb 2026 17:22:52 +0200", "thread_id": "5a3f03e8-89bc-4b46-b125-e08f8297647f@arm.com.mbox.gz" }
lkml
[PATCH V1] nvme-pci: Fix NULL pointer dereference in nvme_pci_prp_iter_next
Fix a NULL pointer dereference that occurs in nvme_pci_prp_iter_next() when SWIOTLB bounce buffering becomes active during runtime. The issue occurs when SWIOTLB activation changes the device's DMA mapping requirements at runtime, creating a mismatch between iod->dma_vecs allocation and access logic. The problem manifests when: 1. Device initially operates with dma_skip_sync=true (coherent DMA assumed) 2. First SWIOTLB mapping occurs due to DMA address limitations, memory encryption, or IOMMU bounce buffering requirements 3. SWIOTLB calls dma_reset_need_sync(), permanently setting dma_skip_sync=false 4. Subsequent I/Os now have dma_need_unmap()=true, requiring iod->dma_vecs The issue arises from the timing of allocation versus access: - nvme_pci_setup_data_prp() allocates iod->dma_vecs only when both (!dma_use_iova() && dma_need_unmap()) conditions are met - nvme_pci_prp_iter_next() assumes iod->dma_vecs is valid whenever the same conditions are true, without NULL checking - This creates a race where the device's DMA requirements change dynamically after the initial allocation decision, leading to NULL pointer access Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 pc : nvme_pci_prp_iter_next+0xe4/0x128 [nvme] Call trace: nvme_pci_prp_iter_next+0xe4/0x128 [nvme] nvme_prep_rq+0x5f4/0xa6c [nvme] nvme_queue_rqs+0xa8/0x18c [nvme] blk_mq_dispatch_queue_requests.constprop.0+0x108/0x120 blk_mq_flush_plug_list+0x8c/0x174 __blk_flush_plug+0xe4/0x140 blk_finish_plug+0x38/0x4c read_pages+0x184/0x288 page_cache_ra_order+0x1e0/0x3a4 filemap_fault+0x518/0xa90 __do_fault+0x3c/0x22c __handle_mm_fault+0x10ec/0x19b8 handle_mm_fault+0xb4/0x294 Fix this by: 1. Initialize iod->dma_vecs to NULL in nvme_prep_rq() 2. Add NULL pointer check before accessing iod->dma_vecs in nvme_pci_prp_iter_next() 3. Set iod->dma_vecs to NULL after freeing for defensive programming Fixes: b8b7570a7ec8 ("nvme-pci: fix dma unmapping when using PRPs and not using the IOVA mapping") Co-developed-by: Nitin Rawat <nitin.rawat@oss.qualcomm.com> Signed-off-by: Nitin Rawat <nitin.rawat@oss.qualcomm.com> Signed-off-by: Pradeep P V K <pradeep.pragallapati@oss.qualcomm.com> --- drivers/nvme/host/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 2a52cf46d960..e235654e7ee0 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -720,6 +720,7 @@ static void nvme_free_prps(struct request *req, unsigned int attrs) dma_unmap_phys(nvmeq->dev->dev, iod->dma_vecs[i].addr, iod->dma_vecs[i].len, rq_dma_dir(req), attrs); mempool_free(iod->dma_vecs, nvmeq->dev->dmavec_mempool); + iod->dma_vecs = NULL; } static void nvme_free_sgls(struct request *req, struct nvme_sgl_desc *sge, @@ -825,7 +826,7 @@ static bool nvme_pci_prp_iter_next(struct request *req, struct device *dma_dev, return true; if (!blk_rq_dma_map_iter_next(req, dma_dev, iter)) return false; - if (!dma_use_iova(&iod->dma_state) && dma_need_unmap(dma_dev)) { + if (iod->dma_vecs && !dma_use_iova(&iod->dma_state) && dma_need_unmap(dma_dev)) { iod->dma_vecs[iod->nr_dma_vecs].addr = iter->addr; iod->dma_vecs[iod->nr_dma_vecs].len = iter->len; iod->nr_dma_vecs++; @@ -1218,6 +1219,7 @@ static blk_status_t nvme_prep_rq(struct request *req) iod->nr_descriptors = 0; iod->total_len = 0; iod->meta_total_len = 0; + iod->dma_vecs = NULL; ret = nvme_setup_cmd(req->q->queuedata, req); if (ret) -- 2.34.1
On 2026-02-02 3:22 pm, Leon Romanovsky wrote: This will always be true if a default SWIOTLB buffer exists at all, and thus pretty much defeat the point of whatever optimisation the caller is trying to make. Thanks, Robin.
{ "author": "Robin Murphy <robin.murphy@arm.com>", "date": "Mon, 2 Feb 2026 15:26:25 +0000", "thread_id": "5a3f03e8-89bc-4b46-b125-e08f8297647f@arm.com.mbox.gz" }
lkml
[PATCH V1] nvme-pci: Fix NULL pointer dereference in nvme_pci_prp_iter_next
Fix a NULL pointer dereference that occurs in nvme_pci_prp_iter_next() when SWIOTLB bounce buffering becomes active during runtime. The issue occurs when SWIOTLB activation changes the device's DMA mapping requirements at runtime, creating a mismatch between iod->dma_vecs allocation and access logic. The problem manifests when: 1. Device initially operates with dma_skip_sync=true (coherent DMA assumed) 2. First SWIOTLB mapping occurs due to DMA address limitations, memory encryption, or IOMMU bounce buffering requirements 3. SWIOTLB calls dma_reset_need_sync(), permanently setting dma_skip_sync=false 4. Subsequent I/Os now have dma_need_unmap()=true, requiring iod->dma_vecs The issue arises from the timing of allocation versus access: - nvme_pci_setup_data_prp() allocates iod->dma_vecs only when both (!dma_use_iova() && dma_need_unmap()) conditions are met - nvme_pci_prp_iter_next() assumes iod->dma_vecs is valid whenever the same conditions are true, without NULL checking - This creates a race where the device's DMA requirements change dynamically after the initial allocation decision, leading to NULL pointer access Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 pc : nvme_pci_prp_iter_next+0xe4/0x128 [nvme] Call trace: nvme_pci_prp_iter_next+0xe4/0x128 [nvme] nvme_prep_rq+0x5f4/0xa6c [nvme] nvme_queue_rqs+0xa8/0x18c [nvme] blk_mq_dispatch_queue_requests.constprop.0+0x108/0x120 blk_mq_flush_plug_list+0x8c/0x174 __blk_flush_plug+0xe4/0x140 blk_finish_plug+0x38/0x4c read_pages+0x184/0x288 page_cache_ra_order+0x1e0/0x3a4 filemap_fault+0x518/0xa90 __do_fault+0x3c/0x22c __handle_mm_fault+0x10ec/0x19b8 handle_mm_fault+0xb4/0x294 Fix this by: 1. Initialize iod->dma_vecs to NULL in nvme_prep_rq() 2. Add NULL pointer check before accessing iod->dma_vecs in nvme_pci_prp_iter_next() 3. Set iod->dma_vecs to NULL after freeing for defensive programming Fixes: b8b7570a7ec8 ("nvme-pci: fix dma unmapping when using PRPs and not using the IOVA mapping") Co-developed-by: Nitin Rawat <nitin.rawat@oss.qualcomm.com> Signed-off-by: Nitin Rawat <nitin.rawat@oss.qualcomm.com> Signed-off-by: Pradeep P V K <pradeep.pragallapati@oss.qualcomm.com> --- drivers/nvme/host/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 2a52cf46d960..e235654e7ee0 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -720,6 +720,7 @@ static void nvme_free_prps(struct request *req, unsigned int attrs) dma_unmap_phys(nvmeq->dev->dev, iod->dma_vecs[i].addr, iod->dma_vecs[i].len, rq_dma_dir(req), attrs); mempool_free(iod->dma_vecs, nvmeq->dev->dmavec_mempool); + iod->dma_vecs = NULL; } static void nvme_free_sgls(struct request *req, struct nvme_sgl_desc *sge, @@ -825,7 +826,7 @@ static bool nvme_pci_prp_iter_next(struct request *req, struct device *dma_dev, return true; if (!blk_rq_dma_map_iter_next(req, dma_dev, iter)) return false; - if (!dma_use_iova(&iod->dma_state) && dma_need_unmap(dma_dev)) { + if (iod->dma_vecs && !dma_use_iova(&iod->dma_state) && dma_need_unmap(dma_dev)) { iod->dma_vecs[iod->nr_dma_vecs].addr = iter->addr; iod->dma_vecs[iod->nr_dma_vecs].len = iter->len; iod->nr_dma_vecs++; @@ -1218,6 +1219,7 @@ static blk_status_t nvme_prep_rq(struct request *req) iod->nr_descriptors = 0; iod->total_len = 0; iod->meta_total_len = 0; + iod->dma_vecs = NULL; ret = nvme_setup_cmd(req->q->queuedata, req); if (ret) -- 2.34.1
On Mon, Feb 02, 2026 at 03:16:50PM +0000, Robin Murphy wrote: At least for HMM, dma_need_unmap() works as expected. HMM doesn't work with SWIOTLB. Thanks
{ "author": "Leon Romanovsky <leon@kernel.org>", "date": "Mon, 2 Feb 2026 17:58:04 +0200", "thread_id": "5a3f03e8-89bc-4b46-b125-e08f8297647f@arm.com.mbox.gz" }
lkml
[PATCH V1] nvme-pci: Fix NULL pointer dereference in nvme_pci_prp_iter_next
Fix a NULL pointer dereference that occurs in nvme_pci_prp_iter_next() when SWIOTLB bounce buffering becomes active during runtime. The issue occurs when SWIOTLB activation changes the device's DMA mapping requirements at runtime, creating a mismatch between iod->dma_vecs allocation and access logic. The problem manifests when: 1. Device initially operates with dma_skip_sync=true (coherent DMA assumed) 2. First SWIOTLB mapping occurs due to DMA address limitations, memory encryption, or IOMMU bounce buffering requirements 3. SWIOTLB calls dma_reset_need_sync(), permanently setting dma_skip_sync=false 4. Subsequent I/Os now have dma_need_unmap()=true, requiring iod->dma_vecs The issue arises from the timing of allocation versus access: - nvme_pci_setup_data_prp() allocates iod->dma_vecs only when both (!dma_use_iova() && dma_need_unmap()) conditions are met - nvme_pci_prp_iter_next() assumes iod->dma_vecs is valid whenever the same conditions are true, without NULL checking - This creates a race where the device's DMA requirements change dynamically after the initial allocation decision, leading to NULL pointer access Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 pc : nvme_pci_prp_iter_next+0xe4/0x128 [nvme] Call trace: nvme_pci_prp_iter_next+0xe4/0x128 [nvme] nvme_prep_rq+0x5f4/0xa6c [nvme] nvme_queue_rqs+0xa8/0x18c [nvme] blk_mq_dispatch_queue_requests.constprop.0+0x108/0x120 blk_mq_flush_plug_list+0x8c/0x174 __blk_flush_plug+0xe4/0x140 blk_finish_plug+0x38/0x4c read_pages+0x184/0x288 page_cache_ra_order+0x1e0/0x3a4 filemap_fault+0x518/0xa90 __do_fault+0x3c/0x22c __handle_mm_fault+0x10ec/0x19b8 handle_mm_fault+0xb4/0x294 Fix this by: 1. Initialize iod->dma_vecs to NULL in nvme_prep_rq() 2. Add NULL pointer check before accessing iod->dma_vecs in nvme_pci_prp_iter_next() 3. Set iod->dma_vecs to NULL after freeing for defensive programming Fixes: b8b7570a7ec8 ("nvme-pci: fix dma unmapping when using PRPs and not using the IOVA mapping") Co-developed-by: Nitin Rawat <nitin.rawat@oss.qualcomm.com> Signed-off-by: Nitin Rawat <nitin.rawat@oss.qualcomm.com> Signed-off-by: Pradeep P V K <pradeep.pragallapati@oss.qualcomm.com> --- drivers/nvme/host/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 2a52cf46d960..e235654e7ee0 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -720,6 +720,7 @@ static void nvme_free_prps(struct request *req, unsigned int attrs) dma_unmap_phys(nvmeq->dev->dev, iod->dma_vecs[i].addr, iod->dma_vecs[i].len, rq_dma_dir(req), attrs); mempool_free(iod->dma_vecs, nvmeq->dev->dmavec_mempool); + iod->dma_vecs = NULL; } static void nvme_free_sgls(struct request *req, struct nvme_sgl_desc *sge, @@ -825,7 +826,7 @@ static bool nvme_pci_prp_iter_next(struct request *req, struct device *dma_dev, return true; if (!blk_rq_dma_map_iter_next(req, dma_dev, iter)) return false; - if (!dma_use_iova(&iod->dma_state) && dma_need_unmap(dma_dev)) { + if (iod->dma_vecs && !dma_use_iova(&iod->dma_state) && dma_need_unmap(dma_dev)) { iod->dma_vecs[iod->nr_dma_vecs].addr = iter->addr; iod->dma_vecs[iod->nr_dma_vecs].len = iter->len; iod->nr_dma_vecs++; @@ -1218,6 +1219,7 @@ static blk_status_t nvme_prep_rq(struct request *req) iod->nr_descriptors = 0; iod->total_len = 0; iod->meta_total_len = 0; + iod->dma_vecs = NULL; ret = nvme_setup_cmd(req->q->queuedata, req); if (ret) -- 2.34.1
On Mon, Feb 02, 2026 at 03:16:50PM +0000, Robin Murphy wrote: Well that doesn't really make sense. No matter how many mappings the driver has done, there will always be more. ?
{ "author": "Keith Busch <kbusch@kernel.org>", "date": "Mon, 2 Feb 2026 10:13:24 -0700", "thread_id": "5a3f03e8-89bc-4b46-b125-e08f8297647f@arm.com.mbox.gz" }
lkml
[PATCH V1] nvme-pci: Fix NULL pointer dereference in nvme_pci_prp_iter_next
Fix a NULL pointer dereference that occurs in nvme_pci_prp_iter_next() when SWIOTLB bounce buffering becomes active during runtime. The issue occurs when SWIOTLB activation changes the device's DMA mapping requirements at runtime, creating a mismatch between iod->dma_vecs allocation and access logic. The problem manifests when: 1. Device initially operates with dma_skip_sync=true (coherent DMA assumed) 2. First SWIOTLB mapping occurs due to DMA address limitations, memory encryption, or IOMMU bounce buffering requirements 3. SWIOTLB calls dma_reset_need_sync(), permanently setting dma_skip_sync=false 4. Subsequent I/Os now have dma_need_unmap()=true, requiring iod->dma_vecs The issue arises from the timing of allocation versus access: - nvme_pci_setup_data_prp() allocates iod->dma_vecs only when both (!dma_use_iova() && dma_need_unmap()) conditions are met - nvme_pci_prp_iter_next() assumes iod->dma_vecs is valid whenever the same conditions are true, without NULL checking - This creates a race where the device's DMA requirements change dynamically after the initial allocation decision, leading to NULL pointer access Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 pc : nvme_pci_prp_iter_next+0xe4/0x128 [nvme] Call trace: nvme_pci_prp_iter_next+0xe4/0x128 [nvme] nvme_prep_rq+0x5f4/0xa6c [nvme] nvme_queue_rqs+0xa8/0x18c [nvme] blk_mq_dispatch_queue_requests.constprop.0+0x108/0x120 blk_mq_flush_plug_list+0x8c/0x174 __blk_flush_plug+0xe4/0x140 blk_finish_plug+0x38/0x4c read_pages+0x184/0x288 page_cache_ra_order+0x1e0/0x3a4 filemap_fault+0x518/0xa90 __do_fault+0x3c/0x22c __handle_mm_fault+0x10ec/0x19b8 handle_mm_fault+0xb4/0x294 Fix this by: 1. Initialize iod->dma_vecs to NULL in nvme_prep_rq() 2. Add NULL pointer check before accessing iod->dma_vecs in nvme_pci_prp_iter_next() 3. Set iod->dma_vecs to NULL after freeing for defensive programming Fixes: b8b7570a7ec8 ("nvme-pci: fix dma unmapping when using PRPs and not using the IOVA mapping") Co-developed-by: Nitin Rawat <nitin.rawat@oss.qualcomm.com> Signed-off-by: Nitin Rawat <nitin.rawat@oss.qualcomm.com> Signed-off-by: Pradeep P V K <pradeep.pragallapati@oss.qualcomm.com> --- drivers/nvme/host/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 2a52cf46d960..e235654e7ee0 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -720,6 +720,7 @@ static void nvme_free_prps(struct request *req, unsigned int attrs) dma_unmap_phys(nvmeq->dev->dev, iod->dma_vecs[i].addr, iod->dma_vecs[i].len, rq_dma_dir(req), attrs); mempool_free(iod->dma_vecs, nvmeq->dev->dmavec_mempool); + iod->dma_vecs = NULL; } static void nvme_free_sgls(struct request *req, struct nvme_sgl_desc *sge, @@ -825,7 +826,7 @@ static bool nvme_pci_prp_iter_next(struct request *req, struct device *dma_dev, return true; if (!blk_rq_dma_map_iter_next(req, dma_dev, iter)) return false; - if (!dma_use_iova(&iod->dma_state) && dma_need_unmap(dma_dev)) { + if (iod->dma_vecs && !dma_use_iova(&iod->dma_state) && dma_need_unmap(dma_dev)) { iod->dma_vecs[iod->nr_dma_vecs].addr = iter->addr; iod->dma_vecs[iod->nr_dma_vecs].len = iter->len; iod->nr_dma_vecs++; @@ -1218,6 +1219,7 @@ static blk_status_t nvme_prep_rq(struct request *req) iod->nr_descriptors = 0; iod->total_len = 0; iod->meta_total_len = 0; + iod->dma_vecs = NULL; ret = nvme_setup_cmd(req->q->queuedata, req); if (ret) -- 2.34.1
On Mon, Feb 02, 2026 at 06:27:38PM +0530, Pradeep P V K wrote: So the return of dma_need_unmap() may change after any call to dma_map_*? Does it only go from false -> true, and never back to false? Since we didn't allocate the dma_vecs here, doesn't that mean the completion side is leaking the mapping?
{ "author": "Keith Busch <kbusch@kernel.org>", "date": "Mon, 2 Feb 2026 10:18:12 -0700", "thread_id": "5a3f03e8-89bc-4b46-b125-e08f8297647f@arm.com.mbox.gz" }
lkml
[PATCH V1] nvme-pci: Fix NULL pointer dereference in nvme_pci_prp_iter_next
Fix a NULL pointer dereference that occurs in nvme_pci_prp_iter_next() when SWIOTLB bounce buffering becomes active during runtime. The issue occurs when SWIOTLB activation changes the device's DMA mapping requirements at runtime, creating a mismatch between iod->dma_vecs allocation and access logic. The problem manifests when: 1. Device initially operates with dma_skip_sync=true (coherent DMA assumed) 2. First SWIOTLB mapping occurs due to DMA address limitations, memory encryption, or IOMMU bounce buffering requirements 3. SWIOTLB calls dma_reset_need_sync(), permanently setting dma_skip_sync=false 4. Subsequent I/Os now have dma_need_unmap()=true, requiring iod->dma_vecs The issue arises from the timing of allocation versus access: - nvme_pci_setup_data_prp() allocates iod->dma_vecs only when both (!dma_use_iova() && dma_need_unmap()) conditions are met - nvme_pci_prp_iter_next() assumes iod->dma_vecs is valid whenever the same conditions are true, without NULL checking - This creates a race where the device's DMA requirements change dynamically after the initial allocation decision, leading to NULL pointer access Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 pc : nvme_pci_prp_iter_next+0xe4/0x128 [nvme] Call trace: nvme_pci_prp_iter_next+0xe4/0x128 [nvme] nvme_prep_rq+0x5f4/0xa6c [nvme] nvme_queue_rqs+0xa8/0x18c [nvme] blk_mq_dispatch_queue_requests.constprop.0+0x108/0x120 blk_mq_flush_plug_list+0x8c/0x174 __blk_flush_plug+0xe4/0x140 blk_finish_plug+0x38/0x4c read_pages+0x184/0x288 page_cache_ra_order+0x1e0/0x3a4 filemap_fault+0x518/0xa90 __do_fault+0x3c/0x22c __handle_mm_fault+0x10ec/0x19b8 handle_mm_fault+0xb4/0x294 Fix this by: 1. Initialize iod->dma_vecs to NULL in nvme_prep_rq() 2. Add NULL pointer check before accessing iod->dma_vecs in nvme_pci_prp_iter_next() 3. Set iod->dma_vecs to NULL after freeing for defensive programming Fixes: b8b7570a7ec8 ("nvme-pci: fix dma unmapping when using PRPs and not using the IOVA mapping") Co-developed-by: Nitin Rawat <nitin.rawat@oss.qualcomm.com> Signed-off-by: Nitin Rawat <nitin.rawat@oss.qualcomm.com> Signed-off-by: Pradeep P V K <pradeep.pragallapati@oss.qualcomm.com> --- drivers/nvme/host/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 2a52cf46d960..e235654e7ee0 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -720,6 +720,7 @@ static void nvme_free_prps(struct request *req, unsigned int attrs) dma_unmap_phys(nvmeq->dev->dev, iod->dma_vecs[i].addr, iod->dma_vecs[i].len, rq_dma_dir(req), attrs); mempool_free(iod->dma_vecs, nvmeq->dev->dmavec_mempool); + iod->dma_vecs = NULL; } static void nvme_free_sgls(struct request *req, struct nvme_sgl_desc *sge, @@ -825,7 +826,7 @@ static bool nvme_pci_prp_iter_next(struct request *req, struct device *dma_dev, return true; if (!blk_rq_dma_map_iter_next(req, dma_dev, iter)) return false; - if (!dma_use_iova(&iod->dma_state) && dma_need_unmap(dma_dev)) { + if (iod->dma_vecs && !dma_use_iova(&iod->dma_state) && dma_need_unmap(dma_dev)) { iod->dma_vecs[iod->nr_dma_vecs].addr = iter->addr; iod->dma_vecs[iod->nr_dma_vecs].len = iter->len; iod->nr_dma_vecs++; @@ -1218,6 +1219,7 @@ static blk_status_t nvme_prep_rq(struct request *req) iod->nr_descriptors = 0; iod->total_len = 0; iod->meta_total_len = 0; + iod->dma_vecs = NULL; ret = nvme_setup_cmd(req->q->queuedata, req); if (ret) -- 2.34.1
On Mon, Feb 02, 2026 at 10:13:24AM -0700, Keith Busch wrote: Yeah. It's more like if this returns true, all future calls, plus the previous one (which might have caused this). For that something like the patch below should work in nvme. Totally untested as I'm about to head away from the desk and prepare dinner. diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 2a52cf46d960..f944b747e1bd 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -816,6 +816,22 @@ static void nvme_unmap_data(struct request *req) nvme_free_descriptors(req); } +static bool nvme_pci_alloc_dma_vecs(struct request *req, + struct blk_dma_iter *iter) +{ + struct nvme_iod *iod = blk_mq_rq_to_pdu(req); + struct nvme_queue *nvmeq = req->mq_hctx->driver_data; + + iod->dma_vecs = mempool_alloc(nvmeq->dev->dmavec_mempool, + GFP_ATOMIC); + if (!iod->dma_vecs) + return false; + iod->dma_vecs[0].addr = iter->addr; + iod->dma_vecs[0].len = iter->len; + iod->nr_dma_vecs = 1; + return true; +} + static bool nvme_pci_prp_iter_next(struct request *req, struct device *dma_dev, struct blk_dma_iter *iter) { @@ -826,6 +842,8 @@ static bool nvme_pci_prp_iter_next(struct request *req, struct device *dma_dev, if (!blk_rq_dma_map_iter_next(req, dma_dev, iter)) return false; if (!dma_use_iova(&iod->dma_state) && dma_need_unmap(dma_dev)) { + if (!iod->nr_dma_vecs && !nvme_pci_alloc_dma_vecs(req, iter)) + return false; iod->dma_vecs[iod->nr_dma_vecs].addr = iter->addr; iod->dma_vecs[iod->nr_dma_vecs].len = iter->len; iod->nr_dma_vecs++; @@ -844,13 +862,8 @@ static blk_status_t nvme_pci_setup_data_prp(struct request *req, __le64 *prp_list; if (!dma_use_iova(&iod->dma_state) && dma_need_unmap(nvmeq->dev->dev)) { - iod->dma_vecs = mempool_alloc(nvmeq->dev->dmavec_mempool, - GFP_ATOMIC); - if (!iod->dma_vecs) + if (!nvme_pci_alloc_dma_vecs(req, iter)) return BLK_STS_RESOURCE; - iod->dma_vecs[0].addr = iter->addr; - iod->dma_vecs[0].len = iter->len; - iod->nr_dma_vecs = 1; } /*
{ "author": "Christoph Hellwig <hch@lst.de>", "date": "Mon, 2 Feb 2026 18:36:24 +0100", "thread_id": "5a3f03e8-89bc-4b46-b125-e08f8297647f@arm.com.mbox.gz" }
lkml
[PATCH V1] nvme-pci: Fix NULL pointer dereference in nvme_pci_prp_iter_next
Fix a NULL pointer dereference that occurs in nvme_pci_prp_iter_next() when SWIOTLB bounce buffering becomes active during runtime. The issue occurs when SWIOTLB activation changes the device's DMA mapping requirements at runtime, creating a mismatch between iod->dma_vecs allocation and access logic. The problem manifests when: 1. Device initially operates with dma_skip_sync=true (coherent DMA assumed) 2. First SWIOTLB mapping occurs due to DMA address limitations, memory encryption, or IOMMU bounce buffering requirements 3. SWIOTLB calls dma_reset_need_sync(), permanently setting dma_skip_sync=false 4. Subsequent I/Os now have dma_need_unmap()=true, requiring iod->dma_vecs The issue arises from the timing of allocation versus access: - nvme_pci_setup_data_prp() allocates iod->dma_vecs only when both (!dma_use_iova() && dma_need_unmap()) conditions are met - nvme_pci_prp_iter_next() assumes iod->dma_vecs is valid whenever the same conditions are true, without NULL checking - This creates a race where the device's DMA requirements change dynamically after the initial allocation decision, leading to NULL pointer access Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 pc : nvme_pci_prp_iter_next+0xe4/0x128 [nvme] Call trace: nvme_pci_prp_iter_next+0xe4/0x128 [nvme] nvme_prep_rq+0x5f4/0xa6c [nvme] nvme_queue_rqs+0xa8/0x18c [nvme] blk_mq_dispatch_queue_requests.constprop.0+0x108/0x120 blk_mq_flush_plug_list+0x8c/0x174 __blk_flush_plug+0xe4/0x140 blk_finish_plug+0x38/0x4c read_pages+0x184/0x288 page_cache_ra_order+0x1e0/0x3a4 filemap_fault+0x518/0xa90 __do_fault+0x3c/0x22c __handle_mm_fault+0x10ec/0x19b8 handle_mm_fault+0xb4/0x294 Fix this by: 1. Initialize iod->dma_vecs to NULL in nvme_prep_rq() 2. Add NULL pointer check before accessing iod->dma_vecs in nvme_pci_prp_iter_next() 3. Set iod->dma_vecs to NULL after freeing for defensive programming Fixes: b8b7570a7ec8 ("nvme-pci: fix dma unmapping when using PRPs and not using the IOVA mapping") Co-developed-by: Nitin Rawat <nitin.rawat@oss.qualcomm.com> Signed-off-by: Nitin Rawat <nitin.rawat@oss.qualcomm.com> Signed-off-by: Pradeep P V K <pradeep.pragallapati@oss.qualcomm.com> --- drivers/nvme/host/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 2a52cf46d960..e235654e7ee0 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -720,6 +720,7 @@ static void nvme_free_prps(struct request *req, unsigned int attrs) dma_unmap_phys(nvmeq->dev->dev, iod->dma_vecs[i].addr, iod->dma_vecs[i].len, rq_dma_dir(req), attrs); mempool_free(iod->dma_vecs, nvmeq->dev->dmavec_mempool); + iod->dma_vecs = NULL; } static void nvme_free_sgls(struct request *req, struct nvme_sgl_desc *sge, @@ -825,7 +826,7 @@ static bool nvme_pci_prp_iter_next(struct request *req, struct device *dma_dev, return true; if (!blk_rq_dma_map_iter_next(req, dma_dev, iter)) return false; - if (!dma_use_iova(&iod->dma_state) && dma_need_unmap(dma_dev)) { + if (iod->dma_vecs && !dma_use_iova(&iod->dma_state) && dma_need_unmap(dma_dev)) { iod->dma_vecs[iod->nr_dma_vecs].addr = iter->addr; iod->dma_vecs[iod->nr_dma_vecs].len = iter->len; iod->nr_dma_vecs++; @@ -1218,6 +1219,7 @@ static blk_status_t nvme_prep_rq(struct request *req) iod->nr_descriptors = 0; iod->total_len = 0; iod->meta_total_len = 0; + iod->dma_vecs = NULL; ret = nvme_setup_cmd(req->q->queuedata, req); if (ret) -- 2.34.1
On 2026-02-02 5:13 pm, Keith Busch wrote: But equally the fact that none of the mappings made so far happened to not need bouncing still doesn't mean that future ones won't. This is not guaranteed to be a static property of the device, but nor is it really a property of the *device* at all; it's a property of a set of one or more DMA mappings with the same lifetime, there's just no suitable generic notion of that temporal context in the DMA API to carry around and pass as an explicit argument, so it's left implicit in the usage model. Whatever higher-level thing it's doing, the driver must have some context, so within "operation A" it makes some DMA mappings, checks dma_need_unmap() and sees it's false, so can conclude that "operation A" does not need to preserve DMA unmap state. However it may then start "operation B", do some more mappings, check dma_need_unmap() and see it's now returned true, so "operation B" *does* need to keep the DMA data and explicitly unmap it when it finishes. This is essentially the point I made at the time about it not necessarily being as useful a thing as it seems, since if an "operation" involves multiple mappings, it must still store the full state of those mappings for at least long enough to finish them all and then call dma_need_unmap(), to only then see if it might be OK to throw that state away again. Thanks, Robin.
{ "author": "Robin Murphy <robin.murphy@arm.com>", "date": "Mon, 2 Feb 2026 17:39:14 +0000", "thread_id": "5a3f03e8-89bc-4b46-b125-e08f8297647f@arm.com.mbox.gz" }
lkml
[PATCH] drm/panel: boe-th101mb31ig002: Remove use of deprecated mipi_dsi_dcs_nop()
Replace calls to deprecated mipi_dsi_dcs_nop() with mipi_dsi_dcs_nop_multi(). No intended functional changes. Signed-off-by: Caio Ishikawa <caio.ishikawa@proton.me> --- drivers/gpu/drm/panel/panel-boe-th101mb31ig002-28a.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/panel/panel-boe-th101mb31ig002-28a.c b/drivers/gpu/drm/panel/panel-boe-th101mb31ig002-28a.c index f33d4f855929..01b4458e55ad 100644 --- a/drivers/gpu/drm/panel/panel-boe-th101mb31ig002-28a.c +++ b/drivers/gpu/drm/panel/panel-boe-th101mb31ig002-28a.c @@ -221,6 +221,7 @@ static int boe_th101mb31ig002_prepare(struct drm_panel *panel) struct boe_th101mb31ig002, panel); struct device *dev = &ctx->dsi->dev; + struct mipi_dsi_multi_context dsi_ctx = { .dsi = ctx->dsi }; int ret; ret = regulator_enable(ctx->power); @@ -233,9 +234,9 @@ static int boe_th101mb31ig002_prepare(struct drm_panel *panel) msleep(ctx->desc->vcioo_to_lp11_delay_ms); if (ctx->desc->lp11_before_reset) { - ret = mipi_dsi_dcs_nop(ctx->dsi); - if (ret) - return ret; + mipi_dsi_dcs_nop_multi(&dsi_ctx); + if (dsi_ctx.accum_err) + return dsi_ctx.accum_err; } if (ctx->desc->lp11_to_reset_delay_ms) -- 2.52.0
Hi, On Sat, Jan 24, 2026 at 4:51 AM Caio Ishikawa <caio.ishikawa@proton.me> wrote: Hmmmm, I guess we missed this one call when we moved the rest of the driver over to the _multi() functions. While moving this one last call over to _multi() doesn't actually help at all with code flow / readability (arguably, it makes it slightly worse in this case), we did agree that it would be better to move everyone over to the "multi" variants and deprecate the non-multi ones. I guess, if nothing else, we'll now get an error printout if the NOP fails to send, which is an improvement. Reviewed-by: Douglas Anderson <dianders@chromium.org> I'll try to apply in about a week if there are no other comments and nobody beats me to it. -Doug
{ "author": "Doug Anderson <dianders@chromium.org>", "date": "Sat, 24 Jan 2026 15:44:53 -0800", "thread_id": "CAD=FV=Vd3PbB9h4=n=8ArkMJ8g1VKxpxSk8pLDJ4gDYn1_=4aw@mail.gmail.com.mbox.gz" }
lkml
[PATCH] drm/panel: boe-th101mb31ig002: Remove use of deprecated mipi_dsi_dcs_nop()
Replace calls to deprecated mipi_dsi_dcs_nop() with mipi_dsi_dcs_nop_multi(). No intended functional changes. Signed-off-by: Caio Ishikawa <caio.ishikawa@proton.me> --- drivers/gpu/drm/panel/panel-boe-th101mb31ig002-28a.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/panel/panel-boe-th101mb31ig002-28a.c b/drivers/gpu/drm/panel/panel-boe-th101mb31ig002-28a.c index f33d4f855929..01b4458e55ad 100644 --- a/drivers/gpu/drm/panel/panel-boe-th101mb31ig002-28a.c +++ b/drivers/gpu/drm/panel/panel-boe-th101mb31ig002-28a.c @@ -221,6 +221,7 @@ static int boe_th101mb31ig002_prepare(struct drm_panel *panel) struct boe_th101mb31ig002, panel); struct device *dev = &ctx->dsi->dev; + struct mipi_dsi_multi_context dsi_ctx = { .dsi = ctx->dsi }; int ret; ret = regulator_enable(ctx->power); @@ -233,9 +234,9 @@ static int boe_th101mb31ig002_prepare(struct drm_panel *panel) msleep(ctx->desc->vcioo_to_lp11_delay_ms); if (ctx->desc->lp11_before_reset) { - ret = mipi_dsi_dcs_nop(ctx->dsi); - if (ret) - return ret; + mipi_dsi_dcs_nop_multi(&dsi_ctx); + if (dsi_ctx.accum_err) + return dsi_ctx.accum_err; } if (ctx->desc->lp11_to_reset_delay_ms) -- 2.52.0
Hi, On Sat, Jan 24, 2026 at 4:51 AM Caio Ishikawa <caio.ishikawa@proton.me> wrote: Pushed to drm-misc-next: [1/1] drm/panel: boe-th101mb31ig002: Remove use of deprecated mipi_dsi_dcs_nop() commit: 3c55330aac69150a1a4ff20684b41e7f66ad5fe9
{ "author": "Doug Anderson <dianders@chromium.org>", "date": "Mon, 2 Feb 2026 08:23:16 -0800", "thread_id": "CAD=FV=Vd3PbB9h4=n=8ArkMJ8g1VKxpxSk8pLDJ4gDYn1_=4aw@mail.gmail.com.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": "aYDhyxjzKtbqFWdM@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": "aYDhyxjzKtbqFWdM@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": "aYDhyxjzKtbqFWdM@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": "aYDhyxjzKtbqFWdM@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": "aYDhyxjzKtbqFWdM@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": "aYDhyxjzKtbqFWdM@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": "aYDhyxjzKtbqFWdM@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": "aYDhyxjzKtbqFWdM@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": "aYDhyxjzKtbqFWdM@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": "aYDhyxjzKtbqFWdM@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": "aYDhyxjzKtbqFWdM@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": "aYDhyxjzKtbqFWdM@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": "aYDhyxjzKtbqFWdM@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": "aYDhyxjzKtbqFWdM@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": "aYDhyxjzKtbqFWdM@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": "aYDhyxjzKtbqFWdM@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": "aYDhyxjzKtbqFWdM@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": "aYDhyxjzKtbqFWdM@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": "aYDhyxjzKtbqFWdM@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": "aYDhyxjzKtbqFWdM@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": "aYDhyxjzKtbqFWdM@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": "aYDhyxjzKtbqFWdM@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH v12 0/4] net: dsa: initial support for MaxLinear MxL862xx switches
This series adds very basic DSA support for the MaxLinear MxL86252 (5x 2500Base-T PHYs) and MxL86282 (8x 2500Base-T PHYs) switches. In addition to the 2.5G TP ports both switches also come with two SerDes interfaces which can be used either to connect external PHYs or SFP cages, or as CPU port when using the switch with this DSA driver. MxL862xx integrates a firmware running on an embedded processor (based on Zephyr RTOS). Host interaction uses a simple netlink-like API transported over MDIO/MMD. This series includes only what's needed to pass traffic between user ports and the CPU port: relayed MDIO to internal PHYs, basic port enable/disable, and CPU-port special tagging. The SerDes interface of the CPU port is automatically configured by the switch after reset using a board-specific configuration stored together with the firmware in the flash chip attached to the switch, so no action is needed from the driver to setup the interface mode of the CPU port. Also MAC settings of the PHY ports are automatically configured, which means the driver works fine with phylink_mac_ops being all no-op stubs. Multiple follow up series will bring support for setting up the other SerDes PCS interface (ie. not used for the CPU port), bridge, VLAN, ... offloading, and support for using an 802.1Q-based special tag instead of the proprietary 8-byte tag. --- basic DSA selftests were run, results: * no_forwarding.sh: all tests PASS * bridge_vlan_unaware.sh: all tests PASS * bridge_vlan_mcast.sh: all tests PASS * bridge_vlan_aware.sh: all tests PASS * local_termination.sh: all tests PASS or XFAIL, except for TEST: VLAN over vlan_filtering=1 bridged port: Unicast IPv4 to unknown MAC address [FAIL] reception succeeded, but should have failed TEST: VLAN over vlan_filtering=1 bridged port: Unicast IPv4 to unknown MAC address, allmulti [FAIL] reception succeeded, but should have failed As obviously this is mostly testing the Linux software bridge at this point so I didn't bother to run any of the FDB or MDB related tests. Some mystery about the relationship between the sub-interface ID and CTP port assignment remains for now, so I cannot yet fully explain the magic numbers when calculating the two. (Why is it neccesary to allocate 23 CTPs when using port 9 as CPU port while there are at most 17 phyiscal interfaces in total, and only at most 13 when using one of the two SerDes as CPU interface? Why is there an offset of 16 when calculating the sub-interface ID? How will a total of 17 ports be possibly represented in a 4-bit field in the tag RX path?) At this point this doesn't impact functionality, and I hope for further clarification discussing all that with MaxLinear engineers. I believe the initial driver is anyway in good shape now, a follow-up series addressing configuring the SerDes interfaces will also have to take care of CTP assignment and sub-interfaces to not hit the mentioned 4-bit cap in the tag driver. Changes since v11: Address comments reported by Jakub Kicinski using netdev-ai https://patchwork.kernel.org/comment/26767905/ 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * list switch variants in Kconfig starting with dash ('-') * remove the __packed attribute on structs which are naturally packed according to C rules (ie. one other struct with only a single byte-aligned member) * log error in mxl862xx_port_disable() * introduce !NULL check for return value of dsa_to_port() in mxl862xx_add_single_port_bridge * check cpu_dp being non-NULL before dereferencing dp->cpu_dp * use non-racy and deterministic name for MII bus * skip ports without cpu_dp assigned in mxl862xx_setup_cpu_bridge() to avoid potential NULL-pointer dereference * call dev_set_drvdata() only after dsa_register_switch() has been successfully completed Changes since v10: 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * arrange local variables in reverse xmas tree order (again) * use MXL862_NAME as .name in struct dsa_device_ops 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix fatal last-second changes dsa_port_is_unused vs. dsa_is_unused_port and dsa_port_is_unused vs. dsa_is_unused_port * use cpu_to_le16 in mxl862xx_configure_ctp_port * improve formatting of some kerneldoc comments Changes since v9: 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * add microcontroller port 0 2/4 net: dsa: add tag format for MxL862xx switches * count ports starting from 0 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix indentation in kernel-doc * remove misleading comment regarding sub-interface IDs * remove unused macros, set MXL862XX_MAX_PORTS to 17 * count ports starting from 0, 0 being the microcontroller * improve port setup: - split tag protocol and CTP port assignment - use ports cpu_dp instead of relying on single (ie. first) CPU port - handle CPU port like any other port - prepare forward DT compatibility with multiple CPU ports Changes since v8: 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * remove practically unused struct hw_info * lots of kerneldoc improvements in mxl862xx-api.h * drop .mac_select_pcs() stub * better handling for firmware error return value * apply reverse xmas tree in mxl862xx_api_wrap * guard headers with #ifdef macro * include net/dsa.h and linux/mdio.h in mxl862xx.h * call mxl862xx_port_fast_age() only once in .port_setup * don't create isolation bridges for unused ports * replace errornous cast with correct range of values denoting firmware errors Changes since v7 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * use little-endian in bridge_port_config API * remove duplciate assignment of br_port_cfg.bridge_port_id when setting up CPU port Changes since v6 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix kerneldoc style Changes since RFC v5 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * remove unnecessary check for skb != NULL * merge consecutively printed warnings into single dev_warn_ratelimited 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * include bridge and bridgeport API needed to isolate ports * remove warning in .setup as ports are now isolated * make ready-after-reset check more robust by adding delay * sort structs in order of struct definitions * best effort to sort functions without introducing additional prototypes * always use enums with kerneldoc comments in mxl862xx-api.h * remove bogus .phy_read and .phy_write DSA ops as the driver anyway registers a user MDIO bus with Clause-22 and Clause-45 operations * various small style fixes Changes since RFC v4 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * drop unused precompiler macros 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * fix indentation 4/4 net: dsa: add basic initial driver for MxL862xx switches * output warning in .setup regarding unknown pre-configuration * add comment explaining why CFGGET is used in reset function Changes since RFC v3 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * remove labels from example * remove 'bindings for' from commit title 2/4 net: dsa: add tag format for MxL862xx switches * describe fields and variables with comments * sub-interface is only 5 bits * harmonize Kconfig symbol name * maintain alphabetic order in Kconfig * fix typo s/beginnig/beginning/ * fix typo s/swtiches/switches/ * arrange local variables in reverse xmas tree order 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * unchanged 4/4 net: dsa: add basic initial driver for MxL862xx switches * poll switch readiness after reset * implement driver shutdown * added port_fast_aging API call and driver op * unified port setup in new .port_setup op * improve comment explaining special handlign for unaligned API read * various typos and formatting improvements Changes since RFC v2 1/4, 2/4, 3/4: unchanged 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix return value being uninitialized on error in mxl862xx_api_wrap() * add missing description in kerneldoc comment of struct mxl862xx_ss_sp_tag Changes since initial RFC 1/4 dt-bindings: net: dsa: add bindings for MaxLinear MxL862xx * better description in dt-bindings doc 2/4 net: dsa: add tag formats for MxL862xx switches * make sure all tag fields are initialized 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * new patch 4/4 net: dsa: add basic initial driver for MxL862xx switches * make use of struct mdio_device * add phylink_mac_ops stubs * drop leftover nonsense from mxl862xx_phylink_get_caps() * fix endian conversions * use __le32 instead of enum types in over-the-wire structs * use existing MDIO_* macros whenever possible * simplify API constants to be more readable * use readx_poll_timeout instead of open-coding poll timeout loop * add mxl862xx_reg_read() and mxl862xx_reg_write() helpers * demystify error codes returned by the firmware * add #defines for mxl862xx_ss_sp_tag member values * move reset to dedicated function, clarify magic number being the reset command ID Daniel Golle (4): dt-bindings: net: dsa: add MaxLinear MxL862xx net: dsa: add tag format for MxL862xx switches net: mdio: add unlocked mdiodev C45 bus accessors net: dsa: add basic initial driver for MxL862xx switches .../bindings/net/dsa/maxlinear,mxl862xx.yaml | 160 +++++ MAINTAINERS | 8 + drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/mxl862xx/Kconfig | 12 + drivers/net/dsa/mxl862xx/Makefile | 3 + drivers/net/dsa/mxl862xx/mxl862xx-api.h | 675 ++++++++++++++++++ drivers/net/dsa/mxl862xx/mxl862xx-cmd.h | 49 ++ drivers/net/dsa/mxl862xx/mxl862xx-host.c | 245 +++++++ drivers/net/dsa/mxl862xx/mxl862xx-host.h | 12 + drivers/net/dsa/mxl862xx/mxl862xx.c | 483 +++++++++++++ drivers/net/dsa/mxl862xx/mxl862xx.h | 16 + include/linux/mdio.h | 13 + include/net/dsa.h | 2 + net/dsa/Kconfig | 7 + net/dsa/Makefile | 1 + net/dsa/tag_mxl862xx.c | 110 +++ 17 files changed, 1799 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/maxlinear,mxl862xx.yaml create mode 100644 drivers/net/dsa/mxl862xx/Kconfig create mode 100644 drivers/net/dsa/mxl862xx/Makefile create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-api.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-cmd.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-host.c create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-host.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx.c create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx.h create mode 100644 net/dsa/tag_mxl862xx.c -- 2.52.0
Add documentation and an example for MaxLinear MxL86282 and MxL86252 switches. Signed-off-by: Daniel Golle <daniel@makrotopia.org> Reviewed-by: Rob Herring (Arm) <robh@kernel.org> --- v12: no changes v11: no changes v10: add microcontroller port 0 v9: no changes v8: no changes v7: no changes v6: no changes v5: no changes RFC v4: * remove labels from example * remove 'bindings for' from commit title RFC v3: no changes RFC v2: better description in dt-bindings doc --- .../bindings/net/dsa/maxlinear,mxl862xx.yaml | 160 ++++++++++++++++++ MAINTAINERS | 6 + 2 files changed, 166 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/maxlinear,mxl862xx.yaml diff --git a/Documentation/devicetree/bindings/net/dsa/maxlinear,mxl862xx.yaml b/Documentation/devicetree/bindings/net/dsa/maxlinear,mxl862xx.yaml new file mode 100644 index 000000000000..6a60e0881a49 --- /dev/null +++ b/Documentation/devicetree/bindings/net/dsa/maxlinear,mxl862xx.yaml @@ -0,0 +1,160 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/dsa/maxlinear,mxl862xx.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MaxLinear MxL862xx Ethernet Switch Family + +maintainers: + - Daniel Golle <daniel@makrotopia.org> + +description: + The MaxLinear MxL862xx switch family are multi-port Ethernet switches with + integrated 2.5GE PHYs. The MxL86252 has five PHY ports and the MxL86282 + has eight PHY ports. Both models come with two 10 Gigabit/s SerDes + interfaces to be used to connect external PHYs or SFP cages, or as CPU + port. + +allOf: + - $ref: dsa.yaml#/$defs/ethernet-ports + +properties: + compatible: + enum: + - maxlinear,mxl86252 + - maxlinear,mxl86282 + + reg: + maxItems: 1 + description: MDIO address of the switch + + mdio: + $ref: /schemas/net/mdio.yaml# + unevaluatedProperties: false + +required: + - compatible + - reg + +unevaluatedProperties: false + +examples: + - | + mdio { + #address-cells = <1>; + #size-cells = <0>; + + switch@0 { + compatible = "maxlinear,mxl86282"; + reg = <0>; + + ethernet-ports { + #address-cells = <1>; + #size-cells = <0>; + + /* Microcontroller port */ + port@0 { + reg = <0>; + status = "disabled"; + }; + + port@1 { + reg = <1>; + phy-handle = <&phy0>; + phy-mode = "internal"; + }; + + port@2 { + reg = <2>; + phy-handle = <&phy1>; + phy-mode = "internal"; + }; + + port@3 { + reg = <3>; + phy-handle = <&phy2>; + phy-mode = "internal"; + }; + + port@4 { + reg = <4>; + phy-handle = <&phy3>; + phy-mode = "internal"; + }; + + port@5 { + reg = <5>; + phy-handle = <&phy4>; + phy-mode = "internal"; + }; + + port@6 { + reg = <6>; + phy-handle = <&phy5>; + phy-mode = "internal"; + }; + + port@7 { + reg = <7>; + phy-handle = <&phy6>; + phy-mode = "internal"; + }; + + port@8 { + reg = <8>; + phy-handle = <&phy7>; + phy-mode = "internal"; + }; + + port@9 { + reg = <9>; + label = "cpu"; + ethernet = <&gmac0>; + phy-mode = "usxgmii"; + + fixed-link { + speed = <10000>; + full-duplex; + }; + }; + }; + + mdio { + #address-cells = <1>; + #size-cells = <0>; + + phy0: ethernet-phy@0 { + reg = <0>; + }; + + phy1: ethernet-phy@1 { + reg = <1>; + }; + + phy2: ethernet-phy@2 { + reg = <2>; + }; + + phy3: ethernet-phy@3 { + reg = <3>; + }; + + phy4: ethernet-phy@4 { + reg = <4>; + }; + + phy5: ethernet-phy@5 { + reg = <5>; + }; + + phy6: ethernet-phy@6 { + reg = <6>; + }; + + phy7: ethernet-phy@7 { + reg = <7>; + }; + }; + }; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 0caa8aee5840..1abcdbc54a3f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -15619,6 +15619,12 @@ S: Supported F: drivers/net/phy/mxl-86110.c F: drivers/net/phy/mxl-gpy.c +MAXLINEAR MXL862XX SWITCH DRIVER +M: Daniel Golle <daniel@makrotopia.org> +L: netdev@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/net/dsa/maxlinear,mxl862xx.yaml + MCAN DEVICE DRIVER M: Markus Schneider-Pargmann <msp@baylibre.com> L: linux-can@vger.kernel.org -- 2.52.0
{ "author": "Daniel Golle <daniel@makrotopia.org>", "date": "Sun, 1 Feb 2026 02:24:47 +0000", "thread_id": "aYDoTSySNt7vXazL@makrotopia.org.mbox.gz" }
lkml
[PATCH v12 0/4] net: dsa: initial support for MaxLinear MxL862xx switches
This series adds very basic DSA support for the MaxLinear MxL86252 (5x 2500Base-T PHYs) and MxL86282 (8x 2500Base-T PHYs) switches. In addition to the 2.5G TP ports both switches also come with two SerDes interfaces which can be used either to connect external PHYs or SFP cages, or as CPU port when using the switch with this DSA driver. MxL862xx integrates a firmware running on an embedded processor (based on Zephyr RTOS). Host interaction uses a simple netlink-like API transported over MDIO/MMD. This series includes only what's needed to pass traffic between user ports and the CPU port: relayed MDIO to internal PHYs, basic port enable/disable, and CPU-port special tagging. The SerDes interface of the CPU port is automatically configured by the switch after reset using a board-specific configuration stored together with the firmware in the flash chip attached to the switch, so no action is needed from the driver to setup the interface mode of the CPU port. Also MAC settings of the PHY ports are automatically configured, which means the driver works fine with phylink_mac_ops being all no-op stubs. Multiple follow up series will bring support for setting up the other SerDes PCS interface (ie. not used for the CPU port), bridge, VLAN, ... offloading, and support for using an 802.1Q-based special tag instead of the proprietary 8-byte tag. --- basic DSA selftests were run, results: * no_forwarding.sh: all tests PASS * bridge_vlan_unaware.sh: all tests PASS * bridge_vlan_mcast.sh: all tests PASS * bridge_vlan_aware.sh: all tests PASS * local_termination.sh: all tests PASS or XFAIL, except for TEST: VLAN over vlan_filtering=1 bridged port: Unicast IPv4 to unknown MAC address [FAIL] reception succeeded, but should have failed TEST: VLAN over vlan_filtering=1 bridged port: Unicast IPv4 to unknown MAC address, allmulti [FAIL] reception succeeded, but should have failed As obviously this is mostly testing the Linux software bridge at this point so I didn't bother to run any of the FDB or MDB related tests. Some mystery about the relationship between the sub-interface ID and CTP port assignment remains for now, so I cannot yet fully explain the magic numbers when calculating the two. (Why is it neccesary to allocate 23 CTPs when using port 9 as CPU port while there are at most 17 phyiscal interfaces in total, and only at most 13 when using one of the two SerDes as CPU interface? Why is there an offset of 16 when calculating the sub-interface ID? How will a total of 17 ports be possibly represented in a 4-bit field in the tag RX path?) At this point this doesn't impact functionality, and I hope for further clarification discussing all that with MaxLinear engineers. I believe the initial driver is anyway in good shape now, a follow-up series addressing configuring the SerDes interfaces will also have to take care of CTP assignment and sub-interfaces to not hit the mentioned 4-bit cap in the tag driver. Changes since v11: Address comments reported by Jakub Kicinski using netdev-ai https://patchwork.kernel.org/comment/26767905/ 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * list switch variants in Kconfig starting with dash ('-') * remove the __packed attribute on structs which are naturally packed according to C rules (ie. one other struct with only a single byte-aligned member) * log error in mxl862xx_port_disable() * introduce !NULL check for return value of dsa_to_port() in mxl862xx_add_single_port_bridge * check cpu_dp being non-NULL before dereferencing dp->cpu_dp * use non-racy and deterministic name for MII bus * skip ports without cpu_dp assigned in mxl862xx_setup_cpu_bridge() to avoid potential NULL-pointer dereference * call dev_set_drvdata() only after dsa_register_switch() has been successfully completed Changes since v10: 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * arrange local variables in reverse xmas tree order (again) * use MXL862_NAME as .name in struct dsa_device_ops 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix fatal last-second changes dsa_port_is_unused vs. dsa_is_unused_port and dsa_port_is_unused vs. dsa_is_unused_port * use cpu_to_le16 in mxl862xx_configure_ctp_port * improve formatting of some kerneldoc comments Changes since v9: 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * add microcontroller port 0 2/4 net: dsa: add tag format for MxL862xx switches * count ports starting from 0 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix indentation in kernel-doc * remove misleading comment regarding sub-interface IDs * remove unused macros, set MXL862XX_MAX_PORTS to 17 * count ports starting from 0, 0 being the microcontroller * improve port setup: - split tag protocol and CTP port assignment - use ports cpu_dp instead of relying on single (ie. first) CPU port - handle CPU port like any other port - prepare forward DT compatibility with multiple CPU ports Changes since v8: 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * remove practically unused struct hw_info * lots of kerneldoc improvements in mxl862xx-api.h * drop .mac_select_pcs() stub * better handling for firmware error return value * apply reverse xmas tree in mxl862xx_api_wrap * guard headers with #ifdef macro * include net/dsa.h and linux/mdio.h in mxl862xx.h * call mxl862xx_port_fast_age() only once in .port_setup * don't create isolation bridges for unused ports * replace errornous cast with correct range of values denoting firmware errors Changes since v7 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * use little-endian in bridge_port_config API * remove duplciate assignment of br_port_cfg.bridge_port_id when setting up CPU port Changes since v6 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix kerneldoc style Changes since RFC v5 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * remove unnecessary check for skb != NULL * merge consecutively printed warnings into single dev_warn_ratelimited 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * include bridge and bridgeport API needed to isolate ports * remove warning in .setup as ports are now isolated * make ready-after-reset check more robust by adding delay * sort structs in order of struct definitions * best effort to sort functions without introducing additional prototypes * always use enums with kerneldoc comments in mxl862xx-api.h * remove bogus .phy_read and .phy_write DSA ops as the driver anyway registers a user MDIO bus with Clause-22 and Clause-45 operations * various small style fixes Changes since RFC v4 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * drop unused precompiler macros 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * fix indentation 4/4 net: dsa: add basic initial driver for MxL862xx switches * output warning in .setup regarding unknown pre-configuration * add comment explaining why CFGGET is used in reset function Changes since RFC v3 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * remove labels from example * remove 'bindings for' from commit title 2/4 net: dsa: add tag format for MxL862xx switches * describe fields and variables with comments * sub-interface is only 5 bits * harmonize Kconfig symbol name * maintain alphabetic order in Kconfig * fix typo s/beginnig/beginning/ * fix typo s/swtiches/switches/ * arrange local variables in reverse xmas tree order 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * unchanged 4/4 net: dsa: add basic initial driver for MxL862xx switches * poll switch readiness after reset * implement driver shutdown * added port_fast_aging API call and driver op * unified port setup in new .port_setup op * improve comment explaining special handlign for unaligned API read * various typos and formatting improvements Changes since RFC v2 1/4, 2/4, 3/4: unchanged 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix return value being uninitialized on error in mxl862xx_api_wrap() * add missing description in kerneldoc comment of struct mxl862xx_ss_sp_tag Changes since initial RFC 1/4 dt-bindings: net: dsa: add bindings for MaxLinear MxL862xx * better description in dt-bindings doc 2/4 net: dsa: add tag formats for MxL862xx switches * make sure all tag fields are initialized 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * new patch 4/4 net: dsa: add basic initial driver for MxL862xx switches * make use of struct mdio_device * add phylink_mac_ops stubs * drop leftover nonsense from mxl862xx_phylink_get_caps() * fix endian conversions * use __le32 instead of enum types in over-the-wire structs * use existing MDIO_* macros whenever possible * simplify API constants to be more readable * use readx_poll_timeout instead of open-coding poll timeout loop * add mxl862xx_reg_read() and mxl862xx_reg_write() helpers * demystify error codes returned by the firmware * add #defines for mxl862xx_ss_sp_tag member values * move reset to dedicated function, clarify magic number being the reset command ID Daniel Golle (4): dt-bindings: net: dsa: add MaxLinear MxL862xx net: dsa: add tag format for MxL862xx switches net: mdio: add unlocked mdiodev C45 bus accessors net: dsa: add basic initial driver for MxL862xx switches .../bindings/net/dsa/maxlinear,mxl862xx.yaml | 160 +++++ MAINTAINERS | 8 + drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/mxl862xx/Kconfig | 12 + drivers/net/dsa/mxl862xx/Makefile | 3 + drivers/net/dsa/mxl862xx/mxl862xx-api.h | 675 ++++++++++++++++++ drivers/net/dsa/mxl862xx/mxl862xx-cmd.h | 49 ++ drivers/net/dsa/mxl862xx/mxl862xx-host.c | 245 +++++++ drivers/net/dsa/mxl862xx/mxl862xx-host.h | 12 + drivers/net/dsa/mxl862xx/mxl862xx.c | 483 +++++++++++++ drivers/net/dsa/mxl862xx/mxl862xx.h | 16 + include/linux/mdio.h | 13 + include/net/dsa.h | 2 + net/dsa/Kconfig | 7 + net/dsa/Makefile | 1 + net/dsa/tag_mxl862xx.c | 110 +++ 17 files changed, 1799 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/maxlinear,mxl862xx.yaml create mode 100644 drivers/net/dsa/mxl862xx/Kconfig create mode 100644 drivers/net/dsa/mxl862xx/Makefile create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-api.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-cmd.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-host.c create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-host.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx.c create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx.h create mode 100644 net/dsa/tag_mxl862xx.c -- 2.52.0
Add proprietary special tag format for the MaxLinear MXL862xx family of switches. While using the same Ethertype as MaxLinear's GSW1xx switches, the actual tag format differs significantly, hence we need a dedicated tag driver for that. Signed-off-by: Daniel Golle <daniel@makrotopia.org> --- v12: no changes v11: * arrange local variables in reverse xmas tree order (again) * use MXL862_NAME as .name in struct dsa_device_ops v10: count ports starting from 0 v9: no changes v8: no changes v7: no changes v6: * remove unnecessary check for skb != NULL * merge consecutively printed warnings into single dev_warn_ratelimited v5: * remove unused macro definitions RFC v4: * describe fields and variables with comments * sub-interface is only 5 bits * harmonize Kconfig symbol name * maintain alphabetic order in Kconfig * fix typo s/beginnig/beginning/ * fix typo s/swtiches/switches/ * arrange local variables in reverse xmas tree order RFC v3: no changes RFC v2: make sure all tag fields are initialized --- MAINTAINERS | 1 + include/net/dsa.h | 2 + net/dsa/Kconfig | 7 +++ net/dsa/Makefile | 1 + net/dsa/tag_mxl862xx.c | 110 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 121 insertions(+) create mode 100644 net/dsa/tag_mxl862xx.c diff --git a/MAINTAINERS b/MAINTAINERS index 1abcdbc54a3f..e64f423b3844 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -15624,6 +15624,7 @@ M: Daniel Golle <daniel@makrotopia.org> L: netdev@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/net/dsa/maxlinear,mxl862xx.yaml +F: net/dsa/tag_mxl862xx.c MCAN DEVICE DRIVER M: Markus Schneider-Pargmann <msp@baylibre.com> diff --git a/include/net/dsa.h b/include/net/dsa.h index 6b2b5ed64ea4..1e33242b6d94 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -57,6 +57,7 @@ struct tc_action; #define DSA_TAG_PROTO_BRCM_LEGACY_FCS_VALUE 29 #define DSA_TAG_PROTO_YT921X_VALUE 30 #define DSA_TAG_PROTO_MXL_GSW1XX_VALUE 31 +#define DSA_TAG_PROTO_MXL862_VALUE 32 enum dsa_tag_protocol { DSA_TAG_PROTO_NONE = DSA_TAG_PROTO_NONE_VALUE, @@ -91,6 +92,7 @@ enum dsa_tag_protocol { DSA_TAG_PROTO_VSC73XX_8021Q = DSA_TAG_PROTO_VSC73XX_8021Q_VALUE, DSA_TAG_PROTO_YT921X = DSA_TAG_PROTO_YT921X_VALUE, DSA_TAG_PROTO_MXL_GSW1XX = DSA_TAG_PROTO_MXL_GSW1XX_VALUE, + DSA_TAG_PROTO_MXL862 = DSA_TAG_PROTO_MXL862_VALUE, }; struct dsa_switch; diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig index f86b30742122..efc95759a10e 100644 --- a/net/dsa/Kconfig +++ b/net/dsa/Kconfig @@ -104,6 +104,13 @@ config NET_DSA_TAG_MTK Say Y or M if you want to enable support for tagging frames for Mediatek switches. +config NET_DSA_TAG_MXL_862XX + tristate "Tag driver for MxL862xx switches" + help + Say Y or M if you want to enable support for tagging frames for the + Maxlinear MxL86252 and MxL86282 switches using their native 8-byte + tagging protocol. + config NET_DSA_TAG_MXL_GSW1XX tristate "Tag driver for MaxLinear GSW1xx switches" help diff --git a/net/dsa/Makefile b/net/dsa/Makefile index 42d173f5a701..bf7247759a64 100644 --- a/net/dsa/Makefile +++ b/net/dsa/Makefile @@ -28,6 +28,7 @@ obj-$(CONFIG_NET_DSA_TAG_HELLCREEK) += tag_hellcreek.o obj-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o obj-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o obj-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o +obj-$(CONFIG_NET_DSA_TAG_MXL_862XX) += tag_mxl862xx.o obj-$(CONFIG_NET_DSA_TAG_MXL_GSW1XX) += tag_mxl-gsw1xx.o obj-$(CONFIG_NET_DSA_TAG_NONE) += tag_none.o obj-$(CONFIG_NET_DSA_TAG_OCELOT) += tag_ocelot.o diff --git a/net/dsa/tag_mxl862xx.c b/net/dsa/tag_mxl862xx.c new file mode 100644 index 000000000000..a0ec878e698e --- /dev/null +++ b/net/dsa/tag_mxl862xx.c @@ -0,0 +1,110 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * DSA Special Tag for MaxLinear 862xx switch chips + * + * Copyright (C) 2025 Daniel Golle <daniel@makrotopia.org> + * Copyright (C) 2024 MaxLinear Inc. + */ + +#include <linux/bitops.h> +#include <linux/etherdevice.h> +#include <linux/skbuff.h> +#include <net/dsa.h> +#include "tag.h" + +#define MXL862_NAME "mxl862xx" + +#define MXL862_HEADER_LEN 8 + +/* Word 0 -> EtherType */ + +/* Word 2 */ +#define MXL862_SUBIF_ID GENMASK(4, 0) + +/* Word 3 */ +#define MXL862_IGP_EGP GENMASK(3, 0) + +static struct sk_buff *mxl862_tag_xmit(struct sk_buff *skb, + struct net_device *dev) +{ + struct dsa_port *dp = dsa_user_to_port(dev); + struct dsa_port *cpu_dp = dp->cpu_dp; + unsigned int cpu_port, sub_interface; + __be16 *mxl862_tag; + + cpu_port = cpu_dp->index; + + /* target port sub-interface ID relative to the CPU port */ + sub_interface = dp->index + 16 - cpu_port; + + /* provide additional space 'MXL862_HEADER_LEN' bytes */ + skb_push(skb, MXL862_HEADER_LEN); + + /* shift MAC address to the beginning of the enlarged buffer, + * releasing the space required for DSA tag (between MAC address and + * Ethertype) + */ + dsa_alloc_etype_header(skb, MXL862_HEADER_LEN); + + /* special tag ingress */ + mxl862_tag = dsa_etype_header_pos_tx(skb); + mxl862_tag[0] = htons(ETH_P_MXLGSW); + mxl862_tag[1] = 0; + mxl862_tag[2] = htons(FIELD_PREP(MXL862_SUBIF_ID, sub_interface)); + mxl862_tag[3] = htons(FIELD_PREP(MXL862_IGP_EGP, cpu_port)); + + return skb; +} + +static struct sk_buff *mxl862_tag_rcv(struct sk_buff *skb, + struct net_device *dev) +{ + __be16 *mxl862_tag; + int port; + + if (unlikely(!pskb_may_pull(skb, MXL862_HEADER_LEN))) { + dev_warn_ratelimited(&dev->dev, "Cannot pull SKB, packet dropped\n"); + return NULL; + } + + mxl862_tag = dsa_etype_header_pos_rx(skb); + + if (unlikely(mxl862_tag[0] != htons(ETH_P_MXLGSW))) { + dev_warn_ratelimited(&dev->dev, + "Invalid special tag marker, packet dropped, tag: %8ph\n", + mxl862_tag); + return NULL; + } + + /* Get source port information */ + port = FIELD_GET(MXL862_IGP_EGP, ntohs(mxl862_tag[3])); + skb->dev = dsa_conduit_find_user(dev, 0, port); + if (unlikely(!skb->dev)) { + dev_warn_ratelimited(&dev->dev, + "Invalid source port, packet dropped, tag: %8ph\n", + mxl862_tag); + return NULL; + } + + /* remove the MxL862xx special tag between the MAC addresses and the + * current ethertype field. + */ + skb_pull_rcsum(skb, MXL862_HEADER_LEN); + dsa_strip_etype_header(skb, MXL862_HEADER_LEN); + + return skb; +} + +static const struct dsa_device_ops mxl862_netdev_ops = { + .name = MXL862_NAME, + .proto = DSA_TAG_PROTO_MXL862, + .xmit = mxl862_tag_xmit, + .rcv = mxl862_tag_rcv, + .needed_headroom = MXL862_HEADER_LEN, +}; + +MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_MXL862, MXL862_NAME); +MODULE_DESCRIPTION("DSA tag driver for MaxLinear MxL862xx switches"); +MODULE_LICENSE("GPL"); + +module_dsa_tag_driver(mxl862_netdev_ops); -- 2.52.0
{ "author": "Daniel Golle <daniel@makrotopia.org>", "date": "Sun, 1 Feb 2026 02:24:56 +0000", "thread_id": "aYDoTSySNt7vXazL@makrotopia.org.mbox.gz" }
lkml
[PATCH v12 0/4] net: dsa: initial support for MaxLinear MxL862xx switches
This series adds very basic DSA support for the MaxLinear MxL86252 (5x 2500Base-T PHYs) and MxL86282 (8x 2500Base-T PHYs) switches. In addition to the 2.5G TP ports both switches also come with two SerDes interfaces which can be used either to connect external PHYs or SFP cages, or as CPU port when using the switch with this DSA driver. MxL862xx integrates a firmware running on an embedded processor (based on Zephyr RTOS). Host interaction uses a simple netlink-like API transported over MDIO/MMD. This series includes only what's needed to pass traffic between user ports and the CPU port: relayed MDIO to internal PHYs, basic port enable/disable, and CPU-port special tagging. The SerDes interface of the CPU port is automatically configured by the switch after reset using a board-specific configuration stored together with the firmware in the flash chip attached to the switch, so no action is needed from the driver to setup the interface mode of the CPU port. Also MAC settings of the PHY ports are automatically configured, which means the driver works fine with phylink_mac_ops being all no-op stubs. Multiple follow up series will bring support for setting up the other SerDes PCS interface (ie. not used for the CPU port), bridge, VLAN, ... offloading, and support for using an 802.1Q-based special tag instead of the proprietary 8-byte tag. --- basic DSA selftests were run, results: * no_forwarding.sh: all tests PASS * bridge_vlan_unaware.sh: all tests PASS * bridge_vlan_mcast.sh: all tests PASS * bridge_vlan_aware.sh: all tests PASS * local_termination.sh: all tests PASS or XFAIL, except for TEST: VLAN over vlan_filtering=1 bridged port: Unicast IPv4 to unknown MAC address [FAIL] reception succeeded, but should have failed TEST: VLAN over vlan_filtering=1 bridged port: Unicast IPv4 to unknown MAC address, allmulti [FAIL] reception succeeded, but should have failed As obviously this is mostly testing the Linux software bridge at this point so I didn't bother to run any of the FDB or MDB related tests. Some mystery about the relationship between the sub-interface ID and CTP port assignment remains for now, so I cannot yet fully explain the magic numbers when calculating the two. (Why is it neccesary to allocate 23 CTPs when using port 9 as CPU port while there are at most 17 phyiscal interfaces in total, and only at most 13 when using one of the two SerDes as CPU interface? Why is there an offset of 16 when calculating the sub-interface ID? How will a total of 17 ports be possibly represented in a 4-bit field in the tag RX path?) At this point this doesn't impact functionality, and I hope for further clarification discussing all that with MaxLinear engineers. I believe the initial driver is anyway in good shape now, a follow-up series addressing configuring the SerDes interfaces will also have to take care of CTP assignment and sub-interfaces to not hit the mentioned 4-bit cap in the tag driver. Changes since v11: Address comments reported by Jakub Kicinski using netdev-ai https://patchwork.kernel.org/comment/26767905/ 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * list switch variants in Kconfig starting with dash ('-') * remove the __packed attribute on structs which are naturally packed according to C rules (ie. one other struct with only a single byte-aligned member) * log error in mxl862xx_port_disable() * introduce !NULL check for return value of dsa_to_port() in mxl862xx_add_single_port_bridge * check cpu_dp being non-NULL before dereferencing dp->cpu_dp * use non-racy and deterministic name for MII bus * skip ports without cpu_dp assigned in mxl862xx_setup_cpu_bridge() to avoid potential NULL-pointer dereference * call dev_set_drvdata() only after dsa_register_switch() has been successfully completed Changes since v10: 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * arrange local variables in reverse xmas tree order (again) * use MXL862_NAME as .name in struct dsa_device_ops 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix fatal last-second changes dsa_port_is_unused vs. dsa_is_unused_port and dsa_port_is_unused vs. dsa_is_unused_port * use cpu_to_le16 in mxl862xx_configure_ctp_port * improve formatting of some kerneldoc comments Changes since v9: 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * add microcontroller port 0 2/4 net: dsa: add tag format for MxL862xx switches * count ports starting from 0 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix indentation in kernel-doc * remove misleading comment regarding sub-interface IDs * remove unused macros, set MXL862XX_MAX_PORTS to 17 * count ports starting from 0, 0 being the microcontroller * improve port setup: - split tag protocol and CTP port assignment - use ports cpu_dp instead of relying on single (ie. first) CPU port - handle CPU port like any other port - prepare forward DT compatibility with multiple CPU ports Changes since v8: 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * remove practically unused struct hw_info * lots of kerneldoc improvements in mxl862xx-api.h * drop .mac_select_pcs() stub * better handling for firmware error return value * apply reverse xmas tree in mxl862xx_api_wrap * guard headers with #ifdef macro * include net/dsa.h and linux/mdio.h in mxl862xx.h * call mxl862xx_port_fast_age() only once in .port_setup * don't create isolation bridges for unused ports * replace errornous cast with correct range of values denoting firmware errors Changes since v7 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * use little-endian in bridge_port_config API * remove duplciate assignment of br_port_cfg.bridge_port_id when setting up CPU port Changes since v6 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix kerneldoc style Changes since RFC v5 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * remove unnecessary check for skb != NULL * merge consecutively printed warnings into single dev_warn_ratelimited 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * include bridge and bridgeport API needed to isolate ports * remove warning in .setup as ports are now isolated * make ready-after-reset check more robust by adding delay * sort structs in order of struct definitions * best effort to sort functions without introducing additional prototypes * always use enums with kerneldoc comments in mxl862xx-api.h * remove bogus .phy_read and .phy_write DSA ops as the driver anyway registers a user MDIO bus with Clause-22 and Clause-45 operations * various small style fixes Changes since RFC v4 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * drop unused precompiler macros 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * fix indentation 4/4 net: dsa: add basic initial driver for MxL862xx switches * output warning in .setup regarding unknown pre-configuration * add comment explaining why CFGGET is used in reset function Changes since RFC v3 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * remove labels from example * remove 'bindings for' from commit title 2/4 net: dsa: add tag format for MxL862xx switches * describe fields and variables with comments * sub-interface is only 5 bits * harmonize Kconfig symbol name * maintain alphabetic order in Kconfig * fix typo s/beginnig/beginning/ * fix typo s/swtiches/switches/ * arrange local variables in reverse xmas tree order 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * unchanged 4/4 net: dsa: add basic initial driver for MxL862xx switches * poll switch readiness after reset * implement driver shutdown * added port_fast_aging API call and driver op * unified port setup in new .port_setup op * improve comment explaining special handlign for unaligned API read * various typos and formatting improvements Changes since RFC v2 1/4, 2/4, 3/4: unchanged 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix return value being uninitialized on error in mxl862xx_api_wrap() * add missing description in kerneldoc comment of struct mxl862xx_ss_sp_tag Changes since initial RFC 1/4 dt-bindings: net: dsa: add bindings for MaxLinear MxL862xx * better description in dt-bindings doc 2/4 net: dsa: add tag formats for MxL862xx switches * make sure all tag fields are initialized 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * new patch 4/4 net: dsa: add basic initial driver for MxL862xx switches * make use of struct mdio_device * add phylink_mac_ops stubs * drop leftover nonsense from mxl862xx_phylink_get_caps() * fix endian conversions * use __le32 instead of enum types in over-the-wire structs * use existing MDIO_* macros whenever possible * simplify API constants to be more readable * use readx_poll_timeout instead of open-coding poll timeout loop * add mxl862xx_reg_read() and mxl862xx_reg_write() helpers * demystify error codes returned by the firmware * add #defines for mxl862xx_ss_sp_tag member values * move reset to dedicated function, clarify magic number being the reset command ID Daniel Golle (4): dt-bindings: net: dsa: add MaxLinear MxL862xx net: dsa: add tag format for MxL862xx switches net: mdio: add unlocked mdiodev C45 bus accessors net: dsa: add basic initial driver for MxL862xx switches .../bindings/net/dsa/maxlinear,mxl862xx.yaml | 160 +++++ MAINTAINERS | 8 + drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/mxl862xx/Kconfig | 12 + drivers/net/dsa/mxl862xx/Makefile | 3 + drivers/net/dsa/mxl862xx/mxl862xx-api.h | 675 ++++++++++++++++++ drivers/net/dsa/mxl862xx/mxl862xx-cmd.h | 49 ++ drivers/net/dsa/mxl862xx/mxl862xx-host.c | 245 +++++++ drivers/net/dsa/mxl862xx/mxl862xx-host.h | 12 + drivers/net/dsa/mxl862xx/mxl862xx.c | 483 +++++++++++++ drivers/net/dsa/mxl862xx/mxl862xx.h | 16 + include/linux/mdio.h | 13 + include/net/dsa.h | 2 + net/dsa/Kconfig | 7 + net/dsa/Makefile | 1 + net/dsa/tag_mxl862xx.c | 110 +++ 17 files changed, 1799 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/maxlinear,mxl862xx.yaml create mode 100644 drivers/net/dsa/mxl862xx/Kconfig create mode 100644 drivers/net/dsa/mxl862xx/Makefile create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-api.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-cmd.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-host.c create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-host.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx.c create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx.h create mode 100644 net/dsa/tag_mxl862xx.c -- 2.52.0
Add helper inline functions __mdiodev_c45_read() and __mdiodev_c45_write(), which are the C45 equivalents of the existing __mdiodev_read() and __mdiodev_write() added by commit e6a45700e7e1 ("net: mdio: add unlocked mdiobus and mdiodev bus accessors") Signed-off-by: Daniel Golle <daniel@makrotopia.org> --- v12: no changes v11: no changes v10: no changes v9: no changes v8: no changes v7: no changes v6: no changes v5: fix indentation RFC v4: no changes RFC v3: no changes RFC v2: add this patch, initial submission --- include/linux/mdio.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/mdio.h b/include/linux/mdio.h index 42d6d47e445b..52d94b8ae371 100644 --- a/include/linux/mdio.h +++ b/include/linux/mdio.h @@ -648,6 +648,19 @@ static inline int mdiodev_modify_changed(struct mdio_device *mdiodev, mask, set); } +static inline int __mdiodev_c45_read(struct mdio_device *mdiodev, int devad, + u16 regnum) +{ + return __mdiobus_c45_read(mdiodev->bus, mdiodev->addr, devad, regnum); +} + +static inline int __mdiodev_c45_write(struct mdio_device *mdiodev, u32 devad, + u16 regnum, u16 val) +{ + return __mdiobus_c45_write(mdiodev->bus, mdiodev->addr, devad, regnum, + val); +} + static inline int mdiodev_c45_modify(struct mdio_device *mdiodev, int devad, u32 regnum, u16 mask, u16 set) { -- 2.52.0
{ "author": "Daniel Golle <daniel@makrotopia.org>", "date": "Sun, 1 Feb 2026 02:25:03 +0000", "thread_id": "aYDoTSySNt7vXazL@makrotopia.org.mbox.gz" }
lkml
[PATCH v12 0/4] net: dsa: initial support for MaxLinear MxL862xx switches
This series adds very basic DSA support for the MaxLinear MxL86252 (5x 2500Base-T PHYs) and MxL86282 (8x 2500Base-T PHYs) switches. In addition to the 2.5G TP ports both switches also come with two SerDes interfaces which can be used either to connect external PHYs or SFP cages, or as CPU port when using the switch with this DSA driver. MxL862xx integrates a firmware running on an embedded processor (based on Zephyr RTOS). Host interaction uses a simple netlink-like API transported over MDIO/MMD. This series includes only what's needed to pass traffic between user ports and the CPU port: relayed MDIO to internal PHYs, basic port enable/disable, and CPU-port special tagging. The SerDes interface of the CPU port is automatically configured by the switch after reset using a board-specific configuration stored together with the firmware in the flash chip attached to the switch, so no action is needed from the driver to setup the interface mode of the CPU port. Also MAC settings of the PHY ports are automatically configured, which means the driver works fine with phylink_mac_ops being all no-op stubs. Multiple follow up series will bring support for setting up the other SerDes PCS interface (ie. not used for the CPU port), bridge, VLAN, ... offloading, and support for using an 802.1Q-based special tag instead of the proprietary 8-byte tag. --- basic DSA selftests were run, results: * no_forwarding.sh: all tests PASS * bridge_vlan_unaware.sh: all tests PASS * bridge_vlan_mcast.sh: all tests PASS * bridge_vlan_aware.sh: all tests PASS * local_termination.sh: all tests PASS or XFAIL, except for TEST: VLAN over vlan_filtering=1 bridged port: Unicast IPv4 to unknown MAC address [FAIL] reception succeeded, but should have failed TEST: VLAN over vlan_filtering=1 bridged port: Unicast IPv4 to unknown MAC address, allmulti [FAIL] reception succeeded, but should have failed As obviously this is mostly testing the Linux software bridge at this point so I didn't bother to run any of the FDB or MDB related tests. Some mystery about the relationship between the sub-interface ID and CTP port assignment remains for now, so I cannot yet fully explain the magic numbers when calculating the two. (Why is it neccesary to allocate 23 CTPs when using port 9 as CPU port while there are at most 17 phyiscal interfaces in total, and only at most 13 when using one of the two SerDes as CPU interface? Why is there an offset of 16 when calculating the sub-interface ID? How will a total of 17 ports be possibly represented in a 4-bit field in the tag RX path?) At this point this doesn't impact functionality, and I hope for further clarification discussing all that with MaxLinear engineers. I believe the initial driver is anyway in good shape now, a follow-up series addressing configuring the SerDes interfaces will also have to take care of CTP assignment and sub-interfaces to not hit the mentioned 4-bit cap in the tag driver. Changes since v11: Address comments reported by Jakub Kicinski using netdev-ai https://patchwork.kernel.org/comment/26767905/ 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * list switch variants in Kconfig starting with dash ('-') * remove the __packed attribute on structs which are naturally packed according to C rules (ie. one other struct with only a single byte-aligned member) * log error in mxl862xx_port_disable() * introduce !NULL check for return value of dsa_to_port() in mxl862xx_add_single_port_bridge * check cpu_dp being non-NULL before dereferencing dp->cpu_dp * use non-racy and deterministic name for MII bus * skip ports without cpu_dp assigned in mxl862xx_setup_cpu_bridge() to avoid potential NULL-pointer dereference * call dev_set_drvdata() only after dsa_register_switch() has been successfully completed Changes since v10: 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * arrange local variables in reverse xmas tree order (again) * use MXL862_NAME as .name in struct dsa_device_ops 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix fatal last-second changes dsa_port_is_unused vs. dsa_is_unused_port and dsa_port_is_unused vs. dsa_is_unused_port * use cpu_to_le16 in mxl862xx_configure_ctp_port * improve formatting of some kerneldoc comments Changes since v9: 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * add microcontroller port 0 2/4 net: dsa: add tag format for MxL862xx switches * count ports starting from 0 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix indentation in kernel-doc * remove misleading comment regarding sub-interface IDs * remove unused macros, set MXL862XX_MAX_PORTS to 17 * count ports starting from 0, 0 being the microcontroller * improve port setup: - split tag protocol and CTP port assignment - use ports cpu_dp instead of relying on single (ie. first) CPU port - handle CPU port like any other port - prepare forward DT compatibility with multiple CPU ports Changes since v8: 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * remove practically unused struct hw_info * lots of kerneldoc improvements in mxl862xx-api.h * drop .mac_select_pcs() stub * better handling for firmware error return value * apply reverse xmas tree in mxl862xx_api_wrap * guard headers with #ifdef macro * include net/dsa.h and linux/mdio.h in mxl862xx.h * call mxl862xx_port_fast_age() only once in .port_setup * don't create isolation bridges for unused ports * replace errornous cast with correct range of values denoting firmware errors Changes since v7 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * use little-endian in bridge_port_config API * remove duplciate assignment of br_port_cfg.bridge_port_id when setting up CPU port Changes since v6 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix kerneldoc style Changes since RFC v5 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * remove unnecessary check for skb != NULL * merge consecutively printed warnings into single dev_warn_ratelimited 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * include bridge and bridgeport API needed to isolate ports * remove warning in .setup as ports are now isolated * make ready-after-reset check more robust by adding delay * sort structs in order of struct definitions * best effort to sort functions without introducing additional prototypes * always use enums with kerneldoc comments in mxl862xx-api.h * remove bogus .phy_read and .phy_write DSA ops as the driver anyway registers a user MDIO bus with Clause-22 and Clause-45 operations * various small style fixes Changes since RFC v4 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * drop unused precompiler macros 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * fix indentation 4/4 net: dsa: add basic initial driver for MxL862xx switches * output warning in .setup regarding unknown pre-configuration * add comment explaining why CFGGET is used in reset function Changes since RFC v3 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * remove labels from example * remove 'bindings for' from commit title 2/4 net: dsa: add tag format for MxL862xx switches * describe fields and variables with comments * sub-interface is only 5 bits * harmonize Kconfig symbol name * maintain alphabetic order in Kconfig * fix typo s/beginnig/beginning/ * fix typo s/swtiches/switches/ * arrange local variables in reverse xmas tree order 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * unchanged 4/4 net: dsa: add basic initial driver for MxL862xx switches * poll switch readiness after reset * implement driver shutdown * added port_fast_aging API call and driver op * unified port setup in new .port_setup op * improve comment explaining special handlign for unaligned API read * various typos and formatting improvements Changes since RFC v2 1/4, 2/4, 3/4: unchanged 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix return value being uninitialized on error in mxl862xx_api_wrap() * add missing description in kerneldoc comment of struct mxl862xx_ss_sp_tag Changes since initial RFC 1/4 dt-bindings: net: dsa: add bindings for MaxLinear MxL862xx * better description in dt-bindings doc 2/4 net: dsa: add tag formats for MxL862xx switches * make sure all tag fields are initialized 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * new patch 4/4 net: dsa: add basic initial driver for MxL862xx switches * make use of struct mdio_device * add phylink_mac_ops stubs * drop leftover nonsense from mxl862xx_phylink_get_caps() * fix endian conversions * use __le32 instead of enum types in over-the-wire structs * use existing MDIO_* macros whenever possible * simplify API constants to be more readable * use readx_poll_timeout instead of open-coding poll timeout loop * add mxl862xx_reg_read() and mxl862xx_reg_write() helpers * demystify error codes returned by the firmware * add #defines for mxl862xx_ss_sp_tag member values * move reset to dedicated function, clarify magic number being the reset command ID Daniel Golle (4): dt-bindings: net: dsa: add MaxLinear MxL862xx net: dsa: add tag format for MxL862xx switches net: mdio: add unlocked mdiodev C45 bus accessors net: dsa: add basic initial driver for MxL862xx switches .../bindings/net/dsa/maxlinear,mxl862xx.yaml | 160 +++++ MAINTAINERS | 8 + drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/mxl862xx/Kconfig | 12 + drivers/net/dsa/mxl862xx/Makefile | 3 + drivers/net/dsa/mxl862xx/mxl862xx-api.h | 675 ++++++++++++++++++ drivers/net/dsa/mxl862xx/mxl862xx-cmd.h | 49 ++ drivers/net/dsa/mxl862xx/mxl862xx-host.c | 245 +++++++ drivers/net/dsa/mxl862xx/mxl862xx-host.h | 12 + drivers/net/dsa/mxl862xx/mxl862xx.c | 483 +++++++++++++ drivers/net/dsa/mxl862xx/mxl862xx.h | 16 + include/linux/mdio.h | 13 + include/net/dsa.h | 2 + net/dsa/Kconfig | 7 + net/dsa/Makefile | 1 + net/dsa/tag_mxl862xx.c | 110 +++ 17 files changed, 1799 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/maxlinear,mxl862xx.yaml create mode 100644 drivers/net/dsa/mxl862xx/Kconfig create mode 100644 drivers/net/dsa/mxl862xx/Makefile create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-api.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-cmd.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-host.c create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-host.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx.c create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx.h create mode 100644 net/dsa/tag_mxl862xx.c -- 2.52.0
Add very basic DSA driver for MaxLinear's MxL862xx switches. In contrast to previous MaxLinear switches the MxL862xx has a built-in processor that runs a sophisticated firmware based on Zephyr RTOS. Interaction between the host and the switch hence is organized using a software API of that firmware rather than accessing hardware registers directly. Add descriptions of the most basic firmware API calls to access the built-in MDIO bus hosting the 2.5GE PHYs, basic port control as well as setting up the CPU port. Implement a very basic DSA driver using that API which is sufficient to get packets flowing between the user ports and the CPU port. The firmware offers all features one would expect from a modern switch hardware, they are going to be added one by one in follow-up patch series. Signed-off-by: Daniel Golle <daniel@makrotopia.org> --- v12: * list switch variants in Kconfig starting with dash ('-') * remove the __packed attribute on structs which are naturally packed according to C rules (ie. one other struct with only a single byte-aligned member) * log error in mxl862xx_port_disable() * introduce !NULL check for return value of dsa_to_port() in mxl862xx_add_single_port_bridge * check cpu_dp being non-NULL before dereferencing dp->cpu_dp * use non-racy and deterministic name for MII bus * skip ports without cpu_dp assigned in mxl862xx_setup_cpu_bridge() to avoid potential NULL-pointer dereference * call dev_set_drvdata() only after dsa_register_switch() has been successfully completed v11: * fix fatal last-second changes dsa_port_is_unused vs. dsa_is_unused_port and dsa_port_is_unused vs. dsa_is_unused_port * use cpu_to_le16 in mxl862xx_configure_ctp_port * improve formatting of some kerneldoc comments v10: * fix indentation in kernel-doc * remove misleading comment regarding sub-interface IDs * remove unused macros, set MXL862XX_MAX_PORTS to 17 * count ports starting from 0, 0 being the microcontroller * improve port setup: - split tag protocol and CTP port assignment - use ports cpu_dp instead of relying on single (ie. first) CPU port - handle CPU port like any other port - prepare forward DT compatibility with multiple CPU ports v9: * remove practically unused struct hw_info * lots of kerneldoc improvements in mxl862xx-api.h * drop .mac_select_pcs() stub * better handling for firmware error return value * apply reverse xmas tree in mxl862xx_api_wrap * guard headers with #ifdef macro * include net/dsa.h and linux/mdio.h in mxl862xx.h * call mxl862xx_port_fast_age() only once in .port_setup * don't create isolation bridges for unused ports * replace errornous cast with correct range of values denoting firmware errors v8: * use le32 endian in bridge_port_config API * remove duplciate assignment of br_port_cfg.bridge_port_id when setting up CPU port v7: * fix kerneldoc style v6: * include bridge and bridgeport API needed to isolate ports * remove warning in .setup as ports are now isolated * make ready-after-reset check more robust by adding delay * sort structs in order of struct definitions * best effort to sort functions without introducing additional prototypes * always use enums with kerneldoc comments in mxl862xx-api.h * remove bogus .phy_read and .phy_write DSA ops as the driver anyway registers a user MDIO bus with Clause-22 and Clause-45 operations * various small style fixes v5: * output warning in .setup regarding unknown pre-configuration * add comment explaining why CFGGET is used in reset function RFC v4: * poll switch readiness after reset * implement driver shutdown * added port_fast_aging API call and driver op * unified port setup in new .port_setup op * improve comment explaining special handlign for unaligned API read * various typos RFC v3: * fix return value being uninitialized on error in mxl862xx_api_wrap() * add missing descrition in kerneldoc comment of struct mxl862xx_ss_sp_tag RFC v2: * make use of struct mdio_device * add phylink_mac_ops stubs * drop leftover nonsense from mxl862xx_phylink_get_caps() * use __le32 instead of enum types in over-the-wire structs * use existing MDIO_* macros whenever possible * simplify API constants to be more readable * use readx_poll_timeout instead of open-coding poll timeout loop * add mxl862xx_reg_read() and mxl862xx_reg_write() helpers * demystify error codes returned by the firmware * add #defines for mxl862xx_ss_sp_tag member values * move reset to dedicated function, clarify magic number being the reset command ID --- MAINTAINERS | 1 + drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/mxl862xx/Kconfig | 12 + drivers/net/dsa/mxl862xx/Makefile | 3 + drivers/net/dsa/mxl862xx/mxl862xx-api.h | 675 +++++++++++++++++++++++ drivers/net/dsa/mxl862xx/mxl862xx-cmd.h | 49 ++ drivers/net/dsa/mxl862xx/mxl862xx-host.c | 245 ++++++++ drivers/net/dsa/mxl862xx/mxl862xx-host.h | 12 + drivers/net/dsa/mxl862xx/mxl862xx.c | 483 ++++++++++++++++ drivers/net/dsa/mxl862xx/mxl862xx.h | 16 + 11 files changed, 1499 insertions(+) create mode 100644 drivers/net/dsa/mxl862xx/Kconfig create mode 100644 drivers/net/dsa/mxl862xx/Makefile create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-api.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-cmd.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-host.c create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-host.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx.c create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx.h diff --git a/MAINTAINERS b/MAINTAINERS index e64f423b3844..28449b299f1f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -15624,6 +15624,7 @@ M: Daniel Golle <daniel@makrotopia.org> L: netdev@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/net/dsa/maxlinear,mxl862xx.yaml +F: drivers/net/dsa/mxl862xx/ F: net/dsa/tag_mxl862xx.c MCAN DEVICE DRIVER diff --git a/drivers/net/dsa/Kconfig b/drivers/net/dsa/Kconfig index 7eb301fd987d..18f6e8b7f4cb 100644 --- a/drivers/net/dsa/Kconfig +++ b/drivers/net/dsa/Kconfig @@ -74,6 +74,8 @@ source "drivers/net/dsa/microchip/Kconfig" source "drivers/net/dsa/mv88e6xxx/Kconfig" +source "drivers/net/dsa/mxl862xx/Kconfig" + source "drivers/net/dsa/ocelot/Kconfig" source "drivers/net/dsa/qca/Kconfig" diff --git a/drivers/net/dsa/Makefile b/drivers/net/dsa/Makefile index 16de4ba3fa38..f5a463b87ec2 100644 --- a/drivers/net/dsa/Makefile +++ b/drivers/net/dsa/Makefile @@ -20,6 +20,7 @@ obj-y += hirschmann/ obj-y += lantiq/ obj-y += microchip/ obj-y += mv88e6xxx/ +obj-y += mxl862xx/ obj-y += ocelot/ obj-y += qca/ obj-y += realtek/ diff --git a/drivers/net/dsa/mxl862xx/Kconfig b/drivers/net/dsa/mxl862xx/Kconfig new file mode 100644 index 000000000000..4db7bab21a71 --- /dev/null +++ b/drivers/net/dsa/mxl862xx/Kconfig @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0-only +config NET_DSA_MXL862 + tristate "MaxLinear MxL862xx" + depends on NET_DSA + select MAXLINEAR_GPHY + select NET_DSA_TAG_MXL_862XX + help + This enables support for the MaxLinear MxL862xx switch family. + These switches have two 10GE SerDes interfaces, one typically + used as CPU port. + - MxL86282 has eight 2.5 Gigabit PHYs + - MxL86252 has five 2.5 Gigabit PHYs diff --git a/drivers/net/dsa/mxl862xx/Makefile b/drivers/net/dsa/mxl862xx/Makefile new file mode 100644 index 000000000000..d23dd3cd511d --- /dev/null +++ b/drivers/net/dsa/mxl862xx/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_NET_DSA_MXL862) += mxl862xx_dsa.o +mxl862xx_dsa-y := mxl862xx.o mxl862xx-host.o diff --git a/drivers/net/dsa/mxl862xx/mxl862xx-api.h b/drivers/net/dsa/mxl862xx/mxl862xx-api.h new file mode 100644 index 000000000000..a9f599dbca25 --- /dev/null +++ b/drivers/net/dsa/mxl862xx/mxl862xx-api.h @@ -0,0 +1,675 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef __MXL862XX_API_H +#define __MXL862XX_API_H + +#include <linux/if_ether.h> + +/** + * struct mdio_relay_data - relayed access to the switch internal MDIO bus + * @data: data to be read or written + * @phy: PHY index + * @mmd: MMD device + * @reg: register index + */ +struct mdio_relay_data { + __le16 data; + u8 phy; + u8 mmd; + __le16 reg; +} __packed; + +/** + * struct mxl862xx_register_mod - Register access parameter to directly + * modify internal registers + * @addr: Register address offset for modification + * @data: Value to write to the register address + * @mask: Mask of bits to be modified (1 to modify, 0 to ignore) + * + * Used for direct register modification operations. + */ +struct mxl862xx_register_mod { + __le16 addr; + __le16 data; + __le16 mask; +} __packed; + +/** + * enum mxl862xx_mac_clear_type - MAC table clear type + * @MXL862XX_MAC_CLEAR_PHY_PORT: clear dynamic entries based on port_id + * @MXL862XX_MAC_CLEAR_DYNAMIC: clear all dynamic entries + */ +enum mxl862xx_mac_clear_type { + MXL862XX_MAC_CLEAR_PHY_PORT = 0, + MXL862XX_MAC_CLEAR_DYNAMIC, +}; + +/** + * struct mxl862xx_mac_table_clear - MAC table clear + * @type: see &enum mxl862xx_mac_clear_type + * @port_id: physical port id + */ +struct mxl862xx_mac_table_clear { + u8 type; + u8 port_id; +} __packed; + +/** + * enum mxl862xx_age_timer - Aging Timer Value. + * @MXL862XX_AGETIMER_1_SEC: 1 second aging time + * @MXL862XX_AGETIMER_10_SEC: 10 seconds aging time + * @MXL862XX_AGETIMER_300_SEC: 300 seconds aging time + * @MXL862XX_AGETIMER_1_HOUR: 1 hour aging time + * @MXL862XX_AGETIMER_1_DAY: 24 hours aging time + * @MXL862XX_AGETIMER_CUSTOM: Custom aging time in seconds + */ +enum mxl862xx_age_timer { + MXL862XX_AGETIMER_1_SEC = 1, + MXL862XX_AGETIMER_10_SEC, + MXL862XX_AGETIMER_300_SEC, + MXL862XX_AGETIMER_1_HOUR, + MXL862XX_AGETIMER_1_DAY, + MXL862XX_AGETIMER_CUSTOM, +}; + +/** + * struct mxl862xx_bridge_alloc - Bridge Allocation + * @bridge_id: If the bridge allocation is successful, a valid ID will be + * returned in this field. Otherwise, INVALID_HANDLE is + * returned. For bridge free, this field should contain a + * valid ID returned by the bridge allocation. ID 0 is not + * used for historic reasons. + * + * Used by MXL862XX_BRIDGE_ALLOC and MXL862XX_BRIDGE_FREE. + */ +struct mxl862xx_bridge_alloc { + __le16 bridge_id; +}; + +/** + * enum mxl862xx_bridge_config_mask - Bridge configuration mask + * @MXL862XX_BRIDGE_CONFIG_MASK_MAC_LEARNING_LIMIT: + * Mask for mac_learning_limit_enable and mac_learning_limit. + * @MXL862XX_BRIDGE_CONFIG_MASK_MAC_LEARNED_COUNT: + * Mask for mac_learning_count + * @MXL862XX_BRIDGE_CONFIG_MASK_MAC_DISCARD_COUNT: + * Mask for learning_discard_event + * @MXL862XX_BRIDGE_CONFIG_MASK_SUB_METER: + * Mask for sub_metering_enable and traffic_sub_meter_id + * @MXL862XX_BRIDGE_CONFIG_MASK_FORWARDING_MODE: + * Mask for forward_broadcast, forward_unknown_multicast_ip, + * forward_unknown_multicast_non_ip and forward_unknown_unicast. + * @MXL862XX_BRIDGE_CONFIG_MASK_ALL: Enable all + * @MXL862XX_BRIDGE_CONFIG_MASK_FORCE: Bypass any check for debug purpose + */ +enum mxl862xx_bridge_config_mask { + MXL862XX_BRIDGE_CONFIG_MASK_MAC_LEARNING_LIMIT = BIT(0), + MXL862XX_BRIDGE_CONFIG_MASK_MAC_LEARNED_COUNT = BIT(1), + MXL862XX_BRIDGE_CONFIG_MASK_MAC_DISCARD_COUNT = BIT(2), + MXL862XX_BRIDGE_CONFIG_MASK_SUB_METER = BIT(3), + MXL862XX_BRIDGE_CONFIG_MASK_FORWARDING_MODE = BIT(4), + MXL862XX_BRIDGE_CONFIG_MASK_ALL = 0x7FFFFFFF, + MXL862XX_BRIDGE_CONFIG_MASK_FORCE = BIT(31) +}; + +/** + * enum mxl862xx_bridge_port_egress_meter - Meters for egress traffic type + * @MXL862XX_BRIDGE_PORT_EGRESS_METER_BROADCAST: + * Index of broadcast traffic meter + * @MXL862XX_BRIDGE_PORT_EGRESS_METER_MULTICAST: + * Index of known multicast traffic meter + * @MXL862XX_BRIDGE_PORT_EGRESS_METER_UNKNOWN_MC_IP: + * Index of unknown multicast IP traffic meter + * @MXL862XX_BRIDGE_PORT_EGRESS_METER_UNKNOWN_MC_NON_IP: + * Index of unknown multicast non-IP traffic meter + * @MXL862XX_BRIDGE_PORT_EGRESS_METER_UNKNOWN_UC: + * Index of unknown unicast traffic meter + * @MXL862XX_BRIDGE_PORT_EGRESS_METER_OTHERS: + * Index of traffic meter for other types + * @MXL862XX_BRIDGE_PORT_EGRESS_METER_MAX: Number of index + */ +enum mxl862xx_bridge_port_egress_meter { + MXL862XX_BRIDGE_PORT_EGRESS_METER_BROADCAST = 0, + MXL862XX_BRIDGE_PORT_EGRESS_METER_MULTICAST, + MXL862XX_BRIDGE_PORT_EGRESS_METER_UNKNOWN_MC_IP, + MXL862XX_BRIDGE_PORT_EGRESS_METER_UNKNOWN_MC_NON_IP, + MXL862XX_BRIDGE_PORT_EGRESS_METER_UNKNOWN_UC, + MXL862XX_BRIDGE_PORT_EGRESS_METER_OTHERS, + MXL862XX_BRIDGE_PORT_EGRESS_METER_MAX, +}; + +/** + * enum mxl862xx_bridge_forward_mode - Bridge forwarding type of packet + * @MXL862XX_BRIDGE_FORWARD_FLOOD: Packet is flooded to port members of + * ingress bridge port + * @MXL862XX_BRIDGE_FORWARD_DISCARD: Packet is discarded + */ +enum mxl862xx_bridge_forward_mode { + MXL862XX_BRIDGE_FORWARD_FLOOD = 0, + MXL862XX_BRIDGE_FORWARD_DISCARD, +}; + +/** + * struct mxl862xx_bridge_config - Bridge Configuration + * @bridge_id: Bridge ID (FID) + * @mask: See &enum mxl862xx_bridge_config_mask + * @mac_learning_limit_enable: Enable MAC learning limitation + * @mac_learning_limit: Max number of MAC addresses that can be learned in + * this bridge (all bridge ports) + * @mac_learning_count: Number of MAC addresses learned from this bridge + * @learning_discard_event: Number of learning discard events due to + * hardware resource not available + * @sub_metering_enable: Traffic metering on type of traffic (such as + * broadcast, multicast, unknown unicast, etc) applies + * @traffic_sub_meter_id: Meter for bridge process with specific type (such + * as broadcast, multicast, unknown unicast, etc) + * @forward_broadcast: Forwarding mode of broadcast traffic. See + * &enum mxl862xx_bridge_forward_mode + * @forward_unknown_multicast_ip: Forwarding mode of unknown multicast IP + * traffic. + * See &enum mxl862xx_bridge_forward_mode + * @forward_unknown_multicast_non_ip: Forwarding mode of unknown multicast + * non-IP traffic. + * See &enum mxl862xx_bridge_forward_mode + * @forward_unknown_unicast: Forwarding mode of unknown unicast traffic. See + * &enum mxl862xx_bridge_forward_mode + */ +struct mxl862xx_bridge_config { + __le16 bridge_id; + __le32 mask; /* enum mxl862xx_bridge_config_mask */ + u8 mac_learning_limit_enable; + __le16 mac_learning_limit; + __le16 mac_learning_count; + __le32 learning_discard_event; + u8 sub_metering_enable[MXL862XX_BRIDGE_PORT_EGRESS_METER_MAX]; + __le16 traffic_sub_meter_id[MXL862XX_BRIDGE_PORT_EGRESS_METER_MAX]; + __le32 forward_broadcast; /* enum mxl862xx_bridge_forward_mode */ + __le32 forward_unknown_multicast_ip; /* enum mxl862xx_bridge_forward_mode */ + __le32 forward_unknown_multicast_non_ip; /* enum mxl862xx_bridge_forward_mode */ + __le32 forward_unknown_unicast; /* enum mxl862xx_bridge_forward_mode */ +} __packed; + +/** + * struct mxl862xx_bridge_port_alloc - Bridge Port Allocation + * @bridge_port_id: If the bridge port allocation is successful, a valid ID + * will be returned in this field. Otherwise, INVALID_HANDLE + * is returned. For bridge port free, this field should + * contain a valid ID returned by the bridge port allocation. + * + * Used by MXL862XX_BRIDGE_PORT_ALLOC and MXL862XX_BRIDGE_PORT_FREE. + */ +struct mxl862xx_bridge_port_alloc { + __le16 bridge_port_id; +}; + +/** + * enum mxl862xx_bridge_port_config_mask - Bridge Port configuration mask + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_BRIDGE_ID: + * Mask for bridge_id + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_INGRESS_VLAN: + * Mask for ingress_extended_vlan_enable, + * ingress_extended_vlan_block_id and ingress_extended_vlan_block_size + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_EGRESS_VLAN: + * Mask for egress_extended_vlan_enable, egress_extended_vlan_block_id + * and egress_extended_vlan_block_size + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_INGRESS_MARKING: + * Mask for ingress_marking_mode + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_EGRESS_REMARKING: + * Mask for egress_remarking_mode + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_INGRESS_METER: + * Mask for ingress_metering_enable and ingress_traffic_meter_id + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_EGRESS_SUB_METER: + * Mask for egress_sub_metering_enable and egress_traffic_sub_meter_id + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_EGRESS_CTP_MAPPING: + * Mask for dest_logical_port_id, pmapper_enable, dest_sub_if_id_group, + * pmapper_mapping_mode, pmapper_id_valid and pmapper + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_BRIDGE_PORT_MAP: + * Mask for bridge_port_map + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_MC_DEST_IP_LOOKUP: + * Mask for mc_dest_ip_lookup_disable + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_MC_SRC_IP_LOOKUP: + * Mask for mc_src_ip_lookup_enable + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_MC_DEST_MAC_LOOKUP: + * Mask for dest_mac_lookup_disable + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_MC_SRC_MAC_LEARNING: + * Mask for src_mac_learning_disable + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_MAC_SPOOFING: + * Mask for mac_spoofing_detect_enable + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_PORT_LOCK: + * Mask for port_lock_enable + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_MAC_LEARNING_LIMIT: + * Mask for mac_learning_limit_enable and mac_learning_limit + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_MAC_LEARNED_COUNT: + * Mask for mac_learning_count + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_INGRESS_VLAN_FILTER: + * Mask for ingress_vlan_filter_enable, ingress_vlan_filter_block_id + * and ingress_vlan_filter_block_size + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_EGRESS_VLAN_FILTER1: + * Mask for bypass_egress_vlan_filter1, egress_vlan_filter1enable, + * egress_vlan_filter1block_id and egress_vlan_filter1block_size + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_EGRESS_VLAN_FILTER2: + * Mask for egress_vlan_filter2enable, egress_vlan_filter2block_id and + * egress_vlan_filter2block_size + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_VLAN_BASED_MAC_LEARNING: + * Mask for vlan_tag_selection, vlan_src_mac_priority_enable, + * vlan_src_mac_dei_enable, vlan_src_mac_vid_enable, + * vlan_dst_mac_priority_enable, vlan_dst_mac_dei_enable and + * vlan_dst_mac_vid_enable + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_VLAN_BASED_MULTICAST_LOOKUP: + * Mask for vlan_multicast_priority_enable, + * vlan_multicast_dei_enable and vlan_multicast_vid_enable + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_LOOP_VIOLATION_COUNTER: + * Mask for loop_violation_count + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_ALL: Enable all + * @MXL862XX_BRIDGE_PORT_CONFIG_MASK_FORCE: Bypass any check for debug purpose + */ +enum mxl862xx_bridge_port_config_mask { + MXL862XX_BRIDGE_PORT_CONFIG_MASK_BRIDGE_ID = BIT(0), + MXL862XX_BRIDGE_PORT_CONFIG_MASK_INGRESS_VLAN = BIT(1), + MXL862XX_BRIDGE_PORT_CONFIG_MASK_EGRESS_VLAN = BIT(2), + MXL862XX_BRIDGE_PORT_CONFIG_MASK_INGRESS_MARKING = BIT(3), + MXL862XX_BRIDGE_PORT_CONFIG_MASK_EGRESS_REMARKING = BIT(4), + MXL862XX_BRIDGE_PORT_CONFIG_MASK_INGRESS_METER = BIT(5), + MXL862XX_BRIDGE_PORT_CONFIG_MASK_EGRESS_SUB_METER = BIT(6), + MXL862XX_BRIDGE_PORT_CONFIG_MASK_EGRESS_CTP_MAPPING = BIT(7), + MXL862XX_BRIDGE_PORT_CONFIG_MASK_BRIDGE_PORT_MAP = BIT(8), + MXL862XX_BRIDGE_PORT_CONFIG_MASK_MC_DEST_IP_LOOKUP = BIT(9), + MXL862XX_BRIDGE_PORT_CONFIG_MASK_MC_SRC_IP_LOOKUP = BIT(10), + MXL862XX_BRIDGE_PORT_CONFIG_MASK_MC_DEST_MAC_LOOKUP = BIT(11), + MXL862XX_BRIDGE_PORT_CONFIG_MASK_MC_SRC_MAC_LEARNING = BIT(12), + MXL862XX_BRIDGE_PORT_CONFIG_MASK_MAC_SPOOFING = BIT(13), + MXL862XX_BRIDGE_PORT_CONFIG_MASK_PORT_LOCK = BIT(14), + MXL862XX_BRIDGE_PORT_CONFIG_MASK_MAC_LEARNING_LIMIT = BIT(15), + MXL862XX_BRIDGE_PORT_CONFIG_MASK_MAC_LEARNED_COUNT = BIT(16), + MXL862XX_BRIDGE_PORT_CONFIG_MASK_INGRESS_VLAN_FILTER = BIT(17), + MXL862XX_BRIDGE_PORT_CONFIG_MASK_EGRESS_VLAN_FILTER1 = BIT(18), + MXL862XX_BRIDGE_PORT_CONFIG_MASK_EGRESS_VLAN_FILTER2 = BIT(19), + MXL862XX_BRIDGE_PORT_CONFIG_MASK_VLAN_BASED_MAC_LEARNING = BIT(20), + MXL862XX_BRIDGE_PORT_CONFIG_MASK_VLAN_BASED_MULTICAST_LOOKUP = BIT(21), + MXL862XX_BRIDGE_PORT_CONFIG_MASK_LOOP_VIOLATION_COUNTER = BIT(22), + MXL862XX_BRIDGE_PORT_CONFIG_MASK_ALL = 0x7FFFFFFF, + MXL862XX_BRIDGE_PORT_CONFIG_MASK_FORCE = BIT(31) +}; + +/** + * enum mxl862xx_color_marking_mode - Color Marking Mode + * @MXL862XX_MARKING_ALL_GREEN: mark packets (except critical) to green + * @MXL862XX_MARKING_INTERNAL_MARKING: do not change color and priority + * @MXL862XX_MARKING_DEI: DEI mark mode + * @MXL862XX_MARKING_PCP_8P0D: PCP 8P0D mark mode + * @MXL862XX_MARKING_PCP_7P1D: PCP 7P1D mark mode + * @MXL862XX_MARKING_PCP_6P2D: PCP 6P2D mark mode + * @MXL862XX_MARKING_PCP_5P3D: PCP 5P3D mark mode + * @MXL862XX_MARKING_DSCP_AF: DSCP AF class + */ +enum mxl862xx_color_marking_mode { + MXL862XX_MARKING_ALL_GREEN = 0, + MXL862XX_MARKING_INTERNAL_MARKING, + MXL862XX_MARKING_DEI, + MXL862XX_MARKING_PCP_8P0D, + MXL862XX_MARKING_PCP_7P1D, + MXL862XX_MARKING_PCP_6P2D, + MXL862XX_MARKING_PCP_5P3D, + MXL862XX_MARKING_DSCP_AF, +}; + +/** + * enum mxl862xx_color_remarking_mode - Color Remarking Mode + * @MXL862XX_REMARKING_NONE: values from last process stage + * @MXL862XX_REMARKING_DEI: DEI mark mode + * @MXL862XX_REMARKING_PCP_8P0D: PCP 8P0D mark mode + * @MXL862XX_REMARKING_PCP_7P1D: PCP 7P1D mark mode + * @MXL862XX_REMARKING_PCP_6P2D: PCP 6P2D mark mode + * @MXL862XX_REMARKING_PCP_5P3D: PCP 5P3D mark mode + * @MXL862XX_REMARKING_DSCP_AF: DSCP AF class + */ +enum mxl862xx_color_remarking_mode { + MXL862XX_REMARKING_NONE = 0, + MXL862XX_REMARKING_DEI = 2, + MXL862XX_REMARKING_PCP_8P0D, + MXL862XX_REMARKING_PCP_7P1D, + MXL862XX_REMARKING_PCP_6P2D, + MXL862XX_REMARKING_PCP_5P3D, + MXL862XX_REMARKING_DSCP_AF, +}; + +/** + * enum mxl862xx_pmapper_mapping_mode - P-mapper Mapping Mode + * @MXL862XX_PMAPPER_MAPPING_PCP: Use PCP for VLAN tagged packets to derive + * sub interface ID group + * @MXL862XX_PMAPPER_MAPPING_LAG: Use LAG Index for Pmapper access + * regardless of IP and VLAN packet + * @MXL862XX_PMAPPER_MAPPING_DSCP: Use DSCP for VLAN tagged IP packets to + * derive sub interface ID group + */ +enum mxl862xx_pmapper_mapping_mode { + MXL862XX_PMAPPER_MAPPING_PCP = 0, + MXL862XX_PMAPPER_MAPPING_LAG, + MXL862XX_PMAPPER_MAPPING_DSCP, +}; + +/** + * struct mxl862xx_pmapper - P-mapper Configuration + * @pmapper_id: Index of P-mapper (0-31) + * @dest_sub_if_id_group: Sub interface ID group. Entry 0 is for non-IP and + * non-VLAN tagged packets. + * Entries 1-8 are PCP mapping entries for VLAN tagged + * packets. + * Entries 9-72 are DSCP or LAG mapping entries. + * + * Used by CTP port config and bridge port config. In case of LAG, it is + * user's responsibility to provide the mapped entries in given P-mapper + * table. In other modes the entries are auto mapped from input packet. + */ +struct mxl862xx_pmapper { + __le16 pmapper_id; + u8 dest_sub_if_id_group[73]; +} __packed; + +/** + * struct mxl862xx_bridge_port_config - Bridge Port Configuration + * @bridge_port_id: Bridge Port ID allocated by bridge port allocation + * @mask: See &enum mxl862xx_bridge_port_config_mask + * @bridge_id: Bridge ID (FID) to which this bridge port is associated + * @ingress_extended_vlan_enable: Enable extended VLAN processing for + * ingress traffic + * @ingress_extended_vlan_block_id: Extended VLAN block allocated for + * ingress traffic + * @ingress_extended_vlan_block_size: Extended VLAN block size for ingress + * traffic + * @egress_extended_vlan_enable: Enable extended VLAN processing for egress + * traffic + * @egress_extended_vlan_block_id: Extended VLAN block allocated for egress + * traffic + * @egress_extended_vlan_block_size: Extended VLAN block size for egress + * traffic + * @ingress_marking_mode: Ingress color marking mode. See + * &enum mxl862xx_color_marking_mode + * @egress_remarking_mode: Color remarking for egress traffic. See + * &enum mxl862xx_color_remarking_mode + * @ingress_metering_enable: Traffic metering on ingress traffic applies + * @ingress_traffic_meter_id: Meter for ingress Bridge Port process + * @egress_sub_metering_enable: Traffic metering on various types of egress + * traffic + * @egress_traffic_sub_meter_id: Meter for egress Bridge Port process with + * specific type + * @dest_logical_port_id: Destination logical port + * @pmapper_enable: Enable P-mapper + * @dest_sub_if_id_group: Destination sub interface ID group when + * pmapper_enable is false + * @pmapper_mapping_mode: P-mapper mapping mode. See + * &enum mxl862xx_pmapper_mapping_mode + * @pmapper_id_valid: When true, P-mapper is re-used; when false, + * allocation is handled by API + * @pmapper: P-mapper configuration used when pmapper_enable is true + * @bridge_port_map: Port map defining broadcast domain. Each bit + * represents one bridge port. Bridge port ID is + * index * 16 + bit offset. + * @mc_dest_ip_lookup_disable: Disable multicast IP destination table + * lookup + * @mc_src_ip_lookup_enable: Enable multicast IP source table lookup + * @dest_mac_lookup_disable: Disable destination MAC lookup; packet treated + * as unknown + * @src_mac_learning_disable: Disable source MAC address learning + * @mac_spoofing_detect_enable: Enable MAC spoofing detection + * @port_lock_enable: Enable port locking + * @mac_learning_limit_enable: Enable MAC learning limitation + * @mac_learning_limit: Maximum number of MAC addresses that can be learned + * from this bridge port + * @loop_violation_count: Number of loop violation events from this bridge + * port + * @mac_learning_count: Number of MAC addresses learned from this bridge + * port + * @ingress_vlan_filter_enable: Enable ingress VLAN filter + * @ingress_vlan_filter_block_id: VLAN filter block of ingress traffic + * @ingress_vlan_filter_block_size: VLAN filter block size for ingress + * traffic + * @bypass_egress_vlan_filter1: For ingress traffic, bypass VLAN filter 1 + * at egress bridge port processing + * @egress_vlan_filter1enable: Enable egress VLAN filter 1 + * @egress_vlan_filter1block_id: VLAN filter block 1 of egress traffic + * @egress_vlan_filter1block_size: VLAN filter block 1 size + * @egress_vlan_filter2enable: Enable egress VLAN filter 2 + * @egress_vlan_filter2block_id: VLAN filter block 2 of egress traffic + * @egress_vlan_filter2block_size: VLAN filter block 2 size + * @vlan_tag_selection: VLAN tag selection for MAC address/multicast + * learning, lookup and filtering. + * 0 - Intermediate outer VLAN tag is used. + * 1 - Original outer VLAN tag is used. + * @vlan_src_mac_priority_enable: Enable VLAN Priority field for source MAC + * learning and filtering + * @vlan_src_mac_dei_enable: Enable VLAN DEI/CFI field for source MAC + * learning and filtering + * @vlan_src_mac_vid_enable: Enable VLAN ID field for source MAC learning + * and filtering + * @vlan_dst_mac_priority_enable: Enable VLAN Priority field for destination + * MAC lookup and filtering + * @vlan_dst_mac_dei_enable: Enable VLAN CFI/DEI field for destination MAC + * lookup and filtering + * @vlan_dst_mac_vid_enable: Enable VLAN ID field for destination MAC lookup + * and filtering + * @vlan_multicast_priority_enable: Enable VLAN Priority field for IP + * multicast lookup + * @vlan_multicast_dei_enable: Enable VLAN CFI/DEI field for IP multicast + * lookup + * @vlan_multicast_vid_enable: Enable VLAN ID field for IP multicast lookup + */ +struct mxl862xx_bridge_port_config { + __le16 bridge_port_id; + __le32 mask; /* enum mxl862xx_bridge_port_config_mask */ + __le16 bridge_id; + u8 ingress_extended_vlan_enable; + __le16 ingress_extended_vlan_block_id; + __le16 ingress_extended_vlan_block_size; + u8 egress_extended_vlan_enable; + __le16 egress_extended_vlan_block_id; + __le16 egress_extended_vlan_block_size; + __le32 ingress_marking_mode; /* enum mxl862xx_color_marking_mode */ + __le32 egress_remarking_mode; /* enum mxl862xx_color_remarking_mode */ + u8 ingress_metering_enable; + __le16 ingress_traffic_meter_id; + u8 egress_sub_metering_enable[MXL862XX_BRIDGE_PORT_EGRESS_METER_MAX]; + __le16 egress_traffic_sub_meter_id[MXL862XX_BRIDGE_PORT_EGRESS_METER_MAX]; + u8 dest_logical_port_id; + u8 pmapper_enable; + __le16 dest_sub_if_id_group; + __le32 pmapper_mapping_mode; /* enum mxl862xx_pmapper_mapping_mode */ + u8 pmapper_id_valid; + struct mxl862xx_pmapper pmapper; + __le16 bridge_port_map[8]; + u8 mc_dest_ip_lookup_disable; + u8 mc_src_ip_lookup_enable; + u8 dest_mac_lookup_disable; + u8 src_mac_learning_disable; + u8 mac_spoofing_detect_enable; + u8 port_lock_enable; + u8 mac_learning_limit_enable; + __le16 mac_learning_limit; + __le16 loop_violation_count; + __le16 mac_learning_count; + u8 ingress_vlan_filter_enable; + __le16 ingress_vlan_filter_block_id; + __le16 ingress_vlan_filter_block_size; + u8 bypass_egress_vlan_filter1; + u8 egress_vlan_filter1enable; + __le16 egress_vlan_filter1block_id; + __le16 egress_vlan_filter1block_size; + u8 egress_vlan_filter2enable; + __le16 egress_vlan_filter2block_id; + __le16 egress_vlan_filter2block_size; + u8 vlan_tag_selection; + u8 vlan_src_mac_priority_enable; + u8 vlan_src_mac_dei_enable; + u8 vlan_src_mac_vid_enable; + u8 vlan_dst_mac_priority_enable; + u8 vlan_dst_mac_dei_enable; + u8 vlan_dst_mac_vid_enable; + u8 vlan_multicast_priority_enable; + u8 vlan_multicast_dei_enable; + u8 vlan_multicast_vid_enable; +} __packed; + +/** + * struct mxl862xx_cfg - Global Switch configuration Attributes + * @mac_table_age_timer: See &enum mxl862xx_age_timer + * @age_timer: Custom MAC table aging timer in seconds + * @max_packet_len: Maximum Ethernet packet length + * @learning_limit_action: Automatic MAC address table learning limitation + * consecutive action + * @mac_locking_action: Accept or discard MAC port locking violation + * packets + * @mac_spoofing_action: Accept or discard MAC spoofing and port MAC locking + * violation packets + * @pause_mac_mode_src: Pause frame MAC source address mode + * @pause_mac_src: Pause frame MAC source address + */ +struct mxl862xx_cfg { + __le32 mac_table_age_timer; /* enum mxl862xx_age_timer */ + __le32 age_timer; + __le16 max_packet_len; + u8 learning_limit_action; + u8 mac_locking_action; + u8 mac_spoofing_action; + u8 pause_mac_mode_src; + u8 pause_mac_src[ETH_ALEN]; +} __packed; + +/** + * enum mxl862xx_ss_sp_tag_mask - Special tag valid field indicator bits + * @MXL862XX_SS_SP_TAG_MASK_RX: valid RX special tag mode + * @MXL862XX_SS_SP_TAG_MASK_TX: valid TX special tag mode + * @MXL862XX_SS_SP_TAG_MASK_RX_PEN: valid RX special tag info over preamble + * @MXL862XX_SS_SP_TAG_MASK_TX_PEN: valid TX special tag info over preamble + */ +enum mxl862xx_ss_sp_tag_mask { + MXL862XX_SS_SP_TAG_MASK_RX = BIT(0), + MXL862XX_SS_SP_TAG_MASK_TX = BIT(1), + MXL862XX_SS_SP_TAG_MASK_RX_PEN = BIT(2), + MXL862XX_SS_SP_TAG_MASK_TX_PEN = BIT(3), +}; + +/** + * enum mxl862xx_ss_sp_tag_rx - RX special tag mode + * @MXL862XX_SS_SP_TAG_RX_NO_TAG_NO_INSERT: packet does NOT have special + * tag and special tag is NOT inserted + * @MXL862XX_SS_SP_TAG_RX_NO_TAG_INSERT: packet does NOT have special tag + * and special tag is inserted + * @MXL862XX_SS_SP_TAG_RX_TAG_NO_INSERT: packet has special tag and special + * tag is NOT inserted + */ +enum mxl862xx_ss_sp_tag_rx { + MXL862XX_SS_SP_TAG_RX_NO_TAG_NO_INSERT = 0, + MXL862XX_SS_SP_TAG_RX_NO_TAG_INSERT = 1, + MXL862XX_SS_SP_TAG_RX_TAG_NO_INSERT = 2, +}; + +/** + * enum mxl862xx_ss_sp_tag_tx - TX special tag mode + * @MXL862XX_SS_SP_TAG_TX_NO_TAG_NO_REMOVE: packet does NOT have special + * tag and special tag is NOT removed + * @MXL862XX_SS_SP_TAG_TX_TAG_REPLACE: packet has special tag and special + * tag is replaced + * @MXL862XX_SS_SP_TAG_TX_TAG_NO_REMOVE: packet has special tag and special + * tag is NOT removed + * @MXL862XX_SS_SP_TAG_TX_TAG_REMOVE: packet has special tag and special + * tag is removed + */ +enum mxl862xx_ss_sp_tag_tx { + MXL862XX_SS_SP_TAG_TX_NO_TAG_NO_REMOVE = 0, + MXL862XX_SS_SP_TAG_TX_TAG_REPLACE = 1, + MXL862XX_SS_SP_TAG_TX_TAG_NO_REMOVE = 2, + MXL862XX_SS_SP_TAG_TX_TAG_REMOVE = 3, +}; + +/** + * enum mxl862xx_ss_sp_tag_rx_pen - RX special tag info over preamble + * @MXL862XX_SS_SP_TAG_RX_PEN_ALL_0: special tag info inserted from byte 2 + * to 7 are all 0 + * @MXL862XX_SS_SP_TAG_RX_PEN_BYTE_5_IS_16: special tag byte 5 is 16, other + * bytes from 2 to 7 are 0 + * @MXL862XX_SS_SP_TAG_RX_PEN_BYTE_5_FROM_PREAMBLE: special tag byte 5 is + * from preamble field, others + * are 0 + * @MXL862XX_SS_SP_TAG_RX_PEN_BYTE_2_TO_7_FROM_PREAMBLE: special tag byte 2 + * to 7 are from preamble + * field + */ +enum mxl862xx_ss_sp_tag_rx_pen { + MXL862XX_SS_SP_TAG_RX_PEN_ALL_0 = 0, + MXL862XX_SS_SP_TAG_RX_PEN_BYTE_5_IS_16 = 1, + MXL862XX_SS_SP_TAG_RX_PEN_BYTE_5_FROM_PREAMBLE = 2, + MXL862XX_SS_SP_TAG_RX_PEN_BYTE_2_TO_7_FROM_PREAMBLE = 3, +}; + +/** + * struct mxl862xx_ss_sp_tag - Special tag port settings + * @pid: port ID (1~16) + * @mask: See &enum mxl862xx_ss_sp_tag_mask + * @rx: See &enum mxl862xx_ss_sp_tag_rx + * @tx: See &enum mxl862xx_ss_sp_tag_tx + * @rx_pen: See &enum mxl862xx_ss_sp_tag_rx_pen + * @tx_pen: TX special tag info over preamble + * 0 - disabled + * 1 - enabled + */ +struct mxl862xx_ss_sp_tag { + u8 pid; + u8 mask; /* enum mxl862xx_ss_sp_tag_mask */ + u8 rx; /* enum mxl862xx_ss_sp_tag_rx */ + u8 tx; /* enum mxl862xx_ss_sp_tag_tx */ + u8 rx_pen; /* enum mxl862xx_ss_sp_tag_rx_pen */ + u8 tx_pen; /* boolean */ +} __packed; + +/** + * enum mxl862xx_logical_port_mode - Logical port mode + * @MXL862XX_LOGICAL_PORT_8BIT_WLAN: WLAN with 8-bit station ID + * @MXL862XX_LOGICAL_PORT_9BIT_WLAN: WLAN with 9-bit station ID + * @MXL862XX_LOGICAL_PORT_ETHERNET: Ethernet port + * @MXL862XX_LOGICAL_PORT_OTHER: Others + */ +enum mxl862xx_logical_port_mode { + MXL862XX_LOGICAL_PORT_8BIT_WLAN = 0, + MXL862XX_LOGICAL_PORT_9BIT_WLAN, + MXL862XX_LOGICAL_PORT_ETHERNET, + MXL862XX_LOGICAL_PORT_OTHER = 0xFF, +}; + +/** + * struct mxl862xx_ctp_port_assignment - CTP Port Assignment/association + * with logical port + * @logical_port_id: Logical Port Id. The valid range is hardware dependent + * @first_ctp_port_id: First CTP (Connectivity Termination Port) ID mapped + * to above logical port ID + * @number_of_ctp_port: Total number of CTP Ports mapped above logical port + * ID + * @mode: Logical port mode to define sub interface ID format. See + * &enum mxl862xx_logical_port_mode + * @bridge_port_id: Bridge Port ID (not FID). For allocation, each CTP + * allocated is mapped to the Bridge Port given by this field. + * The Bridge Port will be configured to use first CTP as + * egress CTP. + */ +struct mxl862xx_ctp_port_assignment { + u8 logical_port_id; + __le16 first_ctp_port_id; + __le16 number_of_ctp_port; + __le32 mode; /* enum mxl862xx_logical_port_mode */ + __le16 bridge_port_id; +} __packed; + +/** + * struct mxl862xx_sys_fw_image_version - Firmware version information + * @iv_major: firmware major version + * @iv_minor: firmware minor version + * @iv_revision: firmware revision + * @iv_build_num: firmware build number + */ +struct mxl862xx_sys_fw_image_version { + u8 iv_major; + u8 iv_minor; + __le16 iv_revision; + __le32 iv_build_num; +} __packed; + +#endif /* __MXL862XX_API_H */ diff --git a/drivers/net/dsa/mxl862xx/mxl862xx-cmd.h b/drivers/net/dsa/mxl862xx/mxl862xx-cmd.h new file mode 100644 index 000000000000..f6852ade64e7 --- /dev/null +++ b/drivers/net/dsa/mxl862xx/mxl862xx-cmd.h @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef __MXL862XX_CMD_H +#define __MXL862XX_CMD_H + +#define MXL862XX_MMD_DEV 30 +#define MXL862XX_MMD_REG_CTRL 0 +#define MXL862XX_MMD_REG_LEN_RET 1 +#define MXL862XX_MMD_REG_DATA_FIRST 2 +#define MXL862XX_MMD_REG_DATA_LAST 95 +#define MXL862XX_MMD_REG_DATA_MAX_SIZE \ + (MXL862XX_MMD_REG_DATA_LAST - MXL862XX_MMD_REG_DATA_FIRST + 1) + +#define MXL862XX_COMMON_MAGIC 0x100 +#define MXL862XX_BRDG_MAGIC 0x300 +#define MXL862XX_BRDGPORT_MAGIC 0x400 +#define MXL862XX_CTP_MAGIC 0x500 +#define MXL862XX_SWMAC_MAGIC 0xa00 +#define MXL862XX_SS_MAGIC 0x1600 +#define GPY_GPY2XX_MAGIC 0x1800 +#define SYS_MISC_MAGIC 0x1900 + +#define MXL862XX_COMMON_CFGGET (MXL862XX_COMMON_MAGIC + 0x9) +#define MXL862XX_COMMON_REGISTERMOD (MXL862XX_COMMON_MAGIC + 0x11) + +#define MXL862XX_BRIDGE_ALLOC (MXL862XX_BRDG_MAGIC + 0x1) +#define MXL862XX_BRIDGE_CONFIGSET (MXL862XX_BRDG_MAGIC + 0x2) +#define MXL862XX_BRIDGE_CONFIGGET (MXL862XX_BRDG_MAGIC + 0x3) +#define MXL862XX_BRIDGE_FREE (MXL862XX_BRDG_MAGIC + 0x4) + +#define MXL862XX_BRIDGEPORT_ALLOC (MXL862XX_BRDGPORT_MAGIC + 0x1) +#define MXL862XX_BRIDGEPORT_CONFIGSET (MXL862XX_BRDGPORT_MAGIC + 0x2) +#define MXL862XX_BRIDGEPORT_CONFIGGET (MXL862XX_BRDGPORT_MAGIC + 0x3) +#define MXL862XX_BRIDGEPORT_FREE (MXL862XX_BRDGPORT_MAGIC + 0x4) + +#define MXL862XX_CTP_PORTASSIGNMENTSET (MXL862XX_CTP_MAGIC + 0x3) + +#define MXL862XX_MAC_TABLECLEARCOND (MXL862XX_SWMAC_MAGIC + 0x8) + +#define MXL862XX_SS_SPTAG_SET (MXL862XX_SS_MAGIC + 0x02) + +#define INT_GPHY_READ (GPY_GPY2XX_MAGIC + 0x01) +#define INT_GPHY_WRITE (GPY_GPY2XX_MAGIC + 0x02) + +#define SYS_MISC_FW_VERSION (SYS_MISC_MAGIC + 0x02) + +#define MMD_API_MAXIMUM_ID 0x7fff + +#endif /* __MXL862XX_CMD_H */ diff --git a/drivers/net/dsa/mxl862xx/mxl862xx-host.c b/drivers/net/dsa/mxl862xx/mxl862xx-host.c new file mode 100644 index 000000000000..f2b3c0b1dff1 --- /dev/null +++ b/drivers/net/dsa/mxl862xx/mxl862xx-host.c @@ -0,0 +1,245 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Based upon the Maxlinear SDK driver + * + * Copyright (C) 2025 Daniel Golle <daniel@makrotopia.org> + * Copyright (C) 2025 John Crispin <john@phrozen.org> + * Copyright (C) 2024 MaxLinear Inc. + */ + +#include <linux/bits.h> +#include <linux/iopoll.h> +#include <linux/limits.h> +#include <net/dsa.h> +#include "mxl862xx.h" +#include "mxl862xx-host.h" + +#define CTRL_BUSY_MASK BIT(15) + +#define MXL862XX_MMD_REG_CTRL 0 +#define MXL862XX_MMD_REG_LEN_RET 1 +#define MXL862XX_MMD_REG_DATA_FIRST 2 +#define MXL862XX_MMD_REG_DATA_LAST 95 +#define MXL862XX_MMD_REG_DATA_MAX_SIZE \ + (MXL862XX_MMD_REG_DATA_LAST - MXL862XX_MMD_REG_DATA_FIRST + 1) + +#define MMD_API_SET_DATA_0 2 +#define MMD_API_GET_DATA_0 5 +#define MMD_API_RST_DATA 8 + +#define MXL862XX_SWITCH_RESET 0x9907 + +static int mxl862xx_reg_read(struct mxl862xx_priv *priv, u32 addr) +{ + return __mdiodev_c45_read(priv->mdiodev, MDIO_MMD_VEND1, addr); +} + +static int mxl862xx_reg_write(struct mxl862xx_priv *priv, u32 addr, u16 data) +{ + return __mdiodev_c45_write(priv->mdiodev, MDIO_MMD_VEND1, addr, data); +} + +static int mxl862xx_ctrl_read(struct mxl862xx_priv *priv) +{ + return mxl862xx_reg_read(priv, MXL862XX_MMD_REG_CTRL); +} + +static int mxl862xx_busy_wait(struct mxl862xx_priv *priv) +{ + int val; + + return readx_poll_timeout(mxl862xx_ctrl_read, priv, val, + !(val & CTRL_BUSY_MASK), 15, 10000); +} + +static int mxl862xx_set_data(struct mxl862xx_priv *priv, u16 words) +{ + int ret; + u16 cmd; + + ret = mxl862xx_reg_write(priv, MXL862XX_MMD_REG_LEN_RET, + MXL862XX_MMD_REG_DATA_MAX_SIZE * sizeof(u16)); + if (ret < 0) + return ret; + + cmd = words / MXL862XX_MMD_REG_DATA_MAX_SIZE - 1; + if (!(cmd < 2)) + return -EINVAL; + + cmd += MMD_API_SET_DATA_0; + ret = mxl862xx_reg_write(priv, MXL862XX_MMD_REG_CTRL, + cmd | CTRL_BUSY_MASK); + if (ret < 0) + return ret; + + return mxl862xx_busy_wait(priv); +} + +static int mxl862xx_get_data(struct mxl862xx_priv *priv, u16 words) +{ + int ret; + u16 cmd; + + ret = mxl862xx_reg_write(priv, MXL862XX_MMD_REG_LEN_RET, + MXL862XX_MMD_REG_DATA_MAX_SIZE * sizeof(u16)); + if (ret < 0) + return ret; + + cmd = words / MXL862XX_MMD_REG_DATA_MAX_SIZE; + if (!(cmd > 0 && cmd < 3)) + return -EINVAL; + + cmd += MMD_API_GET_DATA_0; + ret = mxl862xx_reg_write(priv, MXL862XX_MMD_REG_CTRL, + cmd | CTRL_BUSY_MASK); + if (ret < 0) + return ret; + + return mxl862xx_busy_wait(priv); +} + +static int mxl862xx_firmware_return(int ret) +{ + /* Only 16-bit values are valid. */ + if (WARN_ON(ret & GENMASK(31, 16))) + return -EINVAL; + + /* Interpret value as signed 16-bit integer. */ + return (s16)ret; +} + +static int mxl862xx_send_cmd(struct mxl862xx_priv *priv, u16 cmd, u16 size, + bool quiet) +{ + int ret; + + ret = mxl862xx_reg_write(priv, MXL862XX_MMD_REG_LEN_RET, size); + if (ret) + return ret; + + ret = mxl862xx_reg_write(priv, MXL862XX_MMD_REG_CTRL, + cmd | CTRL_BUSY_MASK); + if (ret) + return ret; + + ret = mxl862xx_busy_wait(priv); + if (ret) + return ret; + + ret = mxl862xx_reg_read(priv, MXL862XX_MMD_REG_LEN_RET); + if (ret < 0) + return ret; + + /* handle errors returned by the firmware as -EIO + * The firmware is based on Zephyr OS and uses the errors as + * defined in errno.h of Zephyr OS. See + * https://github.com/zephyrproject-rtos/zephyr/blob/v3.7.0/lib/libc/minimal/include/errno.h + */ + ret = mxl862xx_firmware_return(ret); + if (ret < 0) { + if (!quiet) + dev_err(&priv->mdiodev->dev, + "CMD %04x returned error %d\n", cmd, ret); + return -EIO; + } + + return ret; +} + +int mxl862xx_api_wrap(struct mxl862xx_priv *priv, u16 cmd, void *_data, + u16 size, bool read, bool quiet) +{ + __le16 *data = _data; + int ret, cmd_ret; + u16 max, i; + + dev_dbg(&priv->mdiodev->dev, "CMD %04x DATA %*ph\n", cmd, size, data); + + mutex_lock_nested(&priv->mdiodev->bus->mdio_lock, MDIO_MUTEX_NESTED); + + max = (size + 1) / 2; + + ret = mxl862xx_busy_wait(priv); + if (ret < 0) + goto out; + + for (i = 0; i < max; i++) { + u16 off = i % MXL862XX_MMD_REG_DATA_MAX_SIZE; + + if (i && off == 0) { + /* Send command to set data when every + * MXL862XX_MMD_REG_DATA_MAX_SIZE of WORDs are written. + */ + ret = mxl862xx_set_data(priv, i); + if (ret < 0) + goto out; + } + + ret = mxl862xx_reg_write(priv, MXL862XX_MMD_REG_DATA_FIRST + off, + le16_to_cpu(data[i])); + if (ret < 0) + goto out; + } + + ret = mxl862xx_send_cmd(priv, cmd, size, quiet); + if (ret < 0 || !read) + goto out; + + /* store result of mxl862xx_send_cmd() */ + cmd_ret = ret; + + for (i = 0; i < max; i++) { + u16 off = i % MXL862XX_MMD_REG_DATA_MAX_SIZE; + + if (i && off == 0) { + /* Send command to fetch next batch of data when every + * MXL862XX_MMD_REG_DATA_MAX_SIZE of WORDs are read. + */ + ret = mxl862xx_get_data(priv, i); + if (ret < 0) + goto out; + } + + ret = mxl862xx_reg_read(priv, MXL862XX_MMD_REG_DATA_FIRST + off); + if (ret < 0) + goto out; + + if ((i * 2 + 1) == size) { + /* Special handling for last BYTE if it's not WORD + * aligned to avoid writing beyond the allocated data + * structure. + */ + *(uint8_t *)&data[i] = ret & 0xff; + } else { + data[i] = cpu_to_le16((u16)ret); + } + } + + /* on success return the result of the mxl862xx_send_cmd() */ + ret = cmd_ret; + + dev_dbg(&priv->mdiodev->dev, "RET %d DATA %*ph\n", ret, size, data); + +out: + mutex_unlock(&priv->mdiodev->bus->mdio_lock); + + return ret; +} + +int mxl862xx_reset(struct mxl862xx_priv *priv) +{ + int ret; + + mutex_lock_nested(&priv->mdiodev->bus->mdio_lock, MDIO_MUTEX_NESTED); + + /* Software reset */ + ret = mxl862xx_reg_write(priv, MXL862XX_MMD_REG_LEN_RET, 0); + if (ret) + goto out; + + ret = mxl862xx_reg_write(priv, MXL862XX_MMD_REG_CTRL, MXL862XX_SWITCH_RESET); +out: + mutex_unlock(&priv->mdiodev->bus->mdio_lock); + + return ret; +} diff --git a/drivers/net/dsa/mxl862xx/mxl862xx-host.h b/drivers/net/dsa/mxl862xx/mxl862xx-host.h new file mode 100644 index 000000000000..7cc496f6be5c --- /dev/null +++ b/drivers/net/dsa/mxl862xx/mxl862xx-host.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef __MXL862XX_HOST_H +#define __MXL862XX_HOST_H + +#include "mxl862xx.h" + +int mxl862xx_api_wrap(struct mxl862xx_priv *priv, u16 cmd, void *data, u16 size, + bool read, bool quiet); +int mxl862xx_reset(struct mxl862xx_priv *priv); + +#endif /* __MXL862XX_HOST_H */ diff --git a/drivers/net/dsa/mxl862xx/mxl862xx.c b/drivers/net/dsa/mxl862xx/mxl862xx.c new file mode 100644 index 000000000000..43d2a6120898 --- /dev/null +++ b/drivers/net/dsa/mxl862xx/mxl862xx.c @@ -0,0 +1,483 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Driver for MaxLinear MxL862xx switch family + * + * Copyright (C) 2024 MaxLinear Inc. + * Copyright (C) 2025 John Crispin <john@phrozen.org> + * Copyright (C) 2025 Daniel Golle <daniel@makrotopia.org> + */ + +#include <linux/module.h> +#include <linux/delay.h> +#include <linux/of_device.h> +#include <linux/of_mdio.h> +#include <linux/phy.h> +#include <linux/phylink.h> +#include <net/dsa.h> + +#include "mxl862xx.h" +#include "mxl862xx-api.h" +#include "mxl862xx-cmd.h" +#include "mxl862xx-host.h" + +#define MXL862XX_API_WRITE(dev, cmd, data) \ + mxl862xx_api_wrap(dev, cmd, &(data), sizeof((data)), false, false) +#define MXL862XX_API_READ(dev, cmd, data) \ + mxl862xx_api_wrap(dev, cmd, &(data), sizeof((data)), true, false) +#define MXL862XX_API_READ_QUIET(dev, cmd, data) \ + mxl862xx_api_wrap(dev, cmd, &(data), sizeof((data)), true, true) + +#define MXL862XX_SDMA_PCTRLP(p) (0xbc0 + ((p) * 0x6)) +#define MXL862XX_SDMA_PCTRL_EN BIT(0) + +#define MXL862XX_FDMA_PCTRLP(p) (0xa80 + ((p) * 0x6)) +#define MXL862XX_FDMA_PCTRL_EN BIT(0) + +#define MXL862XX_READY_TIMEOUT_MS 10000 +#define MXL862XX_READY_POLL_MS 100 + +static enum dsa_tag_protocol mxl862xx_get_tag_protocol(struct dsa_switch *ds, + int port, + enum dsa_tag_protocol m) +{ + return DSA_TAG_PROTO_MXL862; +} + +/* PHY access via firmware relay */ +static int mxl862xx_phy_read_mmd(struct mxl862xx_priv *priv, int port, + int devadd, int reg) +{ + struct mdio_relay_data param = { + .phy = port, + .mmd = devadd, + .reg = cpu_to_le16(reg), + }; + int ret; + + ret = MXL862XX_API_READ(priv, INT_GPHY_READ, param); + if (ret) + return ret; + + return le16_to_cpu(param.data); +} + +static int mxl862xx_phy_write_mmd(struct mxl862xx_priv *priv, int port, + int devadd, int reg, u16 data) +{ + struct mdio_relay_data param = { + .phy = port, + .mmd = devadd, + .reg = cpu_to_le16(reg), + .data = cpu_to_le16(data), + }; + + return MXL862XX_API_WRITE(priv, INT_GPHY_WRITE, param); +} + +static int mxl862xx_phy_read_mii_bus(struct mii_bus *bus, int port, int regnum) +{ + return mxl862xx_phy_read_mmd(bus->priv, port, 0, regnum); +} + +static int mxl862xx_phy_write_mii_bus(struct mii_bus *bus, int port, + int regnum, u16 val) +{ + return mxl862xx_phy_write_mmd(bus->priv, port, 0, regnum, val); +} + +static int mxl862xx_phy_read_c45_mii_bus(struct mii_bus *bus, int port, + int devadd, int regnum) +{ + return mxl862xx_phy_read_mmd(bus->priv, port, devadd, regnum); +} + +static int mxl862xx_phy_write_c45_mii_bus(struct mii_bus *bus, int port, + int devadd, int regnum, u16 val) +{ + return mxl862xx_phy_write_mmd(bus->priv, port, devadd, regnum, val); +} + +static int mxl862xx_configure_ctp_port(struct dsa_switch *ds, int port, + u16 first_ctp_port_id, + u16 number_of_ctp_ports) +{ + struct mxl862xx_ctp_port_assignment ctp_assign = { + .logical_port_id = port, + .first_ctp_port_id = cpu_to_le16(first_ctp_port_id), + .number_of_ctp_port = cpu_to_le16(number_of_ctp_ports), + .mode = cpu_to_le32(MXL862XX_LOGICAL_PORT_ETHERNET), + }; + + return MXL862XX_API_WRITE(ds->priv, MXL862XX_CTP_PORTASSIGNMENTSET, + ctp_assign); +} + +static int mxl862xx_configure_sp_tag_proto(struct dsa_switch *ds, int port, + bool enable) +{ + struct mxl862xx_ss_sp_tag tag = { + .pid = port, + .mask = MXL862XX_SS_SP_TAG_MASK_RX | MXL862XX_SS_SP_TAG_MASK_TX, + .rx = enable ? MXL862XX_SS_SP_TAG_RX_TAG_NO_INSERT : + MXL862XX_SS_SP_TAG_RX_NO_TAG_INSERT, + .tx = enable ? MXL862XX_SS_SP_TAG_TX_TAG_NO_REMOVE : + MXL862XX_SS_SP_TAG_TX_TAG_REMOVE, + }; + + return MXL862XX_API_WRITE(ds->priv, MXL862XX_SS_SPTAG_SET, tag); +} + +static int mxl862xx_port_state(struct dsa_switch *ds, int port, bool enable) +{ + struct mxl862xx_register_mod sdma = { + .addr = cpu_to_le16(MXL862XX_SDMA_PCTRLP(port)), + .data = cpu_to_le16(enable ? MXL862XX_SDMA_PCTRL_EN : 0), + .mask = cpu_to_le16(MXL862XX_SDMA_PCTRL_EN), + }; + struct mxl862xx_register_mod fdma = { + .addr = cpu_to_le16(MXL862XX_FDMA_PCTRLP(port)), + .data = cpu_to_le16(enable ? MXL862XX_FDMA_PCTRL_EN : 0), + .mask = cpu_to_le16(MXL862XX_FDMA_PCTRL_EN), + }; + int ret; + + ret = MXL862XX_API_WRITE(ds->priv, MXL862XX_COMMON_REGISTERMOD, sdma); + if (ret) + return ret; + + return MXL862XX_API_WRITE(ds->priv, MXL862XX_COMMON_REGISTERMOD, fdma); +} + +static int mxl862xx_port_enable(struct dsa_switch *ds, int port, + struct phy_device *phydev) +{ + return mxl862xx_port_state(ds, port, true); +} + +static void mxl862xx_port_disable(struct dsa_switch *ds, int port) +{ + if (mxl862xx_port_state(ds, port, false)) + dev_err(ds->dev, "failed to disable port %d\n", port); +} + +static void mxl862xx_port_fast_age(struct dsa_switch *ds, int port) +{ + struct mxl862xx_mac_table_clear param = { + .type = MXL862XX_MAC_CLEAR_PHY_PORT, + .port_id = port, + }; + + if (MXL862XX_API_WRITE(ds->priv, MXL862XX_MAC_TABLECLEARCOND, param)) + dev_err(ds->dev, "failed to clear fdb on port %d\n", port); +} + +static int mxl862xx_add_single_port_bridge(struct dsa_switch *ds, int port) +{ + struct mxl862xx_bridge_port_config br_port_cfg = {}; + struct dsa_port *dp = dsa_to_port(ds, port); + struct mxl862xx_bridge_alloc br_alloc = {}; + int ret; + + if (!dp) + return -ENODEV; + + ret = MXL862XX_API_READ(ds->priv, MXL862XX_BRIDGE_ALLOC, br_alloc); + if (ret) { + dev_err(ds->dev, "failed to allocate a bridge for port %d\n", port); + return ret; + } + + br_port_cfg.bridge_id = br_alloc.bridge_id; + br_port_cfg.bridge_port_id = cpu_to_le16(port); + br_port_cfg.mask = cpu_to_le32(MXL862XX_BRIDGE_PORT_CONFIG_MASK_BRIDGE_ID | + MXL862XX_BRIDGE_PORT_CONFIG_MASK_BRIDGE_PORT_MAP | + MXL862XX_BRIDGE_PORT_CONFIG_MASK_MC_SRC_MAC_LEARNING | + MXL862XX_BRIDGE_PORT_CONFIG_MASK_VLAN_BASED_MAC_LEARNING); + br_port_cfg.src_mac_learning_disable = true; + br_port_cfg.vlan_src_mac_vid_enable = false; + br_port_cfg.vlan_dst_mac_vid_enable = false; + if (dp->cpu_dp) + br_port_cfg.bridge_port_map[0] = cpu_to_le16(BIT(dp->cpu_dp->index)); + + return MXL862XX_API_WRITE(ds->priv, MXL862XX_BRIDGEPORT_CONFIGSET, br_port_cfg); +} + +static int mxl862xx_setup_mdio(struct dsa_switch *ds) +{ + struct mxl862xx_priv *priv = ds->priv; + struct device *dev = ds->dev; + struct device_node *mdio_np; + struct mii_bus *bus; + int ret; + + bus = devm_mdiobus_alloc(dev); + if (!bus) + return -ENOMEM; + + bus->priv = priv; + ds->user_mii_bus = bus; + bus->name = KBUILD_MODNAME "-mii"; + snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(dev)); + bus->read_c45 = mxl862xx_phy_read_c45_mii_bus; + bus->write_c45 = mxl862xx_phy_write_c45_mii_bus; + bus->read = mxl862xx_phy_read_mii_bus; + bus->write = mxl862xx_phy_write_mii_bus; + bus->parent = dev; + bus->phy_mask = ~ds->phys_mii_mask; + + mdio_np = of_get_child_by_name(dev->of_node, "mdio"); + if (!mdio_np) + return -ENODEV; + + ret = devm_of_mdiobus_register(dev, bus, mdio_np); + of_node_put(mdio_np); + + return ret; +} + +static int mxl862xx_wait_ready(struct dsa_switch *ds) +{ + struct mxl862xx_sys_fw_image_version ver = {}; + unsigned long start = jiffies, timeout; + struct mxl862xx_priv *priv = ds->priv; + struct mxl862xx_cfg cfg = {}; + int ret; + + timeout = start + msecs_to_jiffies(MXL862XX_READY_TIMEOUT_MS); + msleep(2000); /* it always takes at least 2 seconds */ + do { + ret = MXL862XX_API_READ_QUIET(priv, SYS_MISC_FW_VERSION, ver); + if (ret || !ver.iv_major) + goto not_ready_yet; + + /* being able to perform CFGGET indicates that + * the firmware is ready + */ + ret = MXL862XX_API_READ_QUIET(priv, + MXL862XX_COMMON_CFGGET, + cfg); + if (ret) + goto not_ready_yet; + + dev_info(ds->dev, "switch ready after %ums, firmware %u.%u.%u (build %u)\n", + jiffies_to_msecs(jiffies - start), + ver.iv_major, ver.iv_minor, + le16_to_cpu(ver.iv_revision), + le32_to_cpu(ver.iv_build_num)); + return 0; + +not_ready_yet: + msleep(MXL862XX_READY_POLL_MS); + } while (time_before(jiffies, timeout)); + + dev_err(ds->dev, "switch not responding after reset\n"); + return -ETIMEDOUT; +} + +static int mxl862xx_setup_cpu_bridge(struct dsa_switch *ds, int port) +{ + struct mxl862xx_bridge_port_config br_port_cfg = {}; + struct mxl862xx_priv *priv = ds->priv; + u16 bridge_port_map = 0; + struct dsa_port *dp; + + /* CPU port bridge setup */ + br_port_cfg.mask = cpu_to_le32(MXL862XX_BRIDGE_PORT_CONFIG_MASK_BRIDGE_PORT_MAP | + MXL862XX_BRIDGE_PORT_CONFIG_MASK_MC_SRC_MAC_LEARNING | + MXL862XX_BRIDGE_PORT_CONFIG_MASK_VLAN_BASED_MAC_LEARNING); + + br_port_cfg.bridge_port_id = cpu_to_le16(port); + br_port_cfg.src_mac_learning_disable = false; + br_port_cfg.vlan_src_mac_vid_enable = true; + br_port_cfg.vlan_dst_mac_vid_enable = true; + + /* include all assigned user ports in the CPU portmap */ + dsa_switch_for_each_user_port(dp, ds) { + if (!dp->cpu_dp) + continue; + + if (dp->cpu_dp->index != port) + continue; + + bridge_port_map |= BIT(dp->index); + } + br_port_cfg.bridge_port_map[0] |= cpu_to_le16(bridge_port_map); + + return MXL862XX_API_WRITE(priv, MXL862XX_BRIDGEPORT_CONFIGSET, br_port_cfg); +} + +static int mxl862xx_setup(struct dsa_switch *ds) +{ + struct mxl862xx_priv *priv = ds->priv; + int ret; + + ret = mxl862xx_reset(priv); + if (ret) + return ret; + + ret = mxl862xx_wait_ready(ds); + if (ret) + return ret; + + return mxl862xx_setup_mdio(ds); +} + +static int mxl862xx_port_setup(struct dsa_switch *ds, int port) +{ + bool is_cpu_port = dsa_is_cpu_port(ds, port); + int ret; + + /* disable port and flush MAC entries */ + ret = mxl862xx_port_state(ds, port, false); + if (ret) + return ret; + + mxl862xx_port_fast_age(ds, port); + + /* skip setup for unused and DSA ports */ + if (dsa_is_unused_port(ds, port) || + dsa_is_dsa_port(ds, port)) + return 0; + + /* configure tag protocol */ + ret = mxl862xx_configure_sp_tag_proto(ds, port, is_cpu_port); + if (ret) + return ret; + + /* assign CTP port IDs */ + ret = mxl862xx_configure_ctp_port(ds, port, port, + is_cpu_port ? 32 - port : 1); + if (ret) + return ret; + + if (is_cpu_port) + /* assign user ports to CPU port bridge */ + return mxl862xx_setup_cpu_bridge(ds, port); + + /* setup single-port bridge for user ports */ + return mxl862xx_add_single_port_bridge(ds, port); +} + +static void mxl862xx_phylink_get_caps(struct dsa_switch *ds, int port, + struct phylink_config *config) +{ + config->mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE | MAC_10 | + MAC_100 | MAC_1000 | MAC_2500FD; + + __set_bit(PHY_INTERFACE_MODE_INTERNAL, + config->supported_interfaces); +} + +static const struct dsa_switch_ops mxl862xx_switch_ops = { + .get_tag_protocol = mxl862xx_get_tag_protocol, + .setup = mxl862xx_setup, + .port_setup = mxl862xx_port_setup, + .phylink_get_caps = mxl862xx_phylink_get_caps, + .port_enable = mxl862xx_port_enable, + .port_disable = mxl862xx_port_disable, + .port_fast_age = mxl862xx_port_fast_age, +}; + +static void mxl862xx_phylink_mac_config(struct phylink_config *config, + unsigned int mode, + const struct phylink_link_state *state) +{ +} + +static void mxl862xx_phylink_mac_link_down(struct phylink_config *config, + unsigned int mode, + phy_interface_t interface) +{ +} + +static void mxl862xx_phylink_mac_link_up(struct phylink_config *config, + struct phy_device *phydev, + unsigned int mode, + phy_interface_t interface, + int speed, int duplex, + bool tx_pause, bool rx_pause) +{ +} + +static const struct phylink_mac_ops mxl862xx_phylink_mac_ops = { + .mac_config = mxl862xx_phylink_mac_config, + .mac_link_down = mxl862xx_phylink_mac_link_down, + .mac_link_up = mxl862xx_phylink_mac_link_up, +}; + +static int mxl862xx_probe(struct mdio_device *mdiodev) +{ + struct device *dev = &mdiodev->dev; + struct mxl862xx_priv *priv; + struct dsa_switch *ds; + int ret; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->mdiodev = mdiodev; + + ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL); + if (!ds) + return -ENOMEM; + + priv->ds = ds; + ds->dev = dev; + ds->priv = priv; + ds->ops = &mxl862xx_switch_ops; + ds->phylink_mac_ops = &mxl862xx_phylink_mac_ops; + ds->num_ports = MXL862XX_MAX_PORTS; + + ret = dsa_register_switch(ds); + if (ret) + return ret; + + dev_set_drvdata(dev, ds); + + return 0; +} + +static void mxl862xx_remove(struct mdio_device *mdiodev) +{ + struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev); + + if (!ds) + return; + + dsa_unregister_switch(ds); +} + +static void mxl862xx_shutdown(struct mdio_device *mdiodev) +{ + struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev); + + if (!ds) + return; + + dsa_switch_shutdown(ds); + + dev_set_drvdata(&mdiodev->dev, NULL); +} + +static const struct of_device_id mxl862xx_of_match[] = { + { .compatible = "maxlinear,mxl86282" }, + { .compatible = "maxlinear,mxl86252" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, mxl862xx_of_match); + +static struct mdio_driver mxl862xx_driver = { + .probe = mxl862xx_probe, + .remove = mxl862xx_remove, + .shutdown = mxl862xx_shutdown, + .mdiodrv.driver = { + .name = "mxl862xx", + .of_match_table = mxl862xx_of_match, + }, +}; + +mdio_module_driver(mxl862xx_driver); + +MODULE_DESCRIPTION("Driver for MaxLinear MxL862xx switch family"); +MODULE_LICENSE("GPL"); diff --git a/drivers/net/dsa/mxl862xx/mxl862xx.h b/drivers/net/dsa/mxl862xx/mxl862xx.h new file mode 100644 index 000000000000..bfeb436942d5 --- /dev/null +++ b/drivers/net/dsa/mxl862xx/mxl862xx.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef __MXL862XX_H +#define __MXL862XX_H + +#include <linux/mdio.h> +#include <net/dsa.h> + +#define MXL862XX_MAX_PORTS 17 + +struct mxl862xx_priv { + struct dsa_switch *ds; + struct mdio_device *mdiodev; +}; + +#endif /* __MXL862XX_H */ -- 2.52.0
{ "author": "Daniel Golle <daniel@makrotopia.org>", "date": "Sun, 1 Feb 2026 02:25:13 +0000", "thread_id": "aYDoTSySNt7vXazL@makrotopia.org.mbox.gz" }
lkml
[PATCH v12 0/4] net: dsa: initial support for MaxLinear MxL862xx switches
This series adds very basic DSA support for the MaxLinear MxL86252 (5x 2500Base-T PHYs) and MxL86282 (8x 2500Base-T PHYs) switches. In addition to the 2.5G TP ports both switches also come with two SerDes interfaces which can be used either to connect external PHYs or SFP cages, or as CPU port when using the switch with this DSA driver. MxL862xx integrates a firmware running on an embedded processor (based on Zephyr RTOS). Host interaction uses a simple netlink-like API transported over MDIO/MMD. This series includes only what's needed to pass traffic between user ports and the CPU port: relayed MDIO to internal PHYs, basic port enable/disable, and CPU-port special tagging. The SerDes interface of the CPU port is automatically configured by the switch after reset using a board-specific configuration stored together with the firmware in the flash chip attached to the switch, so no action is needed from the driver to setup the interface mode of the CPU port. Also MAC settings of the PHY ports are automatically configured, which means the driver works fine with phylink_mac_ops being all no-op stubs. Multiple follow up series will bring support for setting up the other SerDes PCS interface (ie. not used for the CPU port), bridge, VLAN, ... offloading, and support for using an 802.1Q-based special tag instead of the proprietary 8-byte tag. --- basic DSA selftests were run, results: * no_forwarding.sh: all tests PASS * bridge_vlan_unaware.sh: all tests PASS * bridge_vlan_mcast.sh: all tests PASS * bridge_vlan_aware.sh: all tests PASS * local_termination.sh: all tests PASS or XFAIL, except for TEST: VLAN over vlan_filtering=1 bridged port: Unicast IPv4 to unknown MAC address [FAIL] reception succeeded, but should have failed TEST: VLAN over vlan_filtering=1 bridged port: Unicast IPv4 to unknown MAC address, allmulti [FAIL] reception succeeded, but should have failed As obviously this is mostly testing the Linux software bridge at this point so I didn't bother to run any of the FDB or MDB related tests. Some mystery about the relationship between the sub-interface ID and CTP port assignment remains for now, so I cannot yet fully explain the magic numbers when calculating the two. (Why is it neccesary to allocate 23 CTPs when using port 9 as CPU port while there are at most 17 phyiscal interfaces in total, and only at most 13 when using one of the two SerDes as CPU interface? Why is there an offset of 16 when calculating the sub-interface ID? How will a total of 17 ports be possibly represented in a 4-bit field in the tag RX path?) At this point this doesn't impact functionality, and I hope for further clarification discussing all that with MaxLinear engineers. I believe the initial driver is anyway in good shape now, a follow-up series addressing configuring the SerDes interfaces will also have to take care of CTP assignment and sub-interfaces to not hit the mentioned 4-bit cap in the tag driver. Changes since v11: Address comments reported by Jakub Kicinski using netdev-ai https://patchwork.kernel.org/comment/26767905/ 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * list switch variants in Kconfig starting with dash ('-') * remove the __packed attribute on structs which are naturally packed according to C rules (ie. one other struct with only a single byte-aligned member) * log error in mxl862xx_port_disable() * introduce !NULL check for return value of dsa_to_port() in mxl862xx_add_single_port_bridge * check cpu_dp being non-NULL before dereferencing dp->cpu_dp * use non-racy and deterministic name for MII bus * skip ports without cpu_dp assigned in mxl862xx_setup_cpu_bridge() to avoid potential NULL-pointer dereference * call dev_set_drvdata() only after dsa_register_switch() has been successfully completed Changes since v10: 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * arrange local variables in reverse xmas tree order (again) * use MXL862_NAME as .name in struct dsa_device_ops 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix fatal last-second changes dsa_port_is_unused vs. dsa_is_unused_port and dsa_port_is_unused vs. dsa_is_unused_port * use cpu_to_le16 in mxl862xx_configure_ctp_port * improve formatting of some kerneldoc comments Changes since v9: 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * add microcontroller port 0 2/4 net: dsa: add tag format for MxL862xx switches * count ports starting from 0 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix indentation in kernel-doc * remove misleading comment regarding sub-interface IDs * remove unused macros, set MXL862XX_MAX_PORTS to 17 * count ports starting from 0, 0 being the microcontroller * improve port setup: - split tag protocol and CTP port assignment - use ports cpu_dp instead of relying on single (ie. first) CPU port - handle CPU port like any other port - prepare forward DT compatibility with multiple CPU ports Changes since v8: 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * remove practically unused struct hw_info * lots of kerneldoc improvements in mxl862xx-api.h * drop .mac_select_pcs() stub * better handling for firmware error return value * apply reverse xmas tree in mxl862xx_api_wrap * guard headers with #ifdef macro * include net/dsa.h and linux/mdio.h in mxl862xx.h * call mxl862xx_port_fast_age() only once in .port_setup * don't create isolation bridges for unused ports * replace errornous cast with correct range of values denoting firmware errors Changes since v7 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * use little-endian in bridge_port_config API * remove duplciate assignment of br_port_cfg.bridge_port_id when setting up CPU port Changes since v6 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix kerneldoc style Changes since RFC v5 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * remove unnecessary check for skb != NULL * merge consecutively printed warnings into single dev_warn_ratelimited 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * include bridge and bridgeport API needed to isolate ports * remove warning in .setup as ports are now isolated * make ready-after-reset check more robust by adding delay * sort structs in order of struct definitions * best effort to sort functions without introducing additional prototypes * always use enums with kerneldoc comments in mxl862xx-api.h * remove bogus .phy_read and .phy_write DSA ops as the driver anyway registers a user MDIO bus with Clause-22 and Clause-45 operations * various small style fixes Changes since RFC v4 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * drop unused precompiler macros 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * fix indentation 4/4 net: dsa: add basic initial driver for MxL862xx switches * output warning in .setup regarding unknown pre-configuration * add comment explaining why CFGGET is used in reset function Changes since RFC v3 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * remove labels from example * remove 'bindings for' from commit title 2/4 net: dsa: add tag format for MxL862xx switches * describe fields and variables with comments * sub-interface is only 5 bits * harmonize Kconfig symbol name * maintain alphabetic order in Kconfig * fix typo s/beginnig/beginning/ * fix typo s/swtiches/switches/ * arrange local variables in reverse xmas tree order 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * unchanged 4/4 net: dsa: add basic initial driver for MxL862xx switches * poll switch readiness after reset * implement driver shutdown * added port_fast_aging API call and driver op * unified port setup in new .port_setup op * improve comment explaining special handlign for unaligned API read * various typos and formatting improvements Changes since RFC v2 1/4, 2/4, 3/4: unchanged 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix return value being uninitialized on error in mxl862xx_api_wrap() * add missing description in kerneldoc comment of struct mxl862xx_ss_sp_tag Changes since initial RFC 1/4 dt-bindings: net: dsa: add bindings for MaxLinear MxL862xx * better description in dt-bindings doc 2/4 net: dsa: add tag formats for MxL862xx switches * make sure all tag fields are initialized 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * new patch 4/4 net: dsa: add basic initial driver for MxL862xx switches * make use of struct mdio_device * add phylink_mac_ops stubs * drop leftover nonsense from mxl862xx_phylink_get_caps() * fix endian conversions * use __le32 instead of enum types in over-the-wire structs * use existing MDIO_* macros whenever possible * simplify API constants to be more readable * use readx_poll_timeout instead of open-coding poll timeout loop * add mxl862xx_reg_read() and mxl862xx_reg_write() helpers * demystify error codes returned by the firmware * add #defines for mxl862xx_ss_sp_tag member values * move reset to dedicated function, clarify magic number being the reset command ID Daniel Golle (4): dt-bindings: net: dsa: add MaxLinear MxL862xx net: dsa: add tag format for MxL862xx switches net: mdio: add unlocked mdiodev C45 bus accessors net: dsa: add basic initial driver for MxL862xx switches .../bindings/net/dsa/maxlinear,mxl862xx.yaml | 160 +++++ MAINTAINERS | 8 + drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/mxl862xx/Kconfig | 12 + drivers/net/dsa/mxl862xx/Makefile | 3 + drivers/net/dsa/mxl862xx/mxl862xx-api.h | 675 ++++++++++++++++++ drivers/net/dsa/mxl862xx/mxl862xx-cmd.h | 49 ++ drivers/net/dsa/mxl862xx/mxl862xx-host.c | 245 +++++++ drivers/net/dsa/mxl862xx/mxl862xx-host.h | 12 + drivers/net/dsa/mxl862xx/mxl862xx.c | 483 +++++++++++++ drivers/net/dsa/mxl862xx/mxl862xx.h | 16 + include/linux/mdio.h | 13 + include/net/dsa.h | 2 + net/dsa/Kconfig | 7 + net/dsa/Makefile | 1 + net/dsa/tag_mxl862xx.c | 110 +++ 17 files changed, 1799 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/maxlinear,mxl862xx.yaml create mode 100644 drivers/net/dsa/mxl862xx/Kconfig create mode 100644 drivers/net/dsa/mxl862xx/Makefile create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-api.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-cmd.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-host.c create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-host.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx.c create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx.h create mode 100644 net/dsa/tag_mxl862xx.c -- 2.52.0
On Sun, Feb 01, 2026 at 02:25:13AM +0000, Daniel Golle wrote: I have nothing else to comment except to request you to undo some of the changes requested by AI review. Sorry I didn't have time to comment on v11. I'm sorry, I can't accept code that fears its own shadow. Some people, when they see a defensive NULL check think there is a valid reason behind it and will try to see what that reason is. If dsa_to_port() would have possibly returned NULL, mxl862xx_port_setup() -> dsa_is_cpu_port(), which _is_ implemented using dsa_to_port(), would have already crashed the kernel and this test here would have been too little, too late. But the kernel doesn't crash there, because calling dsa_to_port() is safe for these arguments, and this test is simply logically inconsistent with previous unconditional in this call path. As per the dt-bindings patch, the "mdio" child node is not required. But here it is. All user ports are given a valid non-NULL dp->cpu_dp pointer. I strongly oppose introducing FUD in the code. If there are valid reasons behind this I'm all ears, but there aren't. Each of dsa_is_cpu_port(), dsa_is_unused_port(), dsa_is_dsa_port() are implemented using dsa_to_port(), and that loops over dst->ports in order to find "dp" just to return dp->index. OTOH if you call dsa_to_port() only once, we have dsa_port_is_cpu(), dsa_port_is_unused(), dsa_port_is_dsa() which can be called on that and have lower complexity. Please do that. You do _not_ need to test whether dsa_to_port() returns NULL, if "ds" and "port" were passed to you by DSA in the context of a DSA callback. Any exception to this rule will be explicitly noted in the documentation. There is no point in doing this, calling dev_set_drvdata() before and then simply "return dsa_register_switch()" is perfectly fine. You also won't need the "ret" variable.
{ "author": "Vladimir Oltean <olteanv@gmail.com>", "date": "Mon, 2 Feb 2026 12:23:26 +0200", "thread_id": "aYDoTSySNt7vXazL@makrotopia.org.mbox.gz" }
lkml
[PATCH v12 0/4] net: dsa: initial support for MaxLinear MxL862xx switches
This series adds very basic DSA support for the MaxLinear MxL86252 (5x 2500Base-T PHYs) and MxL86282 (8x 2500Base-T PHYs) switches. In addition to the 2.5G TP ports both switches also come with two SerDes interfaces which can be used either to connect external PHYs or SFP cages, or as CPU port when using the switch with this DSA driver. MxL862xx integrates a firmware running on an embedded processor (based on Zephyr RTOS). Host interaction uses a simple netlink-like API transported over MDIO/MMD. This series includes only what's needed to pass traffic between user ports and the CPU port: relayed MDIO to internal PHYs, basic port enable/disable, and CPU-port special tagging. The SerDes interface of the CPU port is automatically configured by the switch after reset using a board-specific configuration stored together with the firmware in the flash chip attached to the switch, so no action is needed from the driver to setup the interface mode of the CPU port. Also MAC settings of the PHY ports are automatically configured, which means the driver works fine with phylink_mac_ops being all no-op stubs. Multiple follow up series will bring support for setting up the other SerDes PCS interface (ie. not used for the CPU port), bridge, VLAN, ... offloading, and support for using an 802.1Q-based special tag instead of the proprietary 8-byte tag. --- basic DSA selftests were run, results: * no_forwarding.sh: all tests PASS * bridge_vlan_unaware.sh: all tests PASS * bridge_vlan_mcast.sh: all tests PASS * bridge_vlan_aware.sh: all tests PASS * local_termination.sh: all tests PASS or XFAIL, except for TEST: VLAN over vlan_filtering=1 bridged port: Unicast IPv4 to unknown MAC address [FAIL] reception succeeded, but should have failed TEST: VLAN over vlan_filtering=1 bridged port: Unicast IPv4 to unknown MAC address, allmulti [FAIL] reception succeeded, but should have failed As obviously this is mostly testing the Linux software bridge at this point so I didn't bother to run any of the FDB or MDB related tests. Some mystery about the relationship between the sub-interface ID and CTP port assignment remains for now, so I cannot yet fully explain the magic numbers when calculating the two. (Why is it neccesary to allocate 23 CTPs when using port 9 as CPU port while there are at most 17 phyiscal interfaces in total, and only at most 13 when using one of the two SerDes as CPU interface? Why is there an offset of 16 when calculating the sub-interface ID? How will a total of 17 ports be possibly represented in a 4-bit field in the tag RX path?) At this point this doesn't impact functionality, and I hope for further clarification discussing all that with MaxLinear engineers. I believe the initial driver is anyway in good shape now, a follow-up series addressing configuring the SerDes interfaces will also have to take care of CTP assignment and sub-interfaces to not hit the mentioned 4-bit cap in the tag driver. Changes since v11: Address comments reported by Jakub Kicinski using netdev-ai https://patchwork.kernel.org/comment/26767905/ 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * list switch variants in Kconfig starting with dash ('-') * remove the __packed attribute on structs which are naturally packed according to C rules (ie. one other struct with only a single byte-aligned member) * log error in mxl862xx_port_disable() * introduce !NULL check for return value of dsa_to_port() in mxl862xx_add_single_port_bridge * check cpu_dp being non-NULL before dereferencing dp->cpu_dp * use non-racy and deterministic name for MII bus * skip ports without cpu_dp assigned in mxl862xx_setup_cpu_bridge() to avoid potential NULL-pointer dereference * call dev_set_drvdata() only after dsa_register_switch() has been successfully completed Changes since v10: 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * arrange local variables in reverse xmas tree order (again) * use MXL862_NAME as .name in struct dsa_device_ops 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix fatal last-second changes dsa_port_is_unused vs. dsa_is_unused_port and dsa_port_is_unused vs. dsa_is_unused_port * use cpu_to_le16 in mxl862xx_configure_ctp_port * improve formatting of some kerneldoc comments Changes since v9: 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * add microcontroller port 0 2/4 net: dsa: add tag format for MxL862xx switches * count ports starting from 0 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix indentation in kernel-doc * remove misleading comment regarding sub-interface IDs * remove unused macros, set MXL862XX_MAX_PORTS to 17 * count ports starting from 0, 0 being the microcontroller * improve port setup: - split tag protocol and CTP port assignment - use ports cpu_dp instead of relying on single (ie. first) CPU port - handle CPU port like any other port - prepare forward DT compatibility with multiple CPU ports Changes since v8: 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * remove practically unused struct hw_info * lots of kerneldoc improvements in mxl862xx-api.h * drop .mac_select_pcs() stub * better handling for firmware error return value * apply reverse xmas tree in mxl862xx_api_wrap * guard headers with #ifdef macro * include net/dsa.h and linux/mdio.h in mxl862xx.h * call mxl862xx_port_fast_age() only once in .port_setup * don't create isolation bridges for unused ports * replace errornous cast with correct range of values denoting firmware errors Changes since v7 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * use little-endian in bridge_port_config API * remove duplciate assignment of br_port_cfg.bridge_port_id when setting up CPU port Changes since v6 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix kerneldoc style Changes since RFC v5 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * remove unnecessary check for skb != NULL * merge consecutively printed warnings into single dev_warn_ratelimited 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * include bridge and bridgeport API needed to isolate ports * remove warning in .setup as ports are now isolated * make ready-after-reset check more robust by adding delay * sort structs in order of struct definitions * best effort to sort functions without introducing additional prototypes * always use enums with kerneldoc comments in mxl862xx-api.h * remove bogus .phy_read and .phy_write DSA ops as the driver anyway registers a user MDIO bus with Clause-22 and Clause-45 operations * various small style fixes Changes since RFC v4 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * drop unused precompiler macros 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * fix indentation 4/4 net: dsa: add basic initial driver for MxL862xx switches * output warning in .setup regarding unknown pre-configuration * add comment explaining why CFGGET is used in reset function Changes since RFC v3 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * remove labels from example * remove 'bindings for' from commit title 2/4 net: dsa: add tag format for MxL862xx switches * describe fields and variables with comments * sub-interface is only 5 bits * harmonize Kconfig symbol name * maintain alphabetic order in Kconfig * fix typo s/beginnig/beginning/ * fix typo s/swtiches/switches/ * arrange local variables in reverse xmas tree order 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * unchanged 4/4 net: dsa: add basic initial driver for MxL862xx switches * poll switch readiness after reset * implement driver shutdown * added port_fast_aging API call and driver op * unified port setup in new .port_setup op * improve comment explaining special handlign for unaligned API read * various typos and formatting improvements Changes since RFC v2 1/4, 2/4, 3/4: unchanged 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix return value being uninitialized on error in mxl862xx_api_wrap() * add missing description in kerneldoc comment of struct mxl862xx_ss_sp_tag Changes since initial RFC 1/4 dt-bindings: net: dsa: add bindings for MaxLinear MxL862xx * better description in dt-bindings doc 2/4 net: dsa: add tag formats for MxL862xx switches * make sure all tag fields are initialized 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * new patch 4/4 net: dsa: add basic initial driver for MxL862xx switches * make use of struct mdio_device * add phylink_mac_ops stubs * drop leftover nonsense from mxl862xx_phylink_get_caps() * fix endian conversions * use __le32 instead of enum types in over-the-wire structs * use existing MDIO_* macros whenever possible * simplify API constants to be more readable * use readx_poll_timeout instead of open-coding poll timeout loop * add mxl862xx_reg_read() and mxl862xx_reg_write() helpers * demystify error codes returned by the firmware * add #defines for mxl862xx_ss_sp_tag member values * move reset to dedicated function, clarify magic number being the reset command ID Daniel Golle (4): dt-bindings: net: dsa: add MaxLinear MxL862xx net: dsa: add tag format for MxL862xx switches net: mdio: add unlocked mdiodev C45 bus accessors net: dsa: add basic initial driver for MxL862xx switches .../bindings/net/dsa/maxlinear,mxl862xx.yaml | 160 +++++ MAINTAINERS | 8 + drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/mxl862xx/Kconfig | 12 + drivers/net/dsa/mxl862xx/Makefile | 3 + drivers/net/dsa/mxl862xx/mxl862xx-api.h | 675 ++++++++++++++++++ drivers/net/dsa/mxl862xx/mxl862xx-cmd.h | 49 ++ drivers/net/dsa/mxl862xx/mxl862xx-host.c | 245 +++++++ drivers/net/dsa/mxl862xx/mxl862xx-host.h | 12 + drivers/net/dsa/mxl862xx/mxl862xx.c | 483 +++++++++++++ drivers/net/dsa/mxl862xx/mxl862xx.h | 16 + include/linux/mdio.h | 13 + include/net/dsa.h | 2 + net/dsa/Kconfig | 7 + net/dsa/Makefile | 1 + net/dsa/tag_mxl862xx.c | 110 +++ 17 files changed, 1799 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/maxlinear,mxl862xx.yaml create mode 100644 drivers/net/dsa/mxl862xx/Kconfig create mode 100644 drivers/net/dsa/mxl862xx/Makefile create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-api.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-cmd.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-host.c create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-host.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx.c create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx.h create mode 100644 net/dsa/tag_mxl862xx.c -- 2.52.0
On Sun, Feb 01, 2026 at 02:25:03AM +0000, Daniel Golle wrote: Sigh, there's too many versions of this patch series. While netdev has a 24H period, there is also this - note the last sentence. The reason this exists is to stop this exact problem, where ongoing discussion is split across multiple different versions of the same series. Resending after review ~~~~~~~~~~~~~~~~~~~~~~ Allow at least 24 hours to pass between postings. This will ensure reviewers from all geographical locations have a chance to chime in. Do not wait too long (weeks) between postings either as it will make it harder for reviewers to recall all the context. Make sure you address all the feedback in your new posting. *Do not post a new version of the code if the discussion about the previous version is still ongoing, unless directly instructed by a reviewer.* -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
{ "author": "\"Russell King (Oracle)\" <linux@armlinux.org.uk>", "date": "Mon, 2 Feb 2026 11:08:39 +0000", "thread_id": "aYDoTSySNt7vXazL@makrotopia.org.mbox.gz" }
lkml
[PATCH v12 0/4] net: dsa: initial support for MaxLinear MxL862xx switches
This series adds very basic DSA support for the MaxLinear MxL86252 (5x 2500Base-T PHYs) and MxL86282 (8x 2500Base-T PHYs) switches. In addition to the 2.5G TP ports both switches also come with two SerDes interfaces which can be used either to connect external PHYs or SFP cages, or as CPU port when using the switch with this DSA driver. MxL862xx integrates a firmware running on an embedded processor (based on Zephyr RTOS). Host interaction uses a simple netlink-like API transported over MDIO/MMD. This series includes only what's needed to pass traffic between user ports and the CPU port: relayed MDIO to internal PHYs, basic port enable/disable, and CPU-port special tagging. The SerDes interface of the CPU port is automatically configured by the switch after reset using a board-specific configuration stored together with the firmware in the flash chip attached to the switch, so no action is needed from the driver to setup the interface mode of the CPU port. Also MAC settings of the PHY ports are automatically configured, which means the driver works fine with phylink_mac_ops being all no-op stubs. Multiple follow up series will bring support for setting up the other SerDes PCS interface (ie. not used for the CPU port), bridge, VLAN, ... offloading, and support for using an 802.1Q-based special tag instead of the proprietary 8-byte tag. --- basic DSA selftests were run, results: * no_forwarding.sh: all tests PASS * bridge_vlan_unaware.sh: all tests PASS * bridge_vlan_mcast.sh: all tests PASS * bridge_vlan_aware.sh: all tests PASS * local_termination.sh: all tests PASS or XFAIL, except for TEST: VLAN over vlan_filtering=1 bridged port: Unicast IPv4 to unknown MAC address [FAIL] reception succeeded, but should have failed TEST: VLAN over vlan_filtering=1 bridged port: Unicast IPv4 to unknown MAC address, allmulti [FAIL] reception succeeded, but should have failed As obviously this is mostly testing the Linux software bridge at this point so I didn't bother to run any of the FDB or MDB related tests. Some mystery about the relationship between the sub-interface ID and CTP port assignment remains for now, so I cannot yet fully explain the magic numbers when calculating the two. (Why is it neccesary to allocate 23 CTPs when using port 9 as CPU port while there are at most 17 phyiscal interfaces in total, and only at most 13 when using one of the two SerDes as CPU interface? Why is there an offset of 16 when calculating the sub-interface ID? How will a total of 17 ports be possibly represented in a 4-bit field in the tag RX path?) At this point this doesn't impact functionality, and I hope for further clarification discussing all that with MaxLinear engineers. I believe the initial driver is anyway in good shape now, a follow-up series addressing configuring the SerDes interfaces will also have to take care of CTP assignment and sub-interfaces to not hit the mentioned 4-bit cap in the tag driver. Changes since v11: Address comments reported by Jakub Kicinski using netdev-ai https://patchwork.kernel.org/comment/26767905/ 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * list switch variants in Kconfig starting with dash ('-') * remove the __packed attribute on structs which are naturally packed according to C rules (ie. one other struct with only a single byte-aligned member) * log error in mxl862xx_port_disable() * introduce !NULL check for return value of dsa_to_port() in mxl862xx_add_single_port_bridge * check cpu_dp being non-NULL before dereferencing dp->cpu_dp * use non-racy and deterministic name for MII bus * skip ports without cpu_dp assigned in mxl862xx_setup_cpu_bridge() to avoid potential NULL-pointer dereference * call dev_set_drvdata() only after dsa_register_switch() has been successfully completed Changes since v10: 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * arrange local variables in reverse xmas tree order (again) * use MXL862_NAME as .name in struct dsa_device_ops 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix fatal last-second changes dsa_port_is_unused vs. dsa_is_unused_port and dsa_port_is_unused vs. dsa_is_unused_port * use cpu_to_le16 in mxl862xx_configure_ctp_port * improve formatting of some kerneldoc comments Changes since v9: 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * add microcontroller port 0 2/4 net: dsa: add tag format for MxL862xx switches * count ports starting from 0 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix indentation in kernel-doc * remove misleading comment regarding sub-interface IDs * remove unused macros, set MXL862XX_MAX_PORTS to 17 * count ports starting from 0, 0 being the microcontroller * improve port setup: - split tag protocol and CTP port assignment - use ports cpu_dp instead of relying on single (ie. first) CPU port - handle CPU port like any other port - prepare forward DT compatibility with multiple CPU ports Changes since v8: 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * remove practically unused struct hw_info * lots of kerneldoc improvements in mxl862xx-api.h * drop .mac_select_pcs() stub * better handling for firmware error return value * apply reverse xmas tree in mxl862xx_api_wrap * guard headers with #ifdef macro * include net/dsa.h and linux/mdio.h in mxl862xx.h * call mxl862xx_port_fast_age() only once in .port_setup * don't create isolation bridges for unused ports * replace errornous cast with correct range of values denoting firmware errors Changes since v7 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * use little-endian in bridge_port_config API * remove duplciate assignment of br_port_cfg.bridge_port_id when setting up CPU port Changes since v6 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * no changes 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix kerneldoc style Changes since RFC v5 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * remove unnecessary check for skb != NULL * merge consecutively printed warnings into single dev_warn_ratelimited 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * no changes 4/4 net: dsa: add basic initial driver for MxL862xx switches * include bridge and bridgeport API needed to isolate ports * remove warning in .setup as ports are now isolated * make ready-after-reset check more robust by adding delay * sort structs in order of struct definitions * best effort to sort functions without introducing additional prototypes * always use enums with kerneldoc comments in mxl862xx-api.h * remove bogus .phy_read and .phy_write DSA ops as the driver anyway registers a user MDIO bus with Clause-22 and Clause-45 operations * various small style fixes Changes since RFC v4 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * no changes 2/4 net: dsa: add tag format for MxL862xx switches * drop unused precompiler macros 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * fix indentation 4/4 net: dsa: add basic initial driver for MxL862xx switches * output warning in .setup regarding unknown pre-configuration * add comment explaining why CFGGET is used in reset function Changes since RFC v3 1/4 dt-bindings: net: dsa: add MaxLinear MxL862xx * remove labels from example * remove 'bindings for' from commit title 2/4 net: dsa: add tag format for MxL862xx switches * describe fields and variables with comments * sub-interface is only 5 bits * harmonize Kconfig symbol name * maintain alphabetic order in Kconfig * fix typo s/beginnig/beginning/ * fix typo s/swtiches/switches/ * arrange local variables in reverse xmas tree order 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * unchanged 4/4 net: dsa: add basic initial driver for MxL862xx switches * poll switch readiness after reset * implement driver shutdown * added port_fast_aging API call and driver op * unified port setup in new .port_setup op * improve comment explaining special handlign for unaligned API read * various typos and formatting improvements Changes since RFC v2 1/4, 2/4, 3/4: unchanged 4/4 net: dsa: add basic initial driver for MxL862xx switches * fix return value being uninitialized on error in mxl862xx_api_wrap() * add missing description in kerneldoc comment of struct mxl862xx_ss_sp_tag Changes since initial RFC 1/4 dt-bindings: net: dsa: add bindings for MaxLinear MxL862xx * better description in dt-bindings doc 2/4 net: dsa: add tag formats for MxL862xx switches * make sure all tag fields are initialized 3/4 net: mdio: add unlocked mdiodev C45 bus accessors * new patch 4/4 net: dsa: add basic initial driver for MxL862xx switches * make use of struct mdio_device * add phylink_mac_ops stubs * drop leftover nonsense from mxl862xx_phylink_get_caps() * fix endian conversions * use __le32 instead of enum types in over-the-wire structs * use existing MDIO_* macros whenever possible * simplify API constants to be more readable * use readx_poll_timeout instead of open-coding poll timeout loop * add mxl862xx_reg_read() and mxl862xx_reg_write() helpers * demystify error codes returned by the firmware * add #defines for mxl862xx_ss_sp_tag member values * move reset to dedicated function, clarify magic number being the reset command ID Daniel Golle (4): dt-bindings: net: dsa: add MaxLinear MxL862xx net: dsa: add tag format for MxL862xx switches net: mdio: add unlocked mdiodev C45 bus accessors net: dsa: add basic initial driver for MxL862xx switches .../bindings/net/dsa/maxlinear,mxl862xx.yaml | 160 +++++ MAINTAINERS | 8 + drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/mxl862xx/Kconfig | 12 + drivers/net/dsa/mxl862xx/Makefile | 3 + drivers/net/dsa/mxl862xx/mxl862xx-api.h | 675 ++++++++++++++++++ drivers/net/dsa/mxl862xx/mxl862xx-cmd.h | 49 ++ drivers/net/dsa/mxl862xx/mxl862xx-host.c | 245 +++++++ drivers/net/dsa/mxl862xx/mxl862xx-host.h | 12 + drivers/net/dsa/mxl862xx/mxl862xx.c | 483 +++++++++++++ drivers/net/dsa/mxl862xx/mxl862xx.h | 16 + include/linux/mdio.h | 13 + include/net/dsa.h | 2 + net/dsa/Kconfig | 7 + net/dsa/Makefile | 1 + net/dsa/tag_mxl862xx.c | 110 +++ 17 files changed, 1799 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/maxlinear,mxl862xx.yaml create mode 100644 drivers/net/dsa/mxl862xx/Kconfig create mode 100644 drivers/net/dsa/mxl862xx/Makefile create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-api.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-cmd.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-host.c create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-host.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx.c create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx.h create mode 100644 net/dsa/tag_mxl862xx.c -- 2.52.0
On Mon, Feb 02, 2026 at 12:23:26PM +0200, Vladimir Oltean wrote: Now that ports are counted from 0, and 0 being the microcontroller, the port number no longer matches the PHY ID, so I suppose I got to change the dt-bindigns as that kinda makes the mdio node mandatory for anything to work. Looking at other drivers I thought that, and regret not having challenged the AI commenting on this...
{ "author": "Daniel Golle <daniel@makrotopia.org>", "date": "Mon, 2 Feb 2026 18:09:17 +0000", "thread_id": "aYDoTSySNt7vXazL@makrotopia.org.mbox.gz" }
lkml
[PATCH] [v2] i3c, iio: fix i3c driver dependencies
From: Arnd Bergmann <arnd@arndb.de> All combined i2c/i3c drivers appear to suffer from the same link time problem when CONFIG_I3C is set to 'm': arm-linux-gnueabi-ld: drivers/iio/magnetometer/mmc5633.o: in function `mmc5633_i3c_driver_init': mmc5633.c:(.init.text+0x30): undefined reference to `i3c_driver_register_with_owner' This was previously fixed several times by marking individual drivers as 'depends on I2C; depends on I3C || !I3C', but this gets tedious and is somewhat confusing. Add a Kconfig symbol 'I3C_OR_I2C' to help replace those dependencies, and use this in all the existing drivers that had already fixed it as well as the new mmc5633 driver. Fixes: 6e5f6bf2e3f0 ("iio: magnetometer: Add mmc5633 sensor") Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- v2: restore accidentally deleted lines --- drivers/hwmon/Kconfig | 6 ++---- drivers/i3c/Kconfig | 12 ++++++++++++ drivers/iio/magnetometer/Kconfig | 2 +- drivers/misc/amd-sbi/Kconfig | 3 +-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 41c381764c2b..ecfba861f66d 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -1493,8 +1493,7 @@ config SENSORS_LM73 config SENSORS_LM75 tristate "National Semiconductor LM75 and compatibles" - depends on I2C - depends on I3C || !I3C + depends on I3C_OR_I2C select REGMAP_I2C select REGMAP_I3C if I3C help @@ -2392,8 +2391,7 @@ config SENSORS_TMP103 config SENSORS_TMP108 tristate "Texas Instruments TMP108" - depends on I2C - depends on I3C || !I3C + depends on I3C_OR_I2C select REGMAP_I2C select REGMAP_I3C if I3C help diff --git a/drivers/i3c/Kconfig b/drivers/i3c/Kconfig index 30a441506f61..626c54b386d5 100644 --- a/drivers/i3c/Kconfig +++ b/drivers/i3c/Kconfig @@ -22,3 +22,15 @@ menuconfig I3C if I3C source "drivers/i3c/master/Kconfig" endif # I3C + +config I3C_OR_I2C + tristate + default m if I3C=m + default I2C + help + Device drivers using module_i3c_i2c_driver() can use either + i2c or i3c hosts, but cannot be built-in for the kernel when + CONFIG_I3C=m. + + Add 'depends on I2C_OR_I3C' in Kconfig for those drivers to + get the correct dependencies. diff --git a/drivers/iio/magnetometer/Kconfig b/drivers/iio/magnetometer/Kconfig index 2b81b22c9550..448fef4e5716 100644 --- a/drivers/iio/magnetometer/Kconfig +++ b/drivers/iio/magnetometer/Kconfig @@ -143,7 +143,7 @@ config MMC5633 tristate "MEMSIC MMC5633 3-axis magnetic sensor" select REGMAP_I2C if I2C select REGMAP_I3C if I3C - depends on I2C || I3C + depends on I3C_OR_I2C help Say yes here to build support for the MEMSIC MMC5633 3-axis magnetic sensor. diff --git a/drivers/misc/amd-sbi/Kconfig b/drivers/misc/amd-sbi/Kconfig index be022c71a90c..30e7fad7356c 100644 --- a/drivers/misc/amd-sbi/Kconfig +++ b/drivers/misc/amd-sbi/Kconfig @@ -1,10 +1,9 @@ # SPDX-License-Identifier: GPL-2.0-only config AMD_SBRMI_I2C tristate "AMD side band RMI support" - depends on I2C + depends on I3C_OR_I2C depends on ARM || ARM64 || COMPILE_TEST select REGMAP_I2C - depends on I3C || !I3C select REGMAP_I3C if I3C help Side band RMI over I2C/I3C support for AMD out of band management. -- 2.39.5
On Mon, Feb 02, 2026 at 05:04:46PM +0100, Arnd Bergmann wrote: Reviewed-by: Frank Li <Frank.Li@nxp.com>
{ "author": "Frank Li <Frank.li@nxp.com>", "date": "Mon, 2 Feb 2026 11:37:25 -0500", "thread_id": "a8f8ee55-3c87-4e9c-a5a9-12929855b86f@roeck-us.net.mbox.gz" }
lkml
[PATCH] [v2] i3c, iio: fix i3c driver dependencies
From: Arnd Bergmann <arnd@arndb.de> All combined i2c/i3c drivers appear to suffer from the same link time problem when CONFIG_I3C is set to 'm': arm-linux-gnueabi-ld: drivers/iio/magnetometer/mmc5633.o: in function `mmc5633_i3c_driver_init': mmc5633.c:(.init.text+0x30): undefined reference to `i3c_driver_register_with_owner' This was previously fixed several times by marking individual drivers as 'depends on I2C; depends on I3C || !I3C', but this gets tedious and is somewhat confusing. Add a Kconfig symbol 'I3C_OR_I2C' to help replace those dependencies, and use this in all the existing drivers that had already fixed it as well as the new mmc5633 driver. Fixes: 6e5f6bf2e3f0 ("iio: magnetometer: Add mmc5633 sensor") Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- v2: restore accidentally deleted lines --- drivers/hwmon/Kconfig | 6 ++---- drivers/i3c/Kconfig | 12 ++++++++++++ drivers/iio/magnetometer/Kconfig | 2 +- drivers/misc/amd-sbi/Kconfig | 3 +-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 41c381764c2b..ecfba861f66d 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -1493,8 +1493,7 @@ config SENSORS_LM73 config SENSORS_LM75 tristate "National Semiconductor LM75 and compatibles" - depends on I2C - depends on I3C || !I3C + depends on I3C_OR_I2C select REGMAP_I2C select REGMAP_I3C if I3C help @@ -2392,8 +2391,7 @@ config SENSORS_TMP103 config SENSORS_TMP108 tristate "Texas Instruments TMP108" - depends on I2C - depends on I3C || !I3C + depends on I3C_OR_I2C select REGMAP_I2C select REGMAP_I3C if I3C help diff --git a/drivers/i3c/Kconfig b/drivers/i3c/Kconfig index 30a441506f61..626c54b386d5 100644 --- a/drivers/i3c/Kconfig +++ b/drivers/i3c/Kconfig @@ -22,3 +22,15 @@ menuconfig I3C if I3C source "drivers/i3c/master/Kconfig" endif # I3C + +config I3C_OR_I2C + tristate + default m if I3C=m + default I2C + help + Device drivers using module_i3c_i2c_driver() can use either + i2c or i3c hosts, but cannot be built-in for the kernel when + CONFIG_I3C=m. + + Add 'depends on I2C_OR_I3C' in Kconfig for those drivers to + get the correct dependencies. diff --git a/drivers/iio/magnetometer/Kconfig b/drivers/iio/magnetometer/Kconfig index 2b81b22c9550..448fef4e5716 100644 --- a/drivers/iio/magnetometer/Kconfig +++ b/drivers/iio/magnetometer/Kconfig @@ -143,7 +143,7 @@ config MMC5633 tristate "MEMSIC MMC5633 3-axis magnetic sensor" select REGMAP_I2C if I2C select REGMAP_I3C if I3C - depends on I2C || I3C + depends on I3C_OR_I2C help Say yes here to build support for the MEMSIC MMC5633 3-axis magnetic sensor. diff --git a/drivers/misc/amd-sbi/Kconfig b/drivers/misc/amd-sbi/Kconfig index be022c71a90c..30e7fad7356c 100644 --- a/drivers/misc/amd-sbi/Kconfig +++ b/drivers/misc/amd-sbi/Kconfig @@ -1,10 +1,9 @@ # SPDX-License-Identifier: GPL-2.0-only config AMD_SBRMI_I2C tristate "AMD side band RMI support" - depends on I2C + depends on I3C_OR_I2C depends on ARM || ARM64 || COMPILE_TEST select REGMAP_I2C - depends on I3C || !I3C select REGMAP_I3C if I3C help Side band RMI over I2C/I3C support for AMD out of band management. -- 2.39.5
On 2/2/26 08:04, Arnd Bergmann wrote: For hwmon: Acked-by: Guenter Roeck <linux@roeck-us.net>
{ "author": "Guenter Roeck <linux@roeck-us.net>", "date": "Mon, 2 Feb 2026 09:50:58 -0800", "thread_id": "a8f8ee55-3c87-4e9c-a5a9-12929855b86f@roeck-us.net.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": "20260202175417.00000abe@huawei.com.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": "20260202175417.00000abe@huawei.com.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": "20260202175417.00000abe@huawei.com.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": "20260202175417.00000abe@huawei.com.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": "20260202175417.00000abe@huawei.com.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": "20260202175417.00000abe@huawei.com.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": "20260202175417.00000abe@huawei.com.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": "20260202175417.00000abe@huawei.com.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": "20260202175417.00000abe@huawei.com.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": "20260202175417.00000abe@huawei.com.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": "20260202175417.00000abe@huawei.com.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": "20260202175417.00000abe@huawei.com.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": "20260202175417.00000abe@huawei.com.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": "20260202175417.00000abe@huawei.com.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": "20260202175417.00000abe@huawei.com.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": "20260202175417.00000abe@huawei.com.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": "20260202175417.00000abe@huawei.com.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": "20260202175417.00000abe@huawei.com.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": "20260202175417.00000abe@huawei.com.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": "20260202175417.00000abe@huawei.com.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": "20260202175417.00000abe@huawei.com.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": "20260202175417.00000abe@huawei.com.mbox.gz" }
lkml
[PATCH v5] dmaengine: dw-edma: fix MSI data programming for multi-IRQ case
From: Shenghui Shi <brody.shi@m2semi.com> When using MSI (not MSI-X) with multiple IRQs, the MSI data value must be unique per vector to ensure correct interrupt delivery. Currently, the driver fails to increment the MSI data per vector, causing interrupts to be misrouted. Fix this by caching the base MSI data and adjusting each vector's data accordingly during IRQ setup. Fixes: e63d79d1ff04 ("dmaengine: dw-edma: Add Synopsys DesignWare eDMA IP core driver") Signed-off-by: Shenghui Shi <brody.shi@m2semi.com> --- drivers/dma/dw-edma/dw-edma-core.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/dma/dw-edma/dw-edma-core.c b/drivers/dma/dw-edma/dw-edma-core.c index 8e5f7defa6b6..dccc686b7a3e 100644 --- a/drivers/dma/dw-edma/dw-edma-core.c +++ b/drivers/dma/dw-edma/dw-edma-core.c @@ -844,6 +844,7 @@ static int dw_edma_irq_request(struct dw_edma *dw, { struct dw_edma_chip *chip = dw->chip; struct device *dev = dw->chip->dev; + struct msi_desc *msi_desc; u32 wr_mask = 1; u32 rd_mask = 1; int i, err = 0; @@ -895,9 +896,15 @@ static int dw_edma_irq_request(struct dw_edma *dw, &dw->irq[i]); if (err) goto err_irq_free; + msi_desc = irq_get_msi_desc(irq); + if (msi_desc) { + bool is_msi; - if (irq_get_msi_desc(irq)) get_cached_msi_msg(irq, &dw->irq[i].msi); + is_msi = msi_desc && !msi_desc->pci.msi_attrib.is_msix; + if (is_msi) + dw->irq[i].msi.data = dw->irq[0].msi.data + i; + } } dw->nr_irqs = i; -- 2.49.0.windows.1
On Mon, Feb 02, 2026 at 01:53:44PM +0800, Shi-Shenghui wrote: Reviewed-by: Frank Li <Frank.Li@nxp.com>
{ "author": "Frank Li <Frank.li@nxp.com>", "date": "Mon, 2 Feb 2026 11:42:34 -0500", "thread_id": "aYDT+meppNfX9bD3@lizhi-Precision-Tower-5810.mbox.gz" }
lkml
[PATCH] printk: add early_counter_ns routine for printk blind spot
From: Tim Bird <tim.bird@sony.com> During early boot, printk timestamps are reported as zero, which creates a blind spot in early boot timings. This blind spot hinders timing and optimization efforts for code that executes before time_init(), which is when local_clock() is initialized sufficiently to start returning non-zero timestamps. This period is about 400 milliseconds for many current desktop and embedded machines running Linux. Add an early_counter_ns function that returns nanosecond timestamps based on get_cycles(). get_cycles() is operational on arm64 and x86_64 from kernel start. Add some calibration printks to allow setting configuration variables that are used to convert cycle counts to nanoseconds (which are then used in early printks). Add CONFIG_EARLY_COUNTER_NS, as well as some associated conversion variables, as new kernel config variables. After proper configuration, this yields non-zero timestamps for printks from the very start of kernel execution. The timestamps are relative to the start of the architecture-specific counter used in get_cycles (e.g. the TSC on x86_64 and cntvct_el0 on arm64). This means that the time reported reflects time-from-power-on for most embedded products. This is also a useful data point for boot-time optimization work. Note that there is a discontinuity in the timestamp sequencing when standard clocks are finally initialized in time_init(). The printk timestamps are thus not monotonically increasing through the entire boot. Signed-off-by: Tim Bird <tim.bird@sony.com> --- init/Kconfig | 47 ++++++++++++++++++++++++++++++++++++++++++ init/main.c | 25 ++++++++++++++++++++++ kernel/printk/printk.c | 15 ++++++++++++++ 3 files changed, 87 insertions(+) diff --git a/init/Kconfig b/init/Kconfig index cab3ad28ca49..5352567c43ed 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -770,6 +770,53 @@ config IKHEADERS or similar programs. If you build the headers as a module, a module called kheaders.ko is built which can be loaded on-demand to get access to headers. +config EARLY_COUNTER_NS + bool "Use counter for early printk timestamps" + default y + depends on PRINTK + help + Use a cycle-counter to provide printk timestamps during early + boot. This allows seeing timing information that would + otherwise be displayed with 0-valued timestamps. + + In order for this to work, you need to specify values for + EARLY_COUNTER_MULT and EARLY_COUNTER_SHIFT, used to convert + from the cycle count to nanoseconds. + +config EARLY_COUNTER_MULT + int "Multiplier for early cycle counter" + depends on PRINTK && EARLY_COUNTER_NS + default 1 + help + This value specifies a multiplier to be used when converting + cycle counts to nanoseconds. The formula used is: + ns = (cycles * mult) >> shift + + Use a multiplier that will bring the value of (cycles * mult) + to near a power of two, that is greater than 1000. The + nanoseconds returned by this conversion are divided by 1000 + to be used as the printk timestamp counter (with resolution + of microseconds). + + As an example, for a cycle-counter with a frequency of 200 Mhz, + the multiplier would be: 10485760, and the shift would be 21. + +config EARLY_COUNTER_SHIFT + int "Shift value for early cycle counter" + range 0 63 + depends on PRINTK && EARLY_COUNTER_NS + default 0 + help + This value specifies a shift value to be used when converting + cycle counts to nanoseconds. The formula used is: + ns = (cycles * mult) >> shift + + Use a shift that will bring the result to a value + in nanoseconds. + + As an example, for a cycle-counter with a frequency of 200 Mhz, + the multiplier would be: 10485760, and the shift would be 21. + config LOG_BUF_SHIFT int "Kernel log buffer size (16 => 64KB, 17 => 128KB)" range 12 25 diff --git a/init/main.c b/init/main.c index 07a3116811c5..587aaaad22d1 100644 --- a/init/main.c +++ b/init/main.c @@ -105,6 +105,8 @@ #include <linux/ptdump.h> #include <linux/time_namespace.h> #include <net/net_namespace.h> +#include <linux/timex.h> +#include <linux/sched/clock.h> #include <asm/io.h> #include <asm/setup.h> @@ -906,6 +908,8 @@ static void __init early_numa_node_init(void) #endif } +static u64 start_cycles, start_ns; + asmlinkage __visible __init __no_sanitize_address __noreturn __no_stack_protector void start_kernel(void) { @@ -1023,6 +1027,10 @@ void start_kernel(void) timekeeping_init(); time_init(); + /* used to calibrate early_counter_ns */ + start_cycles = get_cycles(); + start_ns = local_clock(); + /* This must be after timekeeping is initialized */ random_init(); @@ -1474,6 +1482,8 @@ void __weak free_initmem(void) static int __ref kernel_init(void *unused) { int ret; + u64 end_cycles, end_ns; + u32 early_mult, early_shift; /* * Wait until kthreadd is all set-up. @@ -1505,6 +1515,21 @@ static int __ref kernel_init(void *unused) do_sysctl_args(); + /* show calibration data for early_counter_ns */ + end_cycles = get_cycles(); + end_ns = local_clock(); + clocks_calc_mult_shift(&early_mult, &early_shift, + ((end_cycles - start_cycles) * NSEC_PER_SEC)/(end_ns - start_ns), + NSEC_PER_SEC, 50); + +#ifdef CONFIG_EARLY_COUNTER_NS + pr_info("Early Counter: start_cycles=%llu, end_cycles=%llu, cycles=%llu\n", + start_cycles, end_cycles, (end_cycles - start_cycles)); + pr_info("Early Counter: start_ns=%llu, end_ns=%llu, ns=%llu\n", + start_ns, end_ns, (end_ns - start_ns)); + pr_info("Early Counter: MULT=%u, SHIFT=%u\n", early_mult, early_shift); +#endif + if (ramdisk_execute_command) { ret = run_init_process(ramdisk_execute_command); if (!ret) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 5aee9ffb16b9..522dd24cd534 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2210,6 +2210,19 @@ static u16 printk_sprint(char *text, u16 size, int facility, return text_len; } +#ifdef CONFIG_EARLY_COUNTER_NS +static inline u64 early_counter_ns(void) +{ + return ((u64)get_cycles() * CONFIG_EARLY_COUNTER_MULT) + >> CONFIG_EARLY_COUNTER_SHIFT; +} +#else +static inline u64 early_counter_ns(void) +{ + return 0; +} +#endif + __printf(4, 0) int vprintk_store(int facility, int level, const struct dev_printk_info *dev_info, @@ -2239,6 +2252,8 @@ int vprintk_store(int facility, int level, * timestamp with respect to the caller. */ ts_nsec = local_clock(); + if (!ts_nsec) + ts_nsec = early_counter_ns(); caller_id = printk_caller_id(); -- 2.43.0
Hi Tim, kernel test robot noticed the following build errors: [auto build test ERROR on linus/master] [also build test ERROR on v6.18-rc7] [cannot apply to akpm-mm/mm-everything next-20251124] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Tim-Bird/printk-add-early_counter_ns-routine-for-printk-blind-spot/20251125-133242 base: linus/master patch link: https://lore.kernel.org/r/39b09edb-8998-4ebd-a564-7d594434a981%40bird.org patch subject: [PATCH] printk: add early_counter_ns routine for printk blind spot config: powerpc-allnoconfig (https://download.01.org/0day-ci/archive/20251125/202511251534.9kMSsAH6-lkp@intel.com/config) compiler: powerpc-linux-gcc (GCC) 15.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251125/202511251534.9kMSsAH6-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202511251534.9kMSsAH6-lkp@intel.com/ All errors (new ones prefixed by >>): powerpc-linux-ld: init/main.o: in function `kernel_init': -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
{ "author": "kernel test robot <lkp@intel.com>", "date": "Tue, 25 Nov 2025 15:52:26 +0800", "thread_id": "39b09edb-8998-4ebd-a564-7d594434a981@bird.org.mbox.gz" }
lkml
[PATCH] printk: add early_counter_ns routine for printk blind spot
From: Tim Bird <tim.bird@sony.com> During early boot, printk timestamps are reported as zero, which creates a blind spot in early boot timings. This blind spot hinders timing and optimization efforts for code that executes before time_init(), which is when local_clock() is initialized sufficiently to start returning non-zero timestamps. This period is about 400 milliseconds for many current desktop and embedded machines running Linux. Add an early_counter_ns function that returns nanosecond timestamps based on get_cycles(). get_cycles() is operational on arm64 and x86_64 from kernel start. Add some calibration printks to allow setting configuration variables that are used to convert cycle counts to nanoseconds (which are then used in early printks). Add CONFIG_EARLY_COUNTER_NS, as well as some associated conversion variables, as new kernel config variables. After proper configuration, this yields non-zero timestamps for printks from the very start of kernel execution. The timestamps are relative to the start of the architecture-specific counter used in get_cycles (e.g. the TSC on x86_64 and cntvct_el0 on arm64). This means that the time reported reflects time-from-power-on for most embedded products. This is also a useful data point for boot-time optimization work. Note that there is a discontinuity in the timestamp sequencing when standard clocks are finally initialized in time_init(). The printk timestamps are thus not monotonically increasing through the entire boot. Signed-off-by: Tim Bird <tim.bird@sony.com> --- init/Kconfig | 47 ++++++++++++++++++++++++++++++++++++++++++ init/main.c | 25 ++++++++++++++++++++++ kernel/printk/printk.c | 15 ++++++++++++++ 3 files changed, 87 insertions(+) diff --git a/init/Kconfig b/init/Kconfig index cab3ad28ca49..5352567c43ed 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -770,6 +770,53 @@ config IKHEADERS or similar programs. If you build the headers as a module, a module called kheaders.ko is built which can be loaded on-demand to get access to headers. +config EARLY_COUNTER_NS + bool "Use counter for early printk timestamps" + default y + depends on PRINTK + help + Use a cycle-counter to provide printk timestamps during early + boot. This allows seeing timing information that would + otherwise be displayed with 0-valued timestamps. + + In order for this to work, you need to specify values for + EARLY_COUNTER_MULT and EARLY_COUNTER_SHIFT, used to convert + from the cycle count to nanoseconds. + +config EARLY_COUNTER_MULT + int "Multiplier for early cycle counter" + depends on PRINTK && EARLY_COUNTER_NS + default 1 + help + This value specifies a multiplier to be used when converting + cycle counts to nanoseconds. The formula used is: + ns = (cycles * mult) >> shift + + Use a multiplier that will bring the value of (cycles * mult) + to near a power of two, that is greater than 1000. The + nanoseconds returned by this conversion are divided by 1000 + to be used as the printk timestamp counter (with resolution + of microseconds). + + As an example, for a cycle-counter with a frequency of 200 Mhz, + the multiplier would be: 10485760, and the shift would be 21. + +config EARLY_COUNTER_SHIFT + int "Shift value for early cycle counter" + range 0 63 + depends on PRINTK && EARLY_COUNTER_NS + default 0 + help + This value specifies a shift value to be used when converting + cycle counts to nanoseconds. The formula used is: + ns = (cycles * mult) >> shift + + Use a shift that will bring the result to a value + in nanoseconds. + + As an example, for a cycle-counter with a frequency of 200 Mhz, + the multiplier would be: 10485760, and the shift would be 21. + config LOG_BUF_SHIFT int "Kernel log buffer size (16 => 64KB, 17 => 128KB)" range 12 25 diff --git a/init/main.c b/init/main.c index 07a3116811c5..587aaaad22d1 100644 --- a/init/main.c +++ b/init/main.c @@ -105,6 +105,8 @@ #include <linux/ptdump.h> #include <linux/time_namespace.h> #include <net/net_namespace.h> +#include <linux/timex.h> +#include <linux/sched/clock.h> #include <asm/io.h> #include <asm/setup.h> @@ -906,6 +908,8 @@ static void __init early_numa_node_init(void) #endif } +static u64 start_cycles, start_ns; + asmlinkage __visible __init __no_sanitize_address __noreturn __no_stack_protector void start_kernel(void) { @@ -1023,6 +1027,10 @@ void start_kernel(void) timekeeping_init(); time_init(); + /* used to calibrate early_counter_ns */ + start_cycles = get_cycles(); + start_ns = local_clock(); + /* This must be after timekeeping is initialized */ random_init(); @@ -1474,6 +1482,8 @@ void __weak free_initmem(void) static int __ref kernel_init(void *unused) { int ret; + u64 end_cycles, end_ns; + u32 early_mult, early_shift; /* * Wait until kthreadd is all set-up. @@ -1505,6 +1515,21 @@ static int __ref kernel_init(void *unused) do_sysctl_args(); + /* show calibration data for early_counter_ns */ + end_cycles = get_cycles(); + end_ns = local_clock(); + clocks_calc_mult_shift(&early_mult, &early_shift, + ((end_cycles - start_cycles) * NSEC_PER_SEC)/(end_ns - start_ns), + NSEC_PER_SEC, 50); + +#ifdef CONFIG_EARLY_COUNTER_NS + pr_info("Early Counter: start_cycles=%llu, end_cycles=%llu, cycles=%llu\n", + start_cycles, end_cycles, (end_cycles - start_cycles)); + pr_info("Early Counter: start_ns=%llu, end_ns=%llu, ns=%llu\n", + start_ns, end_ns, (end_ns - start_ns)); + pr_info("Early Counter: MULT=%u, SHIFT=%u\n", early_mult, early_shift); +#endif + if (ramdisk_execute_command) { ret = run_init_process(ramdisk_execute_command); if (!ret) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 5aee9ffb16b9..522dd24cd534 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2210,6 +2210,19 @@ static u16 printk_sprint(char *text, u16 size, int facility, return text_len; } +#ifdef CONFIG_EARLY_COUNTER_NS +static inline u64 early_counter_ns(void) +{ + return ((u64)get_cycles() * CONFIG_EARLY_COUNTER_MULT) + >> CONFIG_EARLY_COUNTER_SHIFT; +} +#else +static inline u64 early_counter_ns(void) +{ + return 0; +} +#endif + __printf(4, 0) int vprintk_store(int facility, int level, const struct dev_printk_info *dev_info, @@ -2239,6 +2252,8 @@ int vprintk_store(int facility, int level, * timestamp with respect to the caller. */ ts_nsec = local_clock(); + if (!ts_nsec) + ts_nsec = early_counter_ns(); caller_id = printk_caller_id(); -- 2.43.0
Hi Tim, I tested this on my i.MX93 FRDM (arm64) board and after a bit of fiddling with the MULT/SHIFT values I got it working. It can be a very valuable addition. Some comments follow. On Mon, Nov 24, 2025 at 10:30:52PM -0700, Tim Bird wrote: This is... not going to work, IMO, and might lead to breakages in userspace tools (are printk timings a userspace API?). I actually have a counter-proposal: the time obtained through cycle evaluation is used as an offset to be added to the printk time after time_init() is called. A (working, but maybe sub-optimal) patch to obtain this is attached at the end. If I got this correclty: EARLY_COUNTER_MULT = (10^9 / freq) << EARLY_COUNTER_SHIFT where EARLY_COUNTER_SHIFT can be chosen at will, provided it is big enough to survice the ns->us conversion but small enough not to overflow the u64 container. I don't get the need to have these here - should they be an help for the integrator to calibrate and choose EARLY_COUNTER_MULT and EARLY_COUNTER_SHIFT? The ns values printed here have some meaning only if these two parameters are already set correctly in the first place - what's the foreseen calibration procedure? Moreover, if they are only required for calibration, maybe pr_debugi() would be a better choice? Best regards, Francesco --- diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 522dd24cd534..b4108f215c5e 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2216,11 +2216,26 @@ static inline u64 early_counter_ns(void) return ((u64)get_cycles() * CONFIG_EARLY_COUNTER_MULT) >> CONFIG_EARLY_COUNTER_SHIFT; } + +static u64 early_counter_ns_offset(void) +{ + static u64 early_counter_ns_start = 0; + + if (!early_counter_ns_start) + early_counter_ns_start = early_counter_ns(); + + return early_counter_ns_start; +} #else static inline u64 early_counter_ns(void) { return 0; } + +static inline u64 early_counter_ns_offset(void) +{ + return 0; +} #endif __printf(4, 0) @@ -2254,6 +2269,8 @@ int vprintk_store(int facility, int level, ts_nsec = local_clock(); if (!ts_nsec) ts_nsec = early_counter_ns(); + else + ts_nsec += early_counter_ns_offset(); caller_id = printk_caller_id();
{ "author": "Francesco Valla <francesco@valla.it>", "date": "Tue, 25 Nov 2025 14:08:40 +0100", "thread_id": "39b09edb-8998-4ebd-a564-7d594434a981@bird.org.mbox.gz" }
lkml
[PATCH] printk: add early_counter_ns routine for printk blind spot
From: Tim Bird <tim.bird@sony.com> During early boot, printk timestamps are reported as zero, which creates a blind spot in early boot timings. This blind spot hinders timing and optimization efforts for code that executes before time_init(), which is when local_clock() is initialized sufficiently to start returning non-zero timestamps. This period is about 400 milliseconds for many current desktop and embedded machines running Linux. Add an early_counter_ns function that returns nanosecond timestamps based on get_cycles(). get_cycles() is operational on arm64 and x86_64 from kernel start. Add some calibration printks to allow setting configuration variables that are used to convert cycle counts to nanoseconds (which are then used in early printks). Add CONFIG_EARLY_COUNTER_NS, as well as some associated conversion variables, as new kernel config variables. After proper configuration, this yields non-zero timestamps for printks from the very start of kernel execution. The timestamps are relative to the start of the architecture-specific counter used in get_cycles (e.g. the TSC on x86_64 and cntvct_el0 on arm64). This means that the time reported reflects time-from-power-on for most embedded products. This is also a useful data point for boot-time optimization work. Note that there is a discontinuity in the timestamp sequencing when standard clocks are finally initialized in time_init(). The printk timestamps are thus not monotonically increasing through the entire boot. Signed-off-by: Tim Bird <tim.bird@sony.com> --- init/Kconfig | 47 ++++++++++++++++++++++++++++++++++++++++++ init/main.c | 25 ++++++++++++++++++++++ kernel/printk/printk.c | 15 ++++++++++++++ 3 files changed, 87 insertions(+) diff --git a/init/Kconfig b/init/Kconfig index cab3ad28ca49..5352567c43ed 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -770,6 +770,53 @@ config IKHEADERS or similar programs. If you build the headers as a module, a module called kheaders.ko is built which can be loaded on-demand to get access to headers. +config EARLY_COUNTER_NS + bool "Use counter for early printk timestamps" + default y + depends on PRINTK + help + Use a cycle-counter to provide printk timestamps during early + boot. This allows seeing timing information that would + otherwise be displayed with 0-valued timestamps. + + In order for this to work, you need to specify values for + EARLY_COUNTER_MULT and EARLY_COUNTER_SHIFT, used to convert + from the cycle count to nanoseconds. + +config EARLY_COUNTER_MULT + int "Multiplier for early cycle counter" + depends on PRINTK && EARLY_COUNTER_NS + default 1 + help + This value specifies a multiplier to be used when converting + cycle counts to nanoseconds. The formula used is: + ns = (cycles * mult) >> shift + + Use a multiplier that will bring the value of (cycles * mult) + to near a power of two, that is greater than 1000. The + nanoseconds returned by this conversion are divided by 1000 + to be used as the printk timestamp counter (with resolution + of microseconds). + + As an example, for a cycle-counter with a frequency of 200 Mhz, + the multiplier would be: 10485760, and the shift would be 21. + +config EARLY_COUNTER_SHIFT + int "Shift value for early cycle counter" + range 0 63 + depends on PRINTK && EARLY_COUNTER_NS + default 0 + help + This value specifies a shift value to be used when converting + cycle counts to nanoseconds. The formula used is: + ns = (cycles * mult) >> shift + + Use a shift that will bring the result to a value + in nanoseconds. + + As an example, for a cycle-counter with a frequency of 200 Mhz, + the multiplier would be: 10485760, and the shift would be 21. + config LOG_BUF_SHIFT int "Kernel log buffer size (16 => 64KB, 17 => 128KB)" range 12 25 diff --git a/init/main.c b/init/main.c index 07a3116811c5..587aaaad22d1 100644 --- a/init/main.c +++ b/init/main.c @@ -105,6 +105,8 @@ #include <linux/ptdump.h> #include <linux/time_namespace.h> #include <net/net_namespace.h> +#include <linux/timex.h> +#include <linux/sched/clock.h> #include <asm/io.h> #include <asm/setup.h> @@ -906,6 +908,8 @@ static void __init early_numa_node_init(void) #endif } +static u64 start_cycles, start_ns; + asmlinkage __visible __init __no_sanitize_address __noreturn __no_stack_protector void start_kernel(void) { @@ -1023,6 +1027,10 @@ void start_kernel(void) timekeeping_init(); time_init(); + /* used to calibrate early_counter_ns */ + start_cycles = get_cycles(); + start_ns = local_clock(); + /* This must be after timekeeping is initialized */ random_init(); @@ -1474,6 +1482,8 @@ void __weak free_initmem(void) static int __ref kernel_init(void *unused) { int ret; + u64 end_cycles, end_ns; + u32 early_mult, early_shift; /* * Wait until kthreadd is all set-up. @@ -1505,6 +1515,21 @@ static int __ref kernel_init(void *unused) do_sysctl_args(); + /* show calibration data for early_counter_ns */ + end_cycles = get_cycles(); + end_ns = local_clock(); + clocks_calc_mult_shift(&early_mult, &early_shift, + ((end_cycles - start_cycles) * NSEC_PER_SEC)/(end_ns - start_ns), + NSEC_PER_SEC, 50); + +#ifdef CONFIG_EARLY_COUNTER_NS + pr_info("Early Counter: start_cycles=%llu, end_cycles=%llu, cycles=%llu\n", + start_cycles, end_cycles, (end_cycles - start_cycles)); + pr_info("Early Counter: start_ns=%llu, end_ns=%llu, ns=%llu\n", + start_ns, end_ns, (end_ns - start_ns)); + pr_info("Early Counter: MULT=%u, SHIFT=%u\n", early_mult, early_shift); +#endif + if (ramdisk_execute_command) { ret = run_init_process(ramdisk_execute_command); if (!ret) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 5aee9ffb16b9..522dd24cd534 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2210,6 +2210,19 @@ static u16 printk_sprint(char *text, u16 size, int facility, return text_len; } +#ifdef CONFIG_EARLY_COUNTER_NS +static inline u64 early_counter_ns(void) +{ + return ((u64)get_cycles() * CONFIG_EARLY_COUNTER_MULT) + >> CONFIG_EARLY_COUNTER_SHIFT; +} +#else +static inline u64 early_counter_ns(void) +{ + return 0; +} +#endif + __printf(4, 0) int vprintk_store(int facility, int level, const struct dev_printk_info *dev_info, @@ -2239,6 +2252,8 @@ int vprintk_store(int facility, int level, * timestamp with respect to the caller. */ ts_nsec = local_clock(); + if (!ts_nsec) + ts_nsec = early_counter_ns(); caller_id = printk_caller_id(); -- 2.43.0
Hi all, On Wed, 26 Nov 2025 at 03:24, Francesco Valla <francesco@valla.it> wrote: I think they are. Another approach would be to defer the calibration/conversion to userspace, and make sure the early part stands out. I.e. when real timekeeping is available, kernel messages are prefixed by "[%5lu.%06lu]". Early messages could be prefixed by a plain integer "[%12u]", containing the raw cycle counter value. The presence of the decimal point would make the difference obvious. Oh, that's a nice idea, too! Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
{ "author": "Geert Uytterhoeven <geert@linux-m68k.org>", "date": "Wed, 26 Nov 2025 08:38:08 +0100", "thread_id": "39b09edb-8998-4ebd-a564-7d594434a981@bird.org.mbox.gz" }
lkml
[PATCH] printk: add early_counter_ns routine for printk blind spot
From: Tim Bird <tim.bird@sony.com> During early boot, printk timestamps are reported as zero, which creates a blind spot in early boot timings. This blind spot hinders timing and optimization efforts for code that executes before time_init(), which is when local_clock() is initialized sufficiently to start returning non-zero timestamps. This period is about 400 milliseconds for many current desktop and embedded machines running Linux. Add an early_counter_ns function that returns nanosecond timestamps based on get_cycles(). get_cycles() is operational on arm64 and x86_64 from kernel start. Add some calibration printks to allow setting configuration variables that are used to convert cycle counts to nanoseconds (which are then used in early printks). Add CONFIG_EARLY_COUNTER_NS, as well as some associated conversion variables, as new kernel config variables. After proper configuration, this yields non-zero timestamps for printks from the very start of kernel execution. The timestamps are relative to the start of the architecture-specific counter used in get_cycles (e.g. the TSC on x86_64 and cntvct_el0 on arm64). This means that the time reported reflects time-from-power-on for most embedded products. This is also a useful data point for boot-time optimization work. Note that there is a discontinuity in the timestamp sequencing when standard clocks are finally initialized in time_init(). The printk timestamps are thus not monotonically increasing through the entire boot. Signed-off-by: Tim Bird <tim.bird@sony.com> --- init/Kconfig | 47 ++++++++++++++++++++++++++++++++++++++++++ init/main.c | 25 ++++++++++++++++++++++ kernel/printk/printk.c | 15 ++++++++++++++ 3 files changed, 87 insertions(+) diff --git a/init/Kconfig b/init/Kconfig index cab3ad28ca49..5352567c43ed 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -770,6 +770,53 @@ config IKHEADERS or similar programs. If you build the headers as a module, a module called kheaders.ko is built which can be loaded on-demand to get access to headers. +config EARLY_COUNTER_NS + bool "Use counter for early printk timestamps" + default y + depends on PRINTK + help + Use a cycle-counter to provide printk timestamps during early + boot. This allows seeing timing information that would + otherwise be displayed with 0-valued timestamps. + + In order for this to work, you need to specify values for + EARLY_COUNTER_MULT and EARLY_COUNTER_SHIFT, used to convert + from the cycle count to nanoseconds. + +config EARLY_COUNTER_MULT + int "Multiplier for early cycle counter" + depends on PRINTK && EARLY_COUNTER_NS + default 1 + help + This value specifies a multiplier to be used when converting + cycle counts to nanoseconds. The formula used is: + ns = (cycles * mult) >> shift + + Use a multiplier that will bring the value of (cycles * mult) + to near a power of two, that is greater than 1000. The + nanoseconds returned by this conversion are divided by 1000 + to be used as the printk timestamp counter (with resolution + of microseconds). + + As an example, for a cycle-counter with a frequency of 200 Mhz, + the multiplier would be: 10485760, and the shift would be 21. + +config EARLY_COUNTER_SHIFT + int "Shift value for early cycle counter" + range 0 63 + depends on PRINTK && EARLY_COUNTER_NS + default 0 + help + This value specifies a shift value to be used when converting + cycle counts to nanoseconds. The formula used is: + ns = (cycles * mult) >> shift + + Use a shift that will bring the result to a value + in nanoseconds. + + As an example, for a cycle-counter with a frequency of 200 Mhz, + the multiplier would be: 10485760, and the shift would be 21. + config LOG_BUF_SHIFT int "Kernel log buffer size (16 => 64KB, 17 => 128KB)" range 12 25 diff --git a/init/main.c b/init/main.c index 07a3116811c5..587aaaad22d1 100644 --- a/init/main.c +++ b/init/main.c @@ -105,6 +105,8 @@ #include <linux/ptdump.h> #include <linux/time_namespace.h> #include <net/net_namespace.h> +#include <linux/timex.h> +#include <linux/sched/clock.h> #include <asm/io.h> #include <asm/setup.h> @@ -906,6 +908,8 @@ static void __init early_numa_node_init(void) #endif } +static u64 start_cycles, start_ns; + asmlinkage __visible __init __no_sanitize_address __noreturn __no_stack_protector void start_kernel(void) { @@ -1023,6 +1027,10 @@ void start_kernel(void) timekeeping_init(); time_init(); + /* used to calibrate early_counter_ns */ + start_cycles = get_cycles(); + start_ns = local_clock(); + /* This must be after timekeeping is initialized */ random_init(); @@ -1474,6 +1482,8 @@ void __weak free_initmem(void) static int __ref kernel_init(void *unused) { int ret; + u64 end_cycles, end_ns; + u32 early_mult, early_shift; /* * Wait until kthreadd is all set-up. @@ -1505,6 +1515,21 @@ static int __ref kernel_init(void *unused) do_sysctl_args(); + /* show calibration data for early_counter_ns */ + end_cycles = get_cycles(); + end_ns = local_clock(); + clocks_calc_mult_shift(&early_mult, &early_shift, + ((end_cycles - start_cycles) * NSEC_PER_SEC)/(end_ns - start_ns), + NSEC_PER_SEC, 50); + +#ifdef CONFIG_EARLY_COUNTER_NS + pr_info("Early Counter: start_cycles=%llu, end_cycles=%llu, cycles=%llu\n", + start_cycles, end_cycles, (end_cycles - start_cycles)); + pr_info("Early Counter: start_ns=%llu, end_ns=%llu, ns=%llu\n", + start_ns, end_ns, (end_ns - start_ns)); + pr_info("Early Counter: MULT=%u, SHIFT=%u\n", early_mult, early_shift); +#endif + if (ramdisk_execute_command) { ret = run_init_process(ramdisk_execute_command); if (!ret) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 5aee9ffb16b9..522dd24cd534 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2210,6 +2210,19 @@ static u16 printk_sprint(char *text, u16 size, int facility, return text_len; } +#ifdef CONFIG_EARLY_COUNTER_NS +static inline u64 early_counter_ns(void) +{ + return ((u64)get_cycles() * CONFIG_EARLY_COUNTER_MULT) + >> CONFIG_EARLY_COUNTER_SHIFT; +} +#else +static inline u64 early_counter_ns(void) +{ + return 0; +} +#endif + __printf(4, 0) int vprintk_store(int facility, int level, const struct dev_printk_info *dev_info, @@ -2239,6 +2252,8 @@ int vprintk_store(int facility, int level, * timestamp with respect to the caller. */ ts_nsec = local_clock(); + if (!ts_nsec) + ts_nsec = early_counter_ns(); caller_id = printk_caller_id(); -- 2.43.0
Adding some people from the time subsystem into Cc. Please, keep them in the loop in the eventual next version of the patch. For the new people, please note the discussion has already started, see https://lore.kernel.org/r/39b09edb-8998-4ebd-a564-7d594434a981@bird.org Best Regards, Petr On Mon 2025-11-24 22:30:52, Tim Bird wrote:
{ "author": "Petr Mladek <pmladek@suse.com>", "date": "Wed, 26 Nov 2025 12:13:41 +0100", "thread_id": "39b09edb-8998-4ebd-a564-7d594434a981@bird.org.mbox.gz" }
lkml
[PATCH] printk: add early_counter_ns routine for printk blind spot
From: Tim Bird <tim.bird@sony.com> During early boot, printk timestamps are reported as zero, which creates a blind spot in early boot timings. This blind spot hinders timing and optimization efforts for code that executes before time_init(), which is when local_clock() is initialized sufficiently to start returning non-zero timestamps. This period is about 400 milliseconds for many current desktop and embedded machines running Linux. Add an early_counter_ns function that returns nanosecond timestamps based on get_cycles(). get_cycles() is operational on arm64 and x86_64 from kernel start. Add some calibration printks to allow setting configuration variables that are used to convert cycle counts to nanoseconds (which are then used in early printks). Add CONFIG_EARLY_COUNTER_NS, as well as some associated conversion variables, as new kernel config variables. After proper configuration, this yields non-zero timestamps for printks from the very start of kernel execution. The timestamps are relative to the start of the architecture-specific counter used in get_cycles (e.g. the TSC on x86_64 and cntvct_el0 on arm64). This means that the time reported reflects time-from-power-on for most embedded products. This is also a useful data point for boot-time optimization work. Note that there is a discontinuity in the timestamp sequencing when standard clocks are finally initialized in time_init(). The printk timestamps are thus not monotonically increasing through the entire boot. Signed-off-by: Tim Bird <tim.bird@sony.com> --- init/Kconfig | 47 ++++++++++++++++++++++++++++++++++++++++++ init/main.c | 25 ++++++++++++++++++++++ kernel/printk/printk.c | 15 ++++++++++++++ 3 files changed, 87 insertions(+) diff --git a/init/Kconfig b/init/Kconfig index cab3ad28ca49..5352567c43ed 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -770,6 +770,53 @@ config IKHEADERS or similar programs. If you build the headers as a module, a module called kheaders.ko is built which can be loaded on-demand to get access to headers. +config EARLY_COUNTER_NS + bool "Use counter for early printk timestamps" + default y + depends on PRINTK + help + Use a cycle-counter to provide printk timestamps during early + boot. This allows seeing timing information that would + otherwise be displayed with 0-valued timestamps. + + In order for this to work, you need to specify values for + EARLY_COUNTER_MULT and EARLY_COUNTER_SHIFT, used to convert + from the cycle count to nanoseconds. + +config EARLY_COUNTER_MULT + int "Multiplier for early cycle counter" + depends on PRINTK && EARLY_COUNTER_NS + default 1 + help + This value specifies a multiplier to be used when converting + cycle counts to nanoseconds. The formula used is: + ns = (cycles * mult) >> shift + + Use a multiplier that will bring the value of (cycles * mult) + to near a power of two, that is greater than 1000. The + nanoseconds returned by this conversion are divided by 1000 + to be used as the printk timestamp counter (with resolution + of microseconds). + + As an example, for a cycle-counter with a frequency of 200 Mhz, + the multiplier would be: 10485760, and the shift would be 21. + +config EARLY_COUNTER_SHIFT + int "Shift value for early cycle counter" + range 0 63 + depends on PRINTK && EARLY_COUNTER_NS + default 0 + help + This value specifies a shift value to be used when converting + cycle counts to nanoseconds. The formula used is: + ns = (cycles * mult) >> shift + + Use a shift that will bring the result to a value + in nanoseconds. + + As an example, for a cycle-counter with a frequency of 200 Mhz, + the multiplier would be: 10485760, and the shift would be 21. + config LOG_BUF_SHIFT int "Kernel log buffer size (16 => 64KB, 17 => 128KB)" range 12 25 diff --git a/init/main.c b/init/main.c index 07a3116811c5..587aaaad22d1 100644 --- a/init/main.c +++ b/init/main.c @@ -105,6 +105,8 @@ #include <linux/ptdump.h> #include <linux/time_namespace.h> #include <net/net_namespace.h> +#include <linux/timex.h> +#include <linux/sched/clock.h> #include <asm/io.h> #include <asm/setup.h> @@ -906,6 +908,8 @@ static void __init early_numa_node_init(void) #endif } +static u64 start_cycles, start_ns; + asmlinkage __visible __init __no_sanitize_address __noreturn __no_stack_protector void start_kernel(void) { @@ -1023,6 +1027,10 @@ void start_kernel(void) timekeeping_init(); time_init(); + /* used to calibrate early_counter_ns */ + start_cycles = get_cycles(); + start_ns = local_clock(); + /* This must be after timekeeping is initialized */ random_init(); @@ -1474,6 +1482,8 @@ void __weak free_initmem(void) static int __ref kernel_init(void *unused) { int ret; + u64 end_cycles, end_ns; + u32 early_mult, early_shift; /* * Wait until kthreadd is all set-up. @@ -1505,6 +1515,21 @@ static int __ref kernel_init(void *unused) do_sysctl_args(); + /* show calibration data for early_counter_ns */ + end_cycles = get_cycles(); + end_ns = local_clock(); + clocks_calc_mult_shift(&early_mult, &early_shift, + ((end_cycles - start_cycles) * NSEC_PER_SEC)/(end_ns - start_ns), + NSEC_PER_SEC, 50); + +#ifdef CONFIG_EARLY_COUNTER_NS + pr_info("Early Counter: start_cycles=%llu, end_cycles=%llu, cycles=%llu\n", + start_cycles, end_cycles, (end_cycles - start_cycles)); + pr_info("Early Counter: start_ns=%llu, end_ns=%llu, ns=%llu\n", + start_ns, end_ns, (end_ns - start_ns)); + pr_info("Early Counter: MULT=%u, SHIFT=%u\n", early_mult, early_shift); +#endif + if (ramdisk_execute_command) { ret = run_init_process(ramdisk_execute_command); if (!ret) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 5aee9ffb16b9..522dd24cd534 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2210,6 +2210,19 @@ static u16 printk_sprint(char *text, u16 size, int facility, return text_len; } +#ifdef CONFIG_EARLY_COUNTER_NS +static inline u64 early_counter_ns(void) +{ + return ((u64)get_cycles() * CONFIG_EARLY_COUNTER_MULT) + >> CONFIG_EARLY_COUNTER_SHIFT; +} +#else +static inline u64 early_counter_ns(void) +{ + return 0; +} +#endif + __printf(4, 0) int vprintk_store(int facility, int level, const struct dev_printk_info *dev_info, @@ -2239,6 +2252,8 @@ int vprintk_store(int facility, int level, * timestamp with respect to the caller. */ ts_nsec = local_clock(); + if (!ts_nsec) + ts_nsec = early_counter_ns(); caller_id = printk_caller_id(); -- 2.43.0
On Tue 2025-11-25 14:08:40, Francesco Valla wrote: Honestly, I am not sure if it would break anything. The fact is that printk() always used monotonic timers. And it is possible that some userspace depends on it. I personally thing that non-monotonic time stamps might be confusing but they should not cause any serious breakage. But I might be wrong. People are creative... I am not sure if this is a good idea. The offset would cause that all post-timer-init printk timestamps differ from values provided by the timer API. And it might cause confusion, for example, when they are printed as part of the message, or when analyzing a crash dump. On the other hand, there are various clock sources in the kernel which are not comparable anyway. So maybe I am too cautious. So, it is usable only for a particular HW. It is not usable for a generic kernel which is supposed to run on misc HW. I guess that there is no way to detect the CPU frequency at runtime? Best Regards, Petr
{ "author": "Petr Mladek <pmladek@suse.com>", "date": "Wed, 26 Nov 2025 13:55:32 +0100", "thread_id": "39b09edb-8998-4ebd-a564-7d594434a981@bird.org.mbox.gz" }
lkml
[PATCH] printk: add early_counter_ns routine for printk blind spot
From: Tim Bird <tim.bird@sony.com> During early boot, printk timestamps are reported as zero, which creates a blind spot in early boot timings. This blind spot hinders timing and optimization efforts for code that executes before time_init(), which is when local_clock() is initialized sufficiently to start returning non-zero timestamps. This period is about 400 milliseconds for many current desktop and embedded machines running Linux. Add an early_counter_ns function that returns nanosecond timestamps based on get_cycles(). get_cycles() is operational on arm64 and x86_64 from kernel start. Add some calibration printks to allow setting configuration variables that are used to convert cycle counts to nanoseconds (which are then used in early printks). Add CONFIG_EARLY_COUNTER_NS, as well as some associated conversion variables, as new kernel config variables. After proper configuration, this yields non-zero timestamps for printks from the very start of kernel execution. The timestamps are relative to the start of the architecture-specific counter used in get_cycles (e.g. the TSC on x86_64 and cntvct_el0 on arm64). This means that the time reported reflects time-from-power-on for most embedded products. This is also a useful data point for boot-time optimization work. Note that there is a discontinuity in the timestamp sequencing when standard clocks are finally initialized in time_init(). The printk timestamps are thus not monotonically increasing through the entire boot. Signed-off-by: Tim Bird <tim.bird@sony.com> --- init/Kconfig | 47 ++++++++++++++++++++++++++++++++++++++++++ init/main.c | 25 ++++++++++++++++++++++ kernel/printk/printk.c | 15 ++++++++++++++ 3 files changed, 87 insertions(+) diff --git a/init/Kconfig b/init/Kconfig index cab3ad28ca49..5352567c43ed 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -770,6 +770,53 @@ config IKHEADERS or similar programs. If you build the headers as a module, a module called kheaders.ko is built which can be loaded on-demand to get access to headers. +config EARLY_COUNTER_NS + bool "Use counter for early printk timestamps" + default y + depends on PRINTK + help + Use a cycle-counter to provide printk timestamps during early + boot. This allows seeing timing information that would + otherwise be displayed with 0-valued timestamps. + + In order for this to work, you need to specify values for + EARLY_COUNTER_MULT and EARLY_COUNTER_SHIFT, used to convert + from the cycle count to nanoseconds. + +config EARLY_COUNTER_MULT + int "Multiplier for early cycle counter" + depends on PRINTK && EARLY_COUNTER_NS + default 1 + help + This value specifies a multiplier to be used when converting + cycle counts to nanoseconds. The formula used is: + ns = (cycles * mult) >> shift + + Use a multiplier that will bring the value of (cycles * mult) + to near a power of two, that is greater than 1000. The + nanoseconds returned by this conversion are divided by 1000 + to be used as the printk timestamp counter (with resolution + of microseconds). + + As an example, for a cycle-counter with a frequency of 200 Mhz, + the multiplier would be: 10485760, and the shift would be 21. + +config EARLY_COUNTER_SHIFT + int "Shift value for early cycle counter" + range 0 63 + depends on PRINTK && EARLY_COUNTER_NS + default 0 + help + This value specifies a shift value to be used when converting + cycle counts to nanoseconds. The formula used is: + ns = (cycles * mult) >> shift + + Use a shift that will bring the result to a value + in nanoseconds. + + As an example, for a cycle-counter with a frequency of 200 Mhz, + the multiplier would be: 10485760, and the shift would be 21. + config LOG_BUF_SHIFT int "Kernel log buffer size (16 => 64KB, 17 => 128KB)" range 12 25 diff --git a/init/main.c b/init/main.c index 07a3116811c5..587aaaad22d1 100644 --- a/init/main.c +++ b/init/main.c @@ -105,6 +105,8 @@ #include <linux/ptdump.h> #include <linux/time_namespace.h> #include <net/net_namespace.h> +#include <linux/timex.h> +#include <linux/sched/clock.h> #include <asm/io.h> #include <asm/setup.h> @@ -906,6 +908,8 @@ static void __init early_numa_node_init(void) #endif } +static u64 start_cycles, start_ns; + asmlinkage __visible __init __no_sanitize_address __noreturn __no_stack_protector void start_kernel(void) { @@ -1023,6 +1027,10 @@ void start_kernel(void) timekeeping_init(); time_init(); + /* used to calibrate early_counter_ns */ + start_cycles = get_cycles(); + start_ns = local_clock(); + /* This must be after timekeeping is initialized */ random_init(); @@ -1474,6 +1482,8 @@ void __weak free_initmem(void) static int __ref kernel_init(void *unused) { int ret; + u64 end_cycles, end_ns; + u32 early_mult, early_shift; /* * Wait until kthreadd is all set-up. @@ -1505,6 +1515,21 @@ static int __ref kernel_init(void *unused) do_sysctl_args(); + /* show calibration data for early_counter_ns */ + end_cycles = get_cycles(); + end_ns = local_clock(); + clocks_calc_mult_shift(&early_mult, &early_shift, + ((end_cycles - start_cycles) * NSEC_PER_SEC)/(end_ns - start_ns), + NSEC_PER_SEC, 50); + +#ifdef CONFIG_EARLY_COUNTER_NS + pr_info("Early Counter: start_cycles=%llu, end_cycles=%llu, cycles=%llu\n", + start_cycles, end_cycles, (end_cycles - start_cycles)); + pr_info("Early Counter: start_ns=%llu, end_ns=%llu, ns=%llu\n", + start_ns, end_ns, (end_ns - start_ns)); + pr_info("Early Counter: MULT=%u, SHIFT=%u\n", early_mult, early_shift); +#endif + if (ramdisk_execute_command) { ret = run_init_process(ramdisk_execute_command); if (!ret) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 5aee9ffb16b9..522dd24cd534 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2210,6 +2210,19 @@ static u16 printk_sprint(char *text, u16 size, int facility, return text_len; } +#ifdef CONFIG_EARLY_COUNTER_NS +static inline u64 early_counter_ns(void) +{ + return ((u64)get_cycles() * CONFIG_EARLY_COUNTER_MULT) + >> CONFIG_EARLY_COUNTER_SHIFT; +} +#else +static inline u64 early_counter_ns(void) +{ + return 0; +} +#endif + __printf(4, 0) int vprintk_store(int facility, int level, const struct dev_printk_info *dev_info, @@ -2239,6 +2252,8 @@ int vprintk_store(int facility, int level, * timestamp with respect to the caller. */ ts_nsec = local_clock(); + if (!ts_nsec) + ts_nsec = early_counter_ns(); caller_id = printk_caller_id(); -- 2.43.0
I worried about this, but I'm skeptical it's a big deal. Humans might be a little confused, but it's not difficult to see what's going on just by looking at the timestamps. If a tool breaks, especially something that's used in automation, e.g. it's used to report results, or is in some sort of CI loop where the break will cascade into a test failure, then that's a bigger issue. But right now I'm not aware of any boot-time tests where that would be the case. I'll comment more on different fixes for this below. I thought of adding an offset, but I didn't want to disturb anything past the time_init() call. As it is now, the early_counter_ns feature only changes the zero-valued timestamps. So anything relying on the absolute value of an existing timestamp later in the boot would not be affected. I thought that if people suddenly saw the timestamps jump by 10 to 30 seconds (since they are now relative to machine start instead of to kernel clock start (time_init()), it would be very jarring. I suppose they would get used to it, though, and all relative timings should stay the same. I also didn't want to add additional overhead (even a single add) in the case where CONFIG_EARLY_COUNTER_NS was disabled. But, realistically, I don't think an additional add in the printk path is not going to be noticeable, and I can probably structure it so that there's absolutely no overhead when CONFIG_EARLY_COUNTER_NS is disabled. I considered embedding an early counter offset into local_clock(), and thus not modifying the printk code at all. This would have the benefit of keeping the printk timestamps consistent with other uses of local_clock() data (such as crash dumps or inside other messages). But then that would embed the early_counter overhead into every user of local_clock() (whether humans saw the timestamp values or not). And some of those users might be more performance sensitive than printk is. Finally, I considered adding another config option to control adding the offset, but at 3 configs for this fairly niche functionality, I thought I was already pushing my luck. But a new config would be easy to add. My plan is to add an offset for the early_counter_ns value to printk, without a config, in the next patch version, and see what people think. Yeah, I was worried about these Kconfig explanations. I think it will be easier to just explain how I recommend this should be configured, which is something like: Turn on CONFIG_EARLY_COUNTER_NS, run the kernel once, get the values for MULT and SHIFT (printed by the calibration code), enter them in the appropriate configs, and then build and run the kernel again. This only needs to be done once per platform, and could even be put into the defconfig (or a config fragment) for a platform. (More on having hardcoded config for this below). It was not my intent to have kernel developers doing weird (shift) math to enable this feature. Note that I can't get the values from devicetree or the kernel command line, as this is used before either of those is initialized or parsed. That's correct. It is mostly targeted at embedded products, where shaving off 10 to 200 milliseconds in the pre-clock-initialization region of boot would be valuable. For people doing aggressive boot time optimization, they will have a custom kernel anyway (and probably a custom bootloader, device tree, initramfs, udev rules, SE linux rules, module load ordering, systemd config, etc.) Basically, if you're optimizing the code in this kernel boot time blind spot, you are very likely not using a generic kernel. (That's not to say that the optimizations made won't ultimately be valuable to people using generic kernels). This "feature" is used before clock initialization, which is what would be used to calibrate the CPU frequency at runtime. This runs so early that doing the calibration inline doesn't work. Not enough kernel services are available (Actually, zero services are available, as this can be used in the very first printk in start_kernel.) Plan from here... I got a compile error from 0-day on powerpc, so I need to re-spin to fix that. I'll address the other issues raised and submit a new version when I can. I'm off to Japan this week, and between business travel and the holidays, and being away from my lab where I can do hardware testing, it will probably be some time in January before I send the next version. Thanks very much for the feedback! -- Tim
{ "author": "\"Bird, Tim\" <Tim.Bird@sony.com>", "date": "Thu, 27 Nov 2025 00:03:32 +0000", "thread_id": "39b09edb-8998-4ebd-a564-7d594434a981@bird.org.mbox.gz" }
lkml
[PATCH] printk: add early_counter_ns routine for printk blind spot
From: Tim Bird <tim.bird@sony.com> During early boot, printk timestamps are reported as zero, which creates a blind spot in early boot timings. This blind spot hinders timing and optimization efforts for code that executes before time_init(), which is when local_clock() is initialized sufficiently to start returning non-zero timestamps. This period is about 400 milliseconds for many current desktop and embedded machines running Linux. Add an early_counter_ns function that returns nanosecond timestamps based on get_cycles(). get_cycles() is operational on arm64 and x86_64 from kernel start. Add some calibration printks to allow setting configuration variables that are used to convert cycle counts to nanoseconds (which are then used in early printks). Add CONFIG_EARLY_COUNTER_NS, as well as some associated conversion variables, as new kernel config variables. After proper configuration, this yields non-zero timestamps for printks from the very start of kernel execution. The timestamps are relative to the start of the architecture-specific counter used in get_cycles (e.g. the TSC on x86_64 and cntvct_el0 on arm64). This means that the time reported reflects time-from-power-on for most embedded products. This is also a useful data point for boot-time optimization work. Note that there is a discontinuity in the timestamp sequencing when standard clocks are finally initialized in time_init(). The printk timestamps are thus not monotonically increasing through the entire boot. Signed-off-by: Tim Bird <tim.bird@sony.com> --- init/Kconfig | 47 ++++++++++++++++++++++++++++++++++++++++++ init/main.c | 25 ++++++++++++++++++++++ kernel/printk/printk.c | 15 ++++++++++++++ 3 files changed, 87 insertions(+) diff --git a/init/Kconfig b/init/Kconfig index cab3ad28ca49..5352567c43ed 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -770,6 +770,53 @@ config IKHEADERS or similar programs. If you build the headers as a module, a module called kheaders.ko is built which can be loaded on-demand to get access to headers. +config EARLY_COUNTER_NS + bool "Use counter for early printk timestamps" + default y + depends on PRINTK + help + Use a cycle-counter to provide printk timestamps during early + boot. This allows seeing timing information that would + otherwise be displayed with 0-valued timestamps. + + In order for this to work, you need to specify values for + EARLY_COUNTER_MULT and EARLY_COUNTER_SHIFT, used to convert + from the cycle count to nanoseconds. + +config EARLY_COUNTER_MULT + int "Multiplier for early cycle counter" + depends on PRINTK && EARLY_COUNTER_NS + default 1 + help + This value specifies a multiplier to be used when converting + cycle counts to nanoseconds. The formula used is: + ns = (cycles * mult) >> shift + + Use a multiplier that will bring the value of (cycles * mult) + to near a power of two, that is greater than 1000. The + nanoseconds returned by this conversion are divided by 1000 + to be used as the printk timestamp counter (with resolution + of microseconds). + + As an example, for a cycle-counter with a frequency of 200 Mhz, + the multiplier would be: 10485760, and the shift would be 21. + +config EARLY_COUNTER_SHIFT + int "Shift value for early cycle counter" + range 0 63 + depends on PRINTK && EARLY_COUNTER_NS + default 0 + help + This value specifies a shift value to be used when converting + cycle counts to nanoseconds. The formula used is: + ns = (cycles * mult) >> shift + + Use a shift that will bring the result to a value + in nanoseconds. + + As an example, for a cycle-counter with a frequency of 200 Mhz, + the multiplier would be: 10485760, and the shift would be 21. + config LOG_BUF_SHIFT int "Kernel log buffer size (16 => 64KB, 17 => 128KB)" range 12 25 diff --git a/init/main.c b/init/main.c index 07a3116811c5..587aaaad22d1 100644 --- a/init/main.c +++ b/init/main.c @@ -105,6 +105,8 @@ #include <linux/ptdump.h> #include <linux/time_namespace.h> #include <net/net_namespace.h> +#include <linux/timex.h> +#include <linux/sched/clock.h> #include <asm/io.h> #include <asm/setup.h> @@ -906,6 +908,8 @@ static void __init early_numa_node_init(void) #endif } +static u64 start_cycles, start_ns; + asmlinkage __visible __init __no_sanitize_address __noreturn __no_stack_protector void start_kernel(void) { @@ -1023,6 +1027,10 @@ void start_kernel(void) timekeeping_init(); time_init(); + /* used to calibrate early_counter_ns */ + start_cycles = get_cycles(); + start_ns = local_clock(); + /* This must be after timekeeping is initialized */ random_init(); @@ -1474,6 +1482,8 @@ void __weak free_initmem(void) static int __ref kernel_init(void *unused) { int ret; + u64 end_cycles, end_ns; + u32 early_mult, early_shift; /* * Wait until kthreadd is all set-up. @@ -1505,6 +1515,21 @@ static int __ref kernel_init(void *unused) do_sysctl_args(); + /* show calibration data for early_counter_ns */ + end_cycles = get_cycles(); + end_ns = local_clock(); + clocks_calc_mult_shift(&early_mult, &early_shift, + ((end_cycles - start_cycles) * NSEC_PER_SEC)/(end_ns - start_ns), + NSEC_PER_SEC, 50); + +#ifdef CONFIG_EARLY_COUNTER_NS + pr_info("Early Counter: start_cycles=%llu, end_cycles=%llu, cycles=%llu\n", + start_cycles, end_cycles, (end_cycles - start_cycles)); + pr_info("Early Counter: start_ns=%llu, end_ns=%llu, ns=%llu\n", + start_ns, end_ns, (end_ns - start_ns)); + pr_info("Early Counter: MULT=%u, SHIFT=%u\n", early_mult, early_shift); +#endif + if (ramdisk_execute_command) { ret = run_init_process(ramdisk_execute_command); if (!ret) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 5aee9ffb16b9..522dd24cd534 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2210,6 +2210,19 @@ static u16 printk_sprint(char *text, u16 size, int facility, return text_len; } +#ifdef CONFIG_EARLY_COUNTER_NS +static inline u64 early_counter_ns(void) +{ + return ((u64)get_cycles() * CONFIG_EARLY_COUNTER_MULT) + >> CONFIG_EARLY_COUNTER_SHIFT; +} +#else +static inline u64 early_counter_ns(void) +{ + return 0; +} +#endif + __printf(4, 0) int vprintk_store(int facility, int level, const struct dev_printk_info *dev_info, @@ -2239,6 +2252,8 @@ int vprintk_store(int facility, int level, * timestamp with respect to the caller. */ ts_nsec = local_clock(); + if (!ts_nsec) + ts_nsec = early_counter_ns(); caller_id = printk_caller_id(); -- 2.43.0
I thought about this while I was creating this. It wouldn't require the extra configuration for MULT and SHIFT (which would be nice), and it would be, as you say, very obvious that this was not a regular timestamp. This means it could be enabled on a generic kernel (making more likely it could be enabled by default). And really only boot-time optimizers would care enough to decode the data, so the onus would be on them to run the tool. Everyone else could ignore them. I'm not sure if it would break existing printk-processing tools. I suspect it would. Also, I find that post-processing tools often get overlooked. I asked at ELC this year how many people are using show_delta, which has been upstream for years, and can do a few neat things with printk timestamps, and not a single person had even heard of it. In this scenario, you would still need to have the calibration printks in the code so that the tool could pull them out to then convert the cycle-valued printks into printks with regular timestamps. I could see doing this if people object to the non-genericity of the current solution. Thanks for the feedback! -- Tim
{ "author": "\"Bird, Tim\" <Tim.Bird@sony.com>", "date": "Thu, 27 Nov 2025 00:16:23 +0000", "thread_id": "39b09edb-8998-4ebd-a564-7d594434a981@bird.org.mbox.gz" }
lkml
[PATCH] printk: add early_counter_ns routine for printk blind spot
From: Tim Bird <tim.bird@sony.com> During early boot, printk timestamps are reported as zero, which creates a blind spot in early boot timings. This blind spot hinders timing and optimization efforts for code that executes before time_init(), which is when local_clock() is initialized sufficiently to start returning non-zero timestamps. This period is about 400 milliseconds for many current desktop and embedded machines running Linux. Add an early_counter_ns function that returns nanosecond timestamps based on get_cycles(). get_cycles() is operational on arm64 and x86_64 from kernel start. Add some calibration printks to allow setting configuration variables that are used to convert cycle counts to nanoseconds (which are then used in early printks). Add CONFIG_EARLY_COUNTER_NS, as well as some associated conversion variables, as new kernel config variables. After proper configuration, this yields non-zero timestamps for printks from the very start of kernel execution. The timestamps are relative to the start of the architecture-specific counter used in get_cycles (e.g. the TSC on x86_64 and cntvct_el0 on arm64). This means that the time reported reflects time-from-power-on for most embedded products. This is also a useful data point for boot-time optimization work. Note that there is a discontinuity in the timestamp sequencing when standard clocks are finally initialized in time_init(). The printk timestamps are thus not monotonically increasing through the entire boot. Signed-off-by: Tim Bird <tim.bird@sony.com> --- init/Kconfig | 47 ++++++++++++++++++++++++++++++++++++++++++ init/main.c | 25 ++++++++++++++++++++++ kernel/printk/printk.c | 15 ++++++++++++++ 3 files changed, 87 insertions(+) diff --git a/init/Kconfig b/init/Kconfig index cab3ad28ca49..5352567c43ed 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -770,6 +770,53 @@ config IKHEADERS or similar programs. If you build the headers as a module, a module called kheaders.ko is built which can be loaded on-demand to get access to headers. +config EARLY_COUNTER_NS + bool "Use counter for early printk timestamps" + default y + depends on PRINTK + help + Use a cycle-counter to provide printk timestamps during early + boot. This allows seeing timing information that would + otherwise be displayed with 0-valued timestamps. + + In order for this to work, you need to specify values for + EARLY_COUNTER_MULT and EARLY_COUNTER_SHIFT, used to convert + from the cycle count to nanoseconds. + +config EARLY_COUNTER_MULT + int "Multiplier for early cycle counter" + depends on PRINTK && EARLY_COUNTER_NS + default 1 + help + This value specifies a multiplier to be used when converting + cycle counts to nanoseconds. The formula used is: + ns = (cycles * mult) >> shift + + Use a multiplier that will bring the value of (cycles * mult) + to near a power of two, that is greater than 1000. The + nanoseconds returned by this conversion are divided by 1000 + to be used as the printk timestamp counter (with resolution + of microseconds). + + As an example, for a cycle-counter with a frequency of 200 Mhz, + the multiplier would be: 10485760, and the shift would be 21. + +config EARLY_COUNTER_SHIFT + int "Shift value for early cycle counter" + range 0 63 + depends on PRINTK && EARLY_COUNTER_NS + default 0 + help + This value specifies a shift value to be used when converting + cycle counts to nanoseconds. The formula used is: + ns = (cycles * mult) >> shift + + Use a shift that will bring the result to a value + in nanoseconds. + + As an example, for a cycle-counter with a frequency of 200 Mhz, + the multiplier would be: 10485760, and the shift would be 21. + config LOG_BUF_SHIFT int "Kernel log buffer size (16 => 64KB, 17 => 128KB)" range 12 25 diff --git a/init/main.c b/init/main.c index 07a3116811c5..587aaaad22d1 100644 --- a/init/main.c +++ b/init/main.c @@ -105,6 +105,8 @@ #include <linux/ptdump.h> #include <linux/time_namespace.h> #include <net/net_namespace.h> +#include <linux/timex.h> +#include <linux/sched/clock.h> #include <asm/io.h> #include <asm/setup.h> @@ -906,6 +908,8 @@ static void __init early_numa_node_init(void) #endif } +static u64 start_cycles, start_ns; + asmlinkage __visible __init __no_sanitize_address __noreturn __no_stack_protector void start_kernel(void) { @@ -1023,6 +1027,10 @@ void start_kernel(void) timekeeping_init(); time_init(); + /* used to calibrate early_counter_ns */ + start_cycles = get_cycles(); + start_ns = local_clock(); + /* This must be after timekeeping is initialized */ random_init(); @@ -1474,6 +1482,8 @@ void __weak free_initmem(void) static int __ref kernel_init(void *unused) { int ret; + u64 end_cycles, end_ns; + u32 early_mult, early_shift; /* * Wait until kthreadd is all set-up. @@ -1505,6 +1515,21 @@ static int __ref kernel_init(void *unused) do_sysctl_args(); + /* show calibration data for early_counter_ns */ + end_cycles = get_cycles(); + end_ns = local_clock(); + clocks_calc_mult_shift(&early_mult, &early_shift, + ((end_cycles - start_cycles) * NSEC_PER_SEC)/(end_ns - start_ns), + NSEC_PER_SEC, 50); + +#ifdef CONFIG_EARLY_COUNTER_NS + pr_info("Early Counter: start_cycles=%llu, end_cycles=%llu, cycles=%llu\n", + start_cycles, end_cycles, (end_cycles - start_cycles)); + pr_info("Early Counter: start_ns=%llu, end_ns=%llu, ns=%llu\n", + start_ns, end_ns, (end_ns - start_ns)); + pr_info("Early Counter: MULT=%u, SHIFT=%u\n", early_mult, early_shift); +#endif + if (ramdisk_execute_command) { ret = run_init_process(ramdisk_execute_command); if (!ret) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 5aee9ffb16b9..522dd24cd534 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2210,6 +2210,19 @@ static u16 printk_sprint(char *text, u16 size, int facility, return text_len; } +#ifdef CONFIG_EARLY_COUNTER_NS +static inline u64 early_counter_ns(void) +{ + return ((u64)get_cycles() * CONFIG_EARLY_COUNTER_MULT) + >> CONFIG_EARLY_COUNTER_SHIFT; +} +#else +static inline u64 early_counter_ns(void) +{ + return 0; +} +#endif + __printf(4, 0) int vprintk_store(int facility, int level, const struct dev_printk_info *dev_info, @@ -2239,6 +2252,8 @@ int vprintk_store(int facility, int level, * timestamp with respect to the caller. */ ts_nsec = local_clock(); + if (!ts_nsec) + ts_nsec = early_counter_ns(); caller_id = printk_caller_id(); -- 2.43.0
Hi Tim, kernel test robot noticed the following build errors: [auto build test ERROR on linus/master] [also build test ERROR on v6.18-rc7] [cannot apply to akpm-mm/mm-everything next-20251127] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Tim-Bird/printk-add-early_counter_ns-routine-for-printk-blind-spot/20251125-133242 base: linus/master patch link: https://lore.kernel.org/r/39b09edb-8998-4ebd-a564-7d594434a981%40bird.org patch subject: [PATCH] printk: add early_counter_ns routine for printk blind spot config: i386-randconfig-2006-20250825 (https://download.01.org/0day-ci/archive/20251127/202511271051.yfp2O98B-lkp@intel.com/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251127/202511271051.yfp2O98B-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202511271051.yfp2O98B-lkp@intel.com/ All errors (new ones prefixed by >>): ld: init/main.o: in function `kernel_init': vim +1522 init/main.c 1481 1482 static int __ref kernel_init(void *unused) 1483 { 1484 int ret; 1485 u64 end_cycles, end_ns; 1486 u32 early_mult, early_shift; 1487 1488 /* 1489 * Wait until kthreadd is all set-up. 1490 */ 1491 wait_for_completion(&kthreadd_done); 1492 1493 kernel_init_freeable(); 1494 /* need to finish all async __init code before freeing the memory */ 1495 async_synchronize_full(); 1496 1497 system_state = SYSTEM_FREEING_INITMEM; 1498 kprobe_free_init_mem(); 1499 ftrace_free_init_mem(); 1500 kgdb_free_init_mem(); 1501 exit_boot_config(); 1502 free_initmem(); 1503 mark_readonly(); 1504 1505 /* 1506 * Kernel mappings are now finalized - update the userspace page-table 1507 * to finalize PTI. 1508 */ 1509 pti_finalize(); 1510 1511 system_state = SYSTEM_RUNNING; 1512 numa_default_policy(); 1513 1514 rcu_end_inkernel_boot(); 1515 1516 do_sysctl_args(); 1517 1518 /* show calibration data for early_counter_ns */ 1519 end_cycles = get_cycles(); 1520 end_ns = local_clock(); 1521 clocks_calc_mult_shift(&early_mult, &early_shift, 1523 NSEC_PER_SEC, 50); 1524 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
{ "author": "kernel test robot <lkp@intel.com>", "date": "Thu, 27 Nov 2025 10:13:23 +0100", "thread_id": "39b09edb-8998-4ebd-a564-7d594434a981@bird.org.mbox.gz" }