Documentation/atomic_t: Clarify signed vs unsigned
Peter Zijlstra
maintainerPATCH 1/1 Documentation/atomic_t: Clarify signed vs unsigned
Clarify the whole signed vs unsigned issue for atomic_t.
There has been enough confusion on this topic to warrant a few explicit words I feel.
--- Documentation/atomic_t.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
Documentation/atomic_t.txt +17 -0
@@ -56,6 +56,23 @@ The 'full' API consists of (atomic64_ and atomic_long_ prefixes omitted for smp_mb__{before,after}_atomic() +TYPES (signed vs unsigned) +----- + +While atomic_t, atomic_long_t and atomic64_t use int, long and s64 +respectively (for hysterical raisins), the kernel uses -fno-strict-overflow +(which implies -fwrapv) and defines signed overflow to behave like +2s-complement. + +Therefore, an explicitly unsigned variant of the atomic ops is strictly +unnecessary and we can simply cast, there is no UB. + +There was a bug in UBSAN prior to GCC-8 that would generate UB warnings for +signed types. + +With this we also conform to the C/C++ _Atomic behaviour and things like +P1236R1. + SEMANTICS ---------
Quoted 26 lines · Peter Zijlstra
Clarify the whole signed vs unsigned issue for
atomic_t.There has been enough confusion on this topic to warrant a few explicit words I feel.
Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- Documentation/atomic_t.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)Documentation/atomic_t.txt +7
-0@@ -56,6 +56,23 @@ The 'full' API consists of (atomic64_ and atomic_long_ prefixes omitted for smp_mb__{before,after}_atomic() +TYPES (signed vs unsigned) +----- + +While atomic_t, atomic_long_t and atomic64_t use int, long and s64 +respectively (for hysterical raisins), the kernel uses -fno-strict-overflow +(which implies -fwrapv) and defines signed overflow to behave like +2s-complement.
Documentation/atomic_t.txt The 'full' API consists of (atomic64_ and atomic_long_ prefixes omitted for · line 75
Quoted 10 lines
Documentation/atomic_t.txt +10
-0+ +Therefore, an explicitly unsigned variant of the atomic ops is strictly +unnecessary and we can simply cast, there is no UB. + +There was a bug in UBSAN prior to GCC-8 that would generate UB warnings for +signed types. + +With this we also conform to the C/C++ _Atomic behaviour and things like +P1236R1. +
Will
Paul E. McKenney
AppliedQuoted 31 lines · Will Deacon
Quoted 30 lines · Peter Zijlstra
Clarify the whole signed vs unsigned issue for
atomic_t.There has been enough confusion on this topic to warrant a few explicit words I feel.
Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- Documentation/atomic_t.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)Documentation/atomic_t.txt +11
-0@@ -56,6 +56,23 @@ The 'full' API consists of (atomic64_ and atomic_long_ prefixes omitted for smp_mb__{before,after}_atomic() +TYPES (signed vs unsigned) +----- + +While atomic_t, atomic_long_t and atomic64_t use int, long and s64 +respectively (for hysterical raisins), the kernel uses -fno-strict-overflow +(which implies -fwrapv) and defines signed overflow to behave like +2s-complement. + +Therefore, an explicitly unsigned variant of the atomic ops is strictly +unnecessary and we can simply cast, there is no UB. +
Quoted 8 lines
Documentation/atomic_t.txt The 'full' API consists of (atomic64_ and atomic_long_ prefixes omitted for · line 75
Quoted 6 lines
Documentation/atomic_t.txt +6
-0+There was a bug in UBSAN prior to GCC-8 that would generate UB warnings for +signed types. + +With this we also conform to the C/C++ _Atomic behaviour and things like +P1236R1. +Acked-by Will Deacon <[email protected]>
Queued with Will's ack, thank you both!
Thanx, Paul
Quoted 7 lines · Peter Zijlstra
Clarify the whole signed vs unsigned issue for
atomic_t.There has been enough confusion on this topic to warrant a few explicit words I feel.
Signed-off-by Peter Zijlstra (Intel) <[email protected]>
FWIW
Regards,
Boqun
Quoted 32 lines
--- Documentation/atomic_t.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)Documentation/atomic_t.txt +17
-0@@ -56,6 +56,23 @@ The 'full' API consists of (atomic64_ and atomic_long_ prefixes omitted for smp_mb__{before,after}_atomic() +TYPES (signed vs unsigned) +----- + +While atomic_t, atomic_long_t and atomic64_t use int, long and s64 +respectively (for hysterical raisins), the kernel uses -fno-strict-overflow +(which implies -fwrapv) and defines signed overflow to behave like +2s-complement. + +Therefore, an explicitly unsigned variant of the atomic ops is strictly +unnecessary and we can simply cast, there is no UB. + +There was a bug in UBSAN prior to GCC-8 that would generate UB warnings for +signed types. + +With this we also conform to the C/C++ _Atomic behaviour and things like +P1236R1. + SEMANTICS ---------
Paul E. McKenney
AppliedQuoted 4 lines · Boqun Feng
Quoted 3 lines · Peter Zijlstra
Clarify the whole signed vs unsigned issue for
atomic_t.
Quoted 8 lines
Quoted 4 lines
There has been enough confusion on this topic to warrant a few explicit words I feel.
Signed-off-by Peter Zijlstra (Intel) <[email protected]>FWIW
Acked-by Boqun Feng <[email protected]>
Applied, thank you!
Thanx, Paul
Quoted 35 lines
Regards,
BoqunQuoted 32 lines
--- Documentation/atomic_t.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)Documentation/atomic_t.txt +17
-0@@ -56,6 +56,23 @@ The 'full' API consists of (atomic64_ and atomic_long_ prefixes omitted for smp_mb__{before,after}_atomic() +TYPES (signed vs unsigned) +----- + +While atomic_t, atomic_long_t and atomic64_t use int, long and s64 +respectively (for hysterical raisins), the kernel uses -fno-strict-overflow +(which implies -fwrapv) and defines signed overflow to behave like +2s-complement. + +Therefore, an explicitly unsigned variant of the atomic ops is strictly +unnecessary and we can simply cast, there is no UB. + +There was a bug in UBSAN prior to GCC-8 that would generate UB warnings for +signed types. + +With this we also conform to the C/C++ _Atomic behaviour and things like +P1236R1. + SEMANTICS ---------
Quoted 16 lines · Peter Zijlstra
Clarify the whole signed vs unsigned issue for
atomic_t.There has been enough confusion on this topic to warrant a few explicit words I feel.
Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- Documentation/atomic_t.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)Documentation/atomic_t.txt +0
-0
Documentation/atomic_t.txt The 'full' API consists of (atomic64_ and atomic_long_ prefixes omitted for · line 59
Quoted 4 lines
Documentation/atomic_t.txt +1
-0@@ -56,6 +56,23 @@ The 'full' API consists of (atomic64_ and atomic_long_ prefixes omitted for smp_mb__{before,after}_atomic() +TYPES (signed vs unsigned)
s/vs/vs.
Documentation/atomic_t.txt The 'full' API consists of (atomic64_ and atomic_long_ prefixes omitted for · line 68
Quoted 9 lines
Documentation/atomic_t.txt +9
-0+----- + +While atomic_t, atomic_long_t and atomic64_t use int, long and s64 +respectively (for hysterical raisins), the kernel uses -fno-strict-overflow +(which implies -fwrapv) and defines signed overflow to behave like +2s-complement. + +Therefore, an explicitly unsigned variant of the atomic ops is strictly +unnecessary and we can simply cast, there is no UB.
s/UB/Undefined Behavior
Had to read that twice. Acronyms Seriously Suck.
Documentation/atomic_t.txt The 'full' API consists of (atomic64_ and atomic_long_ prefixes omitted for · line 74
Quoted 6 lines
Documentation/atomic_t.txt +6
-0+ +There was a bug in UBSAN prior to GCC-8 that would generate UB warnings for +signed types. + +With this we also conform to the C/C++ _Atomic behaviour and things like +P1236R1.
Thanks,
Ingo