All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH] btrfs: fix infinite loop with dio faulting
Date: Thu, 21 Jul 2022 12:10:14 -0400	[thread overview]
Message-ID: <27a36e2b4cf30de8f7a04e718ba47bb9e98ddb85.1658419807.git.josef@toxicpanda.com> (raw)

Filipe removed the check for the case where we are constantly trying to
fault in the buffer from user space for DIO reads.  He left it for
writes, but for reads you can end up in this infinite loop trying to
fault in a page that won't fault in.  This is the patch I applied ontop
of his patch, without this I was able to get generic/475 to get stuck
infinite looping.

This patch is currently staged so we can probably just fold this into
his actual patch.

Fixes: 5ad7531dbe67 ("btrfs: fault in pages for direct io reads/writes in a more controlled way")
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/file.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 1876072dee9d..79f866e36368 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -3806,20 +3806,21 @@ static ssize_t btrfs_direct_read(struct kiocb *iocb, struct iov_iter *to)
 		read = ret;
 
 	if (iov_iter_count(to) > 0 && (ret == -EFAULT || ret > 0)) {
-		if (iter_is_iovec(to)) {
-			const size_t left = iov_iter_count(to);
-			const size_t size = dio_fault_in_size(iocb, to, prev_left);
+		const size_t left = iov_iter_count(to);
 
-			fault_in_iov_iter_writeable(to, size);
-			prev_left = left;
-			goto again;
-		} else {
+		if (left == prev_left) {
 			/*
 			 * fault_in_iov_iter_writeable() only works for iovecs,
 			 * return with a partial read and fallback to buffered
 			 * IO for the rest of the range.
 			 */
 			ret = read;
+		} else {
+			const size_t size = dio_fault_in_size(iocb, to, prev_left);
+
+			fault_in_iov_iter_writeable(to, size);
+			prev_left = left;
+			goto again;
 		}
 	}
 	btrfs_inode_unlock(inode, BTRFS_ILOCK_SHARED);
-- 
2.26.3


             reply	other threads:[~2022-07-21 16:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-21 16:10 Josef Bacik [this message]
2022-08-02 17:17 ` [PATCH] btrfs: fix infinite loop with dio faulting David Sterba
2022-08-02 18:09   ` Filipe Manana
2022-08-02 18:16     ` David Sterba
2022-08-02 18:08 ` Filipe Manana

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=27a36e2b4cf30de8f7a04e718ba47bb9e98ddb85.1658419807.git.josef@toxicpanda.com \
    --to=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.