Re: [PATCH RFC 03/33] locking: Introduce <linux/thread_safety.h>
From: Marco Elver
Date: Fri Feb 07 2025 - 18:19:55 EST
On Fri, 7 Feb 2025 at 23:34, Bart Van Assche <bvanassche@xxxxxxx> wrote:
[...]
> > Those are all nasty shouting names, without and good prefixing.
> >
> > But more importantly ACQUIRE() and RELEASE() seems to duplicate the
> > existing __acquires/__releases annotations from sparse. We really need
> > to find away to unify them instead of duplicating the annotations.
>
> I think that we are better off to drop support for the sparse locking
> annotations. Linus added the macro __cond_acquires() two years ago in
+1 to dropping Sparse support -- although we can retain the same keywords.
[...]
> * The argument of __acquire() and __release() can be a "capability" or
> the address of a synchronization object. A few examples where the
> argument represents a capability:
Not a problem, and can be solved by introducing "token" instances...
> __acquire(RCU);
> __acquire(RCU_BH);
> __acquire(RCU_SCHED);
For RCU: https://lore.kernel.org/lkml/20250206181711.1902989-16-elver@xxxxxxxxxx/
> __acquire(bitlock);
For bitlock: https://lore.kernel.org/lkml/20250206181711.1902989-15-elver@xxxxxxxxxx/
> An example where the argument represents the address of a
> synchronization object:
>
> static inline void do_raw_spin_lock(raw_spinlock_t *lock)
> __acquires(lock)
> {
> __acquire(lock);
> arch_spin_lock(&lock->raw_lock);
> mmiowb_spin_lock();
> }
>
> If __acquire() and __release() would have to be supported for both
> sparse and Clang, that would probably involve modifying all instances
> of these two macros across the entire kernel tree and making it
> explicit whether the argument is a capability or the address of a
> synchronization object.
This is not a problem as I have demonstrated with my approach. Using
token instances is also the way we'd be able to support things like
preempt-disable-enable, irq-disable-enable, etc.
In general I'm in favor of dropping Sparse support, but the majority
of existing annotations can be reused, simplifying our work.