From: "Kristian Høgsberg" <krh@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: krh@bitplanet.net, eric@anholt.net,
Wang Chen <wangchen@cn.fujitsu.com>,
dri-devel@lists.sf.net, linux-kernel@vger.kernel.org,
Nick Piggin <npiggin@suse.de>,
Andrew Morton <akpm@linux-foundation.org>,
Hugh Dickins <hugh@veritas.com>
Subject: Re: [PATCH] drm: Take mmap_sem up front to avoid lock order violations.
Date: Thu, 19 Feb 2009 09:49:40 -0500 [thread overview]
Message-ID: <1235054980.31384.16.camel@gaara.bos.redhat.com> (raw)
In-Reply-To: <1235039601.4612.45.camel@laptop>
On Thu, 2009-02-19 at 11:33 +0100, Peter Zijlstra wrote:
> On Thu, 2009-02-19 at 10:19 +0100, Peter Zijlstra wrote:
> > On Wed, 2009-02-18 at 11:38 -0500, krh@bitplanet.net wrote:
> > > From: Kristian Høgsberg <krh@redhat.com>
> > >
> > > A number of GEM operations (and legacy drm ones) want to copy data to
> > > or from userspace while holding the struct_mutex lock. However, the
> > > fault handler calls us with the mmap_sem held and thus enforces the
> > > opposite locking order. This patch downs the mmap_sem up front for
> > > those operations that access userspace data under the struct_mutex
> > > lock to ensure the locking order is consistent.
> > >
> > > Signed-off-by: Kristian Høgsberg <krh@redhat.com>
> > > ---
> > >
> > > Here's a different and simpler attempt to fix the locking order
> > > problem. We can just down_read() the mmap_sem pre-emptively up-front,
> > > and the locking order is respected. It's simpler than the
> > > mutex_trylock() game, avoids introducing a new mutex.
> > >
>
> OK let me try that again -- my initial response was a tad curt :/
No that's fair, I was aware that the patch was probably borderline and
got the feedback I was looking for ;)
> While I appreciate your efforts in fixing GEM (I too have an interest in
> seeing it done), I cannot support your patch.
>
> Firstly, you're using mmap_sem well outside its problem domain, this is
> bad form. Furthermore, holding it for extended durations for no good
> reason affects all other users.
Yup, agree.
> Secondly, mmap_sem is not a recursive lock (very few kernel locks are,
> and we generally frown upon recursive locking schemes), this means that
> the fault handler still cannot function properly.
I understand, but we take it twice only as a read lock, so that should
work, right? We prevent the deadlock the lockdep validator warned about
and as far as I can see, the patch doesn't introduce a new one. But
other than that I agree with the frowning on recursive locking, it's too
often used to paper over badly thought out locking.
cheers,
Kristian
next prev parent reply other threads:[~2009-02-19 14:50 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-18 0:59 [PATCH] drm: Fix lock order reversal between mmap_sem and struct_mutex Eric Anholt
2009-02-18 8:02 ` Wang Chen
2009-02-18 16:38 ` [PATCH] drm: Take mmap_sem up front to avoid lock order violations krh
2009-02-19 9:19 ` Peter Zijlstra
2009-02-19 10:33 ` Peter Zijlstra
2009-02-19 14:49 ` Kristian Høgsberg [this message]
2009-02-19 15:17 ` Nick Piggin
2009-02-19 15:21 ` Kristian Høgsberg
2009-02-19 12:57 ` Nick Piggin
2009-02-21 2:33 ` Eric Anholt
2009-02-18 15:08 ` [PATCH] drm: Fix lock order reversal between mmap_sem and struct_mutex Peter Zijlstra
2009-02-19 21:02 ` Thomas Hellstrom
2009-02-19 22:26 ` Peter Zijlstra
2009-02-20 2:04 ` Eric Anholt
2009-02-20 7:36 ` Peter Zijlstra
2009-02-25 8:15 ` Eric Anholt
2009-02-25 8:54 ` Thomas Hellström
2009-02-25 9:07 ` Peter Zijlstra
2009-02-20 8:31 ` Thomas Hellstrom
2009-02-20 8:47 ` Peter Zijlstra
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=1235054980.31384.16.camel@gaara.bos.redhat.com \
--to=krh@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=dri-devel@lists.sf.net \
--cc=eric@anholt.net \
--cc=hugh@veritas.com \
--cc=krh@bitplanet.net \
--cc=linux-kernel@vger.kernel.org \
--cc=npiggin@suse.de \
--cc=peterz@infradead.org \
--cc=wangchen@cn.fujitsu.com \
/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
all inboxes | Powered by JetHome®