public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs: read_write: make default in vfs_copy_file_range() reachable
       [not found] <20231130141624.3338942-4-amir73il@gmail.com>
@ 2023-12-05  0:16 ` Bert Karwatzki
  2023-12-05  3:45   ` Amir Goldstein
  0 siblings, 1 reply; 4+ messages in thread
From: Bert Karwatzki @ 2023-12-05  0:16 UTC (permalink / raw)
  To: amir73il, Jan Kara, Christian Brauner
  Cc: axboe, dhowells, hch, jlayton, josef, linux-fsdevel, miklos, viro,
	Bert Karwatzki, linux-kernel

If vfs_copy_file_range() is called with (flags & COPY_FILE_SPLICE == 0)
and both file_out->f_op->copy_file_range and file_in->f_op->remap_file_range
are NULL, too, the default call to do_splice_direct() cannot be reached.
This patch adds an else clause to make the default reachable in all
cases.

Signed-off-by: Bert Karwatzki <spasswolf@web.de>
---
 fs/read_write.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/read_write.c b/fs/read_write.c
index e0c2c1b5962b..3599c54bd26d 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -1554,6 +1554,8 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
 		/* fallback to splice */
 		if (ret <= 0)
 			splice = true;
+	} else {
+		splice = true;
 	}

 	file_end_write(file_out);
--
2.39.2

Since linux-next-20231204 I noticed that it was impossible to start the
game Path of Exile (using the steam client). I bisected the error to
commit 05ee2d85cd4ace5cd37dc24132e3fd7f5142ebef. Reverting this commit
in linux-next-20231204 made the game start again and after inserting
printks into vfs_copy_file_range() I found that steam (via python3)
calls this function with (flags & COPY_FILE_SPLICE == 0),
file_out->f_op->copy_file_range == NULL and
file_in->f_op->remap_file_range == NULL so the default is never reached.
This patch adds a catch all else clause so the default is reached in
all cases. This patch fixes the describe issue with steam and Path of
Exile.

Bert Karwatzki

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

* Re: [PATCH] fs: read_write: make default in vfs_copy_file_range() reachable
  2023-12-05  0:16 ` [PATCH] fs: read_write: make default in vfs_copy_file_range() reachable Bert Karwatzki
@ 2023-12-05  3:45   ` Amir Goldstein
  2023-12-05  5:01     ` Amir Goldstein
  0 siblings, 1 reply; 4+ messages in thread
From: Amir Goldstein @ 2023-12-05  3:45 UTC (permalink / raw)
  To: Bert Karwatzki, Christian Brauner
  Cc: Jan Kara, axboe, dhowells, hch, jlayton, josef, linux-fsdevel,
	miklos, viro, linux-kernel

On Tue, Dec 5, 2023 at 2:16 AM Bert Karwatzki <spasswolf@web.de> wrote:
>
> If vfs_copy_file_range() is called with (flags & COPY_FILE_SPLICE == 0)
> and both file_out->f_op->copy_file_range and file_in->f_op->remap_file_range
> are NULL, too, the default call to do_splice_direct() cannot be reached.
> This patch adds an else clause to make the default reachable in all
> cases.
>
> Signed-off-by: Bert Karwatzki <spasswolf@web.de>

Hi Bert,

Thank you for testing and reporting this so early!!

I would edit the commit message differently, but anyway, I think that
the fix should be folded into commit 05ee2d85cd4a ("fs: use
do_splice_direct() for nfsd/ksmbd server-side-copy").

Since I end up making a mistake every time I touch this code,
I also added a small edit to your patch below, that should make the logic
more clear to readers. Hopefully, that will help me avoid making a mistake
the next time I touch this code...

Would you mind testing my revised fix, so we can add:
  Tested-by: Bert Karwatzki <spasswolf@web.de>
when folding it into the original patch?

Thanks,
Amir.

> ---
>  fs/read_write.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/fs/read_write.c b/fs/read_write.c
> index e0c2c1b5962b..3599c54bd26d 100644
> --- a/fs/read_write.c
> +++ b/fs/read_write.c
> @@ -1554,6 +1554,8 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
>                 /* fallback to splice */
>                 if (ret <= 0)
>                         splice = true;
> +       } else {

This is logically correct because of the earlier "same sb" check in
generic_copy_file_checks(), but we better spell out the logic here as well:

+            } else if (file_inode(file_in)->i_sb ==
file_inode(file_out)->i_sb) {
+                    /* Fallback to splice for same sb copy for
backward compat */

> +               splice = true;
>         }
>
>         file_end_write(file_out);
> --
> 2.39.2
>
> Since linux-next-20231204 I noticed that it was impossible to start the
> game Path of Exile (using the steam client). I bisected the error to
> commit 05ee2d85cd4ace5cd37dc24132e3fd7f5142ebef. Reverting this commit
> in linux-next-20231204 made the game start again and after inserting
> printks into vfs_copy_file_range() I found that steam (via python3)
> calls this function with (flags & COPY_FILE_SPLICE == 0),
> file_out->f_op->copy_file_range == NULL and
> file_in->f_op->remap_file_range == NULL so the default is never reached.
> This patch adds a catch all else clause so the default is reached in
> all cases. This patch fixes the describe issue with steam and Path of
> Exile.
>
> Bert Karwatzki

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

* Re: [PATCH] fs: read_write: make default in vfs_copy_file_range() reachable
  2023-12-05  3:45   ` Amir Goldstein
@ 2023-12-05  5:01     ` Amir Goldstein
  2023-12-05  9:50       ` Bert Karwatzki
  0 siblings, 1 reply; 4+ messages in thread
From: Amir Goldstein @ 2023-12-05  5:01 UTC (permalink / raw)
  To: Bert Karwatzki, Christian Brauner
  Cc: Jan Kara, axboe, dhowells, hch, jlayton, josef, linux-fsdevel,
	miklos, viro, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 3163 bytes --]

On Tue, Dec 5, 2023 at 5:45 AM Amir Goldstein <amir73il@gmail.com> wrote:
>
> On Tue, Dec 5, 2023 at 2:16 AM Bert Karwatzki <spasswolf@web.de> wrote:
> >
> > If vfs_copy_file_range() is called with (flags & COPY_FILE_SPLICE == 0)
> > and both file_out->f_op->copy_file_range and file_in->f_op->remap_file_range
> > are NULL, too, the default call to do_splice_direct() cannot be reached.
> > This patch adds an else clause to make the default reachable in all
> > cases.
> >
> > Signed-off-by: Bert Karwatzki <spasswolf@web.de>
>
> Hi Bert,
>
> Thank you for testing and reporting this so early!!
>
> I would edit the commit message differently, but anyway, I think that
> the fix should be folded into commit 05ee2d85cd4a ("fs: use
> do_splice_direct() for nfsd/ksmbd server-side-copy").
>
> Since I end up making a mistake every time I touch this code,
> I also added a small edit to your patch below, that should make the logic
> more clear to readers. Hopefully, that will help me avoid making a mistake
> the next time I touch this code...
>
> Would you mind testing my revised fix, so we can add:
>   Tested-by: Bert Karwatzki <spasswolf@web.de>
> when folding it into the original patch?
>

Attached an even cleaner version of the fix patch for you to test.
I tested fstests check -g copy_range on ext4.
My fault was that I had tested earlier only on xfs and overlayfs
(the two other cases in the if/else if statement).

Thanks,
Amir.

> > ---
> >  fs/read_write.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/fs/read_write.c b/fs/read_write.c
> > index e0c2c1b5962b..3599c54bd26d 100644
> > --- a/fs/read_write.c
> > +++ b/fs/read_write.c
> > @@ -1554,6 +1554,8 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
> >                 /* fallback to splice */
> >                 if (ret <= 0)
> >                         splice = true;
> > +       } else {
>
> This is logically correct because of the earlier "same sb" check in
> generic_copy_file_checks(), but we better spell out the logic here as well:
>
> +            } else if (file_inode(file_in)->i_sb ==
> file_inode(file_out)->i_sb) {
> +                    /* Fallback to splice for same sb copy for
> backward compat */
>
> > +               splice = true;
> >         }
> >
> >         file_end_write(file_out);
> > --
> > 2.39.2
> >
> > Since linux-next-20231204 I noticed that it was impossible to start the
> > game Path of Exile (using the steam client). I bisected the error to
> > commit 05ee2d85cd4ace5cd37dc24132e3fd7f5142ebef. Reverting this commit
> > in linux-next-20231204 made the game start again and after inserting
> > printks into vfs_copy_file_range() I found that steam (via python3)
> > calls this function with (flags & COPY_FILE_SPLICE == 0),
> > file_out->f_op->copy_file_range == NULL and
> > file_in->f_op->remap_file_range == NULL so the default is never reached.
> > This patch adds a catch all else clause so the default is reached in
> > all cases. This patch fixes the describe issue with steam and Path of
> > Exile.
> >
> > Bert Karwatzki

[-- Attachment #2: 0001-fs-fix-vfs_copy_file_range-for-files-on-same-sb.patch --]
[-- Type: text/x-patch, Size: 1837 bytes --]

From 33eb3caeacb52a46f808984969c808528d10ee01 Mon Sep 17 00:00:00 2001
From: Amir Goldstein <amir73il@gmail.com>
Date: Tue, 5 Dec 2023 06:26:57 +0200
Subject: [PATCH] fs: fix vfs_copy_file_range() for files on same sb

copy_file-range() should fallback to splice with two files on same sb
that does not implement ->copy_file_range() nor ->remap_file_range().

Fixes: 042e4d9d17ae ("fs: use splice_copy_file_range() inline helper")
Reported-by: Bert Karwatzki <spasswolf@web.de>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 fs/read_write.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index e0c2c1b5962b..01a14570015b 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -1514,6 +1514,7 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
 {
 	ssize_t ret;
 	bool splice = flags & COPY_FILE_SPLICE;
+	bool samesb = file_inode(file_in)->i_sb == file_inode(file_out)->i_sb;
 
 	if (flags & ~COPY_FILE_SPLICE)
 		return -EINVAL;
@@ -1545,8 +1546,7 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
 		ret = file_out->f_op->copy_file_range(file_in, pos_in,
 						      file_out, pos_out,
 						      len, flags);
-	} else if (!splice && file_in->f_op->remap_file_range &&
-		   file_inode(file_in)->i_sb == file_inode(file_out)->i_sb) {
+	} else if (!splice && file_in->f_op->remap_file_range && samesb) {
 		ret = file_in->f_op->remap_file_range(file_in, pos_in,
 				file_out, pos_out,
 				min_t(loff_t, MAX_RW_COUNT, len),
@@ -1554,6 +1554,9 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
 		/* fallback to splice */
 		if (ret <= 0)
 			splice = true;
+	} else if (samesb) {
+		/* Fallback to splice for same sb copy for backward compat */
+		splice = true;
 	}
 
 	file_end_write(file_out);
-- 
2.34.1


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

* Re: [PATCH] fs: read_write: make default in vfs_copy_file_range() reachable
  2023-12-05  5:01     ` Amir Goldstein
@ 2023-12-05  9:50       ` Bert Karwatzki
  0 siblings, 0 replies; 4+ messages in thread
From: Bert Karwatzki @ 2023-12-05  9:50 UTC (permalink / raw)
  To: Amir Goldstein, Christian Brauner
  Cc: Jan Kara, axboe, dhowells, hch, jlayton, josef, linux-fsdevel,
	miklos, viro, linux-kernel

Am Dienstag, dem 05.12.2023 um 07:01 +0200 schrieb Amir Goldstein:
> On Tue, Dec 5, 2023 at 5:45 AM Amir Goldstein <amir73il@gmail.com> wrote:
> >
> > On Tue, Dec 5, 2023 at 2:16 AM Bert Karwatzki <spasswolf@web.de> wrote:
> > >
> > > If vfs_copy_file_range() is called with (flags & COPY_FILE_SPLICE == 0)
> > > and both file_out->f_op->copy_file_range and file_in->f_op-
> > > >remap_file_range
> > > are NULL, too, the default call to do_splice_direct() cannot be reached.
> > > This patch adds an else clause to make the default reachable in all
> > > cases.
> > >
> > > Signed-off-by: Bert Karwatzki <spasswolf@web.de>
> >
> > Hi Bert,
> >
> > Thank you for testing and reporting this so early!!
> >
> > I would edit the commit message differently, but anyway, I think that
> > the fix should be folded into commit 05ee2d85cd4a ("fs: use
> > do_splice_direct() for nfsd/ksmbd server-side-copy").
> >
> > Since I end up making a mistake every time I touch this code,
> > I also added a small edit to your patch below, that should make the logic
> > more clear to readers. Hopefully, that will help me avoid making a mistake
> > the next time I touch this code...
> >
> > Would you mind testing my revised fix, so we can add:
> >   Tested-by: Bert Karwatzki <spasswolf@web.de>
> > when folding it into the original patch?
> >
>
> Attached an even cleaner version of the fix patch for you to test.
> I tested fstests check -g copy_range on ext4.
> My fault was that I had tested earlier only on xfs and overlayfs
> (the two other cases in the if/else if statement).
>
> Thanks,
> Amir.
>
> > > ---
> > >  fs/read_write.c | 2 ++
> > >  1 file changed, 2 insertions(+)
> > >
> > > diff --git a/fs/read_write.c b/fs/read_write.c
> > > index e0c2c1b5962b..3599c54bd26d 100644
> > > --- a/fs/read_write.c
> > > +++ b/fs/read_write.c
> > > @@ -1554,6 +1554,8 @@ ssize_t vfs_copy_file_range(struct file *file_in,
> > > loff_t pos_in,
> > >                 /* fallback to splice */
> > >                 if (ret <= 0)
> > >                         splice = true;
> > > +       } else {
> >
> > This is logically correct because of the earlier "same sb" check in
> > generic_copy_file_checks(), but we better spell out the logic here as well:
> >
> > +            } else if (file_inode(file_in)->i_sb ==
> > file_inode(file_out)->i_sb) {
> > +                    /* Fallback to splice for same sb copy for
> > backward compat */
> >
> > > +               splice = true;
> > >         }
> > >
> > >         file_end_write(file_out);
> > > --
> > > 2.39.2
> > >
> > > Since linux-next-20231204 I noticed that it was impossible to start the
> > > game Path of Exile (using the steam client). I bisected the error to
> > > commit 05ee2d85cd4ace5cd37dc24132e3fd7f5142ebef. Reverting this commit
> > > in linux-next-20231204 made the game start again and after inserting
> > > printks into vfs_copy_file_range() I found that steam (via python3)
> > > calls this function with (flags & COPY_FILE_SPLICE == 0),
> > > file_out->f_op->copy_file_range == NULL and
> > > file_in->f_op->remap_file_range == NULL so the default is never reached.
> > > This patch adds a catch all else clause so the default is reached in
> > > all cases. This patch fixes the describe issue with steam and Path of
> > > Exile.
> > >
> > > Bert Karwatzki

Your new patch works fine (I applied it to linux-next-20231204), again tested by
starting Path of Exile via steam from an ext4 filesystem.

Bert Karwatzki

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

end of thread, other threads:[~2023-12-05  9:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20231130141624.3338942-4-amir73il@gmail.com>
2023-12-05  0:16 ` [PATCH] fs: read_write: make default in vfs_copy_file_range() reachable Bert Karwatzki
2023-12-05  3:45   ` Amir Goldstein
2023-12-05  5:01     ` Amir Goldstein
2023-12-05  9:50       ` Bert Karwatzki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox