From: Gao Xiang <gaoxiang25@huawei.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: "Darrick J. Wong" <darrick.wong@oracle.com>,
Dave Chinner <david@fromorbit.com>,
xfs <linux-xfs@vger.kernel.org>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>
Subject: Re: [PATCH v3] vfs: fix page locking deadlocks when deduping files
Date: Wed, 14 Aug 2019 15:03:21 +0800 [thread overview]
Message-ID: <20190814070321.GB28602@138> (raw)
In-Reply-To: <20190813154010.GD5307@bombadil.infradead.org>
On Tue, Aug 13, 2019 at 08:40:10AM -0700, Matthew Wilcox wrote:
> On Tue, Aug 13, 2019 at 08:14:34AM -0700, Darrick J. Wong wrote:
> > + /*
> > + * Now that we've locked both pages, make sure they still
> > + * represent the data we're interested in. If not, someone
> > + * is invalidating pages on us and we lose.
> > + */
> > + if (src_page->mapping != src->i_mapping ||
> > + src_page->index != srcoff >> PAGE_SHIFT ||
> > + dest_page->mapping != dest->i_mapping ||
> > + dest_page->index != destoff >> PAGE_SHIFT) {
> > + same = false;
> > + goto unlock;
> > + }
>
> It is my understanding that you don't need to check the ->index here.
> If I'm wrong about that, I'd really appreciate being corrected, because
> the page cache locking is subtle.
>
> You call read_mapping_page() which returns the page with an elevated
> refcount. That means the page can't go back to the page allocator and
> be allocated again. It can, because it's unlocked, still be truncated,
> so the check for ->mapping after locking it is needed. But the check
> for ->index being correct was done by find_get_entry().
>
> See pagecache_get_page() -- if we specify FGP_LOCK, then it will lock
> the page, check the ->mapping but not check ->index. OK, it does check
> ->index, but in a VM_BUG_ON(), so it's not something that ought to be
> able to be wrong.
That is my understanding as well. In details...
The page data get ready after read_mapping_page() is successfully
returned. However, if someone needs to get a stable untruncated page,
lock_page() and recheck page->mapping are needed as well.
I have no idea how page->index can be changed safely without reallocating
the page, even some paths could keep using some truncated page temporarily
with some refcounts held but I think those paths cannot add these pages
directly to some page cache again without freeing since it seems really
unsafe.....
Thanks,
Gao Xiang
>
next prev parent reply other threads:[~2019-08-14 6:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-13 15:14 [PATCH v3] vfs: fix page locking deadlocks when deduping files Darrick J. Wong
2019-08-13 15:40 ` Matthew Wilcox
2019-08-14 7:03 ` Gao Xiang [this message]
2019-08-14 7:17 ` Gao Xiang
2019-08-14 9:54 ` Dave Chinner
2019-08-14 15:33 ` Darrick J. Wong
2019-08-14 21:28 ` Dave Chinner
2019-08-15 0:41 ` Darrick J. Wong
2019-08-13 15:53 ` Filipe Manana
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=20190814070321.GB28602@138 \
--to=gaoxiang25@huawei.com \
--cc=darrick.wong@oracle.com \
--cc=david@fromorbit.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=willy@infradead.org \
/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).