Skip to content

Commit e428b01

Browse files
fthainakpm00
authored andcommitted
atomic: specify alignment for atomic_t and atomic64_t
Some recent commits incorrectly assumed 4-byte alignment of locks. That assumption fails on Linux/m68k (and, interestingly, would have failed on Linux/cris also). The jump label implementation makes a similar alignment assumption. The expectation that atomic_t and atomic64_t variables will be naturally aligned seems reasonable, as indeed they are on 64-bit architectures. But atomic64_t isn't naturally aligned on csky, m68k, microblaze, nios2, openrisc and sh. Neither atomic_t nor atomic64_t are naturally aligned on m68k. This patch brings a little uniformity by specifying natural alignment for atomic types. One benefit is that atomic64_t variables do not get split across a page boundary. The cost is that some structs grow which leads to cache misses and wasted memory. See also, commit bbf2a33 ("x86: atomic64: The atomic64_t data type should be 8 bytes aligned on 32-bit too"). Link: https://lkml.kernel.org/r/a76bc24a4e7c1d8112d7d5fa8d14e4b694a0e90c.1768281748.git.fthain@linux-m68k.org Link: https://lore.kernel.org/lkml/CAFr9PX=MYUDGJS2kAvPMkkfvH+0-SwQB_kxE4ea0J_wZ_pk=7w@mail.gmail.com Link: https://lore.kernel.org/lkml/CAMuHMdW7Ab13DdGs2acMQcix5ObJK0O2dG_Fxzr8_g58Rc1_0g@mail.gmail.com/ Signed-off-by: Finn Thain <[email protected]> Acked-by: Guo Ren <[email protected]> Reviewed-by: Arnd Bergmann <[email protected]> Cc: Guo Ren <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Cc: Dinh Nguyen <[email protected]> Cc: Jonas Bonn <[email protected]> Cc: Stefan Kristiansson <[email protected]> Cc: Stafford Horne <[email protected]> Cc: Yoshinori Sato <[email protected]> Cc: Rich Felker <[email protected]> Cc: John Paul Adrian Glaubitz <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Andrii Nakryiko <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Boqun Feng <[email protected]> Cc: "Borislav Petkov (AMD)" <[email protected]> Cc: Daniel Borkman <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Eduard Zingerman <[email protected]> Cc: Gary Guo <[email protected]> Cc: Hao Luo <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: John Fastabend <[email protected]> Cc: KP Singh <[email protected]> Cc: Marc Rutland <[email protected]> Cc: Martin KaFai Lau <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Sasha Levin (Microsoft) <[email protected]> Cc: Song Liu <[email protected]> Cc: Stanislav Fomichev <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Will Deacon <[email protected]> Cc: Yonghong Song <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 3bb83c9 commit e428b01

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

include/asm-generic/atomic64.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <linux/types.h>
1111

1212
typedef struct {
13-
s64 counter;
13+
s64 __aligned(sizeof(s64)) counter;
1414
} atomic64_t;
1515

1616
#define ATOMIC64_INIT(i) { (i) }

include/linux/types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ typedef phys_addr_t resource_size_t;
179179
typedef unsigned long irq_hw_number_t;
180180

181181
typedef struct {
182-
int counter;
182+
int __aligned(sizeof(int)) counter;
183183
} atomic_t;
184184

185185
#define ATOMIC_INIT(i) { (i) }

0 commit comments

Comments
 (0)