Re: [PATCH] [RFC] ubsan: turn off UBSAN_ALIGNMENT on s390

From: Heiko Carstens

Date: Fri May 15 2026 - 13:13:11 EST


On Fri, May 15, 2026 at 11:19:54AM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@xxxxxxxx>
>
> Testing randconfig builds on s390 with gcc-15, I came across a number of
> seemingly unrelated build failures that ended up all being caused
> by the -fsanitize=alignment option:
>
> s390-linux-ld: kernel/sched/build_policy.o: in function `thread_group_cputime':
> include/linux/seqlock.h:1286:(.text+0x1f738): undefined reference to `__scoped_seqlock_bug'

Does this only happen with __scoped_seqlock_bug()?
I just enabled UBSAN_ALIGNMENT, and with gcc-16 I can see this too.

> What I observe here is a huge increase in generated calls to
> __ubsan_handle_type_mismatch_v1() that ends up thowing off a number of
> compiler optimizations that the kernel relies on.
>
> I have not been able to figure out why this happens on s390 but not arm64,
> arm or x86, if other toolchain versions are affected by the same thing,
> and if this is a problem in gcc or in the kernel itself, e.g. some
> variable being identified as unaligned when it should be aligned.
>
> This clearly needs more investigation to figure out properly what is
> going on, but turning it off is currently required for randconfig testing.
...
> ---
> lib/Kconfig.ubsan | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/lib/Kconfig.ubsan b/lib/Kconfig.ubsan
> index 1ecaae7064d2..3fc03a6b5af4 100644
> --- a/lib/Kconfig.ubsan
> +++ b/lib/Kconfig.ubsan
> @@ -152,6 +152,7 @@ config UBSAN_ENUM
>
> config UBSAN_ALIGNMENT
> bool "Perform checking for misaligned pointer usage"
> + depends on !S390 || BROKEN

Wouldn't it be more appropriate to extend the ifdef at __scoped_seqlock_bug()
which emits an empty function for exactly this reason for some gcc versions
and kernel configs?

That is: add CONFIG_UBSAN_ALIGNMENT to the list (copy-pasted - white space
damage below)?

diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h
index 5a40252b8334..18affa4d21a6 100644
--- a/include/linux/seqlock.h
+++ b/include/linux/seqlock.h
@@ -1259,7 +1259,7 @@ 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()