Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1570776
| From | Waiman Long <longman@redhat.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: Q: lockdep_assert_held_read() after downgrade_write() |
| Date | 2017-01-31 15:30 +0100 |
| Message-ID | <t5HBw-1Ll-9@gated-at.bofh.it> (permalink) |
| References | <t5rGq-Ac-35@gated-at.bofh.it> <t5EtZ-8qc-37@gated-at.bofh.it> <t5EtZ-8qc-35@gated-at.bofh.it> <t5H8u-1mq-3@gated-at.bofh.it> |
| Organization | Red Hat |
On 01/31/2017 06:25 AM, Peter Zijlstra wrote:
> On Tue, Jan 31, 2017 at 11:36:20AM +0100, Peter Zijlstra wrote:
>> On Mon, Jan 30, 2017 at 02:30:45PM -0700, Jens Axboe wrote:
>>> I don't think you understand how it works. downgrade_write() turns a write
>>> lock into read held. To make that last sequence valid, you'd need:
>> Correct, and I'm surprised that didn't explode in different ways.
>>
>>> down_write(&rw);
>>> downgrade_write(&rw);
>>> lockdep_assert_held_read(&rw)
>>> up_read(&rw);
>>>
>>> or just not drop up_write() from the last section.
>> Right, but also, there seems to be a missing lockdep annotation to make
>> that work. That is, downgrade_write() doesn't have a lockdep annotation,
>> so it (lockdep) will still think its a write lock.
>>
>>
>> Let me try and fix both issues.
> Something like so I suppose,... completely untested.
>
> There could be a good reason for the current lockdep behaviour, but I
> cannot remember.
>
> ---
> diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
> index 45ba475d4be3..dfa9e40f83d5 100644
> --- a/kernel/locking/rwsem.c
> +++ b/kernel/locking/rwsem.c
> @@ -123,10 +123,9 @@ EXPORT_SYMBOL(up_write);
> */
> void downgrade_write(struct rw_semaphore *sem)
> {
> - /*
> - * lockdep: a downgraded write will live on as a write
> - * dependency.
> - */
> + rwsem_release(&sem->dep_map, 1, _RET_IP_);
> + rwsem_acquire_read(&sem->dep_map, 0, 0, _RET_IP_);
> +
> rwsem_set_reader_owned(sem);
> __downgrade_write(sem);
> }
> diff --git a/kernel/locking/rwsem.h b/kernel/locking/rwsem.h
> index a699f4048ba1..3bd584c81b0b 100644
> --- a/kernel/locking/rwsem.h
> +++ b/kernel/locking/rwsem.h
> @@ -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.
Cheers,
Longman
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Q: lockdep_assert_held_read() after downgrade_write() "J. R. Okajima" <hooanon05g@gmail.com> - 2017-01-30 22:30 +0100
Re: Q: lockdep_assert_held_read() after downgrade_write() Peter Zijlstra <peterz@infradead.org> - 2017-01-31 12:10 +0100
Re: Q: lockdep_assert_held_read() after downgrade_write() Peter Zijlstra <peterz@infradead.org> - 2017-01-31 15:00 +0100
Re: Q: lockdep_assert_held_read() after downgrade_write() Waiman Long <longman@redhat.com> - 2017-01-31 15:30 +0100
Re: Q: lockdep_assert_held_read() after downgrade_write() Peter Zijlstra <peterz@infradead.org> - 2017-01-31 15:30 +0100
Re: Q: lockdep_assert_held_read() after downgrade_write() "J. R. Okajima" <hooanon05g@gmail.com> - 2017-01-31 16:50 +0100
Re: Q: lockdep_assert_held_read() after downgrade_write() Peter Zijlstra <peterz@infradead.org> - 2017-01-31 18:00 +0100
Re: Q: lockdep_assert_held_read() after downgrade_write() "J. R. Okajima" <hooanon05g@gmail.com> - 2017-02-02 17:40 +0100
[PATCH 1/3] lockdep: consolidate by new find_held_lock() "J. R. Okajima" <hooanon05g@gmail.com> - 2017-02-02 17:50 +0100
[PATCH 3/3] lockdep: new annotation lock_downgrade() "J. R. Okajima" <hooanon05g@gmail.com> - 2017-02-02 17:50 +0100
Re: [PATCH 3/3] lockdep: new annotation lock_downgrade() kbuild test robot <lkp@intel.com> - 2017-02-02 19:10 +0100
Re: [PATCH 3/3] lockdep: new annotation lock_downgrade() Peter Zijlstra <peterz@infradead.org> - 2017-02-02 19:50 +0100
Re: [PATCH 3/3] lockdep: new annotation lock_downgrade() "J. R. Okajima" <hooanon05g@gmail.com> - 2017-02-02 22:10 +0100
[PATCH 2/3] lockdep: consolidate by new validate_held_lock() "J. R. Okajima" <hooanon05g@gmail.com> - 2017-02-02 17:50 +0100
csiph-web