seqlock: Allow UBSAN_ALIGNMENT to fail optimizing
Subsystems (2)
Heiko Carstens
maintainerPATCH 1/1 seqlock: Allow UBSAN_ALIGNMENT to fail optimizing
With gcc-15 and gcc-16 with UBSAN_ALIGNMENT enabled the compiler fails to inline and optimize __scoped_seqlock_bug() away on s390:
s390x-16.1.0-ld: kernel/sched/build_policy.o: in function `__scoped_seqlock_next':
/.../seqlock.h:1286:(.text+0x22030): undefined reference to `__scoped_seqlock_bug'
Fix this by adding UBSAN_ALIGNMENT to the list of config options where a not inlined empty __scoped_seqlock_bug() is allowed.
--- include/linux/seqlock.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
include/linux/seqlock.h +4 -3
@@ -1259,14 +1259,15 @@ static __always_inline void __scoped_seqlock_cleanup(struct ss_tmp *sst)extern void __scoped_seqlock_invalid_target (void ); -#if (defined(CONFIG_CC_IS_GCC ) &&CONFIG_GCC_VERSION <90000 ) || defined(CONFIG_KASAN ) +#if (defined(CONFIG_CC_IS_GCC ) &&CONFIG_GCC_VERSION <90000 ) || \ + defined(CONFIG_KASAN ) || defined(CONFIG_UBSAN_ALIGNMENT )/* * For some reason some GCC-8 architectures (nios2, alpha) have trouble * determining that the ss_done state is impossible in __scoped_seqlock_next() * below. * -* Similarly KASAN is known to confuse compilers enough to break this. But we -* don't care about code quality for KASAN builds anyway. +* Similarly KASAN and UBSAN_ALIGNMENT are known to confuse compilers enough +* to break this. But we don't care about code quality for such builds anyway. */ static inline void __scoped_seqlock_bug (void ) { }#else
Signature · 1 line
2.51.0
Quoted 2 lines · Heiko Carstens
With gcc-15 and gcc-16 with
UBSAN_ALIGNMENTenabled the compiler fails to inline and optimize__scoped_seqlock_bug()away on s390:
technically
s/on s390//
since I have been able to reproduce the problem across architectures now.
Quoted 11 lines
s390x-16.1.0-ld:
kernel/sched/build_policy.o: in function `__scoped_seqlock_next':
/.../seqlock.h:1286:(.text+0x22030): undefined reference to `__scoped_seqlock_bug'Fix this by adding
UBSAN_ALIGNMENTto the list of config options where a not inlined empty__scoped_seqlock_bug()is allowed.Reported-by Arnd Bergmann <[email protected]>Signed-off-by Heiko Carstens <[email protected]>
I was about to send the same patch.
Arnd
The following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 43a037d4fa6d7e7f9437e069f857a5e06eb2dff7 Gitweb: https://git.kernel.org/tip/43a037d4fa6d7e7f9437e069f857a5e06eb2dff7 Author: Heiko Carstens <[email protected]> AuthorDate: Tue, 19 May 2026 13:03:15 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 19 May 2026 13:49:01 +02:00
seqlock: Allow UBSAN_ALIGNMENT to fail optimizing
With gcc-15 and gcc-16 with UBSAN_ALIGNMENT enabled the compiler fails to inline and optimize __scoped_seqlock_bug() away on s390:
s390x-16.1.0-ld: kernel/sched/build_policy.o: in function `__scoped_seqlock_next':
/.../seqlock.h:1286:(.text+0x22030): undefined reference to `__scoped_seqlock_bug'
Fix this by adding UBSAN_ALIGNMENT to the list of config options where a not inlined empty __scoped_seqlock_bug() is allowed.
--- include/linux/seqlock.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
include/linux/seqlock.h +4 -3
@@ -1259,14 +1259,15 @@ static __always_inline void __scoped_seqlock_cleanup(struct ss_tmp *sst)extern void __scoped_seqlock_invalid_target (void ); -#if (defined(CONFIG_CC_IS_GCC ) &&CONFIG_GCC_VERSION <90000 ) || defined(CONFIG_KASAN ) +#if (defined(CONFIG_CC_IS_GCC ) &&CONFIG_GCC_VERSION <90000 ) || \ + defined(CONFIG_KASAN ) || defined(CONFIG_UBSAN_ALIGNMENT )/* * For some reason some GCC-8 architectures (nios2, alpha) have trouble * determining that the ss_done state is impossible in __scoped_seqlock_next() * below. * -* Similarly KASAN is known to confuse compilers enough to break this. But we -* don't care about code quality for KASAN builds anyway. +* Similarly KASAN and UBSAN_ALIGNMENT are known to confuse compilers enough +* to break this. But we don't care about code quality for such builds anyway. */ static inline void __scoped_seqlock_bug (void ) { }#else
The following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 88331c4ec23a28c1006ec532fa64763d4c695e90 Gitweb: https://git.kernel.org/tip/88331c4ec23a28c1006ec532fa64763d4c695e90 Author: Heiko Carstens <[email protected]> AuthorDate: Tue, 19 May 2026 13:03:15 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Thu, 28 May 2026 12:23:22 +02:00
seqlock: Allow UBSAN_ALIGNMENT to fail optimizing
With gcc-15 and gcc-16 with UBSAN_ALIGNMENT enabled the compiler fails to inline and optimize __scoped_seqlock_bug() away on s390:
s390x-16.1.0-ld: kernel/sched/build_policy.o: in function `__scoped_seqlock_next':
/.../seqlock.h:1286:(.text+0x22030): undefined reference to `__scoped_seqlock_bug'
Fix this by adding UBSAN_ALIGNMENT to the list of config options where a not inlined empty __scoped_seqlock_bug() is allowed.
--- include/linux/seqlock.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
include/linux/seqlock.h +4 -3
@@ -1259,14 +1259,15 @@ static __always_inline void __scoped_seqlock_cleanup(struct ss_tmp *sst)extern void __scoped_seqlock_invalid_target (void ); -#if (defined(CONFIG_CC_IS_GCC ) &&CONFIG_GCC_VERSION <90000 ) || defined(CONFIG_KASAN ) +#if (defined(CONFIG_CC_IS_GCC ) &&CONFIG_GCC_VERSION <90000 ) || \ + defined(CONFIG_KASAN ) || defined(CONFIG_UBSAN_ALIGNMENT )/* * For some reason some GCC-8 architectures (nios2, alpha) have trouble * determining that the ss_done state is impossible in __scoped_seqlock_next() * below. * -* Similarly KASAN is known to confuse compilers enough to break this. But we -* don't care about code quality for KASAN builds anyway. +* Similarly KASAN and UBSAN_ALIGNMENT are known to confuse compilers enough +* to break this. But we don't care about code quality for such builds anyway. */ static inline void __scoped_seqlock_bug (void ) { }#else