mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-10-29 05:12:59 +01:00
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 bbf2a330d9 ("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]>
76 lines
2.5 KiB
C
76 lines
2.5 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* Generic implementation of 64-bit atomics using spinlocks,
|
|
* useful on processors that don't have 64-bit atomic instructions.
|
|
*
|
|
* Copyright © 2009 Paul Mackerras, IBM Corp. <[email protected]>
|
|
*/
|
|
#ifndef _ASM_GENERIC_ATOMIC64_H
|
|
#define _ASM_GENERIC_ATOMIC64_H
|
|
#include <linux/types.h>
|
|
|
|
typedef struct {
|
|
s64 __aligned(sizeof(s64)) counter;
|
|
} atomic64_t;
|
|
|
|
#define ATOMIC64_INIT(i) { (i) }
|
|
|
|
extern s64 generic_atomic64_read(const atomic64_t *v);
|
|
extern void generic_atomic64_set(atomic64_t *v, s64 i);
|
|
|
|
#define ATOMIC64_OP(op) \
|
|
extern void generic_atomic64_##op(s64 a, atomic64_t *v);
|
|
|
|
#define ATOMIC64_OP_RETURN(op) \
|
|
extern s64 generic_atomic64_##op##_return(s64 a, atomic64_t *v);
|
|
|
|
#define ATOMIC64_FETCH_OP(op) \
|
|
extern s64 generic_atomic64_fetch_##op(s64 a, atomic64_t *v);
|
|
|
|
#define ATOMIC64_OPS(op) ATOMIC64_OP(op) ATOMIC64_OP_RETURN(op) ATOMIC64_FETCH_OP(op)
|
|
|
|
ATOMIC64_OPS(add)
|
|
ATOMIC64_OPS(sub)
|
|
|
|
#undef ATOMIC64_OPS
|
|
#define ATOMIC64_OPS(op) ATOMIC64_OP(op) ATOMIC64_FETCH_OP(op)
|
|
|
|
ATOMIC64_OPS(and)
|
|
ATOMIC64_OPS(or)
|
|
ATOMIC64_OPS(xor)
|
|
|
|
#undef ATOMIC64_OPS
|
|
#undef ATOMIC64_FETCH_OP
|
|
#undef ATOMIC64_OP_RETURN
|
|
#undef ATOMIC64_OP
|
|
|
|
extern s64 generic_atomic64_dec_if_positive(atomic64_t *v);
|
|
extern s64 generic_atomic64_cmpxchg(atomic64_t *v, s64 o, s64 n);
|
|
extern s64 generic_atomic64_xchg(atomic64_t *v, s64 new);
|
|
extern s64 generic_atomic64_fetch_add_unless(atomic64_t *v, s64 a, s64 u);
|
|
|
|
#define arch_atomic64_read generic_atomic64_read
|
|
#define arch_atomic64_set generic_atomic64_set
|
|
#define arch_atomic64_set_release generic_atomic64_set
|
|
|
|
#define arch_atomic64_add generic_atomic64_add
|
|
#define arch_atomic64_add_return generic_atomic64_add_return
|
|
#define arch_atomic64_fetch_add generic_atomic64_fetch_add
|
|
#define arch_atomic64_sub generic_atomic64_sub
|
|
#define arch_atomic64_sub_return generic_atomic64_sub_return
|
|
#define arch_atomic64_fetch_sub generic_atomic64_fetch_sub
|
|
|
|
#define arch_atomic64_and generic_atomic64_and
|
|
#define arch_atomic64_fetch_and generic_atomic64_fetch_and
|
|
#define arch_atomic64_or generic_atomic64_or
|
|
#define arch_atomic64_fetch_or generic_atomic64_fetch_or
|
|
#define arch_atomic64_xor generic_atomic64_xor
|
|
#define arch_atomic64_fetch_xor generic_atomic64_fetch_xor
|
|
|
|
#define arch_atomic64_dec_if_positive generic_atomic64_dec_if_positive
|
|
#define arch_atomic64_cmpxchg generic_atomic64_cmpxchg
|
|
#define arch_atomic64_xchg generic_atomic64_xchg
|
|
#define arch_atomic64_fetch_add_unless generic_atomic64_fetch_add_unless
|
|
|
|
#endif /* _ASM_GENERIC_ATOMIC64_H */
|