Re: [PATCH v2 7/9] locking/rwlocks: introduce write_lock_nested

From: Minchan Kim
Date: Fri Nov 19 2021 - 13:21:42 EST


On Fri, Nov 19, 2021 at 11:35:16AM +0100, Sebastian Andrzej Siewior wrote:
> On 2021-11-15 10:59:07 [-0800], Minchan Kim wrote:
> > diff --git a/include/linux/rwlock_rt.h b/include/linux/rwlock_rt.h
> > index 49c1f3842ed5..efd6da62c893 100644
> > --- a/include/linux/rwlock_rt.h
> > +++ b/include/linux/rwlock_rt.h
> > @@ -28,6 +28,7 @@ extern void rt_read_lock(rwlock_t *rwlock);
> > extern int rt_read_trylock(rwlock_t *rwlock);
> > extern void rt_read_unlock(rwlock_t *rwlock);
> > extern void rt_write_lock(rwlock_t *rwlock);
> > +extern void rt_write_lock_nested(rwlock_t *rwlock, int subclass);
> > extern int rt_write_trylock(rwlock_t *rwlock);
> > extern void rt_write_unlock(rwlock_t *rwlock);
> >
> > @@ -83,6 +84,11 @@ static __always_inline void write_lock(rwlock_t *rwlock)
> > rt_write_lock(rwlock);
> > }
> >
> > +static __always_inline void write_lock_nested(rwlock_t *rwlock, int subclass)
> > +{
> > + rt_write_lock_nested(rwlock, subclass);
> > +}
> > +
>
> These two hunks as-is don't work. You need a CONFIG_DEBUG_LOCK_ALLOC block and
> in the !CONFIG_DEBUG_LOCK_ALLOC case you need
>
> #define rt_write_lock_nested(lock, subclass) rt_write_lock(((void)(subclass), (lock)))

Guess you meant #define write_lock_nested.

>
> > static __always_inline void write_lock_bh(rwlock_t *rwlock)
> > {
> > local_bh_disable();
> > diff --git a/kernel/locking/spinlock_rt.c b/kernel/locking/spinlock_rt.c
> > index b2e553f9255b..b82d346f1e00 100644
> > --- a/kernel/locking/spinlock_rt.c
> > +++ b/kernel/locking/spinlock_rt.c
> > @@ -239,6 +239,18 @@ void __sched rt_write_lock(rwlock_t *rwlock)
> > }
> > EXPORT_SYMBOL(rt_write_lock);
> >
> > +#ifdef CONFIG_DEBUG_LOCK_ALLOC
> > +void __sched rt_write_lock_nested(rwlock_t *rwlock, int subclass)
> > +{
> > + ___might_sleep(__FILE__, __LINE__, 0);
>
> This _must_ be rtlock_might_resched() like it is done in rt_write_lock()
> above.

I should have Cced you. Thanks for the catch.
If it's fine, Andrew, could you fold it?

Thank you.