From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Jan Kara <jack@suse.cz>
Cc: Amir Goldstein <amir73il@gmail.com>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>,
Linux MM <linux-mm@kvack.org>,
linux-xfs <linux-xfs@vger.kernel.org>,
Boaz Harrosh <boaz@plexistor.com>,
stable <stable@vger.kernel.org>
Subject: Re: [PATCH 3/3] xfs: Fix stale data exposure when readahead races with hole punch
Date: Fri, 12 Jul 2019 10:56:44 -0700 [thread overview]
Message-ID: <20190712175644.GQ1654093@magnolia> (raw)
In-Reply-To: <20190712120004.GB24009@quack2.suse.cz>
On Fri, Jul 12, 2019 at 02:00:04PM +0200, Jan Kara wrote:
> On Thu 11-07-19 08:49:17, Darrick J. Wong wrote:
> > On Thu, Jul 11, 2019 at 06:28:54PM +0300, Amir Goldstein wrote:
> > > > +{
> > > > + struct xfs_inode *ip = XFS_I(file_inode(file));
> > > > + int ret;
> > > > +
> > > > + /* Readahead needs protection from hole punching and similar ops */
> > > > + if (advice == POSIX_FADV_WILLNEED)
> > > > + xfs_ilock(ip, XFS_IOLOCK_SHARED);
> >
> > It's good to fix this race, but at the same time I wonder what's the
> > impact to processes writing to one part of a file waiting on IOLOCK_EXCL
> > while readahead holds IOLOCK_SHARED?
> >
> > (bluh bluh range locks ftw bluh bluh)
>
> Yeah, with range locks this would have less impact. Also note that we hold
> the lock only during page setup and IO submission. IO itself will already
> happen without IOLOCK, only under page lock. But that's enough to stop the
> race.
> > Do we need a lock for DONTNEED? I think the answer is that you have to
> > lock the page to drop it and that will protect us from <myriad punch and
> > truncate spaghetti> ... ?
>
> Yeah, DONTNEED is just page writeback + invalidate. So page lock is enough
> to protect from anything bad. Essentially we need IOLOCK only to protect
> the places that creates new pages in page cache.
>
> > > > + ret = generic_fadvise(file, start, end, advice);
> > > > + if (advice == POSIX_FADV_WILLNEED)
> > > > + xfs_iunlock(ip, XFS_IOLOCK_SHARED);
> >
> > Maybe it'd be better to do:
> >
> > int lockflags = 0;
> >
> > if (advice == POSIX_FADV_WILLNEED) {
> > lockflags = XFS_IOLOCK_SHARED;
> > xfs_ilock(ip, lockflags);
> > }
> >
> > ret = generic_fadvise(file, start, end, advice);
> >
> > if (lockflags)
> > xfs_iunlock(ip, lockflags);
> >
> > Just in case we some day want more or different types of inode locks?
>
> OK, will do. Just I'll get to testing this only after I return from
> vacation.
<nod>
--D
>
> Honza
>
> --
> Jan Kara <jack@suse.com>
> SUSE Labs, CR
next prev parent reply other threads:[~2019-07-12 17:56 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-11 14:00 [PATCH 0/3] xfs: Fix races between readahead and hole punching Jan Kara
2019-07-11 14:00 ` [PATCH 1/3] mm: Handle MADV_WILLNEED through vfs_fadvise() Jan Kara
2019-07-12 17:50 ` Darrick J. Wong
2019-07-12 23:55 ` Sasha Levin
2019-07-23 3:08 ` Boaz Harrosh
2019-07-11 14:00 ` [PATCH 2/3] fs: Export generic_fadvise() Jan Kara
2019-07-12 17:50 ` Darrick J. Wong
2019-07-12 23:55 ` Sasha Levin
2019-07-11 14:00 ` [PATCH 3/3] xfs: Fix stale data exposure when readahead races with hole punch Jan Kara
2019-07-11 15:28 ` Amir Goldstein
2019-07-11 15:49 ` Darrick J. Wong
2019-07-12 12:00 ` Jan Kara
2019-07-12 17:56 ` Darrick J. Wong [this message]
2019-08-29 13:10 [PATCH 0/3 v2] xfs: Fix races between readahead and hole punching Jan Kara
2019-08-29 13:10 ` [PATCH 3/3] xfs: Fix stale data exposure when readahead races with hole punch Jan Kara
2019-08-29 15:52 ` Darrick J. Wong
2019-08-30 15:24 ` Jan Kara
2019-08-30 16:02 ` Darrick J. Wong
2019-09-18 12:31 ` Jan Kara
2019-09-18 16:07 ` Darrick J. Wong
2019-09-23 12:33 ` Boaz Harrosh
2019-09-24 15:23 ` Jan Kara
2019-09-24 15:45 ` Boaz Harrosh
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=20190712175644.GQ1654093@magnolia \
--to=darrick.wong@oracle.com \
--cc=amir73il@gmail.com \
--cc=boaz@plexistor.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-xfs@vger.kernel.org \
--cc=stable@vger.kernel.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).