Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-05 Thread Peter Zijlstra
On Fri, Nov 02, 2018 at 07:19:15PM +0300, Andrey Ryabinin wrote: > UBSAN warns about signed overflows despite -fno-strict-overflow if gcc > version is < 8. > I have learned recently that UBSAN in GCC 8 ignores signed overflows if > -fno-strict-overflow of fwrapv is used. > > $ cat

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-05 Thread Peter Zijlstra
On Fri, Nov 02, 2018 at 07:19:15PM +0300, Andrey Ryabinin wrote: > UBSAN warns about signed overflows despite -fno-strict-overflow if gcc > version is < 8. I have learned recently that UBSAN in GCC 8 ignores > signed overflows if -fno-strict-overflow of fwrapv is used. Ah, good. > We can

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-02 Thread Andrey Ryabinin
On 11/01/2018 07:32 PM, Peter Zijlstra wrote: > On Thu, Nov 01, 2018 at 03:22:15PM +, Trond Myklebust wrote: >> On Thu, 2018-11-01 at 15:59 +0100, Peter Zijlstra wrote: >>> On Thu, Nov 01, 2018 at 01:18:46PM +, Mark Rutland wrote: > > My one question (and the reason why I went with

RE: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-02 Thread David Laight
From: Paul E. McKenney > Sent: 01 November 2018 17:02 ... > And there is a push to define C++ signed arithmetic as 2s complement, > but there are still 1s complement systems with C compilers. Just not > C++ compilers. Legacy... Hmmm... I've used C compilers for DSPs where signed integer

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-02 Thread Paul E. McKenney
On Fri, Nov 02, 2018 at 01:23:28PM +0100, Peter Zijlstra wrote: > On Fri, Nov 02, 2018 at 10:56:31AM +, David Laight wrote: > > From: Paul E. McKenney > > > Sent: 01 November 2018 17:02 > > ... > > > And there is a push to define C++ signed arithmetic as 2s complement, > > > but there are

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-02 Thread Paul E. McKenney
On Fri, Nov 02, 2018 at 10:56:31AM +, David Laight wrote: > From: Paul E. McKenney > > Sent: 01 November 2018 17:02 > ... > > And there is a push to define C++ signed arithmetic as 2s complement, > > but there are still 1s complement systems with C compilers. Just not > > C++ compilers.

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-02 Thread Peter Zijlstra
On Fri, Nov 02, 2018 at 10:56:31AM +, David Laight wrote: > From: Paul E. McKenney > > Sent: 01 November 2018 17:02 > ... > > And there is a push to define C++ signed arithmetic as 2s complement, > > but there are still 1s complement systems with C compilers. Just not > > C++ compilers.

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-01 Thread Paul E. McKenney
On Thu, Nov 01, 2018 at 10:38:34PM +0100, Peter Zijlstra wrote: > On Thu, Nov 01, 2018 at 01:29:10PM -0700, Paul E. McKenney wrote: > > On Thu, Nov 01, 2018 at 06:27:39PM +0100, Peter Zijlstra wrote: > > > On Thu, Nov 01, 2018 at 06:14:32PM +0100, Peter Zijlstra wrote: > > > > > This reminds me of

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-01 Thread Peter Zijlstra
On Thu, Nov 01, 2018 at 06:46:50PM +0100, Dmitry Vyukov wrote: > If there is a warning that we don't want to see at all, then we can > disable it. It supposed to be a useful tool, rather than a thing in > itself that lives own life. We already I think removed 1 particularly > noisy warning and

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-01 Thread Peter Zijlstra
On Thu, Nov 01, 2018 at 01:29:10PM -0700, Paul E. McKenney wrote: > On Thu, Nov 01, 2018 at 06:27:39PM +0100, Peter Zijlstra wrote: > > On Thu, Nov 01, 2018 at 06:14:32PM +0100, Peter Zijlstra wrote: > > > > This reminds me of this so silly patch :/ > > > > > > > >

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-01 Thread Paul E. McKenney
On Thu, Nov 01, 2018 at 06:27:39PM +0100, Peter Zijlstra wrote: > On Thu, Nov 01, 2018 at 06:14:32PM +0100, Peter Zijlstra wrote: > > > This reminds me of this so silly patch :/ > > > > > >

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-01 Thread Paul E. McKenney
On Thu, Nov 01, 2018 at 06:14:32PM +0100, Peter Zijlstra wrote: > On Thu, Nov 01, 2018 at 09:59:38AM -0700, Eric Dumazet wrote: > > On 11/01/2018 09:32 AM, Peter Zijlstra wrote: > > > > >> Anyhow, if the atomic maintainers are willing to stand up and state for > > >> the record that the atomic

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-01 Thread Paul E. McKenney
On Thu, Nov 01, 2018 at 06:18:46PM +0100, Peter Zijlstra wrote: > On Thu, Nov 01, 2018 at 10:01:46AM -0700, Paul E. McKenney wrote: > > On Thu, Nov 01, 2018 at 05:32:12PM +0100, Peter Zijlstra wrote: > > > On Thu, Nov 01, 2018 at 03:22:15PM +, Trond Myklebust wrote: > > > > On Thu, 2018-11-01

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-01 Thread Paul E. McKenney
On Thu, Nov 01, 2018 at 05:32:12PM +0100, Peter Zijlstra wrote: > On Thu, Nov 01, 2018 at 03:22:15PM +, Trond Myklebust wrote: > > On Thu, 2018-11-01 at 15:59 +0100, Peter Zijlstra wrote: > > > On Thu, Nov 01, 2018 at 01:18:46PM +, Mark Rutland wrote: > > > > > > My one question (and the

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-01 Thread Paul Burton
Hi Trond, On Thu, Nov 01, 2018 at 12:17:31AM +, Trond Myklebust wrote: > On Wed, 2018-10-31 at 23:32 +, Paul Burton wrote: > > In this particular case I have no idea why > > net/sunrpc/auth_gss/gss_krb5_seal.c is using cmpxchg64() at all. It's > > essentially reinventing

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-01 Thread Peter Zijlstra
On Thu, Nov 01, 2018 at 06:14:32PM +0100, Peter Zijlstra wrote: > > This reminds me of this so silly patch :/ > > > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=adb03115f4590baa280ddc440a8eff08a6be0cb7 You'd probably want to write it like so; +- some

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-01 Thread Peter Zijlstra
On Thu, Nov 01, 2018 at 10:01:46AM -0700, Paul E. McKenney wrote: > On Thu, Nov 01, 2018 at 05:32:12PM +0100, Peter Zijlstra wrote: > > On Thu, Nov 01, 2018 at 03:22:15PM +, Trond Myklebust wrote: > > > On Thu, 2018-11-01 at 15:59 +0100, Peter Zijlstra wrote: > > > > On Thu, Nov 01, 2018 at

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-01 Thread Peter Zijlstra
On Thu, Nov 01, 2018 at 09:59:38AM -0700, Eric Dumazet wrote: > On 11/01/2018 09:32 AM, Peter Zijlstra wrote: > > >> Anyhow, if the atomic maintainers are willing to stand up and state for > >> the record that the atomic counters are guaranteed to wrap modulo 2^n > >> just like unsigned integers,

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-01 Thread Eric Dumazet
On 11/01/2018 09:32 AM, Peter Zijlstra wrote: >> Anyhow, if the atomic maintainers are willing to stand up and state for >> the record that the atomic counters are guaranteed to wrap modulo 2^n >> just like unsigned integers, then I'm happy to take Paul's patch. > > I myself am certainly

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-01 Thread Peter Zijlstra
On Thu, Nov 01, 2018 at 03:22:15PM +, Trond Myklebust wrote: > On Thu, 2018-11-01 at 15:59 +0100, Peter Zijlstra wrote: > > On Thu, Nov 01, 2018 at 01:18:46PM +, Mark Rutland wrote: > > > > My one question (and the reason why I went with cmpxchg() in the > > > > first place) would be

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-01 Thread Guenter Roeck
On Thu, Nov 01, 2018 at 06:30:08AM +, Trond Myklebust wrote: [ ... ] > > > > For my part I agree that this would be a much better solution. The > > argument > > that it is not always absolutely guaranteed that atomics don't wrap > > doesn't > > really hold for me because it looks like they

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-01 Thread Trond Myklebust
On Thu, 2018-11-01 at 15:59 +0100, Peter Zijlstra wrote: > On Thu, Nov 01, 2018 at 01:18:46PM +, Mark Rutland wrote: > > > My one question (and the reason why I went with cmpxchg() in the > > > first > > > place) would be about the overflow behaviour for > > > atomic_fetch_inc() and > > >

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-01 Thread Peter Zijlstra
On Thu, Nov 01, 2018 at 01:18:46PM +, Mark Rutland wrote: > > My one question (and the reason why I went with cmpxchg() in the first > > place) would be about the overflow behaviour for atomic_fetch_inc() and > > friends. I believe those functions should be OK on x86, so that when we > >

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-01 Thread Mark Rutland
[adding the atomic maintainers] On Thu, Nov 01, 2018 at 12:17:31AM +, Trond Myklebust wrote: > On Wed, 2018-10-31 at 23:32 +, Paul Burton wrote: > > (Copying SunRPC & net maintainers.) > > > > Hi Guenter, > > > > On Wed, Oct 31, 2018 at 03:02:53PM -0700, Guenter Roeck wrote: > > > The

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-01 Thread Trond Myklebust
On Wed, 2018-10-31 at 18:18 -0700, Guenter Roeck wrote: > On 10/31/18 4:32 PM, Paul Burton wrote: > > (Copying SunRPC & net maintainers.) > > > > Hi Guenter, > > > > On Wed, Oct 31, 2018 at 03:02:53PM -0700, Guenter Roeck wrote: > > > The alternatives I can see are > > > - Do not use cmpxchg64()

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-10-31 Thread Guenter Roeck
On 10/31/18 4:32 PM, Paul Burton wrote: (Copying SunRPC & net maintainers.) Hi Guenter, On Wed, Oct 31, 2018 at 03:02:53PM -0700, Guenter Roeck wrote: The alternatives I can see are - Do not use cmpxchg64() outside architecture code (ie drop its use from the offending driver, and keep

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-10-31 Thread Trond Myklebust
Hi Paul, On Wed, 2018-10-31 at 23:32 +, Paul Burton wrote: > (Copying SunRPC & net maintainers.) > > Hi Guenter, > > On Wed, Oct 31, 2018 at 03:02:53PM -0700, Guenter Roeck wrote: > > The alternatives I can see are > > - Do not use cmpxchg64() outside architecture code (ie drop its use > >

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-10-31 Thread Paul Burton
(Copying SunRPC & net maintainers.) Hi Guenter, On Wed, Oct 31, 2018 at 03:02:53PM -0700, Guenter Roeck wrote: > The alternatives I can see are > - Do not use cmpxchg64() outside architecture code (ie drop its use from > the offending driver, and keep doing the same whenever the problem comes

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-10-31 Thread Guenter Roeck
On Wed, Oct 31, 2018 at 09:32:43PM +, Paul Burton wrote: > Hi Guenter, > > On Wed, Oct 31, 2018 at 12:52:18PM -0700, Guenter Roeck wrote: > > +/* > > + * Generic version of __cmpxchg_u64, to be used for cmpxchg64(). > > + * Takes u64 parameters. > > + */ > > +u64 __cmpxchg_u64(u64 *ptr, u64

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-10-31 Thread Paul Burton
Hi Guenter, On Wed, Oct 31, 2018 at 12:52:18PM -0700, Guenter Roeck wrote: > +/* > + * Generic version of __cmpxchg_u64, to be used for cmpxchg64(). > + * Takes u64 parameters. > + */ > +u64 __cmpxchg_u64(u64 *ptr, u64 old, u64 new) > +{ > + raw_spinlock_t *lock = lock_addr(ptr); > +