Re: [PATCH v1] proc/vmcore: fix false positive lockdep warning

From: David Hildenbrand
Date: Wed Jan 19 2022 - 10:15:26 EST


On 19.01.22 16:08, Boqun Feng wrote:
> Hi,
>
> On Wed, Jan 19, 2022 at 12:37:02PM +0100, David Hildenbrand wrote:
>> Lockdep complains that we do during mmap of the vmcore:
>> down_write(mmap_lock);
>> down_read(vmcore_cb_rwsem);
>> And during read of the vmcore:
>> down_read(vmcore_cb_rwsem);
>> down_read(mmap_lock);
>>
>> We cannot possibly deadlock when only taking vmcore_cb_rwsem in read
>> mode, however, it's hard to teach that to lockdep.
>>
>
> Lockdep warned about the above sequences because rw_semaphore is a fair
> read-write lock, and the following can cause a deadlock:
>
> TASK 1 TASK 2 TASK 3
> ====== ====== ======
> down_write(mmap_lock);
> down_read(vmcore_cb_rwsem)
> down_write(vmcore_cb_rwsem); // blocked
> down_read(vmcore_cb_rwsem); // cannot get the lock because of the fairness
> down_read(mmap_lock); // blocked
>
> IOW, a reader can block another read if there is a writer queued by the
> second reader and the lock is fair.
>
> So there is a deadlock possiblity.

Task 3 will never take the mmap_lock before doing a
down_write(vmcore_cb_rwsem).

How would this happen?


--
Thanks,

David / dhildenb