OpenCloudOS-Kernel/scripts/atomic/fallbacks
Mark Rutland 1d78814d41 locking/atomic: scripts: simplify raw_atomic*() definitions
Currently each ordering variant has several potential definitions,
with a mixture of preprocessor and C definitions, including several
copies of its C prototype, e.g.

| #if defined(arch_atomic_fetch_andnot_acquire)
| #define raw_atomic_fetch_andnot_acquire arch_atomic_fetch_andnot_acquire
| #elif defined(arch_atomic_fetch_andnot_relaxed)
| static __always_inline int
| raw_atomic_fetch_andnot_acquire(int i, atomic_t *v)
| {
|       int ret = arch_atomic_fetch_andnot_relaxed(i, v);
|       __atomic_acquire_fence();
|       return ret;
| }
| #elif defined(arch_atomic_fetch_andnot)
| #define raw_atomic_fetch_andnot_acquire arch_atomic_fetch_andnot
| #else
| static __always_inline int
| raw_atomic_fetch_andnot_acquire(int i, atomic_t *v)
| {
|       return raw_atomic_fetch_and_acquire(~i, v);
| }
| #endif

Make this a bit simpler by defining the C prototype once, and writing
the various potential definitions as plain C code guarded by ifdeffery.
For example, the above becomes:

| static __always_inline int
| raw_atomic_fetch_andnot_acquire(int i, atomic_t *v)
| {
| #if defined(arch_atomic_fetch_andnot_acquire)
|         return arch_atomic_fetch_andnot_acquire(i, v);
| #elif defined(arch_atomic_fetch_andnot_relaxed)
|         int ret = arch_atomic_fetch_andnot_relaxed(i, v);
|         __atomic_acquire_fence();
|         return ret;
| #elif defined(arch_atomic_fetch_andnot)
|         return arch_atomic_fetch_andnot(i, v);
| #else
|         return raw_atomic_fetch_and_acquire(~i, v);
| #endif
| }

Which is far easier to read. As we now always have a single copy of the
C prototype wrapping all the potential definitions, we now have an
obvious single location for kerneldoc comments.

At the same time, the fallbacks for raw_atomic*_xhcg() are made to use
'new' rather than 'i' as the name of the new value. This is what the
existing fallback template used, and is more consistent with the
raw_atomic{_try,}cmpxchg() fallbacks.

There should be no functional change as a result of this patch.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20230605070124.3741859-24-mark.rutland@arm.com
2023-06-05 09:57:22 +02:00
..
acquire locking/atomic: scripts: simplify raw_atomic*() definitions 2023-06-05 09:57:22 +02:00
add_negative locking/atomic: scripts: simplify raw_atomic*() definitions 2023-06-05 09:57:22 +02:00
add_unless locking/atomic: scripts: simplify raw_atomic*() definitions 2023-06-05 09:57:22 +02:00
andnot locking/atomic: scripts: simplify raw_atomic*() definitions 2023-06-05 09:57:22 +02:00
cmpxchg locking/atomic: scripts: simplify raw_atomic*() definitions 2023-06-05 09:57:22 +02:00
dec locking/atomic: scripts: simplify raw_atomic*() definitions 2023-06-05 09:57:22 +02:00
dec_and_test locking/atomic: scripts: simplify raw_atomic*() definitions 2023-06-05 09:57:22 +02:00
dec_if_positive locking/atomic: scripts: simplify raw_atomic*() definitions 2023-06-05 09:57:22 +02:00
dec_unless_positive locking/atomic: scripts: simplify raw_atomic*() definitions 2023-06-05 09:57:22 +02:00
fence locking/atomic: scripts: simplify raw_atomic*() definitions 2023-06-05 09:57:22 +02:00
fetch_add_unless locking/atomic: scripts: simplify raw_atomic*() definitions 2023-06-05 09:57:22 +02:00
inc locking/atomic: scripts: simplify raw_atomic*() definitions 2023-06-05 09:57:22 +02:00
inc_and_test locking/atomic: scripts: simplify raw_atomic*() definitions 2023-06-05 09:57:22 +02:00
inc_not_zero locking/atomic: scripts: simplify raw_atomic*() definitions 2023-06-05 09:57:22 +02:00
inc_unless_negative locking/atomic: scripts: simplify raw_atomic*() definitions 2023-06-05 09:57:22 +02:00
read_acquire locking/atomic: scripts: simplify raw_atomic*() definitions 2023-06-05 09:57:22 +02:00
release locking/atomic: scripts: simplify raw_atomic*() definitions 2023-06-05 09:57:22 +02:00
set_release locking/atomic: scripts: simplify raw_atomic*() definitions 2023-06-05 09:57:22 +02:00
sub_and_test locking/atomic: scripts: simplify raw_atomic*() definitions 2023-06-05 09:57:22 +02:00
try_cmpxchg locking/atomic: scripts: simplify raw_atomic*() definitions 2023-06-05 09:57:22 +02:00
xchg locking/atomic: scripts: simplify raw_atomic*() definitions 2023-06-05 09:57:22 +02:00