lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Ybcpz1XIU8+EtSV3@FVFF77S0Q05N>
Date:   Mon, 13 Dec 2021 11:09:03 +0000
From:   Mark Rutland <mark.rutland@....com>
To:     Peter Zijlstra <peterz@...radead.org>
Cc:     will@...nel.org, boqun.feng@...il.com,
        linux-kernel@...r.kernel.org, x86@...nel.org, elver@...gle.com,
        keescook@...omium.org, hch@...radead.org,
        torvalds@...ux-foundation.org, axboe@...nel.dk
Subject: Re: [PATCH v2 3/9] atomic: Introduce
 atomic_{inc,dec,dec_and_test}_overflow()

On Mon, Dec 13, 2021 at 11:59:48AM +0100, Peter Zijlstra wrote:
> On Mon, Dec 13, 2021 at 10:06:01AM +0000, Mark Rutland wrote:
> > On Fri, Dec 10, 2021 at 05:16:21PM +0100, Peter Zijlstra wrote:
> 
> > > +#ifndef arch_atomic_inc_overflow
> > > +#define arch_atomic_inc_overflow(_v, _label)				\
> > > +do {									\
> > > +	int __old = arch_atomic_fetch_inc(_v);			\
> > > +	if (unlikely(__old <= 0))					\
> > > +		goto _label;						\
> > > +} while (0)
> > > +#endif
> > > +
> > > +#ifndef arch_atomic_dec_overflow
> > > +#define arch_atomic_dec_overflow(_v, _label)				\
> > > +do {									\
> > > +	int __new = arch_atomic_dec_return(_v);			\
> > > +	if (unlikely(__new <= 0))					\
> > > +		goto _label;						\
> > > +} while (0)
> > > +#endif
> > > +
> > > +#ifndef arch_atomic_dec_and_test_overflow
> > > +#define arch_atomic_dec_and_test_overflow(_v, _label)		\
> > > +({									\
> > > +	bool __ret = false;						\
> > > +	int __new = arch_atomic_dec_return(_v);			\
> > > +	if (unlikely(__new < 0))					\
> > > +		goto _label;						\
> > > +	if (unlikely(__new == 0))					\
> > > +		__ret = true;						\
> > > +	__ret;								\
> > > +})
> > > +#endif
> > 
> > I had wanted to move at least part of this to a function to ensure
> > single-evaluation and avoid accidental symbol aliasing, but (as we discussed
> > over IRC) I couldn't find any good way to do so, and given this is sufficiently
> > specialise I think we should be ok with this as-is. It's certainly no worse
> > than the existing stuff for xchg/cmpxchg.
> 
> Right, as you know I tried the same :-) Anyway, the above macros should
> be free of multi-evaluation issues, both _v and _label are only used the
> once. Aliassing is always a possibility but minimized by __ prefixing
> the local variables.

Agreed! I just wanted something archived in the thread mentioning that this was
the only practical option.

I agree that as this stands we're not doing anything sufficiently complicated
enough to worry about multi-evaluation, and that the underscores should be
sufficient to avoid aliasing in practice.

Mark.


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ