Re: [RFC v2 2/3] atomic: Specify alignment for atomic_t and atomic64_t
From: Peter Zijlstra
Date: Mon Oct 06 2025 - 05:38:05 EST
On Tue, Sep 30, 2025 at 08:35:55AM +0200, Arnd Bergmann wrote:
> Since there is nothing telling the compiler that
> the 'old' argument to atomic*_try_cmpcxchg() needs to
> be naturally aligned, maybe that check should be changed
> to only test for the ABI-guaranteed alignment? I think
> that would still be needed on x86-32.
>
> Arnd
>
> diff --git a/include/linux/atomic/atomic-instrumented.h b/include/linux/atomic/atomic-instrumented.h
> index 9409a6ddf3e0..e57763a889bd 100644
> --- a/include/linux/atomic/atomic-instrumented.h
> +++ b/include/linux/atomic/atomic-instrumented.h
> @@ -1276,7 +1276,7 @@ atomic_try_cmpxchg(atomic_t *v, int *old, int new)
> {
> kcsan_mb();
> instrument_atomic_read_write(v, sizeof(*v));
> - instrument_atomic_read_write(old, sizeof(*old));
> + instrument_atomic_read_write(old, alignof(*old));
> return raw_atomic_try_cmpxchg(v, old, new);
> }
That's wrong. The argument there really is size, it tells KASAN how wide
the access is.
Arguably we could switch old to instrument_read_write() since the target
is not actually an atomic.