All of lore.kernel.org
 help / color / mirror / Atom feed
* [RESEND^2 PATCH v3 0/3] Clean up and fix error handling in DIO
@ 2020-10-08  6:26 Gabriel Krisman Bertazi
  2020-10-08  6:26 ` [RESEND^2 PATCH 1/3] direct-io: clean up error paths of do_blockdev_direct_IO Gabriel Krisman Bertazi
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Gabriel Krisman Bertazi @ 2020-10-08  6:26 UTC (permalink / raw)
  To: viro, jack; +Cc: linux-fsdevel, Gabriel Krisman Bertazi, kernel

Hi,

Given the proximity of the merge window and since I haven't seen it pop
up in any of the trees, and considering it is reviewed and fixes a bug
for us, I'm trying another resend for this so it can get picked up in
time for 5.10.

Jan, thanks again for the review and sorry for the noise but is there
any one else that should be looking at this?

Original cover letter:

This is v3 of Unaligned DIO read error path fix and clean ups.  This
version applies some small fixes to patch 1 suggested by Jan Kara (thank
you!)  and it was tested with xfstests aio group over f2fs and fio
workloads.

Archive:
  v1: https://lkml.org/lkml/2020/9/14/915
  v2: https://www.spinics.net/lists/linux-fsdevel/msg177220.html
  v3: https://www.spinics.net/lists/linux-fsdevel/msg177310.html

Gabriel Krisman Bertazi (3):
  direct-io: clean up error paths of do_blockdev_direct_IO
  direct-io: don't force writeback for reads beyond EOF
  direct-io: defer alignment check until after the EOF check

 fs/direct-io.c | 69 ++++++++++++++++++++++----------------------------
 1 file changed, 30 insertions(+), 39 deletions(-)

-- 
2.28.0


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

* [RESEND^2 PATCH 1/3] direct-io: clean up error paths of do_blockdev_direct_IO
  2020-10-08  6:26 [RESEND^2 PATCH v3 0/3] Clean up and fix error handling in DIO Gabriel Krisman Bertazi
@ 2020-10-08  6:26 ` Gabriel Krisman Bertazi
  2020-10-08  6:26 ` [RESEND^2 PATCH 2/3] direct-io: don't force writeback for reads beyond EOF Gabriel Krisman Bertazi
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Gabriel Krisman Bertazi @ 2020-10-08  6:26 UTC (permalink / raw)
  To: viro, jack; +Cc: linux-fsdevel, Gabriel Krisman Bertazi, kernel

In preparation to resort DIO checks, reduce code duplication of error
handling in do_blockdev_direct_IO.

Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
---
 fs/direct-io.c | 35 ++++++++++++++---------------------
 1 file changed, 14 insertions(+), 21 deletions(-)

diff --git a/fs/direct-io.c b/fs/direct-io.c
index 183299892465..6c11db1cec27 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -1170,7 +1170,7 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
 			blkbits = blksize_bits(bdev_logical_block_size(bdev));
 		blocksize_mask = (1 << blkbits) - 1;
 		if (align & blocksize_mask)
-			goto out;
+			return -EINVAL;
 	}
 
 	/* watch out for a 0 len io from a tricksy fs */
@@ -1178,9 +1178,8 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
 		return 0;
 
 	dio = kmem_cache_alloc(dio_cache, GFP_KERNEL);
-	retval = -ENOMEM;
 	if (!dio)
-		goto out;
+		return -ENOMEM;
 	/*
 	 * Believe it or not, zeroing out the page array caused a .5%
 	 * performance regression in a database benchmark.  So, we take
@@ -1199,22 +1198,16 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
 
 			retval = filemap_write_and_wait_range(mapping, offset,
 							      end - 1);
-			if (retval) {
-				inode_unlock(inode);
-				kmem_cache_free(dio_cache, dio);
-				goto out;
-			}
+			if (retval)
+				goto fail_dio;
 		}
 	}
 
 	/* Once we sampled i_size check for reads beyond EOF */
 	dio->i_size = i_size_read(inode);
 	if (iov_iter_rw(iter) == READ && offset >= dio->i_size) {
-		if (dio->flags & DIO_LOCKING)
-			inode_unlock(inode);
-		kmem_cache_free(dio_cache, dio);
 		retval = 0;
-		goto out;
+		goto fail_dio;
 	}
 
 	/*
@@ -1258,14 +1251,8 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
 			 */
 			retval = sb_init_dio_done_wq(dio->inode->i_sb);
 		}
-		if (retval) {
-			/*
-			 * We grab i_mutex only for reads so we don't have
-			 * to release it here
-			 */
-			kmem_cache_free(dio_cache, dio);
-			goto out;
-		}
+		if (retval)
+			goto fail_dio;
 	}
 
 	/*
@@ -1368,7 +1355,13 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
 	} else
 		BUG_ON(retval != -EIOCBQUEUED);
 
-out:
+	return retval;
+
+fail_dio:
+	if (dio->flags & DIO_LOCKING && iov_iter_rw(iter) == READ)
+		inode_unlock(inode);
+
+	kmem_cache_free(dio_cache, dio);
 	return retval;
 }
 
-- 
2.28.0


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

* [RESEND^2 PATCH 2/3] direct-io: don't force writeback for reads beyond EOF
  2020-10-08  6:26 [RESEND^2 PATCH v3 0/3] Clean up and fix error handling in DIO Gabriel Krisman Bertazi
  2020-10-08  6:26 ` [RESEND^2 PATCH 1/3] direct-io: clean up error paths of do_blockdev_direct_IO Gabriel Krisman Bertazi
@ 2020-10-08  6:26 ` Gabriel Krisman Bertazi
  2020-10-08  6:26 ` [RESEND^2 PATCH 3/3] direct-io: defer alignment check until after the EOF check Gabriel Krisman Bertazi
  2020-10-08  9:32 ` [RESEND^2 PATCH v3 0/3] Clean up and fix error handling in DIO Jan Kara
  3 siblings, 0 replies; 7+ messages in thread
From: Gabriel Krisman Bertazi @ 2020-10-08  6:26 UTC (permalink / raw)
  To: viro, jack; +Cc: linux-fsdevel, Gabriel Krisman Bertazi, kernel

If a DIO read starts past EOF, the kernel won't attempt it, so we don't
need to flush dirty pages before failing the syscall.

Suggested-by: Jan Kara <jack@suse.cz>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
---
 fs/direct-io.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/fs/direct-io.c b/fs/direct-io.c
index 6c11db1cec27..c17efe58f1c9 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -1188,19 +1188,9 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
 	memset(dio, 0, offsetof(struct dio, pages));
 
 	dio->flags = flags;
-	if (dio->flags & DIO_LOCKING) {
-		if (iov_iter_rw(iter) == READ) {
-			struct address_space *mapping =
-					iocb->ki_filp->f_mapping;
-
-			/* will be released by direct_io_worker */
-			inode_lock(inode);
-
-			retval = filemap_write_and_wait_range(mapping, offset,
-							      end - 1);
-			if (retval)
-				goto fail_dio;
-		}
+	if (dio->flags & DIO_LOCKING && iov_iter_rw(iter) == READ) {
+		/* will be released by direct_io_worker */
+		inode_lock(inode);
 	}
 
 	/* Once we sampled i_size check for reads beyond EOF */
@@ -1210,6 +1200,14 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
 		goto fail_dio;
 	}
 
+	if (dio->flags & DIO_LOCKING && iov_iter_rw(iter) == READ) {
+		struct address_space *mapping = iocb->ki_filp->f_mapping;
+
+		retval = filemap_write_and_wait_range(mapping, offset, end - 1);
+		if (retval)
+			goto fail_dio;
+	}
+
 	/*
 	 * For file extending writes updating i_size before data writeouts
 	 * complete can expose uninitialized blocks in dumb filesystems.
-- 
2.28.0


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

* [RESEND^2 PATCH 3/3] direct-io: defer alignment check until after the EOF check
  2020-10-08  6:26 [RESEND^2 PATCH v3 0/3] Clean up and fix error handling in DIO Gabriel Krisman Bertazi
  2020-10-08  6:26 ` [RESEND^2 PATCH 1/3] direct-io: clean up error paths of do_blockdev_direct_IO Gabriel Krisman Bertazi
  2020-10-08  6:26 ` [RESEND^2 PATCH 2/3] direct-io: don't force writeback for reads beyond EOF Gabriel Krisman Bertazi
@ 2020-10-08  6:26 ` Gabriel Krisman Bertazi
  2020-10-08  9:32 ` [RESEND^2 PATCH v3 0/3] Clean up and fix error handling in DIO Jan Kara
  3 siblings, 0 replies; 7+ messages in thread
From: Gabriel Krisman Bertazi @ 2020-10-08  6:26 UTC (permalink / raw)
  To: viro, jack; +Cc: linux-fsdevel, Gabriel Krisman Bertazi, kernel, Jamie Liu

Prior to commit 9fe55eea7e4b ("Fix race when checking i_size on direct
i/o read"), an unaligned direct read past end of file would trigger EOF,
since generic_file_aio_read detected this read-at-EOF condition and
skipped the direct IO read entirely, returning 0. After that change, the
read now reaches dio_generic, which detects the misalignment and returns
EINVAL.

This consolidates the generic direct-io to follow the same behavior of
filesystems.  Apparently, this fix will only affect ocfs2 since other
filesystems do this verification before calling do_blockdev_direct_IO,
with the exception of f2fs, which has the same bug, but is fixed in the
next patch.

it can be verified by a read loop on a file that does a partial read
before EOF (On file that doesn't end at an aligned address).  The
following code fails on an unaligned file on filesystems without
prior validation without this patch, but not on btrfs, ext4, and xfs.

  while (done < total) {
    ssize_t delta = pread(fd, buf + done, total - done, off + done);
    if (!delta)
      break;
    ...
  }

Fix this regression by moving the misalignment check to after the EOF
check added by commit 74cedf9b6c60 ("direct-io: Fix negative return from
dio read beyond eof").

Based on a patch by Jamie Liu.

Reported-by: Jamie Liu <jamieliu@google.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
---
 fs/direct-io.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/fs/direct-io.c b/fs/direct-io.c
index c17efe58f1c9..82838cca934b 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -1165,14 +1165,6 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
 	 * the early prefetch in the caller enough time.
 	 */
 
-	if (align & blocksize_mask) {
-		if (bdev)
-			blkbits = blksize_bits(bdev_logical_block_size(bdev));
-		blocksize_mask = (1 << blkbits) - 1;
-		if (align & blocksize_mask)
-			return -EINVAL;
-	}
-
 	/* watch out for a 0 len io from a tricksy fs */
 	if (iov_iter_rw(iter) == READ && !count)
 		return 0;
@@ -1200,6 +1192,14 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
 		goto fail_dio;
 	}
 
+	if (align & blocksize_mask) {
+		if (bdev)
+			blkbits = blksize_bits(bdev_logical_block_size(bdev));
+		blocksize_mask = (1 << blkbits) - 1;
+		if (align & blocksize_mask)
+			goto fail_dio;
+	}
+
 	if (dio->flags & DIO_LOCKING && iov_iter_rw(iter) == READ) {
 		struct address_space *mapping = iocb->ki_filp->f_mapping;
 
-- 
2.28.0


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

* Re: [RESEND^2 PATCH v3 0/3] Clean up and fix error handling in DIO
  2020-10-08  6:26 [RESEND^2 PATCH v3 0/3] Clean up and fix error handling in DIO Gabriel Krisman Bertazi
                   ` (2 preceding siblings ...)
  2020-10-08  6:26 ` [RESEND^2 PATCH 3/3] direct-io: defer alignment check until after the EOF check Gabriel Krisman Bertazi
@ 2020-10-08  9:32 ` Jan Kara
  2020-10-08 16:16   ` Jens Axboe
  3 siblings, 1 reply; 7+ messages in thread
From: Jan Kara @ 2020-10-08  9:32 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi; +Cc: viro, jack, linux-fsdevel, kernel, Jens Axboe

On Thu 08-10-20 02:26:17, Gabriel Krisman Bertazi wrote:
> Hi,
> 
> Given the proximity of the merge window and since I haven't seen it pop
> up in any of the trees, and considering it is reviewed and fixes a bug
> for us, I'm trying another resend for this so it can get picked up in
> time for 5.10.
> 
> Jan, thanks again for the review and sorry for the noise but is there
> any one else that should be looking at this?

If you can't catch attention of Al Viro, then Jens Axboe is sometimes
merging direct IO fixes as well through his tree. Added to CC. If that
doesn't work out, I can also take the changes through my tree and send them
to Linus in a separate pull request...

								Honza

> Original cover letter:
> 
> This is v3 of Unaligned DIO read error path fix and clean ups.  This
> version applies some small fixes to patch 1 suggested by Jan Kara (thank
> you!)  and it was tested with xfstests aio group over f2fs and fio
> workloads.
> 
> Archive:
>   v1: https://lkml.org/lkml/2020/9/14/915
>   v2: https://www.spinics.net/lists/linux-fsdevel/msg177220.html
>   v3: https://www.spinics.net/lists/linux-fsdevel/msg177310.html
> 
> Gabriel Krisman Bertazi (3):
>   direct-io: clean up error paths of do_blockdev_direct_IO
>   direct-io: don't force writeback for reads beyond EOF
>   direct-io: defer alignment check until after the EOF check
> 
>  fs/direct-io.c | 69 ++++++++++++++++++++++----------------------------
>  1 file changed, 30 insertions(+), 39 deletions(-)
> 
> -- 
> 2.28.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

* Re: [RESEND^2 PATCH v3 0/3] Clean up and fix error handling in DIO
  2020-10-08  9:32 ` [RESEND^2 PATCH v3 0/3] Clean up and fix error handling in DIO Jan Kara
@ 2020-10-08 16:16   ` Jens Axboe
  2020-10-08 16:27     ` Jan Kara
  0 siblings, 1 reply; 7+ messages in thread
From: Jens Axboe @ 2020-10-08 16:16 UTC (permalink / raw)
  To: Jan Kara, Gabriel Krisman Bertazi; +Cc: viro, linux-fsdevel, kernel

On 10/8/20 3:32 AM, Jan Kara wrote:
> On Thu 08-10-20 02:26:17, Gabriel Krisman Bertazi wrote:
>> Hi,
>>
>> Given the proximity of the merge window and since I haven't seen it pop
>> up in any of the trees, and considering it is reviewed and fixes a bug
>> for us, I'm trying another resend for this so it can get picked up in
>> time for 5.10.
>>
>> Jan, thanks again for the review and sorry for the noise but is there
>> any one else that should be looking at this?
> 
> If you can't catch attention of Al Viro, then Jens Axboe is sometimes
> merging direct IO fixes as well through his tree. Added to CC. If that
> doesn't work out, I can also take the changes through my tree and send them
> to Linus in a separate pull request...

For this case, probably best if you take it, Jan. I looked over the
patches and they look good to me, feel free to add:

Reviewed-by: Jens Axboe <axboe@kernel.dk>

-- 
Jens Axboe


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

* Re: [RESEND^2 PATCH v3 0/3] Clean up and fix error handling in DIO
  2020-10-08 16:16   ` Jens Axboe
@ 2020-10-08 16:27     ` Jan Kara
  0 siblings, 0 replies; 7+ messages in thread
From: Jan Kara @ 2020-10-08 16:27 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Jan Kara, Gabriel Krisman Bertazi, viro, linux-fsdevel, kernel

On Thu 08-10-20 10:16:07, Jens Axboe wrote:
> On 10/8/20 3:32 AM, Jan Kara wrote:
> > On Thu 08-10-20 02:26:17, Gabriel Krisman Bertazi wrote:
> >> Hi,
> >>
> >> Given the proximity of the merge window and since I haven't seen it pop
> >> up in any of the trees, and considering it is reviewed and fixes a bug
> >> for us, I'm trying another resend for this so it can get picked up in
> >> time for 5.10.
> >>
> >> Jan, thanks again for the review and sorry for the noise but is there
> >> any one else that should be looking at this?
> > 
> > If you can't catch attention of Al Viro, then Jens Axboe is sometimes
> > merging direct IO fixes as well through his tree. Added to CC. If that
> > doesn't work out, I can also take the changes through my tree and send them
> > to Linus in a separate pull request...
> 
> For this case, probably best if you take it, Jan. I looked over the
> patches and they look good to me, feel free to add:
> 
> Reviewed-by: Jens Axboe <axboe@kernel.dk>

Ok, I'll pull them into my tree. Thanks for review Jens!

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

end of thread, other threads:[~2020-10-08 16:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-08  6:26 [RESEND^2 PATCH v3 0/3] Clean up and fix error handling in DIO Gabriel Krisman Bertazi
2020-10-08  6:26 ` [RESEND^2 PATCH 1/3] direct-io: clean up error paths of do_blockdev_direct_IO Gabriel Krisman Bertazi
2020-10-08  6:26 ` [RESEND^2 PATCH 2/3] direct-io: don't force writeback for reads beyond EOF Gabriel Krisman Bertazi
2020-10-08  6:26 ` [RESEND^2 PATCH 3/3] direct-io: defer alignment check until after the EOF check Gabriel Krisman Bertazi
2020-10-08  9:32 ` [RESEND^2 PATCH v3 0/3] Clean up and fix error handling in DIO Jan Kara
2020-10-08 16:16   ` Jens Axboe
2020-10-08 16:27     ` Jan Kara

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.