Re: [RT WARNING] DEBUG_LOCKS_WARN_ON(rt_mutex_owner(lock) != current) with fsfreeze (4.19.25-rt16)

From: Peter Zijlstra
Date: Fri May 03 2019 - 10:17:09 EST


On Thu, May 02, 2019 at 12:09:32PM +0200, Oleg Nesterov wrote:
> On 05/01, Peter Zijlstra wrote:
> >
> > Anyway; I cobbled together the below. Oleg, could you have a look, I'm
> > sure I messed it up.
>
> Oh, I will need to read this carefully. but at first glance I do not see
> any hole...
>
> > +static void readers_block(struct percpu_rw_semaphore *sem)
> > +{
> > + wait_event_cmd(sem->writer, !sem->readers_block,
> > + __up_read(&sem->rw_sem), __down_read(&sem->rw_sem));
> > +}
> > +
> > +static void block_readers(struct percpu_rw_semaphore *sem)
> > +{
> > + wait_event_exclusive_cmd(sem->writer, !sem->readers_block,
> > + __up_write(&sem->rw_sem),
> > + __down_write(&sem->rw_sem));
> > + /*
> > + * Notify new readers to block; up until now, and thus throughout the
> > + * longish rcu_sync_enter() above, new readers could still come in.
> > + */
> > + WRITE_ONCE(sem->readers_block, 1);
> > +}
>
> So iiuc, despite it name block_readers() also serializes the writers, ->rw_sem
> can be dropped by down_write_non_owner() so the new writer can take this lock.

I don't think block_readers() is sufficient to serialize writers;
suppose two concurrent callers when !->readers_block. Without ->rwsem
that case would not serialize.

> But this all is cosmetic, it seems that we can remove ->rw_sem altogether
> but I am not sure...

Only if we introduce something like ->wait_lock to serialize things.