Re: Q: lockdep_assert_held_read() after downgrade_write()

Peter Zijlstra
2017-01-31T14:26:54Z

On Tue, Jan 31, 2017 at 09:23:08AM -0500, Waiman Long wrote:
> On 01/31/2017 06:25 AM, Peter Zijlstra wrote:
> > @@ -40,8 +40,10 @@ static inline void rwsem_set_reader_owned(struct rw_semaphore *sem)
> > * do a write to the rwsem cacheline when it is really necessary
> > * to minimize cacheline contention.
> > */
> > - if (sem->owner != RWSEM_READER_OWNED)
> > + if (sem->owner != RWSEM_READER_OWNED) {
> > + WARN_ON_ONCE(sem->owner != current);
> > WRITE_ONCE(sem->owner, RWSEM_READER_OWNED);
> > + }
> > }
> >
> > static inline bool rwsem_owner_is_writer(struct task_struct *owner)
>
> I don't think you can do a WARN_ON_ONCE() check for sem->owner !=
> current here. If the rwsem starts from an unlock state, sem->owner will
> be NULL and an incorrect warning message will be printed.

Argh, I only looked at the downgrade_write() user and forgot to look if
it was used elsewhere.