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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANpmjNPfFXjwb1-ou3M6s38w=uXgHioK1d=mMSB3_HjHjV2waw@mail.gmail.com>
Date: Fri, 7 Feb 2025 10:50:18 +0100
From: Marco Elver <elver@...gle.com>
To: Peter Zijlstra <peterz@...radead.org>
Cc: "Paul E. McKenney" <paulmck@...nel.org>, Alexander Potapenko <glider@...gle.com>, 
	Bart Van Assche <bvanassche@....org>, Bill Wendling <morbo@...gle.com>, Boqun Feng <boqun.feng@...il.com>, 
	Dmitry Vyukov <dvyukov@...gle.com>, Frederic Weisbecker <frederic@...nel.org>, 
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>, Ingo Molnar <mingo@...nel.org>, 
	Jann Horn <jannh@...gle.com>, Joel Fernandes <joel@...lfernandes.org>, 
	Jonathan Corbet <corbet@....net>, Josh Triplett <josh@...htriplett.org>, 
	Justin Stitt <justinstitt@...gle.com>, Kees Cook <kees@...nel.org>, 
	Mark Rutland <mark.rutland@....com>, Mathieu Desnoyers <mathieu.desnoyers@...icios.com>, 
	Miguel Ojeda <ojeda@...nel.org>, Nathan Chancellor <nathan@...nel.org>, 
	Neeraj Upadhyay <neeraj.upadhyay@...nel.org>, Nick Desaulniers <ndesaulniers@...gle.com>, 
	Steven Rostedt <rostedt@...dmis.org>, Thomas Gleixner <tglx@...utronix.de>, 
	Uladzislau Rezki <urezki@...il.com>, Waiman Long <longman@...hat.com>, Will Deacon <will@...nel.org>, 
	kasan-dev@...glegroups.com, linux-kernel@...r.kernel.org, 
	llvm@...ts.linux.dev, rcu@...r.kernel.org, linux-crypto@...r.kernel.org
Subject: Re: [PATCH RFC 02/24] compiler-capability-analysis: Rename
 __cond_lock() to __cond_acquire()

On Fri, 7 Feb 2025 at 10:41, Peter Zijlstra <peterz@...radead.org> wrote:
>
> On Fri, Feb 07, 2025 at 10:32:25AM +0100, Marco Elver wrote:
> > On Fri, Feb 07, 2025 at 09:28AM +0100, Peter Zijlstra wrote:
> > > On Thu, Feb 06, 2025 at 07:09:56PM +0100, Marco Elver wrote:
> > > > Just like the pairing of attribute __acquires() with a matching
> > > > function-like macro __acquire(), the attribute __cond_acquires() should
> > > > have a matching function-like macro __cond_acquire().
> > > >
> > > > To be consistent, rename __cond_lock() to __cond_acquire().
> > >
> > > So I hate this __cond_lock() thing we have with a passion. I think it is
> > > one of the very worst annotations possible since it makes a trainwreck
> > > of the trylock code.
> > >
> > > It is a major reason why mutex is not annotated with this nonsense.
> > >
> > > Also, I think very dim of sparse in general -- I don't think I've ever
> > > managed to get a useful warning from between all the noise it generates.
> >
> > Happy to reduce the use of __cond_lock(). :-)
> > Though one problem I found is it's still needed for those complex
> > statement-expression *_trylock that spinlock.h/rwlock.h has, where we
> > e.g. have (with my changes):
> >
> >       #define raw_spin_trylock_irqsave(lock, flags)           \
> >               __cond_acquire(lock, ({                         \
> >                       local_irq_save(flags);                  \
> >                       _raw_spin_trylock(lock) ?               \
> >                       1 : ({ local_irq_restore(flags); 0; }); \
> >               }))
> >
> > Because there's an inner condition using _raw_spin_trylock() and the
> > result of _raw_spin_trylock() is no longer directly used in a branch
> > that also does the unlock, Clang becomes unhappy and complains. I.e.
> > annotating _raw_spin_trylock with __cond_acquires(1, lock) doesn't work
> > for this case because it's in a complex statement-expression. The only
> > way to make it work was to wrap it into a function that has attribute
> > __cond_acquires(1, lock) which is what I made __cond_lock/acquire do.
>
> Does something like:
>
> static inline bool
> _raw_spin_trylock_irqsave(raw_spinlock_t *lock, unsigned long *flags)
>         __cond_acquire(1, lock)
> {
>         local_irq_save(*flags);
>         if (_raw_spin_trylock(lock))
>                 return true;
>         local_irq_restore(*flags);
>         return false;
> }
>
> #define raw_spin_trylock_irqsave(lock, flags) \
>         _raw_spin_trylock_irqsave((lock), &(flags))
>
> work?

Yup it does (tested). Ok, so getting rid of __cond_lock should be doable. :-)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ