atomics: generate atomic headers
Subsystems (6)
Mark Rutland
reviewercover atomics: generate atomic headers
This series scripts the generation of the various atomic headers, to ensure that the various atomic APIs remain consistent, reducing the risk of human error, and simplifying future rework.
The series is based on my atomic API cleanup patches [1,2], and can be found on my atomics/generated branch [3] on kernel.org.
The first three patches are preparatory rework, with patch four introducing the infrastructure. The final three patches migrate to generated headers. The scripts themselves are mostly POSIX sh (modulo local), without bashisms, and work in dash and bash.
Per Linus request that it is possible to use git grep to inspect the atomic headers [3], the headers are committed (and not generated by kbuild). Since we now expand the fallback definitions inline, each *should* be easier to find with grep. Each header also has a comment at the top with a path to the script used to generate it.
While the diff stat looks like a huge addition, the scripting comes in at ~800 lines in total, including the fallback definitions, so we're removing ~1000 lines of hand-written code. At the same time, we fill in gaps in the atomic_long API, and the instrumented atomic wrappers.
Longer-term, I think things could be simplified if we were to rework the headers such that we have:
* arch/*/include/asm/atomic.h providing arch_atomic_*().
* include/linux/atomic-raw.h building raw_atomic_*() atop of the arch_atomic_*() definitions, filling in gaps in the API. Having separate arch_ and raw_ namespaces would simplify the ifdeffery.
* include/linux/atomic.h building atomic_*() atop of the raw_atomic_*() definitions, complete with any instrumentation. Instrumenting at this level would lower the instrumentation overhead, and would not require any ifdeffery as the whole raw_atomic_*() API would be available.
... I've avoided this for the time being due to the necessary churn in arch code.
Thanks,
Mark.
[1] https://lkml.kernel.org/r/[email protected]
[2] git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git atomics/api-cleanup
[3] git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git atomics/generated
[4] https://lkml.kernel.org/r/CA+55aFxjU0op8QLLu0n-RjHBs7gQsLvD8jcyedgw6jeZFN7B+Q@mail.gmail.com
Mark Rutland (7):
atomics/tty: add missing atomic_long_t * cast
atomics/treewide: rework ordering barriers
atomics: separate basic {cmp,}xchg()
atomics: add common header generation files
atomics: switch to generated fallbacks
atomics: switch to generated atomic-long
atomics: switch to generated instrumentation
MAINTAINERS | 1 + arch/alpha/include/asm/atomic.h | 8 +- arch/powerpc/include/asm/atomic.h | 17 +- arch/riscv/include/asm/atomic.h | 17 +- drivers/tty/tty_ldsem.c | 2 +- include/asm-generic/atomic-instrumented-atomic.h | 1629 ++++++++++++++++ include/asm-generic/atomic-instrumented.h | 394 +--- include/asm-generic/atomic-long.h | 1150 +++++++++-- include/linux/atomic-fallback.h | 2223 ++++++++++++++++++++++ include/linux/atomic.h | 1244 +----------- scripts/atomic/atomic-tbl.sh | 186 ++ scripts/atomic/atomics.tbl | 41 + scripts/atomic/fallbacks/acquire | 9 + scripts/atomic/fallbacks/add_negative | 16 + scripts/atomic/fallbacks/add_unless | 16 + scripts/atomic/fallbacks/andnot | 7 + scripts/atomic/fallbacks/dec | 7 + scripts/atomic/fallbacks/dec_and_test | 15 + scripts/atomic/fallbacks/dec_if_positive | 15 + scripts/atomic/fallbacks/dec_unless_positive | 14 + scripts/atomic/fallbacks/fence | 11 + scripts/atomic/fallbacks/fetch_add_unless | 23 + scripts/atomic/fallbacks/inc | 7 + scripts/atomic/fallbacks/inc_and_test | 15 + scripts/atomic/fallbacks/inc_not_zero | 14 + scripts/atomic/fallbacks/inc_unless_negative | 14 + scripts/atomic/fallbacks/read_acquire | 7 + scripts/atomic/fallbacks/release | 8 + scripts/atomic/fallbacks/set_release | 7 + scripts/atomic/fallbacks/sub_and_test | 16 + scripts/atomic/fallbacks/try_cmpxchg | 11 + scripts/atomic/gen-atomic-fallback.sh | 144 ++ scripts/atomic/gen-atomic-instrumented.sh | 122 ++ scripts/atomic/gen-atomic-long.sh | 98 + 34 files changed, 5671 insertions(+), 1837 deletions(-) create mode 100644 include/asm-generic/atomic-instrumented-atomic.h create mode 100644 include/linux/atomic-fallback.h create mode 100755 scripts/atomic/atomic-tbl.sh create mode 100644 scripts/atomic/atomics.tbl create mode 100644 scripts/atomic/fallbacks/acquire create mode 100644 scripts/atomic/fallbacks/add_negative create mode 100644 scripts/atomic/fallbacks/add_unless create mode 100644 scripts/atomic/fallbacks/andnot create mode 100644 scripts/atomic/fallbacks/dec create mode 100644 scripts/atomic/fallbacks/dec_and_test create mode 100644 scripts/atomic/fallbacks/dec_if_positive create mode 100644 scripts/atomic/fallbacks/dec_unless_positive create mode 100644 scripts/atomic/fallbacks/fence create mode 100644 scripts/atomic/fallbacks/fetch_add_unless create mode 100644 scripts/atomic/fallbacks/inc create mode 100644 scripts/atomic/fallbacks/inc_and_test create mode 100644 scripts/atomic/fallbacks/inc_not_zero create mode 100644 scripts/atomic/fallbacks/inc_unless_negative create mode 100644 scripts/atomic/fallbacks/read_acquire create mode 100644 scripts/atomic/fallbacks/release create mode 100644 scripts/atomic/fallbacks/set_release create mode 100644 scripts/atomic/fallbacks/sub_and_test create mode 100644 scripts/atomic/fallbacks/try_cmpxchg create mode 100755 scripts/atomic/gen-atomic-fallback.sh create mode 100755 scripts/atomic/gen-atomic-instrumented.sh create mode 100755 scripts/atomic/gen-atomic-long.sh
Signature · 1 line
2.11.0
Mark Rutland
reviewerPATCH 1/7 atomics/tty: add missing atomic_long_t * cast
In ldsem_cmpxchg a pointer to unsigned long is passed to atomic_long_cmpxchg(), which expects a pointer to atomic_long_t.
In preparation for making the atomic_long_* APIs type safe, add a cast before passing the value to atomic_long_cmpxchg(). Similar is already done in ldsem_atomic_update() when it calls atomic_long_add_return().
--- drivers/tty/tty_ldsem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/tty_ldsem.c +1 -1
@@ -86,7 +86,7 @@ static inline long ldsem_atomic_update(long delta, struct ld_semaphore *sem)*/ static inline int ldsem_cmpxchg (long *old,long new,struct ld_semaphore *sem) { -long tmp =atomic_long_cmpxchg (&sem->count, *old, new); +long tmp =atomic_long_cmpxchg ((atomic_long_t *)&sem->count, *old, new);if (tmp == *old) { *old = new;return 1 ;
Signature · 1 line
2.11.0
Re: [PATCH 1/7] atomics/tty: add missing atomic_long_t * cast
Quoted 32 lines · Mark Rutland
In
ldsem_cmpxchga pointer to unsigned long is passed toatomic_long_cmpxchg(), which expects a pointer toatomic_long_t.In preparation for making the atomic_long_* APIs type safe, add a cast before passing the value to
atomic_long_cmpxchg(). Similar is already done inldsem_atomic_update()when it callsatomic_long_add_return().Signed-off-by Mark Rutland <[email protected]>Cc Boqun Feng <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Will Deacon <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Jiri Slaby <[email protected]>--- drivers/tty/tty_ldsem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/tty/tty_ldsem.c +1
-1@@ -86,7 +86,7 @@ static inline long ldsem_atomic_update(long delta, struct ld_semaphore *sem)*/ static inline int ldsem_cmpxchg (long *old,long new,struct ld_semaphore *sem) { -long tmp =atomic_long_cmpxchg (&sem->count, *old, new); +long tmp =atomic_long_cmpxchg ((atomic_long_t *)&sem->count, *old, new);if (tmp == *old) { *old = new;return 1 ;Signature · 1 line
2.11.0
Peter Zijlstra
maintainerRe: [PATCH 1/7] atomics/tty: add missing atomic_long_t * cast
In reply to Mark RutlandReview
Quoted 5 lines · Mark Rutland
In
ldsem_cmpxchga pointer to unsigned long is passed toatomic_long_cmpxchg(), which expects a pointer toatomic_long_t.(quoted diff) +1
-1- long tmp = atomic_long_cmpxchg(&sem->count, *old, new); + long tmp = atomic_long_cmpxchg((atomic_long_t *)&sem->count, *old, new);
Needing to cast anything to atomic types is dodgy at best, so I had me a look at this code.
Would not the following patch be much better?
--- drivers/tty/tty_ldsem.c | 82 ++++++++++++++++++++--------------------------- include/linux/tty_ldisc.h | 4 +-- 2 files changed, 37 insertions(+), 49 deletions(-)
drivers/tty/tty_ldsem.c +35 -47
@@ -74,28 +74,6 @@ struct ldsem_waiter {struct task_struct *task; }; -static inline long ldsem_atomic_update (long delta,struct ld_semaphore *sem) -{ -return atomic_long_add_return (delta, (atomic_long_t *)&sem->count); -} - -/* -* ldsem_cmpxchg() updates @*old with the last-known sem->count value. -* Returns 1 if count was successfully changed; @*old will have @new value. -* Returns 0 if count was not changed; @*old will have most recent sem->count -*/ -static inline int ldsem_cmpxchg (long *old,long new,struct ld_semaphore *sem) -{ -long tmp =atomic_long_cmpxchg (&sem->count, *old, new); -if (tmp == *old) { - *old = new; -return 1 ; - }else { - *old = tmp; -return 0 ; - } -} -/* * Initialize an ldsem: */
@@ -109,7 +87,7 @@ void __init_ldsem(struct ld_semaphore *sem, const char *name,debug_check_no_locks_freed ((void *)sem,sizeof (*sem));lockdep_init_map (&sem->dep_map, name, key,0 );#endif - sem->count =LDSEM_UNLOCKED ; +atomic_long_set (&sem->count,LDSEM_UNLOCKED ); sem->wait_readers =0 ;raw_spin_lock_init (&sem->wait_lock);INIT_LIST_HEAD (&sem->read_wait);
@@ -122,16 +100,17 @@ static void __ldsem_wake_readers(struct ld_semaphore *sem)struct task_struct *tsk;long adjust, count; -/* Try to grant read locks to all readers on the read wait list. +/* +* Try to grant read locks to all readers on the read wait list. * Note the 'active part' of the count is incremented by * the number of readers before waking any processes up. */ adjust = sem->wait_readers * (LDSEM_ACTIVE_BIAS -LDSEM_WAIT_BIAS ); - count =ldsem_atomic_update (adjust, sem); + count =atomic_long_add_return (adjust, &sem->count);do {if (count >0 )break ; -if (ldsem_cmpxchg (&count, count - adjust, sem)) +if (atomic_long_try_cmpxchg (&sem->count, &count, count - adjust))return ; }while (1 );
@@ -148,14 +127,15 @@ static void __ldsem_wake_readers(struct ld_semaphore *sem)static inline int writer_trylock (struct ld_semaphore *sem) { -/* only wake this writer if the active part of the count can be +/* +* Only wake this writer if the active part of the count can be * transitioned from 0 -> 1 */ -long count =ldsem_atomic_update (LDSEM_ACTIVE_BIAS , sem); +long count =atomic_long_add_return (LDSEM_ACTIVE_BIAS , &sem->count);do {if ((count &LDSEM_ACTIVE_MASK ) ==LDSEM_ACTIVE_BIAS )return 1 ; -if (ldsem_cmpxchg (&count, count -LDSEM_ACTIVE_BIAS , sem)) +if (atomic_long_try_cmpxchg (&sem->count, &count, count -LDSEM_ACTIVE_BIAS ))return 0 ; }while (1 ); }
@@ -205,12 +185,16 @@ down_read_failed(struct ld_semaphore *sem, long count, long timeout)/* set up my own style of waitqueue */ raw_spin_lock_irq (&sem->wait_lock); -/* Try to reverse the lock attempt but if the count has changed +/* +* Try to reverse the lock attempt but if the count has changed * so that reversing fails, check if there are are no waiters, -* and early-out if not */ +* and early-out if not +*/ do { - if (ldsem_cmpxchg(&count, count + adjust, sem)) + if (atomic_long_try_cmpxchg(&sem->count, &count, count + adjust)) { + count += adjust; break; + } if (count > 0) { raw_spin_unlock_irq(&sem->wait_lock); return sem;
@@ -243,12 +227,14 @@ down_read_failed(struct ld_semaphore *sem, long count, long timeout)__set_current_state (TASK_RUNNING );if (!timeout) { -/* lock timed out but check if this task was just +/* +* Lock timed out but check if this task was just * granted lock ownership - if so, pretend there -* was no timeout; otherwise, cleanup lock wait */ +* was no timeout; otherwise, cleanup lock wait. +*/ raw_spin_lock_irq (&sem->wait_lock);if (waiter.task) { -ldsem_atomic_update (-LDSEM_WAIT_BIAS , sem); +atomic_long_add_return (-LDSEM_WAIT_BIAS , &sem->count);list_del (&waiter.list);raw_spin_unlock_irq (&sem->wait_lock);put_task_struct (waiter.task);
@@ -273,11 +259,13 @@ down_write_failed(struct ld_semaphore *sem, long count, long timeout)/* set up my own style of waitqueue */ raw_spin_lock_irq (&sem->wait_lock); -/* Try to reverse the lock attempt but if the count has changed +/* +* Try to reverse the lock attempt but if the count has changed * so that reversing fails, check if the lock is now owned, -* and early-out if so */ +* and early-out if so. +*/ do { - if (ldsem_cmpxchg(&count, count + adjust, sem)) + if (atomic_long_try_cmpxchg(&sem->count, &count, count + adjust)) break; if ((count & LDSEM_ACTIVE_MASK) == LDSEM_ACTIVE_BIAS) { raw_spin_unlock_irq(&sem->wait_lock);
@@ -303,7 +291,7 @@ down_write_failed(struct ld_semaphore *sem, long count, long timeout) }if (!locked) -ldsem_atomic_update (-LDSEM_WAIT_BIAS , sem); +atomic_long_add_return (-LDSEM_WAIT_BIAS , &sem->count);list_del (&waiter.list);raw_spin_unlock_irq (&sem->wait_lock);
@@ -324,7 +312,7 @@ static int __ldsem_down_read_nested(struct ld_semaphore *sem,lockdep_acquire_read (sem, subclass,0 , _RET_IP_); - count =ldsem_atomic_update (LDSEM_READ_BIAS , sem); + count =atomic_long_add_return (LDSEM_READ_BIAS , &sem->count);if (count <=0 ) {lock_stat (sem, contended);if (!down_read_failed (sem, count, timeout)) {
@@ -343,7 +331,7 @@ static int __ldsem_down_write_nested(struct ld_semaphore *sem,lockdep_acquire (sem, subclass,0 , _RET_IP_); - count =ldsem_atomic_update (LDSEM_WRITE_BIAS , sem); + count =atomic_long_add_return (LDSEM_WRITE_BIAS , &sem->count);if ((count &LDSEM_ACTIVE_MASK ) !=LDSEM_ACTIVE_BIAS ) {lock_stat (sem, contended);if (!down_write_failed (sem, count, timeout)) {
@@ -370,10 +358,10 @@ int __sched ldsem_down_read(struct ld_semaphore *sem, long timeout)*/ int ldsem_down_read_trylock (struct ld_semaphore *sem) { -long count = sem->count; +long count =atomic_long_read (&sem->count);while (count >=0 ) { -if (ldsem_cmpxchg (&count, count +LDSEM_READ_BIAS , sem)) { +if (atomic_long_try_cmpxchg (&sem->count, &count, count +LDSEM_READ_BIAS )) {lockdep_acquire_read (sem,0 ,1 , _RET_IP_);lock_stat (sem, acquired);return 1 ;
@@ -396,10 +384,10 @@ int __sched ldsem_down_write(struct ld_semaphore *sem, long timeout)*/ int ldsem_down_write_trylock (struct ld_semaphore *sem) { -long count = sem->count; +long count =atomic_long_read (&sem->count);while ((count &LDSEM_ACTIVE_MASK ) ==0 ) { -if (ldsem_cmpxchg (&count, count +LDSEM_WRITE_BIAS , sem)) { +if (atomic_long_try_cmpxchg (&sem->count, &count, count +LDSEM_WRITE_BIAS )) {lockdep_acquire (sem,0 ,1 , _RET_IP_);lock_stat (sem, acquired);return 1 ;
@@ -417,7 +405,7 @@ void ldsem_up_read(struct ld_semaphore *sem)lockdep_release (sem,1 , _RET_IP_); - count =ldsem_atomic_update (-LDSEM_READ_BIAS , sem); + count =atomic_long_add_return (-LDSEM_READ_BIAS , &sem->count);if (count <0 && (count &LDSEM_ACTIVE_MASK ) ==0 )ldsem_wake (sem); }
@@ -431,7 +419,7 @@ void ldsem_up_write(struct ld_semaphore *sem)lockdep_release (sem,1 , _RET_IP_); - count =ldsem_atomic_update (-LDSEM_WRITE_BIAS , sem); + count =atomic_long_add_return (-LDSEM_WRITE_BIAS , &sem->count);if (count <0 )ldsem_wake (sem); }
include/linux/tty_ldisc.h +2 -2
@@ -119,13 +119,13 @@#include <linux/fs.h> #include <linux/wait.h> - +#include <linux/atomic.h> /* * the semaphore definition */ struct ld_semaphore { -long count; +atomic_long_t count;raw_spinlock_t wait_lock;unsigned int wait_readers;struct list_head read_wait;
Greg Kroah-Hartman
maintainerRe: [PATCH 1/7] atomics/tty: add missing atomic_long_t * cast
Quoted 10 lines · Peter Zijlstra
Review
Quoted 5 lines · Mark Rutland
In
ldsem_cmpxchga pointer to unsigned long is passed toatomic_long_cmpxchg(), which expects a pointer toatomic_long_t.(quoted diff) +1
-1- long tmp = atomic_long_cmpxchg(&sem->count, *old, new); + long tmp = atomic_long_cmpxchg((atomic_long_t *)&sem->count, *old, new);Needing to cast anything to atomic types is dodgy at best, so I had me a look at this code.
Quoted 6 lines
Would not the following patch be much better?
--- drivers/tty/tty_ldsem.c | 82 ++++++++++++++++++++--------------------------- include/linux/tty_ldisc.h | 4 +-- 2 files changed, 37 insertions(+), 49 deletions(-)
At first glance, yes, this does look a lot better, it's less lines at the least :)
I think Peter Hurley was just trying to hid the atomic mess behind function calls, which is why he didn't open-code it like you did here. But this makes it a bit more obvious as to what "magic" is happening, so I like it.
Care to turn it into a real patch so I can queue it up after 4.18-rc1 is out? Or do you want me to do that?
thanks,
greg k-h
Peter Zijlstra
maintainerRe: [PATCH 1/7] atomics/tty: add missing atomic_long_t * cast
Quoted 2 lines · Greg Kroah-Hartman
I think Peter Hurley was just trying to hid the atomic mess behind function calls, which is why he didn't open-code it like you did here.
No reason to then not use the right types though. I mean, you can still use the helper functions, but I figured they weren't worth the bother. Esp. then using try_cmpxchg (which is relatively new) the helpers became very thin.
Quoted 2 lines
But this makes it a bit more obvious as to what "magic" is happening, so I like it.
Well, it also fixes one additional bug in that the old code used a regular unsigned long load of the value:
- long count = sem->count;
+ long count = atomic_long_read(&sem->count);
which doesn't guarantee enough. The atomic_long_read() thing implies READ_ONCE() which ensures the load is single copy atomic (GCC used to guarantee that for regular loads/stores to naturally aligned native words, but no longer).
Quoted 2 lines
Care to turn it into a real patch so I can queue it up after 4.18-rc1 is out? Or do you want me to do that?
I can make a proper patch, hold on.
Peter Zijlstra
maintainerRe: [PATCH 1/7] atomics/tty: add missing atomic_long_t * cast
Quoted 1 line · Peter Zijlstra
I can make a proper patch, hold on.
---
Subject: atomic/tty: Fix up atomic abuse in ldsem
Mark found ldsem_cmpxchg() needed an (atomic_long_t *) cast to keep working after making the atomic_long interface type safe.
Needing casts is bad form, which made me look at the code. There are no ld_semaphore::count users outside of these functions so there is no reason why it can not be an atomic_long_t in the first place, obviating the need for this cast.
That also ensures the loads use atomic_long_read(), which implies (at least) READ_ONCE() in order to guarantee single-copy-atomic loads.
When using atomic_long_try_cmpxchg() the ldsem_cmpxchg() wrapper gets very thin (the only difference is not changing *old on success, which most callers don't seem to care about).
So rework the whole thing to use atomic_long_t and its accessors directly.
While there, fixup all the horrible comment styles.
--- drivers/tty/tty_ldsem.c | 82 ++++++++++++++++++++--------------------------- include/linux/tty_ldisc.h | 4 +-- 2 files changed, 37 insertions(+), 49 deletions(-)
drivers/tty/tty_ldsem.c +35 -47
@@ -74,28 +74,6 @@ struct ldsem_waiter {struct task_struct *task; }; -static inline long ldsem_atomic_update (long delta,struct ld_semaphore *sem) -{ -return atomic_long_add_return (delta, (atomic_long_t *)&sem->count); -} - -/* -* ldsem_cmpxchg() updates @*old with the last-known sem->count value. -* Returns 1 if count was successfully changed; @*old will have @new value. -* Returns 0 if count was not changed; @*old will have most recent sem->count -*/ -static inline int ldsem_cmpxchg (long *old,long new,struct ld_semaphore *sem) -{ -long tmp =atomic_long_cmpxchg (&sem->count, *old, new); -if (tmp == *old) { - *old = new; -return 1 ; - }else { - *old = tmp; -return 0 ; - } -} -/* * Initialize an ldsem: */
@@ -109,7 +87,7 @@ void __init_ldsem(struct ld_semaphore *sem, const char *name,debug_check_no_locks_freed ((void *)sem,sizeof (*sem));lockdep_init_map (&sem->dep_map, name, key,0 );#endif - sem->count =LDSEM_UNLOCKED ; +atomic_long_set (&sem->count,LDSEM_UNLOCKED ); sem->wait_readers =0 ;raw_spin_lock_init (&sem->wait_lock);INIT_LIST_HEAD (&sem->read_wait);
@@ -122,16 +100,17 @@ static void __ldsem_wake_readers(struct ld_semaphore *sem)struct task_struct *tsk;long adjust, count; -/* Try to grant read locks to all readers on the read wait list. +/* +* Try to grant read locks to all readers on the read wait list. * Note the 'active part' of the count is incremented by * the number of readers before waking any processes up. */ adjust = sem->wait_readers * (LDSEM_ACTIVE_BIAS -LDSEM_WAIT_BIAS ); - count =ldsem_atomic_update (adjust, sem); + count =atomic_long_add_return (adjust, &sem->count);do {if (count >0 )break ; -if (ldsem_cmpxchg (&count, count - adjust, sem)) +if (atomic_long_try_cmpxchg (&sem->count, &count, count - adjust))return ; }while (1 );
@@ -148,14 +127,15 @@ static void __ldsem_wake_readers(struct ld_semaphore *sem)static inline int writer_trylock (struct ld_semaphore *sem) { -/* only wake this writer if the active part of the count can be +/* +* Only wake this writer if the active part of the count can be * transitioned from 0 -> 1 */ -long count =ldsem_atomic_update (LDSEM_ACTIVE_BIAS , sem); +long count =atomic_long_add_return (LDSEM_ACTIVE_BIAS , &sem->count);do {if ((count &LDSEM_ACTIVE_MASK ) ==LDSEM_ACTIVE_BIAS )return 1 ; -if (ldsem_cmpxchg (&count, count -LDSEM_ACTIVE_BIAS , sem)) +if (atomic_long_try_cmpxchg (&sem->count, &count, count -LDSEM_ACTIVE_BIAS ))return 0 ; }while (1 ); }
@@ -205,12 +185,16 @@ down_read_failed(struct ld_semaphore *sem, long count, long timeout)/* set up my own style of waitqueue */ raw_spin_lock_irq (&sem->wait_lock); -/* Try to reverse the lock attempt but if the count has changed +/* +* Try to reverse the lock attempt but if the count has changed * so that reversing fails, check if there are are no waiters, -* and early-out if not */ +* and early-out if not +*/ do { - if (ldsem_cmpxchg(&count, count + adjust, sem)) + if (atomic_long_try_cmpxchg(&sem->count, &count, count + adjust)) { + count += adjust; break; + } if (count > 0) { raw_spin_unlock_irq(&sem->wait_lock); return sem;
@@ -243,12 +227,14 @@ down_read_failed(struct ld_semaphore *sem, long count, long timeout)__set_current_state (TASK_RUNNING );if (!timeout) { -/* lock timed out but check if this task was just +/* +* Lock timed out but check if this task was just * granted lock ownership - if so, pretend there -* was no timeout; otherwise, cleanup lock wait */ +* was no timeout; otherwise, cleanup lock wait. +*/ raw_spin_lock_irq (&sem->wait_lock);if (waiter.task) { -ldsem_atomic_update (-LDSEM_WAIT_BIAS , sem); +atomic_long_add_return (-LDSEM_WAIT_BIAS , &sem->count);list_del (&waiter.list);raw_spin_unlock_irq (&sem->wait_lock);put_task_struct (waiter.task);
@@ -273,11 +259,13 @@ down_write_failed(struct ld_semaphore *sem, long count, long timeout)/* set up my own style of waitqueue */ raw_spin_lock_irq (&sem->wait_lock); -/* Try to reverse the lock attempt but if the count has changed +/* +* Try to reverse the lock attempt but if the count has changed * so that reversing fails, check if the lock is now owned, -* and early-out if so */ +* and early-out if so. +*/ do { - if (ldsem_cmpxchg(&count, count + adjust, sem)) + if (atomic_long_try_cmpxchg(&sem->count, &count, count + adjust)) break; if ((count & LDSEM_ACTIVE_MASK) == LDSEM_ACTIVE_BIAS) { raw_spin_unlock_irq(&sem->wait_lock);
@@ -303,7 +291,7 @@ down_write_failed(struct ld_semaphore *sem, long count, long timeout) }if (!locked) -ldsem_atomic_update (-LDSEM_WAIT_BIAS , sem); +atomic_long_add_return (-LDSEM_WAIT_BIAS , &sem->count);list_del (&waiter.list);raw_spin_unlock_irq (&sem->wait_lock);
@@ -324,7 +312,7 @@ static int __ldsem_down_read_nested(struct ld_semaphore *sem,lockdep_acquire_read (sem, subclass,0 , _RET_IP_); - count =ldsem_atomic_update (LDSEM_READ_BIAS , sem); + count =atomic_long_add_return (LDSEM_READ_BIAS , &sem->count);if (count <=0 ) {lock_stat (sem, contended);if (!down_read_failed (sem, count, timeout)) {
@@ -343,7 +331,7 @@ static int __ldsem_down_write_nested(struct ld_semaphore *sem,lockdep_acquire (sem, subclass,0 , _RET_IP_); - count =ldsem_atomic_update (LDSEM_WRITE_BIAS , sem); + count =atomic_long_add_return (LDSEM_WRITE_BIAS , &sem->count);if ((count &LDSEM_ACTIVE_MASK ) !=LDSEM_ACTIVE_BIAS ) {lock_stat (sem, contended);if (!down_write_failed (sem, count, timeout)) {
@@ -370,10 +358,10 @@ int __sched ldsem_down_read(struct ld_semaphore *sem, long timeout)*/ int ldsem_down_read_trylock (struct ld_semaphore *sem) { -long count = sem->count; +long count =atomic_long_read (&sem->count);while (count >=0 ) { -if (ldsem_cmpxchg (&count, count +LDSEM_READ_BIAS , sem)) { +if (atomic_long_try_cmpxchg (&sem->count, &count, count +LDSEM_READ_BIAS )) {lockdep_acquire_read (sem,0 ,1 , _RET_IP_);lock_stat (sem, acquired);return 1 ;
@@ -396,10 +384,10 @@ int __sched ldsem_down_write(struct ld_semaphore *sem, long timeout)*/ int ldsem_down_write_trylock (struct ld_semaphore *sem) { -long count = sem->count; +long count =atomic_long_read (&sem->count);while ((count &LDSEM_ACTIVE_MASK ) ==0 ) { -if (ldsem_cmpxchg (&count, count +LDSEM_WRITE_BIAS , sem)) { +if (atomic_long_try_cmpxchg (&sem->count, &count, count +LDSEM_WRITE_BIAS )) {lockdep_acquire (sem,0 ,1 , _RET_IP_);lock_stat (sem, acquired);return 1 ;
@@ -417,7 +405,7 @@ void ldsem_up_read(struct ld_semaphore *sem)lockdep_release (sem,1 , _RET_IP_); - count =ldsem_atomic_update (-LDSEM_READ_BIAS , sem); + count =atomic_long_add_return (-LDSEM_READ_BIAS , &sem->count);if (count <0 && (count &LDSEM_ACTIVE_MASK ) ==0 )ldsem_wake (sem); }
@@ -431,7 +419,7 @@ void ldsem_up_write(struct ld_semaphore *sem)lockdep_release (sem,1 , _RET_IP_); - count =ldsem_atomic_update (-LDSEM_WRITE_BIAS , sem); + count =atomic_long_add_return (-LDSEM_WRITE_BIAS , &sem->count);if (count <0 )ldsem_wake (sem); }
include/linux/tty_ldisc.h +2 -2
@@ -119,13 +119,13 @@#include <linux/fs.h> #include <linux/wait.h> - +#include <linux/atomic.h> /* * the semaphore definition */ struct ld_semaphore { -long count; +atomic_long_t count;raw_spinlock_t wait_lock;unsigned int wait_readers;struct list_head read_wait;
Re: [PATCH 1/7] atomics/tty: add missing atomic_long_t * cast
Quoted 22 lines · Peter Zijlstra
Quoted 1 line · Peter Zijlstra
I can make a proper patch, hold on.
---
Subject: atomic/tty: Fix up atomic abuse in ldsemMark found
ldsem_cmpxchg()needed an (atomic_long_t*) cast to keep working after making theatomic_longinterface type safe.Needing casts is bad form, which made me look at the code. There are no
ld_semaphore::countusers outside of these functions so there is no reason why it can not be anatomic_long_tin the first place, obviating the need for this cast.That also ensures the loads use
atomic_long_read(), which implies (at least)READ_ONCE()in order to guarantee single-copy-atomic loads.When using
atomic_long_try_cmpxchg()theldsem_cmpxchg()wrapper gets very thin (the only difference is not changing *old on success, which most callers don't seem to care about).
Quoted 8 lines
So rework the whole thing to use
atomic_long_tand its accessors directly.While there, fixup all the horrible comment styles.
Cc Peter Hurley <[email protected]>Reported-by Mark Rutland <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>
FWIW:
Greg, I assume you'll queue this at some point soon.
In the mean time, I've picked this up as part of this series, replacing my patch with the atomic_long_t cast.
Thanks,
Mark.
Quoted 234 lines
--- drivers/tty/tty_ldsem.c | 82 ++++++++++++++++++++--------------------------- include/linux/tty_ldisc.h | 4 +-- 2 files changed, 37 insertions(+), 49 deletions(-)drivers/tty/tty_ldsem.c +35
-47@@ -74,28 +74,6 @@ struct ldsem_waiter {struct task_struct *task; }; -static inline long ldsem_atomic_update (long delta,struct ld_semaphore *sem) -{ -return atomic_long_add_return (delta, (atomic_long_t *)&sem->count); -} - -/* -* ldsem_cmpxchg() updates @*old with the last-known sem->count value. -* Returns 1 if count was successfully changed; @*old will have @new value. -* Returns 0 if count was not changed; @*old will have most recent sem->count -*/ -static inline int ldsem_cmpxchg (long *old,long new,struct ld_semaphore *sem) -{ -long tmp =atomic_long_cmpxchg (&sem->count, *old, new); -if (tmp == *old) { - *old = new; -return 1 ; - }else { - *old = tmp; -return 0 ; - } -} -/* * Initialize an ldsem: */ @@ -109,7 +87,7 @@ void __init_ldsem(struct ld_semaphore *sem, const char *name,debug_check_no_locks_freed ((void *)sem,sizeof (*sem));lockdep_init_map (&sem->dep_map, name, key,0 );#endif - sem->count =LDSEM_UNLOCKED ; +atomic_long_set (&sem->count,LDSEM_UNLOCKED ); sem->wait_readers =0 ;raw_spin_lock_init (&sem->wait_lock);INIT_LIST_HEAD (&sem->read_wait);@@ -122,16 +100,17 @@ static void __ldsem_wake_readers(struct ld_semaphore *sem)struct task_struct *tsk;long adjust, count; -/* Try to grant read locks to all readers on the read wait list. +/* +* Try to grant read locks to all readers on the read wait list. * Note the 'active part' of the count is incremented by * the number of readers before waking any processes up. */ adjust = sem->wait_readers * (LDSEM_ACTIVE_BIAS -LDSEM_WAIT_BIAS ); - count =ldsem_atomic_update (adjust, sem); + count =atomic_long_add_return (adjust, &sem->count);do {if (count >0 )break ; -if (ldsem_cmpxchg (&count, count - adjust, sem)) +if (atomic_long_try_cmpxchg (&sem->count, &count, count - adjust))return ; }while (1 );@@ -148,14 +127,15 @@ static void __ldsem_wake_readers(struct ld_semaphore *sem)static inline int writer_trylock (struct ld_semaphore *sem) { -/* only wake this writer if the active part of the count can be +/* +* Only wake this writer if the active part of the count can be * transitioned from 0 -> 1 */ -long count =ldsem_atomic_update (LDSEM_ACTIVE_BIAS , sem); +long count =atomic_long_add_return (LDSEM_ACTIVE_BIAS , &sem->count);do {if ((count &LDSEM_ACTIVE_MASK ) ==LDSEM_ACTIVE_BIAS )return 1 ; -if (ldsem_cmpxchg (&count, count -LDSEM_ACTIVE_BIAS , sem)) +if (atomic_long_try_cmpxchg (&sem->count, &count, count -LDSEM_ACTIVE_BIAS ))return 0 ; }while (1 ); }@@ -205,12 +185,16 @@ down_read_failed(struct ld_semaphore *sem, long count, long timeout)/* set up my own style of waitqueue */ raw_spin_lock_irq (&sem->wait_lock); -/* Try to reverse the lock attempt but if the count has changed +/* +* Try to reverse the lock attempt but if the count has changed * so that reversing fails, check if there are are no waiters, -* and early-out if not */ +* and early-out if not +*/ do { - if (ldsem_cmpxchg(&count, count + adjust, sem)) + if (atomic_long_try_cmpxchg(&sem->count, &count, count + adjust)) { + count += adjust; break; + } if (count > 0) { raw_spin_unlock_irq(&sem->wait_lock); return sem;@@ -243,12 +227,14 @@ down_read_failed(struct ld_semaphore *sem, long count, long timeout)__set_current_state (TASK_RUNNING );if (!timeout) { -/* lock timed out but check if this task was just +/* +* Lock timed out but check if this task was just * granted lock ownership - if so, pretend there -* was no timeout; otherwise, cleanup lock wait */ +* was no timeout; otherwise, cleanup lock wait. +*/ raw_spin_lock_irq (&sem->wait_lock);if (waiter.task) { -ldsem_atomic_update (-LDSEM_WAIT_BIAS , sem); +atomic_long_add_return (-LDSEM_WAIT_BIAS , &sem->count);list_del (&waiter.list);raw_spin_unlock_irq (&sem->wait_lock);put_task_struct (waiter.task);@@ -273,11 +259,13 @@ down_write_failed(struct ld_semaphore *sem, long count, long timeout)/* set up my own style of waitqueue */ raw_spin_lock_irq (&sem->wait_lock); -/* Try to reverse the lock attempt but if the count has changed +/* +* Try to reverse the lock attempt but if the count has changed * so that reversing fails, check if the lock is now owned, -* and early-out if so */ +* and early-out if so. +*/ do { - if (ldsem_cmpxchg(&count, count + adjust, sem)) + if (atomic_long_try_cmpxchg(&sem->count, &count, count + adjust)) break; if ((count & LDSEM_ACTIVE_MASK) == LDSEM_ACTIVE_BIAS) { raw_spin_unlock_irq(&sem->wait_lock);@@ -303,7 +291,7 @@ down_write_failed(struct ld_semaphore *sem, long count, long timeout) }if (!locked) -ldsem_atomic_update (-LDSEM_WAIT_BIAS , sem); +atomic_long_add_return (-LDSEM_WAIT_BIAS , &sem->count);list_del (&waiter.list);raw_spin_unlock_irq (&sem->wait_lock);@@ -324,7 +312,7 @@ static int __ldsem_down_read_nested(struct ld_semaphore *sem,lockdep_acquire_read (sem, subclass,0 , _RET_IP_); - count =ldsem_atomic_update (LDSEM_READ_BIAS , sem); + count =atomic_long_add_return (LDSEM_READ_BIAS , &sem->count);if (count <=0 ) {lock_stat (sem, contended);if (!down_read_failed (sem, count, timeout)) {@@ -343,7 +331,7 @@ static int __ldsem_down_write_nested(struct ld_semaphore *sem,lockdep_acquire (sem, subclass,0 , _RET_IP_); - count =ldsem_atomic_update (LDSEM_WRITE_BIAS , sem); + count =atomic_long_add_return (LDSEM_WRITE_BIAS , &sem->count);if ((count &LDSEM_ACTIVE_MASK ) !=LDSEM_ACTIVE_BIAS ) {lock_stat (sem, contended);if (!down_write_failed (sem, count, timeout)) {@@ -370,10 +358,10 @@ int __sched ldsem_down_read(struct ld_semaphore *sem, long timeout)*/ int ldsem_down_read_trylock (struct ld_semaphore *sem) { -long count = sem->count; +long count =atomic_long_read (&sem->count);while (count >=0 ) { -if (ldsem_cmpxchg (&count, count +LDSEM_READ_BIAS , sem)) { +if (atomic_long_try_cmpxchg (&sem->count, &count, count +LDSEM_READ_BIAS )) {lockdep_acquire_read (sem,0 ,1 , _RET_IP_);lock_stat (sem, acquired);return 1 ;@@ -396,10 +384,10 @@ int __sched ldsem_down_write(struct ld_semaphore *sem, long timeout)*/ int ldsem_down_write_trylock (struct ld_semaphore *sem) { -long count = sem->count; +long count =atomic_long_read (&sem->count);while ((count &LDSEM_ACTIVE_MASK ) ==0 ) { -if (ldsem_cmpxchg (&count, count +LDSEM_WRITE_BIAS , sem)) { +if (atomic_long_try_cmpxchg (&sem->count, &count, count +LDSEM_WRITE_BIAS )) {lockdep_acquire (sem,0 ,1 , _RET_IP_);lock_stat (sem, acquired);return 1 ;@@ -417,7 +405,7 @@ void ldsem_up_read(struct ld_semaphore *sem)lockdep_release (sem,1 , _RET_IP_); - count =ldsem_atomic_update (-LDSEM_READ_BIAS , sem); + count =atomic_long_add_return (-LDSEM_READ_BIAS , &sem->count);if (count <0 && (count &LDSEM_ACTIVE_MASK ) ==0 )ldsem_wake (sem); }@@ -431,7 +419,7 @@ void ldsem_up_write(struct ld_semaphore *sem)lockdep_release (sem,1 , _RET_IP_); - count =ldsem_atomic_update (-LDSEM_WRITE_BIAS , sem); + count =atomic_long_add_return (-LDSEM_WRITE_BIAS , &sem->count);if (count <0 )ldsem_wake (sem); }include/linux/tty_ldisc.h +2
-2@@ -119,13 +119,13 @@#include <linux/fs.h> #include <linux/wait.h> - +#include <linux/atomic.h> /* * the semaphore definition */ struct ld_semaphore { -long count; +atomic_long_t count;raw_spinlock_t wait_lock;unsigned int wait_readers;struct list_head read_wait;
Greg Kroah-Hartman
maintainerRe: [PATCH 1/7] atomics/tty: add missing atomic_long_t * cast
In reply to Peter ZijlstraQuoted 22 lines · Peter Zijlstra
Quoted 1 line · Peter Zijlstra
I can make a proper patch, hold on.
---
Subject: atomic/tty: Fix up atomic abuse in ldsemMark found
ldsem_cmpxchg()needed an (atomic_long_t*) cast to keep working after making theatomic_longinterface type safe.Needing casts is bad form, which made me look at the code. There are no
ld_semaphore::countusers outside of these functions so there is no reason why it can not be anatomic_long_tin the first place, obviating the need for this cast.That also ensures the loads use
atomic_long_read(), which implies (at least)READ_ONCE()in order to guarantee single-copy-atomic loads.When using
atomic_long_try_cmpxchg()theldsem_cmpxchg()wrapper gets very thin (the only difference is not changing *old on success, which most callers don't seem to care about).
Quoted 8 lines
So rework the whole thing to use
atomic_long_tand its accessors directly.While there, fixup all the horrible comment styles.
Cc Peter Hurley <[email protected]>Reported-by Mark Rutland <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>
Looks good, I'll queue this up after 4.18-rc1 is out, thanks.
greg k-h
Mark Rutland
reviewerRe: [PATCH 1/7] atomics/tty: add missing atomic_long_t * cast
Hi,
Quoted 26 lines · Greg Kroah-Hartman
Quoted 25 lines · Peter Zijlstra
Quoted 1 line · Peter Zijlstra
I can make a proper patch, hold on.
---
Subject: atomic/tty: Fix up atomic abuse in ldsemMark found
ldsem_cmpxchg()needed an (atomic_long_t*) cast to keep working after making theatomic_longinterface type safe.Needing casts is bad form, which made me look at the code. There are no
ld_semaphore::countusers outside of these functions so there is no reason why it can not be anatomic_long_tin the first place, obviating the need for this cast.That also ensures the loads use
atomic_long_read(), which implies (at least)READ_ONCE()in order to guarantee single-copy-atomic loads.When using
atomic_long_try_cmpxchg()theldsem_cmpxchg()wrapper gets very thin (the only difference is not changing *old on success, which most callers don't seem to care about).So rework the whole thing to use
atomic_long_tand its accessors directly.
Quoted 7 lines
Quoted 5 lines
While there, fixup all the horrible comment styles.
Cc Peter Hurley <[email protected]>Reported-by Mark Rutland <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>Looks good, I'll queue this up after 4.18-rc1 is out, thanks.
Now that v4.18-rc1 is out, I thought I'd ping so that this doesn't get forgotten.
Have a good weekend!
Mark.
Greg Kroah-Hartman
maintainerRe: [PATCH 1/7] atomics/tty: add missing atomic_long_t * cast
Quoted 31 lines · Mark Rutland
Hi,
Quoted 28 lines · Greg Kroah-Hartman
Quoted 27 lines · Peter Zijlstra
Quoted 1 line · Peter Zijlstra
I can make a proper patch, hold on.
---
Subject: atomic/tty: Fix up atomic abuse in ldsemMark found
ldsem_cmpxchg()needed an (atomic_long_t*) cast to keep working after making theatomic_longinterface type safe.Needing casts is bad form, which made me look at the code. There are no
ld_semaphore::countusers outside of these functions so there is no reason why it can not be anatomic_long_tin the first place, obviating the need for this cast.That also ensures the loads use
atomic_long_read(), which implies (at least)READ_ONCE()in order to guarantee single-copy-atomic loads.When using
atomic_long_try_cmpxchg()theldsem_cmpxchg()wrapper gets very thin (the only difference is not changing *old on success, which most callers don't seem to care about).So rework the whole thing to use
atomic_long_tand its accessors directly.While there, fixup all the horrible comment styles.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Cc Peter Hurley <[email protected]>Reported-by Mark Rutland <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>Looks good, I'll queue this up after 4.18-rc1 is out, thanks.
Now that v4.18-rc1 is out, I thought I'd ping so that this doesn't get forgotten.
Not forgotten, sorry, now queued up.
greg k-h
Mark Rutland
reviewerPATCH 2/7 atomics/treewide: rework ordering barriers
In reply to Mark RutlandCurrently architectures can override __atomic_op_*() to define the barriers used before/after a relaxed atomic when used to build acquire/release/fence variants.
This has the unfortunate property of requiring the architecture to define the full wrapper for the atomics, rather than just the barriers they care about, and gets in the way of generating atomics which can be easily read.
Instead, this patch has architectures define an optional set of barriers, __atomic_mb_{before,after}_{acquire,release,fence}(), which <linux/atomic.h> uses to build the wrappers.
There should be no functional change as a result of this patch.
--- arch/alpha/include/asm/atomic.h | 8 ++++---- arch/powerpc/include/asm/atomic.h | 17 +++++------------ arch/riscv/include/asm/atomic.h | 17 +++++------------ include/linux/atomic.h | 38 ++++++++++++++++++++++---------------- 4 files changed, 36 insertions(+), 44 deletions(-)
I'm aware that the naming of these barriers is potentially bad, and something like atomic_acquire_mb()/atomic_release_mb() might be better. I only really care that the core code can use the barriers directly rather than this being hidden in an architecture's __atomic_op_*().
Peter/Will, I'll defer to your judgement on naming.
Thanks,
Mark.
arch/alpha/include/asm/atomic.h +4 -4
@@ -18,11 +18,11 @@* To ensure dependency ordering is preserved for the _relaxed and * _release atomics, an smp_read_barrier_depends() is unconditionally * inserted into the _relaxed variants, which are used to build the -* barriered versions. To avoid redundant back-to-back fences, we can -* define the _acquire and _fence versions explicitly. +* barriered versions. Avoid redundant back-to-back fences in the +* _acquire and _fence versions. */ -#define __atomic_op_acquire(op, args...) op##_relaxed(args) -#define __atomic_op_fence __atomic_op_release +#define __atomic_mb__after_acquire () +#define __atomic_mb__after_fence ()#define ATOMIC_INIT (i) { (i) }#define ATOMIC64_INIT (i) { (i) }
arch/powerpc/include/asm/atomic.h +5 -12
@@ -18,18 +18,11 @@* a "bne-" instruction at the end, so an isync is enough as a acquire barrier * on the platform without lwsync. */ -#define __atomic_op_acquire(op, args...) \ -({ \ - typeof(op##_relaxed(args)) __ret = op##_relaxed(args); \ - __asm__ __volatile__(PPC_ACQUIRE_BARRIER "" : : : "memory"); \ - __ret; \ -}) - -#define __atomic_op_release(op, args...) \ -({ \ - __asm__ __volatile__(PPC_RELEASE_BARRIER "" : : : "memory"); \ - op##_relaxed(args); \ -}) +#define __atomic_mb__after_acquire () \ + __asm__ __volatile__(PPC_ACQUIRE_BARRIER "" : : : "memory") + +#define __atomic_mb__before_release () \ + __asm__ __volatile__(PPC_RELEASE_BARRIER "" : : : "memory")static __inline__int atomic_read (const atomic_t *v) {
arch/riscv/include/asm/atomic.h +5 -12
@@ -25,18 +25,11 @@#define ATOMIC_INIT (i) { (i) } -#define __atomic_op_acquire(op, args...) \ -({ \ - typeof(op##_relaxed(args)) __ret = op##_relaxed(args); \ - __asm__ __volatile__(RISCV_ACQUIRE_BARRIER "" ::: "memory"); \ - __ret; \ -}) - -#define __atomic_op_release(op, args...) \ -({ \ - __asm__ __volatile__(RISCV_RELEASE_BARRIER "" ::: "memory"); \ - op##_relaxed(args); \ -}) +#define __atomic_mb__after_acquire () \ + __asm__ __volatile__(RISCV_ACQUIRE_BARRIER "" ::: "memory") + +#define __atomic_mb__before_release () \ + __asm__ __volatile__(RISCV_RELEASE_BARRIER "" ::: "memory"); static __always_inline int atomic_read(const atomic_t *v) {
include/linux/atomic.h +22 -16
@@ -36,40 +36,46 @@* barriers on top of the relaxed variant. In the case where the relaxed * variant is already fully ordered, no additional barriers are needed. * -* Besides, if an arch has a special barrier for acquire/release, it could -* implement its own __atomic_op_* and use the same framework for building -* variants -* -* If an architecture overrides __atomic_op_acquire() it will probably want -* to define smp_mb__after_spinlock(). +* If an architecture overrides __atomic_mb_after_acquire() it will probably +* want to define smp_mb__after_spinlock(). */ -#ifndef __atomic_op_acquire +#ifndef __atomic_mb__after_acquire +#define __atomic_mb__after_acquire smp_mb__after_atomic +#endif + +#ifndef __atomic_mb__before_release +#define __atomic_mb__before_release smp_mb__before_atomic +#endif + +#ifndef __atomic_mb__before_fence +#define __atomic_mb__before_fence smp_mb__before_atomic +#endif + +#ifndef __atomic_mb__after_fence +#define __atomic_mb__after_fence smp_mb__after_atomic +#endif + #define __atomic_op_acquire(op, args...) \ ({ \ typeof(op##_relaxed(args)) __ret = op##_relaxed(args); \ - smp_mb__after_atomic(); \ + __atomic_mb__after_acquire(); \ __ret; \ }) -#endif -#ifndef __atomic_op_release #define __atomic_op_release(op, args...) \ ({ \ - smp_mb__before_atomic(); \ + __atomic_mb__before_release(); \ op##_relaxed(args); \ }) -#endif -#ifndef __atomic_op_fence #define __atomic_op_fence(op, args...) \ ({ \ typeof(op##_relaxed(args)) __ret; \ - smp_mb__before_atomic(); \ + __atomic_mb__before_fence(); \ __ret = op##_relaxed(args); \ - smp_mb__after_atomic(); \ + __atomic_mb__after_fence(); \ __ret; \ }) -#endif /* atomic_add_return_relaxed */ #ifndef atomic_add_return_relaxed
Signature · 1 line
2.11.0
Peter Zijlstra
maintainerRe: [PATCH 2/7] atomics/treewide: rework ordering barriers
Quoted 5 lines · Mark Rutland
include/linux/atomic.h +5
-0+#ifndef __atomic_mb__after_acquire +#define __atomic_mb__after_acquire smp_mb__after_atomic +#endif + +#ifndef __atomic_mb__before_release
include/linux/atomic.h line 56
Quoted 10 lines
include/linux/atomic.h +10
-0+#define __atomic_mb__before_release smp_mb__before_atomic +#endif + +#ifndef __atomic_mb__before_fence +#define __atomic_mb__before_fence smp_mb__before_atomic +#endif + +#ifndef __atomic_mb__after_fence +#define __atomic_mb__after_fence smp_mb__after_atomic +#endif
I really _really_ dislike those names.. because they imply providing an MB before/after something else.
But that is exactly what they do not.
How about:
__atomic_acquire_fence
__atomic_release_fence
for the acquire/release things, and simply using smp_mb__{before,after}_atomic for the full fence, its exactly what they were made for.
Mark Rutland
reviewerRe: [PATCH 2/7] atomics/treewide: rework ordering barriers
Quoted 20 lines · Peter Zijlstra
Quoted 5 lines · Mark Rutland
include/linux/atomic.h +5
-0+#ifndef __atomic_mb__after_acquire +#define __atomic_mb__after_acquire smp_mb__after_atomic +#endif + +#ifndef __atomic_mb__before_releaseinclude/linux/atomic.h line 56
Quoted 10 lines
include/linux/atomic.h +10
-0+#define __atomic_mb__before_release smp_mb__before_atomic +#endif + +#ifndef __atomic_mb__before_fence +#define __atomic_mb__before_fence smp_mb__before_atomic +#endif + +#ifndef __atomic_mb__after_fence +#define __atomic_mb__after_fence smp_mb__after_atomic +#endif I really _really_ dislike those names.. because they imply providing an MB before/after something else.
Quoted 8 lines
But that is exactly what they do not.
How about:
__atomic_acquire_fence
__atomic_release_fencefor the acquire/release things,
Sure, those sound fine to me.
Quoted 2 lines
and simply using smp_mb__{before,after}_atomic for the full fence, its exactly what they were made for.
The snag is arch/alpha, whare we have:
/*
* To ensure dependency ordering is preserved for the _relaxed and
* _release atomics, an smp_read_barrier_depends() is unconditionally
* inserted into the _relaxed variants, which are used to build the
* barriered versions. To avoid redundant back-to-back fences, we can
* define the _acquire and _fence versions explicitly.
*/
#define __atomic_op_acquire(op, args...) op##_relaxed(args)
#define __atomic_op_fence __atomic_op_release
... where alpha's smp_read_barrier_depends() is the same as smp_mb_after_atomic().
Since alpha's non-value-returning atomics do not have the smp_read_barrier_depends(), I can't just define an empty smp_mb_after_atomic().
Thoughts?
Thanks,
Mark.
Peter Zijlstra
maintainerRe: [PATCH 2/7] atomics/treewide: rework ordering barriers
Quoted 16 lines · Mark Rutland
Quoted 2 lines · Peter Zijlstra
and simply using smp_mb__{before,after}_atomic for the full fence, its exactly what they were made for.
The snag is
arch/alpha, whare we have:/*
* To ensure dependency ordering is preserved for the_relaxedand
*_releaseatomics, ansmp_read_barrier_depends()is unconditionally
* inserted into the_relaxedvariants, which are used to build the
* barriered versions. To avoid redundant back-to-back fences, we can
* define the_acquireand_fenceversions explicitly.
*/
#define__atomic_op_acquire(op, args...)op##_relaxed(args)
#define__atomic_op_fence__atomic_op_release
Quoted 8 lines
... where alpha's
smp_read_barrier_depends()is the same assmp_mb_after_atomic().Since alpha's non-value-returning atomics do not have the
smp_read_barrier_depends(), I can't just define an emptysmp_mb_after_atomic().Thoughts?
Bah, of course there had to be a misfit.
Something along these lines then:
__atomic_acquire_fence
__atomic_release_fence
__atomic_mb_before
__atomic_mb_after
?
Mark Rutland
reviewerRe: [PATCH 2/7] atomics/treewide: rework ordering barriers
Quoted 20 lines · Peter Zijlstra
Quoted 19 lines · Mark Rutland
Quoted 2 lines · Peter Zijlstra
and simply using smp_mb__{before,after}_atomic for the full fence, its exactly what they were made for.
The snag is
arch/alpha, whare we have:/*
* To ensure dependency ordering is preserved for the_relaxedand
*_releaseatomics, ansmp_read_barrier_depends()is unconditionally
* inserted into the_relaxedvariants, which are used to build the
* barriered versions. To avoid redundant back-to-back fences, we can
* define the_acquireand_fenceversions explicitly.
*/
#define__atomic_op_acquire(op, args...)op##_relaxed(args)
#define__atomic_op_fence__atomic_op_release... where alpha's
smp_read_barrier_depends()is the same assmp_mb_after_atomic().
Quoted 7 lines
Quoted 5 lines
Since alpha's non-value-returning atomics do not have the
smp_read_barrier_depends(), I can't just define an emptysmp_mb_after_atomic().Thoughts?
Bah, of course there had to be a misfit.
Of course it had to be alpha. ;)
Quoted 6 lines
Something along these lines then:
__atomic_acquire_fence
__atomic_release_fence
__atomic_mb_before
__atomic_mb_after
Locally I've made this:
__atomic_acquire_fence()__atomic_release_fence()__atomic_pre_fence()__atomic_post_fence()
... but I'm more than happy to rename however you prefer.
Thanks,
Mark.
Peter Zijlstra
maintainerRe: [PATCH 2/7] atomics/treewide: rework ordering barriers
Quoted 8 lines · Mark Rutland
Locally I've made this:
__atomic_acquire_fence()__atomic_release_fence()__atomic_pre_fence()__atomic_post_fence()... but I'm more than happy to rename however you prefer.
No that's fine. As long as we're rid of the whole mb_before_release and friends.
Thanks!
Mark Rutland
reviewerPATCH 3/7 atomics: separate basic {cmp,}xchg()
In reply to Mark RutlandCurrently the basic {cmp,}xchg() definitions live in the middle of the atomic_t definitions. Let's pull them earlier so that the file has, in order:
* __atomic_op_<order>() definitions
* {cmp,}xchg() definitions
* atomic_t definiitions
* atomic64_t definitions
* atomic_long_t definitions
... which will make subsequent rework less messy.
There should be no functional change as a result of this patch.
--- include/linux/atomic.h | 138 ++++++++++++++++++++++++------------------------- 1 file changed, 69 insertions(+), 69 deletions(-)
include/linux/atomic.h +69 -69
@@ -77,6 +77,75 @@ __ret; \ }) +/* cmpxchg_relaxed */ +#ifndef cmpxchg_relaxed +#define cmpxchg_relaxed cmpxchg +#define cmpxchg_acquire cmpxchg +#define cmpxchg_release cmpxchg + +#else /* cmpxchg_relaxed */ + +#ifndef cmpxchg_acquire +#define cmpxchg_acquire (...) \ + __atomic_op_acquire(cmpxchg, __VA_ARGS__) +#endif + +#ifndef cmpxchg_release +#define cmpxchg_release (...) \ + __atomic_op_release(cmpxchg, __VA_ARGS__) +#endif + +#ifndef cmpxchg +#define cmpxchg (...) \ + __atomic_op_fence(cmpxchg, __VA_ARGS__) +#endif +#endif /* cmpxchg_relaxed */ + +/* cmpxchg64_relaxed */ +#ifndef cmpxchg64_relaxed +#define cmpxchg64_relaxed cmpxchg64 +#define cmpxchg64_acquire cmpxchg64 +#define cmpxchg64_release cmpxchg64 + +#else /* cmpxchg64_relaxed */ + +#ifndef cmpxchg64_acquire +#define cmpxchg64_acquire (...) \ + __atomic_op_acquire(cmpxchg64, __VA_ARGS__) +#endif + +#ifndef cmpxchg64_release +#define cmpxchg64_release (...) \ + __atomic_op_release(cmpxchg64, __VA_ARGS__) +#endif + +#ifndef cmpxchg64 +#define cmpxchg64 (...) \ + __atomic_op_fence(cmpxchg64, __VA_ARGS__) +#endif +#endif /* cmpxchg64_relaxed */ + +/* xchg_relaxed */ +#ifndef xchg_relaxed +#define xchg_relaxed xchg +#define xchg_acquire xchg +#define xchg_release xchg + +#else /* xchg_relaxed */ + +#ifndef xchg_acquire +#define xchg_acquire (...) __atomic_op_acquire(xchg, __VA_ARGS__) +#endif + +#ifndef xchg_release +#define xchg_release (...) __atomic_op_release(xchg, __VA_ARGS__) +#endif + +#ifndef xchg +#define xchg (...) __atomic_op_fence(xchg, __VA_ARGS__) +#endif +#endif /* xchg_relaxed */ +/* atomic_add_return_relaxed */ #ifndef atomic_add_return_relaxed#define atomic_add_return_relaxed atomic_add_return
@@ -480,75 +549,6 @@#define atomic_try_cmpxchg_release atomic_try_cmpxchg#endif /* atomic_try_cmpxchg */ -/* cmpxchg_relaxed */ -#ifndef cmpxchg_relaxed -#define cmpxchg_relaxed cmpxchg -#define cmpxchg_acquire cmpxchg -#define cmpxchg_release cmpxchg - -#else /* cmpxchg_relaxed */ - -#ifndef cmpxchg_acquire -#define cmpxchg_acquire (...) \ - __atomic_op_acquire(cmpxchg, __VA_ARGS__) -#endif - -#ifndef cmpxchg_release -#define cmpxchg_release (...) \ - __atomic_op_release(cmpxchg, __VA_ARGS__) -#endif - -#ifndef cmpxchg -#define cmpxchg (...) \ - __atomic_op_fence(cmpxchg, __VA_ARGS__) -#endif -#endif /* cmpxchg_relaxed */ - -/* cmpxchg64_relaxed */ -#ifndef cmpxchg64_relaxed -#define cmpxchg64_relaxed cmpxchg64 -#define cmpxchg64_acquire cmpxchg64 -#define cmpxchg64_release cmpxchg64 - -#else /* cmpxchg64_relaxed */ - -#ifndef cmpxchg64_acquire -#define cmpxchg64_acquire (...) \ - __atomic_op_acquire(cmpxchg64, __VA_ARGS__) -#endif - -#ifndef cmpxchg64_release -#define cmpxchg64_release (...) \ - __atomic_op_release(cmpxchg64, __VA_ARGS__) -#endif - -#ifndef cmpxchg64 -#define cmpxchg64 (...) \ - __atomic_op_fence(cmpxchg64, __VA_ARGS__) -#endif -#endif /* cmpxchg64_relaxed */ - -/* xchg_relaxed */ -#ifndef xchg_relaxed -#define xchg_relaxed xchg -#define xchg_acquire xchg -#define xchg_release xchg - -#else /* xchg_relaxed */ - -#ifndef xchg_acquire -#define xchg_acquire (...) __atomic_op_acquire(xchg, __VA_ARGS__) -#endif - -#ifndef xchg_release -#define xchg_release (...) __atomic_op_release(xchg, __VA_ARGS__) -#endif - -#ifndef xchg -#define xchg (...) __atomic_op_fence(xchg, __VA_ARGS__) -#endif -#endif /* xchg_relaxed */ -/** * atomic_fetch_add_unless - add unless the number is already a given value * @v: pointer of type atomic_t
Signature · 1 line
2.11.0
Mark Rutland
reviewerPATCH 4/7 atomics: add common header generation files
In reply to Mark RutlandTo minimize repetition, to allow for future rework, and to ensure regularity of the various atomic APIs, we'd like to automatically generate (the bulk of) a number of headers related to atomics.
This patch adds the infrastructure to do so, leaving actual conversion of headers to subsequent patches. This infrastructure consists of:
* atomics.tbl - a table describing the functions in the atomics API, with names, prototypes, and metadata describing the variants that exist (e.g fetch/return, acquire/release/relaxed). Note that the return type is dependent on the particular variant.
* atomic-tbl.sh - a library of routines useful for dealing with atomics.tbl (e.g. querying which variants exist, or generating argument/parameter lists for a given function variant).
* gen-atomic-fallback.sh - a script which generates a header of fallbacks, covering cases where architecture omit certain functions (e.g. omitting relaxed variants).
* gen-atomic-long.sh - a script which generates wrappers providing the atomic_long API atomic of the relevant atomic or atomic64 API, ensuring the APIs are consistent.
* gen-atomic-instrumented.sh - a script which generates atomic* wrappers atop of arch_atomic* functions, with automatically generated KASAN instrumentation.
* fallbacks/* - a set of fallback implementations for atomics, which should be used when no implementation of a given atomic is provided. These are used by gen-atomic-fallback.sh to generate fallbacks, and these are also used by other scripts to determine the set of optional atomics (as required to generate preprocessor guards correctly).
Fallbacks may use the following variables:
${atomic} atomic prefix: atomic/atomic64/atomic_long, which can be
used to derive the atomic type, and to prefix functions
${int} integer type: int/s64/long
${pfx} variant prefix, e.g. fetch_
${name} base function name, e.g. add
${sfx} variant suffix, e.g. _return
${order} order suffix, e.g. _relaxed
${atomicname} full name, e.g. atomic64_fetch_add_relaxed
${ret} return type of the function, e.g. void
${retstmt} a return statement (with a trailing space), unless the
variant returns void
${params} parameter list for the function declaration, e.g.
"int i, atomic_t *v"
${args} argument list for invoking the function, e.g. "i, v"... for clarity, ${ret}, ${retstmt}, ${params}, and ${args} are open-coded for fallbacks where these do not vary, or are critical to understanding the logic of the fallback.
The MAINTAINERS entry for the atomic infrastructure is updated to cover the new scripts.
There should be no functional change as a result of this patch.
--- MAINTAINERS | 1 + scripts/atomic/atomic-tbl.sh | 186 +++++++++++++++++++++++++++ scripts/atomic/atomics.tbl | 41 ++++++ scripts/atomic/fallbacks/acquire | 9 ++ scripts/atomic/fallbacks/add_negative | 16 +++ scripts/atomic/fallbacks/add_unless | 16 +++ scripts/atomic/fallbacks/andnot | 7 + scripts/atomic/fallbacks/dec | 7 + scripts/atomic/fallbacks/dec_and_test | 15 +++ scripts/atomic/fallbacks/dec_if_positive | 15 +++ scripts/atomic/fallbacks/dec_unless_positive | 14 ++ scripts/atomic/fallbacks/fence | 11 ++ scripts/atomic/fallbacks/fetch_add_unless | 23 ++++ scripts/atomic/fallbacks/inc | 7 + scripts/atomic/fallbacks/inc_and_test | 15 +++ scripts/atomic/fallbacks/inc_not_zero | 14 ++ scripts/atomic/fallbacks/inc_unless_negative | 14 ++ scripts/atomic/fallbacks/read_acquire | 7 + scripts/atomic/fallbacks/release | 8 ++ scripts/atomic/fallbacks/set_release | 7 + scripts/atomic/fallbacks/sub_and_test | 16 +++ scripts/atomic/fallbacks/try_cmpxchg | 11 ++ scripts/atomic/gen-atomic-fallback.sh | 144 +++++++++++++++++++++ scripts/atomic/gen-atomic-instrumented.sh | 122 ++++++++++++++++++ scripts/atomic/gen-atomic-long.sh | 98 ++++++++++++++ 25 files changed, 824 insertions(+) create mode 100755 scripts/atomic/atomic-tbl.sh create mode 100644 scripts/atomic/atomics.tbl create mode 100644 scripts/atomic/fallbacks/acquire create mode 100644 scripts/atomic/fallbacks/add_negative create mode 100644 scripts/atomic/fallbacks/add_unless create mode 100644 scripts/atomic/fallbacks/andnot create mode 100644 scripts/atomic/fallbacks/dec create mode 100644 scripts/atomic/fallbacks/dec_and_test create mode 100644 scripts/atomic/fallbacks/dec_if_positive create mode 100644 scripts/atomic/fallbacks/dec_unless_positive create mode 100644 scripts/atomic/fallbacks/fence create mode 100644 scripts/atomic/fallbacks/fetch_add_unless create mode 100644 scripts/atomic/fallbacks/inc create mode 100644 scripts/atomic/fallbacks/inc_and_test create mode 100644 scripts/atomic/fallbacks/inc_not_zero create mode 100644 scripts/atomic/fallbacks/inc_unless_negative create mode 100644 scripts/atomic/fallbacks/read_acquire create mode 100644 scripts/atomic/fallbacks/release create mode 100644 scripts/atomic/fallbacks/set_release create mode 100644 scripts/atomic/fallbacks/sub_and_test create mode 100644 scripts/atomic/fallbacks/try_cmpxchg create mode 100755 scripts/atomic/gen-atomic-fallback.sh create mode 100755 scripts/atomic/gen-atomic-instrumented.sh create mode 100755 scripts/atomic/gen-atomic-long.sh
MAINTAINERS +1 -0
@@ -2492,6 +2492,7 @@ L: [email protected] S: Maintained F: arch/*/include/asm/atomic*.h F: include/*/atomic*.h +F: scripts/atomic/ ATTO EXPRESSSAS SAS/SATA RAID SCSI DRIVER M: Bradley Grove <[email protected]>
scripts/atomic/atomic-tbl.sh new file +186 -0
186 lines not on this page · raw message
scripts/atomic/atomics.tbl new file +41 -0
41 lines not on this page · raw message
scripts/atomic/fallbacks/acquire new file +9 -0
@@ -0,0 +1,9 @@ +cat <<EOF +static inline ${ret} +${atomic}_${pfx}${name}${sfx}_acquire(${params}) +{ + ${ret} ret = ${atomic}_${pfx}${name}${sfx}_relaxed(${args}); + __atomic_mb__after_acquire(); + return ret; +} +EOF
scripts/atomic/fallbacks/add_negative new file +16 -0
@@ -0,0 +1,16 @@ +cat <<EOF +/** + * ${atomic}_add_negative - add and test if negative + * @i: integer value to add + * @v: pointer of type ${atomic}_t + * + * Atomically adds @i to @v and returns true + * if the result is negative, or false when + * result is greater than or equal to zero. + */ +static inline bool +${atomic}_add_negative(${int} i, ${atomic}_t *v) +{ + return ${atomic}_add_return(i, v) < 0; +} +EOF
scripts/atomic/fallbacks/add_unless new file +16 -0
@@ -0,0 +1,16 @@ +cat << EOF +/** + * ${atomic}_add_unless - add unless the number is already a given value + * @v: pointer of type ${atomic}_t + * @a: the amount to add to v... + * @u: ...unless v is equal to u. + * + * Atomically adds @a to @v, so long as @v was not already @u. + * Returns non-zero if @v was not @u, and zero otherwise. + */ +static inline bool +${atomic}_add_unless(${atomic}_t *v, ${int} a, ${int} u) +{ + return ${atomic}_fetch_add_unless(v, a, u) != u; +} +EOF
scripts/atomic/fallbacks/andnot new file +7 -0
@@ -0,0 +1,7 @@ +cat <<EOF +static inline ${ret} +${atomic}_${pfx}andnot${sfx}${order}(${int} i, ${atomic}_t *v) +{ + ${retstmt}${atomic}_${pfx}and${sfx}${order}(~i, v); +} +EOF
scripts/atomic/fallbacks/dec new file +7 -0
@@ -0,0 +1,7 @@ +cat <<EOF +static inline ${ret} +${atomic}_${pfx}dec${sfx}${order}(${atomic}_t *v) +{ + ${retstmt}${atomic}_${pfx}sub${sfx}${order}(1, v); +} +EOF
scripts/atomic/fallbacks/dec_and_test new file +15 -0
@@ -0,0 +1,15 @@ +cat <<EOF +/** + * ${atomic}_dec_and_test - decrement and test + * @v: pointer of type ${atomic}_t + * + * Atomically decrements @v by 1 and + * returns true if the result is 0, or false for all other + * cases. + */ +static inline bool +${atomic}_dec_and_test(${atomic}_t *v) +{ + return ${atomic}_dec_return(v) == 0; +} +EOF
scripts/atomic/fallbacks/dec_if_positive new file +15 -0
@@ -0,0 +1,15 @@ +cat <<EOF +static inline ${ret} +${atomic}_dec_if_positive(${atomic}_t *v) +{ + ${int} dec, c = ${atomic}_read(v); + + do { + dec = c - 1; + if (dec < 0) + break; + } while (!${atomic}_try_cmpxchg(v, &c, dec)); + + return dec; +} +EOF
scripts/atomic/fallbacks/dec_unless_positive new file +14 -0
@@ -0,0 +1,14 @@ +cat <<EOF +static inline bool +${atomic}_dec_unless_positive(${atomic}_t *v) +{ + ${int} c = ${atomic}_read(v); + + do { + if (c > 0) + return false; + } while (!${atomic}_try_cmpxchg(v, &c, c - 1)); + + return true; +} +EOF
scripts/atomic/fallbacks/fence new file +11 -0
@@ -0,0 +1,11 @@ +cat <<EOF +static inline ${ret} +${atomic}_${pfx}${name}${sfx}(${params}) +{ + ${ret} ret; + __atomic_mb__before_fence(); + ret = ${atomic}_${pfx}${name}${sfx}_relaxed(${args}); + __atomic_mb__after_fence(); + return ret; +} +EOF
scripts/atomic/fallbacks/fetch_add_unless new file +23 -0
@@ -0,0 +1,23 @@ +cat << EOF +/** + * ${atomic}_fetch_add_unless - add unless the number is already a given value + * @v: pointer of type ${atomic}_t + * @a: the amount to add to v... + * @u: ...unless v is equal to u. + * + * Atomically adds @a to @v, so long as @v was not already @u. + * Returns original value of @v + */ +static inline ${int} +${atomic}_fetch_add_unless(${atomic}_t *v, ${int} a, ${int} u) +{ + ${int} c = ${atomic}_read(v); + + do { + if (unlikely(c == u)) + break; + } while (!${atomic}_try_cmpxchg(v, &c, c + a)); + + return c; +} +EOF
scripts/atomic/fallbacks/inc new file +7 -0
@@ -0,0 +1,7 @@ +cat <<EOF +static inline ${ret} +${atomic}_${pfx}inc${sfx}${order}(${atomic}_t *v) +{ + ${retstmt}${atomic}_${pfx}add${sfx}${order}(1, v); +} +EOF
scripts/atomic/fallbacks/inc_and_test new file +15 -0
@@ -0,0 +1,15 @@ +cat <<EOF +/** + * ${atomic}_inc_and_test - increment and test + * @v: pointer of type ${atomic}_t + * + * Atomically increments @v by 1 + * and returns true if the result is zero, or false for all + * other cases. + */ +static inline bool +${atomic}_inc_and_test(${atomic}_t *v) +{ + return ${atomic}_inc_return(v) == 0; +} +EOF
scripts/atomic/fallbacks/inc_not_zero new file +14 -0
@@ -0,0 +1,14 @@ +cat <<EOF +/** + * ${atomic}_inc_not_zero - increment unless the number is zero + * @v: pointer of type ${atomic}_t + * + * Atomically increments @v by 1, so long as @v is non-zero. + * Returns non-zero if @v was non-zero, and zero otherwise. + */ +static inline bool +${atomic}_inc_not_zero(${atomic}_t *v) +{ + return ${atomic}_add_unless(v, 1, 0); +} +EOF
scripts/atomic/fallbacks/inc_unless_negative new file +14 -0
@@ -0,0 +1,14 @@ +cat <<EOF +static inline bool +${atomic}_inc_unless_negative(${atomic}_t *v) +{ + ${int} c = ${atomic}_read(v); + + do { + if (c < 0) + return false; + } while (!${atomic}_try_cmpxchg(v, &c, c + 1)); + + return true; +} +EOF
scripts/atomic/fallbacks/read_acquire new file +7 -0
@@ -0,0 +1,7 @@ +cat <<EOF +static inline ${ret} +${atomic}_read_acquire(const ${atomic}_t *v) +{ + return smp_load_acquire(&(v)->counter); +} +EOF
scripts/atomic/fallbacks/release new file +8 -0
@@ -0,0 +1,8 @@ +cat <<EOF +static inline ${ret} +${atomic}_${pfx}${name}${sfx}_release(${params}) +{ + __atomic_mb__before_release(); + ${retstmt}${atomic}_${pfx}${name}${sfx}_relaxed(${args}); +} +EOF
scripts/atomic/fallbacks/set_release new file +7 -0
@@ -0,0 +1,7 @@ +cat <<EOF +static inline void +${atomic}_set_release(${atomic}_t *v, ${int} i) +{ + smp_store_release(&(v)->counter, i); +} +EOF
scripts/atomic/fallbacks/sub_and_test new file +16 -0
@@ -0,0 +1,16 @@ +cat <<EOF +/** + * ${atomic}_sub_and_test - subtract value from variable and test result + * @i: integer value to subtract + * @v: pointer of type ${atomic}_t + * + * Atomically subtracts @i from @v and returns + * true if the result is zero, or false for all + * other cases. + */ +static inline bool +${atomic}_sub_and_test(${int} i, ${atomic}_t *v) +{ + return ${atomic}_sub_return(i, v) == 0; +} +EOF
scripts/atomic/fallbacks/try_cmpxchg new file +11 -0
@@ -0,0 +1,11 @@ +cat <<EOF +static inline bool +${atomic}_try_cmpxchg${order}(${atomic}_t *v, ${int} *old, ${int} new) +{ + ${int} r, o = *old; + r = ${atomic}_cmpxchg${order}(v, o, new); + if (unlikely(r != o)) + *old = r; + return likely(r == o); +} +EOF
scripts/atomic/gen-atomic-fallback.sh new file +144 -0
144 lines not on this page · raw message
scripts/atomic/gen-atomic-instrumented.sh new file +122 -0
122 lines not on this page · raw message
scripts/atomic/gen-atomic-long.sh new file +98 -0
98 lines not on this page · raw message
Signature · 1 line
2.11.0
Peter Zijlstra
maintainerRe: [PATCH 4/7] atomics: add common header generation files
Quoted 10 lines · Mark Rutland
+++ b/scripts/atomic/atomics.tbl
scripts/atomic/atomics.tbl new file +8
-0@@ -0,0 +1,41 @@ +# name meta args... +# +# Where meta contains a string of variants to generate. +# Upper-case implies _{acquire,release,relaxed} variants. +# Valid meta values are: +# * B/b - bool: returns bool +# * v - void: returns void +# * I/i - int: returns base type
scripts/atomic/atomics.tbl line 18
Quoted 10 lines
scripts/atomic/atomics.tbl new file +10
-0+# * R - return: returns base type (has _return variants) +# * F/f - fetch: returns base type (has fetch_ variants) +# * l - load: returns base type (has _acquire order variant) +# * s - store: returns void (has _release order variant) +# +# Where args contains list of type[:name], where type is: +# * cv - const pointer to atomic base type (atomic_t/atomic64_t/atomic_long_t) +# * v - pointer to atomic base type (atomic_t/atomic64_t/atomic_long_t) +# * i - base type (int/s64/long) +# * I - pointer to base type (int/s64/long)
I thought we agreed to make that 'p' instead of 'I'.
Quoted 23 lines
scripts/atomic/atomics.tbl new file +23
-0+# +read l cv +set s v i +add vRF i v +sub vRF i v +inc vRF v +dec vRF v +and vF i v +andnot vF i v +or vF i v +xor vF i v +xchg I v i +cmpxchg I v i:old i:new +try_cmpxchg B v I:old i:new +sub_and_test b i v +dec_and_test b v +inc_and_test b v +add_negative b i v +add_unless fb v i:a i:u +inc_not_zero b v +inc_unless_negative b v +dec_unless_positive b v +dec_if_positive i v
Mark Rutland
reviewerRe: [PATCH 4/7] atomics: add common header generation files
Quoted 15 lines · Peter Zijlstra
Quoted 14 lines · Mark Rutland
+++ b/scripts/atomic/atomics.tbl
scripts/atomic/atomics.tbl new file +12
-0@@ -0,0 +1,41 @@ +# name meta args... +# +# Where meta contains a string of variants to generate. +# Upper-case implies _{acquire,release,relaxed} variants. +# Valid meta values are: +# * B/b - bool: returns bool +# * v - void: returns void +# * I/i - int: returns base type +# * R - return: returns base type (has _return variants) +# * F/f - fetch: returns base type (has fetch_ variants) +# * l - load: returns base type (has _acquire order variant) +# * s - store: returns void (has _release order variant)
Quoted 8 lines
scripts/atomic/atomics.tbl line 18
Quoted 6 lines
scripts/atomic/atomics.tbl new file +6
-0+# +# Where args contains list of type[:name], where type is: +# * cv - const pointer to atomic base type (atomic_t/atomic64_t/atomic_long_t) +# * v - pointer to atomic base type (atomic_t/atomic64_t/atomic_long_t) +# * i - base type (int/s64/long) +# * I - pointer to base type (int/s64/long)I thought we agreed to make that 'p' instead of 'I'.
Whoops; I'd left that as a cleanup and never folded it in.
Fixed up now.
Thanks,
Mark
Mark Rutland
reviewerPATCH 5/7 atomics: switch to generated fallbacks
In reply to Mark RutlandAs a step to ensuring the atomic* APIs are consistent, switch to fallbacks generated by gen-atomic-fallback.sh.
These are checked in rather than generated with Kbuild, since:
* This allows inspection of the atomics with git grep and ctags on a pristine tree, which Linus strongly prefers being able to do.
* The fallbacks are not expected to change very often, and are not affected by machine details or configuration options, so regenerating them for *every* build is somewhat wasteful.
* These are included by files required *very* early in the build process (e.g. for generating bounds.h), and we'd rather not complicate the top-level Kbuild file.
The new fallback header should be equivalent to the old fallbacks in <linux/atomic.h>, but it is formatted a little differently due to scripting ensuring regularity, and things are somewhat larger as fallbacks are now expanded in place as static inline functions, with return type consitently on a separate line to try to keep each line at a sensible length.
There should be no functional change as a result of this patch.
--- include/linux/atomic-fallback.h | 2223 +++++++++++++++++++++++++++++++++++++++ include/linux/atomic.h | 1206 +-------------------- 2 files changed, 2224 insertions(+), 1205 deletions(-) create mode 100644 include/linux/atomic-fallback.h
Note: this is generated code. Please see patch 3 for the code which generated it, along with rationale in the cover letter.
Mark.
include/linux/atomic-fallback.h new file +2223 -0
@@ -0,0 +1,2223 @@ +// SPDX-License-Identifier: GPL-2.0 + +// Generated by ./scripts/atomic/gen-atomic-fallback.sh +// DO NOT MODIFY THIS FILE DIRECTLY + +#ifndef _LINUX_ATOMIC_FALLBACK_H +#define _LINUX_ATOMIC_FALLBACK_H + +#ifndef atomic_read_acquire +static inline int +atomic_read_acquire (const atomic_t *v) +{ +return smp_load_acquire (&(v)->counter); +} +#define atomic_read_acquire atomic_read_acquire +#endif + +#ifndef atomic_set_release +static inline void +atomic_set_release (atomic_t *v,int i) +{ +smp_store_release (&(v)->counter, i); +} +#define atomic_set_release atomic_set_release +#endif + +#ifndef atomic_add_return_relaxed +#define atomic_add_return_acquire atomic_add_return +#define atomic_add_return_release atomic_add_return +#define atomic_add_return_relaxed atomic_add_return +#else /* atomic_add_return_relaxed */ + +#ifndef atomic_add_return_acquire +static inline int +atomic_add_return_acquire (int i,atomic_t *v) +{ +int ret =atomic_add_return_relaxed (i, v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic_add_return_acquire atomic_add_return_acquire +#endif + +#ifndef atomic_add_return_release +static inline int +atomic_add_return_release (int i,atomic_t *v) +{ +__atomic_mb__before_release (); +return atomic_add_return_relaxed (i, v); +} +#define atomic_add_return_release atomic_add_return_release +#endif + +#ifndef atomic_add_return +static inline int +atomic_add_return (int i,atomic_t *v) +{ +int ret; +__atomic_mb__before_fence (); + ret =atomic_add_return_relaxed (i, v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic_add_return atomic_add_return +#endif + +#endif /* atomic_add_return_relaxed */ + +#ifndef atomic_fetch_add_relaxed +#define atomic_fetch_add_acquire atomic_fetch_add +#define atomic_fetch_add_release atomic_fetch_add +#define atomic_fetch_add_relaxed atomic_fetch_add +#else /* atomic_fetch_add_relaxed */ + +#ifndef atomic_fetch_add_acquire +static inline int +atomic_fetch_add_acquire (int i,atomic_t *v) +{ +int ret =atomic_fetch_add_relaxed (i, v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic_fetch_add_acquire atomic_fetch_add_acquire +#endif + +#ifndef atomic_fetch_add_release +static inline int +atomic_fetch_add_release (int i,atomic_t *v) +{ +__atomic_mb__before_release (); +return atomic_fetch_add_relaxed (i, v); +} +#define atomic_fetch_add_release atomic_fetch_add_release +#endif + +#ifndef atomic_fetch_add +static inline int +atomic_fetch_add (int i,atomic_t *v) +{ +int ret; +__atomic_mb__before_fence (); + ret =atomic_fetch_add_relaxed (i, v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic_fetch_add atomic_fetch_add +#endif + +#endif /* atomic_fetch_add_relaxed */ + +#ifndef atomic_sub_return_relaxed +#define atomic_sub_return_acquire atomic_sub_return +#define atomic_sub_return_release atomic_sub_return +#define atomic_sub_return_relaxed atomic_sub_return +#else /* atomic_sub_return_relaxed */ + +#ifndef atomic_sub_return_acquire +static inline int +atomic_sub_return_acquire (int i,atomic_t *v) +{ +int ret =atomic_sub_return_relaxed (i, v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic_sub_return_acquire atomic_sub_return_acquire +#endif + +#ifndef atomic_sub_return_release +static inline int +atomic_sub_return_release (int i,atomic_t *v) +{ +__atomic_mb__before_release (); +return atomic_sub_return_relaxed (i, v); +} +#define atomic_sub_return_release atomic_sub_return_release +#endif + +#ifndef atomic_sub_return +static inline int +atomic_sub_return (int i,atomic_t *v) +{ +int ret; +__atomic_mb__before_fence (); + ret =atomic_sub_return_relaxed (i, v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic_sub_return atomic_sub_return +#endif + +#endif /* atomic_sub_return_relaxed */ + +#ifndef atomic_fetch_sub_relaxed +#define atomic_fetch_sub_acquire atomic_fetch_sub +#define atomic_fetch_sub_release atomic_fetch_sub +#define atomic_fetch_sub_relaxed atomic_fetch_sub +#else /* atomic_fetch_sub_relaxed */ + +#ifndef atomic_fetch_sub_acquire +static inline int +atomic_fetch_sub_acquire (int i,atomic_t *v) +{ +int ret =atomic_fetch_sub_relaxed (i, v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic_fetch_sub_acquire atomic_fetch_sub_acquire +#endif + +#ifndef atomic_fetch_sub_release +static inline int +atomic_fetch_sub_release (int i,atomic_t *v) +{ +__atomic_mb__before_release (); +return atomic_fetch_sub_relaxed (i, v); +} +#define atomic_fetch_sub_release atomic_fetch_sub_release +#endif + +#ifndef atomic_fetch_sub +static inline int +atomic_fetch_sub (int i,atomic_t *v) +{ +int ret; +__atomic_mb__before_fence (); + ret =atomic_fetch_sub_relaxed (i, v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic_fetch_sub atomic_fetch_sub +#endif + +#endif /* atomic_fetch_sub_relaxed */ + +#ifndef atomic_inc +static inline void +atomic_inc (atomic_t *v) +{ +atomic_add (1 , v); +} +#define atomic_inc atomic_inc +#endif + +#ifndef atomic_inc_return_relaxed +#ifdef atomic_inc_return +#define atomic_inc_return_acquire atomic_inc_return +#define atomic_inc_return_release atomic_inc_return +#define atomic_inc_return_relaxed atomic_inc_return +#endif /* atomic_inc_return */ + +#ifndef atomic_inc_return +static inline int +atomic_inc_return (atomic_t *v) +{ +return atomic_add_return (1 , v); +} +#define atomic_inc_return atomic_inc_return +#endif + +#ifndef atomic_inc_return_acquire +static inline int +atomic_inc_return_acquire (atomic_t *v) +{ +return atomic_add_return_acquire (1 , v); +} +#define atomic_inc_return_acquire atomic_inc_return_acquire +#endif + +#ifndef atomic_inc_return_release +static inline int +atomic_inc_return_release (atomic_t *v) +{ +return atomic_add_return_release (1 , v); +} +#define atomic_inc_return_release atomic_inc_return_release +#endif + +#ifndef atomic_inc_return_relaxed +static inline int +atomic_inc_return_relaxed (atomic_t *v) +{ +return atomic_add_return_relaxed (1 , v); +} +#define atomic_inc_return_relaxed atomic_inc_return_relaxed +#endif + +#else /* atomic_inc_return_relaxed */ + +#ifndef atomic_inc_return_acquire +static inline int +atomic_inc_return_acquire (atomic_t *v) +{ +int ret =atomic_inc_return_relaxed (v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic_inc_return_acquire atomic_inc_return_acquire +#endif + +#ifndef atomic_inc_return_release +static inline int +atomic_inc_return_release (atomic_t *v) +{ +__atomic_mb__before_release (); +return atomic_inc_return_relaxed (v); +} +#define atomic_inc_return_release atomic_inc_return_release +#endif + +#ifndef atomic_inc_return +static inline int +atomic_inc_return (atomic_t *v) +{ +int ret; +__atomic_mb__before_fence (); + ret =atomic_inc_return_relaxed (v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic_inc_return atomic_inc_return +#endif + +#endif /* atomic_inc_return_relaxed */ + +#ifndef atomic_fetch_inc_relaxed +#ifdef atomic_fetch_inc +#define atomic_fetch_inc_acquire atomic_fetch_inc +#define atomic_fetch_inc_release atomic_fetch_inc +#define atomic_fetch_inc_relaxed atomic_fetch_inc +#endif /* atomic_fetch_inc */ + +#ifndef atomic_fetch_inc +static inline int +atomic_fetch_inc (atomic_t *v) +{ +return atomic_fetch_add (1 , v); +} +#define atomic_fetch_inc atomic_fetch_inc +#endif + +#ifndef atomic_fetch_inc_acquire +static inline int +atomic_fetch_inc_acquire (atomic_t *v) +{ +return atomic_fetch_add_acquire (1 , v); +} +#define atomic_fetch_inc_acquire atomic_fetch_inc_acquire +#endif + +#ifndef atomic_fetch_inc_release +static inline int +atomic_fetch_inc_release (atomic_t *v) +{ +return atomic_fetch_add_release (1 , v); +} +#define atomic_fetch_inc_release atomic_fetch_inc_release +#endif + +#ifndef atomic_fetch_inc_relaxed +static inline int +atomic_fetch_inc_relaxed (atomic_t *v) +{ +return atomic_fetch_add_relaxed (1 , v); +} +#define atomic_fetch_inc_relaxed atomic_fetch_inc_relaxed +#endif + +#else /* atomic_fetch_inc_relaxed */ + +#ifndef atomic_fetch_inc_acquire +static inline int +atomic_fetch_inc_acquire (atomic_t *v) +{ +int ret =atomic_fetch_inc_relaxed (v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic_fetch_inc_acquire atomic_fetch_inc_acquire +#endif + +#ifndef atomic_fetch_inc_release +static inline int +atomic_fetch_inc_release (atomic_t *v) +{ +__atomic_mb__before_release (); +return atomic_fetch_inc_relaxed (v); +} +#define atomic_fetch_inc_release atomic_fetch_inc_release +#endif + +#ifndef atomic_fetch_inc +static inline int +atomic_fetch_inc (atomic_t *v) +{ +int ret; +__atomic_mb__before_fence (); + ret =atomic_fetch_inc_relaxed (v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic_fetch_inc atomic_fetch_inc +#endif + +#endif /* atomic_fetch_inc_relaxed */ + +#ifndef atomic_dec +static inline void +atomic_dec (atomic_t *v) +{ +atomic_sub (1 , v); +} +#define atomic_dec atomic_dec +#endif + +#ifndef atomic_dec_return_relaxed +#ifdef atomic_dec_return +#define atomic_dec_return_acquire atomic_dec_return +#define atomic_dec_return_release atomic_dec_return +#define atomic_dec_return_relaxed atomic_dec_return +#endif /* atomic_dec_return */ + +#ifndef atomic_dec_return +static inline int +atomic_dec_return (atomic_t *v) +{ +return atomic_sub_return (1 , v); +} +#define atomic_dec_return atomic_dec_return +#endif + +#ifndef atomic_dec_return_acquire +static inline int +atomic_dec_return_acquire (atomic_t *v) +{ +return atomic_sub_return_acquire (1 , v); +} +#define atomic_dec_return_acquire atomic_dec_return_acquire +#endif + +#ifndef atomic_dec_return_release +static inline int +atomic_dec_return_release (atomic_t *v) +{ +return atomic_sub_return_release (1 , v); +} +#define atomic_dec_return_release atomic_dec_return_release +#endif + +#ifndef atomic_dec_return_relaxed +static inline int +atomic_dec_return_relaxed (atomic_t *v) +{ +return atomic_sub_return_relaxed (1 , v); +} +#define atomic_dec_return_relaxed atomic_dec_return_relaxed +#endif + +#else /* atomic_dec_return_relaxed */ + +#ifndef atomic_dec_return_acquire +static inline int +atomic_dec_return_acquire (atomic_t *v) +{ +int ret =atomic_dec_return_relaxed (v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic_dec_return_acquire atomic_dec_return_acquire +#endif + +#ifndef atomic_dec_return_release +static inline int +atomic_dec_return_release (atomic_t *v) +{ +__atomic_mb__before_release (); +return atomic_dec_return_relaxed (v); +} +#define atomic_dec_return_release atomic_dec_return_release +#endif + +#ifndef atomic_dec_return +static inline int +atomic_dec_return (atomic_t *v) +{ +int ret; +__atomic_mb__before_fence (); + ret =atomic_dec_return_relaxed (v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic_dec_return atomic_dec_return +#endif + +#endif /* atomic_dec_return_relaxed */ + +#ifndef atomic_fetch_dec_relaxed +#ifdef atomic_fetch_dec +#define atomic_fetch_dec_acquire atomic_fetch_dec +#define atomic_fetch_dec_release atomic_fetch_dec +#define atomic_fetch_dec_relaxed atomic_fetch_dec +#endif /* atomic_fetch_dec */ + +#ifndef atomic_fetch_dec +static inline int +atomic_fetch_dec (atomic_t *v) +{ +return atomic_fetch_sub (1 , v); +} +#define atomic_fetch_dec atomic_fetch_dec +#endif + +#ifndef atomic_fetch_dec_acquire +static inline int +atomic_fetch_dec_acquire (atomic_t *v) +{ +return atomic_fetch_sub_acquire (1 , v); +} +#define atomic_fetch_dec_acquire atomic_fetch_dec_acquire +#endif + +#ifndef atomic_fetch_dec_release +static inline int +atomic_fetch_dec_release (atomic_t *v) +{ +return atomic_fetch_sub_release (1 , v); +} +#define atomic_fetch_dec_release atomic_fetch_dec_release +#endif + +#ifndef atomic_fetch_dec_relaxed +static inline int +atomic_fetch_dec_relaxed (atomic_t *v) +{ +return atomic_fetch_sub_relaxed (1 , v); +} +#define atomic_fetch_dec_relaxed atomic_fetch_dec_relaxed +#endif + +#else /* atomic_fetch_dec_relaxed */ + +#ifndef atomic_fetch_dec_acquire +static inline int +atomic_fetch_dec_acquire (atomic_t *v) +{ +int ret =atomic_fetch_dec_relaxed (v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic_fetch_dec_acquire atomic_fetch_dec_acquire +#endif + +#ifndef atomic_fetch_dec_release +static inline int +atomic_fetch_dec_release (atomic_t *v) +{ +__atomic_mb__before_release (); +return atomic_fetch_dec_relaxed (v); +} +#define atomic_fetch_dec_release atomic_fetch_dec_release +#endif + +#ifndef atomic_fetch_dec +static inline int +atomic_fetch_dec (atomic_t *v) +{ +int ret; +__atomic_mb__before_fence (); + ret =atomic_fetch_dec_relaxed (v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic_fetch_dec atomic_fetch_dec +#endif + +#endif /* atomic_fetch_dec_relaxed */ + +#ifndef atomic_fetch_and_relaxed +#define atomic_fetch_and_acquire atomic_fetch_and +#define atomic_fetch_and_release atomic_fetch_and +#define atomic_fetch_and_relaxed atomic_fetch_and +#else /* atomic_fetch_and_relaxed */ + +#ifndef atomic_fetch_and_acquire +static inline int +atomic_fetch_and_acquire (int i,atomic_t *v) +{ +int ret =atomic_fetch_and_relaxed (i, v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic_fetch_and_acquire atomic_fetch_and_acquire +#endif + +#ifndef atomic_fetch_and_release +static inline int +atomic_fetch_and_release (int i,atomic_t *v) +{ +__atomic_mb__before_release (); +return atomic_fetch_and_relaxed (i, v); +} +#define atomic_fetch_and_release atomic_fetch_and_release +#endif + +#ifndef atomic_fetch_and +static inline int +atomic_fetch_and (int i,atomic_t *v) +{ +int ret; +__atomic_mb__before_fence (); + ret =atomic_fetch_and_relaxed (i, v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic_fetch_and atomic_fetch_and +#endif + +#endif /* atomic_fetch_and_relaxed */ + +#ifndef atomic_andnot +static inline void +atomic_andnot (int i,atomic_t *v) +{ +atomic_and (~i, v); +} +#define atomic_andnot atomic_andnot +#endif + +#ifndef atomic_fetch_andnot_relaxed +#ifdef atomic_fetch_andnot +#define atomic_fetch_andnot_acquire atomic_fetch_andnot +#define atomic_fetch_andnot_release atomic_fetch_andnot +#define atomic_fetch_andnot_relaxed atomic_fetch_andnot +#endif /* atomic_fetch_andnot */ + +#ifndef atomic_fetch_andnot +static inline int +atomic_fetch_andnot (int i,atomic_t *v) +{ +return atomic_fetch_and (~i, v); +} +#define atomic_fetch_andnot atomic_fetch_andnot +#endif + +#ifndef atomic_fetch_andnot_acquire +static inline int +atomic_fetch_andnot_acquire (int i,atomic_t *v) +{ +return atomic_fetch_and_acquire (~i, v); +} +#define atomic_fetch_andnot_acquire atomic_fetch_andnot_acquire +#endif + +#ifndef atomic_fetch_andnot_release +static inline int +atomic_fetch_andnot_release (int i,atomic_t *v) +{ +return atomic_fetch_and_release (~i, v); +} +#define atomic_fetch_andnot_release atomic_fetch_andnot_release +#endif + +#ifndef atomic_fetch_andnot_relaxed +static inline int +atomic_fetch_andnot_relaxed (int i,atomic_t *v) +{ +return atomic_fetch_and_relaxed (~i, v); +} +#define atomic_fetch_andnot_relaxed atomic_fetch_andnot_relaxed +#endif + +#else /* atomic_fetch_andnot_relaxed */ + +#ifndef atomic_fetch_andnot_acquire +static inline int +atomic_fetch_andnot_acquire (int i,atomic_t *v) +{ +int ret =atomic_fetch_andnot_relaxed (i, v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic_fetch_andnot_acquire atomic_fetch_andnot_acquire +#endif + +#ifndef atomic_fetch_andnot_release +static inline int +atomic_fetch_andnot_release (int i,atomic_t *v) +{ +__atomic_mb__before_release (); +return atomic_fetch_andnot_relaxed (i, v); +} +#define atomic_fetch_andnot_release atomic_fetch_andnot_release +#endif + +#ifndef atomic_fetch_andnot +static inline int +atomic_fetch_andnot (int i,atomic_t *v) +{ +int ret; +__atomic_mb__before_fence (); + ret =atomic_fetch_andnot_relaxed (i, v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic_fetch_andnot atomic_fetch_andnot +#endif + +#endif /* atomic_fetch_andnot_relaxed */ + +#ifndef atomic_fetch_or_relaxed +#define atomic_fetch_or_acquire atomic_fetch_or +#define atomic_fetch_or_release atomic_fetch_or +#define atomic_fetch_or_relaxed atomic_fetch_or +#else /* atomic_fetch_or_relaxed */ + +#ifndef atomic_fetch_or_acquire +static inline int +atomic_fetch_or_acquire (int i,atomic_t *v) +{ +int ret =atomic_fetch_or_relaxed (i, v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic_fetch_or_acquire atomic_fetch_or_acquire +#endif + +#ifndef atomic_fetch_or_release +static inline int +atomic_fetch_or_release (int i,atomic_t *v) +{ +__atomic_mb__before_release (); +return atomic_fetch_or_relaxed (i, v); +} +#define atomic_fetch_or_release atomic_fetch_or_release +#endif + +#ifndef atomic_fetch_or +static inline int +atomic_fetch_or (int i,atomic_t *v) +{ +int ret; +__atomic_mb__before_fence (); + ret =atomic_fetch_or_relaxed (i, v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic_fetch_or atomic_fetch_or +#endif + +#endif /* atomic_fetch_or_relaxed */ + +#ifndef atomic_fetch_xor_relaxed +#define atomic_fetch_xor_acquire atomic_fetch_xor +#define atomic_fetch_xor_release atomic_fetch_xor +#define atomic_fetch_xor_relaxed atomic_fetch_xor +#else /* atomic_fetch_xor_relaxed */ + +#ifndef atomic_fetch_xor_acquire +static inline int +atomic_fetch_xor_acquire (int i,atomic_t *v) +{ +int ret =atomic_fetch_xor_relaxed (i, v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic_fetch_xor_acquire atomic_fetch_xor_acquire +#endif + +#ifndef atomic_fetch_xor_release +static inline int +atomic_fetch_xor_release (int i,atomic_t *v) +{ +__atomic_mb__before_release (); +return atomic_fetch_xor_relaxed (i, v); +} +#define atomic_fetch_xor_release atomic_fetch_xor_release +#endif + +#ifndef atomic_fetch_xor +static inline int +atomic_fetch_xor (int i,atomic_t *v) +{ +int ret; +__atomic_mb__before_fence (); + ret =atomic_fetch_xor_relaxed (i, v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic_fetch_xor atomic_fetch_xor +#endif + +#endif /* atomic_fetch_xor_relaxed */ + +#ifndef atomic_xchg_relaxed +#define atomic_xchg_acquire atomic_xchg +#define atomic_xchg_release atomic_xchg +#define atomic_xchg_relaxed atomic_xchg +#else /* atomic_xchg_relaxed */ + +#ifndef atomic_xchg_acquire +static inline int +atomic_xchg_acquire (atomic_t *v,int i) +{ +int ret =atomic_xchg_relaxed (v, i); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic_xchg_acquire atomic_xchg_acquire +#endif + +#ifndef atomic_xchg_release +static inline int +atomic_xchg_release (atomic_t *v,int i) +{ +__atomic_mb__before_release (); +return atomic_xchg_relaxed (v, i); +} +#define atomic_xchg_release atomic_xchg_release +#endif + +#ifndef atomic_xchg +static inline int +atomic_xchg (atomic_t *v,int i) +{ +int ret; +__atomic_mb__before_fence (); + ret =atomic_xchg_relaxed (v, i); +__atomic_mb__after_fence (); +return ret; +} +#define atomic_xchg atomic_xchg +#endif + +#endif /* atomic_xchg_relaxed */ + +#ifndef atomic_cmpxchg_relaxed +#define atomic_cmpxchg_acquire atomic_cmpxchg +#define atomic_cmpxchg_release atomic_cmpxchg +#define atomic_cmpxchg_relaxed atomic_cmpxchg +#else /* atomic_cmpxchg_relaxed */ + +#ifndef atomic_cmpxchg_acquire +static inline int +atomic_cmpxchg_acquire (atomic_t *v,int old,int new) +{ +int ret =atomic_cmpxchg_relaxed (v, old, new); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic_cmpxchg_acquire atomic_cmpxchg_acquire +#endif + +#ifndef atomic_cmpxchg_release +static inline int +atomic_cmpxchg_release (atomic_t *v,int old,int new) +{ +__atomic_mb__before_release (); +return atomic_cmpxchg_relaxed (v, old, new); +} +#define atomic_cmpxchg_release atomic_cmpxchg_release +#endif + +#ifndef atomic_cmpxchg +static inline int +atomic_cmpxchg (atomic_t *v,int old,int new) +{ +int ret; +__atomic_mb__before_fence (); + ret =atomic_cmpxchg_relaxed (v, old, new); +__atomic_mb__after_fence (); +return ret; +} +#define atomic_cmpxchg atomic_cmpxchg +#endif + +#endif /* atomic_cmpxchg_relaxed */ + +#ifndef atomic_try_cmpxchg_relaxed +#ifdef atomic_try_cmpxchg +#define atomic_try_cmpxchg_acquire atomic_try_cmpxchg +#define atomic_try_cmpxchg_release atomic_try_cmpxchg +#define atomic_try_cmpxchg_relaxed atomic_try_cmpxchg +#endif /* atomic_try_cmpxchg */ + +#ifndef atomic_try_cmpxchg +static inline bool +atomic_try_cmpxchg (atomic_t *v,int *old,int new) +{ +int r, o = *old; + r =atomic_cmpxchg (v, o, new); +if (unlikely (r != o)) + *old = r; +return likely (r == o); +} +#define atomic_try_cmpxchg atomic_try_cmpxchg +#endif + +#ifndef atomic_try_cmpxchg_acquire +static inline bool +atomic_try_cmpxchg_acquire (atomic_t *v,int *old,int new) +{ +int r, o = *old; + r =atomic_cmpxchg_acquire (v, o, new); +if (unlikely (r != o)) + *old = r; +return likely (r == o); +} +#define atomic_try_cmpxchg_acquire atomic_try_cmpxchg_acquire +#endif + +#ifndef atomic_try_cmpxchg_release +static inline bool +atomic_try_cmpxchg_release (atomic_t *v,int *old,int new) +{ +int r, o = *old; + r =atomic_cmpxchg_release (v, o, new); +if (unlikely (r != o)) + *old = r; +return likely (r == o); +} +#define atomic_try_cmpxchg_release atomic_try_cmpxchg_release +#endif + +#ifndef atomic_try_cmpxchg_relaxed +static inline bool +atomic_try_cmpxchg_relaxed (atomic_t *v,int *old,int new) +{ +int r, o = *old; + r =atomic_cmpxchg_relaxed (v, o, new); +if (unlikely (r != o)) + *old = r; +return likely (r == o); +} +#define atomic_try_cmpxchg_relaxed atomic_try_cmpxchg_relaxed +#endif + +#else /* atomic_try_cmpxchg_relaxed */ + +#ifndef atomic_try_cmpxchg_acquire +static inline bool +atomic_try_cmpxchg_acquire (atomic_t *v,int *old,int new) +{ +bool ret =atomic_try_cmpxchg_relaxed (v, old, new); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic_try_cmpxchg_acquire atomic_try_cmpxchg_acquire +#endif + +#ifndef atomic_try_cmpxchg_release +static inline bool +atomic_try_cmpxchg_release (atomic_t *v,int *old,int new) +{ +__atomic_mb__before_release (); +return atomic_try_cmpxchg_relaxed (v, old, new); +} +#define atomic_try_cmpxchg_release atomic_try_cmpxchg_release +#endif + +#ifndef atomic_try_cmpxchg +static inline bool +atomic_try_cmpxchg (atomic_t *v,int *old,int new) +{ +bool ret; +__atomic_mb__before_fence (); + ret =atomic_try_cmpxchg_relaxed (v, old, new); +__atomic_mb__after_fence (); +return ret; +} +#define atomic_try_cmpxchg atomic_try_cmpxchg +#endif + +#endif /* atomic_try_cmpxchg_relaxed */ + +#ifndef atomic_sub_and_test +/** +* atomic_sub_and_test - subtract value from variable and test result +* @i: integer value to subtract +* @v: pointer of type atomic_t +* +* Atomically subtracts @i from @v and returns +* true if the result is zero, or false for all +* other cases. +*/ +static inline bool +atomic_sub_and_test (int i,atomic_t *v) +{ +return atomic_sub_return (i, v) ==0 ; +} +#define atomic_sub_and_test atomic_sub_and_test +#endif + +#ifndef atomic_dec_and_test +/** +* atomic_dec_and_test - decrement and test +* @v: pointer of type atomic_t +* +* Atomically decrements @v by 1 and +* returns true if the result is 0, or false for all other +* cases. +*/ +static inline bool +atomic_dec_and_test (atomic_t *v) +{ +return atomic_dec_return (v) ==0 ; +} +#define atomic_dec_and_test atomic_dec_and_test +#endif + +#ifndef atomic_inc_and_test +/** +* atomic_inc_and_test - increment and test +* @v: pointer of type atomic_t +* +* Atomically increments @v by 1 +* and returns true if the result is zero, or false for all +* other cases. +*/ +static inline bool +atomic_inc_and_test (atomic_t *v) +{ +return atomic_inc_return (v) ==0 ; +} +#define atomic_inc_and_test atomic_inc_and_test +#endif + +#ifndef atomic_add_negative +/** +* atomic_add_negative - add and test if negative +* @i: integer value to add +* @v: pointer of type atomic_t +* +* Atomically adds @i to @v and returns true +* if the result is negative, or false when +* result is greater than or equal to zero. +*/ +static inline bool +atomic_add_negative (int i,atomic_t *v) +{ +return atomic_add_return (i, v) <0 ; +} +#define atomic_add_negative atomic_add_negative +#endif + +#ifndef atomic_fetch_add_unless +/** +* atomic_fetch_add_unless - add unless the number is already a given value +* @v: pointer of type atomic_t +* @a: the amount to add to v... +* @u: ...unless v is equal to u. +* +* Atomically adds @a to @v, so long as @v was not already @u. +* Returns original value of @v +*/ +static inline int +atomic_fetch_add_unless (atomic_t *v,int a,int u) +{ +int c =atomic_read (v); + +do { +if (unlikely (c == u)) +break ; + }while (!atomic_try_cmpxchg (v, &c, c + a)); + +return c; +} +#define atomic_fetch_add_unless atomic_fetch_add_unless +#endif + +#ifndef atomic_add_unless +/** +* atomic_add_unless - add unless the number is already a given value +* @v: pointer of type atomic_t +* @a: the amount to add to v... +* @u: ...unless v is equal to u. +* +* Atomically adds @a to @v, so long as @v was not already @u. +* Returns non-zero if @v was not @u, and zero otherwise. +*/ +static inline bool +atomic_add_unless (atomic_t *v,int a,int u) +{ +return atomic_fetch_add_unless (v, a, u) != u; +} +#define atomic_add_unless atomic_add_unless +#endif + +#ifndef atomic_inc_not_zero +/** +* atomic_inc_not_zero - increment unless the number is zero +* @v: pointer of type atomic_t +* +* Atomically increments @v by 1, so long as @v is non-zero. +* Returns non-zero if @v was non-zero, and zero otherwise. +*/ +static inline bool +atomic_inc_not_zero (atomic_t *v) +{ +return atomic_add_unless (v,1 ,0 ); +} +#define atomic_inc_not_zero atomic_inc_not_zero +#endif + +#ifndef atomic_inc_unless_negative +static inline bool +atomic_inc_unless_negative (atomic_t *v) +{ +int c =atomic_read (v); + +do { +if (c <0 ) +return false; + }while (!atomic_try_cmpxchg (v, &c, c +1 )); + +return true; +} +#define atomic_inc_unless_negative atomic_inc_unless_negative +#endif + +#ifndef atomic_dec_unless_positive +static inline bool +atomic_dec_unless_positive (atomic_t *v) +{ +int c =atomic_read (v); + +do { +if (c >0 ) +return false; + }while (!atomic_try_cmpxchg (v, &c, c -1 )); + +return true; +} +#define atomic_dec_unless_positive atomic_dec_unless_positive +#endif + +#ifndef atomic_dec_if_positive +static inline int +atomic_dec_if_positive (atomic_t *v) +{ +int dec, c =atomic_read (v); + +do { + dec = c -1 ; +if (dec <0 ) +break ; + }while (!atomic_try_cmpxchg (v, &c, dec)); + +return dec; +} +#define atomic_dec_if_positive atomic_dec_if_positive +#endif + +#define atomic_cond_read_acquire (v, c) smp_cond_load_acquire(&(v)->counter, (c)) + +#ifdef CONFIG_GENERIC_ATOMIC64 +#include <asm-generic/atomic64.h> +#endif + +#ifndef atomic64_read_acquire +static inline s64 +atomic64_read_acquire (const atomic64_t *v) +{ +return smp_load_acquire (&(v)->counter); +} +#define atomic64_read_acquire atomic64_read_acquire +#endif + +#ifndef atomic64_set_release +static inline void +atomic64_set_release (atomic64_t *v,s64 i) +{ +smp_store_release (&(v)->counter, i); +} +#define atomic64_set_release atomic64_set_release +#endif + +#ifndef atomic64_add_return_relaxed +#define atomic64_add_return_acquire atomic64_add_return +#define atomic64_add_return_release atomic64_add_return +#define atomic64_add_return_relaxed atomic64_add_return +#else /* atomic64_add_return_relaxed */ + +#ifndef atomic64_add_return_acquire +static inline s64 +atomic64_add_return_acquire (s64 i,atomic64_t *v) +{ +s64 ret =atomic64_add_return_relaxed (i, v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic64_add_return_acquire atomic64_add_return_acquire +#endif + +#ifndef atomic64_add_return_release +static inline s64 +atomic64_add_return_release (s64 i,atomic64_t *v) +{ +__atomic_mb__before_release (); +return atomic64_add_return_relaxed (i, v); +} +#define atomic64_add_return_release atomic64_add_return_release +#endif + +#ifndef atomic64_add_return +static inline s64 +atomic64_add_return (s64 i,atomic64_t *v) +{ +s64 ret; +__atomic_mb__before_fence (); + ret =atomic64_add_return_relaxed (i, v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic64_add_return atomic64_add_return +#endif + +#endif /* atomic64_add_return_relaxed */ + +#ifndef atomic64_fetch_add_relaxed +#define atomic64_fetch_add_acquire atomic64_fetch_add +#define atomic64_fetch_add_release atomic64_fetch_add +#define atomic64_fetch_add_relaxed atomic64_fetch_add +#else /* atomic64_fetch_add_relaxed */ + +#ifndef atomic64_fetch_add_acquire +static inline s64 +atomic64_fetch_add_acquire (s64 i,atomic64_t *v) +{ +s64 ret =atomic64_fetch_add_relaxed (i, v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic64_fetch_add_acquire atomic64_fetch_add_acquire +#endif + +#ifndef atomic64_fetch_add_release +static inline s64 +atomic64_fetch_add_release (s64 i,atomic64_t *v) +{ +__atomic_mb__before_release (); +return atomic64_fetch_add_relaxed (i, v); +} +#define atomic64_fetch_add_release atomic64_fetch_add_release +#endif + +#ifndef atomic64_fetch_add +static inline s64 +atomic64_fetch_add (s64 i,atomic64_t *v) +{ +s64 ret; +__atomic_mb__before_fence (); + ret =atomic64_fetch_add_relaxed (i, v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic64_fetch_add atomic64_fetch_add +#endif + +#endif /* atomic64_fetch_add_relaxed */ + +#ifndef atomic64_sub_return_relaxed +#define atomic64_sub_return_acquire atomic64_sub_return +#define atomic64_sub_return_release atomic64_sub_return +#define atomic64_sub_return_relaxed atomic64_sub_return +#else /* atomic64_sub_return_relaxed */ + +#ifndef atomic64_sub_return_acquire +static inline s64 +atomic64_sub_return_acquire (s64 i,atomic64_t *v) +{ +s64 ret =atomic64_sub_return_relaxed (i, v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic64_sub_return_acquire atomic64_sub_return_acquire +#endif + +#ifndef atomic64_sub_return_release +static inline s64 +atomic64_sub_return_release (s64 i,atomic64_t *v) +{ +__atomic_mb__before_release (); +return atomic64_sub_return_relaxed (i, v); +} +#define atomic64_sub_return_release atomic64_sub_return_release +#endif + +#ifndef atomic64_sub_return +static inline s64 +atomic64_sub_return (s64 i,atomic64_t *v) +{ +s64 ret; +__atomic_mb__before_fence (); + ret =atomic64_sub_return_relaxed (i, v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic64_sub_return atomic64_sub_return +#endif + +#endif /* atomic64_sub_return_relaxed */ + +#ifndef atomic64_fetch_sub_relaxed +#define atomic64_fetch_sub_acquire atomic64_fetch_sub +#define atomic64_fetch_sub_release atomic64_fetch_sub +#define atomic64_fetch_sub_relaxed atomic64_fetch_sub +#else /* atomic64_fetch_sub_relaxed */ + +#ifndef atomic64_fetch_sub_acquire +static inline s64 +atomic64_fetch_sub_acquire (s64 i,atomic64_t *v) +{ +s64 ret =atomic64_fetch_sub_relaxed (i, v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic64_fetch_sub_acquire atomic64_fetch_sub_acquire +#endif + +#ifndef atomic64_fetch_sub_release +static inline s64 +atomic64_fetch_sub_release (s64 i,atomic64_t *v) +{ +__atomic_mb__before_release (); +return atomic64_fetch_sub_relaxed (i, v); +} +#define atomic64_fetch_sub_release atomic64_fetch_sub_release +#endif + +#ifndef atomic64_fetch_sub +static inline s64 +atomic64_fetch_sub (s64 i,atomic64_t *v) +{ +s64 ret; +__atomic_mb__before_fence (); + ret =atomic64_fetch_sub_relaxed (i, v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic64_fetch_sub atomic64_fetch_sub +#endif + +#endif /* atomic64_fetch_sub_relaxed */ + +#ifndef atomic64_inc +static inline void +atomic64_inc (atomic64_t *v) +{ +atomic64_add (1 , v); +} +#define atomic64_inc atomic64_inc +#endif + +#ifndef atomic64_inc_return_relaxed +#ifdef atomic64_inc_return +#define atomic64_inc_return_acquire atomic64_inc_return +#define atomic64_inc_return_release atomic64_inc_return +#define atomic64_inc_return_relaxed atomic64_inc_return +#endif /* atomic64_inc_return */ + +#ifndef atomic64_inc_return +static inline s64 +atomic64_inc_return (atomic64_t *v) +{ +return atomic64_add_return (1 , v); +} +#define atomic64_inc_return atomic64_inc_return +#endif + +#ifndef atomic64_inc_return_acquire +static inline s64 +atomic64_inc_return_acquire (atomic64_t *v) +{ +return atomic64_add_return_acquire (1 , v); +} +#define atomic64_inc_return_acquire atomic64_inc_return_acquire +#endif + +#ifndef atomic64_inc_return_release +static inline s64 +atomic64_inc_return_release (atomic64_t *v) +{ +return atomic64_add_return_release (1 , v); +} +#define atomic64_inc_return_release atomic64_inc_return_release +#endif + +#ifndef atomic64_inc_return_relaxed +static inline s64 +atomic64_inc_return_relaxed (atomic64_t *v) +{ +return atomic64_add_return_relaxed (1 , v); +} +#define atomic64_inc_return_relaxed atomic64_inc_return_relaxed +#endif + +#else /* atomic64_inc_return_relaxed */ + +#ifndef atomic64_inc_return_acquire +static inline s64 +atomic64_inc_return_acquire (atomic64_t *v) +{ +s64 ret =atomic64_inc_return_relaxed (v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic64_inc_return_acquire atomic64_inc_return_acquire +#endif + +#ifndef atomic64_inc_return_release +static inline s64 +atomic64_inc_return_release (atomic64_t *v) +{ +__atomic_mb__before_release (); +return atomic64_inc_return_relaxed (v); +} +#define atomic64_inc_return_release atomic64_inc_return_release +#endif + +#ifndef atomic64_inc_return +static inline s64 +atomic64_inc_return (atomic64_t *v) +{ +s64 ret; +__atomic_mb__before_fence (); + ret =atomic64_inc_return_relaxed (v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic64_inc_return atomic64_inc_return +#endif + +#endif /* atomic64_inc_return_relaxed */ + +#ifndef atomic64_fetch_inc_relaxed +#ifdef atomic64_fetch_inc +#define atomic64_fetch_inc_acquire atomic64_fetch_inc +#define atomic64_fetch_inc_release atomic64_fetch_inc +#define atomic64_fetch_inc_relaxed atomic64_fetch_inc +#endif /* atomic64_fetch_inc */ + +#ifndef atomic64_fetch_inc +static inline s64 +atomic64_fetch_inc (atomic64_t *v) +{ +return atomic64_fetch_add (1 , v); +} +#define atomic64_fetch_inc atomic64_fetch_inc +#endif + +#ifndef atomic64_fetch_inc_acquire +static inline s64 +atomic64_fetch_inc_acquire (atomic64_t *v) +{ +return atomic64_fetch_add_acquire (1 , v); +} +#define atomic64_fetch_inc_acquire atomic64_fetch_inc_acquire +#endif + +#ifndef atomic64_fetch_inc_release +static inline s64 +atomic64_fetch_inc_release (atomic64_t *v) +{ +return atomic64_fetch_add_release (1 , v); +} +#define atomic64_fetch_inc_release atomic64_fetch_inc_release +#endif + +#ifndef atomic64_fetch_inc_relaxed +static inline s64 +atomic64_fetch_inc_relaxed (atomic64_t *v) +{ +return atomic64_fetch_add_relaxed (1 , v); +} +#define atomic64_fetch_inc_relaxed atomic64_fetch_inc_relaxed +#endif + +#else /* atomic64_fetch_inc_relaxed */ + +#ifndef atomic64_fetch_inc_acquire +static inline s64 +atomic64_fetch_inc_acquire (atomic64_t *v) +{ +s64 ret =atomic64_fetch_inc_relaxed (v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic64_fetch_inc_acquire atomic64_fetch_inc_acquire +#endif + +#ifndef atomic64_fetch_inc_release +static inline s64 +atomic64_fetch_inc_release (atomic64_t *v) +{ +__atomic_mb__before_release (); +return atomic64_fetch_inc_relaxed (v); +} +#define atomic64_fetch_inc_release atomic64_fetch_inc_release +#endif + +#ifndef atomic64_fetch_inc +static inline s64 +atomic64_fetch_inc (atomic64_t *v) +{ +s64 ret; +__atomic_mb__before_fence (); + ret =atomic64_fetch_inc_relaxed (v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic64_fetch_inc atomic64_fetch_inc +#endif + +#endif /* atomic64_fetch_inc_relaxed */ + +#ifndef atomic64_dec +static inline void +atomic64_dec (atomic64_t *v) +{ +atomic64_sub (1 , v); +} +#define atomic64_dec atomic64_dec +#endif + +#ifndef atomic64_dec_return_relaxed +#ifdef atomic64_dec_return +#define atomic64_dec_return_acquire atomic64_dec_return +#define atomic64_dec_return_release atomic64_dec_return +#define atomic64_dec_return_relaxed atomic64_dec_return +#endif /* atomic64_dec_return */ + +#ifndef atomic64_dec_return +static inline s64 +atomic64_dec_return (atomic64_t *v) +{ +return atomic64_sub_return (1 , v); +} +#define atomic64_dec_return atomic64_dec_return +#endif + +#ifndef atomic64_dec_return_acquire +static inline s64 +atomic64_dec_return_acquire (atomic64_t *v) +{ +return atomic64_sub_return_acquire (1 , v); +} +#define atomic64_dec_return_acquire atomic64_dec_return_acquire +#endif + +#ifndef atomic64_dec_return_release +static inline s64 +atomic64_dec_return_release (atomic64_t *v) +{ +return atomic64_sub_return_release (1 , v); +} +#define atomic64_dec_return_release atomic64_dec_return_release +#endif + +#ifndef atomic64_dec_return_relaxed +static inline s64 +atomic64_dec_return_relaxed (atomic64_t *v) +{ +return atomic64_sub_return_relaxed (1 , v); +} +#define atomic64_dec_return_relaxed atomic64_dec_return_relaxed +#endif + +#else /* atomic64_dec_return_relaxed */ + +#ifndef atomic64_dec_return_acquire +static inline s64 +atomic64_dec_return_acquire (atomic64_t *v) +{ +s64 ret =atomic64_dec_return_relaxed (v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic64_dec_return_acquire atomic64_dec_return_acquire +#endif + +#ifndef atomic64_dec_return_release +static inline s64 +atomic64_dec_return_release (atomic64_t *v) +{ +__atomic_mb__before_release (); +return atomic64_dec_return_relaxed (v); +} +#define atomic64_dec_return_release atomic64_dec_return_release +#endif + +#ifndef atomic64_dec_return +static inline s64 +atomic64_dec_return (atomic64_t *v) +{ +s64 ret; +__atomic_mb__before_fence (); + ret =atomic64_dec_return_relaxed (v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic64_dec_return atomic64_dec_return +#endif + +#endif /* atomic64_dec_return_relaxed */ + +#ifndef atomic64_fetch_dec_relaxed +#ifdef atomic64_fetch_dec +#define atomic64_fetch_dec_acquire atomic64_fetch_dec +#define atomic64_fetch_dec_release atomic64_fetch_dec +#define atomic64_fetch_dec_relaxed atomic64_fetch_dec +#endif /* atomic64_fetch_dec */ + +#ifndef atomic64_fetch_dec +static inline s64 +atomic64_fetch_dec (atomic64_t *v) +{ +return atomic64_fetch_sub (1 , v); +} +#define atomic64_fetch_dec atomic64_fetch_dec +#endif + +#ifndef atomic64_fetch_dec_acquire +static inline s64 +atomic64_fetch_dec_acquire (atomic64_t *v) +{ +return atomic64_fetch_sub_acquire (1 , v); +} +#define atomic64_fetch_dec_acquire atomic64_fetch_dec_acquire +#endif + +#ifndef atomic64_fetch_dec_release +static inline s64 +atomic64_fetch_dec_release (atomic64_t *v) +{ +return atomic64_fetch_sub_release (1 , v); +} +#define atomic64_fetch_dec_release atomic64_fetch_dec_release +#endif + +#ifndef atomic64_fetch_dec_relaxed +static inline s64 +atomic64_fetch_dec_relaxed (atomic64_t *v) +{ +return atomic64_fetch_sub_relaxed (1 , v); +} +#define atomic64_fetch_dec_relaxed atomic64_fetch_dec_relaxed +#endif + +#else /* atomic64_fetch_dec_relaxed */ + +#ifndef atomic64_fetch_dec_acquire +static inline s64 +atomic64_fetch_dec_acquire (atomic64_t *v) +{ +s64 ret =atomic64_fetch_dec_relaxed (v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic64_fetch_dec_acquire atomic64_fetch_dec_acquire +#endif + +#ifndef atomic64_fetch_dec_release +static inline s64 +atomic64_fetch_dec_release (atomic64_t *v) +{ +__atomic_mb__before_release (); +return atomic64_fetch_dec_relaxed (v); +} +#define atomic64_fetch_dec_release atomic64_fetch_dec_release +#endif + +#ifndef atomic64_fetch_dec +static inline s64 +atomic64_fetch_dec (atomic64_t *v) +{ +s64 ret; +__atomic_mb__before_fence (); + ret =atomic64_fetch_dec_relaxed (v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic64_fetch_dec atomic64_fetch_dec +#endif + +#endif /* atomic64_fetch_dec_relaxed */ + +#ifndef atomic64_fetch_and_relaxed +#define atomic64_fetch_and_acquire atomic64_fetch_and +#define atomic64_fetch_and_release atomic64_fetch_and +#define atomic64_fetch_and_relaxed atomic64_fetch_and +#else /* atomic64_fetch_and_relaxed */ + +#ifndef atomic64_fetch_and_acquire +static inline s64 +atomic64_fetch_and_acquire (s64 i,atomic64_t *v) +{ +s64 ret =atomic64_fetch_and_relaxed (i, v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic64_fetch_and_acquire atomic64_fetch_and_acquire +#endif + +#ifndef atomic64_fetch_and_release +static inline s64 +atomic64_fetch_and_release (s64 i,atomic64_t *v) +{ +__atomic_mb__before_release (); +return atomic64_fetch_and_relaxed (i, v); +} +#define atomic64_fetch_and_release atomic64_fetch_and_release +#endif + +#ifndef atomic64_fetch_and +static inline s64 +atomic64_fetch_and (s64 i,atomic64_t *v) +{ +s64 ret; +__atomic_mb__before_fence (); + ret =atomic64_fetch_and_relaxed (i, v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic64_fetch_and atomic64_fetch_and +#endif + +#endif /* atomic64_fetch_and_relaxed */ + +#ifndef atomic64_andnot +static inline void +atomic64_andnot (s64 i,atomic64_t *v) +{ +atomic64_and (~i, v); +} +#define atomic64_andnot atomic64_andnot +#endif + +#ifndef atomic64_fetch_andnot_relaxed +#ifdef atomic64_fetch_andnot +#define atomic64_fetch_andnot_acquire atomic64_fetch_andnot +#define atomic64_fetch_andnot_release atomic64_fetch_andnot +#define atomic64_fetch_andnot_relaxed atomic64_fetch_andnot +#endif /* atomic64_fetch_andnot */ + +#ifndef atomic64_fetch_andnot +static inline s64 +atomic64_fetch_andnot (s64 i,atomic64_t *v) +{ +return atomic64_fetch_and (~i, v); +} +#define atomic64_fetch_andnot atomic64_fetch_andnot +#endif + +#ifndef atomic64_fetch_andnot_acquire +static inline s64 +atomic64_fetch_andnot_acquire (s64 i,atomic64_t *v) +{ +return atomic64_fetch_and_acquire (~i, v); +} +#define atomic64_fetch_andnot_acquire atomic64_fetch_andnot_acquire +#endif + +#ifndef atomic64_fetch_andnot_release +static inline s64 +atomic64_fetch_andnot_release (s64 i,atomic64_t *v) +{ +return atomic64_fetch_and_release (~i, v); +} +#define atomic64_fetch_andnot_release atomic64_fetch_andnot_release +#endif + +#ifndef atomic64_fetch_andnot_relaxed +static inline s64 +atomic64_fetch_andnot_relaxed (s64 i,atomic64_t *v) +{ +return atomic64_fetch_and_relaxed (~i, v); +} +#define atomic64_fetch_andnot_relaxed atomic64_fetch_andnot_relaxed +#endif + +#else /* atomic64_fetch_andnot_relaxed */ + +#ifndef atomic64_fetch_andnot_acquire +static inline s64 +atomic64_fetch_andnot_acquire (s64 i,atomic64_t *v) +{ +s64 ret =atomic64_fetch_andnot_relaxed (i, v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic64_fetch_andnot_acquire atomic64_fetch_andnot_acquire +#endif + +#ifndef atomic64_fetch_andnot_release +static inline s64 +atomic64_fetch_andnot_release (s64 i,atomic64_t *v) +{ +__atomic_mb__before_release (); +return atomic64_fetch_andnot_relaxed (i, v); +} +#define atomic64_fetch_andnot_release atomic64_fetch_andnot_release +#endif + +#ifndef atomic64_fetch_andnot +static inline s64 +atomic64_fetch_andnot (s64 i,atomic64_t *v) +{ +s64 ret; +__atomic_mb__before_fence (); + ret =atomic64_fetch_andnot_relaxed (i, v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic64_fetch_andnot atomic64_fetch_andnot +#endif + +#endif /* atomic64_fetch_andnot_relaxed */ + +#ifndef atomic64_fetch_or_relaxed +#define atomic64_fetch_or_acquire atomic64_fetch_or +#define atomic64_fetch_or_release atomic64_fetch_or +#define atomic64_fetch_or_relaxed atomic64_fetch_or +#else /* atomic64_fetch_or_relaxed */ + +#ifndef atomic64_fetch_or_acquire +static inline s64 +atomic64_fetch_or_acquire (s64 i,atomic64_t *v) +{ +s64 ret =atomic64_fetch_or_relaxed (i, v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic64_fetch_or_acquire atomic64_fetch_or_acquire +#endif + +#ifndef atomic64_fetch_or_release +static inline s64 +atomic64_fetch_or_release (s64 i,atomic64_t *v) +{ +__atomic_mb__before_release (); +return atomic64_fetch_or_relaxed (i, v); +} +#define atomic64_fetch_or_release atomic64_fetch_or_release +#endif + +#ifndef atomic64_fetch_or +static inline s64 +atomic64_fetch_or (s64 i,atomic64_t *v) +{ +s64 ret; +__atomic_mb__before_fence (); + ret =atomic64_fetch_or_relaxed (i, v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic64_fetch_or atomic64_fetch_or +#endif + +#endif /* atomic64_fetch_or_relaxed */ + +#ifndef atomic64_fetch_xor_relaxed +#define atomic64_fetch_xor_acquire atomic64_fetch_xor +#define atomic64_fetch_xor_release atomic64_fetch_xor +#define atomic64_fetch_xor_relaxed atomic64_fetch_xor +#else /* atomic64_fetch_xor_relaxed */ + +#ifndef atomic64_fetch_xor_acquire +static inline s64 +atomic64_fetch_xor_acquire (s64 i,atomic64_t *v) +{ +s64 ret =atomic64_fetch_xor_relaxed (i, v); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic64_fetch_xor_acquire atomic64_fetch_xor_acquire +#endif + +#ifndef atomic64_fetch_xor_release +static inline s64 +atomic64_fetch_xor_release (s64 i,atomic64_t *v) +{ +__atomic_mb__before_release (); +return atomic64_fetch_xor_relaxed (i, v); +} +#define atomic64_fetch_xor_release atomic64_fetch_xor_release +#endif + +#ifndef atomic64_fetch_xor +static inline s64 +atomic64_fetch_xor (s64 i,atomic64_t *v) +{ +s64 ret; +__atomic_mb__before_fence (); + ret =atomic64_fetch_xor_relaxed (i, v); +__atomic_mb__after_fence (); +return ret; +} +#define atomic64_fetch_xor atomic64_fetch_xor +#endif + +#endif /* atomic64_fetch_xor_relaxed */ + +#ifndef atomic64_xchg_relaxed +#define atomic64_xchg_acquire atomic64_xchg +#define atomic64_xchg_release atomic64_xchg +#define atomic64_xchg_relaxed atomic64_xchg +#else /* atomic64_xchg_relaxed */ + +#ifndef atomic64_xchg_acquire +static inline s64 +atomic64_xchg_acquire (atomic64_t *v,s64 i) +{ +s64 ret =atomic64_xchg_relaxed (v, i); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic64_xchg_acquire atomic64_xchg_acquire +#endif + +#ifndef atomic64_xchg_release +static inline s64 +atomic64_xchg_release (atomic64_t *v,s64 i) +{ +__atomic_mb__before_release (); +return atomic64_xchg_relaxed (v, i); +} +#define atomic64_xchg_release atomic64_xchg_release +#endif + +#ifndef atomic64_xchg +static inline s64 +atomic64_xchg (atomic64_t *v,s64 i) +{ +s64 ret; +__atomic_mb__before_fence (); + ret =atomic64_xchg_relaxed (v, i); +__atomic_mb__after_fence (); +return ret; +} +#define atomic64_xchg atomic64_xchg +#endif + +#endif /* atomic64_xchg_relaxed */ + +#ifndef atomic64_cmpxchg_relaxed +#define atomic64_cmpxchg_acquire atomic64_cmpxchg +#define atomic64_cmpxchg_release atomic64_cmpxchg +#define atomic64_cmpxchg_relaxed atomic64_cmpxchg +#else /* atomic64_cmpxchg_relaxed */ + +#ifndef atomic64_cmpxchg_acquire +static inline s64 +atomic64_cmpxchg_acquire (atomic64_t *v,s64 old,s64 new) +{ +s64 ret =atomic64_cmpxchg_relaxed (v, old, new); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic64_cmpxchg_acquire atomic64_cmpxchg_acquire +#endif + +#ifndef atomic64_cmpxchg_release +static inline s64 +atomic64_cmpxchg_release (atomic64_t *v,s64 old,s64 new) +{ +__atomic_mb__before_release (); +return atomic64_cmpxchg_relaxed (v, old, new); +} +#define atomic64_cmpxchg_release atomic64_cmpxchg_release +#endif + +#ifndef atomic64_cmpxchg +static inline s64 +atomic64_cmpxchg (atomic64_t *v,s64 old,s64 new) +{ +s64 ret; +__atomic_mb__before_fence (); + ret =atomic64_cmpxchg_relaxed (v, old, new); +__atomic_mb__after_fence (); +return ret; +} +#define atomic64_cmpxchg atomic64_cmpxchg +#endif + +#endif /* atomic64_cmpxchg_relaxed */ + +#ifndef atomic64_try_cmpxchg_relaxed +#ifdef atomic64_try_cmpxchg +#define atomic64_try_cmpxchg_acquire atomic64_try_cmpxchg +#define atomic64_try_cmpxchg_release atomic64_try_cmpxchg +#define atomic64_try_cmpxchg_relaxed atomic64_try_cmpxchg +#endif /* atomic64_try_cmpxchg */ + +#ifndef atomic64_try_cmpxchg +static inline bool +atomic64_try_cmpxchg (atomic64_t *v,s64 *old,s64 new) +{ +s64 r, o = *old; + r =atomic64_cmpxchg (v, o, new); +if (unlikely (r != o)) + *old = r; +return likely (r == o); +} +#define atomic64_try_cmpxchg atomic64_try_cmpxchg +#endif + +#ifndef atomic64_try_cmpxchg_acquire +static inline bool +atomic64_try_cmpxchg_acquire (atomic64_t *v,s64 *old,s64 new) +{ +s64 r, o = *old; + r =atomic64_cmpxchg_acquire (v, o, new); +if (unlikely (r != o)) + *old = r; +return likely (r == o); +} +#define atomic64_try_cmpxchg_acquire atomic64_try_cmpxchg_acquire +#endif + +#ifndef atomic64_try_cmpxchg_release +static inline bool +atomic64_try_cmpxchg_release (atomic64_t *v,s64 *old,s64 new) +{ +s64 r, o = *old; + r =atomic64_cmpxchg_release (v, o, new); +if (unlikely (r != o)) + *old = r; +return likely (r == o); +} +#define atomic64_try_cmpxchg_release atomic64_try_cmpxchg_release +#endif + +#ifndef atomic64_try_cmpxchg_relaxed +static inline bool +atomic64_try_cmpxchg_relaxed (atomic64_t *v,s64 *old,s64 new) +{ +s64 r, o = *old; + r =atomic64_cmpxchg_relaxed (v, o, new); +if (unlikely (r != o)) + *old = r; +return likely (r == o); +} +#define atomic64_try_cmpxchg_relaxed atomic64_try_cmpxchg_relaxed +#endif + +#else /* atomic64_try_cmpxchg_relaxed */ + +#ifndef atomic64_try_cmpxchg_acquire +static inline bool +atomic64_try_cmpxchg_acquire (atomic64_t *v,s64 *old,s64 new) +{ +bool ret =atomic64_try_cmpxchg_relaxed (v, old, new); +__atomic_mb__after_acquire (); +return ret; +} +#define atomic64_try_cmpxchg_acquire atomic64_try_cmpxchg_acquire +#endif + +#ifndef atomic64_try_cmpxchg_release +static inline bool +atomic64_try_cmpxchg_release (atomic64_t *v,s64 *old,s64 new) +{ +__atomic_mb__before_release (); +return atomic64_try_cmpxchg_relaxed (v, old, new); +} +#define atomic64_try_cmpxchg_release atomic64_try_cmpxchg_release +#endif + +#ifndef atomic64_try_cmpxchg +static inline bool +atomic64_try_cmpxchg (atomic64_t *v,s64 *old,s64 new) +{ +bool ret; +__atomic_mb__before_fence (); + ret =atomic64_try_cmpxchg_relaxed (v, old, new); +__atomic_mb__after_fence (); +return ret; +} +#define atomic64_try_cmpxchg atomic64_try_cmpxchg +#endif + +#endif /* atomic64_try_cmpxchg_relaxed */ + +#ifndef atomic64_sub_and_test +/** +* atomic64_sub_and_test - subtract value from variable and test result +* @i: integer value to subtract +* @v: pointer of type atomic64_t +* +* Atomically subtracts @i from @v and returns +* true if the result is zero, or false for all +* other cases. +*/ +static inline bool +atomic64_sub_and_test (s64 i,atomic64_t *v) +{ +return atomic64_sub_return (i, v) ==0 ; +} +#define atomic64_sub_and_test atomic64_sub_and_test +#endif + +#ifndef atomic64_dec_and_test +/** +* atomic64_dec_and_test - decrement and test +* @v: pointer of type atomic64_t +* +* Atomically decrements @v by 1 and +* returns true if the result is 0, or false for all other +* cases. +*/ +static inline bool +atomic64_dec_and_test (atomic64_t *v) +{ +return atomic64_dec_return (v) ==0 ; +} +#define atomic64_dec_and_test atomic64_dec_and_test +#endif + +#ifndef atomic64_inc_and_test +/** +* atomic64_inc_and_test - increment and test +* @v: pointer of type atomic64_t +* +* Atomically increments @v by 1 +* and returns true if the result is zero, or false for all +* other cases. +*/ +static inline bool +atomic64_inc_and_test (atomic64_t *v) +{ +return atomic64_inc_return (v) ==0 ; +} +#define atomic64_inc_and_test atomic64_inc_and_test +#endif + +#ifndef atomic64_add_negative +/** +* atomic64_add_negative - add and test if negative +* @i: integer value to add +* @v: pointer of type atomic64_t +* +* Atomically adds @i to @v and returns true +* if the result is negative, or false when +* result is greater than or equal to zero. +*/ +static inline bool +atomic64_add_negative (s64 i,atomic64_t *v) +{ +return atomic64_add_return (i, v) <0 ; +} +#define atomic64_add_negative atomic64_add_negative +#endif + +#ifndef atomic64_fetch_add_unless +/** +* atomic64_fetch_add_unless - add unless the number is already a given value +* @v: pointer of type atomic64_t +* @a: the amount to add to v... +* @u: ...unless v is equal to u. +* +* Atomically adds @a to @v, so long as @v was not already @u. +* Returns original value of @v +*/ +static inline s64 +atomic64_fetch_add_unless (atomic64_t *v,s64 a,s64 u) +{ +s64 c =atomic64_read (v); + +do { +if (unlikely (c == u)) +break ; + }while (!atomic64_try_cmpxchg (v, &c, c + a)); + +return c; +} +#define atomic64_fetch_add_unless atomic64_fetch_add_unless +#endif + +#ifndef atomic64_add_unless +/** +* atomic64_add_unless - add unless the number is already a given value +* @v: pointer of type atomic64_t +* @a: the amount to add to v... +* @u: ...unless v is equal to u. +* +* Atomically adds @a to @v, so long as @v was not already @u. +* Returns non-zero if @v was not @u, and zero otherwise. +*/ +static inline bool +atomic64_add_unless (atomic64_t *v,s64 a,s64 u) +{ +return atomic64_fetch_add_unless (v, a, u) != u; +} +#define atomic64_add_unless atomic64_add_unless +#endif + +#ifndef atomic64_inc_not_zero +/** +* atomic64_inc_not_zero - increment unless the number is zero +* @v: pointer of type atomic64_t +* +* Atomically increments @v by 1, so long as @v is non-zero. +* Returns non-zero if @v was non-zero, and zero otherwise. +*/ +static inline bool +atomic64_inc_not_zero (atomic64_t *v) +{ +return atomic64_add_unless (v,1 ,0 ); +} +#define atomic64_inc_not_zero atomic64_inc_not_zero +#endif + +#ifndef atomic64_inc_unless_negative +static inline bool +atomic64_inc_unless_negative (atomic64_t *v) +{ +s64 c =atomic64_read (v); + +do { +if (c <0 ) +return false; + }while (!atomic64_try_cmpxchg (v, &c, c +1 )); + +return true; +} +#define atomic64_inc_unless_negative atomic64_inc_unless_negative +#endif + +#ifndef atomic64_dec_unless_positive +static inline bool +atomic64_dec_unless_positive (atomic64_t *v) +{ +s64 c =atomic64_read (v); + +do { +if (c >0 ) +return false; + }while (!atomic64_try_cmpxchg (v, &c, c -1 )); + +return true; +} +#define atomic64_dec_unless_positive atomic64_dec_unless_positive +#endif + +#ifndef atomic64_dec_if_positive +static inline s64 +atomic64_dec_if_positive (atomic64_t *v) +{ +s64 dec, c =atomic64_read (v); + +do { + dec = c -1 ; +if (dec <0 ) +break ; + }while (!atomic64_try_cmpxchg (v, &c, dec)); + +return dec; +} +#define atomic64_dec_if_positive atomic64_dec_if_positive +#endif + +#define atomic64_cond_read_acquire (v, c) smp_cond_load_acquire(&(v)->counter, (c)) + +#endif /* _LINUX_ATOMIC_FALLBACK_H */
include/linux/atomic.h +1 -1205
777 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.11.0
Part of the diff is not shown here. View the raw message.
Mark Rutland
reviewerPATCH 6/7 atomics: switch to generated atomic-long
In reply to Mark RutlandAs a step towards ensuring the atomic* APIs are consistent, let's switch to wrappers generated by gen-atomic-long.h, using the same table that gen-atomic-fallbacks.h uses to fill in gaps in the atomic_* and atomic64_* APIs.
These are checked in rather than generated with Kbuild, since:
* This allows inspection of the atomics with git grep and ctags on a pristine tree, which Linus strongly prefers being able to do.
* The fallbacks are not expected to change very often, and are not affected by machine details or configuration options, so regenerating them for *every* build is somewhat wasteful.
* These are included by files required *very* early in the build process (e.g. for generating bounds.h), and we'd rather not complicate the top-level Kbuild file.
Other than *_INIT() and *_cond_read_acquire(), all API functions are implemented as static inline C functions, ensuring consistent type promotion and/or truncation without requiring explicit casts to be applied to parameters or return values.
Since we typedef atomic_long_t to either atomic_t or atomic64_t, we know these types are equivalent, and don't require explicit casts between them. However, as the try_cmpxchg*() functions take a pointer for the 'old' parameter, which may be an int or s64, an explicit cast is generated for this.
There should be no functional change as a result of this patch (i.e. existing code should not be affected). However, this introduces a number of functions into the atomic_long_* API, bringing it into line with the atomic_* and atomic64_* APIs.
--- include/asm-generic/atomic-long.h | 1150 ++++++++++++++++++++++++++++++------- 1 file changed, 955 insertions(+), 195 deletions(-)
Note: this is generated code. Please see patch 3 for the code which generated it, along with rationale in the cover letter.
Mark.
include/asm-generic/atomic-long.h +955 -195
@@ -1,250 +1,1010 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +// SPDX-License-Identifier: GPL-2.0 + +// Generated by ./scripts/atomic/gen-atomic-long.sh +// DO NOT MODIFY THIS FILE DIRECTLY +#ifndef _ASM_GENERIC_ATOMIC_LONG_H#define _ASM_GENERIC_ATOMIC_LONG_H -/* - * Copyright (C) 2005 Silicon Graphics, Inc. - * Christoph Lameter - * - * Allows to provide arch independent atomic definitions without the need to - * edit all arch specific atomic.h files. - */#include <asm/types.h> -/* - * Suppport for atomic_long_t - * - * Casts for parameters are avoided for existing atomic functions in order to - * avoid issues with cast-as-lval under gcc 4.x and other limitations that the - * macros of a platform may have. - */ +#ifdef CONFIG_64BIT +typedef atomic64_t atomic_long_t ; +#define ATOMIC_LONG_INIT (i) ATOMIC64_INIT(i) +#define atomic_long_cond_read_acquire atomic64_cond_read_acquire +#else +typedef atomic_t atomic_long_t ; +#define ATOMIC_LONG_INIT (i) ATOMIC_INIT(i) +#define atomic_long_cond_read_acquire atomic_cond_read_acquire +#endif -#if BITS_PER_LONG == 64 +#ifdef CONFIG_64BIT -typedef atomic64_t atomic_long_t; +static inline long +atomic_long_read (const atomic_long_t *v) +{ +return atomic64_read (v); +} -#define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i) -#define ATOMIC_LONG_PFX(x) atomic64 ## x +static inline long +atomic_long_read_acquire (const atomic_long_t *v) +{ +return atomic64_read_acquire (v); +} -#else +static inline void +atomic_long_set (atomic_long_t *v,long i) +{ +atomic64_set (v, i); +} -typedef atomic_t atomic_long_t; +static inline void +atomic_long_set_release (atomic_long_t *v,long i) +{ +atomic64_set_release (v, i); +} -#define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i) -#define ATOMIC_LONG_PFX(x) atomic ## x +static inline void +atomic_long_add (long i,atomic_long_t *v) +{ +atomic64_add (i, v); +} -#endif +static inline long +atomic_long_add_return (long i,atomic_long_t *v) +{ +return atomic64_add_return (i, v); +} + +static inline long +atomic_long_add_return_acquire (long i,atomic_long_t *v) +{ +return atomic64_add_return_acquire (i, v); +} + +static inline long +atomic_long_add_return_release (long i,atomic_long_t *v) +{ +return atomic64_add_return_release (i, v); +} + +static inline long +atomic_long_add_return_relaxed (long i,atomic_long_t *v) +{ +return atomic64_add_return_relaxed (i, v); +} + +static inline long +atomic_long_fetch_add (long i,atomic_long_t *v) +{ +return atomic64_fetch_add (i, v); +} + +static inline long +atomic_long_fetch_add_acquire (long i,atomic_long_t *v) +{ +return atomic64_fetch_add_acquire (i, v); +} + +static inline long +atomic_long_fetch_add_release (long i,atomic_long_t *v) +{ +return atomic64_fetch_add_release (i, v); +} + +static inline long +atomic_long_fetch_add_relaxed (long i,atomic_long_t *v) +{ +return atomic64_fetch_add_relaxed (i, v); +} + +static inline void +atomic_long_sub (long i,atomic_long_t *v) +{ +atomic64_sub (i, v); +} + +static inline long +atomic_long_sub_return (long i,atomic_long_t *v) +{ +return atomic64_sub_return (i, v); +} + +static inline long +atomic_long_sub_return_acquire (long i,atomic_long_t *v) +{ +return atomic64_sub_return_acquire (i, v); +} + +static inline long +atomic_long_sub_return_release (long i,atomic_long_t *v) +{ +return atomic64_sub_return_release (i, v); +} + +static inline long +atomic_long_sub_return_relaxed (long i,atomic_long_t *v) +{ +return atomic64_sub_return_relaxed (i, v); +} + +static inline long +atomic_long_fetch_sub (long i,atomic_long_t *v) +{ +return atomic64_fetch_sub (i, v); +} + +static inline long +atomic_long_fetch_sub_acquire (long i,atomic_long_t *v) +{ +return atomic64_fetch_sub_acquire (i, v); +} + +static inline long +atomic_long_fetch_sub_release (long i,atomic_long_t *v) +{ +return atomic64_fetch_sub_release (i, v); +} + +static inline long +atomic_long_fetch_sub_relaxed (long i,atomic_long_t *v) +{ +return atomic64_fetch_sub_relaxed (i, v); +} + +static inline void +atomic_long_inc (atomic_long_t *v) +{ +atomic64_inc (v); +} + +static inline long +atomic_long_inc_return (atomic_long_t *v) +{ +return atomic64_inc_return (v); +} + +static inline long +atomic_long_inc_return_acquire (atomic_long_t *v) +{ +return atomic64_inc_return_acquire (v); +} + +static inline long +atomic_long_inc_return_release (atomic_long_t *v) +{ +return atomic64_inc_return_release (v); +} + +static inline long +atomic_long_inc_return_relaxed (atomic_long_t *v) +{ +return atomic64_inc_return_relaxed (v); +} + +static inline long +atomic_long_fetch_inc (atomic_long_t *v) +{ +return atomic64_fetch_inc (v); +} + +static inline long +atomic_long_fetch_inc_acquire (atomic_long_t *v) +{ +return atomic64_fetch_inc_acquire (v); +} + +static inline long +atomic_long_fetch_inc_release (atomic_long_t *v) +{ +return atomic64_fetch_inc_release (v); +} + +static inline long +atomic_long_fetch_inc_relaxed (atomic_long_t *v) +{ +return atomic64_fetch_inc_relaxed (v); +} + +static inline void +atomic_long_dec (atomic_long_t *v) +{ +atomic64_dec (v); +} + +static inline long +atomic_long_dec_return (atomic_long_t *v) +{ +return atomic64_dec_return (v); +} + +static inline long +atomic_long_dec_return_acquire (atomic_long_t *v) +{ +return atomic64_dec_return_acquire (v); +} + +static inline long +atomic_long_dec_return_release (atomic_long_t *v) +{ +return atomic64_dec_return_release (v); +} + +static inline long +atomic_long_dec_return_relaxed (atomic_long_t *v) +{ +return atomic64_dec_return_relaxed (v); +} + +static inline long +atomic_long_fetch_dec (atomic_long_t *v) +{ +return atomic64_fetch_dec (v); +} + +static inline long +atomic_long_fetch_dec_acquire (atomic_long_t *v) +{ +return atomic64_fetch_dec_acquire (v); +} + +static inline long +atomic_long_fetch_dec_release (atomic_long_t *v) +{ +return atomic64_fetch_dec_release (v); +} + +static inline long +atomic_long_fetch_dec_relaxed (atomic_long_t *v) +{ +return atomic64_fetch_dec_relaxed (v); +} + +static inline void +atomic_long_and (long i,atomic_long_t *v) +{ +atomic64_and (i, v); +} + +static inline long +atomic_long_fetch_and (long i,atomic_long_t *v) +{ +return atomic64_fetch_and (i, v); +} + +static inline long +atomic_long_fetch_and_acquire (long i,atomic_long_t *v) +{ +return atomic64_fetch_and_acquire (i, v); +} + +static inline long +atomic_long_fetch_and_release (long i,atomic_long_t *v) +{ +return atomic64_fetch_and_release (i, v); +} + +static inline long +atomic_long_fetch_and_relaxed (long i,atomic_long_t *v) +{ +return atomic64_fetch_and_relaxed (i, v); +} + +static inline void +atomic_long_andnot (long i,atomic_long_t *v) +{ +atomic64_andnot (i, v); +} + +static inline long +atomic_long_fetch_andnot (long i,atomic_long_t *v) +{ +return atomic64_fetch_andnot (i, v); +} + +static inline long +atomic_long_fetch_andnot_acquire (long i,atomic_long_t *v) +{ +return atomic64_fetch_andnot_acquire (i, v); +} + +static inline long +atomic_long_fetch_andnot_release (long i,atomic_long_t *v) +{ +return atomic64_fetch_andnot_release (i, v); +} + +static inline long +atomic_long_fetch_andnot_relaxed (long i,atomic_long_t *v) +{ +return atomic64_fetch_andnot_relaxed (i, v); +} + +static inline void +atomic_long_or (long i,atomic_long_t *v) +{ +atomic64_or (i, v); +} + +static inline long +atomic_long_fetch_or (long i,atomic_long_t *v) +{ +return atomic64_fetch_or (i, v); +} + +static inline long +atomic_long_fetch_or_acquire (long i,atomic_long_t *v) +{ +return atomic64_fetch_or_acquire (i, v); +} + +static inline long +atomic_long_fetch_or_release (long i,atomic_long_t *v) +{ +return atomic64_fetch_or_release (i, v); +} + +static inline long +atomic_long_fetch_or_relaxed (long i,atomic_long_t *v) +{ +return atomic64_fetch_or_relaxed (i, v); +} + +static inline void +atomic_long_xor (long i,atomic_long_t *v) +{ +atomic64_xor (i, v); +} -#define ATOMIC_LONG_READ_OP(mo) \ -static inline long atomic_long_read##mo(const atomic_long_t *l) \ -{ \ - ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \ - \ - return (long)ATOMIC_LONG_PFX(_read##mo)(v); \ -} -ATOMIC_LONG_READ_OP() -ATOMIC_LONG_READ_OP(_acquire) - -#undef ATOMIC_LONG_READ_OP - -#define ATOMIC_LONG_SET_OP(mo) \ -static inline void atomic_long_set##mo(atomic_long_t *l, long i) \ -{ \ - ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \ - \ - ATOMIC_LONG_PFX(_set##mo)(v, i); \ -} -ATOMIC_LONG_SET_OP() -ATOMIC_LONG_SET_OP(_release) - -#undef ATOMIC_LONG_SET_OP - -#define ATOMIC_LONG_ADD_SUB_OP(op, mo) \ -static inline long \ -atomic_long_##op##_return##mo(long i, atomic_long_t *l) \ -{ \ - ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \ - \ - return (long)ATOMIC_LONG_PFX(_##op##_return##mo)(i, v); \ -} -ATOMIC_LONG_ADD_SUB_OP(add,) -ATOMIC_LONG_ADD_SUB_OP(add, _relaxed) -ATOMIC_LONG_ADD_SUB_OP(add, _acquire) -ATOMIC_LONG_ADD_SUB_OP(add, _release) -ATOMIC_LONG_ADD_SUB_OP(sub,) -ATOMIC_LONG_ADD_SUB_OP(sub, _relaxed) -ATOMIC_LONG_ADD_SUB_OP(sub, _acquire) -ATOMIC_LONG_ADD_SUB_OP(sub, _release) - -#undef ATOMIC_LONG_ADD_SUB_OP - -#define atomic_long_cmpxchg_relaxed(l, old, new) \ - (ATOMIC_LONG_PFX(_cmpxchg_relaxed)((ATOMIC_LONG_PFX(_t) *)(l), \ - (old), (new))) -#define atomic_long_cmpxchg_acquire(l, old, new) \ - (ATOMIC_LONG_PFX(_cmpxchg_acquire)((ATOMIC_LONG_PFX(_t) *)(l), \ - (old), (new))) -#define atomic_long_cmpxchg_release(l, old, new) \ - (ATOMIC_LONG_PFX(_cmpxchg_release)((ATOMIC_LONG_PFX(_t) *)(l), \ - (old), (new))) -#define atomic_long_cmpxchg(l, old, new) \ - (ATOMIC_LONG_PFX(_cmpxchg)((ATOMIC_LONG_PFX(_t) *)(l), (old), (new))) - -#define atomic_long_xchg_relaxed(v, new) \ - (ATOMIC_LONG_PFX(_xchg_relaxed)((ATOMIC_LONG_PFX(_t) *)(v), (new))) -#define atomic_long_xchg_acquire(v, new) \ - (ATOMIC_LONG_PFX(_xchg_acquire)((ATOMIC_LONG_PFX(_t) *)(v), (new))) -#define atomic_long_xchg_release(v, new) \ - (ATOMIC_LONG_PFX(_xchg_release)((ATOMIC_LONG_PFX(_t) *)(v), (new))) -#define atomic_long_xchg(v, new) \ - (ATOMIC_LONG_PFX(_xchg)((ATOMIC_LONG_PFX(_t) *)(v), (new))) - -static __always_inline void atomic_long_inc(atomic_long_t *l) -{ - ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; - - ATOMIC_LONG_PFX(_inc)(v); +static inline long +atomic_long_fetch_xor (long i,atomic_long_t *v) +{ +return atomic64_fetch_xor (i, v); } - -static __always_inline void atomic_long_dec(atomic_long_t *l) + +static inline long +atomic_long_fetch_xor_acquire (long i,atomic_long_t *v) { - ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; +return atomic64_fetch_xor_acquire (i, v); +} - ATOMIC_LONG_PFX(_dec)(v); +static inline long +atomic_long_fetch_xor_release (long i,atomic_long_t *v) +{ +return atomic64_fetch_xor_release (i, v); } -#define ATOMIC_LONG_FETCH_OP(op, mo) \ -static inline long \ -atomic_long_fetch_##op##mo(long i, atomic_long_t *l) \ -{ \ - ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \ - \ - return (long)ATOMIC_LONG_PFX(_fetch_##op##mo)(i, v); \ +static inline long +atomic_long_fetch_xor_relaxed (long i,atomic_long_t *v) +{ +return atomic64_fetch_xor_relaxed (i, v); } -ATOMIC_LONG_FETCH_OP(add, ) -ATOMIC_LONG_FETCH_OP(add, _relaxed) -ATOMIC_LONG_FETCH_OP(add, _acquire) -ATOMIC_LONG_FETCH_OP(add, _release) -ATOMIC_LONG_FETCH_OP(sub, ) -ATOMIC_LONG_FETCH_OP(sub, _relaxed) -ATOMIC_LONG_FETCH_OP(sub, _acquire) -ATOMIC_LONG_FETCH_OP(sub, _release) -ATOMIC_LONG_FETCH_OP(and, ) -ATOMIC_LONG_FETCH_OP(and, _relaxed) -ATOMIC_LONG_FETCH_OP(and, _acquire) -ATOMIC_LONG_FETCH_OP(and, _release) -ATOMIC_LONG_FETCH_OP(andnot, ) -ATOMIC_LONG_FETCH_OP(andnot, _relaxed) -ATOMIC_LONG_FETCH_OP(andnot, _acquire) -ATOMIC_LONG_FETCH_OP(andnot, _release) -ATOMIC_LONG_FETCH_OP(or, ) -ATOMIC_LONG_FETCH_OP(or, _relaxed) -ATOMIC_LONG_FETCH_OP(or, _acquire) -ATOMIC_LONG_FETCH_OP(or, _release) -ATOMIC_LONG_FETCH_OP(xor, ) -ATOMIC_LONG_FETCH_OP(xor, _relaxed) -ATOMIC_LONG_FETCH_OP(xor, _acquire) -ATOMIC_LONG_FETCH_OP(xor, _release) +static inline long +atomic_long_xchg (atomic_long_t *v,long i) +{ +return atomic64_xchg (v, i); +} -#undef ATOMIC_LONG_FETCH_OP +static inline long +atomic_long_xchg_acquire (atomic_long_t *v,long i) +{ +return atomic64_xchg_acquire (v, i); +} -#define ATOMIC_LONG_FETCH_INC_DEC_OP(op, mo) \ -static inline long \ -atomic_long_fetch_##op##mo(atomic_long_t *l) \ -{ \ - ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \ - \ - return (long)ATOMIC_LONG_PFX(_fetch_##op##mo)(v); \ +static inline long +atomic_long_xchg_release (atomic_long_t *v,long i) +{ +return atomic64_xchg_release (v, i); } -ATOMIC_LONG_FETCH_INC_DEC_OP(inc,) -ATOMIC_LONG_FETCH_INC_DEC_OP(inc, _relaxed) -ATOMIC_LONG_FETCH_INC_DEC_OP(inc, _acquire) -ATOMIC_LONG_FETCH_INC_DEC_OP(inc, _release) -ATOMIC_LONG_FETCH_INC_DEC_OP(dec,) -ATOMIC_LONG_FETCH_INC_DEC_OP(dec, _relaxed) -ATOMIC_LONG_FETCH_INC_DEC_OP(dec, _acquire) -ATOMIC_LONG_FETCH_INC_DEC_OP(dec, _release) +static inline long +atomic_long_xchg_relaxed (atomic_long_t *v,long i) +{ +return atomic64_xchg_relaxed (v, i); +} -#undef ATOMIC_LONG_FETCH_INC_DEC_OP +static inline long +atomic_long_cmpxchg (atomic_long_t *v,long old,long new) +{ +return atomic64_cmpxchg (v, old, new); +} -#define ATOMIC_LONG_OP(op) \ -static __always_inline void \ -atomic_long_##op(long i, atomic_long_t *l) \ -{ \ - ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \ - \ - ATOMIC_LONG_PFX(_##op)(i, v); \ +static inline long +atomic_long_cmpxchg_acquire (atomic_long_t *v,long old,long new) +{ +return atomic64_cmpxchg_acquire (v, old, new); } -ATOMIC_LONG_OP(add) -ATOMIC_LONG_OP(sub) -ATOMIC_LONG_OP(and) -ATOMIC_LONG_OP(andnot) -ATOMIC_LONG_OP(or) -ATOMIC_LONG_OP(xor) +static inline long +atomic_long_cmpxchg_release (atomic_long_t *v,long old,long new) +{ +return atomic64_cmpxchg_release (v, old, new); +} -#undef ATOMIC_LONG_OP +static inline long +atomic_long_cmpxchg_relaxed (atomic_long_t *v,long old,long new) +{ +return atomic64_cmpxchg_relaxed (v, old, new); +} -static inline int atomic_long_sub_and_test(long i, atomic_long_t *l) +static inline bool +atomic_long_try_cmpxchg (atomic_long_t *v,long *old,long new) { - ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; +return atomic64_try_cmpxchg (v, (s64 *)old, new); +} - return ATOMIC_LONG_PFX(_sub_and_test)(i, v); +static inline bool +atomic_long_try_cmpxchg_acquire (atomic_long_t *v,long *old,long new) +{ +return atomic64_try_cmpxchg_acquire (v, (s64 *)old, new); } -static inline int atomic_long_dec_and_test(atomic_long_t *l) +static inline bool +atomic_long_try_cmpxchg_release (atomic_long_t *v,long *old,long new) { - ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; +return atomic64_try_cmpxchg_release (v, (s64 *)old, new); +} - return ATOMIC_LONG_PFX(_dec_and_test)(v); +static inline bool +atomic_long_try_cmpxchg_relaxed (atomic_long_t *v,long *old,long new) +{ +return atomic64_try_cmpxchg_relaxed (v, (s64 *)old, new); } -static inline int atomic_long_inc_and_test(atomic_long_t *l) +static inline bool +atomic_long_sub_and_test (long i,atomic_long_t *v) { - ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; +return atomic64_sub_and_test (i, v); +} - return ATOMIC_LONG_PFX(_inc_and_test)(v); +static inline bool +atomic_long_dec_and_test (atomic_long_t *v) +{ +return atomic64_dec_and_test (v); } -static inline int atomic_long_add_negative(long i, atomic_long_t *l) +static inline bool +atomic_long_inc_and_test (atomic_long_t *v) { - ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; +return atomic64_inc_and_test (v); +} - return ATOMIC_LONG_PFX(_add_negative)(i, v); +static inline bool +atomic_long_add_negative (long i,atomic_long_t *v) +{ +return atomic64_add_negative (i, v); } -#define ATOMIC_LONG_INC_DEC_OP(op, mo) \ -static inline long \ -atomic_long_##op##_return##mo(atomic_long_t *l) \ -{ \ - ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \ - \ - return (long)ATOMIC_LONG_PFX(_##op##_return##mo)(v); \ +static inline long +atomic_long_fetch_add_unless (atomic_long_t *v,long a,long u) +{ +return atomic64_fetch_add_unless (v, a, u); } -ATOMIC_LONG_INC_DEC_OP(inc,) -ATOMIC_LONG_INC_DEC_OP(inc, _relaxed) -ATOMIC_LONG_INC_DEC_OP(inc, _acquire) -ATOMIC_LONG_INC_DEC_OP(inc, _release) -ATOMIC_LONG_INC_DEC_OP(dec,) -ATOMIC_LONG_INC_DEC_OP(dec, _relaxed) -ATOMIC_LONG_INC_DEC_OP(dec, _acquire) -ATOMIC_LONG_INC_DEC_OP(dec, _release) -#undef ATOMIC_LONG_INC_DEC_OP +static inline bool +atomic_long_add_unless (atomic_long_t *v,long a,long u) +{ +return atomic64_add_unless (v, a, u); +} + +static inline bool +atomic_long_inc_not_zero (atomic_long_t *v) +{ +return atomic64_inc_not_zero (v); +} + +static inline bool +atomic_long_inc_unless_negative (atomic_long_t *v) +{ +return atomic64_inc_unless_negative (v); +} + +static inline bool +atomic_long_dec_unless_positive (atomic_long_t *v) +{ +return atomic64_dec_unless_positive (v); +} + +static inline long +atomic_long_dec_if_positive (atomic_long_t *v) +{ +return atomic64_dec_if_positive (v); +} -static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u) +#else /* CONFIG_64BIT */ + +static inline long +atomic_long_read (const atomic_long_t *v) +{ +return atomic_read (v); +} + +static inline long +atomic_long_read_acquire (const atomic_long_t *v) +{ +return atomic_read_acquire (v); +} + +static inline void +atomic_long_set (atomic_long_t *v,long i) { - ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; +atomic_set (v, i); +} - return (long)ATOMIC_LONG_PFX(_add_unless)(v, a, u); +static inline void +atomic_long_set_release (atomic_long_t *v,long i) +{ +atomic_set_release (v, i); } -#define atomic_long_inc_not_zero(l) \ - ATOMIC_LONG_PFX(_inc_not_zero)((ATOMIC_LONG_PFX(_t) *)(l)) +static inline void +atomic_long_add (long i,atomic_long_t *v) +{ +atomic_add (i, v); +} + +static inline long +atomic_long_add_return (long i,atomic_long_t *v) +{ +return atomic_add_return (i, v); +} -#define atomic_long_cond_read_acquire(v, c) \ - ATOMIC_LONG_PFX(_cond_read_acquire)((ATOMIC_LONG_PFX(_t) *)(v), (c)) +static inline long +atomic_long_add_return_acquire (long i,atomic_long_t *v) +{ +return atomic_add_return_acquire (i, v); +} + +static inline long +atomic_long_add_return_release (long i,atomic_long_t *v) +{ +return atomic_add_return_release (i, v); +} + +static inline long +atomic_long_add_return_relaxed (long i,atomic_long_t *v) +{ +return atomic_add_return_relaxed (i, v); +} + +static inline long +atomic_long_fetch_add (long i,atomic_long_t *v) +{ +return atomic_fetch_add (i, v); +} + +static inline long +atomic_long_fetch_add_acquire (long i,atomic_long_t *v) +{ +return atomic_fetch_add_acquire (i, v); +} + +static inline long +atomic_long_fetch_add_release (long i,atomic_long_t *v) +{ +return atomic_fetch_add_release (i, v); +} + +static inline long +atomic_long_fetch_add_relaxed (long i,atomic_long_t *v) +{ +return atomic_fetch_add_relaxed (i, v); +} + +static inline void +atomic_long_sub (long i,atomic_long_t *v) +{ +atomic_sub (i, v); +} + +static inline long +atomic_long_sub_return (long i,atomic_long_t *v) +{ +return atomic_sub_return (i, v); +} + +static inline long +atomic_long_sub_return_acquire (long i,atomic_long_t *v) +{ +return atomic_sub_return_acquire (i, v); +} + +static inline long +atomic_long_sub_return_release (long i,atomic_long_t *v) +{ +return atomic_sub_return_release (i, v); +} + +static inline long +atomic_long_sub_return_relaxed (long i,atomic_long_t *v) +{ +return atomic_sub_return_relaxed (i, v); +} + +static inline long +atomic_long_fetch_sub (long i,atomic_long_t *v) +{ +return atomic_fetch_sub (i, v); +} + +static inline long +atomic_long_fetch_sub_acquire (long i,atomic_long_t *v) +{ +return atomic_fetch_sub_acquire (i, v); +} + +static inline long +atomic_long_fetch_sub_release (long i,atomic_long_t *v) +{ +return atomic_fetch_sub_release (i, v); +} + +static inline long +atomic_long_fetch_sub_relaxed (long i,atomic_long_t *v) +{ +return atomic_fetch_sub_relaxed (i, v); +} + +static inline void +atomic_long_inc (atomic_long_t *v) +{ +atomic_inc (v); +} + +static inline long +atomic_long_inc_return (atomic_long_t *v) +{ +return atomic_inc_return (v); +} + +static inline long +atomic_long_inc_return_acquire (atomic_long_t *v) +{ +return atomic_inc_return_acquire (v); +} + +static inline long +atomic_long_inc_return_release (atomic_long_t *v) +{ +return atomic_inc_return_release (v); +} + +static inline long +atomic_long_inc_return_relaxed (atomic_long_t *v) +{ +return atomic_inc_return_relaxed (v); +} + +static inline long +atomic_long_fetch_inc (atomic_long_t *v) +{ +return atomic_fetch_inc (v); +} + +static inline long +atomic_long_fetch_inc_acquire (atomic_long_t *v) +{ +return atomic_fetch_inc_acquire (v); +} + +static inline long +atomic_long_fetch_inc_release (atomic_long_t *v) +{ +return atomic_fetch_inc_release (v); +} + +static inline long +atomic_long_fetch_inc_relaxed (atomic_long_t *v) +{ +return atomic_fetch_inc_relaxed (v); +} + +static inline void +atomic_long_dec (atomic_long_t *v) +{ +atomic_dec (v); +} + +static inline long +atomic_long_dec_return (atomic_long_t *v) +{ +return atomic_dec_return (v); +} + +static inline long +atomic_long_dec_return_acquire (atomic_long_t *v) +{ +return atomic_dec_return_acquire (v); +} + +static inline long +atomic_long_dec_return_release (atomic_long_t *v) +{ +return atomic_dec_return_release (v); +} + +static inline long +atomic_long_dec_return_relaxed (atomic_long_t *v) +{ +return atomic_dec_return_relaxed (v); +} + +static inline long +atomic_long_fetch_dec (atomic_long_t *v) +{ +return atomic_fetch_dec (v); +} + +static inline long +atomic_long_fetch_dec_acquire (atomic_long_t *v) +{ +return atomic_fetch_dec_acquire (v); +} + +static inline long +atomic_long_fetch_dec_release (atomic_long_t *v) +{ +return atomic_fetch_dec_release (v); +} + +static inline long +atomic_long_fetch_dec_relaxed (atomic_long_t *v) +{ +return atomic_fetch_dec_relaxed (v); +} + +static inline void +atomic_long_and (long i,atomic_long_t *v) +{ +atomic_and (i, v); +} + +static inline long +atomic_long_fetch_and (long i,atomic_long_t *v) +{ +return atomic_fetch_and (i, v); +} + +static inline long +atomic_long_fetch_and_acquire (long i,atomic_long_t *v) +{ +return atomic_fetch_and_acquire (i, v); +} + +static inline long +atomic_long_fetch_and_release (long i,atomic_long_t *v) +{ +return atomic_fetch_and_release (i, v); +} + +static inline long +atomic_long_fetch_and_relaxed (long i,atomic_long_t *v) +{ +return atomic_fetch_and_relaxed (i, v); +} + +static inline void +atomic_long_andnot (long i,atomic_long_t *v) +{ +atomic_andnot (i, v); +} + +static inline long +atomic_long_fetch_andnot (long i,atomic_long_t *v) +{ +return atomic_fetch_andnot (i, v); +} + +static inline long +atomic_long_fetch_andnot_acquire (long i,atomic_long_t *v) +{ +return atomic_fetch_andnot_acquire (i, v); +} + +static inline long +atomic_long_fetch_andnot_release (long i,atomic_long_t *v) +{ +return atomic_fetch_andnot_release (i, v); +} + +static inline long +atomic_long_fetch_andnot_relaxed (long i,atomic_long_t *v) +{ +return atomic_fetch_andnot_relaxed (i, v); +} + +static inline void +atomic_long_or (long i,atomic_long_t *v) +{ +atomic_or (i, v); +} + +static inline long +atomic_long_fetch_or (long i,atomic_long_t *v) +{ +return atomic_fetch_or (i, v); +} + +static inline long +atomic_long_fetch_or_acquire (long i,atomic_long_t *v) +{ +return atomic_fetch_or_acquire (i, v); +} + +static inline long +atomic_long_fetch_or_release (long i,atomic_long_t *v) +{ +return atomic_fetch_or_release (i, v); +} + +static inline long +atomic_long_fetch_or_relaxed (long i,atomic_long_t *v) +{ +return atomic_fetch_or_relaxed (i, v); +} + +static inline void +atomic_long_xor (long i,atomic_long_t *v) +{ +atomic_xor (i, v); +} + +static inline long +atomic_long_fetch_xor (long i,atomic_long_t *v) +{ +return atomic_fetch_xor (i, v); +} + +static inline long +atomic_long_fetch_xor_acquire (long i,atomic_long_t *v) +{ +return atomic_fetch_xor_acquire (i, v); +} + +static inline long +atomic_long_fetch_xor_release (long i,atomic_long_t *v) +{ +return atomic_fetch_xor_release (i, v); +} + +static inline long +atomic_long_fetch_xor_relaxed (long i,atomic_long_t *v) +{ +return atomic_fetch_xor_relaxed (i, v); +} + +static inline long +atomic_long_xchg (atomic_long_t *v,long i) +{ +return atomic_xchg (v, i); +} + +static inline long +atomic_long_xchg_acquire (atomic_long_t *v,long i) +{ +return atomic_xchg_acquire (v, i); +} + +static inline long +atomic_long_xchg_release (atomic_long_t *v,long i) +{ +return atomic_xchg_release (v, i); +} + +static inline long +atomic_long_xchg_relaxed (atomic_long_t *v,long i) +{ +return atomic_xchg_relaxed (v, i); +} + +static inline long +atomic_long_cmpxchg (atomic_long_t *v,long old,long new) +{ +return atomic_cmpxchg (v, old, new); +} + +static inline long +atomic_long_cmpxchg_acquire (atomic_long_t *v,long old,long new) +{ +return atomic_cmpxchg_acquire (v, old, new); +} + +static inline long +atomic_long_cmpxchg_release (atomic_long_t *v,long old,long new) +{ +return atomic_cmpxchg_release (v, old, new); +} + +static inline long +atomic_long_cmpxchg_relaxed (atomic_long_t *v,long old,long new) +{ +return atomic_cmpxchg_relaxed (v, old, new); +} + +static inline bool +atomic_long_try_cmpxchg (atomic_long_t *v,long *old,long new) +{ +return atomic_try_cmpxchg (v, (int *)old, new); +} + +static inline bool +atomic_long_try_cmpxchg_acquire (atomic_long_t *v,long *old,long new) +{ +return atomic_try_cmpxchg_acquire (v, (int *)old, new); +} + +static inline bool +atomic_long_try_cmpxchg_release (atomic_long_t *v,long *old,long new) +{ +return atomic_try_cmpxchg_release (v, (int *)old, new); +} + +static inline bool +atomic_long_try_cmpxchg_relaxed (atomic_long_t *v,long *old,long new) +{ +return atomic_try_cmpxchg_relaxed (v, (int *)old, new); +} + +static inline bool +atomic_long_sub_and_test (long i,atomic_long_t *v) +{ +return atomic_sub_and_test (i, v); +} + +static inline bool +atomic_long_dec_and_test (atomic_long_t *v) +{ +return atomic_dec_and_test (v); +} + +static inline bool +atomic_long_inc_and_test (atomic_long_t *v) +{ +return atomic_inc_and_test (v); +} + +static inline bool +atomic_long_add_negative (long i,atomic_long_t *v) +{ +return atomic_add_negative (i, v); +} + +static inline long +atomic_long_fetch_add_unless (atomic_long_t *v,long a,long u) +{ +return atomic_fetch_add_unless (v, a, u); +} + +static inline bool +atomic_long_add_unless (atomic_long_t *v,long a,long u) +{ +return atomic_add_unless (v, a, u); +} + +static inline bool +atomic_long_inc_not_zero (atomic_long_t *v) +{ +return atomic_inc_not_zero (v); +} + +static inline bool +atomic_long_inc_unless_negative (atomic_long_t *v) +{ +return atomic_inc_unless_negative (v); +} + +static inline bool +atomic_long_dec_unless_positive (atomic_long_t *v) +{ +return atomic_dec_unless_positive (v); +} + +static inline long +atomic_long_dec_if_positive (atomic_long_t *v) +{ +return atomic_dec_if_positive (v); +} -#endif /* _ASM_GENERIC_ATOMIC_LONG_H */ +#endif /* CONFIG_64BIT */ +#endif /* _ASM_GENERIC_ATOMIC_LONG_H */
Signature · 1 line
2.11.0
Mark Rutland
reviewerPATCH 7/7 atomics: switch to generated instrumentation
In reply to Mark RutlandAs a step towards ensuring the atomic* APIs are consistent, let's switch to wrappers generated by gen-atomic-instrumented.h, using the same table used to generate the fallbacks and atomic-long wrappers.
These are checked in rather than generated with Kbuild, since:
* This allows inspection of the atomics with git grep and ctags on a pristine tree, which Linus strongly prefers being able to do.
* The fallbacks are not expected to change very often, and are not affected by machine details or configuration options, so regenerating them for *every* build is somewhat wasteful.
* These are included by files required *very* early in the build process (e.g. for generating bounds.h), and we'd rather not complicate the top-level Kbuild file.
Generating the atomic headers means that the instrumented wrappers will remain in sync with the rest of the atomic APIs, and we gain all the ordering variants of each atomic without having to manually expaned them all.
The KASAN checks are automatically generated based on the function parameters defined in atomics.tbl. Note that try_cmpxchg() now correctly treats 'old' as a parameter that may be written to, and not only read as the hand-written instrumentation assumed.
Other than try_cmpxchg, there should be no functional change as a result of this patch (i.e. existing code should not be affected). However, this change will allow architectures with relaxed atomics to gain instrumentation.
--- include/asm-generic/atomic-instrumented-atomic.h | 1629 ++++++++++++++++++++++ include/asm-generic/atomic-instrumented.h | 394 +----- 2 files changed, 1631 insertions(+), 392 deletions(-) create mode 100644 include/asm-generic/atomic-instrumented-atomic.h
Note: this is generated code. Please see patch 3 for the code which generated it, along with rationale in the cover letter.
Mark.
include/asm-generic/atomic-instrumented-atomic.h new file +1629 -0
@@ -0,0 +1,1629 @@ +// SPDX-License-Identifier: GPL-2.0 + +// Generated by ./scripts/atomic/gen-atomic-instrumented.sh +// DO NOT MODIFY THIS FILE DIRECTLY + +#ifndef _ASM_GENERIC_ATOMIC_INSTRUMENTED_ATOMIC_H +#define _ASM_GENERIC_ATOMIC_INSTRUMENTED_ATOMIC_H + +static inline int +atomic_read (const atomic_t *v) +{ +kasan_check_read (v,sizeof (*v)); +return arch_atomic_read (v); +} +#define atomic_read atomic_read + +#if defined(arch_atomic_read_acquire) +static inline int +atomic_read_acquire (const atomic_t *v) +{ +kasan_check_read (v,sizeof (*v)); +return arch_atomic_read_acquire (v); +} +#define atomic_read_acquire atomic_read_acquire +#endif + +static inline void +atomic_set (atomic_t *v,int i) +{ +kasan_check_write (v,sizeof (*v)); +arch_atomic_set (v, i); +} +#define atomic_set atomic_set + +#if defined(arch_atomic_set_release) +static inline void +atomic_set_release (atomic_t *v,int i) +{ +kasan_check_write (v,sizeof (*v)); +arch_atomic_set_release (v, i); +} +#define atomic_set_release atomic_set_release +#endif + +static inline void +atomic_add (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +arch_atomic_add (i, v); +} +#define atomic_add atomic_add + +#if !defined(arch_atomic_add_return_relaxed) || defined(arch_atomic_add_return) +static inline int +atomic_add_return (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_add_return (i, v); +} +#define atomic_add_return atomic_add_return +#endif + +#if defined(arch_atomic_add_return_acquire) +static inline int +atomic_add_return_acquire (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_add_return_acquire (i, v); +} +#define atomic_add_return_acquire atomic_add_return_acquire +#endif + +#if defined(arch_atomic_add_return_release) +static inline int +atomic_add_return_release (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_add_return_release (i, v); +} +#define atomic_add_return_release atomic_add_return_release +#endif + +#if defined(arch_atomic_add_return_relaxed) +static inline int +atomic_add_return_relaxed (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_add_return_relaxed (i, v); +} +#define atomic_add_return_relaxed atomic_add_return_relaxed +#endif + +#if !defined(arch_atomic_fetch_add_relaxed) || defined(arch_atomic_fetch_add) +static inline int +atomic_fetch_add (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_add (i, v); +} +#define atomic_fetch_add atomic_fetch_add +#endif + +#if defined(arch_atomic_fetch_add_acquire) +static inline int +atomic_fetch_add_acquire (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_add_acquire (i, v); +} +#define atomic_fetch_add_acquire atomic_fetch_add_acquire +#endif + +#if defined(arch_atomic_fetch_add_release) +static inline int +atomic_fetch_add_release (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_add_release (i, v); +} +#define atomic_fetch_add_release atomic_fetch_add_release +#endif + +#if defined(arch_atomic_fetch_add_relaxed) +static inline int +atomic_fetch_add_relaxed (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_add_relaxed (i, v); +} +#define atomic_fetch_add_relaxed atomic_fetch_add_relaxed +#endif + +static inline void +atomic_sub (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +arch_atomic_sub (i, v); +} +#define atomic_sub atomic_sub + +#if !defined(arch_atomic_sub_return_relaxed) || defined(arch_atomic_sub_return) +static inline int +atomic_sub_return (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_sub_return (i, v); +} +#define atomic_sub_return atomic_sub_return +#endif + +#if defined(arch_atomic_sub_return_acquire) +static inline int +atomic_sub_return_acquire (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_sub_return_acquire (i, v); +} +#define atomic_sub_return_acquire atomic_sub_return_acquire +#endif + +#if defined(arch_atomic_sub_return_release) +static inline int +atomic_sub_return_release (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_sub_return_release (i, v); +} +#define atomic_sub_return_release atomic_sub_return_release +#endif + +#if defined(arch_atomic_sub_return_relaxed) +static inline int +atomic_sub_return_relaxed (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_sub_return_relaxed (i, v); +} +#define atomic_sub_return_relaxed atomic_sub_return_relaxed +#endif + +#if !defined(arch_atomic_fetch_sub_relaxed) || defined(arch_atomic_fetch_sub) +static inline int +atomic_fetch_sub (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_sub (i, v); +} +#define atomic_fetch_sub atomic_fetch_sub +#endif + +#if defined(arch_atomic_fetch_sub_acquire) +static inline int +atomic_fetch_sub_acquire (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_sub_acquire (i, v); +} +#define atomic_fetch_sub_acquire atomic_fetch_sub_acquire +#endif + +#if defined(arch_atomic_fetch_sub_release) +static inline int +atomic_fetch_sub_release (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_sub_release (i, v); +} +#define atomic_fetch_sub_release atomic_fetch_sub_release +#endif + +#if defined(arch_atomic_fetch_sub_relaxed) +static inline int +atomic_fetch_sub_relaxed (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_sub_relaxed (i, v); +} +#define atomic_fetch_sub_relaxed atomic_fetch_sub_relaxed +#endif + +#if defined(arch_atomic_inc) +static inline void +atomic_inc (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +arch_atomic_inc (v); +} +#define atomic_inc atomic_inc +#endif + +#if defined(arch_atomic_inc_return) +static inline int +atomic_inc_return (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_inc_return (v); +} +#define atomic_inc_return atomic_inc_return +#endif + +#if defined(arch_atomic_inc_return_acquire) +static inline int +atomic_inc_return_acquire (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_inc_return_acquire (v); +} +#define atomic_inc_return_acquire atomic_inc_return_acquire +#endif + +#if defined(arch_atomic_inc_return_release) +static inline int +atomic_inc_return_release (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_inc_return_release (v); +} +#define atomic_inc_return_release atomic_inc_return_release +#endif + +#if defined(arch_atomic_inc_return_relaxed) +static inline int +atomic_inc_return_relaxed (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_inc_return_relaxed (v); +} +#define atomic_inc_return_relaxed atomic_inc_return_relaxed +#endif + +#if defined(arch_atomic_fetch_inc) +static inline int +atomic_fetch_inc (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_inc (v); +} +#define atomic_fetch_inc atomic_fetch_inc +#endif + +#if defined(arch_atomic_fetch_inc_acquire) +static inline int +atomic_fetch_inc_acquire (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_inc_acquire (v); +} +#define atomic_fetch_inc_acquire atomic_fetch_inc_acquire +#endif + +#if defined(arch_atomic_fetch_inc_release) +static inline int +atomic_fetch_inc_release (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_inc_release (v); +} +#define atomic_fetch_inc_release atomic_fetch_inc_release +#endif + +#if defined(arch_atomic_fetch_inc_relaxed) +static inline int +atomic_fetch_inc_relaxed (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_inc_relaxed (v); +} +#define atomic_fetch_inc_relaxed atomic_fetch_inc_relaxed +#endif + +#if defined(arch_atomic_dec) +static inline void +atomic_dec (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +arch_atomic_dec (v); +} +#define atomic_dec atomic_dec +#endif + +#if defined(arch_atomic_dec_return) +static inline int +atomic_dec_return (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_dec_return (v); +} +#define atomic_dec_return atomic_dec_return +#endif + +#if defined(arch_atomic_dec_return_acquire) +static inline int +atomic_dec_return_acquire (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_dec_return_acquire (v); +} +#define atomic_dec_return_acquire atomic_dec_return_acquire +#endif + +#if defined(arch_atomic_dec_return_release) +static inline int +atomic_dec_return_release (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_dec_return_release (v); +} +#define atomic_dec_return_release atomic_dec_return_release +#endif + +#if defined(arch_atomic_dec_return_relaxed) +static inline int +atomic_dec_return_relaxed (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_dec_return_relaxed (v); +} +#define atomic_dec_return_relaxed atomic_dec_return_relaxed +#endif + +#if defined(arch_atomic_fetch_dec) +static inline int +atomic_fetch_dec (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_dec (v); +} +#define atomic_fetch_dec atomic_fetch_dec +#endif + +#if defined(arch_atomic_fetch_dec_acquire) +static inline int +atomic_fetch_dec_acquire (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_dec_acquire (v); +} +#define atomic_fetch_dec_acquire atomic_fetch_dec_acquire +#endif + +#if defined(arch_atomic_fetch_dec_release) +static inline int +atomic_fetch_dec_release (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_dec_release (v); +} +#define atomic_fetch_dec_release atomic_fetch_dec_release +#endif + +#if defined(arch_atomic_fetch_dec_relaxed) +static inline int +atomic_fetch_dec_relaxed (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_dec_relaxed (v); +} +#define atomic_fetch_dec_relaxed atomic_fetch_dec_relaxed +#endif + +static inline void +atomic_and (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +arch_atomic_and (i, v); +} +#define atomic_and atomic_and + +#if !defined(arch_atomic_fetch_and_relaxed) || defined(arch_atomic_fetch_and) +static inline int +atomic_fetch_and (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_and (i, v); +} +#define atomic_fetch_and atomic_fetch_and +#endif + +#if defined(arch_atomic_fetch_and_acquire) +static inline int +atomic_fetch_and_acquire (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_and_acquire (i, v); +} +#define atomic_fetch_and_acquire atomic_fetch_and_acquire +#endif + +#if defined(arch_atomic_fetch_and_release) +static inline int +atomic_fetch_and_release (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_and_release (i, v); +} +#define atomic_fetch_and_release atomic_fetch_and_release +#endif + +#if defined(arch_atomic_fetch_and_relaxed) +static inline int +atomic_fetch_and_relaxed (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_and_relaxed (i, v); +} +#define atomic_fetch_and_relaxed atomic_fetch_and_relaxed +#endif + +#if defined(arch_atomic_andnot) +static inline void +atomic_andnot (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +arch_atomic_andnot (i, v); +} +#define atomic_andnot atomic_andnot +#endif + +#if defined(arch_atomic_fetch_andnot) +static inline int +atomic_fetch_andnot (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_andnot (i, v); +} +#define atomic_fetch_andnot atomic_fetch_andnot +#endif + +#if defined(arch_atomic_fetch_andnot_acquire) +static inline int +atomic_fetch_andnot_acquire (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_andnot_acquire (i, v); +} +#define atomic_fetch_andnot_acquire atomic_fetch_andnot_acquire +#endif + +#if defined(arch_atomic_fetch_andnot_release) +static inline int +atomic_fetch_andnot_release (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_andnot_release (i, v); +} +#define atomic_fetch_andnot_release atomic_fetch_andnot_release +#endif + +#if defined(arch_atomic_fetch_andnot_relaxed) +static inline int +atomic_fetch_andnot_relaxed (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_andnot_relaxed (i, v); +} +#define atomic_fetch_andnot_relaxed atomic_fetch_andnot_relaxed +#endif + +static inline void +atomic_or (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +arch_atomic_or (i, v); +} +#define atomic_or atomic_or + +#if !defined(arch_atomic_fetch_or_relaxed) || defined(arch_atomic_fetch_or) +static inline int +atomic_fetch_or (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_or (i, v); +} +#define atomic_fetch_or atomic_fetch_or +#endif + +#if defined(arch_atomic_fetch_or_acquire) +static inline int +atomic_fetch_or_acquire (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_or_acquire (i, v); +} +#define atomic_fetch_or_acquire atomic_fetch_or_acquire +#endif + +#if defined(arch_atomic_fetch_or_release) +static inline int +atomic_fetch_or_release (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_or_release (i, v); +} +#define atomic_fetch_or_release atomic_fetch_or_release +#endif + +#if defined(arch_atomic_fetch_or_relaxed) +static inline int +atomic_fetch_or_relaxed (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_or_relaxed (i, v); +} +#define atomic_fetch_or_relaxed atomic_fetch_or_relaxed +#endif + +static inline void +atomic_xor (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +arch_atomic_xor (i, v); +} +#define atomic_xor atomic_xor + +#if !defined(arch_atomic_fetch_xor_relaxed) || defined(arch_atomic_fetch_xor) +static inline int +atomic_fetch_xor (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_xor (i, v); +} +#define atomic_fetch_xor atomic_fetch_xor +#endif + +#if defined(arch_atomic_fetch_xor_acquire) +static inline int +atomic_fetch_xor_acquire (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_xor_acquire (i, v); +} +#define atomic_fetch_xor_acquire atomic_fetch_xor_acquire +#endif + +#if defined(arch_atomic_fetch_xor_release) +static inline int +atomic_fetch_xor_release (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_xor_release (i, v); +} +#define atomic_fetch_xor_release atomic_fetch_xor_release +#endif + +#if defined(arch_atomic_fetch_xor_relaxed) +static inline int +atomic_fetch_xor_relaxed (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_xor_relaxed (i, v); +} +#define atomic_fetch_xor_relaxed atomic_fetch_xor_relaxed +#endif + +#if !defined(arch_atomic_xchg_relaxed) || defined(arch_atomic_xchg) +static inline int +atomic_xchg (atomic_t *v,int i) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_xchg (v, i); +} +#define atomic_xchg atomic_xchg +#endif + +#if defined(arch_atomic_xchg_acquire) +static inline int +atomic_xchg_acquire (atomic_t *v,int i) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_xchg_acquire (v, i); +} +#define atomic_xchg_acquire atomic_xchg_acquire +#endif + +#if defined(arch_atomic_xchg_release) +static inline int +atomic_xchg_release (atomic_t *v,int i) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_xchg_release (v, i); +} +#define atomic_xchg_release atomic_xchg_release +#endif + +#if defined(arch_atomic_xchg_relaxed) +static inline int +atomic_xchg_relaxed (atomic_t *v,int i) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_xchg_relaxed (v, i); +} +#define atomic_xchg_relaxed atomic_xchg_relaxed +#endif + +#if !defined(arch_atomic_cmpxchg_relaxed) || defined(arch_atomic_cmpxchg) +static inline int +atomic_cmpxchg (atomic_t *v,int old,int new) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_cmpxchg (v, old, new); +} +#define atomic_cmpxchg atomic_cmpxchg +#endif + +#if defined(arch_atomic_cmpxchg_acquire) +static inline int +atomic_cmpxchg_acquire (atomic_t *v,int old,int new) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_cmpxchg_acquire (v, old, new); +} +#define atomic_cmpxchg_acquire atomic_cmpxchg_acquire +#endif + +#if defined(arch_atomic_cmpxchg_release) +static inline int +atomic_cmpxchg_release (atomic_t *v,int old,int new) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_cmpxchg_release (v, old, new); +} +#define atomic_cmpxchg_release atomic_cmpxchg_release +#endif + +#if defined(arch_atomic_cmpxchg_relaxed) +static inline int +atomic_cmpxchg_relaxed (atomic_t *v,int old,int new) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_cmpxchg_relaxed (v, old, new); +} +#define atomic_cmpxchg_relaxed atomic_cmpxchg_relaxed +#endif + +#if defined(arch_atomic_try_cmpxchg) +static inline bool +atomic_try_cmpxchg (atomic_t *v,int *old,int new) +{ +kasan_check_write (v,sizeof (*v)); +kasan_check_write (old,sizeof (*old)); +return arch_atomic_try_cmpxchg (v, old, new); +} +#define atomic_try_cmpxchg atomic_try_cmpxchg +#endif + +#if defined(arch_atomic_try_cmpxchg_acquire) +static inline bool +atomic_try_cmpxchg_acquire (atomic_t *v,int *old,int new) +{ +kasan_check_write (v,sizeof (*v)); +kasan_check_write (old,sizeof (*old)); +return arch_atomic_try_cmpxchg_acquire (v, old, new); +} +#define atomic_try_cmpxchg_acquire atomic_try_cmpxchg_acquire +#endif + +#if defined(arch_atomic_try_cmpxchg_release) +static inline bool +atomic_try_cmpxchg_release (atomic_t *v,int *old,int new) +{ +kasan_check_write (v,sizeof (*v)); +kasan_check_write (old,sizeof (*old)); +return arch_atomic_try_cmpxchg_release (v, old, new); +} +#define atomic_try_cmpxchg_release atomic_try_cmpxchg_release +#endif + +#if defined(arch_atomic_try_cmpxchg_relaxed) +static inline bool +atomic_try_cmpxchg_relaxed (atomic_t *v,int *old,int new) +{ +kasan_check_write (v,sizeof (*v)); +kasan_check_write (old,sizeof (*old)); +return arch_atomic_try_cmpxchg_relaxed (v, old, new); +} +#define atomic_try_cmpxchg_relaxed atomic_try_cmpxchg_relaxed +#endif + +#if defined(arch_atomic_sub_and_test) +static inline bool +atomic_sub_and_test (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_sub_and_test (i, v); +} +#define atomic_sub_and_test atomic_sub_and_test +#endif + +#if defined(arch_atomic_dec_and_test) +static inline bool +atomic_dec_and_test (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_dec_and_test (v); +} +#define atomic_dec_and_test atomic_dec_and_test +#endif + +#if defined(arch_atomic_inc_and_test) +static inline bool +atomic_inc_and_test (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_inc_and_test (v); +} +#define atomic_inc_and_test atomic_inc_and_test +#endif + +#if defined(arch_atomic_add_negative) +static inline bool +atomic_add_negative (int i,atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_add_negative (i, v); +} +#define atomic_add_negative atomic_add_negative +#endif + +#if defined(arch_atomic_fetch_add_unless) +static inline int +atomic_fetch_add_unless (atomic_t *v,int a,int u) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_fetch_add_unless (v, a, u); +} +#define atomic_fetch_add_unless atomic_fetch_add_unless +#endif + +#if defined(arch_atomic_add_unless) +static inline bool +atomic_add_unless (atomic_t *v,int a,int u) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_add_unless (v, a, u); +} +#define atomic_add_unless atomic_add_unless +#endif + +#if defined(arch_atomic_inc_not_zero) +static inline bool +atomic_inc_not_zero (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_inc_not_zero (v); +} +#define atomic_inc_not_zero atomic_inc_not_zero +#endif + +#if defined(arch_atomic_inc_unless_negative) +static inline bool +atomic_inc_unless_negative (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_inc_unless_negative (v); +} +#define atomic_inc_unless_negative atomic_inc_unless_negative +#endif + +#if defined(arch_atomic_dec_unless_positive) +static inline bool +atomic_dec_unless_positive (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_dec_unless_positive (v); +} +#define atomic_dec_unless_positive atomic_dec_unless_positive +#endif + +#if defined(arch_atomic_dec_if_positive) +static inline int +atomic_dec_if_positive (atomic_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic_dec_if_positive (v); +} +#define atomic_dec_if_positive atomic_dec_if_positive +#endif + +static inline s64 +atomic64_read (const atomic64_t *v) +{ +kasan_check_read (v,sizeof (*v)); +return arch_atomic64_read (v); +} +#define atomic64_read atomic64_read + +#if defined(arch_atomic64_read_acquire) +static inline s64 +atomic64_read_acquire (const atomic64_t *v) +{ +kasan_check_read (v,sizeof (*v)); +return arch_atomic64_read_acquire (v); +} +#define atomic64_read_acquire atomic64_read_acquire +#endif + +static inline void +atomic64_set (atomic64_t *v,s64 i) +{ +kasan_check_write (v,sizeof (*v)); +arch_atomic64_set (v, i); +} +#define atomic64_set atomic64_set + +#if defined(arch_atomic64_set_release) +static inline void +atomic64_set_release (atomic64_t *v,s64 i) +{ +kasan_check_write (v,sizeof (*v)); +arch_atomic64_set_release (v, i); +} +#define atomic64_set_release atomic64_set_release +#endif + +static inline void +atomic64_add (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +arch_atomic64_add (i, v); +} +#define atomic64_add atomic64_add + +#if !defined(arch_atomic64_add_return_relaxed) || defined(arch_atomic64_add_return) +static inline s64 +atomic64_add_return (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_add_return (i, v); +} +#define atomic64_add_return atomic64_add_return +#endif + +#if defined(arch_atomic64_add_return_acquire) +static inline s64 +atomic64_add_return_acquire (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_add_return_acquire (i, v); +} +#define atomic64_add_return_acquire atomic64_add_return_acquire +#endif + +#if defined(arch_atomic64_add_return_release) +static inline s64 +atomic64_add_return_release (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_add_return_release (i, v); +} +#define atomic64_add_return_release atomic64_add_return_release +#endif + +#if defined(arch_atomic64_add_return_relaxed) +static inline s64 +atomic64_add_return_relaxed (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_add_return_relaxed (i, v); +} +#define atomic64_add_return_relaxed atomic64_add_return_relaxed +#endif + +#if !defined(arch_atomic64_fetch_add_relaxed) || defined(arch_atomic64_fetch_add) +static inline s64 +atomic64_fetch_add (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_add (i, v); +} +#define atomic64_fetch_add atomic64_fetch_add +#endif + +#if defined(arch_atomic64_fetch_add_acquire) +static inline s64 +atomic64_fetch_add_acquire (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_add_acquire (i, v); +} +#define atomic64_fetch_add_acquire atomic64_fetch_add_acquire +#endif + +#if defined(arch_atomic64_fetch_add_release) +static inline s64 +atomic64_fetch_add_release (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_add_release (i, v); +} +#define atomic64_fetch_add_release atomic64_fetch_add_release +#endif + +#if defined(arch_atomic64_fetch_add_relaxed) +static inline s64 +atomic64_fetch_add_relaxed (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_add_relaxed (i, v); +} +#define atomic64_fetch_add_relaxed atomic64_fetch_add_relaxed +#endif + +static inline void +atomic64_sub (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +arch_atomic64_sub (i, v); +} +#define atomic64_sub atomic64_sub + +#if !defined(arch_atomic64_sub_return_relaxed) || defined(arch_atomic64_sub_return) +static inline s64 +atomic64_sub_return (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_sub_return (i, v); +} +#define atomic64_sub_return atomic64_sub_return +#endif + +#if defined(arch_atomic64_sub_return_acquire) +static inline s64 +atomic64_sub_return_acquire (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_sub_return_acquire (i, v); +} +#define atomic64_sub_return_acquire atomic64_sub_return_acquire +#endif + +#if defined(arch_atomic64_sub_return_release) +static inline s64 +atomic64_sub_return_release (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_sub_return_release (i, v); +} +#define atomic64_sub_return_release atomic64_sub_return_release +#endif + +#if defined(arch_atomic64_sub_return_relaxed) +static inline s64 +atomic64_sub_return_relaxed (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_sub_return_relaxed (i, v); +} +#define atomic64_sub_return_relaxed atomic64_sub_return_relaxed +#endif + +#if !defined(arch_atomic64_fetch_sub_relaxed) || defined(arch_atomic64_fetch_sub) +static inline s64 +atomic64_fetch_sub (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_sub (i, v); +} +#define atomic64_fetch_sub atomic64_fetch_sub +#endif + +#if defined(arch_atomic64_fetch_sub_acquire) +static inline s64 +atomic64_fetch_sub_acquire (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_sub_acquire (i, v); +} +#define atomic64_fetch_sub_acquire atomic64_fetch_sub_acquire +#endif + +#if defined(arch_atomic64_fetch_sub_release) +static inline s64 +atomic64_fetch_sub_release (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_sub_release (i, v); +} +#define atomic64_fetch_sub_release atomic64_fetch_sub_release +#endif + +#if defined(arch_atomic64_fetch_sub_relaxed) +static inline s64 +atomic64_fetch_sub_relaxed (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_sub_relaxed (i, v); +} +#define atomic64_fetch_sub_relaxed atomic64_fetch_sub_relaxed +#endif + +#if defined(arch_atomic64_inc) +static inline void +atomic64_inc (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +arch_atomic64_inc (v); +} +#define atomic64_inc atomic64_inc +#endif + +#if defined(arch_atomic64_inc_return) +static inline s64 +atomic64_inc_return (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_inc_return (v); +} +#define atomic64_inc_return atomic64_inc_return +#endif + +#if defined(arch_atomic64_inc_return_acquire) +static inline s64 +atomic64_inc_return_acquire (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_inc_return_acquire (v); +} +#define atomic64_inc_return_acquire atomic64_inc_return_acquire +#endif + +#if defined(arch_atomic64_inc_return_release) +static inline s64 +atomic64_inc_return_release (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_inc_return_release (v); +} +#define atomic64_inc_return_release atomic64_inc_return_release +#endif + +#if defined(arch_atomic64_inc_return_relaxed) +static inline s64 +atomic64_inc_return_relaxed (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_inc_return_relaxed (v); +} +#define atomic64_inc_return_relaxed atomic64_inc_return_relaxed +#endif + +#if defined(arch_atomic64_fetch_inc) +static inline s64 +atomic64_fetch_inc (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_inc (v); +} +#define atomic64_fetch_inc atomic64_fetch_inc +#endif + +#if defined(arch_atomic64_fetch_inc_acquire) +static inline s64 +atomic64_fetch_inc_acquire (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_inc_acquire (v); +} +#define atomic64_fetch_inc_acquire atomic64_fetch_inc_acquire +#endif + +#if defined(arch_atomic64_fetch_inc_release) +static inline s64 +atomic64_fetch_inc_release (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_inc_release (v); +} +#define atomic64_fetch_inc_release atomic64_fetch_inc_release +#endif + +#if defined(arch_atomic64_fetch_inc_relaxed) +static inline s64 +atomic64_fetch_inc_relaxed (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_inc_relaxed (v); +} +#define atomic64_fetch_inc_relaxed atomic64_fetch_inc_relaxed +#endif + +#if defined(arch_atomic64_dec) +static inline void +atomic64_dec (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +arch_atomic64_dec (v); +} +#define atomic64_dec atomic64_dec +#endif + +#if defined(arch_atomic64_dec_return) +static inline s64 +atomic64_dec_return (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_dec_return (v); +} +#define atomic64_dec_return atomic64_dec_return +#endif + +#if defined(arch_atomic64_dec_return_acquire) +static inline s64 +atomic64_dec_return_acquire (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_dec_return_acquire (v); +} +#define atomic64_dec_return_acquire atomic64_dec_return_acquire +#endif + +#if defined(arch_atomic64_dec_return_release) +static inline s64 +atomic64_dec_return_release (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_dec_return_release (v); +} +#define atomic64_dec_return_release atomic64_dec_return_release +#endif + +#if defined(arch_atomic64_dec_return_relaxed) +static inline s64 +atomic64_dec_return_relaxed (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_dec_return_relaxed (v); +} +#define atomic64_dec_return_relaxed atomic64_dec_return_relaxed +#endif + +#if defined(arch_atomic64_fetch_dec) +static inline s64 +atomic64_fetch_dec (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_dec (v); +} +#define atomic64_fetch_dec atomic64_fetch_dec +#endif + +#if defined(arch_atomic64_fetch_dec_acquire) +static inline s64 +atomic64_fetch_dec_acquire (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_dec_acquire (v); +} +#define atomic64_fetch_dec_acquire atomic64_fetch_dec_acquire +#endif + +#if defined(arch_atomic64_fetch_dec_release) +static inline s64 +atomic64_fetch_dec_release (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_dec_release (v); +} +#define atomic64_fetch_dec_release atomic64_fetch_dec_release +#endif + +#if defined(arch_atomic64_fetch_dec_relaxed) +static inline s64 +atomic64_fetch_dec_relaxed (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_dec_relaxed (v); +} +#define atomic64_fetch_dec_relaxed atomic64_fetch_dec_relaxed +#endif + +static inline void +atomic64_and (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +arch_atomic64_and (i, v); +} +#define atomic64_and atomic64_and + +#if !defined(arch_atomic64_fetch_and_relaxed) || defined(arch_atomic64_fetch_and) +static inline s64 +atomic64_fetch_and (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_and (i, v); +} +#define atomic64_fetch_and atomic64_fetch_and +#endif + +#if defined(arch_atomic64_fetch_and_acquire) +static inline s64 +atomic64_fetch_and_acquire (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_and_acquire (i, v); +} +#define atomic64_fetch_and_acquire atomic64_fetch_and_acquire +#endif + +#if defined(arch_atomic64_fetch_and_release) +static inline s64 +atomic64_fetch_and_release (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_and_release (i, v); +} +#define atomic64_fetch_and_release atomic64_fetch_and_release +#endif + +#if defined(arch_atomic64_fetch_and_relaxed) +static inline s64 +atomic64_fetch_and_relaxed (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_and_relaxed (i, v); +} +#define atomic64_fetch_and_relaxed atomic64_fetch_and_relaxed +#endif + +#if defined(arch_atomic64_andnot) +static inline void +atomic64_andnot (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +arch_atomic64_andnot (i, v); +} +#define atomic64_andnot atomic64_andnot +#endif + +#if defined(arch_atomic64_fetch_andnot) +static inline s64 +atomic64_fetch_andnot (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_andnot (i, v); +} +#define atomic64_fetch_andnot atomic64_fetch_andnot +#endif + +#if defined(arch_atomic64_fetch_andnot_acquire) +static inline s64 +atomic64_fetch_andnot_acquire (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_andnot_acquire (i, v); +} +#define atomic64_fetch_andnot_acquire atomic64_fetch_andnot_acquire +#endif + +#if defined(arch_atomic64_fetch_andnot_release) +static inline s64 +atomic64_fetch_andnot_release (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_andnot_release (i, v); +} +#define atomic64_fetch_andnot_release atomic64_fetch_andnot_release +#endif + +#if defined(arch_atomic64_fetch_andnot_relaxed) +static inline s64 +atomic64_fetch_andnot_relaxed (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_andnot_relaxed (i, v); +} +#define atomic64_fetch_andnot_relaxed atomic64_fetch_andnot_relaxed +#endif + +static inline void +atomic64_or (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +arch_atomic64_or (i, v); +} +#define atomic64_or atomic64_or + +#if !defined(arch_atomic64_fetch_or_relaxed) || defined(arch_atomic64_fetch_or) +static inline s64 +atomic64_fetch_or (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_or (i, v); +} +#define atomic64_fetch_or atomic64_fetch_or +#endif + +#if defined(arch_atomic64_fetch_or_acquire) +static inline s64 +atomic64_fetch_or_acquire (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_or_acquire (i, v); +} +#define atomic64_fetch_or_acquire atomic64_fetch_or_acquire +#endif + +#if defined(arch_atomic64_fetch_or_release) +static inline s64 +atomic64_fetch_or_release (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_or_release (i, v); +} +#define atomic64_fetch_or_release atomic64_fetch_or_release +#endif + +#if defined(arch_atomic64_fetch_or_relaxed) +static inline s64 +atomic64_fetch_or_relaxed (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_or_relaxed (i, v); +} +#define atomic64_fetch_or_relaxed atomic64_fetch_or_relaxed +#endif + +static inline void +atomic64_xor (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +arch_atomic64_xor (i, v); +} +#define atomic64_xor atomic64_xor + +#if !defined(arch_atomic64_fetch_xor_relaxed) || defined(arch_atomic64_fetch_xor) +static inline s64 +atomic64_fetch_xor (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_xor (i, v); +} +#define atomic64_fetch_xor atomic64_fetch_xor +#endif + +#if defined(arch_atomic64_fetch_xor_acquire) +static inline s64 +atomic64_fetch_xor_acquire (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_xor_acquire (i, v); +} +#define atomic64_fetch_xor_acquire atomic64_fetch_xor_acquire +#endif + +#if defined(arch_atomic64_fetch_xor_release) +static inline s64 +atomic64_fetch_xor_release (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_xor_release (i, v); +} +#define atomic64_fetch_xor_release atomic64_fetch_xor_release +#endif + +#if defined(arch_atomic64_fetch_xor_relaxed) +static inline s64 +atomic64_fetch_xor_relaxed (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_xor_relaxed (i, v); +} +#define atomic64_fetch_xor_relaxed atomic64_fetch_xor_relaxed +#endif + +#if !defined(arch_atomic64_xchg_relaxed) || defined(arch_atomic64_xchg) +static inline s64 +atomic64_xchg (atomic64_t *v,s64 i) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_xchg (v, i); +} +#define atomic64_xchg atomic64_xchg +#endif + +#if defined(arch_atomic64_xchg_acquire) +static inline s64 +atomic64_xchg_acquire (atomic64_t *v,s64 i) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_xchg_acquire (v, i); +} +#define atomic64_xchg_acquire atomic64_xchg_acquire +#endif + +#if defined(arch_atomic64_xchg_release) +static inline s64 +atomic64_xchg_release (atomic64_t *v,s64 i) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_xchg_release (v, i); +} +#define atomic64_xchg_release atomic64_xchg_release +#endif + +#if defined(arch_atomic64_xchg_relaxed) +static inline s64 +atomic64_xchg_relaxed (atomic64_t *v,s64 i) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_xchg_relaxed (v, i); +} +#define atomic64_xchg_relaxed atomic64_xchg_relaxed +#endif + +#if !defined(arch_atomic64_cmpxchg_relaxed) || defined(arch_atomic64_cmpxchg) +static inline s64 +atomic64_cmpxchg (atomic64_t *v,s64 old,s64 new) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_cmpxchg (v, old, new); +} +#define atomic64_cmpxchg atomic64_cmpxchg +#endif + +#if defined(arch_atomic64_cmpxchg_acquire) +static inline s64 +atomic64_cmpxchg_acquire (atomic64_t *v,s64 old,s64 new) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_cmpxchg_acquire (v, old, new); +} +#define atomic64_cmpxchg_acquire atomic64_cmpxchg_acquire +#endif + +#if defined(arch_atomic64_cmpxchg_release) +static inline s64 +atomic64_cmpxchg_release (atomic64_t *v,s64 old,s64 new) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_cmpxchg_release (v, old, new); +} +#define atomic64_cmpxchg_release atomic64_cmpxchg_release +#endif + +#if defined(arch_atomic64_cmpxchg_relaxed) +static inline s64 +atomic64_cmpxchg_relaxed (atomic64_t *v,s64 old,s64 new) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_cmpxchg_relaxed (v, old, new); +} +#define atomic64_cmpxchg_relaxed atomic64_cmpxchg_relaxed +#endif + +#if defined(arch_atomic64_try_cmpxchg) +static inline bool +atomic64_try_cmpxchg (atomic64_t *v,s64 *old,s64 new) +{ +kasan_check_write (v,sizeof (*v)); +kasan_check_write (old,sizeof (*old)); +return arch_atomic64_try_cmpxchg (v, old, new); +} +#define atomic64_try_cmpxchg atomic64_try_cmpxchg +#endif + +#if defined(arch_atomic64_try_cmpxchg_acquire) +static inline bool +atomic64_try_cmpxchg_acquire (atomic64_t *v,s64 *old,s64 new) +{ +kasan_check_write (v,sizeof (*v)); +kasan_check_write (old,sizeof (*old)); +return arch_atomic64_try_cmpxchg_acquire (v, old, new); +} +#define atomic64_try_cmpxchg_acquire atomic64_try_cmpxchg_acquire +#endif + +#if defined(arch_atomic64_try_cmpxchg_release) +static inline bool +atomic64_try_cmpxchg_release (atomic64_t *v,s64 *old,s64 new) +{ +kasan_check_write (v,sizeof (*v)); +kasan_check_write (old,sizeof (*old)); +return arch_atomic64_try_cmpxchg_release (v, old, new); +} +#define atomic64_try_cmpxchg_release atomic64_try_cmpxchg_release +#endif + +#if defined(arch_atomic64_try_cmpxchg_relaxed) +static inline bool +atomic64_try_cmpxchg_relaxed (atomic64_t *v,s64 *old,s64 new) +{ +kasan_check_write (v,sizeof (*v)); +kasan_check_write (old,sizeof (*old)); +return arch_atomic64_try_cmpxchg_relaxed (v, old, new); +} +#define atomic64_try_cmpxchg_relaxed atomic64_try_cmpxchg_relaxed +#endif + +#if defined(arch_atomic64_sub_and_test) +static inline bool +atomic64_sub_and_test (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_sub_and_test (i, v); +} +#define atomic64_sub_and_test atomic64_sub_and_test +#endif + +#if defined(arch_atomic64_dec_and_test) +static inline bool +atomic64_dec_and_test (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_dec_and_test (v); +} +#define atomic64_dec_and_test atomic64_dec_and_test +#endif + +#if defined(arch_atomic64_inc_and_test) +static inline bool +atomic64_inc_and_test (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_inc_and_test (v); +} +#define atomic64_inc_and_test atomic64_inc_and_test +#endif + +#if defined(arch_atomic64_add_negative) +static inline bool +atomic64_add_negative (s64 i,atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_add_negative (i, v); +} +#define atomic64_add_negative atomic64_add_negative +#endif + +#if defined(arch_atomic64_fetch_add_unless) +static inline s64 +atomic64_fetch_add_unless (atomic64_t *v,s64 a,s64 u) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_fetch_add_unless (v, a, u); +} +#define atomic64_fetch_add_unless atomic64_fetch_add_unless +#endif + +#if defined(arch_atomic64_add_unless) +static inline bool +atomic64_add_unless (atomic64_t *v,s64 a,s64 u) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_add_unless (v, a, u); +} +#define atomic64_add_unless atomic64_add_unless +#endif + +#if defined(arch_atomic64_inc_not_zero) +static inline bool +atomic64_inc_not_zero (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_inc_not_zero (v); +} +#define atomic64_inc_not_zero atomic64_inc_not_zero +#endif + +#if defined(arch_atomic64_inc_unless_negative) +static inline bool +atomic64_inc_unless_negative (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_inc_unless_negative (v); +} +#define atomic64_inc_unless_negative atomic64_inc_unless_negative +#endif + +#if defined(arch_atomic64_dec_unless_positive) +static inline bool +atomic64_dec_unless_positive (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_dec_unless_positive (v); +} +#define atomic64_dec_unless_positive atomic64_dec_unless_positive +#endif + +#if defined(arch_atomic64_dec_if_positive) +static inline s64 +atomic64_dec_if_positive (atomic64_t *v) +{ +kasan_check_write (v,sizeof (*v)); +return arch_atomic64_dec_if_positive (v); +} +#define atomic64_dec_if_positive atomic64_dec_if_positive +#endif + +#endif /* _ASM_GENERIC_ATOMIC_INSTRUMENTED_ATOMIC_H */
include/asm-generic/atomic-instrumented.h +2 -392
404 lines not on this page · raw message
Signature · 1 line
2.11.0
Quoted 37 lines · Mark Rutland
This series scripts the generation of the various atomic headers, to ensure that the various atomic APIs remain consistent, reducing the risk of human error, and simplifying future rework.
The series is based on my atomic API cleanup patches [1,2], and can be found on my atomics/generated branch [3] on kernel.org.
The first three patches are preparatory rework, with patch four introducing the infrastructure. The final three patches migrate to generated headers. The scripts themselves are mostly POSIX sh (modulo local), without bashisms, and work in dash and bash.
Per Linus request that it is possible to use git grep to inspect the atomic headers [3], the headers are committed (and not generated by kbuild). Since we now expand the fallback definitions inline, each *should* be easier to find with grep. Each header also has a comment at the top with a path to the script used to generate it.
While the diff stat looks like a huge addition, the scripting comes in at ~800 lines in total, including the fallback definitions, so we're removing ~1000 lines of hand-written code. At the same time, we fill in gaps in the
atomic_longAPI, and the instrumented atomic wrappers.Longer-term, I think things could be simplified if we were to rework the headers such that we have:
*
arch/*/include/asm/atomic.hproviding arch_atomic_*().*
include/linux/atomic-raw.hbuilding raw_atomic_*() atop of the arch_atomic_*() definitions, filling in gaps in the API. Having separatearch_andraw_namespaces would simplify the ifdeffery.*
include/linux/atomic.hbuilding atomic_*() atop of the raw_atomic_*() definitions, complete with any instrumentation. Instrumenting at this level would lower the instrumentation overhead, and would not require any ifdeffery as the whole raw_atomic_*() API would be available.
Quoted 5 lines
... I've avoided this for the time being due to the necessary churn in arch code.
Thanks,
Mark.
Wow! Nice work!
I can say that besides KASAN, we will need hooking into atomics for KMSAN and KTSAN in future. Without this it would be lots of manual work with possibility of copy-paste errors.
Quoted 79 lines
[1] https://lkml.kernel.org/r/[email protected]
[2]git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.gitatomics/api-cleanup
[3]git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.gitatomics/generated
[4] https://lkml.kernel.org/r/CA+55aFxjU0op8QLLu0n-RjHBs7gQsLvD8jcyedgw6jeZFN7B+Q@mail.gmail.comMark Rutland (7):
atomics/tty: add missingatomic_long_t* cast
atomics/treewide: rework ordering barriers
atomics: separate basic {cmp,}xchg()
atomics: add common header generation files
atomics: switch to generated fallbacks
atomics: switch to generated atomic-long
atomics: switch to generated instrumentationMAINTAINERS | 1 + arch/alpha/include/asm/atomic.h | 8 +- arch/powerpc/include/asm/atomic.h | 17 +- arch/riscv/include/asm/atomic.h | 17 +- drivers/tty/tty_ldsem.c | 2 +- include/asm-generic/atomic-instrumented-atomic.h | 1629 ++++++++++++++++ include/asm-generic/atomic-instrumented.h | 394 +--- include/asm-generic/atomic-long.h | 1150 +++++++++-- include/linux/atomic-fallback.h | 2223 ++++++++++++++++++++++ include/linux/atomic.h | 1244 +----------- scripts/atomic/atomic-tbl.sh | 186 ++ scripts/atomic/atomics.tbl | 41 + scripts/atomic/fallbacks/acquire | 9 + scripts/atomic/fallbacks/add_negative | 16 + scripts/atomic/fallbacks/add_unless | 16 + scripts/atomic/fallbacks/andnot | 7 + scripts/atomic/fallbacks/dec | 7 + scripts/atomic/fallbacks/dec_and_test | 15 + scripts/atomic/fallbacks/dec_if_positive | 15 + scripts/atomic/fallbacks/dec_unless_positive | 14 + scripts/atomic/fallbacks/fence | 11 + scripts/atomic/fallbacks/fetch_add_unless | 23 + scripts/atomic/fallbacks/inc | 7 + scripts/atomic/fallbacks/inc_and_test | 15 + scripts/atomic/fallbacks/inc_not_zero | 14 + scripts/atomic/fallbacks/inc_unless_negative | 14 + scripts/atomic/fallbacks/read_acquire | 7 + scripts/atomic/fallbacks/release | 8 + scripts/atomic/fallbacks/set_release | 7 + scripts/atomic/fallbacks/sub_and_test | 16 + scripts/atomic/fallbacks/try_cmpxchg | 11 + scripts/atomic/gen-atomic-fallback.sh | 144 ++ scripts/atomic/gen-atomic-instrumented.sh | 122 ++ scripts/atomic/gen-atomic-long.sh | 98 + 34 files changed, 5671 insertions(+), 1837 deletions(-) create mode 100644 include/asm-generic/atomic-instrumented-atomic.h create mode 100644 include/linux/atomic-fallback.h create mode 100755 scripts/atomic/atomic-tbl.sh create mode 100644 scripts/atomic/atomics.tbl create mode 100644 scripts/atomic/fallbacks/acquire create mode 100644 scripts/atomic/fallbacks/add_negative create mode 100644 scripts/atomic/fallbacks/add_unless create mode 100644 scripts/atomic/fallbacks/andnot create mode 100644 scripts/atomic/fallbacks/dec create mode 100644 scripts/atomic/fallbacks/dec_and_test create mode 100644 scripts/atomic/fallbacks/dec_if_positive create mode 100644 scripts/atomic/fallbacks/dec_unless_positive create mode 100644 scripts/atomic/fallbacks/fence create mode 100644 scripts/atomic/fallbacks/fetch_add_unless create mode 100644 scripts/atomic/fallbacks/inc create mode 100644 scripts/atomic/fallbacks/inc_and_test create mode 100644 scripts/atomic/fallbacks/inc_not_zero create mode 100644 scripts/atomic/fallbacks/inc_unless_negative create mode 100644 scripts/atomic/fallbacks/read_acquire create mode 100644 scripts/atomic/fallbacks/release create mode 100644 scripts/atomic/fallbacks/set_release create mode 100644 scripts/atomic/fallbacks/sub_and_test create mode 100644 scripts/atomic/fallbacks/try_cmpxchg create mode 100755 scripts/atomic/gen-atomic-fallback.sh create mode 100755 scripts/atomic/gen-atomic-instrumented.sh create mode 100755 scripts/atomic/gen-atomic-long.sh--
2.11.0
Mark Rutland
reviewerQuoted 38 lines · Dmitry Vyukov
Quoted 37 lines · Mark Rutland
This series scripts the generation of the various atomic headers, to ensure that the various atomic APIs remain consistent, reducing the risk of human error, and simplifying future rework.
The series is based on my atomic API cleanup patches [1,2], and can be found on my atomics/generated branch [3] on kernel.org.
The first three patches are preparatory rework, with patch four introducing the infrastructure. The final three patches migrate to generated headers. The scripts themselves are mostly POSIX sh (modulo local), without bashisms, and work in dash and bash.
Per Linus request that it is possible to use git grep to inspect the atomic headers [3], the headers are committed (and not generated by kbuild). Since we now expand the fallback definitions inline, each *should* be easier to find with grep. Each header also has a comment at the top with a path to the script used to generate it.
While the diff stat looks like a huge addition, the scripting comes in at ~800 lines in total, including the fallback definitions, so we're removing ~1000 lines of hand-written code. At the same time, we fill in gaps in the
atomic_longAPI, and the instrumented atomic wrappers.Longer-term, I think things could be simplified if we were to rework the headers such that we have:
*
arch/*/include/asm/atomic.hproviding arch_atomic_*().*
include/linux/atomic-raw.hbuilding raw_atomic_*() atop of the arch_atomic_*() definitions, filling in gaps in the API. Having separatearch_andraw_namespaces would simplify the ifdeffery.*
include/linux/atomic.hbuilding atomic_*() atop of the raw_atomic_*() definitions, complete with any instrumentation. Instrumenting at this level would lower the instrumentation overhead, and would not require any ifdeffery as the whole raw_atomic_*() API would be available.
Quoted 7 lines
Quoted 5 lines
... I've avoided this for the time being due to the necessary churn in arch code.
Thanks,
Mark.Wow! Nice work!
Thanks!
Quoted 3 lines
I can say that besides KASAN, we will need hooking into atomics for KMSAN and KTSAN in future. Without this it would be lots of manual work with possibility of copy-paste errors.
Indeed!
This was largely driven by wanting the arm64 atomics instrumented, and generating that does end up easier to get right than manually expanding all the acquire/release/relaxed ifdeffery manually.
First we need to get the preparatory patches [1,2] merged. Those have had a few fixups since they were last posted, so I'll send an updated version come v4.18-rc1 unless the atomics maintainers really want to queue those ASAP.
There'll be some additional prep work for instrumentation on arm64, too (e.g. fiddling with the (cmp)xchg instrumentation), so I'll look into that in the mean time.
Thanks,
Mark.
Quoted 4 lines
Quoted 4 lines
[1] https://lkml.kernel.org/r/[email protected]
[2]git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.gitatomics/api-cleanup
[3]git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.gitatomics/generated
[4] https://lkml.kernel.org/r/CA+55aFxjU0op8QLLu0n-RjHBs7gQsLvD8jcyedgw6jeZFN7B+Q@mail.gmail.com
Peter Zijlstra
maintainerQuoted 7 lines · Dmitry Vyukov
Quoted 4 lines · Mark Rutland
While the diff stat looks like a huge addition, the scripting comes in at ~800 lines in total, including the fallback definitions, so we're removing ~1000 lines of hand-written code. At the same time, we fill in gaps in the
atomic_longAPI, and the instrumented atomic wrappers.Wow! Nice work!
Indeed, looking good Mark, thanks!
Peter Zijlstra
maintainerQuoted 9 lines · Mark Rutland
Longer-term, I think things could be simplified if we were to rework the headers such that we have:
*
arch/*/include/asm/atomic.hproviding arch_atomic_*().*
include/linux/atomic-raw.hbuilding raw_atomic_*() atop of the arch_atomic_*() definitions, filling in gaps in the API. Having separatearch_andraw_namespaces would simplify the ifdeffery.
Quoted 7 lines
*
include/linux/atomic.hbuilding atomic_*() atop of the raw_atomic_*() definitions, complete with any instrumentation. Instrumenting at this level would lower the instrumentation overhead, and would not require any ifdeffery as the whole raw_atomic_*() API would be available.... I've avoided this for the time being due to the necessary churn in arch code.
I'm not entirely sure I get the point of raw_atomic, we only need to instrument the arch_atomic bits, right? When those are done, everything that's build on top will also automagically be instrumented.
Mark Rutland
reviewerQuoted 15 lines · Peter Zijlstra
Quoted 14 lines · Mark Rutland
Longer-term, I think things could be simplified if we were to rework the headers such that we have:
*
arch/*/include/asm/atomic.hproviding arch_atomic_*().*
include/linux/atomic-raw.hbuilding raw_atomic_*() atop of the arch_atomic_*() definitions, filling in gaps in the API. Having separatearch_andraw_namespaces would simplify the ifdeffery.*
include/linux/atomic.hbuilding atomic_*() atop of the raw_atomic_*() definitions, complete with any instrumentation. Instrumenting at this level would lower the instrumentation overhead, and would not require any ifdeffery as the whole raw_atomic_*() API would be available.
Quoted 5 lines
Quoted 2 lines
... I've avoided this for the time being due to the necessary churn in arch code.
I'm not entirely sure I get the point of
raw_atomic, we only need to instrument thearch_atomicbits, right?
Well, we only *need* to instrument the top-level atomic. KASAN (and KTSAN/KMSAN) only care that we're touching a memory location, and not how many times we happen to touch it.
e.g. when we have fallbacks we might have:
static inline int atomic_fetch_add_unless(atomic_t *v, int a, int u)
{
int c = atomic_read(v);
do {
if (unlikely(c == u))
break;
} while (!atomic_try_cmpxchg(v, &c, c + a));
return c;
}... where:
* atomic_read() is a simple wrapper around arch_atomic_read(), with instrumentation.
* atomic_try_cmpxchg() might be a simple wrapper around arch_atomic_try_cmpxchg, or a wrapper around atomic_cmpxchg(), which calls arch_atomic_cmpxchg(). Either way, one of the two is instrumented.
... so each call to atomic_fetch_add_unless() calls the instrumentation at least once for the read, and at least once per retry. Whereas if implemented in arch code, it only calls the instrumentation once.
Quoted 2 lines
When those are done, everything that's build on top will also automagically be instrumented.
Sure, it all works, it's just less than optimal as above, and also means that we have to duplicate the ifdeffery for optional atomics -- once in the instrumented atomics, then in the "real" atomics.
Whereas if we filled in the raw atomics atop of the arch atomics, everything above that can assume the whole API is present, no ifdeffery required.
Thanks,
Mark.
Peter Zijlstra
maintainerQuoted 7 lines · Mark Rutland
Sure, it all works, it's just less than optimal as above, and also means that we have to duplicate the ifdeffery for optional atomics -- once in the instrumented atomics, then in the "real" atomics.
Whereas if we filled in the raw atomics atop of the arch atomics, everything above that can assume the whole API is present, no ifdeffery required.
Aah, I see your point now. I don't think performance is a particular concern when you enable K*SAN, but getting rid of a fair bunch of ifdeffery is always nice.
Mark Rutland
reviewerQuoted 6 lines · Peter Zijlstra
Quoted 4 lines · Mark Rutland
Sure, it all works, it's just less than optimal as above, and also means that we have to duplicate the ifdeffery for optional atomics -- once in the instrumented atomics, then in the "real" atomics.
Quoted 7 lines
Quoted 3 lines
Whereas if we filled in the raw atomics atop of the arch atomics, everything above that can assume the whole API is present, no ifdeffery required.
Aah, I see your point now. I don't think performance is a particular concern when you enable K*SAN, but getting rid of a fair bunch of ifdeffery is always nice.
I agree that performance isn't a concern there when debugging, but I would like to keep the overhead down when fuzzing.
Regardless, we'd have to move arches over to arch_atomic_* first, and once that's done the raw_atomic_* stuff is fairly easy to implement by reworking the scripts.
Thanks,
Mark.