From mboxrd@z Thu Jan 1 00:00:00 1970 From: Al Viro Subject: Re: [PATCH, RFC] xip: use i_mutex for xip_file_fault Date: Sun, 11 Sep 2011 12:25:52 +0100 Message-ID: <20110911112552.GB2203@ZenIV.linux.org.uk> References: <4E6B82DB.50803@gmail.com> <20110910155639.GY2203@ZenIV.linux.org.uk> <4E6C705F.8010101@gmail.com> <20110911111504.GA2203@ZenIV.linux.org.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Linux FS Devel , Linux Kernel To: Marco Stornelli Return-path: Content-Disposition: inline In-Reply-To: <20110911111504.GA2203@ZenIV.linux.org.uk> Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org 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.