* [PATCH v5 0/4] Align atomic storage
@ 2025-12-16 6:31 Finn Thain
2025-12-16 6:31 ` [PATCH v5 1/4] bpf: Explicitly align bpf_res_spin_lock Finn Thain
2025-12-16 19:49 ` [PATCH v5 0/4] Align atomic storage Andrew Morton
0 siblings, 2 replies; 4+ messages in thread
From: Finn Thain @ 2025-12-16 6:31 UTC (permalink / raw)
To: Peter Zijlstra, Will Deacon
Cc: Andrew Morton, Andrii Nakryiko, Arnd Bergmann, Alexei Starovoitov,
Boqun Feng, bpf, Rich Felker, Daniel Borkmann, Dinh Nguyen,
Eduard Zingerman, Gary Guo, Geert Uytterhoeven,
John Paul Adrian Glaubitz, Guo Ren, Hao Luo, John Fastabend,
Jiri Olsa, Jonas Bonn, KP Singh, linux-arch, linux-csky,
linux-kernel, linux-m68k, linux-openrisc, linux-sh, Mark Rutland,
Martin KaFai Lau, Stanislav Fomichev, Stafford Horne, Song Liu,
Stefan Kristiansson, 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 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
include/asm-generic/atomic64.h | 2 +-
include/asm-generic/rqspinlock.h | 2 +-
include/linux/instrumented.h | 15 +++++++++++++++
include/linux/types.h | 2 +-
kernel/bpf/rqspinlock.c | 1 -
lib/Kconfig.debug | 18 ++++++++++++++++++
6 files changed, 36 insertions(+), 4 deletions(-)
--
2.49.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v5 1/4] bpf: Explicitly align bpf_res_spin_lock
2025-12-16 6:31 [PATCH v5 0/4] Align atomic storage Finn Thain
@ 2025-12-16 6:31 ` Finn Thain
2025-12-16 7:24 ` Arnd Bergmann
2025-12-16 19:49 ` [PATCH v5 0/4] Align atomic storage Andrew Morton
1 sibling, 1 reply; 4+ messages in thread
From: Finn Thain @ 2025-12-16 6:31 UTC (permalink / raw)
To: Peter Zijlstra, Will Deacon
Cc: Andrew Morton, Arnd Bergmann, Boqun Feng, Gary Guo, Mark Rutland,
linux-arch, linux-kernel, linux-m68k, Alexei Starovoitov,
Daniel Borkmann, Andrii Nakryiko, Martin KaFai Lau,
Eduard Zingerman, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
Geert Uytterhoeven, bpf
Align bpf_res_spin_lock to avoid a BUILD_BUG_ON() when the alignment
changes, as it will do on m68k when, in a subsequent patch, the minimum
alignment of the atomic_t member of struct rqspinlock gets increased
from 2 to 4. Drop the BUILD_BUG_ON() as it becomes redundant.
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: linux-m68k@lists.linux-m68k.org
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Finn Thain <fthain@linux-m68k.org>
---
include/asm-generic/rqspinlock.h | 2 +-
kernel/bpf/rqspinlock.c | 1 -
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/include/asm-generic/rqspinlock.h b/include/asm-generic/rqspinlock.h
index 6d4244d643df..eac2dcd31b83 100644
--- a/include/asm-generic/rqspinlock.h
+++ b/include/asm-generic/rqspinlock.h
@@ -28,7 +28,7 @@ struct rqspinlock {
*/
struct bpf_res_spin_lock {
u32 val;
-};
+} __aligned(__alignof__(struct rqspinlock));
struct qspinlock;
#ifdef CONFIG_QUEUED_SPINLOCKS
diff --git a/kernel/bpf/rqspinlock.c b/kernel/bpf/rqspinlock.c
index a00561b1d3e5..02f1f671e624 100644
--- a/kernel/bpf/rqspinlock.c
+++ b/kernel/bpf/rqspinlock.c
@@ -692,7 +692,6 @@ __bpf_kfunc int bpf_res_spin_lock(struct bpf_res_spin_lock *lock)
int ret;
BUILD_BUG_ON(sizeof(rqspinlock_t) != sizeof(struct bpf_res_spin_lock));
- BUILD_BUG_ON(__alignof__(rqspinlock_t) != __alignof__(struct bpf_res_spin_lock));
preempt_disable();
ret = res_spin_lock((rqspinlock_t *)lock);
--
2.49.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v5 1/4] bpf: Explicitly align bpf_res_spin_lock
2025-12-16 6:31 ` [PATCH v5 1/4] bpf: Explicitly align bpf_res_spin_lock Finn Thain
@ 2025-12-16 7:24 ` Arnd Bergmann
0 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2025-12-16 7:24 UTC (permalink / raw)
To: Finn Thain, Peter Zijlstra, Will Deacon
Cc: Andrew Morton, Boqun Feng, Gary Guo, Mark Rutland, Linux-Arch,
linux-kernel, linux-m68k, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
Hao Luo, Jiri Olsa, Geert Uytterhoeven, bpf
On Tue, Dec 16, 2025, at 07:31, Finn Thain wrote:
> Align bpf_res_spin_lock to avoid a BUILD_BUG_ON() when the alignment
> changes, as it will do on m68k when, in a subsequent patch, the minimum
> alignment of the atomic_t member of struct rqspinlock gets increased
> from 2 to 4. Drop the BUILD_BUG_ON() as it becomes redundant.
>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: linux-m68k@lists.linux-m68k.org
> Acked-by: Alexei Starovoitov <ast@kernel.org>
> Signed-off-by: Finn Thain <fthain@linux-m68k.org>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v5 0/4] Align atomic storage
2025-12-16 6:31 [PATCH v5 0/4] Align atomic storage Finn Thain
2025-12-16 6:31 ` [PATCH v5 1/4] bpf: Explicitly align bpf_res_spin_lock Finn Thain
@ 2025-12-16 19:49 ` Andrew Morton
1 sibling, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2025-12-16 19:49 UTC (permalink / raw)
To: Finn Thain
Cc: Peter Zijlstra, Will Deacon, Andrii Nakryiko, Arnd Bergmann,
Alexei Starovoitov, Boqun Feng, bpf, Rich Felker, Daniel Borkmann,
Dinh Nguyen, Eduard Zingerman, Gary Guo, Geert Uytterhoeven,
John Paul Adrian Glaubitz, Guo Ren, Hao Luo, John Fastabend,
Jiri Olsa, Jonas Bonn, KP Singh, linux-arch, linux-csky,
linux-kernel, linux-m68k, linux-openrisc, linux-sh, Mark Rutland,
Martin KaFai Lau, Stanislav Fomichev, Stafford Horne, Song Liu,
Stefan Kristiansson, Yonghong Song, Yoshinori Sato
On Tue, 16 Dec 2025 17:31:05 +1100 Finn Thain <fthain@linux-m68k.org> wrote:
> 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.
Looks nice, thanks.
I don't know which tree this is aimed at. I grabbed a copy for
mm.git's mm-nonmm-unstable tree, can drop it again if this pops up in
linux-next via another route.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-12-16 19:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-16 6:31 [PATCH v5 0/4] Align atomic storage Finn Thain
2025-12-16 6:31 ` [PATCH v5 1/4] bpf: Explicitly align bpf_res_spin_lock Finn Thain
2025-12-16 7:24 ` Arnd Bergmann
2025-12-16 19:49 ` [PATCH v5 0/4] Align atomic storage Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox