From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26972C43461 for ; Mon, 7 Sep 2020 09:36:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E1BF82075A for ; Mon, 7 Sep 2020 09:36:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728331AbgIGJgs (ORCPT ); Mon, 7 Sep 2020 05:36:48 -0400 Received: from mx2.suse.de ([195.135.220.15]:35810 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727122AbgIGJgr (ORCPT ); Mon, 7 Sep 2020 05:36:47 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 29F91AC3C; Mon, 7 Sep 2020 09:36:46 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 30E321E12D1; Mon, 7 Sep 2020 11:36:45 +0200 (CEST) Date: Mon, 7 Sep 2020 11:36:45 +0200 From: Jan Kara To: Gabriel Krisman Bertazi Cc: viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, jack@suse.cz, khazhy@google.com, kernel@collabora.com, Jamie Liu Subject: Re: [PATCH v3 3/3] direct-io: defer alignment check until after the EOF check Message-ID: <20200907093645.GE16559@quack2.suse.cz> References: <20200905052023.3719585-1-krisman@collabora.com> <20200905052023.3719585-4-krisman@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200905052023.3719585-4-krisman@collabora.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 > Signed-off-by: Gabriel Krisman Bertazi The patch looks good to me. You can add: Reviewed-by: Jan Kara 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 SUSE Labs, CR