From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Christoph Hellwig <hch@infradead.org>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 8/8] xfs: ensure post-EOF zeroing happens after zeroing part of a file
Date: Thu, 21 Jun 2018 23:49:23 -0700 [thread overview]
Message-ID: <20180622064923.GR4838@magnolia> (raw)
In-Reply-To: <20180622062907.GA27254@infradead.org>
On Thu, Jun 21, 2018 at 11:29:07PM -0700, Christoph Hellwig wrote:
> On Thu, Jun 21, 2018 at 11:31:53AM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> >
> > If a user asks us to zero_range part of a file, the end of the range is
> > EOF, and not aligned to a page boundary, invoke writeback of the EOF
> > page to ensure that the post-EOF part of the page is zeroed. This
> > ensures that we don't expose stale memory contents via mmap, if in a
> > clumsy manner.
> >
> > Found by running generic/127 when it runs zero_range and mapread at EOF
> > one after the other.
> >
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> > fs/xfs/xfs_bmap_util.c | 15 ++++++++++++++-
> > 1 file changed, 14 insertions(+), 1 deletion(-)
> >
> >
> > diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
> > index abc37b0899c0..c94d376e4152 100644
> > --- a/fs/xfs/xfs_bmap_util.c
> > +++ b/fs/xfs/xfs_bmap_util.c
> > @@ -1208,7 +1208,20 @@ xfs_free_file_space(
> > return 0;
> > if (offset + len > XFS_ISIZE(ip))
> > len = XFS_ISIZE(ip) - offset;
> > - return iomap_zero_range(VFS_I(ip), offset, len, NULL, &xfs_iomap_ops);
> > + error = iomap_zero_range(VFS_I(ip), offset, len, NULL, &xfs_iomap_ops);
> > + if (error)
> > + return error;
> > +
> > + /*
> > + * If we zeroed right up to EOF and EOF straddles a page boundary we
> > + * must make sure that the post-EOF area is also zeroed because the
> > + * page could be mmap'd and iomap_zero_range doesn't do that for us.
> > + * Writeback of the eof page will do this, albeit clumsily.
> > + */
> > + if (offset + len < XFS_ISIZE(ip) || ((offset + len) & PAGE_MASK) == 0)
> > + return 0;
> > + return filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
> > + (offset + len) & ~PAGE_MASK, LLONG_MAX);
>
> Total nitpick, but between the kernel logic flow and comment I'd invert
> the check:
>
> if (offset + len >= XFS_ISIZE(ip) && (offset + len) & PAGE_MASK) {
> error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
> (offset + len) & ~PAGE_MASK, LLONG_MAX);
> }
>
> return error;
>
> Otherwise looks good:
>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
Ok, will update & test overnight.
--D
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2018-06-22 6:49 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-21 18:31 [PATCH 0/8] xfs-4.18: various fixes Darrick J. Wong
2018-06-21 18:31 ` [PATCH 1/8] xfs: allow empty transactions while frozen Darrick J. Wong
2018-06-22 6:18 ` Allison Henderson
2018-06-22 6:31 ` Christoph Hellwig
2018-06-21 18:31 ` [PATCH 2/8] xfs: fix fdblocks accounting w/ RMAPBT per-AG reservation Darrick J. Wong
2018-06-22 6:21 ` Allison Henderson
2018-06-21 18:31 ` [PATCH 3/8] xfs: don't trip over negative free space in xfs_reserve_blocks Darrick J. Wong
2018-06-22 6:31 ` Christoph Hellwig
2018-06-22 6:32 ` Allison Henderson
2018-06-21 18:31 ` [PATCH 4/8] xfs: don't allow insert-range to shift extents past the maximum offset Darrick J. Wong
2018-06-22 6:33 ` Allison Henderson
2018-06-22 6:39 ` Christoph Hellwig
2018-06-22 6:47 ` Darrick J. Wong
2018-06-22 21:21 ` [PATCH v2 " Darrick J. Wong
2018-06-23 6:47 ` Christoph Hellwig
2018-06-21 18:31 ` [PATCH 5/8] xfs: recheck reflink state after grabbing ILOCK_SHARED for a write Darrick J. Wong
2018-06-22 6:40 ` Christoph Hellwig
2018-06-21 18:31 ` [PATCH 6/8] xfs: fix uninitialized field in rtbitmap fsmap backend Darrick J. Wong
2018-06-22 6:37 ` Allison Henderson
2018-06-22 6:41 ` Christoph Hellwig
2018-06-22 6:47 ` Darrick J. Wong
2018-06-22 21:22 ` [PATCH v2 " Darrick J. Wong
2018-06-23 6:47 ` Christoph Hellwig
2018-06-21 18:31 ` [PATCH 7/8] xfs: fix off-by-one error in xfs_rtalloc_query_range Darrick J. Wong
2018-06-22 6:41 ` Christoph Hellwig
2018-06-22 6:41 ` Allison Henderson
2018-06-21 18:31 ` [PATCH 8/8] xfs: ensure post-EOF zeroing happens after zeroing part of a file Darrick J. Wong
2018-06-22 6:29 ` Christoph Hellwig
2018-06-22 6:49 ` Darrick J. Wong [this message]
2018-06-22 6:42 ` Allison Henderson
2018-06-22 6:21 ` [PATCH 9/8] xfs: check leaf attribute block freemap in verifier Darrick J. Wong
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=20180622064923.GR4838@magnolia \
--to=darrick.wong@oracle.com \
--cc=hch@infradead.org \
--cc=linux-xfs@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).