public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs: fix PAGE_MASK usage in xfs_free_file_space
@ 2018-11-27 23:43 Darrick J. Wong
  2018-11-28  4:28 ` Dave Chinner
  2018-11-28  7:14 ` Christoph Hellwig
  0 siblings, 2 replies; 3+ messages in thread
From: Darrick J. Wong @ 2018-11-27 23:43 UTC (permalink / raw)
  To: xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

In commit e53c4b598, I *tried* to teach xfs to force writeback when we
fzero/fpunch right up to EOF so that if EOF is in the middle of a page,
the post-EOF part of the page gets zeroed before we return to userspace.
Unfortunately, I missed the part where PAGE_MASK is ~(PAGE_SIZE - 1),
which means that we totally fail to zero if we're fpunching and EOF is
within the first page.  Worse yet, the same PAGE_MASK thinko plagues the
filemap_write_and_wait_range call, so we'd initiate writeback of the
entire file, which (mostly) masked the thinko.

Drop the tricky PAGE_MASK and replace it with correct usage of PAGE_SIZE
and the proper rounding macros.

Fixes: e53c4b598 ("xfs: ensure post-EOF zeroing happens after zeroing part of a file")
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/xfs_bmap_util.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index 404e581f1ea1..1ee8c5539fa4 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -1126,9 +1126,9 @@ xfs_free_file_space(
 	 * 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)) {
+	if (offset + len >= XFS_ISIZE(ip) && offset_in_page(offset + len) > 0) {
 		error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
-				(offset + len) & ~PAGE_MASK, LLONG_MAX);
+				round_down(offset + len, PAGE_SIZE), LLONG_MAX);
 	}
 
 	return error;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] xfs: fix PAGE_MASK usage in xfs_free_file_space
  2018-11-27 23:43 [PATCH] xfs: fix PAGE_MASK usage in xfs_free_file_space Darrick J. Wong
@ 2018-11-28  4:28 ` Dave Chinner
  2018-11-28  7:14 ` Christoph Hellwig
  1 sibling, 0 replies; 3+ messages in thread
From: Dave Chinner @ 2018-11-28  4:28 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: xfs

On Tue, Nov 27, 2018 at 03:43:34PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> In commit e53c4b598, I *tried* to teach xfs to force writeback when we
> fzero/fpunch right up to EOF so that if EOF is in the middle of a page,
> the post-EOF part of the page gets zeroed before we return to userspace.
> Unfortunately, I missed the part where PAGE_MASK is ~(PAGE_SIZE - 1),
> which means that we totally fail to zero if we're fpunching and EOF is
> within the first page.  Worse yet, the same PAGE_MASK thinko plagues the
> filemap_write_and_wait_range call, so we'd initiate writeback of the
> entire file, which (mostly) masked the thinko.
> 
> Drop the tricky PAGE_MASK and replace it with correct usage of PAGE_SIZE
> and the proper rounding macros.
> 
> Fixes: e53c4b598 ("xfs: ensure post-EOF zeroing happens after zeroing part of a file")
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>  fs/xfs/xfs_bmap_util.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
> index 404e581f1ea1..1ee8c5539fa4 100644
> --- a/fs/xfs/xfs_bmap_util.c
> +++ b/fs/xfs/xfs_bmap_util.c
> @@ -1126,9 +1126,9 @@ xfs_free_file_space(
>  	 * 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)) {
> +	if (offset + len >= XFS_ISIZE(ip) && offset_in_page(offset + len) > 0) {
>  		error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
> -				(offset + len) & ~PAGE_MASK, LLONG_MAX);
> +				round_down(offset + len, PAGE_SIZE), LLONG_MAX);

Looks fine. I think I tripped over this in my bs > ps series and
changed it to round_down(..., max(bs, ps)), but that's not necessary
here...

Reviewed-by: Dave Chinner <dchinner@redhat.com>

-- 
Dave Chinner
david@fromorbit.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] xfs: fix PAGE_MASK usage in xfs_free_file_space
  2018-11-27 23:43 [PATCH] xfs: fix PAGE_MASK usage in xfs_free_file_space Darrick J. Wong
  2018-11-28  4:28 ` Dave Chinner
@ 2018-11-28  7:14 ` Christoph Hellwig
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2018-11-28  7:14 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: xfs

On Tue, Nov 27, 2018 at 03:43:34PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> In commit e53c4b598, I *tried* to teach xfs to force writeback when we
> fzero/fpunch right up to EOF so that if EOF is in the middle of a page,
> the post-EOF part of the page gets zeroed before we return to userspace.
> Unfortunately, I missed the part where PAGE_MASK is ~(PAGE_SIZE - 1),
> which means that we totally fail to zero if we're fpunching and EOF is
> within the first page.  Worse yet, the same PAGE_MASK thinko plagues the
> filemap_write_and_wait_range call, so we'd initiate writeback of the
> entire file, which (mostly) masked the thinko.
> 
> Drop the tricky PAGE_MASK and replace it with correct usage of PAGE_SIZE
> and the proper rounding macros.
> 
> Fixes: e53c4b598 ("xfs: ensure post-EOF zeroing happens after zeroing part of a file")
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

Thanks.  This also happens to be much more readable as well:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-11-28 18:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-27 23:43 [PATCH] xfs: fix PAGE_MASK usage in xfs_free_file_space Darrick J. Wong
2018-11-28  4:28 ` Dave Chinner
2018-11-28  7:14 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox