* [PATCH v6 0/4] Align atomic storage
@ 2025-12-31 8:25 Finn Thain
2025-12-31 8:25 ` [PATCH v6 2/4] atomic: Specify alignment for atomic_t and atomic64_t Finn Thain
0 siblings, 1 reply; 2+ messages in thread
From: Finn Thain @ 2025-12-31 8:25 UTC (permalink / raw)
To: Andrew Morton, Peter Zijlstra, Will Deacon
Cc: Andrii Nakryiko, Ard Biesheuvel, Arnd Bergmann,
Alexei Starovoitov, Boqun Feng, Borislav Petkov, bpf, Rich Felker,
Daniel Borkmann, Dave Hansen, Dinh Nguyen, Eduard Zingerman,
Gary Guo, Geert Uytterhoeven, John Paul Adrian Glaubitz, Guo Ren,
Hao Luo, H. Peter Anvin, John Fastabend, Jiri Olsa, Jonas Bonn,
KP Singh, linux-arch, linux-csky, linux-efi, linux-kernel,
linux-m68k, linux-openrisc, linux-sh, Mark Rutland,
Martin KaFai Lau, Ingo Molnar, Sasha Levin, Stanislav Fomichev,
Stafford Horne, Song Liu, Stefan Kristiansson, Thomas Gleixner,
x86, Yonghong Song, Yoshinori Sato
This series adds the __aligned attribute to atomic_t and atomic64_t
definitions in include/linux and include/asm-generic (respectively)
to get natural alignment of both types on csky, m68k, microblaze,
nios2, openrisc and sh.
This series also adds Kconfig options to enable a new run-time warning
to help reveal misaligned atomic accesses on platforms which don't
trap that.
The performance impact is expected to vary across platforms and workloads.
The measurements I made on m68k show that some workloads run faster and
others slower.
---
Changed since v5:
- Added acked-by and revewed-by tags.
- Added a new macro to inhibit emission of __bug_table section, for the
benefit of pre-boot code like the EFI stub loader.
Changed since v4:
- Dropped parisc header file patch as it's been merged already.
- Submitted as PATCH instead of RFC.
Changed since v3:
- Rebased on v6.17.
- New patch to resolve header dependency issue on parisc.
- Dropped documentation patch.
Changed since v2:
- Specify natural alignment for atomic64_t.
- CONFIG_DEBUG_ATOMIC checks for natural alignment again.
- New patch to add weakened alignment check.
- New patch for explicit alignment in BPF header.
---
Finn Thain (3):
bpf: Explicitly align bpf_res_spin_lock
atomic: Specify alignment for atomic_t and atomic64_t
atomic: Add option for weaker alignment check
Peter Zijlstra (1):
atomic: Add alignment check to instrumented atomic operations
arch/x86/boot/compressed/Makefile | 1 +
drivers/firmware/efi/libstub/Makefile | 1 +
include/asm-generic/atomic64.h | 2 +-
include/asm-generic/rqspinlock.h | 2 +-
include/linux/instrumented.h | 17 +++++++++++++++++
include/linux/types.h | 2 +-
kernel/bpf/rqspinlock.c | 1 -
lib/Kconfig.debug | 18 ++++++++++++++++++
8 files changed, 40 insertions(+), 4 deletions(-)
--
2.49.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH v6 2/4] atomic: Specify alignment for atomic_t and atomic64_t
2025-12-31 8:25 [PATCH v6 0/4] Align atomic storage Finn Thain
@ 2025-12-31 8:25 ` Finn Thain
0 siblings, 0 replies; 2+ messages in thread
From: Finn Thain @ 2025-12-31 8:25 UTC (permalink / raw)
To: Andrew Morton, Peter Zijlstra, Will Deacon
Cc: Arnd Bergmann, Boqun Feng, Gary Guo, Mark Rutland, linux-arch,
linux-kernel, linux-m68k, Guo Ren, linux-csky, Geert Uytterhoeven,
Dinh Nguyen, Jonas Bonn, Stefan Kristiansson, Stafford Horne,
linux-openrisc, Yoshinori Sato, Rich Felker,
John Paul Adrian Glaubitz, linux-sh
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.
Cc: Guo Ren <guoren@kernel.org>
Cc: linux-csky@vger.kernel.org
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: linux-m68k@lists.linux-m68k.org
Cc: Dinh Nguyen <dinguyen@kernel.org>
Cc: Jonas Bonn <jonas@southpole.se>
Cc: Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
Cc: Stafford Horne <shorne@gmail.com>
Cc: linux-openrisc@vger.kernel.org
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Rich Felker <dalias@libc.org>
Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Cc: linux-sh@vger.kernel.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/
Acked-by: Guo Ren <guoren@kernel.org>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Finn Thain <fthain@linux-m68k.org>
---
Changed since v5:
- Added tags from Guo Ren and Arnd Bergmann.
Changed since v2:
- Specify natural alignment for atomic64_t.
Changed since v1:
- atomic64_t now gets an __aligned attribute too.
- The 'Fixes' tag has been dropped because Lance sent a different fix
for commit e711faaafbe5 ("hung_task: replace blocker_mutex with encoded
blocker") that's suitable for -stable.
---
include/asm-generic/atomic64.h | 2 +-
include/linux/types.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
index 100d24b02e52..f22ccfc0df98 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 __aligned(sizeof(s64)) counter;
} atomic64_t;
#define ATOMIC64_INIT(i) { (i) }
diff --git a/include/linux/types.h b/include/linux/types.h
index d4437e9c452c..1760e1feeab9 100644
--- a/include/linux/types.h
+++ b/include/linux/types.h
@@ -180,7 +180,7 @@ typedef phys_addr_t resource_size_t;
typedef unsigned long irq_hw_number_t;
typedef struct {
- int counter;
+ int __aligned(sizeof(int)) counter;
} atomic_t;
#define ATOMIC_INIT(i) { (i) }
--
2.49.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-12-31 8:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-31 8:25 [PATCH v6 0/4] Align atomic storage Finn Thain
2025-12-31 8:25 ` [PATCH v6 2/4] atomic: Specify alignment for atomic_t and atomic64_t Finn Thain
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).