public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] atomic/bitops: Clarify ordering semantics for failed test_and_{}_bit()
@ 2018-02-13 13:30 Will Deacon
  2018-02-13 13:51 ` Peter Zijlstra
  2018-02-13 15:28 ` [tip:locking/urgent] locking/atomic/bitops: Document and clarify " tip-bot for Will Deacon
  0 siblings, 2 replies; 3+ messages in thread
From: Will Deacon @ 2018-02-13 13:30 UTC (permalink / raw)
  To: linux-kernel; +Cc: Will Deacon, Peter Zijlstra, Paul E. McKenney

A test_and_{}_bit() operation fails if the value of the bit is such that
the modification does not take place. For example, if test_and_set_bit()
returns 1. In these cases, follow the behaviour of cmpxchg and allow the
operation to be unordered. This also applies to test_and_set_bit_lock()
if the lock is found to be be taken already.

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
---
 Documentation/atomic_bitops.txt   | 7 ++++++-
 include/asm-generic/bitops/lock.h | 3 ++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/Documentation/atomic_bitops.txt b/Documentation/atomic_bitops.txt
index 5550bfdcce5f..be70b32c95d9 100644
--- a/Documentation/atomic_bitops.txt
+++ b/Documentation/atomic_bitops.txt
@@ -58,7 +58,12 @@ Like with atomic_t, the rule of thumb is:
 
  - RMW operations that have a return value are fully ordered.
 
-Except for test_and_set_bit_lock() which has ACQUIRE semantics and
+ - RMW operations that are conditional are unordered on FAILURE,
+   otherwise the above rules apply. In the case of test_and_{}_bit() operations,
+   if the bit in memory is unchanged by the operation then it is deemed to have
+   failed.
+
+Except for a successful test_and_set_bit_lock() which has ACQUIRE semantics and
 clear_bit_unlock() which has RELEASE semantics.
 
 Since a platform only has a single means of achieving atomic operations
diff --git a/include/asm-generic/bitops/lock.h b/include/asm-generic/bitops/lock.h
index bc397573c43a..67ab280ad134 100644
--- a/include/asm-generic/bitops/lock.h
+++ b/include/asm-generic/bitops/lock.h
@@ -7,7 +7,8 @@
  * @nr: Bit to set
  * @addr: Address to count from
  *
- * This operation is atomic and provides acquire barrier semantics.
+ * This operation is atomic and provides acquire barrier semantics if
+ * the returned value is 0.
  * It can be used to implement bit locks.
  */
 #define test_and_set_bit_lock(nr, addr)	test_and_set_bit(nr, addr)
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] atomic/bitops: Clarify ordering semantics for failed test_and_{}_bit()
  2018-02-13 13:30 [PATCH] atomic/bitops: Clarify ordering semantics for failed test_and_{}_bit() Will Deacon
@ 2018-02-13 13:51 ` Peter Zijlstra
  2018-02-13 15:28 ` [tip:locking/urgent] locking/atomic/bitops: Document and clarify " tip-bot for Will Deacon
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2018-02-13 13:51 UTC (permalink / raw)
  To: Will Deacon; +Cc: linux-kernel, Paul E. McKenney

On Tue, Feb 13, 2018 at 01:30:19PM +0000, Will Deacon wrote:
> A test_and_{}_bit() operation fails if the value of the bit is such that
> the modification does not take place. For example, if test_and_set_bit()
> returns 1. In these cases, follow the behaviour of cmpxchg and allow the
> operation to be unordered. This also applies to test_and_set_bit_lock()
> if the lock is found to be be taken already.

You also looked at a bunch of users, right? And while you found some
dodgy ones, they were not more broken because of this IIRC.

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>

> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
> Signed-off-by: Will Deacon <will.deacon@arm.com>
> ---
>  Documentation/atomic_bitops.txt   | 7 ++++++-
>  include/asm-generic/bitops/lock.h | 3 ++-
>  2 files changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/atomic_bitops.txt b/Documentation/atomic_bitops.txt
> index 5550bfdcce5f..be70b32c95d9 100644
> --- a/Documentation/atomic_bitops.txt
> +++ b/Documentation/atomic_bitops.txt
> @@ -58,7 +58,12 @@ Like with atomic_t, the rule of thumb is:
>  
>   - RMW operations that have a return value are fully ordered.
>  
> -Except for test_and_set_bit_lock() which has ACQUIRE semantics and
> + - RMW operations that are conditional are unordered on FAILURE,
> +   otherwise the above rules apply. In the case of test_and_{}_bit() operations,
> +   if the bit in memory is unchanged by the operation then it is deemed to have
> +   failed.
> +
> +Except for a successful test_and_set_bit_lock() which has ACQUIRE semantics and
>  clear_bit_unlock() which has RELEASE semantics.
>  
>  Since a platform only has a single means of achieving atomic operations
> diff --git a/include/asm-generic/bitops/lock.h b/include/asm-generic/bitops/lock.h
> index bc397573c43a..67ab280ad134 100644
> --- a/include/asm-generic/bitops/lock.h
> +++ b/include/asm-generic/bitops/lock.h
> @@ -7,7 +7,8 @@
>   * @nr: Bit to set
>   * @addr: Address to count from
>   *
> - * This operation is atomic and provides acquire barrier semantics.
> + * This operation is atomic and provides acquire barrier semantics if
> + * the returned value is 0.
>   * It can be used to implement bit locks.
>   */
>  #define test_and_set_bit_lock(nr, addr)	test_and_set_bit(nr, addr)
> -- 
> 2.1.4
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip:locking/urgent] locking/atomic/bitops: Document and clarify ordering semantics for failed test_and_{}_bit()
  2018-02-13 13:30 [PATCH] atomic/bitops: Clarify ordering semantics for failed test_and_{}_bit() Will Deacon
  2018-02-13 13:51 ` Peter Zijlstra
@ 2018-02-13 15:28 ` tip-bot for Will Deacon
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Will Deacon @ 2018-02-13 15:28 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: torvalds, peterz, will.deacon, paulmck, hpa, tglx, linux-kernel,
	mingo

Commit-ID:  61e02392d3c7ecac1f91c0a90a8043d67e081846
Gitweb:     https://git.kernel.org/tip/61e02392d3c7ecac1f91c0a90a8043d67e081846
Author:     Will Deacon <will.deacon@arm.com>
AuthorDate: Tue, 13 Feb 2018 13:30:19 +0000
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 13 Feb 2018 14:55:53 +0100

locking/atomic/bitops: Document and clarify ordering semantics for failed test_and_{}_bit()

A test_and_{}_bit() operation fails if the value of the bit is such that
the modification does not take place. For example, if test_and_set_bit()
returns 1. In these cases, follow the behaviour of cmpxchg and allow the
operation to be unordered. This also applies to test_and_set_bit_lock()
if the lock is found to be be taken already.

Signed-off-by: Will Deacon <will.deacon@arm.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1518528619-20049-1-git-send-email-will.deacon@arm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 Documentation/atomic_bitops.txt   | 7 ++++++-
 include/asm-generic/bitops/lock.h | 3 ++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/Documentation/atomic_bitops.txt b/Documentation/atomic_bitops.txt
index 5550bfdc..be70b32 100644
--- a/Documentation/atomic_bitops.txt
+++ b/Documentation/atomic_bitops.txt
@@ -58,7 +58,12 @@ Like with atomic_t, the rule of thumb is:
 
  - RMW operations that have a return value are fully ordered.
 
-Except for test_and_set_bit_lock() which has ACQUIRE semantics and
+ - RMW operations that are conditional are unordered on FAILURE,
+   otherwise the above rules apply. In the case of test_and_{}_bit() operations,
+   if the bit in memory is unchanged by the operation then it is deemed to have
+   failed.
+
+Except for a successful test_and_set_bit_lock() which has ACQUIRE semantics and
 clear_bit_unlock() which has RELEASE semantics.
 
 Since a platform only has a single means of achieving atomic operations
diff --git a/include/asm-generic/bitops/lock.h b/include/asm-generic/bitops/lock.h
index bc39757..67ab280 100644
--- a/include/asm-generic/bitops/lock.h
+++ b/include/asm-generic/bitops/lock.h
@@ -7,7 +7,8 @@
  * @nr: Bit to set
  * @addr: Address to count from
  *
- * This operation is atomic and provides acquire barrier semantics.
+ * This operation is atomic and provides acquire barrier semantics if
+ * the returned value is 0.
  * It can be used to implement bit locks.
  */
 #define test_and_set_bit_lock(nr, addr)	test_and_set_bit(nr, addr)

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-02-13 15:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-13 13:30 [PATCH] atomic/bitops: Clarify ordering semantics for failed test_and_{}_bit() Will Deacon
2018-02-13 13:51 ` Peter Zijlstra
2018-02-13 15:28 ` [tip:locking/urgent] locking/atomic/bitops: Document and clarify " tip-bot for Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox