From: Al Viro <viro@ZenIV.linux.org.uk>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>,
linux-mm@kvack.org, mgorman@suse.de,
kamezawa.hiroyu@jp.fujitsu.com, dhillf@gmail.com,
hughd@google.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] hugetlbfs: Add new rw_semaphore to fix truncate/read race
Date: Tue, 28 Feb 2012 00:02:28 +0000 [thread overview]
Message-ID: <20120228000228.GE23916@ZenIV.linux.org.uk> (raw)
In-Reply-To: <20120227151135.7d4076c6.akpm@linux-foundation.org>
On Mon, Feb 27, 2012 at 03:11:35PM -0800, Andrew Morton wrote:
> This patch comes somewhat out of the blue and I'm unsure what's going on.
>
> You say there's some (potential?) deadlock with mmap, but it is
> undescribed. Have people observed this deadlock? Has it caused
> lockdep warnings? Please update the changelog to fully describe the
> bug.
There's one simple rule: never, ever take ->i_mutex under ->mmap_sem.
E.g. in any ->mmap() (obvious - mmap(2) calls that under ->mmap_sem) or
any ->release() of mappable file (munmap(2) does fput() under ->mmap_sem
and that will call ->release() if no other references are still around).
Hugetlbfs is slightly unusual since it takes ->i_mutex in read() - usually
that's done in write(), while read() doesn't bother with that. In either
case you do copying to/from userland buffer while holding ->i_mutex, which
nests ->mmap_sem within it.
> Also, the new truncate_sem is undoumented. This leaves readers to work
> out for themselves what it might be for. Please let's add code
> comments which completely describe the race, and how this lock prevents
> it.
>
> We should also document our locking rules.
Hell, yes. I've spent the last couple of weeks crawling through VM-related
code and locking in there is _scary_. "Convoluted" doesn't even begin to
cover it, especially when it gets to "what locks are required when accessing
this field" ;-/ Got quite a catch out of that trawl by now...
> When should code take this
> lock? What are its ranking rules with respect to i_mutex, i_mmap_mutex
> and possibly others?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
WARNING: multiple messages have this Message-ID (diff)
From: Al Viro <viro@ZenIV.linux.org.uk>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>,
linux-mm@kvack.org, mgorman@suse.de,
kamezawa.hiroyu@jp.fujitsu.com, dhillf@gmail.com,
hughd@google.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] hugetlbfs: Add new rw_semaphore to fix truncate/read race
Date: Tue, 28 Feb 2012 00:02:28 +0000 [thread overview]
Message-ID: <20120228000228.GE23916@ZenIV.linux.org.uk> (raw)
In-Reply-To: <20120227151135.7d4076c6.akpm@linux-foundation.org>
On Mon, Feb 27, 2012 at 03:11:35PM -0800, Andrew Morton wrote:
> This patch comes somewhat out of the blue and I'm unsure what's going on.
>
> You say there's some (potential?) deadlock with mmap, but it is
> undescribed. Have people observed this deadlock? Has it caused
> lockdep warnings? Please update the changelog to fully describe the
> bug.
There's one simple rule: never, ever take ->i_mutex under ->mmap_sem.
E.g. in any ->mmap() (obvious - mmap(2) calls that under ->mmap_sem) or
any ->release() of mappable file (munmap(2) does fput() under ->mmap_sem
and that will call ->release() if no other references are still around).
Hugetlbfs is slightly unusual since it takes ->i_mutex in read() - usually
that's done in write(), while read() doesn't bother with that. In either
case you do copying to/from userland buffer while holding ->i_mutex, which
nests ->mmap_sem within it.
> Also, the new truncate_sem is undoumented. This leaves readers to work
> out for themselves what it might be for. Please let's add code
> comments which completely describe the race, and how this lock prevents
> it.
>
> We should also document our locking rules.
Hell, yes. I've spent the last couple of weeks crawling through VM-related
code and locking in there is _scary_. "Convoluted" doesn't even begin to
cover it, especially when it gets to "what locks are required when accessing
this field" ;-/ Got quite a catch out of that trawl by now...
> When should code take this
> lock? What are its ranking rules with respect to i_mutex, i_mmap_mutex
> and possibly others?
next prev parent reply other threads:[~2012-02-28 0:02 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-26 18:19 [PATCH] hugetlbfs: Add new rw_semaphore to fix truncate/read race Aneesh Kumar K.V
2012-02-26 18:19 ` Aneesh Kumar K.V
2012-02-27 23:11 ` Andrew Morton
2012-02-27 23:11 ` Andrew Morton
2012-02-28 0:02 ` Al Viro [this message]
2012-02-28 0:02 ` Al Viro
2012-02-28 10:15 ` Aneesh Kumar K.V
2012-02-28 10:15 ` Aneesh Kumar K.V
2012-02-28 12:17 ` Hillf Danton
2012-02-28 12:17 ` Hillf Danton
2012-02-29 11:04 ` Aneesh Kumar K.V
2012-02-29 11:04 ` Aneesh Kumar K.V
2012-02-29 14:42 ` Hillf Danton
2012-02-29 14:42 ` Hillf Danton
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=20120228000228.GE23916@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=akpm@linux-foundation.org \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=dhillf@gmail.com \
--cc=hughd@google.com \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@suse.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.