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=-14.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 13479C433E2 for ; Mon, 14 Sep 2020 14:39:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C3C5E20829 for ; Mon, 14 Sep 2020 14:39:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600094350; bh=hcg0xITRDx7PJvaz4JYlC8n1jzqkFTy22dae6DGDrbI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=lHGvYaBL/LLE3AaMANAiMisX5ce9k2OGTnpRxw2ZTuWT+3ro8GFyrnVWcRAH4vZkw cmJ8CRu1RR/e5Ej46DvbOhazqK3zpNROnArP7BiUTE0Rtm5qCnrLctif9RDGPLDl2T FYPRl/JMugmsaWEM7DkDPiRHsW6emTvB3EkgIvTs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726655AbgINOjH (ORCPT ); Mon, 14 Sep 2020 10:39:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:60272 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726646AbgINNFm (ORCPT ); Mon, 14 Sep 2020 09:05:42 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0916F22249; Mon, 14 Sep 2020 13:04:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600088696; bh=hcg0xITRDx7PJvaz4JYlC8n1jzqkFTy22dae6DGDrbI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1/kp7RtJeLWo0vLBDkBZZU69C2h1e/BjBShpl01TSKfPfKNwmcy3ojWoYabnGUpXz ybXtKI6UTlBhnoRWlZukRy+DsQj9CWhJ9CXQ61FCXDPI7DBoCZ7WdFmNBNcLz+EdzC BhoIKTnetwGU14shSRhaNICH129Qz8BqE2V9qurw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Gabriel Krisman Bertazi , Chao Yu , Jaegeuk Kim , Sasha Levin , linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH AUTOSEL 5.4 18/22] f2fs: Return EOF on unaligned end of file DIO read Date: Mon, 14 Sep 2020 09:04:30 -0400 Message-Id: <20200914130434.1804478-18-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914130434.1804478-1-sashal@kernel.org> References: <20200914130434.1804478-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gabriel Krisman Bertazi [ Upstream commit 20d0a107fb35f37578b919f62bd474d6d358d579 ] Reading past end of file returns EOF for aligned reads but -EINVAL for unaligned reads on f2fs. While documentation is not strict about this corner case, most filesystem returns EOF on this case, like iomap filesystems. This patch consolidates the behavior for f2fs, by making it return EOF(0). it can be verified by a read loop on a file that does a partial read before EOF (A file that doesn't end at an aligned address). The following code fails on an unaligned file on f2fs, but not on btrfs, ext4, and xfs. while (done < total) { ssize_t delta = pread(fd, buf + done, total - done, off + done); if (!delta) break; ... } It is arguable whether filesystems should actually return EOF or -EINVAL, but since iomap filesystems support it, and so does the original DIO code, it seems reasonable to consolidate on that. Signed-off-by: Gabriel Krisman Bertazi Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/data.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index ec9a1f9ce2dd6..68be334afc286 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2753,6 +2753,9 @@ static int check_direct_IO(struct inode *inode, struct iov_iter *iter, unsigned long align = offset | iov_iter_alignment(iter); struct block_device *bdev = inode->i_sb->s_bdev; + if (iov_iter_rw(iter) == READ && offset >= i_size_read(inode)) + return 1; + if (align & blocksize_mask) { if (bdev) blkbits = blksize_bits(bdev_logical_block_size(bdev)); -- 2.25.1