From: Al Viro <viro@ZenIV.linux.org.uk>
To: Vladislav Bolkhovitin <vst@vlnb.net>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
linux-kernel@vger.kernel.org
Subject: Re: Lockdep and rw_semaphores
Date: Sun, 11 Sep 2011 03:38:40 +0100 [thread overview]
Message-ID: <20110911023840.GZ2203@ZenIV.linux.org.uk> (raw)
In-Reply-To: <4E6C1016.8030703@vlnb.net>
On Sat, Sep 10, 2011 at 09:34:14PM -0400, Vladislav Bolkhovitin wrote:
> Hello,
>
> Looks like lockdep somehow over-restrictive for rw_semaphores in case when they
> are taken for read (down_read()) and requires them to follow the same inner-outer
> rules as for plain locks.
>
> For instance, code like:
>
> DECLARE_RWSEM(QQ_sem);
> DECLARE_RWSEM(QQ1_sem);
>
> thread1:
>
> down_read(&QQ_sem);
> down_read(&QQ1_sem);
> thread2:
>
> down_read(&QQ1_sem);
> down_read(&QQ_sem);
> Is it by design or just something overlooked? I don't see how reverse order of
> down_read()'s can lead to any deadlock. Or am I missing anything?
thread1: got QQ
thread2: got QQ1
thread3: tries to do down_write() on QQ, gets blocked
thread4: tries to do down_write() on QQ1, gets blocked
Now we have thread1 that can't get QQ1 once the threads trying to get it
exclusive get a shot at it. Thread2 is blocked in the same way on QQ.
And neither is going to release the (shared) lock they are holding, so
thread3 and thread4 are not going to get anywhere either.
IOW, ordering *is* needed there. Note that for the same reason trying to
grab the same lock shared twice is a deadlock:
A: already holds X shared
B: blocks trying to grab it exclusive
A: tries to grab it shared again and gets stuck, since there is a pending
down_write() and we are guaranteed that writer will get served as soon
as all current readers are through; no new readers are allowed to starve it.
next prev parent reply other threads:[~2011-09-11 2:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-11 1:34 Lockdep and rw_semaphores Vladislav Bolkhovitin
2011-09-11 2:38 ` Al Viro [this message]
2011-09-13 2:19 ` Vladislav Bolkhovitin
2011-09-13 5:17 ` Al Viro
2011-09-14 1:55 ` Vladislav Bolkhovitin
2011-09-14 4:40 ` Al Viro
2011-09-15 2:16 ` Vladislav Bolkhovitin
2011-09-13 14:07 ` David Howells
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110911023840.GZ2203@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=vst@vlnb.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox