[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250915080600.GT3419281@noisy.programming.kicks-ass.net>
Date: Mon, 15 Sep 2025 10:06:00 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Arnd Bergmann <arnd@...db.de>
Cc: Finn Thain <fthain@...ux-m68k.org>, Will Deacon <will@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Boqun Feng <boqun.feng@...il.com>, Jonathan Corbet <corbet@....net>,
Mark Rutland <mark.rutland@....com>, linux-kernel@...r.kernel.org,
Linux-Arch <linux-arch@...r.kernel.org>,
Geert Uytterhoeven <geert@...ux-m68k.org>,
linux-m68k@...r.kernel.org, Lance Yang <lance.yang@...ux.dev>
Subject: Re: [RFC v2 2/3] atomic: Specify alignment for atomic_t and
atomic64_t
On Mon, Sep 15, 2025 at 09:35:08AM +0200, Arnd Bergmann wrote:
> On Sun, Sep 14, 2025, at 02:45, Finn Thain wrote:
> > index 100d24b02e52..7ae82ac17645 100644
> > --- a/include/asm-generic/atomic64.h
> > +++ b/include/asm-generic/atomic64.h
> > @@ -10,7 +10,7 @@
> > #include <linux/types.h>
> >
> > typedef struct {
> > - s64 counter;
> > + s64 counter __aligned(sizeof(long));
> > } atomic64_t;
>
> Why is this not aligned to 8 bytes?
Yeah, please use natural alignment for all atomic types.
> I checked all supported architectures
> and found that arc, csky, m68k, microblaze, openrisc, sh and x86-32
> use a smaller alignment by default, but arc and x86-32 override it
> to 8 bytes already. x86 changed it back in 2009 with commit
> bbf2a330d92c ("x86: atomic64: The atomic64_t data type should be 8
> bytes aligned on 32-bit too"), and arc uses the same one.
Right, so x86 as a whole will accept unaligned data for its atomics, but
at terrible overhead. Modern x86 grew (optional) trap on unaligned, and
we've made sure the kernel is 'clean'.
With that, the i586 cmpxchg8b instruction very much wants 8 byte alignment.
Similarly, the x86_64 cmpxchg16b instruction wants 16 bytes alignment.
Powered by blists - more mailing lists