All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: fix infinite loop with dio faulting
@ 2022-07-21 16:10 Josef Bacik
  2022-08-02 17:17 ` David Sterba
  2022-08-02 18:08 ` Filipe Manana
  0 siblings, 2 replies; 5+ messages in thread
From: Josef Bacik @ 2022-07-21 16:10 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs: fix infinite loop with dio faulting
  2022-07-21 16:10 [PATCH] btrfs: fix infinite loop with dio faulting Josef Bacik
@ 2022-08-02 17:17 ` David Sterba
  2022-08-02 18:09   ` Filipe Manana
  2022-08-02 18:08 ` Filipe Manana
  1 sibling, 1 reply; 5+ messages in thread
From: David Sterba @ 2022-08-02 17:17 UTC (permalink / raw)
  To: Josef Bacik; +Cc: linux-btrfs, kernel-team

On Thu, Jul 21, 2022 at 12:10:14PM -0400, Josef Bacik wrote:
> 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.

Folded to the patch, thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs: fix infinite loop with dio faulting
  2022-07-21 16:10 [PATCH] btrfs: fix infinite loop with dio faulting Josef Bacik
  2022-08-02 17:17 ` David Sterba
@ 2022-08-02 18:08 ` Filipe Manana
  1 sibling, 0 replies; 5+ messages in thread
From: Filipe Manana @ 2022-08-02 18:08 UTC (permalink / raw)
  To: Josef Bacik; +Cc: linux-btrfs, kernel-team

On Thu, Jul 21, 2022 at 5:12 PM Josef Bacik <josef@toxicpanda.com> wrote:
>
> 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.

Yes, and the removal was intentional (not by accident).

Adding the check back makes the same check at dio_fault_in_size()
useless and redundant.

> 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 doesn't answer why the infinite loop happens.
Why can't we faultin at least one page? Have you checked why this happens?

So I'd rather not fold this into the original patch, and instead
revert it until we know exactly why we end in the infinite loop.

Thanks.

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


-- 
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs: fix infinite loop with dio faulting
  2022-08-02 17:17 ` David Sterba
@ 2022-08-02 18:09   ` Filipe Manana
  2022-08-02 18:16     ` David Sterba
  0 siblings, 1 reply; 5+ messages in thread
From: Filipe Manana @ 2022-08-02 18:09 UTC (permalink / raw)
  To: David Sterba, Josef Bacik, linux-btrfs, kernel-team

On Tue, Aug 2, 2022 at 7:00 PM David Sterba <dsterba@suse.cz> wrote:
>
> On Thu, Jul 21, 2022 at 12:10:14PM -0400, Josef Bacik wrote:
> > 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.
>
> Folded to the patch, thanks.

Please don't, revert instead the original patch.
See my previous reply to the patch.

Thanks.



-- 
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs: fix infinite loop with dio faulting
  2022-08-02 18:09   ` Filipe Manana
@ 2022-08-02 18:16     ` David Sterba
  0 siblings, 0 replies; 5+ messages in thread
From: David Sterba @ 2022-08-02 18:16 UTC (permalink / raw)
  To: Filipe Manana; +Cc: David Sterba, Josef Bacik, linux-btrfs, kernel-team

On Tue, Aug 02, 2022 at 07:09:28PM +0100, Filipe Manana wrote:
> On Tue, Aug 2, 2022 at 7:00 PM David Sterba <dsterba@suse.cz> wrote:
> >
> > On Thu, Jul 21, 2022 at 12:10:14PM -0400, Josef Bacik wrote:
> > > 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.
> >
> > Folded to the patch, thanks.
> 
> Please don't, revert instead the original patch.

OK, patch removed from misc-next, no need to revert.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-08-02 18:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-21 16:10 [PATCH] btrfs: fix infinite loop with dio faulting Josef Bacik
2022-08-02 17:17 ` David Sterba
2022-08-02 18:09   ` Filipe Manana
2022-08-02 18:16     ` David Sterba
2022-08-02 18:08 ` Filipe Manana

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.