Linux-Fsdevel Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Gabriel Krisman Bertazi <krisman@collabora.com>
Cc: viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org,
	jack@suse.cz, khazhy@google.com, kernel@collabora.com,
	Jamie Liu <jamieliu@google.com>
Subject: Re: [PATCH v3 3/3] direct-io: defer alignment check until after the EOF check
Date: Mon, 7 Sep 2020 11:36:45 +0200	[thread overview]
Message-ID: <20200907093645.GE16559@quack2.suse.cz> (raw)
In-Reply-To: <20200905052023.3719585-4-krisman@collabora.com>

On Sat 05-09-20 01:20:23, Gabriel Krisman Bertazi wrote:
> 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>
> Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>

The patch looks good to me. You can add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  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
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

      reply	other threads:[~2020-09-07  9:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-05  5:20 [PATCH v3 0/3] Unaligned DIO read error path fix and clean ups Gabriel Krisman Bertazi
2020-09-05  5:20 ` [PATCH v3 1/3] direct-io: clean up error paths of do_blockdev_direct_IO Gabriel Krisman Bertazi
2020-09-07  9:32   ` Jan Kara
2020-09-05  5:20 ` [PATCH v3 2/3] direct-io: don't force writeback for reads beyond EOF Gabriel Krisman Bertazi
2020-09-05  5:20 ` [PATCH v3 3/3] direct-io: defer alignment check until after the EOF check Gabriel Krisman Bertazi
2020-09-07  9:36   ` Jan Kara [this message]

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=20200907093645.GE16559@quack2.suse.cz \
    --to=jack@suse.cz \
    --cc=jamieliu@google.com \
    --cc=kernel@collabora.com \
    --cc=khazhy@google.com \
    --cc=krisman@collabora.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --subject='Re: [PATCH v3 3/3] direct-io: defer alignment check until after the EOF check' \
    /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

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).