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
Cc: Dylan Yudaken <dylany@fb.com>, Jens Axboe <axboe@kernel.dk>
Subject: [PATCH] btrfs: handle DIO read faults properly
Date: Thu, 11 Aug 2022 17:06:11 -0400	[thread overview]
Message-ID: <552156d49d65ab7d635554b697252fdbfb8f93b0.1660251962.git.josef@toxicpanda.com> (raw)

Dylan reported a problem where he had an io_uring test that was returning
short DIO reads with ee5b46a353af ("btrfs: increase direct io read size
limit to 256 sectors") applied.  This turned out to be a red herring,
this simply increases the size of the reads we'll attempt to do in one
go.  The root of the problem is that because we're now trying to read in
more into our buffer, we're more likely to hit a page fault while trying
to read into the buffer.

Because we pass IOMAP_DIO_PARTIAL into iomap if we get an -EFAULT we'll
simply return 0, expecting that we'll do the fault and then try again.
However since we're only checking for a ret > 0 || ret == -EFAULT we
return a short read.  Fix this by checking for a 0 read from iomap as
well.  I've left the EFAULT case because it appears like we can still
get this in the case of a page fault from a direct read from an inline
extent.

Jens tested this patch with their testcase and it fixed the problem.

Reported-by: Dylan Yudaken <dylany@fb.com>
Tested-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index c9649b7b2f18..a61085ac59d6 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -3776,7 +3776,7 @@ static ssize_t btrfs_direct_read(struct kiocb *iocb, struct iov_iter *to)
 	if (ret > 0)
 		read = ret;
 
-	if (iov_iter_count(to) > 0 && (ret == -EFAULT || ret > 0)) {
+	if (iov_iter_count(to) > 0 && (ret == -EFAULT || ret >= 0)) {
 		const size_t left = iov_iter_count(to);
 
 		if (left == prev_left) {
-- 
2.26.3


             reply	other threads:[~2022-08-11 21:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-11 21:06 Josef Bacik [this message]
2022-08-12  9:02 ` [PATCH] btrfs: handle DIO read faults properly Filipe Manana
2022-08-12 15:39   ` Josef Bacik
2022-08-19 15:55   ` Josef Bacik

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=552156d49d65ab7d635554b697252fdbfb8f93b0.1660251962.git.josef@toxicpanda.com \
    --to=josef@toxicpanda.com \
    --cc=axboe@kernel.dk \
    --cc=dylany@fb.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.