From: Marco Stornelli <marco.stornelli@gmail.com>
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Linux FS Devel <linux-fsdevel@vger.kernel.org>,
Linux Kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH, RFC] xip: use i_mutex for xip_file_fault
Date: Sun, 11 Sep 2011 17:57:36 +0200 [thread overview]
Message-ID: <4E6CDA70.5080205@gmail.com> (raw)
In-Reply-To: <20110911112552.GB2203@ZenIV.linux.org.uk>
Il 11/09/2011 13:25, Al Viro ha scritto:
> On Sun, Sep 11, 2011 at 12:15:04PM +0100, Al Viro wrote:
>
>> write() grabs ->i_mutex on the file it's going to write to. It uses
>> copy_from_user() while holding ->i_mutex; that can end up calling ->fault().
>> If your data comes from the same file mmapped in your address space, you
>> have xip_write_fault() called while you are in xip_file_write() and *already*
>> are holding ->i_mutex on the same inode. With your patch it will, AFAICS,
>> cheerfully deadlock.
>
> Oh, wait... You are only doing that to write side of pagefault? That's
> better, but not much:
>
> thread 1: mmap the file, modify mapping
> thread 2: write() to file
>
> The former will do xip_write_fault() while holding ->mmap_sem.
> The latter will do copy_from_user() from xip_file_write(), getting
> pagefaults while holding ->i_mutex.
>
> Note that we are grabbing ->mmap_sem and ->i_mutex in opposite orders.
> I.e. that will deadlock on you - all you need is threads sharing the
> address space.
>
Ok, thank you very much for the on-line debug :) So i_mutex is not a
good lock to use in this situation. It was a common sync point, but it
has some collateral effect on the write path that we must avoid. At this
point, what can be a good strategy? Any opinion is welcome.
Marco
prev parent reply other threads:[~2011-09-11 16:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-10 15:31 [PATCH, RFC] xip: use i_mutex for xip_file_fault Marco Stornelli
2011-09-10 15:56 ` Al Viro
2011-09-11 8:25 ` Marco Stornelli
2011-09-11 11:15 ` Al Viro
2011-09-11 11:25 ` Al Viro
2011-09-11 15:57 ` Marco Stornelli [this message]
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=4E6CDA70.5080205@gmail.com \
--to=marco.stornelli@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@ZenIV.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).