Introduce cmpxchg128() -- aka. the demise of cmpxchg_double()
Subsystems (14)
Peter Zijlstra
maintainerv3 cover Introduce cmpxchg128() -- aka. the demise of cmpxchg_double()
Hi!
I seem to have forgotten to post this series last release; so here goes. I'm really hoping to merge it and forget about it.
Since Linus hated on cmpxchg_double(), a few patches to get rid of it, as proposed here:
https://lkml.kernel.org/r/[email protected]
These patches are based on 6.4.0-rc2.
Available here:
git://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git core/wip-u128
Since v2:
- reworked this_cpu_cmpxchg() to not implicity do u128 but provide explicit this_cpu_cmpxchg128() (arnd)
- added try_cmpxchg12_local() (per the addition of the try_cmpxchg*_local() family of functions)
- slight cleanup of the SLUB conversion (due to rebase and having to touch it)
- added a 'cleanup' patch for SLUB, since I was staring at that anyway
Since v1:
- rebaed on Eric's ghash cleanups (hence the cryptodev-2.6 dependency)
- rebased on Heiko's s390/cpum_sf CDSG patch
- fixed up a bunch of arch code
- fixed up the inline asm to use 'u128 *' mem argument so the compiler knows how wide the modification is.
- reworked the percpu thing to use union based type-punning instead of _Generic() based casts.
--- Documentation/core-api/this_cpu_ops.rst | 2 - arch/arm64/include/asm/atomic_ll_sc.h | 56 ++++---- arch/arm64/include/asm/atomic_lse.h | 39 +++--- arch/arm64/include/asm/cmpxchg.h | 48 ++----- arch/arm64/include/asm/percpu.h | 30 +++-- arch/s390/include/asm/cmpxchg.h | 32 +---- arch/s390/include/asm/cpu_mf.h | 2 +- arch/s390/include/asm/percpu.h | 34 +++-- arch/s390/kernel/perf_cpum_sf.c | 16 +-- arch/x86/include/asm/cmpxchg.h | 25 ---- arch/x86/include/asm/cmpxchg_32.h | 2 +- arch/x86/include/asm/cmpxchg_64.h | 63 ++++++++- arch/x86/include/asm/percpu.h | 100 +++++++++------ drivers/iommu/amd/amd_iommu_types.h | 9 +- drivers/iommu/amd/iommu.c | 10 +- drivers/iommu/intel/irq_remapping.c | 8 +- include/asm-generic/percpu.h | 66 ++-------- include/crypto/b128ops.h | 14 +- include/linux/atomic/atomic-arch-fallback.h | 95 +++++++++++++- include/linux/atomic/atomic-instrumented.h | 93 ++++++++++++-- include/linux/dmar.h | 125 +++++++++--------- include/linux/percpu-defs.h | 38 ------ include/linux/slub_def.h | 12 +- include/linux/types.h | 5 + include/uapi/linux/types.h | 4 + lib/crypto/curve25519-hacl64.c | 2 - lib/crypto/poly1305-donna64.c | 2 - mm/slab.h | 49 ++++++- mm/slub.c | 191 ++++++++++++++-------------- scripts/atomic/gen-atomic-fallback.sh | 4 +- scripts/atomic/gen-atomic-instrumented.sh | 19 +-- 31 files changed, 667 insertions(+), 528 deletions(-)
Peter Zijlstra
maintainerPATCH v3 1/11 cyrpto/b128ops: Remove struct u128
Per git-grep u128_xor() and its related struct u128 are unused except to implement {be,le}128_xor(). Remove them to free up the namespace.
--- include/crypto/b128ops.h | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
include/crypto/b128ops.h +3 -11
@@ -50,10 +50,6 @@#include <linux/types.h> typedef struct { -u64 a, b; -}u128 ; - -typedef struct {__be64 a, b; }be128 ;
@@ -61,20 +57,16 @@ typedef struct { __le64 b, a; } le128; -static inline void u128_xor (u128 *r,const u128 *p,const u128 *q) +static inline void be128_xor (be128 *r,const be128 *p,const be128 *q) { r->a = p->a ^ q->a; r->b = p->b ^ q->b; } -static inline void be128_xor (be128 *r,const be128 *p,const be128 *q) -{ -u128_xor ((u128 *)r, (u128 *)p, (u128 *)q); -} -static inline void le128_xor (le128 *r,const le128 *p,const le128 *q) { -u128_xor ((u128 *)r, (u128 *)p, (u128 *)q); + r->a = p->a ^ q->a; + r->b = p->b ^ q->b; }#endif /* _CRYPTO_B128OPS_H */
[tip: locking/core] cyrpto/b128ops: Remove struct u128
The following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: f49a2237d34009e1623fd04a5f3c34ea39dd5792 Gitweb: https://git.kernel.org/tip/f49a2237d34009e1623fd04a5f3c34ea39dd5792 Author: Peter Zijlstra <[email protected]> AuthorDate: Mon, 15 May 2023 09:57:00 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 19 May 2023 12:35:10 +02:00
cyrpto/b128ops: Remove struct u128
Per git-grep u128_xor() and its related struct u128 are unused except to implement {be,le}128_xor(). Remove them to free up the namespace.
--- include/crypto/b128ops.h | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
include/crypto/b128ops.h +3 -11
@@ -50,10 +50,6 @@#include <linux/types.h> typedef struct { -u64 a, b; -}u128 ; - -typedef struct {__be64 a, b; }be128 ;
@@ -61,20 +57,16 @@ typedef struct { __le64 b, a; } le128; -static inline void u128_xor (u128 *r,const u128 *p,const u128 *q) +static inline void be128_xor (be128 *r,const be128 *p,const be128 *q) { r->a = p->a ^ q->a; r->b = p->b ^ q->b; } -static inline void be128_xor (be128 *r,const be128 *p,const be128 *q) -{ -u128_xor ((u128 *)r, (u128 *)p, (u128 *)q); -} -static inline void le128_xor (le128 *r,const le128 *p,const le128 *q) { -u128_xor ((u128 *)r, (u128 *)p, (u128 *)q); + r->a = p->a ^ q->a; + r->b = p->b ^ q->b; }#endif /* _CRYPTO_B128OPS_H */
[tip: locking/core] cyrpto/b128ops: Remove struct u128
In reply to Peter ZijlstraThe following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: a42d381f16c00d894ef56e579035d8db3552bc61 Gitweb: https://git.kernel.org/tip/a42d381f16c00d894ef56e579035d8db3552bc61 Author: Peter Zijlstra <[email protected]> AuthorDate: Mon, 15 May 2023 09:57:00 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Mon, 22 May 2023 10:49:48 +02:00
cyrpto/b128ops: Remove struct u128
Per git-grep u128_xor() and its related struct u128 are unused except to implement {be,le}128_xor(). Remove them to free up the namespace.
--- include/crypto/b128ops.h | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
include/crypto/b128ops.h +3 -11
@@ -50,10 +50,6 @@#include <linux/types.h> typedef struct { -u64 a, b; -}u128 ; - -typedef struct {__be64 a, b; }be128 ;
@@ -61,20 +57,16 @@ typedef struct { __le64 b, a; } le128; -static inline void u128_xor (u128 *r,const u128 *p,const u128 *q) +static inline void be128_xor (be128 *r,const be128 *p,const be128 *q) { r->a = p->a ^ q->a; r->b = p->b ^ q->b; } -static inline void be128_xor (be128 *r,const be128 *p,const be128 *q) -{ -u128_xor ((u128 *)r, (u128 *)p, (u128 *)q); -} -static inline void le128_xor (le128 *r,const le128 *p,const le128 *q) { -u128_xor ((u128 *)r, (u128 *)p, (u128 *)q); + r->a = p->a ^ q->a; + r->b = p->b ^ q->b; }#endif /* _CRYPTO_B128OPS_H */
Peter Zijlstra
maintainerPATCH v3 2/11 types: Introduce [us]128
In reply to Peter ZijlstraIntroduce [us]128 (when available). Unlike [us]64, ensure they are always naturally aligned.
This also enables 128bit wide atomics (which require natural alignment) such as cmpxchg128().
--- include/linux/types.h | 5 +++++ include/uapi/linux/types.h | 4 ++++ 2 files changed, 9 insertions(+)
include/linux/types.h +5 -0
@@ -10,6 +10,11 @@#define DECLARE_BITMAP (name,bits) \ unsigned long name[BITS_TO_LONGS(bits)] +#ifdef __SIZEOF_INT128__ +typedef __s128 s128 ; +typedef __u128 u128 ; +#endif +typedef u32 __kernel_dev_t ;typedef __kernel_fd_set fd_set ;
include/uapi/linux/types.h +4 -0
@@ -13,6 +13,10 @@#include <linux/posix_types.h> +#ifdef __SIZEOF_INT128__ +typedef __signed__ __int128 __s128 __attribute__((aligned(16))); +typedef unsigned __int128 __u128 __attribute__((aligned (16 ))); +#endif /* * Below are truly Linux-specific types that should never collide with
lib/crypto/curve25519-hacl64.c +0 -2
@@ -14,8 +14,6 @@#include <crypto/curve25519.h> #include <linux/string.h> -typedef __uint128_t u128 ; - static __always_inline u64 u64_eq_mask(u64 a, u64 b) {u64 x = a ^ b;
lib/crypto/poly1305-donna64.c +0 -2
@@ -10,8 +10,6 @@#include <asm/unaligned.h> #include <crypto/internal/poly1305.h> -typedef __uint128_t u128 ; -void poly1305_core_setkey (struct poly1305_core_key *key,const u8 raw_key[POLY1305_BLOCK_SIZE ]) {
[tip: locking/core] types: Introduce [us]128
The following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 1fbd899da7d7a5eb7dd81404d37342b4de95f48f Gitweb: https://git.kernel.org/tip/1fbd899da7d7a5eb7dd81404d37342b4de95f48f Author: Peter Zijlstra <[email protected]> AuthorDate: Mon, 15 May 2023 09:57:01 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 19 May 2023 12:35:11 +02:00
types: Introduce [us]128
Introduce [us]128 (when available). Unlike [us]64, ensure they are always naturally aligned.
This also enables 128bit wide atomics (which require natural alignment) such as cmpxchg128().
--- include/linux/types.h | 5 +++++ include/uapi/linux/types.h | 4 ++++ lib/crypto/curve25519-hacl64.c | 2 -- lib/crypto/poly1305-donna64.c | 2 -- 4 files changed, 9 insertions(+), 4 deletions(-)
include/linux/types.h +5 -0
@@ -10,6 +10,11 @@#define DECLARE_BITMAP (name,bits) \ unsigned long name[BITS_TO_LONGS(bits)] +#ifdef __SIZEOF_INT128__ +typedef __s128 s128 ; +typedef __u128 u128 ; +#endif +typedef u32 __kernel_dev_t ;typedef __kernel_fd_set fd_set ;
include/uapi/linux/types.h +4 -0
@@ -13,6 +13,10 @@#include <linux/posix_types.h> +#ifdef __SIZEOF_INT128__ +typedef __signed__ __int128 __s128 __attribute__((aligned(16))); +typedef unsigned __int128 __u128 __attribute__((aligned (16 ))); +#endif /* * Below are truly Linux-specific types that should never collide with
lib/crypto/curve25519-hacl64.c +0 -2
@@ -14,8 +14,6 @@#include <crypto/curve25519.h> #include <linux/string.h> -typedef __uint128_t u128 ; - static __always_inline u64 u64_eq_mask(u64 a, u64 b) {u64 x = a ^ b;
lib/crypto/poly1305-donna64.c +0 -2
@@ -10,8 +10,6 @@#include <asm/unaligned.h> #include <crypto/internal/poly1305.h> -typedef __uint128_t u128 ; -void poly1305_core_setkey (struct poly1305_core_key *key,const u8 raw_key[POLY1305_BLOCK_SIZE ]) {
[tip: locking/core] types: Introduce [us]128
In reply to Peter ZijlstraThe following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: c8c216a63fe28b247046a15e995688289ce416ad Gitweb: https://git.kernel.org/tip/c8c216a63fe28b247046a15e995688289ce416ad Author: Peter Zijlstra <[email protected]> AuthorDate: Mon, 15 May 2023 09:57:01 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Mon, 22 May 2023 10:49:49 +02:00
types: Introduce [us]128
Introduce [us]128 (when available). Unlike [us]64, ensure they are always naturally aligned.
This also enables 128bit wide atomics (which require natural alignment) such as cmpxchg128().
--- include/linux/types.h | 5 +++++ include/uapi/linux/types.h | 4 ++++ lib/crypto/curve25519-hacl64.c | 2 -- lib/crypto/poly1305-donna64.c | 2 -- 4 files changed, 9 insertions(+), 4 deletions(-)
include/linux/types.h +5 -0
@@ -10,6 +10,11 @@#define DECLARE_BITMAP (name,bits) \ unsigned long name[BITS_TO_LONGS(bits)] +#ifdef __SIZEOF_INT128__ +typedef __s128 s128 ; +typedef __u128 u128 ; +#endif +typedef u32 __kernel_dev_t ;typedef __kernel_fd_set fd_set ;
include/uapi/linux/types.h +4 -0
@@ -13,6 +13,10 @@#include <linux/posix_types.h> +#ifdef __SIZEOF_INT128__ +typedef __signed__ __int128 __s128 __attribute__((aligned(16))); +typedef unsigned __int128 __u128 __attribute__((aligned (16 ))); +#endif /* * Below are truly Linux-specific types that should never collide with
lib/crypto/curve25519-hacl64.c +0 -2
@@ -14,8 +14,6 @@#include <crypto/curve25519.h> #include <linux/string.h> -typedef __uint128_t u128 ; - static __always_inline u64 u64_eq_mask(u64 a, u64 b) {u64 x = a ^ b;
lib/crypto/poly1305-donna64.c +0 -2
@@ -10,8 +10,6 @@#include <asm/unaligned.h> #include <crypto/internal/poly1305.h> -typedef __uint128_t u128 ; -void poly1305_core_setkey (struct poly1305_core_key *key,const u8 raw_key[POLY1305_BLOCK_SIZE ]) {
Peter Zijlstra
maintainerPATCH v3 3/11 arch: Introduce arch_{,try_}_cmpxchg128{,_local}()
In reply to Peter ZijlstraFor all architectures that currently support cmpxchg_double() implement the cmpxchg128() family of functions that is basically the same but with a saner interface.
--- arch/arm64/include/asm/atomic_ll_sc.h | 41 +++++++++++++++++++++ arch/arm64/include/asm/atomic_lse.h | 31 ++++++++++++++++ arch/arm64/include/asm/cmpxchg.h | 26 +++++++++++++ arch/s390/include/asm/cmpxchg.h | 14 +++++++ arch/x86/include/asm/cmpxchg_32.h | 3 + arch/x86/include/asm/cmpxchg_64.h | 64 +++++++++++++++++++++++++++++++++- 6 files changed, 177 insertions(+), 2 deletions(-)
arch/arm64/include/asm/atomic_ll_sc.h +41 -0
@@ -326,6 +326,47 @@ __CMPXCHG_DBL( , , , ) __CMPXCHG_DBL(_mb, dmb ish, l, "memory")#undef __CMPXCHG_DBL + +union __u128_halves { +u128 full; +struct { +u64 low, high; + }; +}; + +#define __CMPXCHG128(name, mb, rel, cl...) \ +static __always_inline u128 \ +__ll_sc__cmpxchg128##name(volatile u128 *ptr, u128 old, u128 new) \ +{ \ + union __u128_halves r, o = { .full = (old) }, \ + n = { .full = (new) }; \ + unsigned int tmp; \ + \ + asm volatile("// __cmpxchg128" #name "\n" \ + " prfm pstl1strm, %[v]\n" \ + "1: ldxp %[rl], %[rh], %[v]\n" \ + " cmp %[rl], %[ol]\n" \ + " ccmp %[rh], %[oh], 0, eq\n" \ + " b.ne 2f\n" \ + " st" #rel "xp %w[tmp], %[nl], %[nh], %[v]\n" \ + " cbnz %w[tmp], 1b\n" \ + " " #mb "\n" \ + "2:" \ + : [v] "+Q" (*(u128 *)ptr), \ + [rl] "=&r" (r.low), [rh] "=&r" (r.high), \ + [tmp] "=&r" (tmp) \ + : [ol] "r" (o.low), [oh] "r" (o.high), \ + [nl] "r" (n.low), [nh] "r" (n.high) \ + : "cc", ##cl); \ + \ + return r.full; \ +} + +__CMPXCHG128( , , ) +__CMPXCHG128(_mb, dmb ish, l, "memory") + +#undef __CMPXCHG128 +#undef K#endif /* __ASM_ATOMIC_LL_SC_H */
arch/arm64/include/asm/atomic_lse.h +31 -0
@@ -317,4 +317,35 @@ __CMPXCHG_DBL(_mb, al, "memory")#undef __CMPXCHG_DBL +#define __CMPXCHG128(name, mb, cl...) \ +static __always_inline u128 \ +__lse__cmpxchg128##name(volatile u128 *ptr, u128 old, u128 new) \ +{ \ + union __u128_halves r, o = { .full = (old) }, \ + n = { .full = (new) }; \ + register unsigned long x0 asm ("x0") = o.low; \ + register unsigned long x1 asm ("x1") = o.high; \ + register unsigned long x2 asm ("x2") = n.low; \ + register unsigned long x3 asm ("x3") = n.high; \ + register unsigned long x4 asm ("x4") = (unsigned long)ptr; \ + \ + asm volatile( \ + __LSE_PREAMBLE \ + " casp" #mb "\t%[old1], %[old2], %[new1], %[new2], %[v]\n"\ + : [old1] "+&r" (x0), [old2] "+&r" (x1), \ + [v] "+Q" (*(u128 *)ptr) \ + : [new1] "r" (x2), [new2] "r" (x3), [ptr] "r" (x4), \ + [oldval1] "r" (o.low), [oldval2] "r" (o.high) \ + : cl); \ + \ + r.low = x0; r.high = x1; \ + \ + return r.full; \ +} + +__CMPXCHG128( , ) +__CMPXCHG128(_mb, al, "memory") + +#undef __CMPXCHG128 +#endif /* __ASM_ATOMIC_LSE_H */
arch/arm64/include/asm/cmpxchg.h +26 -0
@@ -146,6 +146,19 @@ __CMPXCHG_DBL(_mb)#undef __CMPXCHG_DBL +#define __CMPXCHG128 (name) \ +static inline u128 __cmpxchg128##name(volatile u128 *ptr, \ + u128 old, u128 new) \ +{ \ + return __lse_ll_sc_body(_cmpxchg128##name, \ + ptr, old, new); \ +} + +__CMPXCHG128( ) +__CMPXCHG128(_mb) + +#undef __CMPXCHG128 +#define __CMPXCHG_GEN (sfx) \ static __always_inline unsigned long __cmpxchg##sfx(volatile void *ptr, \ unsigned long old, \
@@ -228,6 +241,19 @@ __CMPXCHG_GEN(_mb) __ret; \ }) +/* cmpxchg128 */ +#define system_has_cmpxchg128 () 1 + +#define arch_cmpxchg128 (ptr, o, n) \ +({ \ + __cmpxchg128_mb((ptr), (o), (n)); \ +}) + +#define arch_cmpxchg128_local (ptr, o, n) \ +({ \ + __cmpxchg128((ptr), (o), (n)); \ +}) +#define __CMPWAIT_CASE (w, sfx, sz) \ static inline void __cmpwait_case_##sz(volatile void *ptr, \ unsigned long val) \
arch/s390/include/asm/cmpxchg.h +14 -0
@@ -224,4 +224,18 @@ static __always_inline int __cmpxchg_dou (unsigned long)(n1), (unsigned long)(n2)); \ }) +#define system_has_cmpxchg128 () 1 + +static __always_inline u128 arch_cmpxchg128(volatile u128 *ptr, u128 old, u128 new) +{ + asmvolatile ( +" cdsg %[old],%[new],%[ptr]\n" + : [old]"+d" (old), [ptr]"+QS" (*ptr) + : [new]"d" (new) + :"memory" ,"cc" ); +return old; +} + +#define arch_cmpxchg128 arch_cmpxchg128 +#endif /* __ASM_CMPXCHG_H */
arch/x86/include/asm/cmpxchg_32.h +2 -1
@@ -103,6 +103,7 @@ static inline bool __try_cmpxchg64(volat#endif -#define system_has_cmpxchg_double () boot_cpu_has(X86_FEATURE_CX8) +#define system_has_cmpxchg_double () boot_cpu_has(X86_FEATURE_CX8) +#define system_has_cmpxchg64 () boot_cpu_has(X86_FEATURE_CX8)#endif /* _ASM_X86_CMPXCHG_32_H */
arch/x86/include/asm/cmpxchg_64.h +63 -1
69 lines not on this page · raw message
[tip: locking/core] arch: Introduce arch_{,try_}_cmpxchg128{,_local}()
The following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 1bb3ba21c2c235f637f5ad6b7e56c2471a52716c Gitweb: https://git.kernel.org/tip/1bb3ba21c2c235f637f5ad6b7e56c2471a52716c Author: Peter Zijlstra <[email protected]> AuthorDate: Mon, 15 May 2023 09:57:02 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 19 May 2023 12:35:11 +02:00
arch: Introduce arch_{,try_}_cmpxchg128{,_local}()
For all architectures that currently support cmpxchg_double() implement the cmpxchg128() family of functions that is basically the same but with a saner interface.
--- arch/arm64/include/asm/atomic_ll_sc.h | 41 +++++++++++++++++- arch/arm64/include/asm/atomic_lse.h | 31 +++++++++++++- arch/arm64/include/asm/cmpxchg.h | 26 +++++++++++- arch/s390/include/asm/cmpxchg.h | 14 ++++++- arch/x86/include/asm/cmpxchg_32.h | 3 +- arch/x86/include/asm/cmpxchg_64.h | 64 +++++++++++++++++++++++++- 6 files changed, 177 insertions(+), 2 deletions(-)
arch/arm64/include/asm/atomic_ll_sc.h +41 -0
@@ -326,6 +326,47 @@ __CMPXCHG_DBL( , , , ) __CMPXCHG_DBL(_mb, dmb ish, l, "memory")#undef __CMPXCHG_DBL + +union __u128_halves { +u128 full; +struct { +u64 low, high; + }; +}; + +#define __CMPXCHG128(name, mb, rel, cl...) \ +static __always_inline u128 \ +__ll_sc__cmpxchg128##name(volatile u128 *ptr, u128 old, u128 new) \ +{ \ + union __u128_halves r, o = { .full = (old) }, \ + n = { .full = (new) }; \ + unsigned int tmp; \ + \ + asm volatile("// __cmpxchg128" #name "\n" \ + " prfm pstl1strm, %[v]\n" \ + "1: ldxp %[rl], %[rh], %[v]\n" \ + " cmp %[rl], %[ol]\n" \ + " ccmp %[rh], %[oh], 0, eq\n" \ + " b.ne 2f\n" \ + " st" #rel "xp %w[tmp], %[nl], %[nh], %[v]\n" \ + " cbnz %w[tmp], 1b\n" \ + " " #mb "\n" \ + "2:" \ + : [v] "+Q" (*(u128 *)ptr), \ + [rl] "=&r" (r.low), [rh] "=&r" (r.high), \ + [tmp] "=&r" (tmp) \ + : [ol] "r" (o.low), [oh] "r" (o.high), \ + [nl] "r" (n.low), [nh] "r" (n.high) \ + : "cc", ##cl); \ + \ + return r.full; \ +} + +__CMPXCHG128( , , ) +__CMPXCHG128(_mb, dmb ish, l, "memory") + +#undef __CMPXCHG128 +#undef K#endif /* __ASM_ATOMIC_LL_SC_H */
arch/arm64/include/asm/atomic_lse.h +31 -0
@@ -317,4 +317,35 @@ __CMPXCHG_DBL(_mb, al, "memory")#undef __CMPXCHG_DBL +#define __CMPXCHG128(name, mb, cl...) \ +static __always_inline u128 \ +__lse__cmpxchg128##name(volatile u128 *ptr, u128 old, u128 new) \ +{ \ + union __u128_halves r, o = { .full = (old) }, \ + n = { .full = (new) }; \ + register unsigned long x0 asm ("x0") = o.low; \ + register unsigned long x1 asm ("x1") = o.high; \ + register unsigned long x2 asm ("x2") = n.low; \ + register unsigned long x3 asm ("x3") = n.high; \ + register unsigned long x4 asm ("x4") = (unsigned long)ptr; \ + \ + asm volatile( \ + __LSE_PREAMBLE \ + " casp" #mb "\t%[old1], %[old2], %[new1], %[new2], %[v]\n"\ + : [old1] "+&r" (x0), [old2] "+&r" (x1), \ + [v] "+Q" (*(u128 *)ptr) \ + : [new1] "r" (x2), [new2] "r" (x3), [ptr] "r" (x4), \ + [oldval1] "r" (o.low), [oldval2] "r" (o.high) \ + : cl); \ + \ + r.low = x0; r.high = x1; \ + \ + return r.full; \ +} + +__CMPXCHG128( , ) +__CMPXCHG128(_mb, al, "memory") + +#undef __CMPXCHG128 +#endif /* __ASM_ATOMIC_LSE_H */
arch/arm64/include/asm/cmpxchg.h +26 -0
@@ -146,6 +146,19 @@ __CMPXCHG_DBL(_mb)#undef __CMPXCHG_DBL +#define __CMPXCHG128 (name) \ +static inline u128 __cmpxchg128##name(volatile u128 *ptr, \ + u128 old, u128 new) \ +{ \ + return __lse_ll_sc_body(_cmpxchg128##name, \ + ptr, old, new); \ +} + +__CMPXCHG128( ) +__CMPXCHG128(_mb) + +#undef __CMPXCHG128 +#define __CMPXCHG_GEN (sfx) \ static __always_inline unsigned long __cmpxchg##sfx(volatile void *ptr, \ unsigned long old, \
@@ -228,6 +241,19 @@ __CMPXCHG_GEN(_mb) __ret; \ }) +/* cmpxchg128 */ +#define system_has_cmpxchg128 () 1 + +#define arch_cmpxchg128 (ptr, o, n) \ +({ \ + __cmpxchg128_mb((ptr), (o), (n)); \ +}) + +#define arch_cmpxchg128_local (ptr, o, n) \ +({ \ + __cmpxchg128((ptr), (o), (n)); \ +}) +#define __CMPWAIT_CASE (w, sfx, sz) \ static inline void __cmpwait_case_##sz(volatile void *ptr, \ unsigned long val) \
arch/s390/include/asm/cmpxchg.h +14 -0
@@ -224,4 +224,18 @@ static __always_inline int __cmpxchg_double(unsigned long p1, unsigned long p2, (unsigned long)(n1), (unsigned long)(n2)); \ }) +#define system_has_cmpxchg128 () 1 + +static __always_inline u128 arch_cmpxchg128(volatile u128 *ptr, u128 old, u128 new) +{ + asmvolatile ( +" cdsg %[old],%[new],%[ptr]\n" + : [old]"+d" (old), [ptr]"+QS" (*ptr) + : [new]"d" (new) + :"memory" ,"cc" ); +return old; +} + +#define arch_cmpxchg128 arch_cmpxchg128 +#endif /* __ASM_CMPXCHG_H */
arch/x86/include/asm/cmpxchg_32.h +2 -1
@@ -103,6 +103,7 @@ static inline bool __try_cmpxchg64(volatile u64 *ptr, u64 *pold, u64 new)#endif -#define system_has_cmpxchg_double () boot_cpu_has(X86_FEATURE_CX8) +#define system_has_cmpxchg_double () boot_cpu_has(X86_FEATURE_CX8) +#define system_has_cmpxchg64 () boot_cpu_has(X86_FEATURE_CX8)#endif /* _ASM_X86_CMPXCHG_32_H */
arch/x86/include/asm/cmpxchg_64.h +63 -1
69 lines not on this page · raw message
[tip: locking/core] arch: Introduce arch_{,try_}_cmpxchg128{,_local}()
In reply to Peter ZijlstraThe following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 8c9719a1ae1f290250da18bb0b41cd00067319bf Gitweb: https://git.kernel.org/tip/8c9719a1ae1f290250da18bb0b41cd00067319bf Author: Peter Zijlstra <[email protected]> AuthorDate: Mon, 15 May 2023 09:57:02 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Mon, 22 May 2023 10:49:49 +02:00
arch: Introduce arch_{,try_}_cmpxchg128{,_local}()
For all architectures that currently support cmpxchg_double() implement the cmpxchg128() family of functions that is basically the same but with a saner interface.
--- arch/arm64/include/asm/atomic_ll_sc.h | 41 +++++++++++++++++- arch/arm64/include/asm/atomic_lse.h | 31 +++++++++++++- arch/arm64/include/asm/cmpxchg.h | 26 +++++++++++- arch/s390/include/asm/cmpxchg.h | 14 ++++++- arch/x86/include/asm/cmpxchg_32.h | 3 +- arch/x86/include/asm/cmpxchg_64.h | 64 +++++++++++++++++++++++++- 6 files changed, 177 insertions(+), 2 deletions(-)
arch/arm64/include/asm/atomic_ll_sc.h +41 -0
@@ -326,6 +326,47 @@ __CMPXCHG_DBL( , , , ) __CMPXCHG_DBL(_mb, dmb ish, l, "memory")#undef __CMPXCHG_DBL + +union __u128_halves { +u128 full; +struct { +u64 low, high; + }; +}; + +#define __CMPXCHG128(name, mb, rel, cl...) \ +static __always_inline u128 \ +__ll_sc__cmpxchg128##name(volatile u128 *ptr, u128 old, u128 new) \ +{ \ + union __u128_halves r, o = { .full = (old) }, \ + n = { .full = (new) }; \ + unsigned int tmp; \ + \ + asm volatile("// __cmpxchg128" #name "\n" \ + " prfm pstl1strm, %[v]\n" \ + "1: ldxp %[rl], %[rh], %[v]\n" \ + " cmp %[rl], %[ol]\n" \ + " ccmp %[rh], %[oh], 0, eq\n" \ + " b.ne 2f\n" \ + " st" #rel "xp %w[tmp], %[nl], %[nh], %[v]\n" \ + " cbnz %w[tmp], 1b\n" \ + " " #mb "\n" \ + "2:" \ + : [v] "+Q" (*(u128 *)ptr), \ + [rl] "=&r" (r.low), [rh] "=&r" (r.high), \ + [tmp] "=&r" (tmp) \ + : [ol] "r" (o.low), [oh] "r" (o.high), \ + [nl] "r" (n.low), [nh] "r" (n.high) \ + : "cc", ##cl); \ + \ + return r.full; \ +} + +__CMPXCHG128( , , ) +__CMPXCHG128(_mb, dmb ish, l, "memory") + +#undef __CMPXCHG128 +#undef K#endif /* __ASM_ATOMIC_LL_SC_H */
arch/arm64/include/asm/atomic_lse.h +31 -0
@@ -317,4 +317,35 @@ __CMPXCHG_DBL(_mb, al, "memory")#undef __CMPXCHG_DBL +#define __CMPXCHG128(name, mb, cl...) \ +static __always_inline u128 \ +__lse__cmpxchg128##name(volatile u128 *ptr, u128 old, u128 new) \ +{ \ + union __u128_halves r, o = { .full = (old) }, \ + n = { .full = (new) }; \ + register unsigned long x0 asm ("x0") = o.low; \ + register unsigned long x1 asm ("x1") = o.high; \ + register unsigned long x2 asm ("x2") = n.low; \ + register unsigned long x3 asm ("x3") = n.high; \ + register unsigned long x4 asm ("x4") = (unsigned long)ptr; \ + \ + asm volatile( \ + __LSE_PREAMBLE \ + " casp" #mb "\t%[old1], %[old2], %[new1], %[new2], %[v]\n"\ + : [old1] "+&r" (x0), [old2] "+&r" (x1), \ + [v] "+Q" (*(u128 *)ptr) \ + : [new1] "r" (x2), [new2] "r" (x3), [ptr] "r" (x4), \ + [oldval1] "r" (o.low), [oldval2] "r" (o.high) \ + : cl); \ + \ + r.low = x0; r.high = x1; \ + \ + return r.full; \ +} + +__CMPXCHG128( , ) +__CMPXCHG128(_mb, al, "memory") + +#undef __CMPXCHG128 +#endif /* __ASM_ATOMIC_LSE_H */
arch/arm64/include/asm/cmpxchg.h +26 -0
@@ -146,6 +146,19 @@ __CMPXCHG_DBL(_mb)#undef __CMPXCHG_DBL +#define __CMPXCHG128 (name) \ +static inline u128 __cmpxchg128##name(volatile u128 *ptr, \ + u128 old, u128 new) \ +{ \ + return __lse_ll_sc_body(_cmpxchg128##name, \ + ptr, old, new); \ +} + +__CMPXCHG128( ) +__CMPXCHG128(_mb) + +#undef __CMPXCHG128 +#define __CMPXCHG_GEN (sfx) \ static __always_inline unsigned long __cmpxchg##sfx(volatile void *ptr, \ unsigned long old, \
@@ -228,6 +241,19 @@ __CMPXCHG_GEN(_mb) __ret; \ }) +/* cmpxchg128 */ +#define system_has_cmpxchg128 () 1 + +#define arch_cmpxchg128 (ptr, o, n) \ +({ \ + __cmpxchg128_mb((ptr), (o), (n)); \ +}) + +#define arch_cmpxchg128_local (ptr, o, n) \ +({ \ + __cmpxchg128((ptr), (o), (n)); \ +}) +#define __CMPWAIT_CASE (w, sfx, sz) \ static inline void __cmpwait_case_##sz(volatile void *ptr, \ unsigned long val) \
arch/s390/include/asm/cmpxchg.h +14 -0
@@ -224,4 +224,18 @@ static __always_inline int __cmpxchg_double(unsigned long p1, unsigned long p2, (unsigned long)(n1), (unsigned long)(n2)); \ }) +#define system_has_cmpxchg128 () 1 + +static __always_inline u128 arch_cmpxchg128(volatile u128 *ptr, u128 old, u128 new) +{ + asmvolatile ( +" cdsg %[old],%[new],%[ptr]\n" + : [old]"+d" (old), [ptr]"+QS" (*ptr) + : [new]"d" (new) + :"memory" ,"cc" ); +return old; +} + +#define arch_cmpxchg128 arch_cmpxchg128 +#endif /* __ASM_CMPXCHG_H */
arch/x86/include/asm/cmpxchg_32.h +2 -1
@@ -103,6 +103,7 @@ static inline bool __try_cmpxchg64(volatile u64 *ptr, u64 *pold, u64 new)#endif -#define system_has_cmpxchg_double () boot_cpu_has(X86_FEATURE_CX8) +#define system_has_cmpxchg_double () boot_cpu_has(X86_FEATURE_CX8) +#define system_has_cmpxchg64 () boot_cpu_has(X86_FEATURE_CX8)#endif /* _ASM_X86_CMPXCHG_32_H */
arch/x86/include/asm/cmpxchg_64.h +63 -1
69 lines not on this page · raw message
Peter Zijlstra
maintainerPATCH v3 4/11 instrumentation: Wire up cmpxchg128()
In reply to Peter ZijlstraWire up the cmpxchg128 family in the atomic wrapper scripts.
These provide the generic cmpxchg128 family of functions from the arch_ prefixed version, adding explicit instrumentation where needed.
--- include/linux/atomic/atomic-arch-fallback.h | 95 +++++++++++++++++++++++++++- include/linux/atomic/atomic-instrumented.h | 86 +++++++++++++++++++++++++ scripts/atomic/gen-atomic-fallback.sh | 4 - scripts/atomic/gen-atomic-instrumented.sh | 4 - 4 files changed, 183 insertions(+), 6 deletions(-)
include/linux/atomic/atomic-arch-fallback.h +94 -1
@@ -77,6 +77,29 @@#endif /* arch_cmpxchg64_relaxed */ +#ifndef arch_cmpxchg128_relaxed +#define arch_cmpxchg128_acquire arch_cmpxchg128 +#define arch_cmpxchg128_release arch_cmpxchg128 +#define arch_cmpxchg128_relaxed arch_cmpxchg128 +#else /* arch_cmpxchg128_relaxed */ + +#ifndef arch_cmpxchg128_acquire +#define arch_cmpxchg128_acquire (...) \ + __atomic_op_acquire(arch_cmpxchg128, __VA_ARGS__) +#endif + +#ifndef arch_cmpxchg128_release +#define arch_cmpxchg128_release (...) \ + __atomic_op_release(arch_cmpxchg128, __VA_ARGS__) +#endif + +#ifndef arch_cmpxchg128 +#define arch_cmpxchg128 (...) \ + __atomic_op_fence(arch_cmpxchg128, __VA_ARGS__) +#endif + +#endif /* arch_cmpxchg128_relaxed */ +#ifndef arch_try_cmpxchg_relaxed#ifdef arch_try_cmpxchg#define arch_try_cmpxchg_acquire arch_try_cmpxchg
@@ -217,6 +240,76 @@#endif /* arch_try_cmpxchg64_relaxed */ +#ifndef arch_try_cmpxchg128_relaxed +#ifdef arch_try_cmpxchg128 +#define arch_try_cmpxchg128_acquire arch_try_cmpxchg128 +#define arch_try_cmpxchg128_release arch_try_cmpxchg128 +#define arch_try_cmpxchg128_relaxed arch_try_cmpxchg128 +#endif /* arch_try_cmpxchg128 */ + +#ifndef arch_try_cmpxchg128 +#define arch_try_cmpxchg128 (_ptr, _oldp, _new) \ +({ \ + typeof(*(_ptr)) *___op = (_oldp), ___o = *___op, ___r; \ + ___r = arch_cmpxchg128((_ptr), ___o, (_new)); \ + if (unlikely(___r != ___o)) \ + *___op = ___r; \ + likely(___r == ___o); \ +}) +#endif /* arch_try_cmpxchg128 */ + +#ifndef arch_try_cmpxchg128_acquire +#define arch_try_cmpxchg128_acquire (_ptr, _oldp, _new) \ +({ \ + typeof(*(_ptr)) *___op = (_oldp), ___o = *___op, ___r; \ + ___r = arch_cmpxchg128_acquire((_ptr), ___o, (_new)); \ + if (unlikely(___r != ___o)) \ + *___op = ___r; \ + likely(___r == ___o); \ +}) +#endif /* arch_try_cmpxchg128_acquire */ + +#ifndef arch_try_cmpxchg128_release +#define arch_try_cmpxchg128_release (_ptr, _oldp, _new) \ +({ \ + typeof(*(_ptr)) *___op = (_oldp), ___o = *___op, ___r; \ + ___r = arch_cmpxchg128_release((_ptr), ___o, (_new)); \ + if (unlikely(___r != ___o)) \ + *___op = ___r; \ + likely(___r == ___o); \ +}) +#endif /* arch_try_cmpxchg128_release */ + +#ifndef arch_try_cmpxchg128_relaxed +#define arch_try_cmpxchg128_relaxed (_ptr, _oldp, _new) \ +({ \ + typeof(*(_ptr)) *___op = (_oldp), ___o = *___op, ___r; \ + ___r = arch_cmpxchg128_relaxed((_ptr), ___o, (_new)); \ + if (unlikely(___r != ___o)) \ + *___op = ___r; \ + likely(___r == ___o); \ +}) +#endif /* arch_try_cmpxchg128_relaxed */ + +#else /* arch_try_cmpxchg128_relaxed */ + +#ifndef arch_try_cmpxchg128_acquire +#define arch_try_cmpxchg128_acquire (...) \ + __atomic_op_acquire(arch_try_cmpxchg128, __VA_ARGS__) +#endif + +#ifndef arch_try_cmpxchg128_release +#define arch_try_cmpxchg128_release (...) \ + __atomic_op_release(arch_try_cmpxchg128, __VA_ARGS__) +#endif + +#ifndef arch_try_cmpxchg128 +#define arch_try_cmpxchg128 (...) \ + __atomic_op_fence(arch_try_cmpxchg128, __VA_ARGS__) +#endif + +#endif /* arch_try_cmpxchg128_relaxed */ +#ifndef arch_try_cmpxchg_local#define arch_try_cmpxchg_local (_ptr, _oldp, _new) \ ({ \
@@ -2668,4 +2761,4 @@ arch_atomic64_dec_if_positive(atomic64_t#endif #endif /* _LINUX_ATOMIC_FALLBACK_H */ -// ad2e2b4d168dbc60a73922616047a9bfa446af36 +// 52dfc6fe4a2e7234bbd2aa3e16a377c1db793a53
include/linux/atomic/atomic-instrumented.h +85 -1
113 lines not on this page · raw message
scripts/atomic/gen-atomic-fallback.sh +2 -2
@@ -217,11 +217,11 @@ cat << EOF EOF -for xchg in "arch_xchg" "arch_cmpxchg" "arch_cmpxchg64"; do +for xchg in "arch_xchg" "arch_cmpxchg" "arch_cmpxchg64" "arch_cmpxchg128"; do gen_xchg_fallbacks "${xchg}" done -for cmpxchg in "cmpxchg" "cmpxchg64"; do +for cmpxchg in "cmpxchg" "cmpxchg64" "cmpxchg128"; do gen_try_cmpxchg_fallbacks "${cmpxchg}" done
scripts/atomic/gen-atomic-instrumented.sh +2 -2
@@ -166,14 +166,14 @@ grep '^[a-z]' "$1" | while read name met done -for xchg in "xchg" "cmpxchg" "cmpxchg64" "try_cmpxchg" "try_cmpxchg64"; do +for xchg in "xchg" "cmpxchg" "cmpxchg64" "cmpxchg128" "try_cmpxchg" "try_cmpxchg64" "try_cmpxchg128"; do for order in "" "_acquire" "_release" "_relaxed"; do gen_xchg "${xchg}" "${order}" "" printf "\n" done done -for xchg in "cmpxchg_local" "cmpxchg64_local" "sync_cmpxchg" "try_cmpxchg_local" "try_cmpxchg64_local" ; do +for xchg in "cmpxchg_local" "cmpxchg64_local" "cmpxchg128_local" "sync_cmpxchg" "try_cmpxchg_local" "try_cmpxchg64_local" "try_cmpxchg128_local"; do gen_xchg "${xchg}" "" "" printf "\n" done
[tip: locking/core] instrumentation: Wire up cmpxchg128()
The following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 2dfdbe12758bbc435af489e3ee167dbfab7d66be Gitweb: https://git.kernel.org/tip/2dfdbe12758bbc435af489e3ee167dbfab7d66be Author: Peter Zijlstra <[email protected]> AuthorDate: Mon, 15 May 2023 09:57:03 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 19 May 2023 12:35:12 +02:00
instrumentation: Wire up cmpxchg128()
Wire up the cmpxchg128 family in the atomic wrapper scripts.
These provide the generic cmpxchg128 family of functions from the arch_ prefixed version, adding explicit instrumentation where needed.
--- include/linux/atomic/atomic-arch-fallback.h | 95 +++++++++++++++++++- include/linux/atomic/atomic-instrumented.h | 86 +++++++++++++++++- scripts/atomic/gen-atomic-fallback.sh | 4 +- scripts/atomic/gen-atomic-instrumented.sh | 4 +- 4 files changed, 183 insertions(+), 6 deletions(-)
include/linux/atomic/atomic-arch-fallback.h +94 -1
@@ -77,6 +77,29 @@#endif /* arch_cmpxchg64_relaxed */ +#ifndef arch_cmpxchg128_relaxed +#define arch_cmpxchg128_acquire arch_cmpxchg128 +#define arch_cmpxchg128_release arch_cmpxchg128 +#define arch_cmpxchg128_relaxed arch_cmpxchg128 +#else /* arch_cmpxchg128_relaxed */ + +#ifndef arch_cmpxchg128_acquire +#define arch_cmpxchg128_acquire (...) \ + __atomic_op_acquire(arch_cmpxchg128, __VA_ARGS__) +#endif + +#ifndef arch_cmpxchg128_release +#define arch_cmpxchg128_release (...) \ + __atomic_op_release(arch_cmpxchg128, __VA_ARGS__) +#endif + +#ifndef arch_cmpxchg128 +#define arch_cmpxchg128 (...) \ + __atomic_op_fence(arch_cmpxchg128, __VA_ARGS__) +#endif + +#endif /* arch_cmpxchg128_relaxed */ +#ifndef arch_try_cmpxchg_relaxed#ifdef arch_try_cmpxchg#define arch_try_cmpxchg_acquire arch_try_cmpxchg
@@ -217,6 +240,76 @@#endif /* arch_try_cmpxchg64_relaxed */ +#ifndef arch_try_cmpxchg128_relaxed +#ifdef arch_try_cmpxchg128 +#define arch_try_cmpxchg128_acquire arch_try_cmpxchg128 +#define arch_try_cmpxchg128_release arch_try_cmpxchg128 +#define arch_try_cmpxchg128_relaxed arch_try_cmpxchg128 +#endif /* arch_try_cmpxchg128 */ + +#ifndef arch_try_cmpxchg128 +#define arch_try_cmpxchg128 (_ptr, _oldp, _new) \ +({ \ + typeof(*(_ptr)) *___op = (_oldp), ___o = *___op, ___r; \ + ___r = arch_cmpxchg128((_ptr), ___o, (_new)); \ + if (unlikely(___r != ___o)) \ + *___op = ___r; \ + likely(___r == ___o); \ +}) +#endif /* arch_try_cmpxchg128 */ + +#ifndef arch_try_cmpxchg128_acquire +#define arch_try_cmpxchg128_acquire (_ptr, _oldp, _new) \ +({ \ + typeof(*(_ptr)) *___op = (_oldp), ___o = *___op, ___r; \ + ___r = arch_cmpxchg128_acquire((_ptr), ___o, (_new)); \ + if (unlikely(___r != ___o)) \ + *___op = ___r; \ + likely(___r == ___o); \ +}) +#endif /* arch_try_cmpxchg128_acquire */ + +#ifndef arch_try_cmpxchg128_release +#define arch_try_cmpxchg128_release (_ptr, _oldp, _new) \ +({ \ + typeof(*(_ptr)) *___op = (_oldp), ___o = *___op, ___r; \ + ___r = arch_cmpxchg128_release((_ptr), ___o, (_new)); \ + if (unlikely(___r != ___o)) \ + *___op = ___r; \ + likely(___r == ___o); \ +}) +#endif /* arch_try_cmpxchg128_release */ + +#ifndef arch_try_cmpxchg128_relaxed +#define arch_try_cmpxchg128_relaxed (_ptr, _oldp, _new) \ +({ \ + typeof(*(_ptr)) *___op = (_oldp), ___o = *___op, ___r; \ + ___r = arch_cmpxchg128_relaxed((_ptr), ___o, (_new)); \ + if (unlikely(___r != ___o)) \ + *___op = ___r; \ + likely(___r == ___o); \ +}) +#endif /* arch_try_cmpxchg128_relaxed */ + +#else /* arch_try_cmpxchg128_relaxed */ + +#ifndef arch_try_cmpxchg128_acquire +#define arch_try_cmpxchg128_acquire (...) \ + __atomic_op_acquire(arch_try_cmpxchg128, __VA_ARGS__) +#endif + +#ifndef arch_try_cmpxchg128_release +#define arch_try_cmpxchg128_release (...) \ + __atomic_op_release(arch_try_cmpxchg128, __VA_ARGS__) +#endif + +#ifndef arch_try_cmpxchg128 +#define arch_try_cmpxchg128 (...) \ + __atomic_op_fence(arch_try_cmpxchg128, __VA_ARGS__) +#endif + +#endif /* arch_try_cmpxchg128_relaxed */ +#ifndef arch_try_cmpxchg_local#define arch_try_cmpxchg_local (_ptr, _oldp, _new) \ ({ \
@@ -2668,4 +2761,4 @@ arch_atomic64_dec_if_positive(atomic64_t *v)#endif #endif /* _LINUX_ATOMIC_FALLBACK_H */ -// ad2e2b4d168dbc60a73922616047a9bfa446af36 +// 52dfc6fe4a2e7234bbd2aa3e16a377c1db793a53
include/linux/atomic/atomic-instrumented.h +85 -1
113 lines not on this page · raw message
scripts/atomic/gen-atomic-fallback.sh +2 -2
@@ -217,11 +217,11 @@ cat << EOF EOF -for xchg in "arch_xchg" "arch_cmpxchg" "arch_cmpxchg64"; do +for xchg in "arch_xchg" "arch_cmpxchg" "arch_cmpxchg64" "arch_cmpxchg128"; do gen_xchg_fallbacks "${xchg}" done -for cmpxchg in "cmpxchg" "cmpxchg64"; do +for cmpxchg in "cmpxchg" "cmpxchg64" "cmpxchg128"; do gen_try_cmpxchg_fallbacks "${cmpxchg}" done
scripts/atomic/gen-atomic-instrumented.sh +2 -2
@@ -166,14 +166,14 @@ grep '^[a-z]' "$1" | while read name meta args; do done -for xchg in "xchg" "cmpxchg" "cmpxchg64" "try_cmpxchg" "try_cmpxchg64"; do +for xchg in "xchg" "cmpxchg" "cmpxchg64" "cmpxchg128" "try_cmpxchg" "try_cmpxchg64" "try_cmpxchg128"; do for order in "" "_acquire" "_release" "_relaxed"; do gen_xchg "${xchg}" "${order}" "" printf "\n" done done -for xchg in "cmpxchg_local" "cmpxchg64_local" "sync_cmpxchg" "try_cmpxchg_local" "try_cmpxchg64_local" ; do +for xchg in "cmpxchg_local" "cmpxchg64_local" "cmpxchg128_local" "sync_cmpxchg" "try_cmpxchg_local" "try_cmpxchg64_local" "try_cmpxchg128_local"; do gen_xchg "${xchg}" "" "" printf "\n" done
[tip: locking/core] instrumentation: Wire up cmpxchg128()
In reply to Peter ZijlstraThe following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: cfce96506621b91e3d0bd59b78a4997d0614c413 Gitweb: https://git.kernel.org/tip/cfce96506621b91e3d0bd59b78a4997d0614c413 Author: Peter Zijlstra <[email protected]> AuthorDate: Mon, 15 May 2023 09:57:03 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Mon, 22 May 2023 10:49:49 +02:00
instrumentation: Wire up cmpxchg128()
Wire up the cmpxchg128 family in the atomic wrapper scripts.
These provide the generic cmpxchg128 family of functions from the arch_ prefixed version, adding explicit instrumentation where needed.
--- include/linux/atomic/atomic-arch-fallback.h | 95 +++++++++++++++++++- include/linux/atomic/atomic-instrumented.h | 86 +++++++++++++++++- scripts/atomic/gen-atomic-fallback.sh | 4 +- scripts/atomic/gen-atomic-instrumented.sh | 4 +- 4 files changed, 183 insertions(+), 6 deletions(-)
include/linux/atomic/atomic-arch-fallback.h +94 -1
@@ -77,6 +77,29 @@#endif /* arch_cmpxchg64_relaxed */ +#ifndef arch_cmpxchg128_relaxed +#define arch_cmpxchg128_acquire arch_cmpxchg128 +#define arch_cmpxchg128_release arch_cmpxchg128 +#define arch_cmpxchg128_relaxed arch_cmpxchg128 +#else /* arch_cmpxchg128_relaxed */ + +#ifndef arch_cmpxchg128_acquire +#define arch_cmpxchg128_acquire (...) \ + __atomic_op_acquire(arch_cmpxchg128, __VA_ARGS__) +#endif + +#ifndef arch_cmpxchg128_release +#define arch_cmpxchg128_release (...) \ + __atomic_op_release(arch_cmpxchg128, __VA_ARGS__) +#endif + +#ifndef arch_cmpxchg128 +#define arch_cmpxchg128 (...) \ + __atomic_op_fence(arch_cmpxchg128, __VA_ARGS__) +#endif + +#endif /* arch_cmpxchg128_relaxed */ +#ifndef arch_try_cmpxchg_relaxed#ifdef arch_try_cmpxchg#define arch_try_cmpxchg_acquire arch_try_cmpxchg
@@ -217,6 +240,76 @@#endif /* arch_try_cmpxchg64_relaxed */ +#ifndef arch_try_cmpxchg128_relaxed +#ifdef arch_try_cmpxchg128 +#define arch_try_cmpxchg128_acquire arch_try_cmpxchg128 +#define arch_try_cmpxchg128_release arch_try_cmpxchg128 +#define arch_try_cmpxchg128_relaxed arch_try_cmpxchg128 +#endif /* arch_try_cmpxchg128 */ + +#ifndef arch_try_cmpxchg128 +#define arch_try_cmpxchg128 (_ptr, _oldp, _new) \ +({ \ + typeof(*(_ptr)) *___op = (_oldp), ___o = *___op, ___r; \ + ___r = arch_cmpxchg128((_ptr), ___o, (_new)); \ + if (unlikely(___r != ___o)) \ + *___op = ___r; \ + likely(___r == ___o); \ +}) +#endif /* arch_try_cmpxchg128 */ + +#ifndef arch_try_cmpxchg128_acquire +#define arch_try_cmpxchg128_acquire (_ptr, _oldp, _new) \ +({ \ + typeof(*(_ptr)) *___op = (_oldp), ___o = *___op, ___r; \ + ___r = arch_cmpxchg128_acquire((_ptr), ___o, (_new)); \ + if (unlikely(___r != ___o)) \ + *___op = ___r; \ + likely(___r == ___o); \ +}) +#endif /* arch_try_cmpxchg128_acquire */ + +#ifndef arch_try_cmpxchg128_release +#define arch_try_cmpxchg128_release (_ptr, _oldp, _new) \ +({ \ + typeof(*(_ptr)) *___op = (_oldp), ___o = *___op, ___r; \ + ___r = arch_cmpxchg128_release((_ptr), ___o, (_new)); \ + if (unlikely(___r != ___o)) \ + *___op = ___r; \ + likely(___r == ___o); \ +}) +#endif /* arch_try_cmpxchg128_release */ + +#ifndef arch_try_cmpxchg128_relaxed +#define arch_try_cmpxchg128_relaxed (_ptr, _oldp, _new) \ +({ \ + typeof(*(_ptr)) *___op = (_oldp), ___o = *___op, ___r; \ + ___r = arch_cmpxchg128_relaxed((_ptr), ___o, (_new)); \ + if (unlikely(___r != ___o)) \ + *___op = ___r; \ + likely(___r == ___o); \ +}) +#endif /* arch_try_cmpxchg128_relaxed */ + +#else /* arch_try_cmpxchg128_relaxed */ + +#ifndef arch_try_cmpxchg128_acquire +#define arch_try_cmpxchg128_acquire (...) \ + __atomic_op_acquire(arch_try_cmpxchg128, __VA_ARGS__) +#endif + +#ifndef arch_try_cmpxchg128_release +#define arch_try_cmpxchg128_release (...) \ + __atomic_op_release(arch_try_cmpxchg128, __VA_ARGS__) +#endif + +#ifndef arch_try_cmpxchg128 +#define arch_try_cmpxchg128 (...) \ + __atomic_op_fence(arch_try_cmpxchg128, __VA_ARGS__) +#endif + +#endif /* arch_try_cmpxchg128_relaxed */ +#ifndef arch_try_cmpxchg_local#define arch_try_cmpxchg_local (_ptr, _oldp, _new) \ ({ \
@@ -2668,4 +2761,4 @@ arch_atomic64_dec_if_positive(atomic64_t *v)#endif #endif /* _LINUX_ATOMIC_FALLBACK_H */ -// ad2e2b4d168dbc60a73922616047a9bfa446af36 +// 52dfc6fe4a2e7234bbd2aa3e16a377c1db793a53
include/linux/atomic/atomic-instrumented.h +85 -1
113 lines not on this page · raw message
scripts/atomic/gen-atomic-fallback.sh +2 -2
@@ -217,11 +217,11 @@ cat << EOF EOF -for xchg in "arch_xchg" "arch_cmpxchg" "arch_cmpxchg64"; do +for xchg in "arch_xchg" "arch_cmpxchg" "arch_cmpxchg64" "arch_cmpxchg128"; do gen_xchg_fallbacks "${xchg}" done -for cmpxchg in "cmpxchg" "cmpxchg64"; do +for cmpxchg in "cmpxchg" "cmpxchg64" "cmpxchg128"; do gen_try_cmpxchg_fallbacks "${cmpxchg}" done
scripts/atomic/gen-atomic-instrumented.sh +2 -2
@@ -166,14 +166,14 @@ grep '^[a-z]' "$1" | while read name meta args; do done -for xchg in "xchg" "cmpxchg" "cmpxchg64" "try_cmpxchg" "try_cmpxchg64"; do +for xchg in "xchg" "cmpxchg" "cmpxchg64" "cmpxchg128" "try_cmpxchg" "try_cmpxchg64" "try_cmpxchg128"; do for order in "" "_acquire" "_release" "_relaxed"; do gen_xchg "${xchg}" "${order}" "" printf "\n" done done -for xchg in "cmpxchg_local" "cmpxchg64_local" "sync_cmpxchg" "try_cmpxchg_local" "try_cmpxchg64_local" ; do +for xchg in "cmpxchg_local" "cmpxchg64_local" "cmpxchg128_local" "sync_cmpxchg" "try_cmpxchg_local" "try_cmpxchg64_local" "try_cmpxchg128_local"; do gen_xchg "${xchg}" "" "" printf "\n" done
Peter Zijlstra
maintainerPATCH v3 5/11 percpu: Wire up cmpxchg128
In reply to Peter ZijlstraIn order to replace cmpxchg_double() with the newly minted cmpxchg128() family of functions, wire it up in this_cpu_cmpxchg().
--- arch/arm64/include/asm/percpu.h | 20 +++++++++++++ arch/s390/include/asm/percpu.h | 16 ++++++++++ arch/x86/include/asm/percpu.h | 59 ++++++++++++++++++++++++++++++++++++++++ include/asm-generic/percpu.h | 16 ++++++++++ 4 files changed, 111 insertions(+)
arch/arm64/include/asm/percpu.h +20 -0
@@ -140,6 +140,10 @@ PERCPU_RET_OP(add, add, ldadd)* re-enabling preemption for preemptible kernels, but doing that in a way * which builds inside a module would mean messing directly with the preempt * count. If you do this, peterz and tglx will hunt you down. +* +* Not to mention it'll break the actual preemption model for missing a +* preemption point when TIF_NEED_RESCHED gets set while preemption is +* disabled. */ #define this_cpu_cmpxchg_double_8 (ptr1, ptr2, o1, o2, n1, n2) \ ({ \
@@ -240,6 +244,22 @@ PERCPU_RET_OP(add, add, ldadd)#define this_cpu_cmpxchg_8 (pcp, o, n) \ _pcp_protect_return(cmpxchg_relaxed, pcp, o, n) +#define this_cpu_cmpxchg64 (pcp, o, n) this_cpu_cmpxchg_8(pcp, o, n) + +#define this_cpu_cmpxchg128 (pcp, o, n) \ +({ \ + typedef typeof(pcp) pcp_op_T__; \ + u128 old__, new__, ret__; \ + pcp_op_T__ *ptr__; \ + old__ = o; \ + new__ = n; \ + preempt_disable_notrace(); \ + ptr__ = raw_cpu_ptr(&(pcp)); \ + ret__ = cmpxchg128_local((void *)ptr__, old__, new__); \ + preempt_enable_notrace(); \ + ret__; \ +}) +#ifdef __KVM_NVHE_HYPERVISOR__extern unsigned long __hyp_per_cpu_offset (unsigned int cpu);#define __per_cpu_offset
arch/s390/include/asm/percpu.h +16 -0
@@ -148,6 +148,22 @@#define this_cpu_cmpxchg_4 (pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval)#define this_cpu_cmpxchg_8 (pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval) +#define this_cpu_cmpxchg64 (pcp, o, n) this_cpu_cmpxchg_8(pcp, o, n) + +#define this_cpu_cmpxchg128 (pcp, oval, nval) \ +({ \ + typedef typeof(pcp) pcp_op_T__; \ + u128 old__, new__, ret__; \ + pcp_op_T__ *ptr__; \ + old__ = oval; \ + new__ = nval; \ + preempt_disable_notrace(); \ + ptr__ = raw_cpu_ptr(&(pcp)); \ + ret__ = cmpxchg128((void *)ptr__, old__, new__); \ + preempt_enable_notrace(); \ + ret__; \ +}) +#define arch_this_cpu_xchg (pcp, nval) \ ({ \ typeof(pcp) *ptr__; \
arch/x86/include/asm/percpu.h +59 -0
65 lines not on this page · raw message
include/asm-generic/percpu.h +16 -0
@@ -298,6 +298,14 @@ do { \#define raw_cpu_cmpxchg_8 (pcp, oval, nval) \ raw_cpu_generic_cmpxchg(pcp, oval, nval)#endif +#ifndef raw_cpu_cmpxchg64 +#define raw_cpu_cmpxchg64 (pcp, oval, nval) \ + raw_cpu_generic_cmpxchg(pcp, oval, nval) +#endif +#ifndef raw_cpu_cmpxchg128 +#define raw_cpu_cmpxchg128 (pcp, oval, nval) \ + raw_cpu_generic_cmpxchg(pcp, oval, nval) +#endif #ifndef raw_cpu_cmpxchg_double_1#define raw_cpu_cmpxchg_double_1 (pcp1, pcp2, oval1, oval2, nval1, nval2) \
@@ -423,6 +431,14 @@ do { \#define this_cpu_cmpxchg_8 (pcp, oval, nval) \ this_cpu_generic_cmpxchg(pcp, oval, nval)#endif +#ifndef this_cpu_cmpxchg64 +#define this_cpu_cmpxchg64 (pcp, oval, nval) \ + this_cpu_generic_cmpxchg(pcp, oval, nval) +#endif +#ifndef this_cpu_cmpxchg128 +#define this_cpu_cmpxchg128 (pcp, oval, nval) \ + this_cpu_generic_cmpxchg(pcp, oval, nval) +#endif #ifndef this_cpu_cmpxchg_double_1#define this_cpu_cmpxchg_double_1 (pcp1, pcp2, oval1, oval2, nval1, nval2) \
[tip: locking/core] percpu: Wire up cmpxchg128
The following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 58e59a577359bd13d2219f5db064af41af68011e Gitweb: https://git.kernel.org/tip/58e59a577359bd13d2219f5db064af41af68011e Author: Peter Zijlstra <[email protected]> AuthorDate: Mon, 15 May 2023 09:57:04 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 19 May 2023 12:35:13 +02:00
percpu: Wire up cmpxchg128
In order to replace cmpxchg_double() with the newly minted cmpxchg128() family of functions, wire it up in this_cpu_cmpxchg().
--- arch/arm64/include/asm/percpu.h | 20 +++++++++++- arch/s390/include/asm/percpu.h | 16 +++++++++- arch/x86/include/asm/percpu.h | 59 ++++++++++++++++++++++++++++++++- include/asm-generic/percpu.h | 16 +++++++++- 4 files changed, 111 insertions(+)
arch/arm64/include/asm/percpu.h +20 -0
@@ -140,6 +140,10 @@ PERCPU_RET_OP(add, add, ldadd)* re-enabling preemption for preemptible kernels, but doing that in a way * which builds inside a module would mean messing directly with the preempt * count. If you do this, peterz and tglx will hunt you down. +* +* Not to mention it'll break the actual preemption model for missing a +* preemption point when TIF_NEED_RESCHED gets set while preemption is +* disabled. */ #define this_cpu_cmpxchg_double_8 (ptr1, ptr2, o1, o2, n1, n2) \ ({ \
@@ -240,6 +244,22 @@ PERCPU_RET_OP(add, add, ldadd)#define this_cpu_cmpxchg_8 (pcp, o, n) \ _pcp_protect_return(cmpxchg_relaxed, pcp, o, n) +#define this_cpu_cmpxchg64 (pcp, o, n) this_cpu_cmpxchg_8(pcp, o, n) + +#define this_cpu_cmpxchg128 (pcp, o, n) \ +({ \ + typedef typeof(pcp) pcp_op_T__; \ + u128 old__, new__, ret__; \ + pcp_op_T__ *ptr__; \ + old__ = o; \ + new__ = n; \ + preempt_disable_notrace(); \ + ptr__ = raw_cpu_ptr(&(pcp)); \ + ret__ = cmpxchg128_local((void *)ptr__, old__, new__); \ + preempt_enable_notrace(); \ + ret__; \ +}) +#ifdef __KVM_NVHE_HYPERVISOR__extern unsigned long __hyp_per_cpu_offset (unsigned int cpu);#define __per_cpu_offset
arch/s390/include/asm/percpu.h +16 -0
@@ -148,6 +148,22 @@#define this_cpu_cmpxchg_4 (pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval)#define this_cpu_cmpxchg_8 (pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval) +#define this_cpu_cmpxchg64 (pcp, o, n) this_cpu_cmpxchg_8(pcp, o, n) + +#define this_cpu_cmpxchg128 (pcp, oval, nval) \ +({ \ + typedef typeof(pcp) pcp_op_T__; \ + u128 old__, new__, ret__; \ + pcp_op_T__ *ptr__; \ + old__ = oval; \ + new__ = nval; \ + preempt_disable_notrace(); \ + ptr__ = raw_cpu_ptr(&(pcp)); \ + ret__ = cmpxchg128((void *)ptr__, old__, new__); \ + preempt_enable_notrace(); \ + ret__; \ +}) +#define arch_this_cpu_xchg (pcp, nval) \ ({ \ typeof(pcp) *ptr__; \
arch/x86/include/asm/percpu.h +59 -0
65 lines not on this page · raw message
include/asm-generic/percpu.h +16 -0
@@ -298,6 +298,14 @@ do { \#define raw_cpu_cmpxchg_8 (pcp, oval, nval) \ raw_cpu_generic_cmpxchg(pcp, oval, nval)#endif +#ifndef raw_cpu_cmpxchg64 +#define raw_cpu_cmpxchg64 (pcp, oval, nval) \ + raw_cpu_generic_cmpxchg(pcp, oval, nval) +#endif +#ifndef raw_cpu_cmpxchg128 +#define raw_cpu_cmpxchg128 (pcp, oval, nval) \ + raw_cpu_generic_cmpxchg(pcp, oval, nval) +#endif #ifndef raw_cpu_cmpxchg_double_1#define raw_cpu_cmpxchg_double_1 (pcp1, pcp2, oval1, oval2, nval1, nval2) \
@@ -423,6 +431,14 @@ do { \#define this_cpu_cmpxchg_8 (pcp, oval, nval) \ this_cpu_generic_cmpxchg(pcp, oval, nval)#endif +#ifndef this_cpu_cmpxchg64 +#define this_cpu_cmpxchg64 (pcp, oval, nval) \ + this_cpu_generic_cmpxchg(pcp, oval, nval) +#endif +#ifndef this_cpu_cmpxchg128 +#define this_cpu_cmpxchg128 (pcp, oval, nval) \ + this_cpu_generic_cmpxchg(pcp, oval, nval) +#endif #ifndef this_cpu_cmpxchg_double_1#define this_cpu_cmpxchg_double_1 (pcp1, pcp2, oval1, oval2, nval1, nval2) \
[tip: locking/core] percpu: Wire up cmpxchg128
In reply to Peter ZijlstraThe following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: fed3b1fae1030f87828ff000c69077d660f3bdf3 Gitweb: https://git.kernel.org/tip/fed3b1fae1030f87828ff000c69077d660f3bdf3 Author: Peter Zijlstra <[email protected]> AuthorDate: Mon, 15 May 2023 09:57:04 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Mon, 22 May 2023 10:49:49 +02:00
percpu: Wire up cmpxchg128
In order to replace cmpxchg_double() with the newly minted cmpxchg128() family of functions, wire it up in this_cpu_cmpxchg().
--- arch/arm64/include/asm/percpu.h | 20 +++++++++++- arch/s390/include/asm/percpu.h | 16 +++++++++- arch/x86/include/asm/percpu.h | 59 ++++++++++++++++++++++++++++++++- include/asm-generic/percpu.h | 16 +++++++++- 4 files changed, 111 insertions(+)
arch/arm64/include/asm/percpu.h +20 -0
@@ -140,6 +140,10 @@ PERCPU_RET_OP(add, add, ldadd)* re-enabling preemption for preemptible kernels, but doing that in a way * which builds inside a module would mean messing directly with the preempt * count. If you do this, peterz and tglx will hunt you down. +* +* Not to mention it'll break the actual preemption model for missing a +* preemption point when TIF_NEED_RESCHED gets set while preemption is +* disabled. */ #define this_cpu_cmpxchg_double_8 (ptr1, ptr2, o1, o2, n1, n2) \ ({ \
@@ -240,6 +244,22 @@ PERCPU_RET_OP(add, add, ldadd)#define this_cpu_cmpxchg_8 (pcp, o, n) \ _pcp_protect_return(cmpxchg_relaxed, pcp, o, n) +#define this_cpu_cmpxchg64 (pcp, o, n) this_cpu_cmpxchg_8(pcp, o, n) + +#define this_cpu_cmpxchg128 (pcp, o, n) \ +({ \ + typedef typeof(pcp) pcp_op_T__; \ + u128 old__, new__, ret__; \ + pcp_op_T__ *ptr__; \ + old__ = o; \ + new__ = n; \ + preempt_disable_notrace(); \ + ptr__ = raw_cpu_ptr(&(pcp)); \ + ret__ = cmpxchg128_local((void *)ptr__, old__, new__); \ + preempt_enable_notrace(); \ + ret__; \ +}) +#ifdef __KVM_NVHE_HYPERVISOR__extern unsigned long __hyp_per_cpu_offset (unsigned int cpu);#define __per_cpu_offset
arch/s390/include/asm/percpu.h +16 -0
@@ -148,6 +148,22 @@#define this_cpu_cmpxchg_4 (pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval)#define this_cpu_cmpxchg_8 (pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval) +#define this_cpu_cmpxchg64 (pcp, o, n) this_cpu_cmpxchg_8(pcp, o, n) + +#define this_cpu_cmpxchg128 (pcp, oval, nval) \ +({ \ + typedef typeof(pcp) pcp_op_T__; \ + u128 old__, new__, ret__; \ + pcp_op_T__ *ptr__; \ + old__ = oval; \ + new__ = nval; \ + preempt_disable_notrace(); \ + ptr__ = raw_cpu_ptr(&(pcp)); \ + ret__ = cmpxchg128((void *)ptr__, old__, new__); \ + preempt_enable_notrace(); \ + ret__; \ +}) +#define arch_this_cpu_xchg (pcp, nval) \ ({ \ typeof(pcp) *ptr__; \
arch/x86/include/asm/percpu.h +59 -0
65 lines not on this page · raw message
include/asm-generic/percpu.h +16 -0
@@ -298,6 +298,14 @@ do { \#define raw_cpu_cmpxchg_8 (pcp, oval, nval) \ raw_cpu_generic_cmpxchg(pcp, oval, nval)#endif +#ifndef raw_cpu_cmpxchg64 +#define raw_cpu_cmpxchg64 (pcp, oval, nval) \ + raw_cpu_generic_cmpxchg(pcp, oval, nval) +#endif +#ifndef raw_cpu_cmpxchg128 +#define raw_cpu_cmpxchg128 (pcp, oval, nval) \ + raw_cpu_generic_cmpxchg(pcp, oval, nval) +#endif #ifndef raw_cpu_cmpxchg_double_1#define raw_cpu_cmpxchg_double_1 (pcp1, pcp2, oval1, oval2, nval1, nval2) \
@@ -423,6 +431,14 @@ do { \#define this_cpu_cmpxchg_8 (pcp, oval, nval) \ this_cpu_generic_cmpxchg(pcp, oval, nval)#endif +#ifndef this_cpu_cmpxchg64 +#define this_cpu_cmpxchg64 (pcp, oval, nval) \ + this_cpu_generic_cmpxchg(pcp, oval, nval) +#endif +#ifndef this_cpu_cmpxchg128 +#define this_cpu_cmpxchg128 (pcp, oval, nval) \ + this_cpu_generic_cmpxchg(pcp, oval, nval) +#endif #ifndef this_cpu_cmpxchg_double_1#define this_cpu_cmpxchg_double_1 (pcp1, pcp2, oval1, oval2, nval1, nval2) \
Peter Zijlstra
maintainerRe: [PATCH v3 05/11] percpu: Wire up cmpxchg128
In reply to Peter ZijlstraQuoted 64 lines · Peter Zijlstra
In order to replace
cmpxchg_double()with the newly mintedcmpxchg128()family of functions, wire it up inthis_cpu_cmpxchg().Signed-off-by Peter Zijlstra (Intel) <[email protected]>---
arch/x86/include/asm/percpu.h +52
-0@@ -210,6 +210,65 @@ do { \ (typeof (_var ))(unsigned long ) pco_old__; \ }) +#if defined(CONFIG_X86_32 ) && defined(CONFIG_X86_CMPXCHG64 ) +#define percpu_cmpxchg64_op (size, qual, _var, _oval, _nval) \ +({ \ + union { \ + u64 var; \ + struct { \ + u32 low, high; \ + }; \ + } old__, new__; \ + \ + old__.var = _oval; \ + new__.var = _nval; \ + \ + asm qual ("cmpxchg8b " __percpu_arg([var]) \ + : [var] "+m" (_var), \ + "+a" (old__.low), \ + "+d" (old__.high) \ + : "b" (new__.low), \ + "c" (new__.high) \ + : "memory"); \ + \ + old__.var; \ +}) + +#define raw_cpu_cmpxchg64 (pcp, oval, nval) percpu_cmpxchg64_op(8, , pcp, oval, nval) +#define this_cpu_cmpxchg64 (pcp, oval, nval) percpu_cmpxchg64_op(8, volatile, pcp, oval, nval) +#endif + +#ifdef CONFIG_X86_64 +#define raw_cpu_cmpxchg64 (pcp, oval, nval) percpu_cmpxchg_op(8, , pcp, oval, nval); +#define this_cpu_cmpxchg64 (pcp, oval, nval) percpu_cmpxchg_op(8, volatile, pcp, oval, nval); + +#define percpu_cmpxchg128_op (size, qual, _var, _oval, _nval) \ +({ \ + union { \ + u128 var; \ + struct { \ + u64 low, high; \ + }; \ + } old__, new__; \ + \ + old__.var = _oval; \ + new__.var = _nval; \ + \ + asm qual ("cmpxchg16b " __percpu_arg([var]) \ + : [var] "+m" (_var), \ + "+a" (old__.low), \ + "+d" (old__.high) \ + : "b" (new__.low), \ + "c" (new__.high) \ + : "memory"); \ + \
arch/x86/include/asm/percpu.h do { \ · line 274
Quoted 10 lines
arch/x86/include/asm/percpu.h +7
-0+ old__.var; \ +}) + +#define raw_cpu_cmpxchg128 (pcp, oval, nval) percpu_cmpxchg128_op(16, , pcp, oval, nval) +#define this_cpu_cmpxchg128 (pcp, oval, nval) percpu_cmpxchg128_op(16, volatile, pcp, oval, nval) +#endif +/* * this_cpu_read() makes gcc load the percpu variable every time it is * accessed while this_cpu_read_stable() allows the value to be cached.
Since this_cpu_cmpxchg*() is assumed to always be present (their usage is not guarded with system_has_cmpxchg*() it needs a fallback for then the instruction is not present.
The below has been tested with clearcpuid=cx16; adding an obvious defect in the fallback implemention crashes the kernel, with the code as presented it boots.
Build tested i386-defconfig.
(the things we do for museum pieces :/)
--- include/asm/percpu.h | 25 +++++++++++--------- lib/Makefile | 3 +- lib/cmpxchg16b_emu.S | 43 ++++++++++++++++++++-------------- lib/cmpxchg8b_emu.S | 63 +++++++++++++++++++++++++++++++++++++++------------ 4 files changed, 90 insertions(+), 44 deletions(-)
arch/x86/include/asm/percpu.h +14 -11
@@ -210,7 +210,7 @@ do { \ (typeof (_var ))(unsigned long ) pco_old__; \ }) -#if defined(CONFIG_X86_32 ) && defined(CONFIG_X86_CMPXCHG64 ) +#ifdef CONFIG_X86_32 #define percpu_cmpxchg64_op (size, qual, _var, _oval, _nval) \ ({ \ union { \
@@ -223,13 +223,14 @@ do { \ old__.var = _oval; \ new__.var = _nval; \ \ - asm qual ("cmpxchg8b " __percpu_arg([var]) \ + asm qual (ALTERNATIVE("leal %P[var], %%esi; call this_cpu_cmpxchg8b_emu", \ + "cmpxchg8b " __percpu_arg([var]), X86_FEATURE_CX8) \ : [var] "+m" (_var), \" +a" (old__.low), \ " +d" (old__.high) \ : " b" (new__.low), \ " c" (new__.high) \ - : "memory"); \ +: " memory", " esi"); \ \ old__.var; \ })
@@ -254,13 +255,14 @@ do { \ old__.var = _oval; \ new__.var = _nval; \ \ - asm qual ("cmpxchg16b " __percpu_arg([var]) \ + asm qual (ALTERNATIVE("leaq %P[var], %%rsi; call this_cpu_cmpxchg16b_emu", \ + "cmpxchg16b " __percpu_arg([var]), X86_FEATURE_CX16) \ : [var] "+m" (_var), \" +a" (old__.low), \ " +d" (old__.high) \ : " b" (new__.low), \ " c" (new__.high) \ - : "memory"); \ +: " memory", " rsi"); \ \ old__.var; \ })
@@ -400,12 +402,13 @@ do { \bool __ret; \typeof (pcp1) __o1 = (o1), __n1 = (n1); \typeof (pcp2) __o2 = (o2), __n2 = (n2); \ -alternative_io ("leaq %P1,%%rsi\n\tcall this_cpu_cmpxchg16b_emu\n\t" , \ - "cmpxchg16b " __percpu_arg(1) "\n\tsetz %0\n\t", \ -X86_FEATURE_CX16 , \ -ASM_OUTPUT2 ("=a" (__ret),"+m" (pcp1), \ -"+m" (pcp2),"+d" (__o2)), \ - "b" (__n1), "c" (__n2), "a" (__o1) : "rsi"); \ + asm volatile (ALTERNATIVE("leaq %P1, %%rsi; call this_cpu_cmpxchg16b_emu", \ + "cmpxchg16b " __percpu_arg(1), X86_FEATURE_CX16) \ + "setz %0" \ + : "=a" (__ret), "+m" (pcp1) \ + : "b" (__n1), "c" (__n2), \ + "a" (__o1), "d" (__o2) \ + : "memory", "rsi"); \ __ret; \ })
arch/x86/lib/Makefile +2 -1
@@ -61,8 +61,9 @@ ifeq ($(CONFIG_X86_32),y) lib-y += strstr_32.o lib-y += string_32.o lib-y += memmove_32.o + lib-y += cmpxchg8b_emu.o ifneq ($(CONFIG_X86_CMPXCHG64),y) - lib-y += cmpxchg8b_emu.o atomic64_386_32.o + lib-y += atomic64_386_32.o endif else obj-y += iomap_copy_64.o
arch/x86/lib/cmpxchg16b_emu.S +25 -18
72 lines not on this page · raw message
arch/x86/lib/cmpxchg8b_emu.S +49 -14
91 lines not on this page · raw message
Re: [PATCH v3 05/11] percpu: Wire up cmpxchg128
Quoted 4 lines · On Thu, 25 May 2023 14:49:55 +0200 Peter Zijlstra <[email protected]> wrote:
[...]
Build tested i386-defconfig.(the things we do for museum pieces :/)
I have always thought it's not done for museum pieces but rather for dumb emulators. I can vaguely recall a reverse-engineered MIPS firmware which was able to run i386 binaries, but not i586...
Petr T
Peter Zijlstra
maintainerPATCH v3 6/11 x86,amd_iommu: Replace cmpxchg_double()
In reply to Peter Zijlstra--- drivers/iommu/amd/amd_iommu_types.h | 9 +++++++-- drivers/iommu/amd/iommu.c | 10 ++++------ 2 files changed, 11 insertions(+), 8 deletions(-)
drivers/iommu/amd/amd_iommu_types.h +7 -2
@@ -986,8 +986,13 @@ union irte_ga_hi { };struct irte_ga { -union irte_ga_lo lo; -union irte_ga_hi hi; +union { +struct { +union irte_ga_lo lo; +union irte_ga_hi hi; + }; +u128 irte; + }; };struct irq_2_irte {
drivers/iommu/amd/iommu.c +4 -6
@@ -3003,10 +3003,10 @@ static int alloc_irq_index(struct amd_iostatic int modify_irte_ga (struct amd_iommu *iommu,u16 devid,int index,struct irte_ga *irte,struct amd_ir_data *data) { -bool ret;struct irq_remap_table *table; -unsigned long flags;struct irte_ga *entry; +unsigned long flags; +u128 old; table =get_irq_table (iommu, devid);if (!table)
@@ -3017,16 +3017,14 @@ static int modify_irte_ga(struct amd_iom entry = (struct irte_ga *)table->table; entry = &entry[index]; - ret =cmpxchg_double (&entry->lo.val, &entry->hi.val, - entry->lo.val, entry->hi.val, - irte->lo.val, irte->hi.val);/* * We use cmpxchg16 to atomically update the 128-bit IRTE, * and it cannot be updated by the hardware or other processors * behind us, so the return value of cmpxchg16 should be the * same as the old value. */ -WARN_ON (!ret); + old = entry->irte; +WARN_ON (!try_cmpxchg128 (&entry->irte, &old, irte->irte));if (data) data->ref = entry;
[tip: locking/core] x86,amd_iommu: Replace cmpxchg_double()
The following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: d41f6f473d0f825678585fd1d782b4bdb9c3a528 Gitweb: https://git.kernel.org/tip/d41f6f473d0f825678585fd1d782b4bdb9c3a528 Author: Peter Zijlstra <[email protected]> AuthorDate: Mon, 15 May 2023 09:57:05 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 19 May 2023 12:35:13 +02:00
x86,amd_iommu: Replace cmpxchg_double()
--- drivers/iommu/amd/amd_iommu_types.h | 9 +++++++-- drivers/iommu/amd/iommu.c | 10 ++++------ 2 files changed, 11 insertions(+), 8 deletions(-)
drivers/iommu/amd/amd_iommu_types.h +7 -2
@@ -986,8 +986,13 @@ union irte_ga_hi { };struct irte_ga { -union irte_ga_lo lo; -union irte_ga_hi hi; +union { +struct { +union irte_ga_lo lo; +union irte_ga_hi hi; + }; +u128 irte; + }; };struct irq_2_irte {
drivers/iommu/amd/iommu.c +4 -6
@@ -3003,10 +3003,10 @@ out:static int modify_irte_ga (struct amd_iommu *iommu,u16 devid,int index,struct irte_ga *irte,struct amd_ir_data *data) { -bool ret;struct irq_remap_table *table; -unsigned long flags;struct irte_ga *entry; +unsigned long flags; +u128 old; table =get_irq_table (iommu, devid);if (!table)
@@ -3017,16 +3017,14 @@ static int modify_irte_ga(struct amd_iommu *iommu, u16 devid, int index, entry = (struct irte_ga *)table->table; entry = &entry[index]; - ret =cmpxchg_double (&entry->lo.val, &entry->hi.val, - entry->lo.val, entry->hi.val, - irte->lo.val, irte->hi.val);/* * We use cmpxchg16 to atomically update the 128-bit IRTE, * and it cannot be updated by the hardware or other processors * behind us, so the return value of cmpxchg16 should be the * same as the old value. */ -WARN_ON (!ret); + old = entry->irte; +WARN_ON (!try_cmpxchg128 (&entry->irte, &old, irte->irte));if (data) data->ref = entry;
[tip: locking/core] x86,amd_iommu: Replace cmpxchg_double()
In reply to Peter ZijlstraThe following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: b9ae9266b1965ad162c10af5c3d83571408dc3c3 Gitweb: https://git.kernel.org/tip/b9ae9266b1965ad162c10af5c3d83571408dc3c3 Author: Peter Zijlstra <[email protected]> AuthorDate: Mon, 15 May 2023 09:57:05 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Mon, 22 May 2023 10:49:50 +02:00
x86,amd_iommu: Replace cmpxchg_double()
--- drivers/iommu/amd/amd_iommu_types.h | 9 +++++++-- drivers/iommu/amd/iommu.c | 10 ++++------ 2 files changed, 11 insertions(+), 8 deletions(-)
drivers/iommu/amd/amd_iommu_types.h +7 -2
@@ -986,8 +986,13 @@ union irte_ga_hi { };struct irte_ga { -union irte_ga_lo lo; -union irte_ga_hi hi; +union { +struct { +union irte_ga_lo lo; +union irte_ga_hi hi; + }; +u128 irte; + }; };struct irq_2_irte {
drivers/iommu/amd/iommu.c +4 -6
@@ -3003,10 +3003,10 @@ out:static int modify_irte_ga (struct amd_iommu *iommu,u16 devid,int index,struct irte_ga *irte,struct amd_ir_data *data) { -bool ret;struct irq_remap_table *table; -unsigned long flags;struct irte_ga *entry; +unsigned long flags; +u128 old; table =get_irq_table (iommu, devid);if (!table)
@@ -3017,16 +3017,14 @@ static int modify_irte_ga(struct amd_iommu *iommu, u16 devid, int index, entry = (struct irte_ga *)table->table; entry = &entry[index]; - ret =cmpxchg_double (&entry->lo.val, &entry->hi.val, - entry->lo.val, entry->hi.val, - irte->lo.val, irte->hi.val);/* * We use cmpxchg16 to atomically update the 128-bit IRTE, * and it cannot be updated by the hardware or other processors * behind us, so the return value of cmpxchg16 should be the * same as the old value. */ -WARN_ON (!ret); + old = entry->irte; +WARN_ON (!try_cmpxchg128 (&entry->irte, &old, irte->irte));if (data) data->ref = entry;
Peter Zijlstra
maintainerPATCH v3 7/11 x86,intel_iommu: Replace cmpxchg_double()
In reply to Peter Zijlstra--- drivers/iommu/intel/irq_remapping.c | 8 -- include/linux/dmar.h | 125 +++++++++++++++++++----------------- 2 files changed, 68 insertions(+), 65 deletions(-)
drivers/iommu/intel/irq_remapping.c +2 -6
@@ -174,18 +174,14 @@ static int modify_irte(struct irq_2_iomm irte = &iommu->ir_table->base[index];if ((irte->pst ==1 ) || (irte_modified->pst ==1 )) { -bool ret; - - ret =cmpxchg_double (&irte->low, &irte->high, - irte->low, irte->high, - irte_modified->low, irte_modified->high);/* * We use cmpxchg16 to atomically update the 128-bit IRTE, * and it cannot be updated by the hardware or other processors * behind us, so the return value of cmpxchg16 should be the * same as the old value. */ -WARN_ON (!ret); +u128 old = irte->irte; +WARN_ON (!try_cmpxchg128 (&irte->irte, &old, irte_modified->irte)); }else {WRITE_ONCE (irte->low, irte_modified->low);WRITE_ONCE (irte->high, irte_modified->high);
include/linux/dmar.h +66 -59
133 lines not on this page · raw message
[tip: locking/core] x86,intel_iommu: Replace cmpxchg_double()
The following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 48f423cdb43ab00ae99ad43fbb2ef70e15ce9592 Gitweb: https://git.kernel.org/tip/48f423cdb43ab00ae99ad43fbb2ef70e15ce9592 Author: Peter Zijlstra <[email protected]> AuthorDate: Mon, 15 May 2023 09:57:06 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 19 May 2023 12:35:14 +02:00
x86,intel_iommu: Replace cmpxchg_double()
--- drivers/iommu/intel/irq_remapping.c | 8 +-- include/linux/dmar.h | 125 ++++++++++++++------------- 2 files changed, 68 insertions(+), 65 deletions(-)
drivers/iommu/intel/irq_remapping.c +2 -6
@@ -175,18 +175,14 @@ static int modify_irte(struct irq_2_iommu *irq_iommu, irte = &iommu->ir_table->base[index];if ((irte->pst ==1 ) || (irte_modified->pst ==1 )) { -bool ret; - - ret =cmpxchg_double (&irte->low, &irte->high, - irte->low, irte->high, - irte_modified->low, irte_modified->high);/* * We use cmpxchg16 to atomically update the 128-bit IRTE, * and it cannot be updated by the hardware or other processors * behind us, so the return value of cmpxchg16 should be the * same as the old value. */ -WARN_ON (!ret); +u128 old = irte->irte; +WARN_ON (!try_cmpxchg128 (&irte->irte, &old, irte_modified->irte)); }else {WRITE_ONCE (irte->low, irte_modified->low);WRITE_ONCE (irte->high, irte_modified->high);
include/linux/dmar.h +66 -59
133 lines not on this page · raw message
[tip: locking/core] x86,intel_iommu: Replace cmpxchg_double()
In reply to Peter ZijlstraThe following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 6d46dba6bb1cfb1885d9751fadc00ac247d9ccaf Gitweb: https://git.kernel.org/tip/6d46dba6bb1cfb1885d9751fadc00ac247d9ccaf Author: Peter Zijlstra <[email protected]> AuthorDate: Mon, 15 May 2023 09:57:06 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Mon, 22 May 2023 10:49:50 +02:00
x86,intel_iommu: Replace cmpxchg_double()
--- drivers/iommu/intel/irq_remapping.c | 8 +-- include/linux/dmar.h | 125 ++++++++++++++------------- 2 files changed, 68 insertions(+), 65 deletions(-)
drivers/iommu/intel/irq_remapping.c +2 -6
@@ -175,18 +175,14 @@ static int modify_irte(struct irq_2_iommu *irq_iommu, irte = &iommu->ir_table->base[index];if ((irte->pst ==1 ) || (irte_modified->pst ==1 )) { -bool ret; - - ret =cmpxchg_double (&irte->low, &irte->high, - irte->low, irte->high, - irte_modified->low, irte_modified->high);/* * We use cmpxchg16 to atomically update the 128-bit IRTE, * and it cannot be updated by the hardware or other processors * behind us, so the return value of cmpxchg16 should be the * same as the old value. */ -WARN_ON (!ret); +u128 old = irte->irte; +WARN_ON (!try_cmpxchg128 (&irte->irte, &old, irte_modified->irte)); }else {WRITE_ONCE (irte->low, irte_modified->low);WRITE_ONCE (irte->high, irte_modified->high);
include/linux/dmar.h +66 -59
133 lines not on this page · raw message
Peter Zijlstra
maintainerPATCH v3 8/11 slub: Replace cmpxchg_double()
In reply to Peter Zijlstra--- include/linux/slub_def.h | 12 ++- mm/slab.h | 49 ++++++++++++++-- mm/slub.c | 143 ++++++++++++++++++++++++++++------------------- 3 files changed, 138 insertions(+), 66 deletions(-)
include/linux/slub_def.h +9 -3
@@ -39,7 +39,8 @@ enum stat_item {CPU_PARTIAL_FREE ,/* Refill cpu partial on free */ CPU_PARTIAL_NODE ,/* Refill cpu partial from node partial */ CPU_PARTIAL_DRAIN ,/* Drain cpu partial to node partial */ - NR_SLUB_STAT_ITEMS }; + NR_SLUB_STAT_ITEMS +};#ifndef CONFIG_SLUB_TINY /*
@@ -47,8 +48,13 @@ enum stat_item {* with this_cpu_cmpxchg_double() alignment requirements. */ struct kmem_cache_cpu { -void **freelist;/* Pointer to next available object */ -unsigned long tid;/* Globally unique transaction id */ +union { +struct { +void **freelist;/* Pointer to next available object */ +unsigned long tid;/* Globally unique transaction id */ + }; +freelist_aba_t freelist_tid; + };struct slab *slab;/* The slab from which we are allocating */ #ifdef CONFIG_SLUB_CPU_PARTIAL struct slab *partial;/* Partially allocated frozen slabs */
mm/slab.h +43 -6
70 lines not on this page · raw message
mm/slub.c +86 -57
242 lines not on this page · raw message
[tip: locking/core] slub: Replace cmpxchg_double()
The following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 37668dff5f904fdb13a0aee8123349379d0f0499 Gitweb: https://git.kernel.org/tip/37668dff5f904fdb13a0aee8123349379d0f0499 Author: Peter Zijlstra <[email protected]> AuthorDate: Mon, 15 May 2023 09:57:07 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 19 May 2023 12:35:14 +02:00
slub: Replace cmpxchg_double()
--- include/linux/slub_def.h | 12 ++- mm/slab.h | 49 +++++++++++-- mm/slub.c | 143 ++++++++++++++++++++++---------------- 3 files changed, 138 insertions(+), 66 deletions(-)
include/linux/slub_def.h +9 -3
@@ -39,7 +39,8 @@ enum stat_item {CPU_PARTIAL_FREE ,/* Refill cpu partial on free */ CPU_PARTIAL_NODE ,/* Refill cpu partial from node partial */ CPU_PARTIAL_DRAIN ,/* Drain cpu partial to node partial */ - NR_SLUB_STAT_ITEMS }; + NR_SLUB_STAT_ITEMS +};#ifndef CONFIG_SLUB_TINY /*
@@ -47,8 +48,13 @@ enum stat_item {* with this_cpu_cmpxchg_double() alignment requirements. */ struct kmem_cache_cpu { -void **freelist;/* Pointer to next available object */ -unsigned long tid;/* Globally unique transaction id */ +union { +struct { +void **freelist;/* Pointer to next available object */ +unsigned long tid;/* Globally unique transaction id */ + }; +freelist_aba_t freelist_tid; + };struct slab *slab;/* The slab from which we are allocating */ #ifdef CONFIG_SLUB_CPU_PARTIAL struct slab *partial;/* Partially allocated frozen slabs */
mm/slab.h +43 -6
70 lines not on this page · raw message
mm/slub.c +86 -57
242 lines not on this page · raw message
[tip: locking/core] slub: Replace cmpxchg_double()
In reply to Peter ZijlstraThe following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: f4ab23558310d2181260b30825a90cdf050ebfc0 Gitweb: https://git.kernel.org/tip/f4ab23558310d2181260b30825a90cdf050ebfc0 Author: Peter Zijlstra <[email protected]> AuthorDate: Mon, 15 May 2023 09:57:07 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Mon, 22 May 2023 10:49:50 +02:00
slub: Replace cmpxchg_double()
--- include/linux/slub_def.h | 12 ++- mm/slab.h | 49 +++++++++++-- mm/slub.c | 143 ++++++++++++++++++++++---------------- 3 files changed, 138 insertions(+), 66 deletions(-)
include/linux/slub_def.h +9 -3
@@ -39,7 +39,8 @@ enum stat_item {CPU_PARTIAL_FREE ,/* Refill cpu partial on free */ CPU_PARTIAL_NODE ,/* Refill cpu partial from node partial */ CPU_PARTIAL_DRAIN ,/* Drain cpu partial to node partial */ - NR_SLUB_STAT_ITEMS }; + NR_SLUB_STAT_ITEMS +};#ifndef CONFIG_SLUB_TINY /*
@@ -47,8 +48,13 @@ enum stat_item {* with this_cpu_cmpxchg_double() alignment requirements. */ struct kmem_cache_cpu { -void **freelist;/* Pointer to next available object */ -unsigned long tid;/* Globally unique transaction id */ +union { +struct { +void **freelist;/* Pointer to next available object */ +unsigned long tid;/* Globally unique transaction id */ + }; +freelist_aba_t freelist_tid; + };struct slab *slab;/* The slab from which we are allocating */ #ifdef CONFIG_SLUB_CPU_PARTIAL struct slab *partial;/* Partially allocated frozen slabs */
mm/slab.h +43 -6
70 lines not on this page · raw message
mm/slub.c +86 -57
242 lines not on this page · raw message
Peter Zijlstra
maintainerRe: [PATCH v3 08/11] slub: Replace cmpxchg_double()
In reply to Peter ZijlstraQuoted 39 lines · Peter Zijlstra
(quoted diff) +17
-5@@ -3008,6 +3029,22 @@ static inline bool pfmemalloc_match(stru } #ifndef CONFIG_SLUB_TINY +static inline bool +__update_cpu_freelist_fast(struct kmem_cache *s, + void *freelist_old, void *freelist_new, + unsigned long tid) +{ +#ifdef system_has_freelist_aba + freelist_aba_t old = { .freelist = freelist_old, .counter = tid }; + freelist_aba_t new = { .freelist = freelist_new, .counter = next_tid(tid) }; + + return this_cpu_cmpxchg_freelist(s->cpu_slab->freelist_tid.full, + old.full, new.full) == old.full; +#else + return false; +#endif +} + /* * Check the slab->freelist and either transfer the freelist to the * per cpu freelist or deactivate the slab.@@ -3359,11 +3396,7 @@ static __always_inline void *__slab_allo * against code executing on this cpu *not* from access by * other cpus. */ - if (unlikely(!this_cpu_cmpxchg_double( - s->cpu_slab->freelist, s->cpu_slab->tid, - object, tid, - next_object, next_tid(tid)))) { - + if (unlikely(!__update_cpu_freelist_fast(s, object, next_object, tid))) { note_cmpxchg_failure("slab_alloc", s, tid); goto redo; }@@ -3736,11 +3769,7 @@ static __always_inline void do_slab_free set_freepointer(s, tail_obj, freelist);
Review static __always_inline void do_slab_free · line 3775
Quoted 10 lines
(quoted diff) +1
-5- if (unlikely(!this_cpu_cmpxchg_double( - s->cpu_slab->freelist, s->cpu_slab->tid, - freelist, tid, - head, next_tid(tid)))) { - + if (unlikely(!__update_cpu_freelist_fast(s, freelist, head, tid))) { note_cmpxchg_failure("slab_free", s, tid); goto redo; }
This isn't right; the this_cpu_cmpxchg_double() was unconditional and relied on the local_irq_save() fallback when no native cmpxchg128 is present.
The below delta makes things boot again when system_has_cmpxchg128 is not defined.
I'm going to zap these patches from tip/locking/core for a few days and fold the below back into the series and let it run through the robots again.
--- mm/slab.h | 20 +++++++++++--------- mm/slub.c | 6 +----- 2 files changed, 12 insertions(+), 14 deletions(-)
mm/slab.h +11 -9
@@ -6,36 +6,36 @@*/ void __init kmem_cache_init (void ); -#ifdef CONFIG_HAVE_ALIGNED_STRUCT_PAGE #ifdef CONFIG_64BIT # ifdef system_has_cmpxchg128# define system_has_freelist_aba () system_has_cmpxchg128()# define try_cmpxchg_freelist try_cmpxchg128 -# define this_cpu_cmpxchg_freelist this_cpu_cmpxchg128 -typedef u128 freelist_full_t ;# endif +#define this_cpu_cmpxchg_freelist this_cpu_cmpxchg128 +typedef u128 freelist_full_t ;#else /* CONFIG_64BIT */ # ifdef system_has_cmpxchg64# define system_has_freelist_aba () system_has_cmpxchg64()# define try_cmpxchg_freelist try_cmpxchg64 -# define this_cpu_cmpxchg_freelist this_cpu_cmpxchg64 -typedef u64 freelist_full_t ;# endif +#define this_cpu_cmpxchg_freelist this_cpu_cmpxchg64 +typedef u64 freelist_full_t ;#endif /* CONFIG_64BIT */ -#endif /* CONFIG_HAVE_ALIGNED_STRUCT_PAGE */ + +#if defined(system_has_freelist_aba) && !defined(CONFIG_HAVE_ALIGNED_STRUCT_PAGE ) +#undef system_has_freelist_aba +#endif /* * Freelist pointer and counter to cmpxchg together, avoids the typical ABA * problems with cmpxchg of just a pointer. */ typedef union { -#ifdef system_has_freelist_abastruct {void *freelist;unsigned long counter; };freelist_full_t full; -#endif }freelist_aba_t ;/* Reuses the bits in struct page */
@@ -82,7 +82,9 @@ struct slab { }; }; }; +#ifdef system_has_freelist_abafreelist_aba_t freelist_counter; +#endif }; };struct rcu_head rcu_head;
@@ -110,7 +112,7 @@ SLAB_MATCH(memcg_data, memcg_data);#undef SLAB_MATCHstatic_assert (sizeof (struct slab ) <=sizeof (struct page ));#if defined(system_has_freelist_aba) && defined(CONFIG_SLUB ) -static_assert (IS_ALIGNED (offsetof(struct slab , freelist),2 *sizeof (void *))); +static_assert (IS_ALIGNED (offsetof(struct slab , freelist),sizeof (freelist_aba_t)));#endif /**
mm/slub.c +0 -4
@@ -3034,15 +3034,11 @@ __update_cpu_freelist_fast(struct kmem_cache *s, void *freelist_old, void *freelist_new, unsigned long tid) { -#ifdef system_has_freelist_aba freelist_aba_t old = { .freelist = freelist_old, .counter = tid };freelist_aba_t new = { .freelist = freelist_new, .counter =next_tid (tid) };return this_cpu_cmpxchg_freelist (s->cpu_slab->freelist_tid.full, old.full, new.full) == old.full; -#else -return false; -#endif }/*
Re: [PATCH v3 08/11] slub: Replace cmpxchg_double()
Quoted 56 lines · Peter Zijlstra
Quoted 39 lines · Peter Zijlstra
(quoted diff) +17
-5@@ -3008,6 +3029,22 @@ static inline bool pfmemalloc_match(stru } #ifndef CONFIG_SLUB_TINY +static inline bool +__update_cpu_freelist_fast(struct kmem_cache *s, + void *freelist_old, void *freelist_new, + unsigned long tid) +{ +#ifdef system_has_freelist_aba + freelist_aba_t old = { .freelist = freelist_old, .counter = tid }; + freelist_aba_t new = { .freelist = freelist_new, .counter = next_tid(tid) }; + + return this_cpu_cmpxchg_freelist(s->cpu_slab->freelist_tid.full, + old.full, new.full) == old.full; +#else + return false; +#endif +} + /* * Check the slab->freelist and either transfer the freelist to the * per cpu freelist or deactivate the slab.@@ -3359,11 +3396,7 @@ static __always_inline void *__slab_allo * against code executing on this cpu *not* from access by * other cpus. */ - if (unlikely(!this_cpu_cmpxchg_double( - s->cpu_slab->freelist, s->cpu_slab->tid, - object, tid, - next_object, next_tid(tid)))) { - + if (unlikely(!__update_cpu_freelist_fast(s, object, next_object, tid))) { note_cmpxchg_failure("slab_alloc", s, tid); goto redo; }@@ -3736,11 +3769,7 @@ static __always_inline void do_slab_free set_freepointer(s, tail_obj, freelist);Review static __always_inline void do_slab_free · line 3775
Quoted 10 lines
(quoted diff) +1
-5- if (unlikely(!this_cpu_cmpxchg_double( - s->cpu_slab->freelist, s->cpu_slab->tid, - freelist, tid, - head, next_tid(tid)))) { - + if (unlikely(!__update_cpu_freelist_fast(s, freelist, head, tid))) { note_cmpxchg_failure("slab_free", s, tid); goto redo; }This isn't right; the
this_cpu_cmpxchg_double()was unconditional and relied on thelocal_irq_save()fallback when no native cmpxchg128 is present.
Quoted 2 lines
The below delta makes things boot again when
system_has_cmpxchg128is not defined.
Right, that should do.
Quoted 3 lines
I'm going to zap these patches from tip/locking/core for a few days and fold the below back into the series and let it run through the robots again.
I noticed some comments in mm/slub.c still mention "cmpxchg_double", dunno how much you want to clean it right now or can be postponed. Also some sysfs stats files for CONFIG_SLUB_STATS (not widely used) which we probably might try renaming without breaking anyone, but it's not guaranteed.
Peter Zijlstra
maintainerRe: [PATCH v3 08/11] slub: Replace cmpxchg_double()
In reply to Peter ZijlstraQuoted 42 lines · Peter Zijlstra
Quoted 40 lines · Peter Zijlstra
(quoted diff) +17
-5@@ -3008,6 +3029,22 @@ static inline bool pfmemalloc_match(stru } #ifndef CONFIG_SLUB_TINY +static inline bool +__update_cpu_freelist_fast(struct kmem_cache *s, + void *freelist_old, void *freelist_new, + unsigned long tid) +{ +#ifdef system_has_freelist_aba + freelist_aba_t old = { .freelist = freelist_old, .counter = tid }; + freelist_aba_t new = { .freelist = freelist_new, .counter = next_tid(tid) }; + + return this_cpu_cmpxchg_freelist(s->cpu_slab->freelist_tid.full, + old.full, new.full) == old.full; +#else + return false; +#endif +} + /* * Check the slab->freelist and either transfer the freelist to the * per cpu freelist or deactivate the slab.@@ -3359,11 +3396,7 @@ static __always_inline void *__slab_allo * against code executing on this cpu *not* from access by * other cpus. */ - if (unlikely(!this_cpu_cmpxchg_double( - s->cpu_slab->freelist, s->cpu_slab->tid, - object, tid, - next_object, next_tid(tid)))) { - + if (unlikely(!__update_cpu_freelist_fast(s, object, next_object, tid))) { note_cmpxchg_failure("slab_alloc", s, tid); goto redo; }@@ -3736,11 +3769,7 @@ static __always_inline void do_slab_free set_freepointer(s, tail_obj, freelist);
Quoted 13 lines
Review static __always_inline void do_slab_free · line 3775
Quoted 9 lines
(quoted diff) +1
-5- if (unlikely(!this_cpu_cmpxchg_double( - s->cpu_slab->freelist, s->cpu_slab->tid, - freelist, tid, - head, next_tid(tid)))) { - + if (unlikely(!__update_cpu_freelist_fast(s, freelist, head, tid))) { note_cmpxchg_failure("slab_free", s, tid); goto redo; }This isn't right; the
this_cpu_cmpxchg_double()was unconditional and relied on thelocal_irq_save()fallback when no native cmpxchg128 is present.
This then also means I need to look at this_cpu_cmpxchg128 and this_cpu_cmoxchg64 behaviour when we dont have the CPUID feature.
Because current verions seem to assume the instruction is present.
Arnd Bergmann
maintainerRe: [PATCH v3 08/11] slub: Replace cmpxchg_double()
Quoted 7 lines · Peter Zijlstra
Quoted 1 line · Peter Zijlstra
On Mon, May 15, 2023 at 09:57:07AM +0200, Peter Zijlstra wrote:
This then also means I need to look at
this_cpu_cmpxchg128andthis_cpu_cmoxchg64behaviour when we dont have the CPUID feature.Because current verions seem to assume the instruction is present.
As far as I could tell when reviewing your series, this_cpu_cmpxchg64() is always available on all architectures. Depending on compile-time feature detection this would be either a native instruction that is guaranteed to work, or the irq-disabled version. On x86, this is handled at runtime with alternative_io().
this_cpu_cmpxchg128() clearly needed the system_has_cmpxchg128() check, same as system_has_cmpxchg_double() today.
Arnd
Peter Zijlstra
maintainerRe: [PATCH v3 08/11] slub: Replace cmpxchg_double()
Quoted 9 lines · Arnd Bergmann
Quoted 7 lines · Peter Zijlstra
Quoted 1 line · Peter Zijlstra
On Mon, May 15, 2023 at 09:57:07AM +0200, Peter Zijlstra wrote:
This then also means I need to look at
this_cpu_cmpxchg128andthis_cpu_cmoxchg64behaviour when we dont have the CPUID feature.Because current verions seem to assume the instruction is present.
Quoted 8 lines
As far as I could tell when reviewing your series,
this_cpu_cmpxchg64()is always available on all architectures. Depending on compile-time feature detection this would be either a native instruction that is guaranteed to work, or the irq-disabled version. On x86, this is handled at runtime withalternative_io().
this_cpu_cmpxchg128()clearly needed thesystem_has_cmpxchg128()check, same assystem_has_cmpxchg_double()today.
So, having just dug through all that, on x86:
this_cpu_cmpxchg64() is:
X86_CMPXCHG64=n -> fallback, irrespective of CX8
X86_CMPXCHG64=y -> cmpxchg8b
X86_64 -> cmpxchg
I've changed it to be similar between 32bit and 64bit such that both:
cmpxchg#b when CX#, otherwise this_cpu_cmpxchg#b_emu
Peter Zijlstra
maintainerRe: [PATCH v3 08/11] slub: Replace cmpxchg_double()
In reply to Peter ZijlstraQuoted 42 lines · Peter Zijlstra
Quoted 40 lines · Peter Zijlstra
(quoted diff) +17
-5@@ -3008,6 +3029,22 @@ static inline bool pfmemalloc_match(stru } #ifndef CONFIG_SLUB_TINY +static inline bool +__update_cpu_freelist_fast(struct kmem_cache *s, + void *freelist_old, void *freelist_new, + unsigned long tid) +{ +#ifdef system_has_freelist_aba + freelist_aba_t old = { .freelist = freelist_old, .counter = tid }; + freelist_aba_t new = { .freelist = freelist_new, .counter = next_tid(tid) }; + + return this_cpu_cmpxchg_freelist(s->cpu_slab->freelist_tid.full, + old.full, new.full) == old.full; +#else + return false; +#endif +} + /* * Check the slab->freelist and either transfer the freelist to the * per cpu freelist or deactivate the slab.@@ -3359,11 +3396,7 @@ static __always_inline void *__slab_allo * against code executing on this cpu *not* from access by * other cpus. */ - if (unlikely(!this_cpu_cmpxchg_double( - s->cpu_slab->freelist, s->cpu_slab->tid, - object, tid, - next_object, next_tid(tid)))) { - + if (unlikely(!__update_cpu_freelist_fast(s, object, next_object, tid))) { note_cmpxchg_failure("slab_alloc", s, tid); goto redo; }@@ -3736,11 +3769,7 @@ static __always_inline void do_slab_free set_freepointer(s, tail_obj, freelist);
Quoted 13 lines
Review static __always_inline void do_slab_free · line 3775
Quoted 9 lines
(quoted diff) +1
-5- if (unlikely(!this_cpu_cmpxchg_double( - s->cpu_slab->freelist, s->cpu_slab->tid, - freelist, tid, - head, next_tid(tid)))) { - + if (unlikely(!__update_cpu_freelist_fast(s, freelist, head, tid))) { note_cmpxchg_failure("slab_free", s, tid); goto redo; }This isn't right; the
this_cpu_cmpxchg_double()was unconditional and relied on thelocal_irq_save()fallback when no native cmpxchg128 is present.
This means this_cpu_cmpxchg128 is expected to be present on all 64bit archs, except Mark just found out that HPPA doens't support __int128 until gcc-11.
(I've been building using gcc-12.2)
And because the cmpxchg128 fallback relies on '==' we can't trivally fudge that with a struct type either :/ Now, afaict it all magically works if I use:
#ifdef __SIZEOF_INT128__
typedef __s128 s128
typedef __u128 u128
#else
#if defined(CONFIG_PARISC) && defined(CONFIG_64BIT) typedef long double u128;
#endif
#endif
but that is *super* gross.
The alternative is raising the minimum GCC for PARISC to gcc-11..
Yet another alternative is using a struct type and an equality function, just for this.
Anybody?
Peter Zijlstra
maintainerRe: [PATCH v3 08/11] slub: Replace cmpxchg_double()
Quoted 2 lines · Peter Zijlstra
Yet another alternative is using a struct type and an equality function, just for this.
The best I could come up with in the regard is the below. It builds on HPPA64 and x86_64, but I've not ran it yet.
(also, the introduction of this_cpu_try_cmpxchg() should probably be split out into its own patch)
include/asm-generic/percpu.h +125 -0
@@ -99,6 +99,15 @@ do { \ __ret; \ }) +#define raw_cpu_generic_try_cmpxchg (pcp, ovalp, nval) \ +({ \ + typeof(pcp) __ret, __old = *(ovalp); \ + __ret = raw_cpu_cmpxchg(pcp, __old, nval); \ + if (!likely(__ret == __old)) \ + *(ovalp) = __ret; \ + likely(__ret == __old); \ +}) +#define __this_cpu_generic_read_nopreempt (pcp) \ ({ \ typeof(pcp) ___ret; \
@@ -167,6 +176,15 @@ do { \ __ret; \ }) +#define this_cpu_generic_try_cmpxchg (pcp, ovalp, nval) \ +({ \ + typeof(pcp) __ret, __old = *(ovalp); \ + __ret = this_cpu_cmpxchg(pcp, __old, nval); \ + if (!likely(__ret == __old)) \ + *(ovalp) = __ret; \ + likely(__ret == __old); \ +}) +#ifndef raw_cpu_read_1#define raw_cpu_read_1 (pcp) raw_cpu_generic_read(pcp)#endif
@@ -258,6 +276,36 @@ do { \#define raw_cpu_xchg_8 (pcp, nval) raw_cpu_generic_xchg(pcp, nval)#endif +#ifndef __SIZEOF_INT128__ +#define raw_cpu_generic_try_cmpxchg_memcmp (pcp, ovalp, nval) \ +({ \ + typeof(pcp) *__p = raw_cpu_ptr(&(pcp)); \ + typeof(pcp) __ret, __old = *(ovalp); \ + bool __s; \ + __ret = *__p; \ + if (!__builtin_memcmp(&__ret, &__old, sizeof(pcp))) { \ + *__p = nval; \ + __s = true; \ + } else { \ + *(ovalp) = __ret; \ + __s = false; \ + } \ + __s; \ +}) + +#define raw_cpu_generic_cmpxchg_memcmp (pcp, oval, nval) \ +({ \ + typeof(pcp) __old = (oval); \ + raw_cpu_generic_try_cmpxchg_memcpy(pcp, &__old, nval); \ + __old; \ +}) + +#define raw_cpu_cmpxchg128 (pcp, oval, nval) \ + raw_cpu_generic_cmpxchg_memcmp(pcp, oval, nval) +#define raw_cpu_try_cmpxchg128 (pcp, ovalp, nval) \ + raw_cpu_generic_try_cmpxchg_memcmp(pcp, ovalp, nval) +#endif +#ifndef raw_cpu_cmpxchg_1#define raw_cpu_cmpxchg_1 (pcp, oval, nval) \ raw_cpu_generic_cmpxchg(pcp, oval, nval)
@@ -283,6 +331,31 @@ do { \ raw_cpu_generic_cmpxchg(pcp, oval, nval)#endif +#ifndef raw_cpu_try_cmpxchg_1 +#define raw_cpu_try_cmpxchg_1 (pcp, ovalp, nval) \ + raw_cpu_generic_try_cmpxchg(pcp, ovalp, nval) +#endif +#ifndef raw_cpu_try_cmpxchg_2 +#define raw_cpu_try_cmpxchg_2 (pcp, ovalp, nval) \ + raw_cpu_generic_try_cmpxchg(pcp, ovalp, nval) +#endif +#ifndef raw_cpu_try_cmpxchg_4 +#define raw_cpu_try_cmpxchg_4 (pcp, ovalp, nval) \ + raw_cpu_generic_try_cmpxchg(pcp, ovalp, nval) +#endif +#ifndef raw_cpu_try_cmpxchg_8 +#define raw_cpu_try_cmpxchg_8 (pcp, ovalp, nval) \ + raw_cpu_generic_try_cmpxchg(pcp, ovalp, nval) +#endif +#ifndef raw_cpu_try_cmpxchg64 +#define raw_cpu_try_cmpxchg64 (pcp, ovalp, nval) \ + raw_cpu_generic_try_cmpxchg(pcp, ovalp, nval) +#endif +#ifndef raw_cpu_try_cmpxchg128 +#define raw_cpu_try_cmpxchg128 (pcp, ovalp, nval) \ + raw_cpu_generic_try_cmpxchg(pcp, ovalp, nval) +#endif +#ifndef this_cpu_read_1#define this_cpu_read_1 (pcp) this_cpu_generic_read(pcp)#endif
@@ -374,6 +447,33 @@ do { \#define this_cpu_xchg_8 (pcp, nval) this_cpu_generic_xchg(pcp, nval)#endif +#ifndef __SIZEOF_INT128__ +#define this_cpu_generic_try_cmpxchg_memcmp (pcp, ovalp, nval) \ +({ \ + bool __ret; \ + unsigned long __flags; \ + raw_local_irq_save(__flags); \ + __ret = raw_cpu_generic_try_cmpxchg_memcmp(pcp, ovalp, nval); \ + raw_local_irq_restore(__flags); \ + __ret; \ +}) + +#define this_cpu_generic_cmpxchg_memcmp (pcp, oval, nval) \ +({ \ + typeof(pcp) __ret; \ + unsigned long __flags; \ + raw_local_irq_save(__flags); \ + __ret = raw_cpu_generic_cmpxchg_memcmp(pcp, oval, nval); \ + raw_local_irq_restore(__flags); \ + __ret; \ +}) + +#define this_cpu_cmpxchg128 (pcp, oval, nval) \ + this_cpu_generic_cmpxchg_memcmp(pcp, oval, nval) +#define this_cpu_try_cmpxchg128 (pcp, ovalp, nval) \ + this_cpu_generic_try_cmpxchg_memcmp(pcp, ovalp, nval) +#endif +#ifndef this_cpu_cmpxchg_1#define this_cpu_cmpxchg_1 (pcp, oval, nval) \ this_cpu_generic_cmpxchg(pcp, oval, nval)
@@ -399,4 +499,29 @@ do { \ this_cpu_generic_cmpxchg(pcp, oval, nval)#endif +#ifndef this_cpu_try_cmpxchg_1 +#define this_cpu_try_cmpxchg_1 (pcp, ovalp, nval) \ + this_cpu_generic_try_cmpxchg(pcp, ovalp, nval) +#endif +#ifndef this_cpu_try_cmpxchg_2 +#define this_cpu_try_cmpxchg_2 (pcp, ovalp, nval) \ + this_cpu_generic_try_cmpxchg(pcp, ovalp, nval) +#endif +#ifndef this_cpu_try_cmpxchg_4 +#define this_cpu_try_cmpxchg_4 (pcp, ovalp, nval) \ + this_cpu_generic_try_cmpxchg(pcp, ovalp, nval) +#endif +#ifndef this_cpu_try_cmpxchg_8 +#define this_cpu_try_cmpxchg_8 (pcp, ovalp, nval) \ + this_cpu_generic_try_cmpxchg(pcp, ovalp, nval) +#endif +#ifndef this_cpu_try_cmpxchg64 +#define this_cpu_try_cmpxchg64 (pcp, ovalp, nval) \ + this_cpu_generic_try_cmpxchg(pcp, ovalp, nval) +#endif +#ifndef this_cpu_try_cmpxchg128 +#define this_cpu_try_cmpxchg128 (pcp, ovalp, nval) \ + this_cpu_generic_try_cmpxchg(pcp, ovalp, nval) +#endif +#endif /* _ASM_GENERIC_PERCPU_H_ */
include/linux/types.h +7 -0
@@ -13,6 +13,13 @@#ifdef __SIZEOF_INT128__typedef __s128 s128 ;typedef __u128 u128 ; +#else +#ifdef CONFIG_64BIT +/* hack for this_cpu_cmpxchg128 */ +typedef struct { +u64 a, b; +}u128 __attribute__((aligned (16 ))); +#endif #endif typedef u32 __kernel_dev_t ;
mm/slab.h +2 -2
@@ -11,14 +11,14 @@ void __init kmem_cache_init(void);# define system_has_freelist_aba () system_has_cmpxchg128()# define try_cmpxchg_freelist try_cmpxchg128# endif -#define this_cpu_cmpxchg_freelist this_cpu_cmpxchg128 +#define this_cpu_try_cmpxchg_freelist this_cpu_try_cmpxchg128typedef u128 freelist_full_t ;#else /* CONFIG_64BIT */ # ifdef system_has_cmpxchg64# define system_has_freelist_aba () system_has_cmpxchg64()# define try_cmpxchg_freelist try_cmpxchg64# endif -#define this_cpu_cmpxchg_freelist this_cpu_cmpxchg64 +#define this_cpu_try_cmpxchg_freelist this_cpu_try_cmpxchg64typedef u64 freelist_full_t ;#endif /* CONFIG_64BIT */
mm/slub.c +2 -2
@@ -3037,8 +3037,8 @@ __update_cpu_freelist_fast(struct kmem_cfreelist_aba_t old = { .freelist = freelist_old, .counter = tid };freelist_aba_t new = { .freelist = freelist_new, .counter =next_tid (tid) }; -return this_cpu_cmpxchg_freelist (s->cpu_slab->freelist_tid.full, - old.full, new.full) == old.full; +return this_cpu_try_cmpxchg_freelist (s->cpu_slab->freelist_tid.full, + &old.full, new.full); }/*
Peter Zijlstra
maintainerPATCH v3 9/11 mm/slub: Fold slab_update_freelist()
In reply to Peter ZijlstraThe two functions slab_update_freelist() and __slab_update_freelist() are nearly identical, fold and add a boolean argument and rely on constant propagation.
--- mm/slub.c | 80 +++++++++++++++++++++----------------------------------------- 1 file changed, 28 insertions(+), 52 deletions(-)
mm/slub.c +28 -52
@@ -559,53 +559,29 @@ __update_freelist_slow(struct slab *slab* allocation/ free operation in hardirq context. Therefore nothing can * interrupt the operation. */ -static inline bool __slab_update_freelist (struct kmem_cache *s,struct slab *slab, -void *freelist_old,unsigned long counters_old, -void *freelist_new,unsigned long counters_new, -const char *n) +static __always_inline +bool slab_update_freelist(struct kmem_cache *s, struct slab *slab, +void *freelist_old,unsigned long counters_old, +void *freelist_new,unsigned long counters_new, +bool irq_save,const char *n) {bool ret; -if (USE_LOCKLESS_FAST_PATH ()) +if (!irq_save &&USE_LOCKLESS_FAST_PATH ())lockdep_assert_irqs_disabled ();if (s->flags & __CMPXCHG_DOUBLE) { ret =__update_freelist_fast (slab, freelist_old, counters_old, freelist_new, counters_new); }else { - ret =__update_freelist_slow (slab, freelist_old, counters_old, - freelist_new, counters_new); - } -if (likely (ret)) -return true; - -cpu_relax (); -stat (s,CMPXCHG_DOUBLE_FAIL ); - -#ifdef SLUB_DEBUG_CMPXCHG -pr_info ("%s %s: cmpxchg double redo " , n, s->name); -#endif - -return false; -} - -static inline bool slab_update_freelist (struct kmem_cache *s,struct slab *slab, -void *freelist_old,unsigned long counters_old, -void *freelist_new,unsigned long counters_new, -const char *n) -{ -bool ret; - -if (s->flags & __CMPXCHG_DOUBLE) { - ret =__update_freelist_fast (slab, freelist_old, counters_old, - freelist_new, counters_new); - }else {unsigned long flags; -local_irq_save (flags); +if (irq_save) +local_irq_save (flags); ret =__update_freelist_slow (slab, freelist_old, counters_old, freelist_new, counters_new); -local_irq_restore (flags); +if (irq_save) +local_irq_restore (flags); }if (likely (ret))return true;
@@ -2250,10 +2226,10 @@ static inline void *acquire_slab(structVM_BUG_ON (new.frozen); new.frozen =1 ; -if (!__slab_update_freelist (s, slab, - freelist, counters, - new.freelist, new.counters, -"acquire_slab" )) +if (!slab_update_freelist (s, slab, + freelist, counters, + new.freelist, new.counters, + false,"acquire_slab" ))return NULL ;remove_partial (n, slab);
@@ -2577,9 +2553,9 @@ static void deactivate_slab(struct kmem_if (!slab_update_freelist (s, slab, - old.freelist, old.counters, - new.freelist, new.counters, -"unfreezing slab" )) { + old.freelist, old.counters, + new.freelist, new.counters, + true,"unfreezing slab" )) {if (mode ==M_PARTIAL )spin_unlock_irqrestore (&n->list_lock, flags); goto redo;
@@ -2633,10 +2609,10 @@ static void __unfreeze_partials(struct k new.frozen =0 ; - }while (!__slab_update_freelist (s, slab, - old.freelist, old.counters, - new.freelist, new.counters, -"unfreezing slab" )); + }while (!slab_update_freelist (s, slab, + old.freelist, old.counters, + new.freelist, new.counters, + false,"unfreezing slab" ));if (unlikely (!new.inuse && n->nr_partial >= s->min_partial)) { slab->next = slab_to_discard;
@@ -3072,10 +3048,10 @@ static inline void *get_freelist(struct new.inuse = slab->objects; new.frozen = freelist !=NULL ; - }while (!__slab_update_freelist (s, slab, - freelist, counters, -NULL , new.counters, -"get_freelist" )); + }while (!slab_update_freelist (s, slab, + freelist, counters, +NULL , new.counters, + false,"get_freelist" ));return freelist; }
@@ -3666,9 +3642,9 @@ static void __slab_free(struct kmem_cach } }while (!slab_update_freelist (s, slab, - prior, counters, - head, new.counters, -"__slab_free" )); + prior, counters, + head, new.counters, + true,"__slab_free" ));if (likely (!n)) {
Re: [PATCH v3 09/11] mm/slub: Fold slab_update_freelist()
Quoted 5 lines · Peter Zijlstra
The two functions
slab_update_freelist()and__slab_update_freelist()are nearly identical, fold and add a boolean argument and rely on constant propagation.Signed-off-by Peter Zijlstra (Intel) <[email protected]>
Something like that has been tried before and the result:
https://lore.kernel.org/all/CAHk-=wiJLqL2cUhJbvpyPQpkbVOu1rVSzgO2=S2jC55hneLtfQ@mail.gmail.com/
Your parameter is not called 'locked' but 'irq_save' which is better, but that's just one detail.
After your refactoring in 08/11 which puts most of the code into __update_freelist_fast() and _slow() I'd say the result is not so bad already.
BTW I have some suspicion that some SLUB code is based on assumptions that are no longer true these days. IIRC I've seen some microbenchmark results a while ago that showed that disabling/enabling irqs is surprisingly (to me) very cheap today, so maybe it's not so useful to keep doing the this_cpu_cmpxchg128 for the struct kmem_cache_cpu operations (less so for struct slab cmpxchg128 where actually different cpus may be involved). But it needs a closer look.
Quoted 143 lines
--- mm/slub.c | 80 +++++++++++++++++++++----------------------------------------- 1 file changed, 28 insertions(+), 52 deletions(-)mm/slub.c +28
-52@@ -559,53 +559,29 @@ __update_freelist_slow(struct slab *slab* allocation/ free operation in hardirq context. Therefore nothing can * interrupt the operation. */ -static inline bool __slab_update_freelist (struct kmem_cache *s,struct slab *slab, -void *freelist_old,unsigned long counters_old, -void *freelist_new,unsigned long counters_new, -const char *n) +static __always_inline +bool slab_update_freelist(struct kmem_cache *s, struct slab *slab, +void *freelist_old,unsigned long counters_old, +void *freelist_new,unsigned long counters_new, +bool irq_save,const char *n) {bool ret; -if (USE_LOCKLESS_FAST_PATH ()) +if (!irq_save &&USE_LOCKLESS_FAST_PATH ())lockdep_assert_irqs_disabled ();if (s->flags & __CMPXCHG_DOUBLE) { ret =__update_freelist_fast (slab, freelist_old, counters_old, freelist_new, counters_new); }else { - ret =__update_freelist_slow (slab, freelist_old, counters_old, - freelist_new, counters_new); - } -if (likely (ret)) -return true; - -cpu_relax (); -stat (s,CMPXCHG_DOUBLE_FAIL ); - -#ifdef SLUB_DEBUG_CMPXCHG -pr_info ("%s %s: cmpxchg double redo " , n, s->name); -#endif - -return false; -} - -static inline bool slab_update_freelist (struct kmem_cache *s,struct slab *slab, -void *freelist_old,unsigned long counters_old, -void *freelist_new,unsigned long counters_new, -const char *n) -{ -bool ret; - -if (s->flags & __CMPXCHG_DOUBLE) { - ret =__update_freelist_fast (slab, freelist_old, counters_old, - freelist_new, counters_new); - }else {unsigned long flags; -local_irq_save (flags); +if (irq_save) +local_irq_save (flags); ret =__update_freelist_slow (slab, freelist_old, counters_old, freelist_new, counters_new); -local_irq_restore (flags); +if (irq_save) +local_irq_restore (flags); }if (likely (ret))return true;@@ -2250,10 +2226,10 @@ static inline void *acquire_slab(structVM_BUG_ON (new.frozen); new.frozen =1 ; -if (!__slab_update_freelist (s, slab, - freelist, counters, - new.freelist, new.counters, -"acquire_slab" )) +if (!slab_update_freelist (s, slab, + freelist, counters, + new.freelist, new.counters, + false,"acquire_slab" ))return NULL ;remove_partial (n, slab);@@ -2577,9 +2553,9 @@ static void deactivate_slab(struct kmem_if (!slab_update_freelist (s, slab, - old.freelist, old.counters, - new.freelist, new.counters, -"unfreezing slab" )) { + old.freelist, old.counters, + new.freelist, new.counters, + true,"unfreezing slab" )) {if (mode ==M_PARTIAL )spin_unlock_irqrestore (&n->list_lock, flags); goto redo;@@ -2633,10 +2609,10 @@ static void __unfreeze_partials(struct k new.frozen =0 ; - }while (!__slab_update_freelist (s, slab, - old.freelist, old.counters, - new.freelist, new.counters, -"unfreezing slab" )); + }while (!slab_update_freelist (s, slab, + old.freelist, old.counters, + new.freelist, new.counters, + false,"unfreezing slab" ));if (unlikely (!new.inuse && n->nr_partial >= s->min_partial)) { slab->next = slab_to_discard;@@ -3072,10 +3048,10 @@ static inline void *get_freelist(struct new.inuse = slab->objects; new.frozen = freelist !=NULL ; - }while (!__slab_update_freelist (s, slab, - freelist, counters, -NULL , new.counters, -"get_freelist" )); + }while (!slab_update_freelist (s, slab, + freelist, counters, +NULL , new.counters, + false,"get_freelist" ));return freelist; }@@ -3666,9 +3642,9 @@ static void __slab_free(struct kmem_cach } }while (!slab_update_freelist (s, slab, - prior, counters, - head, new.counters, -"__slab_free" )); + prior, counters, + head, new.counters, + true,"__slab_free" ));if (likely (!n)) {
Peter Zijlstra
maintainerPATCH v3 10/11 arch: Remove cmpxchg_double
In reply to Peter ZijlstraNo moar users, remove the monster.
--- Documentation/core-api/this_cpu_ops.rst | 2 - arch/arm64/include/asm/atomic_ll_sc.h | 33 ---------------- arch/arm64/include/asm/atomic_lse.h | 36 ------------------ arch/arm64/include/asm/cmpxchg.h | 46 ----------------------- arch/arm64/include/asm/percpu.h | 10 ----- arch/s390/include/asm/cmpxchg.h | 34 ----------------- arch/s390/include/asm/percpu.h | 18 --------- arch/x86/include/asm/cmpxchg.h | 25 ------------ arch/x86/include/asm/cmpxchg_32.h | 1 arch/x86/include/asm/cmpxchg_64.h | 1 arch/x86/include/asm/percpu.h | 41 -------------------- include/asm-generic/percpu.h | 58 ----------------------------- include/linux/atomic/atomic-instrumented.h | 17 -------- include/linux/percpu-defs.h | 38 ------------------- scripts/atomic/gen-atomic-instrumented.sh | 15 ++----- 15 files changed, 5 insertions(+), 370 deletions(-)
Documentation/core-api/this_cpu_ops.rst +0 -2
@@ -53,7 +53,6 @@ are defined. These operations can be use this_cpu_add_return(pcp, val) this_cpu_xchg(pcp, nval) this_cpu_cmpxchg(pcp, oval, nval) - this_cpu_cmpxchg_double(pcp1, pcp2, oval1, oval2, nval1, nval2) this_cpu_sub(pcp, val) this_cpu_inc(pcp) this_cpu_dec(pcp)
@@ -242,7 +241,6 @@ modifies the variable, then RMW actions __this_cpu_add_return(pcp, val) __this_cpu_xchg(pcp, nval) __this_cpu_cmpxchg(pcp, oval, nval) - __this_cpu_cmpxchg_double(pcp1, pcp2, oval1, oval2, nval1, nval2) __this_cpu_sub(pcp, val) __this_cpu_inc(pcp) __this_cpu_dec(pcp)
arch/arm64/include/asm/atomic_ll_sc.h +0 -33
@@ -294,39 +294,6 @@ __CMPXCHG_CASE( , , mb_, 64, dmb ish,#undef __CMPXCHG_CASE -#define __CMPXCHG_DBL (name, mb, rel, cl) \ -static __always_inline long \ -__ll_sc__cmpxchg_double##name(unsigned long old1, \ - unsigned long old2, \ - unsigned long new1, \ - unsigned long new2, \ - volatile void *ptr) \ -{ \ - unsigned long tmp, ret; \ - \ - asm volatile("// __cmpxchg_double" #name "\n" \ - " prfm pstl1strm, %2\n" \ - "1: ldxp %0, %1, %2\n" \ - " eor %0, %0, %3\n" \ - " eor %1, %1, %4\n" \ - " orr %1, %0, %1\n" \ - " cbnz %1, 2f\n" \ - " st" #rel "xp %w0, %5, %6, %2\n" \ - " cbnz %w0, 1b\n" \ - " " #mb "\n" \ - "2:" \ - : "=&r" (tmp), "=&r" (ret), "+Q" (*(__uint128_t *)ptr) \ - : "r" (old1), "r" (old2), "r" (new1), "r" (new2) \ - : cl); \ - \ - return ret; \ -} - -__CMPXCHG_DBL( , , , ) -__CMPXCHG_DBL(_mb, dmb ish, l, "memory") - -#undef __CMPXCHG_DBL -union __u128_halves {u128 full;struct {
arch/arm64/include/asm/atomic_lse.h +0 -36
@@ -281,42 +281,6 @@ __CMPXCHG_CASE(x, , mb_, 64, al, "memo#undef __CMPXCHG_CASE -#define __CMPXCHG_DBL(name, mb, cl...) \ -static __always_inline long \ -__lse__cmpxchg_double##name(unsigned long old1, \ - unsigned long old2, \ - unsigned long new1, \ - unsigned long new2, \ - volatile void *ptr) \ -{ \ - unsigned long oldval1 = old1; \ - unsigned long oldval2 = old2; \ - register unsigned long x0 asm ("x0") = old1; \ - register unsigned long x1 asm ("x1") = old2; \ - register unsigned long x2 asm ("x2") = new1; \ - register unsigned long x3 asm ("x3") = new2; \ - register unsigned long x4 asm ("x4") = (unsigned long)ptr; \ - \ - asm volatile( \ - __LSE_PREAMBLE \ - " casp" #mb "\t%[old1], %[old2], %[new1], %[new2], %[v]\n"\ - " eor %[old1], %[old1], %[oldval1]\n" \ - " eor %[old2], %[old2], %[oldval2]\n" \ - " orr %[old1], %[old1], %[old2]" \ - : [old1] "+&r" (x0), [old2] "+&r" (x1), \ - [v] "+Q" (*(__uint128_t *)ptr) \ - : [new1] "r" (x2), [new2] "r" (x3), [ptr] "r" (x4), \ - [oldval1] "r" (oldval1), [oldval2] "r" (oldval2) \ - : cl); \ - \ - return x0; \ -} - -__CMPXCHG_DBL( , ) -__CMPXCHG_DBL(_mb, al, "memory") - -#undef __CMPXCHG_DBL - #define __CMPXCHG128(name, mb, cl...) \ static __always_inline u128 \ __lse__cmpxchg128##name(volatile u128 *ptr, u128 old, u128 new) \
arch/arm64/include/asm/cmpxchg.h +0 -46
58 lines not on this page · raw message
arch/arm64/include/asm/percpu.h +0 -10
@@ -145,16 +145,6 @@ PERCPU_RET_OP(add, add, ldadd)* preemption point when TIF_NEED_RESCHED gets set while preemption is * disabled. */ -#define this_cpu_cmpxchg_double_8 (ptr1, ptr2, o1, o2, n1, n2) \ -({ \ - int __ret; \ - preempt_disable_notrace(); \ - __ret = cmpxchg_double_local( raw_cpu_ptr(&(ptr1)), \ - raw_cpu_ptr(&(ptr2)), \ - o1, o2, n1, n2); \ - preempt_enable_notrace(); \ - __ret; \ -})#define _pcp_protect (op, pcp, ...) \ ({ \
arch/s390/include/asm/cmpxchg.h +0 -34
@@ -190,40 +190,6 @@ static __always_inline unsigned long __c#define arch_cmpxchg_local arch_cmpxchg#define arch_cmpxchg64_local arch_cmpxchg -#define system_has_cmpxchg_double () 1 - -static __always_inline int __cmpxchg_double(unsigned long p1, unsigned long p2, -unsigned long o1,unsigned long o2, -unsigned long n1,unsigned long n2) -{ -union register_pair old = { .even = o1, .odd = o2, }; -union register_pair new = { .even = n1, .odd = n2, }; -int cc; - - asmvolatile ( -" cdsg %[old],%[new],%[ptr]\n" -" ipm %[cc]\n" -" srl %[cc],28\n" - : [cc]"=&d" (cc), [old]"+&d" (old.pair) - : [new]"d" (new.pair), - [ptr]"QS" (*(unsigned long *)p1),"Q" (*(unsigned long *)p2) - :"memory" ,"cc" ); -return !cc; -} - -#define arch_cmpxchg_double (p1, p2, o1, o2, n1, n2) \ -({ \ - typeof(p1) __p1 = (p1); \ - typeof(p2) __p2 = (p2); \ - \ - BUILD_BUG_ON(sizeof(*(p1)) != sizeof(long)); \ - BUILD_BUG_ON(sizeof(*(p2)) != sizeof(long)); \ - VM_BUG_ON((unsigned long)((__p1) + 1) != (unsigned long)(__p2));\ - __cmpxchg_double((unsigned long)__p1, (unsigned long)__p2, \ - (unsigned long)(o1), (unsigned long)(o2), \ - (unsigned long)(n1), (unsigned long)(n2)); \ -}) -#define system_has_cmpxchg128 () 1 static __always_inline u128 arch_cmpxchg128(volatile u128 *ptr, u128 old, u128 new)
arch/s390/include/asm/percpu.h +0 -18
@@ -180,24 +180,6 @@#define this_cpu_xchg_4 (pcp, nval) arch_this_cpu_xchg(pcp, nval)#define this_cpu_xchg_8 (pcp, nval) arch_this_cpu_xchg(pcp, nval) -#define arch_this_cpu_cmpxchg_double (pcp1, pcp2, o1, o2, n1, n2) \ -({ \ - typeof(pcp1) *p1__; \ - typeof(pcp2) *p2__; \ - int ret__; \ - \ - preempt_disable_notrace(); \ - p1__ = raw_cpu_ptr(&(pcp1)); \ - p2__ = raw_cpu_ptr(&(pcp2)); \ - ret__ = __cmpxchg_double((unsigned long)p1__, (unsigned long)p2__, \ - (unsigned long)(o1), (unsigned long)(o2), \ - (unsigned long)(n1), (unsigned long)(n2)); \ - preempt_enable_notrace(); \ - ret__; \ -}) - -#define this_cpu_cmpxchg_double_8 arch_this_cpu_cmpxchg_double -#include <asm-generic/percpu.h> #endif /* __ARCH_S390_PERCPU__ */
arch/x86/include/asm/cmpxchg.h +0 -25
@@ -239,29 +239,4 @@ extern void __add_wrong_size(void)#define __xadd (ptr, inc, lock) __xchg_op((ptr), (inc), xadd, lock)#define xadd (ptr, inc) __xadd((ptr), (inc), LOCK_PREFIX) -#define __cmpxchg_double (pfx, p1, p2, o1, o2, n1, n2) \ -({ \ - bool __ret; \ - __typeof__(*(p1)) __old1 = (o1), __new1 = (n1); \ - __typeof__(*(p2)) __old2 = (o2), __new2 = (n2); \ - BUILD_BUG_ON(sizeof(*(p1)) != sizeof(long)); \ - BUILD_BUG_ON(sizeof(*(p2)) != sizeof(long)); \ - VM_BUG_ON((unsigned long)(p1) % (2 * sizeof(long))); \ - VM_BUG_ON((unsigned long)((p1) + 1) != (unsigned long)(p2)); \ - asm volatile(pfx "cmpxchg%c5b %1" \ - CC_SET(e) \ - : CC_OUT(e) (__ret), \ - "+m" (*(p1)), "+m" (*(p2)), \ - "+a" (__old1), "+d" (__old2) \ - : "i" (2 * sizeof(long)), \ - "b" (__new1), "c" (__new2)); \ - __ret; \ -}) - -#define arch_cmpxchg_double (p1, p2, o1, o2, n1, n2) \ - __cmpxchg_double(LOCK_PREFIX, p1, p2, o1, o2, n1, n2) - -#define arch_cmpxchg_double_local (p1, p2, o1, o2, n1, n2) \ - __cmpxchg_double(, p1, p2, o1, o2, n1, n2) -#endif /* ASM_X86_CMPXCHG_H */
arch/x86/include/asm/cmpxchg_32.h +0 -1
@@ -103,7 +103,6 @@ static inline bool __try_cmpxchg64(volat#endif -#define system_has_cmpxchg_double () boot_cpu_has(X86_FEATURE_CX8)#define system_has_cmpxchg64 () boot_cpu_has(X86_FEATURE_CX8)#endif /* _ASM_X86_CMPXCHG_32_H */
arch/x86/include/asm/cmpxchg_64.h +0 -1
@@ -81,7 +81,6 @@ static __always_inline bool arch_try_cmp return __arch_try_cmpxchg128(ptr, oldp, new,); } -#define system_has_cmpxchg_double () boot_cpu_has(X86_FEATURE_CX16)#define system_has_cmpxchg128 () boot_cpu_has(X86_FEATURE_CX16)#endif /* _ASM_X86_CMPXCHG_64_H */
arch/x86/include/asm/percpu.h +0 -41
53 lines not on this page · raw message
include/asm-generic/percpu.h +0 -58
80 lines not on this page · raw message
include/linux/atomic/atomic-instrumented.h +1 -16
@@ -2234,21 +2234,6 @@ atomic_long_dec_if_positive(atomic_long_arch_try_cmpxchg128_local (__ai_ptr, __ai_oldp, __VA_ARGS__); \ }) -#define cmpxchg_double (ptr, ...) \ -({ \ - typeof(ptr) __ai_ptr = (ptr); \ - kcsan_mb(); \ - instrument_atomic_read_write(__ai_ptr, 2 * sizeof(*__ai_ptr)); \ - arch_cmpxchg_double(__ai_ptr, __VA_ARGS__); \ -}) - - -#define cmpxchg_double_local (ptr, ...) \ -({ \ - typeof(ptr) __ai_ptr = (ptr); \ - instrument_atomic_read_write(__ai_ptr, 2 * sizeof(*__ai_ptr)); \ - arch_cmpxchg_double_local(__ai_ptr, __VA_ARGS__); \ -})#endif /* _LINUX_ATOMIC_INSTRUMENTED_H */ -// 82d1be694fab30414527d0877c29fa75ed5a0b74 +// 3611991b015450e119bcd7417a9431af7f3ba13c
include/linux/percpu-defs.h +0 -38
@@ -343,33 +343,6 @@ static __always_inline void __this_cpu_p pscr2_ret__; \ }) -/* -* Special handling for cmpxchg_double. cmpxchg_double is passed two -* percpu variables. The first has to be aligned to a double word -* boundary and the second has to follow directly thereafter. -* We enforce this on all architectures even if they don't support -* a double cmpxchg instruction, since it's a cheap requirement, and it -* avoids breaking the requirement for architectures with the instruction. -*/ -#define __pcpu_double_call_return_bool (stem, pcp1, pcp2, ...) \ -({ \ - bool pdcrb_ret__; \ - __verify_pcpu_ptr(&(pcp1)); \ - BUILD_BUG_ON(sizeof(pcp1) != sizeof(pcp2)); \ - VM_BUG_ON((unsigned long)(&(pcp1)) % (2 * sizeof(pcp1))); \ - VM_BUG_ON((unsigned long)(&(pcp2)) != \ - (unsigned long)(&(pcp1)) + sizeof(pcp1)); \ - switch(sizeof(pcp1)) { \ - case 1: pdcrb_ret__ = stem##1(pcp1, pcp2, __VA_ARGS__); break; \ - case 2: pdcrb_ret__ = stem##2(pcp1, pcp2, __VA_ARGS__); break; \ - case 4: pdcrb_ret__ = stem##4(pcp1, pcp2, __VA_ARGS__); break; \ - case 8: pdcrb_ret__ = stem##8(pcp1, pcp2, __VA_ARGS__); break; \ - default: \ - __bad_size_call_parameter(); break; \ - } \ - pdcrb_ret__; \ -}) -#define __pcpu_size_call (stem, variable, ...) \ do { \ __verify_pcpu_ptr(&(variable)); \
@@ -426,9 +399,6 @@ do { \#define raw_cpu_xchg (pcp, nval) __pcpu_size_call_return2(raw_cpu_xchg_, pcp, nval)#define raw_cpu_cmpxchg (pcp, oval, nval) \ __pcpu_size_call_return2(raw_cpu_cmpxchg_, pcp, oval, nval) -#define raw_cpu_cmpxchg_double (pcp1, pcp2, oval1, oval2, nval1, nval2) \ - __pcpu_double_call_return_bool(raw_cpu_cmpxchg_double_, pcp1, pcp2, oval1, oval2, nval1, nval2) -#define raw_cpu_sub (pcp, val) raw_cpu_add(pcp, -(val))#define raw_cpu_inc (pcp) raw_cpu_add(pcp, 1)#define raw_cpu_dec (pcp) raw_cpu_sub(pcp, 1)
@@ -488,11 +458,6 @@ do { \raw_cpu_cmpxchg (pcp, oval, nval); \ }) -#define __this_cpu_cmpxchg_double (pcp1, pcp2, oval1, oval2, nval1, nval2) \ -({ __this_cpu_preempt_check("cmpxchg_double"); \ - raw_cpu_cmpxchg_double(pcp1, pcp2, oval1, oval2, nval1, nval2); \ -}) -#define __this_cpu_sub (pcp, val) __this_cpu_add(pcp, -(typeof(pcp))(val))#define __this_cpu_inc (pcp) __this_cpu_add(pcp, 1)#define __this_cpu_dec (pcp) __this_cpu_sub(pcp, 1)
@@ -513,9 +478,6 @@ do { \#define this_cpu_xchg (pcp, nval) __pcpu_size_call_return2(this_cpu_xchg_, pcp, nval)#define this_cpu_cmpxchg (pcp, oval, nval) \ __pcpu_size_call_return2(this_cpu_cmpxchg_, pcp, oval, nval) -#define this_cpu_cmpxchg_double (pcp1, pcp2, oval1, oval2, nval1, nval2) \ - __pcpu_double_call_return_bool(this_cpu_cmpxchg_double_, pcp1, pcp2, oval1, oval2, nval1, nval2) -#define this_cpu_sub (pcp, val) this_cpu_add(pcp, -(typeof(pcp))(val))#define this_cpu_inc (pcp) this_cpu_add(pcp, 1)#define this_cpu_dec (pcp) this_cpu_sub(pcp, 1)
scripts/atomic/gen-atomic-instrumented.sh +4 -11
@@ -84,7 +84,6 @@ gen_xchg() { local xchg="$1"; shift local order="$1"; shift - local mult="$1"; shift kcsan_barrier="" if [ "${xchg%_local}" = "${xchg}" ]; then
@@ -104,8 +103,8 @@ cat <<EOF EOF [ -n "$kcsan_barrier" ] && printf "\t${kcsan_barrier}; \\\\\n" cat <<EOF - instrument_atomic_read_write(__ai_ptr, ${mult}sizeof(*__ai_ptr)); \\ - instrument_read_write(__ai_oldp, ${mult}sizeof(*__ai_oldp)); \\ + instrument_atomic_read_write(__ai_ptr, sizeof(*__ai_ptr)); \\ + instrument_read_write(__ai_oldp, sizeof(*__ai_oldp)); \\ arch_${xchg}${order}(__ai_ptr, __ai_oldp, __VA_ARGS__); \\ }) EOF
@@ -168,22 +167,16 @@ done for xchg in "xchg" "cmpxchg" "cmpxchg64" "cmpxchg128" "try_cmpxchg" "try_cmpxchg64" "try_cmpxchg128"; do for order in "" "_acquire" "_release" "_relaxed"; do - gen_xchg "${xchg}" "${order}" "" + gen_xchg "${xchg}" "${order}" printf "\n" done done for xchg in "cmpxchg_local" "cmpxchg64_local" "cmpxchg128_local" "sync_cmpxchg" "try_cmpxchg_local" "try_cmpxchg64_local" "try_cmpxchg128_local"; do - gen_xchg "${xchg}" "" "" + gen_xchg "${xchg}" "" printf "\n" done -gen_xchg "cmpxchg_double" "" "2 * " - -printf "\n\n" - -gen_xchg "cmpxchg_double_local" "" "2 * " - cat <<EOF #endif /* _LINUX_ATOMIC_INSTRUMENTED_H */
Re: [PATCH v3 10/11] arch: Remove cmpxchg_double
Quoted 4 lines · Peter Zijlstra
No moar users, remove the monster.
Signed-off-by Peter Zijlstra (Intel) <[email protected]>---
...
Quoted 2 lines
arch/s390/include/asm/cmpxchg.h | 34 ----------------- arch/s390/include/asm/percpu.h | 18 ---------
FWIW, for s390:
[tip: locking/core] arch: Remove cmpxchg_double
In reply to Peter ZijlstraThe following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 47b8ba6f60d8ea9b64c94609ab50830d10a2662d Gitweb: https://git.kernel.org/tip/47b8ba6f60d8ea9b64c94609ab50830d10a2662d Author: Peter Zijlstra <[email protected]> AuthorDate: Mon, 15 May 2023 09:57:09 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 19 May 2023 12:35:15 +02:00
arch: Remove cmpxchg_double
No moar users, remove the monster.
--- Documentation/core-api/this_cpu_ops.rst | 2 +- arch/arm64/include/asm/atomic_ll_sc.h | 33 +------------ arch/arm64/include/asm/atomic_lse.h | 36 +------------- arch/arm64/include/asm/cmpxchg.h | 46 +----------------- arch/arm64/include/asm/percpu.h | 10 +---- arch/s390/include/asm/cmpxchg.h | 34 +------------ arch/s390/include/asm/percpu.h | 18 +------- arch/x86/include/asm/cmpxchg.h | 25 +--------- arch/x86/include/asm/cmpxchg_32.h | 1 +- arch/x86/include/asm/cmpxchg_64.h | 1 +- arch/x86/include/asm/percpu.h | 41 +--------------- include/asm-generic/percpu.h | 58 +--------------------- include/linux/atomic/atomic-instrumented.h | 17 +------ include/linux/percpu-defs.h | 38 +-------------- scripts/atomic/gen-atomic-instrumented.sh | 15 +---- 15 files changed, 5 insertions(+), 370 deletions(-)
Documentation/core-api/this_cpu_ops.rst +0 -2
@@ -53,7 +53,6 @@ preemption and interrupts:: this_cpu_add_return(pcp, val) this_cpu_xchg(pcp, nval) this_cpu_cmpxchg(pcp, oval, nval) - this_cpu_cmpxchg_double(pcp1, pcp2, oval1, oval2, nval1, nval2) this_cpu_sub(pcp, val) this_cpu_inc(pcp) this_cpu_dec(pcp)
@@ -242,7 +241,6 @@ safe:: __this_cpu_add_return(pcp, val) __this_cpu_xchg(pcp, nval) __this_cpu_cmpxchg(pcp, oval, nval) - __this_cpu_cmpxchg_double(pcp1, pcp2, oval1, oval2, nval1, nval2) __this_cpu_sub(pcp, val) __this_cpu_inc(pcp) __this_cpu_dec(pcp)
arch/arm64/include/asm/atomic_ll_sc.h +0 -33
@@ -294,39 +294,6 @@ __CMPXCHG_CASE( , , mb_, 64, dmb ish, , l, "memory", L)#undef __CMPXCHG_CASE -#define __CMPXCHG_DBL (name, mb, rel, cl) \ -static __always_inline long \ -__ll_sc__cmpxchg_double##name(unsigned long old1, \ - unsigned long old2, \ - unsigned long new1, \ - unsigned long new2, \ - volatile void *ptr) \ -{ \ - unsigned long tmp, ret; \ - \ - asm volatile("// __cmpxchg_double" #name "\n" \ - " prfm pstl1strm, %2\n" \ - "1: ldxp %0, %1, %2\n" \ - " eor %0, %0, %3\n" \ - " eor %1, %1, %4\n" \ - " orr %1, %0, %1\n" \ - " cbnz %1, 2f\n" \ - " st" #rel "xp %w0, %5, %6, %2\n" \ - " cbnz %w0, 1b\n" \ - " " #mb "\n" \ - "2:" \ - : "=&r" (tmp), "=&r" (ret), "+Q" (*(__uint128_t *)ptr) \ - : "r" (old1), "r" (old2), "r" (new1), "r" (new2) \ - : cl); \ - \ - return ret; \ -} - -__CMPXCHG_DBL( , , , ) -__CMPXCHG_DBL(_mb, dmb ish, l, "memory") - -#undef __CMPXCHG_DBL -union __u128_halves {u128 full;struct {
arch/arm64/include/asm/atomic_lse.h +0 -36
@@ -281,42 +281,6 @@ __CMPXCHG_CASE(x, , mb_, 64, al, "memory")#undef __CMPXCHG_CASE -#define __CMPXCHG_DBL(name, mb, cl...) \ -static __always_inline long \ -__lse__cmpxchg_double##name(unsigned long old1, \ - unsigned long old2, \ - unsigned long new1, \ - unsigned long new2, \ - volatile void *ptr) \ -{ \ - unsigned long oldval1 = old1; \ - unsigned long oldval2 = old2; \ - register unsigned long x0 asm ("x0") = old1; \ - register unsigned long x1 asm ("x1") = old2; \ - register unsigned long x2 asm ("x2") = new1; \ - register unsigned long x3 asm ("x3") = new2; \ - register unsigned long x4 asm ("x4") = (unsigned long)ptr; \ - \ - asm volatile( \ - __LSE_PREAMBLE \ - " casp" #mb "\t%[old1], %[old2], %[new1], %[new2], %[v]\n"\ - " eor %[old1], %[old1], %[oldval1]\n" \ - " eor %[old2], %[old2], %[oldval2]\n" \ - " orr %[old1], %[old1], %[old2]" \ - : [old1] "+&r" (x0), [old2] "+&r" (x1), \ - [v] "+Q" (*(__uint128_t *)ptr) \ - : [new1] "r" (x2), [new2] "r" (x3), [ptr] "r" (x4), \ - [oldval1] "r" (oldval1), [oldval2] "r" (oldval2) \ - : cl); \ - \ - return x0; \ -} - -__CMPXCHG_DBL( , ) -__CMPXCHG_DBL(_mb, al, "memory") - -#undef __CMPXCHG_DBL - #define __CMPXCHG128(name, mb, cl...) \ static __always_inline u128 \ __lse__cmpxchg128##name(volatile u128 *ptr, u128 old, u128 new) \
arch/arm64/include/asm/cmpxchg.h +0 -46
58 lines not on this page · raw message
arch/arm64/include/asm/percpu.h +0 -10
@@ -145,16 +145,6 @@ PERCPU_RET_OP(add, add, ldadd)* preemption point when TIF_NEED_RESCHED gets set while preemption is * disabled. */ -#define this_cpu_cmpxchg_double_8 (ptr1, ptr2, o1, o2, n1, n2) \ -({ \ - int __ret; \ - preempt_disable_notrace(); \ - __ret = cmpxchg_double_local( raw_cpu_ptr(&(ptr1)), \ - raw_cpu_ptr(&(ptr2)), \ - o1, o2, n1, n2); \ - preempt_enable_notrace(); \ - __ret; \ -})#define _pcp_protect (op, pcp, ...) \ ({ \
arch/s390/include/asm/cmpxchg.h +0 -34
@@ -190,40 +190,6 @@ static __always_inline unsigned long __cmpxchg(unsigned long address,#define arch_cmpxchg_local arch_cmpxchg#define arch_cmpxchg64_local arch_cmpxchg -#define system_has_cmpxchg_double () 1 - -static __always_inline int __cmpxchg_double(unsigned long p1, unsigned long p2, -unsigned long o1,unsigned long o2, -unsigned long n1,unsigned long n2) -{ -union register_pair old = { .even = o1, .odd = o2, }; -union register_pair new = { .even = n1, .odd = n2, }; -int cc; - - asmvolatile ( -" cdsg %[old],%[new],%[ptr]\n" -" ipm %[cc]\n" -" srl %[cc],28\n" - : [cc]"=&d" (cc), [old]"+&d" (old.pair) - : [new]"d" (new.pair), - [ptr]"QS" (*(unsigned long *)p1),"Q" (*(unsigned long *)p2) - :"memory" ,"cc" ); -return !cc; -} - -#define arch_cmpxchg_double (p1, p2, o1, o2, n1, n2) \ -({ \ - typeof(p1) __p1 = (p1); \ - typeof(p2) __p2 = (p2); \ - \ - BUILD_BUG_ON(sizeof(*(p1)) != sizeof(long)); \ - BUILD_BUG_ON(sizeof(*(p2)) != sizeof(long)); \ - VM_BUG_ON((unsigned long)((__p1) + 1) != (unsigned long)(__p2));\ - __cmpxchg_double((unsigned long)__p1, (unsigned long)__p2, \ - (unsigned long)(o1), (unsigned long)(o2), \ - (unsigned long)(n1), (unsigned long)(n2)); \ -}) -#define system_has_cmpxchg128 () 1 static __always_inline u128 arch_cmpxchg128(volatile u128 *ptr, u128 old, u128 new)
arch/s390/include/asm/percpu.h +0 -18
@@ -180,24 +180,6 @@#define this_cpu_xchg_4 (pcp, nval) arch_this_cpu_xchg(pcp, nval)#define this_cpu_xchg_8 (pcp, nval) arch_this_cpu_xchg(pcp, nval) -#define arch_this_cpu_cmpxchg_double (pcp1, pcp2, o1, o2, n1, n2) \ -({ \ - typeof(pcp1) *p1__; \ - typeof(pcp2) *p2__; \ - int ret__; \ - \ - preempt_disable_notrace(); \ - p1__ = raw_cpu_ptr(&(pcp1)); \ - p2__ = raw_cpu_ptr(&(pcp2)); \ - ret__ = __cmpxchg_double((unsigned long)p1__, (unsigned long)p2__, \ - (unsigned long)(o1), (unsigned long)(o2), \ - (unsigned long)(n1), (unsigned long)(n2)); \ - preempt_enable_notrace(); \ - ret__; \ -}) - -#define this_cpu_cmpxchg_double_8 arch_this_cpu_cmpxchg_double -#include <asm-generic/percpu.h> #endif /* __ARCH_S390_PERCPU__ */
arch/x86/include/asm/cmpxchg.h +0 -25
@@ -239,29 +239,4 @@ extern void __add_wrong_size(void)#define __xadd (ptr, inc, lock) __xchg_op((ptr), (inc), xadd, lock)#define xadd (ptr, inc) __xadd((ptr), (inc), LOCK_PREFIX) -#define __cmpxchg_double (pfx, p1, p2, o1, o2, n1, n2) \ -({ \ - bool __ret; \ - __typeof__(*(p1)) __old1 = (o1), __new1 = (n1); \ - __typeof__(*(p2)) __old2 = (o2), __new2 = (n2); \ - BUILD_BUG_ON(sizeof(*(p1)) != sizeof(long)); \ - BUILD_BUG_ON(sizeof(*(p2)) != sizeof(long)); \ - VM_BUG_ON((unsigned long)(p1) % (2 * sizeof(long))); \ - VM_BUG_ON((unsigned long)((p1) + 1) != (unsigned long)(p2)); \ - asm volatile(pfx "cmpxchg%c5b %1" \ - CC_SET(e) \ - : CC_OUT(e) (__ret), \ - "+m" (*(p1)), "+m" (*(p2)), \ - "+a" (__old1), "+d" (__old2) \ - : "i" (2 * sizeof(long)), \ - "b" (__new1), "c" (__new2)); \ - __ret; \ -}) - -#define arch_cmpxchg_double (p1, p2, o1, o2, n1, n2) \ - __cmpxchg_double(LOCK_PREFIX, p1, p2, o1, o2, n1, n2) - -#define arch_cmpxchg_double_local (p1, p2, o1, o2, n1, n2) \ - __cmpxchg_double(, p1, p2, o1, o2, n1, n2) -#endif /* ASM_X86_CMPXCHG_H */
arch/x86/include/asm/cmpxchg_32.h +0 -1
@@ -103,7 +103,6 @@ static inline bool __try_cmpxchg64(volatile u64 *ptr, u64 *pold, u64 new)#endif -#define system_has_cmpxchg_double () boot_cpu_has(X86_FEATURE_CX8)#define system_has_cmpxchg64 () boot_cpu_has(X86_FEATURE_CX8)#endif /* _ASM_X86_CMPXCHG_32_H */
arch/x86/include/asm/cmpxchg_64.h +0 -1
@@ -81,7 +81,6 @@ static __always_inline bool arch_try_cmpxchg128_local(volatile u128 *ptr, u128 * return __arch_try_cmpxchg128(ptr, oldp, new,); } -#define system_has_cmpxchg_double () boot_cpu_has(X86_FEATURE_CX16)#define system_has_cmpxchg128 () boot_cpu_has(X86_FEATURE_CX16)#endif /* _ASM_X86_CMPXCHG_64_H */
arch/x86/include/asm/percpu.h +0 -41
53 lines not on this page · raw message
include/asm-generic/percpu.h +0 -58
80 lines not on this page · raw message
include/linux/atomic/atomic-instrumented.h +1 -16
@@ -2234,21 +2234,6 @@ atomic_long_dec_if_positive(atomic_long_t *v)arch_try_cmpxchg128_local (__ai_ptr, __ai_oldp, __VA_ARGS__); \ }) -#define cmpxchg_double (ptr, ...) \ -({ \ - typeof(ptr) __ai_ptr = (ptr); \ - kcsan_mb(); \ - instrument_atomic_read_write(__ai_ptr, 2 * sizeof(*__ai_ptr)); \ - arch_cmpxchg_double(__ai_ptr, __VA_ARGS__); \ -}) - - -#define cmpxchg_double_local (ptr, ...) \ -({ \ - typeof(ptr) __ai_ptr = (ptr); \ - instrument_atomic_read_write(__ai_ptr, 2 * sizeof(*__ai_ptr)); \ - arch_cmpxchg_double_local(__ai_ptr, __VA_ARGS__); \ -})#endif /* _LINUX_ATOMIC_INSTRUMENTED_H */ -// 82d1be694fab30414527d0877c29fa75ed5a0b74 +// 3611991b015450e119bcd7417a9431af7f3ba13c
include/linux/percpu-defs.h +0 -38
@@ -343,33 +343,6 @@ static __always_inline void __this_cpu_preempt_check(const char *op) { } pscr2_ret__; \ }) -/* -* Special handling for cmpxchg_double. cmpxchg_double is passed two -* percpu variables. The first has to be aligned to a double word -* boundary and the second has to follow directly thereafter. -* We enforce this on all architectures even if they don't support -* a double cmpxchg instruction, since it's a cheap requirement, and it -* avoids breaking the requirement for architectures with the instruction. -*/ -#define __pcpu_double_call_return_bool (stem, pcp1, pcp2, ...) \ -({ \ - bool pdcrb_ret__; \ - __verify_pcpu_ptr(&(pcp1)); \ - BUILD_BUG_ON(sizeof(pcp1) != sizeof(pcp2)); \ - VM_BUG_ON((unsigned long)(&(pcp1)) % (2 * sizeof(pcp1))); \ - VM_BUG_ON((unsigned long)(&(pcp2)) != \ - (unsigned long)(&(pcp1)) + sizeof(pcp1)); \ - switch(sizeof(pcp1)) { \ - case 1: pdcrb_ret__ = stem##1(pcp1, pcp2, __VA_ARGS__); break; \ - case 2: pdcrb_ret__ = stem##2(pcp1, pcp2, __VA_ARGS__); break; \ - case 4: pdcrb_ret__ = stem##4(pcp1, pcp2, __VA_ARGS__); break; \ - case 8: pdcrb_ret__ = stem##8(pcp1, pcp2, __VA_ARGS__); break; \ - default: \ - __bad_size_call_parameter(); break; \ - } \ - pdcrb_ret__; \ -}) -#define __pcpu_size_call (stem, variable, ...) \ do { \ __verify_pcpu_ptr(&(variable)); \
@@ -426,9 +399,6 @@ do { \#define raw_cpu_xchg (pcp, nval) __pcpu_size_call_return2(raw_cpu_xchg_, pcp, nval)#define raw_cpu_cmpxchg (pcp, oval, nval) \ __pcpu_size_call_return2(raw_cpu_cmpxchg_, pcp, oval, nval) -#define raw_cpu_cmpxchg_double (pcp1, pcp2, oval1, oval2, nval1, nval2) \ - __pcpu_double_call_return_bool(raw_cpu_cmpxchg_double_, pcp1, pcp2, oval1, oval2, nval1, nval2) -#define raw_cpu_sub (pcp, val) raw_cpu_add(pcp, -(val))#define raw_cpu_inc (pcp) raw_cpu_add(pcp, 1)#define raw_cpu_dec (pcp) raw_cpu_sub(pcp, 1)
@@ -488,11 +458,6 @@ do { \raw_cpu_cmpxchg (pcp, oval, nval); \ }) -#define __this_cpu_cmpxchg_double (pcp1, pcp2, oval1, oval2, nval1, nval2) \ -({ __this_cpu_preempt_check("cmpxchg_double"); \ - raw_cpu_cmpxchg_double(pcp1, pcp2, oval1, oval2, nval1, nval2); \ -}) -#define __this_cpu_sub (pcp, val) __this_cpu_add(pcp, -(typeof(pcp))(val))#define __this_cpu_inc (pcp) __this_cpu_add(pcp, 1)#define __this_cpu_dec (pcp) __this_cpu_sub(pcp, 1)
@@ -513,9 +478,6 @@ do { \#define this_cpu_xchg (pcp, nval) __pcpu_size_call_return2(this_cpu_xchg_, pcp, nval)#define this_cpu_cmpxchg (pcp, oval, nval) \ __pcpu_size_call_return2(this_cpu_cmpxchg_, pcp, oval, nval) -#define this_cpu_cmpxchg_double (pcp1, pcp2, oval1, oval2, nval1, nval2) \ - __pcpu_double_call_return_bool(this_cpu_cmpxchg_double_, pcp1, pcp2, oval1, oval2, nval1, nval2) -#define this_cpu_sub (pcp, val) this_cpu_add(pcp, -(typeof(pcp))(val))#define this_cpu_inc (pcp) this_cpu_add(pcp, 1)#define this_cpu_dec (pcp) this_cpu_sub(pcp, 1)
scripts/atomic/gen-atomic-instrumented.sh +4 -11
@@ -84,7 +84,6 @@ gen_xchg() { local xchg="$1"; shift local order="$1"; shift - local mult="$1"; shift kcsan_barrier="" if [ "${xchg%_local}" = "${xchg}" ]; then
@@ -104,8 +103,8 @@ cat <<EOF EOF [ -n "$kcsan_barrier" ] && printf "\t${kcsan_barrier}; \\\\\n" cat <<EOF - instrument_atomic_read_write(__ai_ptr, ${mult}sizeof(*__ai_ptr)); \\ - instrument_read_write(__ai_oldp, ${mult}sizeof(*__ai_oldp)); \\ + instrument_atomic_read_write(__ai_ptr, sizeof(*__ai_ptr)); \\ + instrument_read_write(__ai_oldp, sizeof(*__ai_oldp)); \\ arch_${xchg}${order}(__ai_ptr, __ai_oldp, __VA_ARGS__); \\ }) EOF
@@ -168,22 +167,16 @@ done for xchg in "xchg" "cmpxchg" "cmpxchg64" "cmpxchg128" "try_cmpxchg" "try_cmpxchg64" "try_cmpxchg128"; do for order in "" "_acquire" "_release" "_relaxed"; do - gen_xchg "${xchg}" "${order}" "" + gen_xchg "${xchg}" "${order}" printf "\n" done done for xchg in "cmpxchg_local" "cmpxchg64_local" "cmpxchg128_local" "sync_cmpxchg" "try_cmpxchg_local" "try_cmpxchg64_local" "try_cmpxchg128_local"; do - gen_xchg "${xchg}" "" "" + gen_xchg "${xchg}" "" printf "\n" done -gen_xchg "cmpxchg_double" "" "2 * " - -printf "\n\n" - -gen_xchg "cmpxchg_double_local" "" "2 * " - cat <<EOF #endif /* _LINUX_ATOMIC_INSTRUMENTED_H */
[tip: locking/core] arch: Remove cmpxchg_double
In reply to Peter ZijlstraThe following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: b4cf83b2d1da40b253eeb0b8122e20b89b7dd4e7 Gitweb: https://git.kernel.org/tip/b4cf83b2d1da40b253eeb0b8122e20b89b7dd4e7 Author: Peter Zijlstra <[email protected]> AuthorDate: Mon, 15 May 2023 09:57:09 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Mon, 22 May 2023 10:49:50 +02:00
arch: Remove cmpxchg_double
No moar users, remove the monster.
--- Documentation/core-api/this_cpu_ops.rst | 2 +- arch/arm64/include/asm/atomic_ll_sc.h | 33 +------------ arch/arm64/include/asm/atomic_lse.h | 36 +------------- arch/arm64/include/asm/cmpxchg.h | 46 +----------------- arch/arm64/include/asm/percpu.h | 10 +---- arch/s390/include/asm/cmpxchg.h | 34 +------------ arch/s390/include/asm/percpu.h | 18 +------- arch/x86/include/asm/cmpxchg.h | 25 +--------- arch/x86/include/asm/cmpxchg_32.h | 1 +- arch/x86/include/asm/cmpxchg_64.h | 1 +- arch/x86/include/asm/percpu.h | 41 +--------------- include/asm-generic/percpu.h | 58 +--------------------- include/linux/atomic/atomic-instrumented.h | 17 +------ include/linux/percpu-defs.h | 38 +-------------- scripts/atomic/gen-atomic-instrumented.sh | 15 +---- 15 files changed, 5 insertions(+), 370 deletions(-)
Documentation/core-api/this_cpu_ops.rst +0 -2
@@ -53,7 +53,6 @@ preemption and interrupts:: this_cpu_add_return(pcp, val) this_cpu_xchg(pcp, nval) this_cpu_cmpxchg(pcp, oval, nval) - this_cpu_cmpxchg_double(pcp1, pcp2, oval1, oval2, nval1, nval2) this_cpu_sub(pcp, val) this_cpu_inc(pcp) this_cpu_dec(pcp)
@@ -242,7 +241,6 @@ safe:: __this_cpu_add_return(pcp, val) __this_cpu_xchg(pcp, nval) __this_cpu_cmpxchg(pcp, oval, nval) - __this_cpu_cmpxchg_double(pcp1, pcp2, oval1, oval2, nval1, nval2) __this_cpu_sub(pcp, val) __this_cpu_inc(pcp) __this_cpu_dec(pcp)
arch/arm64/include/asm/atomic_ll_sc.h +0 -33
@@ -294,39 +294,6 @@ __CMPXCHG_CASE( , , mb_, 64, dmb ish, , l, "memory", L)#undef __CMPXCHG_CASE -#define __CMPXCHG_DBL (name, mb, rel, cl) \ -static __always_inline long \ -__ll_sc__cmpxchg_double##name(unsigned long old1, \ - unsigned long old2, \ - unsigned long new1, \ - unsigned long new2, \ - volatile void *ptr) \ -{ \ - unsigned long tmp, ret; \ - \ - asm volatile("// __cmpxchg_double" #name "\n" \ - " prfm pstl1strm, %2\n" \ - "1: ldxp %0, %1, %2\n" \ - " eor %0, %0, %3\n" \ - " eor %1, %1, %4\n" \ - " orr %1, %0, %1\n" \ - " cbnz %1, 2f\n" \ - " st" #rel "xp %w0, %5, %6, %2\n" \ - " cbnz %w0, 1b\n" \ - " " #mb "\n" \ - "2:" \ - : "=&r" (tmp), "=&r" (ret), "+Q" (*(__uint128_t *)ptr) \ - : "r" (old1), "r" (old2), "r" (new1), "r" (new2) \ - : cl); \ - \ - return ret; \ -} - -__CMPXCHG_DBL( , , , ) -__CMPXCHG_DBL(_mb, dmb ish, l, "memory") - -#undef __CMPXCHG_DBL -union __u128_halves {u128 full;struct {
arch/arm64/include/asm/atomic_lse.h +0 -36
@@ -281,42 +281,6 @@ __CMPXCHG_CASE(x, , mb_, 64, al, "memory")#undef __CMPXCHG_CASE -#define __CMPXCHG_DBL(name, mb, cl...) \ -static __always_inline long \ -__lse__cmpxchg_double##name(unsigned long old1, \ - unsigned long old2, \ - unsigned long new1, \ - unsigned long new2, \ - volatile void *ptr) \ -{ \ - unsigned long oldval1 = old1; \ - unsigned long oldval2 = old2; \ - register unsigned long x0 asm ("x0") = old1; \ - register unsigned long x1 asm ("x1") = old2; \ - register unsigned long x2 asm ("x2") = new1; \ - register unsigned long x3 asm ("x3") = new2; \ - register unsigned long x4 asm ("x4") = (unsigned long)ptr; \ - \ - asm volatile( \ - __LSE_PREAMBLE \ - " casp" #mb "\t%[old1], %[old2], %[new1], %[new2], %[v]\n"\ - " eor %[old1], %[old1], %[oldval1]\n" \ - " eor %[old2], %[old2], %[oldval2]\n" \ - " orr %[old1], %[old1], %[old2]" \ - : [old1] "+&r" (x0), [old2] "+&r" (x1), \ - [v] "+Q" (*(__uint128_t *)ptr) \ - : [new1] "r" (x2), [new2] "r" (x3), [ptr] "r" (x4), \ - [oldval1] "r" (oldval1), [oldval2] "r" (oldval2) \ - : cl); \ - \ - return x0; \ -} - -__CMPXCHG_DBL( , ) -__CMPXCHG_DBL(_mb, al, "memory") - -#undef __CMPXCHG_DBL - #define __CMPXCHG128(name, mb, cl...) \ static __always_inline u128 \ __lse__cmpxchg128##name(volatile u128 *ptr, u128 old, u128 new) \
arch/arm64/include/asm/cmpxchg.h +0 -46
58 lines not on this page · raw message
arch/arm64/include/asm/percpu.h +0 -10
@@ -145,16 +145,6 @@ PERCPU_RET_OP(add, add, ldadd)* preemption point when TIF_NEED_RESCHED gets set while preemption is * disabled. */ -#define this_cpu_cmpxchg_double_8 (ptr1, ptr2, o1, o2, n1, n2) \ -({ \ - int __ret; \ - preempt_disable_notrace(); \ - __ret = cmpxchg_double_local( raw_cpu_ptr(&(ptr1)), \ - raw_cpu_ptr(&(ptr2)), \ - o1, o2, n1, n2); \ - preempt_enable_notrace(); \ - __ret; \ -})#define _pcp_protect (op, pcp, ...) \ ({ \
arch/s390/include/asm/cmpxchg.h +0 -34
@@ -190,40 +190,6 @@ static __always_inline unsigned long __cmpxchg(unsigned long address,#define arch_cmpxchg_local arch_cmpxchg#define arch_cmpxchg64_local arch_cmpxchg -#define system_has_cmpxchg_double () 1 - -static __always_inline int __cmpxchg_double(unsigned long p1, unsigned long p2, -unsigned long o1,unsigned long o2, -unsigned long n1,unsigned long n2) -{ -union register_pair old = { .even = o1, .odd = o2, }; -union register_pair new = { .even = n1, .odd = n2, }; -int cc; - - asmvolatile ( -" cdsg %[old],%[new],%[ptr]\n" -" ipm %[cc]\n" -" srl %[cc],28\n" - : [cc]"=&d" (cc), [old]"+&d" (old.pair) - : [new]"d" (new.pair), - [ptr]"QS" (*(unsigned long *)p1),"Q" (*(unsigned long *)p2) - :"memory" ,"cc" ); -return !cc; -} - -#define arch_cmpxchg_double (p1, p2, o1, o2, n1, n2) \ -({ \ - typeof(p1) __p1 = (p1); \ - typeof(p2) __p2 = (p2); \ - \ - BUILD_BUG_ON(sizeof(*(p1)) != sizeof(long)); \ - BUILD_BUG_ON(sizeof(*(p2)) != sizeof(long)); \ - VM_BUG_ON((unsigned long)((__p1) + 1) != (unsigned long)(__p2));\ - __cmpxchg_double((unsigned long)__p1, (unsigned long)__p2, \ - (unsigned long)(o1), (unsigned long)(o2), \ - (unsigned long)(n1), (unsigned long)(n2)); \ -}) -#define system_has_cmpxchg128 () 1 static __always_inline u128 arch_cmpxchg128(volatile u128 *ptr, u128 old, u128 new)
arch/s390/include/asm/percpu.h +0 -18
@@ -180,24 +180,6 @@#define this_cpu_xchg_4 (pcp, nval) arch_this_cpu_xchg(pcp, nval)#define this_cpu_xchg_8 (pcp, nval) arch_this_cpu_xchg(pcp, nval) -#define arch_this_cpu_cmpxchg_double (pcp1, pcp2, o1, o2, n1, n2) \ -({ \ - typeof(pcp1) *p1__; \ - typeof(pcp2) *p2__; \ - int ret__; \ - \ - preempt_disable_notrace(); \ - p1__ = raw_cpu_ptr(&(pcp1)); \ - p2__ = raw_cpu_ptr(&(pcp2)); \ - ret__ = __cmpxchg_double((unsigned long)p1__, (unsigned long)p2__, \ - (unsigned long)(o1), (unsigned long)(o2), \ - (unsigned long)(n1), (unsigned long)(n2)); \ - preempt_enable_notrace(); \ - ret__; \ -}) - -#define this_cpu_cmpxchg_double_8 arch_this_cpu_cmpxchg_double -#include <asm-generic/percpu.h> #endif /* __ARCH_S390_PERCPU__ */
arch/x86/include/asm/cmpxchg.h +0 -25
@@ -239,29 +239,4 @@ extern void __add_wrong_size(void)#define __xadd (ptr, inc, lock) __xchg_op((ptr), (inc), xadd, lock)#define xadd (ptr, inc) __xadd((ptr), (inc), LOCK_PREFIX) -#define __cmpxchg_double (pfx, p1, p2, o1, o2, n1, n2) \ -({ \ - bool __ret; \ - __typeof__(*(p1)) __old1 = (o1), __new1 = (n1); \ - __typeof__(*(p2)) __old2 = (o2), __new2 = (n2); \ - BUILD_BUG_ON(sizeof(*(p1)) != sizeof(long)); \ - BUILD_BUG_ON(sizeof(*(p2)) != sizeof(long)); \ - VM_BUG_ON((unsigned long)(p1) % (2 * sizeof(long))); \ - VM_BUG_ON((unsigned long)((p1) + 1) != (unsigned long)(p2)); \ - asm volatile(pfx "cmpxchg%c5b %1" \ - CC_SET(e) \ - : CC_OUT(e) (__ret), \ - "+m" (*(p1)), "+m" (*(p2)), \ - "+a" (__old1), "+d" (__old2) \ - : "i" (2 * sizeof(long)), \ - "b" (__new1), "c" (__new2)); \ - __ret; \ -}) - -#define arch_cmpxchg_double (p1, p2, o1, o2, n1, n2) \ - __cmpxchg_double(LOCK_PREFIX, p1, p2, o1, o2, n1, n2) - -#define arch_cmpxchg_double_local (p1, p2, o1, o2, n1, n2) \ - __cmpxchg_double(, p1, p2, o1, o2, n1, n2) -#endif /* ASM_X86_CMPXCHG_H */
arch/x86/include/asm/cmpxchg_32.h +0 -1
@@ -103,7 +103,6 @@ static inline bool __try_cmpxchg64(volatile u64 *ptr, u64 *pold, u64 new)#endif -#define system_has_cmpxchg_double () boot_cpu_has(X86_FEATURE_CX8)#define system_has_cmpxchg64 () boot_cpu_has(X86_FEATURE_CX8)#endif /* _ASM_X86_CMPXCHG_32_H */
arch/x86/include/asm/cmpxchg_64.h +0 -1
@@ -81,7 +81,6 @@ static __always_inline bool arch_try_cmpxchg128_local(volatile u128 *ptr, u128 * return __arch_try_cmpxchg128(ptr, oldp, new,); } -#define system_has_cmpxchg_double () boot_cpu_has(X86_FEATURE_CX16)#define system_has_cmpxchg128 () boot_cpu_has(X86_FEATURE_CX16)#endif /* _ASM_X86_CMPXCHG_64_H */
arch/x86/include/asm/percpu.h +0 -41
53 lines not on this page · raw message
include/asm-generic/percpu.h +0 -58
80 lines not on this page · raw message
include/linux/atomic/atomic-instrumented.h +1 -16
@@ -2234,21 +2234,6 @@ atomic_long_dec_if_positive(atomic_long_t *v)arch_try_cmpxchg128_local (__ai_ptr, __ai_oldp, __VA_ARGS__); \ }) -#define cmpxchg_double (ptr, ...) \ -({ \ - typeof(ptr) __ai_ptr = (ptr); \ - kcsan_mb(); \ - instrument_atomic_read_write(__ai_ptr, 2 * sizeof(*__ai_ptr)); \ - arch_cmpxchg_double(__ai_ptr, __VA_ARGS__); \ -}) - - -#define cmpxchg_double_local (ptr, ...) \ -({ \ - typeof(ptr) __ai_ptr = (ptr); \ - instrument_atomic_read_write(__ai_ptr, 2 * sizeof(*__ai_ptr)); \ - arch_cmpxchg_double_local(__ai_ptr, __VA_ARGS__); \ -})#endif /* _LINUX_ATOMIC_INSTRUMENTED_H */ -// 82d1be694fab30414527d0877c29fa75ed5a0b74 +// 3611991b015450e119bcd7417a9431af7f3ba13c
include/linux/percpu-defs.h +0 -38
@@ -343,33 +343,6 @@ static __always_inline void __this_cpu_preempt_check(const char *op) { } pscr2_ret__; \ }) -/* -* Special handling for cmpxchg_double. cmpxchg_double is passed two -* percpu variables. The first has to be aligned to a double word -* boundary and the second has to follow directly thereafter. -* We enforce this on all architectures even if they don't support -* a double cmpxchg instruction, since it's a cheap requirement, and it -* avoids breaking the requirement for architectures with the instruction. -*/ -#define __pcpu_double_call_return_bool (stem, pcp1, pcp2, ...) \ -({ \ - bool pdcrb_ret__; \ - __verify_pcpu_ptr(&(pcp1)); \ - BUILD_BUG_ON(sizeof(pcp1) != sizeof(pcp2)); \ - VM_BUG_ON((unsigned long)(&(pcp1)) % (2 * sizeof(pcp1))); \ - VM_BUG_ON((unsigned long)(&(pcp2)) != \ - (unsigned long)(&(pcp1)) + sizeof(pcp1)); \ - switch(sizeof(pcp1)) { \ - case 1: pdcrb_ret__ = stem##1(pcp1, pcp2, __VA_ARGS__); break; \ - case 2: pdcrb_ret__ = stem##2(pcp1, pcp2, __VA_ARGS__); break; \ - case 4: pdcrb_ret__ = stem##4(pcp1, pcp2, __VA_ARGS__); break; \ - case 8: pdcrb_ret__ = stem##8(pcp1, pcp2, __VA_ARGS__); break; \ - default: \ - __bad_size_call_parameter(); break; \ - } \ - pdcrb_ret__; \ -}) -#define __pcpu_size_call (stem, variable, ...) \ do { \ __verify_pcpu_ptr(&(variable)); \
@@ -426,9 +399,6 @@ do { \#define raw_cpu_xchg (pcp, nval) __pcpu_size_call_return2(raw_cpu_xchg_, pcp, nval)#define raw_cpu_cmpxchg (pcp, oval, nval) \ __pcpu_size_call_return2(raw_cpu_cmpxchg_, pcp, oval, nval) -#define raw_cpu_cmpxchg_double (pcp1, pcp2, oval1, oval2, nval1, nval2) \ - __pcpu_double_call_return_bool(raw_cpu_cmpxchg_double_, pcp1, pcp2, oval1, oval2, nval1, nval2) -#define raw_cpu_sub (pcp, val) raw_cpu_add(pcp, -(val))#define raw_cpu_inc (pcp) raw_cpu_add(pcp, 1)#define raw_cpu_dec (pcp) raw_cpu_sub(pcp, 1)
@@ -488,11 +458,6 @@ do { \raw_cpu_cmpxchg (pcp, oval, nval); \ }) -#define __this_cpu_cmpxchg_double (pcp1, pcp2, oval1, oval2, nval1, nval2) \ -({ __this_cpu_preempt_check("cmpxchg_double"); \ - raw_cpu_cmpxchg_double(pcp1, pcp2, oval1, oval2, nval1, nval2); \ -}) -#define __this_cpu_sub (pcp, val) __this_cpu_add(pcp, -(typeof(pcp))(val))#define __this_cpu_inc (pcp) __this_cpu_add(pcp, 1)#define __this_cpu_dec (pcp) __this_cpu_sub(pcp, 1)
@@ -513,9 +478,6 @@ do { \#define this_cpu_xchg (pcp, nval) __pcpu_size_call_return2(this_cpu_xchg_, pcp, nval)#define this_cpu_cmpxchg (pcp, oval, nval) \ __pcpu_size_call_return2(this_cpu_cmpxchg_, pcp, oval, nval) -#define this_cpu_cmpxchg_double (pcp1, pcp2, oval1, oval2, nval1, nval2) \ - __pcpu_double_call_return_bool(this_cpu_cmpxchg_double_, pcp1, pcp2, oval1, oval2, nval1, nval2) -#define this_cpu_sub (pcp, val) this_cpu_add(pcp, -(typeof(pcp))(val))#define this_cpu_inc (pcp) this_cpu_add(pcp, 1)#define this_cpu_dec (pcp) this_cpu_sub(pcp, 1)
scripts/atomic/gen-atomic-instrumented.sh +4 -11
@@ -84,7 +84,6 @@ gen_xchg() { local xchg="$1"; shift local order="$1"; shift - local mult="$1"; shift kcsan_barrier="" if [ "${xchg%_local}" = "${xchg}" ]; then
@@ -104,8 +103,8 @@ cat <<EOF EOF [ -n "$kcsan_barrier" ] && printf "\t${kcsan_barrier}; \\\\\n" cat <<EOF - instrument_atomic_read_write(__ai_ptr, ${mult}sizeof(*__ai_ptr)); \\ - instrument_read_write(__ai_oldp, ${mult}sizeof(*__ai_oldp)); \\ + instrument_atomic_read_write(__ai_ptr, sizeof(*__ai_ptr)); \\ + instrument_read_write(__ai_oldp, sizeof(*__ai_oldp)); \\ arch_${xchg}${order}(__ai_ptr, __ai_oldp, __VA_ARGS__); \\ }) EOF
@@ -168,22 +167,16 @@ done for xchg in "xchg" "cmpxchg" "cmpxchg64" "cmpxchg128" "try_cmpxchg" "try_cmpxchg64" "try_cmpxchg128"; do for order in "" "_acquire" "_release" "_relaxed"; do - gen_xchg "${xchg}" "${order}" "" + gen_xchg "${xchg}" "${order}" printf "\n" done done for xchg in "cmpxchg_local" "cmpxchg64_local" "cmpxchg128_local" "sync_cmpxchg" "try_cmpxchg_local" "try_cmpxchg64_local" "try_cmpxchg128_local"; do - gen_xchg "${xchg}" "" "" + gen_xchg "${xchg}" "" printf "\n" done -gen_xchg "cmpxchg_double" "" "2 * " - -printf "\n\n" - -gen_xchg "cmpxchg_double_local" "" "2 * " - cat <<EOF #endif /* _LINUX_ATOMIC_INSTRUMENTED_H */
Peter Zijlstra
maintainerPATCH v3 11/11 s390/cpum_sf: Convert to cmpxchg128()
In reply to Peter ZijlstraNow that there is a cross arch u128 and cmpxchg128(), use those instead of the custom CDSG helper.
--- arch/s390/include/asm/cpu_mf.h | 2 +- arch/s390/kernel/perf_cpum_sf.c | 16 +++------------- 2 files changed, 4 insertions(+), 14 deletions(-)
arch/s390/include/asm/cpu_mf.h +1 -1
@@ -140,7 +140,7 @@ union hws_trailer_header { unsigned int dsdes:16; /* 48-63: size of diagnostic SDE */unsigned long long overflow;/* 64 - Overflow Count */ }; -__uint128_t val; +u128 val; };struct hws_trailer_entry {
arch/s390/kernel/perf_cpum_sf.c +3 -13
@@ -1275,16 +1275,6 @@ static void hw_collect_samples(struct pe } } -static inline __uint128_t __cdsg (__uint128_t *ptr,__uint128_t old,__uint128_t new) -{ - asmvolatile ( -" cdsg %[old],%[new],%[ptr]\n" - : [old]"+d" (old), [ptr]"+QS" (*ptr) - : [new]"d" (new) - :"memory" ,"cc" ); -return old; -} -/* hw_perf_event_update() - Process sampling buffer * @event: The perf event * @flush_all: Flag to also flush partially filled sample-data-blocks
@@ -1362,7 +1352,7 @@ static void hw_perf_event_update(struct new.f =0 ; new.a =1 ; new.overflow =0 ; - prev.val =__cdsg (&te->header.val, old.val, new.val); + prev.val =cmpxchg128 (&te->header.val, old.val, new.val); }while (prev.val != old.val);/* Advance to next sample-data-block */
@@ -1572,7 +1562,7 @@ static bool aux_set_alert(struct aux_buf } new.a =1 ; new.overflow =0 ; - prev.val =__cdsg (&te->header.val, old.val, new.val); + prev.val =cmpxchg128 (&te->header.val, old.val, new.val); }while (prev.val != old.val);return true; }
@@ -1646,7 +1636,7 @@ static bool aux_reset_buffer(struct aux_ new.a =1 ; else new.a = 0; - prev.val =__cdsg (&te->header.val, old.val, new.val); + prev.val =cmpxchg128 (&te->header.val, old.val, new.val); }while (prev.val != old.val); *overflow += orig_overflow; }
[tip: locking/core] s390/cpum_sf: Convert to cmpxchg128()
The following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 71af29d0671b5bd38846176fb48f31152a026925 Gitweb: https://git.kernel.org/tip/71af29d0671b5bd38846176fb48f31152a026925 Author: Peter Zijlstra <[email protected]> AuthorDate: Mon, 15 May 2023 09:57:10 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 19 May 2023 12:35:15 +02:00
s390/cpum_sf: Convert to cmpxchg128()
Now that there is a cross arch u128 and cmpxchg128(), use those instead of the custom CDSG helper.
--- arch/s390/include/asm/cpu_mf.h | 2 +- arch/s390/kernel/perf_cpum_sf.c | 16 +++------------- 2 files changed, 4 insertions(+), 14 deletions(-)
arch/s390/include/asm/cpu_mf.h +1 -1
@@ -140,7 +140,7 @@ union hws_trailer_header { unsigned int dsdes:16; /* 48-63: size of diagnostic SDE */unsigned long long overflow;/* 64 - Overflow Count */ }; -__uint128_t val; +u128 val; };struct hws_trailer_entry {
arch/s390/kernel/perf_cpum_sf.c +3 -13
@@ -1271,16 +1271,6 @@ static void hw_collect_samples(struct perf_event *event, unsigned long *sdbt, } } -static inline __uint128_t __cdsg (__uint128_t *ptr,__uint128_t old,__uint128_t new) -{ - asmvolatile ( -" cdsg %[old],%[new],%[ptr]\n" - : [old]"+d" (old), [ptr]"+QS" (*ptr) - : [new]"d" (new) - :"memory" ,"cc" ); -return old; -} -/* hw_perf_event_update() - Process sampling buffer * @event: The perf event * @flush_all: Flag to also flush partially filled sample-data-blocks
@@ -1352,7 +1342,7 @@ static void hw_perf_event_update(struct perf_event *event, int flush_all) new.f =0 ; new.a =1 ; new.overflow =0 ; - prev.val =__cdsg (&te->header.val, old.val, new.val); + prev.val =cmpxchg128 (&te->header.val, old.val, new.val); }while (prev.val != old.val);/* Advance to next sample-data-block */
@@ -1562,7 +1552,7 @@ static bool aux_set_alert(struct aux_buffer *aux, unsigned long alert_index, } new.a =1 ; new.overflow =0 ; - prev.val =__cdsg (&te->header.val, old.val, new.val); + prev.val =cmpxchg128 (&te->header.val, old.val, new.val); }while (prev.val != old.val);return true; }
@@ -1636,7 +1626,7 @@ static bool aux_reset_buffer(struct aux_buffer *aux, unsigned long range, new.a =1 ; else new.a = 0; - prev.val =__cdsg (&te->header.val, old.val, new.val); + prev.val =cmpxchg128 (&te->header.val, old.val, new.val); }while (prev.val != old.val); *overflow += orig_overflow; }
[tip: locking/core] s390/cpum_sf: Convert to cmpxchg128()
In reply to Peter ZijlstraThe following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 3cf363a4daf359e8392b5048c619b7e9e429f122 Gitweb: https://git.kernel.org/tip/3cf363a4daf359e8392b5048c619b7e9e429f122 Author: Peter Zijlstra <[email protected]> AuthorDate: Mon, 15 May 2023 09:57:10 +02:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Mon, 22 May 2023 10:49:51 +02:00
s390/cpum_sf: Convert to cmpxchg128()
Now that there is a cross arch u128 and cmpxchg128(), use those instead of the custom CDSG helper.
--- arch/s390/include/asm/cpu_mf.h | 2 +- arch/s390/kernel/perf_cpum_sf.c | 16 +++------------- 2 files changed, 4 insertions(+), 14 deletions(-)
arch/s390/include/asm/cpu_mf.h +1 -1
@@ -140,7 +140,7 @@ union hws_trailer_header { unsigned int dsdes:16; /* 48-63: size of diagnostic SDE */unsigned long long overflow;/* 64 - Overflow Count */ }; -__uint128_t val; +u128 val; };struct hws_trailer_entry {
arch/s390/kernel/perf_cpum_sf.c +3 -13
@@ -1271,16 +1271,6 @@ static void hw_collect_samples(struct perf_event *event, unsigned long *sdbt, } } -static inline __uint128_t __cdsg (__uint128_t *ptr,__uint128_t old,__uint128_t new) -{ - asmvolatile ( -" cdsg %[old],%[new],%[ptr]\n" - : [old]"+d" (old), [ptr]"+QS" (*ptr) - : [new]"d" (new) - :"memory" ,"cc" ); -return old; -} -/* hw_perf_event_update() - Process sampling buffer * @event: The perf event * @flush_all: Flag to also flush partially filled sample-data-blocks
@@ -1352,7 +1342,7 @@ static void hw_perf_event_update(struct perf_event *event, int flush_all) new.f =0 ; new.a =1 ; new.overflow =0 ; - prev.val =__cdsg (&te->header.val, old.val, new.val); + prev.val =cmpxchg128 (&te->header.val, old.val, new.val); }while (prev.val != old.val);/* Advance to next sample-data-block */
@@ -1562,7 +1552,7 @@ static bool aux_set_alert(struct aux_buffer *aux, unsigned long alert_index, } new.a =1 ; new.overflow =0 ; - prev.val =__cdsg (&te->header.val, old.val, new.val); + prev.val =cmpxchg128 (&te->header.val, old.val, new.val); }while (prev.val != old.val);return true; }
@@ -1636,7 +1626,7 @@ static bool aux_reset_buffer(struct aux_buffer *aux, unsigned long range, new.a =1 ; else new.a = 0; - prev.val =__cdsg (&te->header.val, old.val, new.val); + prev.val =cmpxchg128 (&te->header.val, old.val, new.val); }while (prev.val != old.val); *overflow += orig_overflow; }
Quoted 10 lines · Peter Zijlstra
Since v2:
- reworked
this_cpu_cmpxchg()to not implicity do u128 but provide explicitthis_cpu_cmpxchg128()(arnd)
- addedtry_cmpxchg12_local()(per the addition of the try_cmpxchg*_local() family of functions)
- slight cleanup of the SLUB conversion (due to rebase and having to touch it)
- added a 'cleanup' patch for SLUB, since I was staring at that anyway
This is clearly an improvement over the previous state, so I'm happy with that, and the explicit this_cpu_cmpxchg128() interface addresses most of my previous concerns.
The need for runtime feature checking in the callers on x86-64 is still a bit awkward, but this is no worse than before. I understand that turning this into a compile-time choice would require first settling a larger debate about raising the default target for distros beyond the current CONFIG_GENERIC_CPU.
Arnd
Peter Zijlstra
maintainerQuoted 5 lines · Arnd Bergmann
The need for runtime feature checking in the callers on x86-64 is still a bit awkward, but this is no worse than before. I understand that turning this into a compile-time choice would require first settling a larger debate about raising the default target for distros beyond the current
CONFIG_GENERIC_CPU.
Looks like Power is going to be in the same boat, they can do cmpxchg128, but only for Power8+.