alpha: catch up on architecture Kconfig options
Subsystems (2)
Matt Turner
maintainerv2 cover alpha: catch up on architecture Kconfig options
This is v2 of "alpha: catch up on architecture Kconfig options"
(https://lore.kernel.org/linux-alpha/CAEdQ38FoUPzftf9vDcJK8L38j+cDzTyxdL+Fj-3oAQHmmOxaOA@mail.gmail.com/T/#t),
addressing Magnus Lindholm's review and rebased onto v7.3-rc1 plus his GENERIC_ENTRY v5
(https://lore.kernel.org/linux-alpha/[email protected]/T/#t),
per his request.
Changes since v1:
- Dropped "fix arch_irqs_disabled_flags() to treat any raised IPL as disabled". Magnus's objection was right: per the Architecture Reference Manual an intermediate IPL only masks interrupts at or below that level, and do_entInt() already drives PS.IPL to IPL_MAX itself before reporting hardirq state to lockdep, so the original arch_irqs_disabled_flags() was correct as it stood.
- Dropped "add TRACE_IRQFLAGS_SUPPORT". It conflicted with GENERIC_ENTRY exactly where Magnus expected: the entInt, entSys, and restore_all instrumentation it added is now redundant with the hardirq-state transitions GENERIC_ENTRY performs on those paths itself. I want to work out separately, and with real testing, whether the remaining synchronous-exception entry points need anything at all here, rather than resend a patch I can't fully justify.
- Fixed "add ARCH_SUPPORTS_PAGE_TABLE_CHECK support", which no longer built against v7.3-rc1: commit cf8771ca4cdb ("mm/page_table_check:
Pass mm_struct to pxx_user_accessible_page()") changed the callback signature, and Alpha's copy is now updated to match.
- Added the Signed-off-by that was missing from "select SPARSE_IRQ".
- Folded the corresponding arch-support.txt updates into "select ARCH_HAS_GCOV_PROFILE_ALL", "select HAVE_DEBUG_KMEMLEAK", "add ARCH_HAS_PTE_SPECIAL support", and "select ARCH_HAS_DEBUG_VM_PGTABLE", and added ALPHA to the memtest= parameter list in kernel-parameters.txt.
- Did not touch "add HAVE_PERF_REGS and HAVE_PERF_USER_STACK_DUMP support" beyond rebasing it. Magnus found real gaps there (tools/perf has no Alpha register mask, and regs->usp isn't snapshotted on the interrupt path), so I've left the corresponding feature matrices alone rather than claim it's done.
- Picked up Tested-by/Reviewed-by from Magnus on the patches he gave them for.
Not yet addressed: whether do_entInt() should own hardirq context for both interrupt paths and drop the irq_enter()/irq_exit() pair from handle_irq(), which Magnus asked about on "enter hardirq context before looking up the irq descriptor". No code change there yet; I'll follow up on that thread separately.
Tested by cross-building with alpha-unknown-linux-gnu-gcc against defconfig and, for the page-table-check fix, against a config with CONFIG_PAGE_TABLE_CHECK=y. Boot tested on an AlphaServer ES47.
Also available at:
git://git.kernel.org/pub/scm/linux/kernel/git/mattst88/alpha.git arch-kconfig-options-v2
---
Matt Turner (22):
alpha: enter hardirq context before looking up the irq descriptor
alpha: select ARCH_HAS_UBSAN
alpha: select ARCH_HAS_GCOV_PROFILE_ALL
alpha: select HAVE_DEBUG_KMEMLEAK
alpha: select EDAC_SUPPORT
alpha: select ARCH_SUPPORTS_ATOMIC_RMW
alpha: select ARCH_HAS_FAST_MULTIPLIER
alpha: select ARCH_SUPPORTS_INT128
alpha: select HAVE_ARCH_COMPILER_H
alpha: select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
alpha: add HAVE_ARCH_THREAD_STRUCT_WHITELIST support
alpha: add ARCH_HAS_PTE_SPECIAL support
alpha: add ARCH_SUPPORTS_PAGE_TABLE_CHECK support
alpha: select ARCH_HAS_DEBUG_VM_PGTABLE
alpha: select HAVE_GUP_FAST
alpha: select ARCH_USE_MEMTEST
alpha: select SYSCTL_EXCEPTION_TRACE
alpha: discard .eh_frame and the relocation sections
alpha: select ARCH_WANT_LD_ORPHAN_WARN
alpha: select ARCH_WANT_IRQS_OFF_ACTIVATE_MM
alpha: add HAVE_PERF_REGS and HAVE_PERF_USER_STACK_DUMP support
alpha: select SPARSE_IRQ
Documentation/admin-guide/kernel-parameters.txt | 2 +- .../debug/debug-vm-pgtable/arch-support.txt | 2 +- .../debug/gcov-profile-all/arch-support.txt | 2 +- .../features/debug/kmemleak/arch-support.txt | 2 +- .../features/vm/pte_special/arch-support.txt | 2 +- arch/alpha/Kconfig | 21 ++++++ arch/alpha/include/asm/perf_regs.h | 7 ++ arch/alpha/include/asm/pgtable.h | 24 +++++- arch/alpha/include/asm/processor.h | 7 ++ arch/alpha/include/uapi/asm/perf_regs.h | 34 +++++++++ arch/alpha/kernel/Makefile | 1 + arch/alpha/kernel/irq.c | 9 ++- arch/alpha/kernel/irq_alpha.c | 13 ++++ arch/alpha/kernel/perf_regs.c | 86 ++++++++++++++++++++++ arch/alpha/kernel/vmlinux.lds.S | 11 +++ arch/alpha/mm/fault.c | 29 ++++++++ arch/alpha/mm/init.c | 5 ++ 17 files changed, 248 insertions(+), 9 deletions(-)
---
base-commit: f321329c1b70835e6b0807fddac6d4117e5604fc
change-id: 20260904-arch-kconfig-options-v2-8efa959ffcbd
Best regards,
Signature · 1 line
Matt Turner <[email protected]>
Matt Turner
maintainerPATCH v2 1/22 alpha: enter hardirq context before looking up the irq descriptor
handle_irq() called irq_to_desc() before irq_enter(), so that lookup ran with the preempt count still saying task context and with RCU not yet watching. Generic code called from an interrupt handler should see hardirq context, and irq_to_desc() is more than an array index once SPARSE_IRQ is in use.
Move irq_enter() to the top of the function and add the matching irq_exit() to the invalid interrupt path.
--- arch/alpha/kernel/irq.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
arch/alpha/kernel/irq.c +6 -3
@@ -107,18 +107,21 @@ handle_irq(int irq)* handled by some other CPU. (or is disabled) */ static unsigned int illegal_count=0 ; -struct irq_desc *desc =irq_to_desc (irq); - +struct irq_desc *desc; + +irq_enter (); + + desc =irq_to_desc (irq);if (!desc || ((unsigned ) irq >ACTUAL_NR_IRQS && illegal_count <MAX_ILLEGAL_IRQS )) { irq_err_count++; illegal_count++;printk (KERN_CRIT "device_interrupt: invalid interrupt %d\n" , irq); +irq_exit ();return ; } -irq_enter ();generic_handle_irq_desc (desc);irq_exit (); }
Signature · 1 line
2.54.0
Re: [PATCH v2 01/22] alpha: enter hardirq context before looking up the irq descriptor
Hi Matt,
Quoted 36 lines · Matt Turner
handle_irq()calledirq_to_desc()beforeirq_enter(), so that lookup ran with the preempt count still saying task context and with RCU not yet watching. Generic code called from an interrupt handler should see hardirq context, andirq_to_desc()is more than an array index onceSPARSE_IRQis in use.Move
irq_enter()to the top of the function and add the matchingirq_exit()to the invalid interrupt path.Assisted-by Claude:claude-opus-5Signed-off-by Matt Turner <[email protected]>--- arch/alpha/kernel/irq.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)arch/alpha/kernel/irq.c +5
-2@@ -107,18 +107,21 @@ handle_irq(int irq)* handled by some other CPU. (or is disabled) */ static unsigned int illegal_count=0 ; -struct irq_desc *desc =irq_to_desc (irq); - +struct irq_desc *desc; + +irq_enter (); + + desc =irq_to_desc (irq);if (!desc || ((unsigned ) irq >ACTUAL_NR_IRQS && illegal_count <MAX_ILLEGAL_IRQS )) { irq_err_count++; illegal_count++;
arch/alpha/kernel/irq.c handle_irq(int irq) · line 127
Quoted 10 lines
arch/alpha/kernel/irq.c +1
-1printk (KERN_CRIT "device_interrupt: invalid interrupt %d\n" , irq); +irq_exit ();return ; } -irq_enter ();generic_handle_irq_desc (desc);irq_exit (); }
Since this patch is unchanged in v2, and we agreed to handle the hardirq-context consolidation as a follow-up, my tags from reviewing and testing the current change are:
Regards,
Magnus
Matt Turner
maintainerPATCH v2 2/22 alpha: select ARCH_HAS_UBSAN
In reply to Matt TurnerGCC's undefined behavior sanitizer has no architecture-specific runtime requirements. Enable it for Alpha to allow UBSAN instrumentation of the kernel.
--- arch/alpha/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/alpha/Kconfig +1 -0
@@ -7,6 +7,7 @@ config ALPHA select ARCH_32BIT_USTAT_F_TINODE select ARCH_HAS_CURRENT_STACK_POINTER select ARCH_HAS_DMA_OPS if PCI + select ARCH_HAS_UBSAN select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_MIGHT_HAVE_PC_SERIO select ARCH_MODULE_NEEDS_WEAK_PER_CPU if SMP
Signature · 1 line
2.54.0
Matt Turner
maintainerPATCH v2 3/22 alpha: select ARCH_HAS_GCOV_PROFILE_ALL
In reply to Matt TurnerGCC's gcov instrumentation (-fprofile-arcs -ftest-coverage) has no architecture-specific runtime requirements. Enable GCOV_PROFILE_ALL support for Alpha to allow whole-kernel code coverage analysis.
Also mark Alpha as "ok" in the gcov-profile-all feature matrix.
--- Documentation/features/debug/gcov-profile-all/arch-support.txt | 2 +- arch/alpha/Kconfig | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
Documentation/features/debug/gcov-profile-all/arch-support.txt +1 -1
@@ -6,7 +6,7 @@ ----------------------- | arch |status| ----------------------- - | alpha: | TODO | + | alpha: | ok | | arc: | TODO | | arm: | ok | | arm64: | ok |
arch/alpha/Kconfig +1 -0
@@ -7,6 +7,7 @@ config ALPHA select ARCH_32BIT_USTAT_F_TINODE select ARCH_HAS_CURRENT_STACK_POINTER select ARCH_HAS_DMA_OPS if PCI + select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_UBSAN select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_MIGHT_HAVE_PC_SERIO
Signature · 1 line
2.54.0
Matt Turner
maintainerPATCH v2 4/22 alpha: select HAVE_DEBUG_KMEMLEAK
In reply to Matt TurnerKmemleak needs no architecture support beyond the standard linker script symbols for the data and bss sections, which Alpha already provides, and a scan of the kernel stacks, which is done generically.
Also mark Alpha as "ok" in the kmemleak feature matrix.
--- Documentation/features/debug/kmemleak/arch-support.txt | 2 +- arch/alpha/Kconfig | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
Documentation/features/debug/kmemleak/arch-support.txt +1 -1
@@ -6,7 +6,7 @@ ----------------------- | arch |status| ----------------------- - | alpha: | TODO | + | alpha: | ok | | arc: | ok | | arm: | ok | | arm64: | ok |
arch/alpha/Kconfig +1 -0
@@ -19,6 +19,7 @@ config ALPHA select PCI_DOMAINS if PCI select PCI_SYSCALL if PCI select HAVE_ASM_MODVERSIONS + select HAVE_DEBUG_KMEMLEAK select HAVE_PAGE_SIZE_8KB select HAVE_PCSPKR_PLATFORM select HAVE_PERF_EVENTS
Signature · 1 line
2.54.0
Matt Turner
maintainerPATCH v2 5/22 alpha: select EDAC_SUPPORT
In reply to Matt TurnerThe EDAC core builds and works on Alpha; it only needs the architecture to declare support. There is no Alpha memory controller driver yet, but the core is what a future driver, or the existing machine check error decoding in err_ev6.c and err_ev7.c, would report through.
--- arch/alpha/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/alpha/Kconfig +1 -0
@@ -32,6 +32,7 @@ config ALPHA select ARCH_WANT_IPC_PARSE_VERSION select ARCH_HAVE_NMI_SAFE_CMPXCHG select AUDIT_ARCH + select EDAC_SUPPORT select GENERIC_CPU_VULNERABILITIES select GENERIC_SMP_IDLE_THREAD select HAS_IOPORT
Signature · 1 line
2.54.0
Matt Turner
maintainerPATCH v2 6/22 alpha: select ARCH_SUPPORTS_ATOMIC_RMW
In reply to Matt TurnerAlpha has native LL/SC instructions (LDL_L/STL_C, LDQ_L/STQ_C) that provide atomic read-modify-write capability, and already selects ARCH_HAVE_NMI_SAFE_CMPXCHG.
Selecting ARCH_SUPPORTS_ATOMIC_RMW enables MUTEX_SPIN_ON_OWNER and RWSEM_SPIN_ON_OWNER on SMP, allowing optimistic spinning on contended locks rather than immediately sleeping.
--- arch/alpha/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/alpha/Kconfig +1 -0
@@ -14,6 +14,7 @@ config ALPHA select ARCH_MODULE_NEEDS_WEAK_PER_CPU if SMP select ARCH_NO_PREEMPT select ARCH_NO_SG_CHAIN + select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_USE_CMPXCHG_LOCKREF select FORCE_PCI select PCI_DOMAINS if PCI
Signature · 1 line
2.54.0
Matt Turner
maintainerPATCH v2 7/22 alpha: select ARCH_HAS_FAST_MULTIPLIER
In reply to Matt TurnerAll Alpha CPUs have hardware integer multiply (MULL/MULQ). EV4 and EV5 implement it in microcode; EV56 and later have fast single-cycle multiply. Since no EV4 system is likely to run a modern kernel, select this unconditionally to enable multiply-based fast paths in hweight and string routines.
--- arch/alpha/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/alpha/Kconfig +1 -0
@@ -7,6 +7,7 @@ config ALPHA select ARCH_32BIT_USTAT_F_TINODE select ARCH_HAS_CURRENT_STACK_POINTER select ARCH_HAS_DMA_OPS if PCI + select ARCH_HAS_FAST_MULTIPLIER select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_UBSAN select ARCH_MIGHT_HAVE_PC_PARPORT
Signature · 1 line
2.54.0
Matt Turner
maintainerPATCH v2 8/22 alpha: select ARCH_SUPPORTS_INT128
In reply to Matt Turnergcc supports __int128 on Alpha, and the 64x64 to 128-bit multiply that the users in the scheduler and in lib/ care about maps onto mulq/umulh rather than an out-of-line libgcc helper.
Gate the select on CC_HAS_INT128 as the other 64-bit architectures do.
--- arch/alpha/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/alpha/Kconfig +1 -0
@@ -16,6 +16,7 @@ config ALPHA select ARCH_NO_PREEMPT select ARCH_NO_SG_CHAIN select ARCH_SUPPORTS_ATOMIC_RMW + select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 select ARCH_USE_CMPXCHG_LOCKREF select FORCE_PCI select PCI_DOMAINS if PCI
Signature · 1 line
2.54.0
Magnus Lindholm
maintainerRe: [PATCH v2 08/22] alpha: select ARCH_SUPPORTS_INT128
Hi Matt,
Quoted 29 lines · Matt Turner
gcc supports
__int128on Alpha, and the 64x64 to 128-bit multiply that the users in the scheduler and inlib/care about maps onto mulq/umulh rather than an out-of-line libgcc helper.Gate the select on
CC_HAS_INT128as the other 64-bit architectures do.Assisted-by Claude:claude-opus-5Signed-off-by Matt Turner <[email protected]>Tested-by Magnus Lindholm <[email protected]>Reviewed-by Magnus Lindholm <[email protected]>--- arch/alpha/Kconfig | 1 + 1 file changed, 1 insertion(+)arch/alpha/Kconfig +1
-1@@ -16,6 +16,7 @@ config ALPHA select ARCH_NO_PREEMPT select ARCH_NO_SG_CHAIN select ARCH_SUPPORTS_ATOMIC_RMW + select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 select ARCH_USE_CMPXCHG_LOCKREF select FORCE_PCI select PCI_DOMAINS if PCI --
Quoted 2 lines
2.54.0
The kernel test robot reported undefined references to __ashlti3, __ashrti3 and __lshrti3 with CONFIG_CC_OPTIMIZE_FOR_SIZE=y.
Alpha doesn't currently provide these helpers. CC_HAS_INT128 confirms support for the type, but doesn't guarantee that the generated code can link without libgcc.
I suggest dropping "alpha: select ARCH_SUPPORTS_INT128" for now and bringing it back once the required helpers are implemented and tested with size-optimized builds, including UBSAN. Removing the select eliminates the missing references in the affected objects.
There are no functional dependencies on this patch in the rest of for-next. I tested rebasing without it: the page-table-check and hugetlb patches each needed a small Kconfig context conflict resolved, keeping their own selects and omitting ARCH_SUPPORTS_INT128. The remaining commits replayed cleanly, and the resulting tree differs only by that one-line removal.
Magnus
Matt Turner
maintainerPATCH 1/1 alpha: add 128-bit shift helpers
Selecting ARCH_SUPPORTS_INT128 lets generic code shift __int128 values by a variable count. gcc open-codes such a shift when optimizing for speed, but with CONFIG_CC_OPTIMIZE_FOR_SIZE=y it calls the libgcc routines __ashlti3, __ashrti3 and __lshrti3 instead. The kernel does not link against libgcc and Alpha does not provide them, so the link fails:
alpha-linux-ld: lib/ubsan.o: in function `get_signed_val':
(.text+0x1c0): undefined reference to __ashlti3' (.text+0x1f8): undefined reference to __ashrti3'
alpha-linux-ld: kernel/time/timekeeping.o: in function `delta_to_ns_safe':
(.text+0x2ac): undefined reference to `__lshrti3'
Provide the three helpers in C, as s390 does, and export them for modules. They are built into the kernel proper rather than lib.a so the exports are present even when nothing built in references them.
The 64x64 to 128-bit multiply is always expanded inline with mulq/umulh, so no __multi3 is needed.
---
Magnus, this is an alternative to dropping the select. It applies on top of for-next (496e328c6107). If you would rather drop "alpha: select ARCH_SUPPORTS_INT128" for now, I will resend this without the Fixes tag, followed by the select, as a two-patch series.
Tested with gcc 16: defconfig plus CONFIG_CC_OPTIMIZE_FOR_SIZE=y and CONFIG_UBSAN=y builds and links (vmlinux and modules, W=1), and the helpers match the compiler's inline shifts for every count from 0 to 127 in a userspace test. Not boot tested.
arch/alpha/include/asm/asm-prototypes.h | 6 +++ arch/alpha/lib/Makefile | 2 + arch/alpha/lib/tishift.c | 70 +++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 arch/alpha/lib/tishift.c
arch/alpha/include/asm/asm-prototypes.h +6 -0
@@ -17,3 +17,9 @@ extern void __remlu(void);extern void __divqu (void );extern void __remqu (void );extern unsigned long __udiv_qrnnd (unsigned long *,unsigned long ,unsigned long ,unsigned long ); + +#ifdef CONFIG_ARCH_SUPPORTS_INT128 +extern __int128_t __ashlti3 (__int128_t a,int shift); +extern __int128_t __ashrti3 (__int128_t a,int shift); +extern __int128_t __lshrti3 (__int128_t a,int shift); +#endif
arch/alpha/lib/Makefile +2 -0
@@ -35,6 +35,8 @@ lib-y = __divqu.o __remqu.o __divlu.o __remlu.o \ callback_srm.o srm_puts.o srm_printk.o \ fls.o +obj-$(CONFIG_ARCH_SUPPORTS_INT128) += tishift.o + # The division routines are built from single source, with different defines. AFLAGS___divqu.o = -DDIV AFLAGS___remqu.o = -DREM
arch/alpha/lib/tishift.c new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
2.55.0
Re: [PATCH] alpha: add 128-bit shift helpers
Hi Matt,
Quoted 25 lines · Matt Turner
Selecting
ARCH_SUPPORTS_INT128lets generic code shift__int128values by a variable count. gcc open-codes such a shift when optimizing for speed, but withCONFIG_CC_OPTIMIZE_FOR_SIZE=yit calls the libgcc routines__ashlti3,__ashrti3and__lshrti3instead. The kernel does not link against libgcc and Alpha does not provide them, so the link fails:alpha-linux-ld:
lib/ubsan.o: in function `get_signed_val':
(.text+0x1c0): undefined reference to__ashlti3' (.text+0x1f8): undefined reference to__ashrti3'
alpha-linux-ld:kernel/time/timekeeping.o: in function `delta_to_ns_safe':
(.text+0x2ac): undefined reference to `__lshrti3'Provide the three helpers in C, as s390 does, and export them for modules. They are built into the kernel proper rather than lib.a so the exports are present even when nothing built in references them.
The 64x64 to 128-bit multiply is always expanded inline with mulq/umulh, so no
__multi3is needed.Fixes fd04433a5bf3 ("alpha: select ARCH_SUPPORTS_INT128")Reported-by kernel test robot <[email protected]>Assisted-by Claude:claude-opus-5-5Signed-off-by Matt Turner <[email protected]>
Quoted 6 lines
---
Magnus, this is an alternative to dropping the select. It applies on top of for-next (496e328c6107). If you would rather drop "alpha: selectARCH_SUPPORTS_INT128" for now, I will resend this without the Fixes tag, followed by the select, as a two-patch series.
I'll apply this on top of my for-next, no need for a separate series
Quoted 115 lines
Tested with gcc 16: defconfig plus
CONFIG_CC_OPTIMIZE_FOR_SIZE=yandCONFIG_UBSAN=ybuilds and links (vmlinux and modules, W=1), and the helpers match the compiler's inline shifts for every count from 0 to 127 in a userspace test. Not boot tested.arch/alpha/include/asm/asm-prototypes.h | 6 +++ arch/alpha/lib/Makefile | 2 + arch/alpha/lib/tishift.c | 70 +++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 arch/alpha/lib/tishift.carch/alpha/include/asm/asm-prototypes.h +6
-0@@ -17,3 +17,9 @@ extern void __remlu(void);extern void __divqu (void );extern void __remqu (void );extern unsigned long __udiv_qrnnd (unsigned long *,unsigned long ,unsigned long ,unsigned long ); + +#ifdef CONFIG_ARCH_SUPPORTS_INT128 +extern __int128_t __ashlti3 (__int128_t a,int shift); +extern __int128_t __ashrti3 (__int128_t a,int shift); +extern __int128_t __lshrti3 (__int128_t a,int shift); +#endif arch/alpha/lib/Makefile +2
-0@@ -35,6 +35,8 @@ lib-y = __divqu.o __remqu.o __divlu.o __remlu.o \ callback_srm.o srm_puts.o srm_printk.o \ fls.o +obj-$(CONFIG_ARCH_SUPPORTS_INT128) += tishift.o + # The division routines are built from single source, with different defines. AFLAGS___divqu.o = -DDIV AFLAGS___remqu.o = -DREMarch/alpha/lib/tishift.c new file +70
-1@@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* 128-bit shift helpers. +* +* gcc open-codes a variable 128-bit shift when optimizing for speed, but +* calls these libgcc routines when optimizing for size. +*/ + +#include <linux/export.h> +#include <linux/types.h> +#include <asm/asm-prototypes.h> + +union ti { +__int128_t val; +struct { +u64 low; +u64 high; + }; +}; + +__int128_t __ashlti3 (__int128_t a,int shift) +{ +union ti ti = { .val = a }; + +if (!shift) +return ti.val; +if (shift <64 ) { + ti.high = (ti.high << shift) | (ti.low >> (64 - shift)); + ti.low <<= shift; + }else { + ti.high = ti.low << (shift -64 ); + ti.low =0 ; + } +return ti.val; +} +EXPORT_SYMBOL (__ashlti3); + +__int128_t __ashrti3 (__int128_t a,int shift) +{ +union ti ti = { .val = a }; + +if (!shift) +return ti.val; +if (shift <64 ) { + ti.low = (ti.low >> shift) | (ti.high << (64 - shift)); + ti.high = (s64 )ti.high >> shift; + }else { + ti.low = (s64 )ti.high >> (shift -64 ); + ti.high = (s64 )ti.high >>63 ; + } +return ti.val; +} +EXPORT_SYMBOL (__ashrti3); + +__int128_t __lshrti3 (__int128_t a,int shift) +{ +union ti ti = { .val = a }; + +if (!shift) +return ti.val; +if (shift <64 ) { + ti.low = (ti.low >> shift) | (ti.high << (64 - shift)); + ti.high >>= shift; + }else { + ti.low = ti.high >> (shift -64 ); + ti.high =0 ; + } +return ti.val; +} +EXPORT_SYMBOL (__lshrti3); --
Quoted 2 lines
2.55.0
I build-tested this on top of the current Alpha for-next branch with CONFIG_CC_OPTIMIZE_FOR_SIZE=y and CONFIG_UBSAN=y. Both vmlinux and the configured modules built successfully, with no unresolved references to the new 128-bit shift helpers.
Re: [PATCH] alpha: add 128-bit shift helpers
In reply to Matt TurnerQuoted 12 lines · On Fri, 9 Oct 2026 22:20:39 -0400 Matt Turner <[email protected]> wrote:
Selecting
ARCH_SUPPORTS_INT128lets generic code shift__int128values by a variable count. gcc open-codes such a shift when optimizing for speed, but withCONFIG_CC_OPTIMIZE_FOR_SIZE=yit calls the libgcc routines__ashlti3,__ashrti3and__lshrti3instead. The kernel does not link against libgcc and Alpha does not provide them, so the link fails:alpha-linux-ld:
lib/ubsan.o: in function `get_signed_val':
(.text+0x1c0): undefined reference to__ashlti3' (.text+0x1f8): undefined reference to__ashrti3'
alpha-linux-ld:kernel/time/timekeeping.o: in function `delta_to_ns_safe':
(.text+0x2ac): undefined reference to `__lshrti3'
Quoted 3 lines
Provide the three helpers in C, as s390 does, and export them for modules. They are built into the kernel proper rather than lib.a so the exports are present even when nothing built in references them.
Do they need an explicit (shift &= 63)?
I've seen gcc/clang remove an explicit '&= 63' because they know the hardware instruction ignores the high bits.
But I'm not sure what happens here.
Adding it won't make much difference - unless it matters.
David
Quoted 129 lines
The 64x64 to 128-bit multiply is always expanded inline with mulq/umulh, so no
__multi3is needed.Fixes fd04433a5bf3 ("alpha: select ARCH_SUPPORTS_INT128")Reported-by kernel test robot <[email protected]>Assisted-by Claude:claude-opus-5-5Signed-off-by Matt Turner <[email protected]>---
Magnus, this is an alternative to dropping the select. It applies on top of for-next (496e328c6107). If you would rather drop "alpha: selectARCH_SUPPORTS_INT128" for now, I will resend this without the Fixes tag, followed by the select, as a two-patch series.Tested with gcc 16: defconfig plus
CONFIG_CC_OPTIMIZE_FOR_SIZE=yandCONFIG_UBSAN=ybuilds and links (vmlinux and modules, W=1), and the helpers match the compiler's inline shifts for every count from 0 to 127 in a userspace test. Not boot tested.arch/alpha/include/asm/asm-prototypes.h | 6 +++ arch/alpha/lib/Makefile | 2 + arch/alpha/lib/tishift.c | 70 +++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 arch/alpha/lib/tishift.carch/alpha/include/asm/asm-prototypes.h +6
-0@@ -17,3 +17,9 @@ extern void __remlu(void);extern void __divqu (void );extern void __remqu (void );extern unsigned long __udiv_qrnnd (unsigned long *,unsigned long ,unsigned long ,unsigned long ); + +#ifdef CONFIG_ARCH_SUPPORTS_INT128 +extern __int128_t __ashlti3 (__int128_t a,int shift); +extern __int128_t __ashrti3 (__int128_t a,int shift); +extern __int128_t __lshrti3 (__int128_t a,int shift); +#endif arch/alpha/lib/Makefile +2
-0@@ -35,6 +35,8 @@ lib-y = __divqu.o __remqu.o __divlu.o __remlu.o \ callback_srm.o srm_puts.o srm_printk.o \ fls.o +obj-$(CONFIG_ARCH_SUPPORTS_INT128) += tishift.o + # The division routines are built from single source, with different defines. AFLAGS___divqu.o = -DDIV AFLAGS___remqu.o = -DREMarch/alpha/lib/tishift.c new file +70
-0@@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* 128-bit shift helpers. +* +* gcc open-codes a variable 128-bit shift when optimizing for speed, but +* calls these libgcc routines when optimizing for size. +*/ + +#include <linux/export.h> +#include <linux/types.h> +#include <asm/asm-prototypes.h> + +union ti { +__int128_t val; +struct { +u64 low; +u64 high; + }; +}; + +__int128_t __ashlti3 (__int128_t a,int shift) +{ +union ti ti = { .val = a }; + +if (!shift) +return ti.val; +if (shift <64 ) { + ti.high = (ti.high << shift) | (ti.low >> (64 - shift)); + ti.low <<= shift; + }else { + ti.high = ti.low << (shift -64 ); + ti.low =0 ; + } +return ti.val; +} +EXPORT_SYMBOL (__ashlti3); + +__int128_t __ashrti3 (__int128_t a,int shift) +{ +union ti ti = { .val = a }; + +if (!shift) +return ti.val; +if (shift <64 ) { + ti.low = (ti.low >> shift) | (ti.high << (64 - shift)); + ti.high = (s64 )ti.high >> shift; + }else { + ti.low = (s64 )ti.high >> (shift -64 ); + ti.high = (s64 )ti.high >>63 ; + } +return ti.val; +} +EXPORT_SYMBOL (__ashrti3); + +__int128_t __lshrti3 (__int128_t a,int shift) +{ +union ti ti = { .val = a }; + +if (!shift) +return ti.val; +if (shift <64 ) { + ti.low = (ti.low >> shift) | (ti.high << (64 - shift)); + ti.high >>= shift; + }else { + ti.low = ti.high >> (shift -64 ); + ti.high =0 ; + } +return ti.val; +} +EXPORT_SYMBOL (__lshrti3);
Matt Turner
maintainerRe: [PATCH] alpha: add 128-bit shift helpers
Quoted 20 lines · David Laight
Quoted 12 lines · On Fri, 9 Oct 2026 22:20:39 -0400 Matt Turner <[email protected]> wrote:
Selecting
ARCH_SUPPORTS_INT128lets generic code shift__int128values by a variable count. gcc open-codes such a shift when optimizing for speed, but withCONFIG_CC_OPTIMIZE_FOR_SIZE=yit calls the libgcc routines__ashlti3,__ashrti3and__lshrti3instead. The kernel does not link against libgcc and Alpha does not provide them, so the link fails:alpha-linux-ld:
lib/ubsan.o: in function `get_signed_val':
(.text+0x1c0): undefined reference to__ashlti3' (.text+0x1f8): undefined reference to__ashrti3'
alpha-linux-ld:kernel/time/timekeeping.o: in function `delta_to_ns_safe':
(.text+0x2ac): undefined reference to `__lshrti3'Quoted 3 lines
Provide the three helpers in C, as s390 does, and export them for modules. They are built into the kernel proper rather than lib.a so the exports are present even when nothing built in references them.
Quoted 5 lines
Do they need an explicit (shift &= 63)?
I've seen gcc/clang remove an explicit '&= 63' because they know the hardware instruction ignores the high bits.
But I'm not sure what happens here.
Adding it won't make much difference - unless it matters.
No, I don't think so, the 64-bit shift counts are already 0..63 for any count in 0..127. The !shift check is what keeps 64 - shift from reaching 64.
gcc doesn't remove an explicit mask here, by the way. It costs an extra and per function on Alpha. Out-of-range counts give the same results as libgcc's versions, which is all the callers could expect.
Matt Turner
maintainerPATCH v2 9/22 alpha: select HAVE_ARCH_COMPILER_H
In reply to Matt TurnerAlpha already provides asm/compiler.h (wrapping uapi/asm/compiler.h) which defines architecture-specific compiler intrinsics like __kernel_cmpbge, __kernel_cttz, __kernel_ctlz, and __kernel_ctpop.
Selecting HAVE_ARCH_COMPILER_H causes linux/compiler_types.h to include asm/compiler.h, making these definitions available consistently.
--- arch/alpha/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/alpha/Kconfig +1 -0
@@ -21,6 +21,7 @@ config ALPHA select FORCE_PCI select PCI_DOMAINS if PCI select PCI_SYSCALL if PCI + select HAVE_ARCH_COMPILER_H select HAVE_ASM_MODVERSIONS select HAVE_DEBUG_KMEMLEAK select HAVE_PAGE_SIZE_8KB
Signature · 1 line
2.54.0
Matt Turner
maintainerPATCH v2 10/22 alpha: select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
In reply to Matt TurnerAlpha has a clean split between user and kernel address spaces: user space occupies 0x0000000000000000-0x000003ffffffffff (TASK_SIZE), while kernel space uses KSEG and vmalloc regions near the top of the 64-bit address space. These are strictly non-overlapping.
This enables optimizations in BPF and tracing that can skip address range checks when user and kernel pointers are distinguishable by address alone.
--- arch/alpha/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/alpha/Kconfig +1 -0
@@ -9,6 +9,7 @@ config ALPHA select ARCH_HAS_DMA_OPS if PCI select ARCH_HAS_FAST_MULTIPLIER select ARCH_HAS_GCOV_PROFILE_ALL + select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE select ARCH_HAS_UBSAN select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_MIGHT_HAVE_PC_SERIO
Signature · 1 line
2.54.0
Matt Turner
maintainerPATCH v2 11/22 alpha: add HAVE_ARCH_THREAD_STRUCT_WHITELIST support
In reply to Matt TurnerAlpha's thread_struct is empty (all per-thread state lives in thread_info), so the whitelist is trivially empty. This is more explicit than the generic fallback, which computes the full thread_struct size as copyable.
--- arch/alpha/Kconfig | 1 + arch/alpha/include/asm/processor.h | 7 +++++++ 2 files changed, 8 insertions(+)
arch/alpha/Kconfig +1 -0
@@ -44,6 +44,7 @@ config ALPHA select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_SECCOMP select HAVE_ARCH_SECCOMP_FILTER + select HAVE_ARCH_THREAD_STRUCT_WHITELIST select HAVE_ARCH_TRACEHOOK select HAVE_MOD_ARCH_SPECIFIC select LOCK_MM_AND_FIND_VMA
arch/alpha/include/asm/processor.h +7 -0
@@ -26,6 +26,13 @@struct thread_struct { };#define INIT_THREAD { } +static inline void arch_thread_struct_whitelist (unsigned long *offset, +unsigned long *size) +{ + *offset =0 ; + *size =0 ; +} +/* Do necessary setup to start up a newly executed thread. */ struct pt_regs ;extern void start_thread (struct pt_regs *,unsigned long ,unsigned long );
Signature · 1 line
2.54.0
Matt Turner
maintainerPATCH v2 12/22 alpha: add ARCH_HAS_PTE_SPECIAL support
In reply to Matt TurnerAdd _PAGE_SPECIAL using bit 19 (0x80000), which is unused in the Alpha PTE layout. This enables pte_special()/pte_mkspecial() for marking PTEs that are not backed by struct page (VDSO mappings, zero page, io_remap_pfn_range, etc.).
Include _PAGE_SPECIAL in _PAGE_CHG_MASK so it is preserved across pte_modify() calls.
Also mark Alpha as "ok" in the pte_special feature matrix.
--- Documentation/features/vm/pte_special/arch-support.txt | 2 +- arch/alpha/Kconfig | 1 + arch/alpha/include/asm/pgtable.h | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-)
Documentation/features/vm/pte_special/arch-support.txt +1 -1
@@ -6,7 +6,7 @@ ----------------------- | arch |status| ----------------------- - | alpha: | TODO | + | alpha: | ok | | arc: | ok | | arm: | ok | | arm64: | ok |
arch/alpha/Kconfig +1 -0
@@ -10,6 +10,7 @@ config ALPHA select ARCH_HAS_FAST_MULTIPLIER select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE + select ARCH_HAS_PTE_SPECIAL select ARCH_HAS_UBSAN select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_MIGHT_HAVE_PC_SERIO
arch/alpha/include/asm/pgtable.h +4 -1
@@ -73,6 +73,7 @@ struct vm_area_struct;/* .. and these are ours ... */ #define _PAGE_DIRTY 0x20000#define _PAGE_ACCESSED 0x40000 +#define _PAGE_SPECIAL 0x80000/* We borrow bit 39 to store the exclusive marker in swap PTEs. */ #define _PAGE_SWP_EXCLUSIVE 0x8000000000UL
@@ -94,7 +95,7 @@ struct vm_area_struct;#define _PFN_MASK 0xFFFFFFFF00000000UL#define _PAGE_TABLE (_PAGE_VALID | __DIRTY_BITS | __ACCESS_BITS) -#define _PAGE_CHG_MASK (_PFN_MASK | __DIRTY_BITS | __ACCESS_BITS) +#define _PAGE_CHG_MASK (_PFN_MASK | __DIRTY_BITS | __ACCESS_BITS | _PAGE_SPECIAL)/* * All the normal masks have the "page accessed" bits on, as any time they are used,
@@ -238,6 +239,8 @@ extern inline pte_t pte_mkold(pte_t pte) { pte_val(pte) &= ~(__ACCESS_BITS); retextern inline pte_t pte_mkwrite_novma (pte_t pte){pte_val (pte) &= ~_PAGE_FOW;return pte; }extern inline pte_t pte_mkdirty (pte_t pte) {pte_val (pte) |= __DIRTY_BITS;return pte; }extern inline pte_t pte_mkyoung (pte_t pte) {pte_val (pte) |= __ACCESS_BITS;return pte; } +extern inline int pte_special (pte_t pte) {return pte_val (pte) & _PAGE_SPECIAL; } +extern inline pte_t pte_mkspecial (pte_t pte) {pte_val (pte) |= _PAGE_SPECIAL;return pte; }/* * The smp_rmb() in the following functions are required to order the load of
Signature · 1 line
2.54.0
Matt Turner
maintainerPATCH v2 13/22 alpha: add ARCH_SUPPORTS_PAGE_TABLE_CHECK support
In reply to Matt TurnerAdd the page table check helpers needed for CONFIG_PAGE_TABLE_CHECK and select ARCH_SUPPORTS_PAGE_TABLE_CHECK in Kconfig.
Alpha does not support huge pages, so pmd_user_accessible_page() and pud_user_accessible_page() always return false. pte_user_accessible_page() checks for present PTEs with user read access (_PAGE_URE).
Update the helpers to the three-argument pxx_user_accessible_page(mm, addr, pxx) signature introduced by commit cf8771ca4cdb ("mm/page_table_check:
Pass mm_struct to pxx_user_accessible_page()"), matching the other architectures.
--- arch/alpha/Kconfig | 1 + arch/alpha/include/asm/pgtable.h | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+)
arch/alpha/Kconfig +1 -0
@@ -19,6 +19,7 @@ config ALPHA select ARCH_NO_SG_CHAIN select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 + select ARCH_SUPPORTS_PAGE_TABLE_CHECK select ARCH_USE_CMPXCHG_LOCKREF select FORCE_PCI select PCI_DOMAINS if PCI
arch/alpha/include/asm/pgtable.h +19 -0
@@ -232,6 +232,25 @@ extern inline void pud_clear(pud_t * pudp) { pud_val(*pudp) = 0; }extern inline int pte_write (pte_t pte) {return !(pte_val (pte) & _PAGE_FOW); }extern inline int pte_dirty (pte_t pte) {return pte_val (pte) & _PAGE_DIRTY; }extern inline int pte_young (pte_t pte) {return pte_val (pte) & _PAGE_ACCESSED; } +extern inline int pte_user (pte_t pte) {return pte_val (pte) & _PAGE_URE; } + +static inline bool pte_user_accessible_page (struct mm_struct *mm, +unsigned long addr,pte_t pte) +{ +return pte_present (pte) &&pte_user (pte); +} + +static inline bool pmd_user_accessible_page (struct mm_struct *mm, +unsigned long addr,pmd_t pmd) +{ +return false; +} + +static inline bool pud_user_accessible_page (struct mm_struct *mm, +unsigned long addr,pud_t pud) +{ +return false; +}extern inline pte_t pte_wrprotect (pte_t pte) {pte_val (pte) |= _PAGE_FOW;return pte; }extern inline pte_t pte_mkclean (pte_t pte) {pte_val (pte) &= ~(__DIRTY_BITS);return pte; }
Signature · 1 line
2.54.0
Re: [PATCH v2 13/22] alpha: add ARCH_SUPPORTS_PAGE_TABLE_CHECK support
Hi Matt,
Quoted 53 lines · Matt Turner
Add the page table check helpers needed for
CONFIG_PAGE_TABLE_CHECKand selectARCH_SUPPORTS_PAGE_TABLE_CHECKinKconfig.Alpha does not support huge pages, so
pmd_user_accessible_page()andpud_user_accessible_page()always return false.pte_user_accessible_page()checks for present PTEs with user read access (_PAGE_URE).Assisted-by Claude:claude-opus-4-6Signed-off-by Matt Turner <[email protected]>Update the helpers to the three-argument
pxx_user_accessible_page(mm, addr, pxx)signature introduced by commitcf8771ca4cdb("mm/page_table_check:
Passmm_structtopxx_user_accessible_page()"), matching the other architectures.--- arch/alpha/Kconfig | 1 + arch/alpha/include/asm/pgtable.h | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+)arch/alpha/Kconfig +1
-0@@ -19,6 +19,7 @@ config ALPHA select ARCH_NO_SG_CHAIN select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 + select ARCH_SUPPORTS_PAGE_TABLE_CHECK select ARCH_USE_CMPXCHG_LOCKREF select FORCE_PCI select PCI_DOMAINS if PCIarch/alpha/include/asm/pgtable.h +12
-0@@ -232,6 +232,25 @@ extern inline void pud_clear(pud_t * pudp) { pud_val(*pudp) = 0; }extern inline int pte_write (pte_t pte) {return !(pte_val (pte) & _PAGE_FOW); }extern inline int pte_dirty (pte_t pte) {return pte_val (pte) & _PAGE_DIRTY; }extern inline int pte_young (pte_t pte) {return pte_val (pte) & _PAGE_ACCESSED; } +extern inline int pte_user (pte_t pte) {return pte_val (pte) & _PAGE_URE; } + +static inline bool pte_user_accessible_page (struct mm_struct *mm, +unsigned long addr,pte_t pte) +{ +return pte_present (pte) &&pte_user (pte); +} + +static inline bool pmd_user_accessible_page (struct mm_struct *mm, +unsigned long addr,pmd_t pmd) +{ +return false;
arch/alpha/include/asm/pgtable.h extern inline void pud_clear(pud_t * pudp) { pud_val(*pudp) = 0; } · line 256
Quoted 10 lines
arch/alpha/include/asm/pgtable.h +7
-0+} + +static inline bool pud_user_accessible_page (struct mm_struct *mm, +unsigned long addr,pud_t pud) +{ +return false; +}extern inline pte_t pte_wrprotect (pte_t pte) {pte_val (pte) |= _PAGE_FOW;return pte; }extern inline pte_t pte_mkclean (pte_t pte) {pte_val (pte) &= ~(__DIRTY_BITS);return pte; }
Hi Matt,
I tested this on a two-CPU UP2000 with PAGE_TABLE_CHECK enabled and enforced. A userspace test exercised anonymous, private file-backed, and shared mappings, together with fork/COW, mprotect(), madvise(), PTE teardown, and refault.
Single-process and concurrent CPU-pinned runs completed successfully, with no page-table-check warnings, BUGs, or oopses.
Regards,
Magnus
Matt Turner
maintainerPATCH v2 14/22 alpha: select ARCH_HAS_DEBUG_VM_PGTABLE
In reply to Matt TurnerCONFIG_DEBUG_VM_PGTABLE runs a boot-time self test over the page table
helpers: the protection bit accessors, pte_modify(), the swap entry encoding including the exclusive marker, and, where the architecture supports them, the huge page helpers. Alpha implements everything the test needs for a three-level page table without huge page support.
Also mark Alpha as "ok" in the debug-vm-pgtable feature matrix.
--- Documentation/features/debug/debug-vm-pgtable/arch-support.txt | 2 +- arch/alpha/Kconfig | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
Documentation/features/debug/debug-vm-pgtable/arch-support.txt +1 -1
@@ -6,7 +6,7 @@ ----------------------- | arch |status| ----------------------- - | alpha: | TODO | + | alpha: | ok | | arc: | ok | | arm: | TODO | | arm64: | ok |
arch/alpha/Kconfig +1 -0
@@ -6,6 +6,7 @@ config ALPHA select HAVE_SYSCALL_TRACEPOINTS select ARCH_32BIT_USTAT_F_TINODE select ARCH_HAS_CURRENT_STACK_POINTER + select ARCH_HAS_DEBUG_VM_PGTABLE select ARCH_HAS_DMA_OPS if PCI select ARCH_HAS_FAST_MULTIPLIER select ARCH_HAS_GCOV_PROFILE_ALL
Signature · 1 line
2.54.0
Matt Turner
maintainerPATCH v2 15/22 alpha: select HAVE_GUP_FAST
In reply to Matt TurnerThe lockless GUP fast path needs the architecture to distinguish PTEs with no struct page behind them and to keep page table pages alive while a walker holds no lock. Alpha now has ARCH_HAS_PTE_SPECIAL, and it has selected MMU_GATHER_RCU_TABLE_FREE for a long time, so both requirements are met.
PTEs are a single 64-bit word on Alpha, so the lockless reads that the generic walker performs cannot tear, and no arch-specific gup_fast_permitted() or ptep_get_lockless() is needed.
--- arch/alpha/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/alpha/Kconfig +1 -0
@@ -28,6 +28,7 @@ config ALPHA select HAVE_ARCH_COMPILER_H select HAVE_ASM_MODVERSIONS select HAVE_DEBUG_KMEMLEAK + select HAVE_GUP_FAST select HAVE_PAGE_SIZE_8KB select HAVE_PCSPKR_PLATFORM select HAVE_PERF_EVENTS
Signature · 1 line
2.54.0
Matt Turner
maintainerPATCH v2 16/22 alpha: select ARCH_USE_MEMTEST
In reply to Matt TurnerWire up the generic early memtest from arch_mm_preinit(), which runs after parse_early_param() has picked up the memtest= command line option and before memblock_free_all() hands the memory to the buddy allocator. paging_init() would be the natural place, but Alpha calls it from setup_arch(), before the option is parsed, so the test would never run.
The test range starts at the first DRAM address rather than physical zero because low memory on Alpha is owned by the console and PALcode.
Tested under QEMU with memtest=4: all four patterns pass over the free memblock ranges, with no bad memory reserved.
Also add ALPHA to the memtest= parameter's architecture list.
--- Documentation/admin-guide/kernel-parameters.txt | 2 +- arch/alpha/Kconfig | 1 + arch/alpha/mm/init.c | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-)
Documentation/admin-guide/kernel-parameters.txt +1 -1
@@ -4030,7 +4030,7 @@ Kernel parameters poison checking when freeing elements back to the pool. Useful for debugging mempool corruption. - memtest= [KNL,X86,ARM,M68K,PPC,RISCV,EARLY] Enable memtest + memtest= [KNL,ALPHA,X86,ARM,M68K,PPC,RISCV,EARLY] Enable memtest Format: <integer> default : 0 <disable> Specifies the number of memtest passes to be
arch/alpha/Kconfig +1 -0
@@ -22,6 +22,7 @@ config ALPHA select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 select ARCH_SUPPORTS_PAGE_TABLE_CHECK select ARCH_USE_CMPXCHG_LOCKREF + select ARCH_USE_MEMTEST select FORCE_PCI select PCI_DOMAINS if PCI select PCI_SYSCALL if PCI
arch/alpha/mm/init.c +5 -0
@@ -226,6 +226,11 @@ void __init paging_init(void)memset (absolute_pointer (ZERO_PGE ),0 ,PAGE_SIZE ); } +void __init arch_mm_preinit (void ) +{ +early_memtest (memblock_start_of_DRAM (),PFN_PHYS (max_low_pfn)); +} +#if defined(CONFIG_ALPHA_GENERIC ) || defined(CONFIG_ALPHA_SRM )void srm_paging_stop (void )
Signature · 1 line
2.54.0
Matt Turner
maintainerPATCH v2 17/22 alpha: select SYSCTL_EXCEPTION_TRACE
In reply to Matt TurnerReport unhandled user faults the way other architectures do, and hook up the debug.exception-trace sysctl that controls the reporting.
The message gives the faulting address, the PC and the user stack pointer, and is rate limited.
--- arch/alpha/Kconfig | 1 + arch/alpha/mm/fault.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+)
arch/alpha/Kconfig +1 -0
@@ -61,6 +61,7 @@ config ALPHA select MMU_GATHER_NO_RANGE select MMU_GATHER_RCU_TABLE_FREE select SPARSEMEM_EXTREME if SPARSEMEM + select SYSCTL_EXCEPTION_TRACE select ZONE_DMA select TRACE_IRQFLAGS_SUPPORT select ARCH_WANT_FRAME_POINTERS
arch/alpha/mm/fault.c +29 -0
@@ -27,8 +27,32 @@#include <linux/uaccess.h> #include <linux/perf_event.h> +#include <asm/pal.h> +extern void die_if_kernel (char *,struct pt_regs *,long ,unsigned long *); +int show_unhandled_signals =1 ; + +static void +show_signal_msg (struct pt_regs *regs,unsigned long address,int signo, +const char *desc) +{ +const char *level; + +if (!show_unhandled_signals || !unhandled_signal (current, signo)) +return ; +if (!printk_ratelimit ()) +return ; + +/* Losing init is fatal, so shout about it. */ + level =task_pid_nr (current) >1 ?KERN_INFO :KERN_EMERG ; + +printk ("%s%s[%d]: %s at %016lx pc %016lx sp %016lx\n" , + level, current->comm,task_pid_nr (current), desc, + address, regs->pc,rdusp ()); +print_vma_addr (KERN_CONT " in " , regs->pc); +printk (KERN_CONT "\n" ); +}/* * Force a new ASN for a task.
@@ -217,12 +241,17 @@ do_page_fault(unsigned long address, unsigned long mmcsr,mmap_read_unlock (mm);/* Send a sigbus, regardless of whether we were in kernel or user mode. */ +if (user_mode (regs)) +show_signal_msg (regs, address,SIGBUS ,"bus error" );force_sig_fault (SIGBUS ,BUS_ADRERR , (void __user *) address);if (!user_mode (regs)) goto no_context;return ; do_sigsegv: +show_signal_msg (regs, address,SIGSEGV , + si_code ==SEGV_MAPERR ?"unmapped access" + :"access violation" );force_sig_fault (SIGSEGV , si_code, (void __user *) address);return ;
Signature · 1 line
2.54.0
Matt Turner
maintainerPATCH v2 18/22 alpha: discard .eh_frame and the relocation sections
In reply to Matt Turnergcc emits .eh_frame for Alpha even though the kernel builds with -fno-asynchronous-unwind-tables, and nothing in the kernel consumes it:
the stack trace code scans the stack for text addresses rather than unwinding DWARF. It was allocated in the loaded image, so dropping it shrinks vmlinux by about 1.1MB for a Marvel SMP configuration.
The .rela* sections are equally useless, as the kernel image is not relocatable. The linker was already dropping their contents.
Both were being placed as orphan sections, which is what drew attention to them.
--- arch/alpha/kernel/vmlinux.lds.S | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/alpha/kernel/vmlinux.lds.S +11 -0
@@ -76,5 +76,16 @@ SECTIONS MODINFO ELF_DETAILS + /* + * gcc emits .eh_frame for Alpha even with + * -fno-asynchronous-unwind-tables, and the kernel has no DWARF + * unwinder to consume it. The relocation sections are likewise + * useless as the kernel image is not relocatable. + */ + /DISCARD/ : { + *(.eh_frame) + *(.rela .rela*) + } + DISCARDS }
Signature · 1 line
2.54.0
Matt Turner
maintainerPATCH v2 19/22 alpha: select ARCH_WANT_LD_ORPHAN_WARN
In reply to Matt TurnerWith .eh_frame and the relocation sections now placed explicitly, an Alpha kernel links with no orphan sections left, so ask the linker to warn if new ones appear.
--- arch/alpha/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/alpha/Kconfig +1 -0
@@ -40,6 +40,7 @@ config ALPHA select AUTO_IRQ_AFFINITY if SMP select GENERIC_IRQ_SHOW select ARCH_WANT_IPC_PARSE_VERSION + select ARCH_WANT_LD_ORPHAN_WARN select ARCH_HAVE_NMI_SAFE_CMPXCHG select AUDIT_ARCH select EDAC_SUPPORT
Signature · 1 line
2.54.0
Matt Turner
maintainerPATCH v2 20/22 alpha: select ARCH_WANT_IRQS_OFF_ACTIVATE_MM
In reply to Matt Turneractivate_mm() on Alpha calls __load_new_mm_context() which assigns a new ASID and invokes PALcode swpctx. On SMP, an interrupt arriving between the ASID update and the page table switch could see inconsistent state. Ensure activate_mm() is called with interrupts disabled during exec.
--- arch/alpha/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/alpha/Kconfig +1 -0
@@ -39,6 +39,7 @@ config ALPHA select GENERIC_PCI_IOMAP select AUTO_IRQ_AFFINITY if SMP select GENERIC_IRQ_SHOW + select ARCH_WANT_IRQS_OFF_ACTIVATE_MM select ARCH_WANT_IPC_PARSE_VERSION select ARCH_WANT_LD_ORPHAN_WARN select ARCH_HAVE_NMI_SAFE_CMPXCHG
Signature · 1 line
2.54.0
Matt Turner
maintainerPATCH v2 21/22 alpha: add HAVE_PERF_REGS and HAVE_PERF_USER_STACK_DUMP support
In reply to Matt TurnerImplement the perf register sampling interface for Alpha. This enables perf to capture register state and user stack dumps with samples, supporting --call-graph dwarf.
The perf_regs enum exposes the registers available in pt_regs: r0-r8, r16-r28, gp, pc, and ps. Registers r9-r15 are callee-saved and live in switch_stack, not pt_regs, so they are not included.
A switch statement maps perf register indices to pt_regs fields since Alpha's pt_regs layout is non-contiguous (unlike architectures where direct array indexing works).
--- arch/alpha/Kconfig | 2 + arch/alpha/include/asm/perf_regs.h | 7 +++ arch/alpha/include/uapi/asm/perf_regs.h | 34 +++++++++++++ arch/alpha/kernel/Makefile | 1 + arch/alpha/kernel/perf_regs.c | 86 +++++++++++++++++++++++++++++++++ 5 files changed, 130 insertions(+)
arch/alpha/Kconfig +2 -0
@@ -33,6 +33,8 @@ config ALPHA select HAVE_PAGE_SIZE_8KB select HAVE_PCSPKR_PLATFORM select HAVE_PERF_EVENTS + select HAVE_PERF_REGS + select HAVE_PERF_USER_STACK_DUMP select NEED_DMA_MAP_STATE select NEED_SG_DMA_LENGTH select GENERIC_IRQ_PROBE
arch/alpha/include/asm/perf_regs.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_ALPHA_PERF_REGS_H +#define _ASM_ALPHA_PERF_REGS_H + +#include <uapi/asm/perf_regs.h> + +#endif /* _ASM_ALPHA_PERF_REGS_H */
arch/alpha/include/uapi/asm/perf_regs.h new file +34 -0
@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _UAPI_ASM_ALPHA_PERF_REGS_H +#define _UAPI_ASM_ALPHA_PERF_REGS_H + +enum perf_event_alpha_regs { +PERF_REG_ALPHA_R0 , +PERF_REG_ALPHA_R1 , +PERF_REG_ALPHA_R2 , +PERF_REG_ALPHA_R3 , +PERF_REG_ALPHA_R4 , +PERF_REG_ALPHA_R5 , +PERF_REG_ALPHA_R6 , +PERF_REG_ALPHA_R7 , +PERF_REG_ALPHA_R8 , +PERF_REG_ALPHA_R16 , +PERF_REG_ALPHA_R17 , +PERF_REG_ALPHA_R18 , +PERF_REG_ALPHA_R19 , +PERF_REG_ALPHA_R20 , +PERF_REG_ALPHA_R21 , +PERF_REG_ALPHA_R22 , +PERF_REG_ALPHA_R23 , +PERF_REG_ALPHA_R24 , +PERF_REG_ALPHA_R25 , +PERF_REG_ALPHA_R26 , +PERF_REG_ALPHA_R27 , +PERF_REG_ALPHA_R28 , +PERF_REG_ALPHA_GP , +PERF_REG_ALPHA_PC , +PERF_REG_ALPHA_PS , +PERF_REG_ALPHA_MAX , +}; + +#endif /* _UAPI_ASM_ALPHA_PERF_REGS_H */
arch/alpha/kernel/Makefile +1 -0
@@ -18,6 +18,7 @@ obj-$(CONFIG_PCI) += pci.o pci_iommu.o pci-sysfs.o obj-$(CONFIG_SRM_ENV) += srm_env.o obj-$(CONFIG_MODULES) += module.o obj-$(CONFIG_PERF_EVENTS) += perf_event.o +obj-$(CONFIG_HAVE_PERF_REGS) += perf_regs.o obj-$(CONFIG_RTC_DRV_ALPHA) += rtc.o obj-$(CONFIG_AUDIT) += audit.o
arch/alpha/kernel/perf_regs.c new file +86 -0
86 lines not on this page · raw message
Signature · 1 line
2.54.0
Magnus Lindholm
maintainerRe: [PATCH v2 21/22] alpha: add HAVE_PERF_REGS and HAVE_PERF_USER_STACK_DUMP support
Hi Matt,
Quoted 9 lines · Matt Turner
Implement the perf register sampling interface for Alpha. This enables perf to capture register state and user stack dumps with samples, supporting --call-graph dwarf.
The
perf_regsenum exposes the registers available inpt_regs: r0-r8, r16-r28, gp, pc, and ps. Registers r9-r15 are callee-saved and live inswitch_stack, notpt_regs, so they are not included.
Quoted 6 lines
A switch statement maps perf register indices to
pt_regsfields since Alpha'spt_regslayout is non-contiguous (unlike architectures where direct array indexing works).Assisted-by Claude:claude-opus-4-6Signed-off-by Matt Turner <[email protected]>
I think this patch still needs kernel-side work in addition to the matching tools/perf support.
HAVE_PERF_USER_STACK_DUMP makes the generic perf code obtain the user stack pointer through user_stack_pointer(regs), which on Alpha returns regs->usp. However, the interrupt SAVE_ALL path does not initialize that field, and do_entInt() does not snapshot USP. A profiling interrupt taken from user mode may therefore attempt to copy the stack from a stale or uninitialized address.
The proposed perf register ABI also does not include SP. A DWARF unwinder needs both the sampled stack contents and the corresponding stack pointer, so this cannot be completed solely by a later tools/perf patch.
Would it make sense to drop this patch from the current series and submit the perf support separately, including USP capture on interrupt entry, SP in the kernel perf register ABI, and the matching tools/perf support? That would allow the rest of this series to proceed without waiting for the perf interface to be completed.
Regards,
Magnus
Matt Turner
maintainerRe: [PATCH v2 21/22] alpha: add HAVE_PERF_REGS and HAVE_PERF_USER_STACK_DUMP support
Quoted 35 lines · Magnus Lindholm
Hi Matt,
Quoted 9 lines · Matt Turner
Implement the perf register sampling interface for Alpha. This enables perf to capture register state and user stack dumps with samples, supporting --call-graph dwarf.
The
perf_regsenum exposes the registers available inpt_regs: r0-r8, r16-r28, gp, pc, and ps. Registers r9-r15 are callee-saved and live inswitch_stack, notpt_regs, so they are not included.Quoted 6 lines
A switch statement maps perf register indices to
pt_regsfields since Alpha'spt_regslayout is non-contiguous (unlike architectures where direct array indexing works).Assisted-by Claude:claude-opus-4-6Signed-off-by Matt Turner <[email protected]>I think this patch still needs kernel-side work in addition to the matching
tools/perfsupport.
HAVE_PERF_USER_STACK_DUMPmakes the generic perf code obtain the user stack pointer throughuser_stack_pointer(regs), which on Alpha returnsregs->usp. However, the interruptSAVE_ALLpath does not initialize that field, anddo_entInt()does not snapshot USP. A profiling interrupt taken from user mode may therefore attempt to copy the stack from a stale or uninitialized address.The proposed perf register ABI also does not include SP. A DWARF unwinder needs both the sampled stack contents and the corresponding stack pointer, so this cannot be completed solely by a later
tools/perfpatch.
Quoted 5 lines
Would it make sense to drop this patch from the current series and submit the perf support separately, including USP capture on interrupt entry, SP in the kernel perf register ABI, and the matching
tools/perfsupport? That would allow the rest of this series to proceed without waiting for the perf interface to be completed.
Yes, let's drop this patch from the series.
Matt Turner
maintainerPATCH v2 22/22 alpha: select SPARSE_IRQ
In reply to Matt TurnerNR_IRQS on Alpha is sized for the largest configuration each platform supports, and for Marvel that is 32 PIDs, or 32784 interrupts. Without SPARSE_IRQ that becomes a static irq_desc[] array of 12.6 MB in .data, carried by every Marvel and every generic kernel regardless of how many interrupts the machine actually has. A real ES47 uses 87 of them.
That is not just wasted memory, it constrains where the kernel can be loaded. The image links at a fixed 0xfffffc0001010000, just above the console's low memory reservation, and with memory striping enabled the console leaves only about 16 MB of usable low memory before the rest is relocated to an interleaved aperture. A 12.6 MB array of mostly unused interrupt descriptors is the difference between fitting and not.
Alpha already goes through irq_to_desc() rather than indexing irq_desc[] directly, so nothing stands in the way. The platforms do wire up their interrupts by number, though, which needs the descriptors to exist by then, so provide arch_probe_nr_irqs() returning the machine vector's count instead of taking the NR_IRQS_LEGACY default. Without it every interrupt above 15 would have no descriptor and the handler setup would be silently dropped.
Tested on an ES47 (Marvel, 2 EV7z): boots with all device interrupts working, and .data drops by 12.6 MB, from 15.7 MB to 3.1 MB.
--- arch/alpha/Kconfig | 1 + arch/alpha/kernel/irq_alpha.c | 13 +++++++++++++ 2 files changed, 14 insertions(+)
arch/alpha/Kconfig +1 -0
@@ -64,6 +64,7 @@ config ALPHA select CPU_NO_EFFICIENT_FFS if !ALPHA_EV67 select MMU_GATHER_NO_RANGE select MMU_GATHER_RCU_TABLE_FREE + select SPARSE_IRQ select SPARSEMEM_EXTREME if SPARSEMEM select SYSCTL_EXCEPTION_TRACE select ZONE_DMA
arch/alpha/kernel/irq_alpha.c +13 -0
@@ -152,6 +152,19 @@ common_init_isa_dma(void)outb (0 ,DMA2_CLR_MASK_REG ); } +/* +* The platforms wire up their interrupts by calling into the generic irq +* code with fixed interrupt numbers, so the descriptors have to exist by +* then. Preallocate the machine's full complement rather than take the +* NR_IRQS_LEGACY default, which would leave everything above IRQ 15 +* without a descriptor and silently drop the handler setup. +*/ +int __init +arch_probe_nr_irqs (void ) +{ +return alpha_mv.nr_irqs; +} +void __init init_IRQ (void ) {
Signature · 1 line
2.54.0
Magnus Lindholm
maintainerHi Matt,
Quoted 106 lines · Matt Turner
This is v2 of "alpha: catch up on architecture
Kconfigoptions"
(https://lore.kernel.org/linux-alpha/CAEdQ38FoUPzftf9vDcJK8L38j+cDzTyxdL+Fj-3oAQHmmOxaOA@mail.gmail.com/T/#t),
addressing Magnus Lindholm's review and rebased onto v7.3-rc1 plus hisGENERIC_ENTRYv5
(https://lore.kernel.org/linux-alpha/[email protected]/T/#t),
per his request.Changes since v1:
- Dropped "fix
arch_irqs_disabled_flags()to treat any raised IPL as disabled". Magnus's objection was right: per the Architecture Reference Manual an intermediate IPL only masks interrupts at or below that level, anddo_entInt()already drives PS.IPL toIPL_MAXitself before reporting hardirq state to lockdep, so the originalarch_irqs_disabled_flags()was correct as it stood.- Dropped "add
TRACE_IRQFLAGS_SUPPORT". It conflicted withGENERIC_ENTRYexactly where Magnus expected: the entInt, entSys, andrestore_allinstrumentation it added is now redundant with the hardirq-state transitionsGENERIC_ENTRYperforms on those paths itself. I want to work out separately, and with real testing, whether the remaining synchronous-exception entry points need anything at all here, rather than resend a patch I can't fully justify.- Fixed "add
ARCH_SUPPORTS_PAGE_TABLE_CHECKsupport", which no longer built against v7.3-rc1: commitcf8771ca4cdb("mm/page_table_check:
Passmm_structtopxx_user_accessible_page()") changed the callback signature, and Alpha's copy is now updated to match.- Added the Signed-off-by that was missing from "select
SPARSE_IRQ".- Folded the corresponding arch-support.txt updates into "select
ARCH_HAS_GCOV_PROFILE_ALL", "selectHAVE_DEBUG_KMEMLEAK", "addARCH_HAS_PTE_SPECIALsupport", and "selectARCH_HAS_DEBUG_VM_PGTABLE", and added ALPHA to the memtest= parameter list in kernel-parameters.txt.- Did not touch "add
HAVE_PERF_REGSandHAVE_PERF_USER_STACK_DUMPsupport" beyond rebasing it. Magnus found real gaps there (tools/perfhas no Alpha register mask, andregs->uspisn't snapshotted on the interrupt path), so I've left the corresponding feature matrices alone rather than claim it's done.- Picked up Tested-by/Reviewed-by from Magnus on the patches he gave them for.
Not yet addressed: whether
do_entInt()should own hardirq context for both interrupt paths and drop the irq_enter()/irq_exit() pair fromhandle_irq(), which Magnus asked about on "enter hardirq context before looking up the irq descriptor". No code change there yet; I'll follow up on that thread separately.Tested by cross-building with alpha-unknown-linux-gnu-gcc against defconfig and, for the page-table-check fix, against a config with
CONFIG_PAGE_TABLE_CHECK=y. Boot tested on an AlphaServer ES47.Also available at:
git://git.kernel.org/pub/scm/linux/kernel/git/mattst88/alpha.gitarch-kconfig-options-v2Signed-off-by Matt Turner <[email protected]>---
Matt Turner (22):
alpha: enter hardirq context before looking up the irq descriptor
alpha: selectARCH_HAS_UBSAN
alpha: selectARCH_HAS_GCOV_PROFILE_ALL
alpha: selectHAVE_DEBUG_KMEMLEAK
alpha: selectEDAC_SUPPORT
alpha: selectARCH_SUPPORTS_ATOMIC_RMW
alpha: selectARCH_HAS_FAST_MULTIPLIER
alpha: selectARCH_SUPPORTS_INT128
alpha: selectHAVE_ARCH_COMPILER_H
alpha: selectARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
alpha: addHAVE_ARCH_THREAD_STRUCT_WHITELISTsupport
alpha: addARCH_HAS_PTE_SPECIALsupport
alpha: addARCH_SUPPORTS_PAGE_TABLE_CHECKsupport
alpha: selectARCH_HAS_DEBUG_VM_PGTABLE
alpha: selectHAVE_GUP_FAST
alpha: selectARCH_USE_MEMTEST
alpha: selectSYSCTL_EXCEPTION_TRACE
alpha: discard .eh_frame and the relocation sections
alpha: selectARCH_WANT_LD_ORPHAN_WARN
alpha: selectARCH_WANT_IRQS_OFF_ACTIVATE_MM
alpha: addHAVE_PERF_REGSandHAVE_PERF_USER_STACK_DUMPsupport
alpha: selectSPARSE_IRQDocumentation/admin-guide/kernel-parameters.txt | 2 +- .../debug/debug-vm-pgtable/arch-support.txt | 2 +- .../debug/gcov-profile-all/arch-support.txt | 2 +- .../features/debug/kmemleak/arch-support.txt | 2 +- .../features/vm/pte_special/arch-support.txt | 2 +- arch/alpha/Kconfig | 21 ++++++ arch/alpha/include/asm/perf_regs.h | 7 ++ arch/alpha/include/asm/pgtable.h | 24 +++++- arch/alpha/include/asm/processor.h | 7 ++ arch/alpha/include/uapi/asm/perf_regs.h | 34 +++++++++ arch/alpha/kernel/Makefile | 1 + arch/alpha/kernel/irq.c | 9 ++- arch/alpha/kernel/irq_alpha.c | 13 ++++ arch/alpha/kernel/perf_regs.c | 86 ++++++++++++++++++++++ arch/alpha/kernel/vmlinux.lds.S | 11 +++ arch/alpha/mm/fault.c | 29 ++++++++ arch/alpha/mm/init.c | 5 ++ 17 files changed, 248 insertions(+), 9 deletions(-)
Quoted 8 lines
---
base-commit:f321329c1b70835e6b0807fddac6d4117e5604fc
change-id: 20260904-arch-kconfig-options-v2-8efa959ffcbdBest regards,
--
Matt Turner <[email protected]>
Overall, nice work with this series!
I noticed that patches 3, 4, 12, 13, 14, and 16 contain additional prose between your Signed-off-by and the --- separator. git mailinfo includes this prose in the commit message, so it separates your sign-off from the final trailer block.
These changes are already documented in the cover letter's changes-since-v1 section, so I think the extra paragraphs can simply be removed. If any are intended to remain in the permanent commit message, they should be moved above the trailer block instead.
Regards,
Magnus