Re: [RFC v2 3/3] atomic: Add alignment check to instrumented atomic operations

From: Finn Thain

Date: Mon Sep 15 2025 - 20:16:26 EST



On Mon, 15 Sep 2025, Arnd Bergmann wrote:

> On Mon, Sep 15, 2025, at 12:37, Finn Thain wrote:
> > On Mon, 15 Sep 2025, Peter Zijlstra wrote:
> >>
> >> > When you do atomic operations on atomic_t or atomic64_t, (sizeof(long)
> >> > - 1) probably doesn't make much sense. But atomic operations get used on
> >> > scalar types (aside from atomic_t and atomic64_t) that don't have natural
> >> > alignment. Please refer to the other thread about this:
> >> > https://lore.kernel.org/all/ed1e0896-fd85-5101-e136-e4a5a37ca5ff@xxxxxxxxxxxxxx/
> >>
> >> Perhaps set ARCH_SLAB_MINALIGN ?
> >>
> >
> > That's not going to help much. The 850 byte offset of task_works into
> > struct task_struct and the 418 byte offset of exit_state in struct
> > task_struct are already misaligned.
>
> Has there been any progress on building m68k kernels with -mint-align?

Not that I know of.

> IIRC there are only a small number of uapi structures that need
> __packed annotations to maintain the existing syscall ABI.
>

Packing uapi structures (and adopting -malign-int) sounds easier than the
alternative, which might be to align certain internal kernel struct
members, on a case-by-case basis, where doing so could be shown to improve
performance on some architecture or other (while keeping -mno-align-int).

Well, it's easy to find all the structs that belong to the uapi, but it's
not easy to find all the internal kernel structs that describe MMIO
registers. For -malign-int, both kinds of structs are a problem.

If better performance is to be had, my guess is that aligning atomic_t
will get 80% of it (just an appeal to the Pareto principle, FWIW...)