Skip to contentSkip to conversation

splice: fix wrong __splice_from_pipe() usage

PATCH In review OGAWA Hirofumi 2 participants 6 messages Jul 16, 2007 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 splice: fix wrong __splice_from_pipe() usage

Hi,

I've noticed the nfsd read corruption by recent change. And this patch fixes the problem for me, is this right fix?

Signature · 49 lines
OGAWA Hirofumi <[email protected]>


__splice_from_pipe() is updating the sd->pos for the actor, but those
functions are passing the sd of reader side directory. So, splice
updates sd->pos twice.

This fixes usage of __splice_from_pipe().

Signed-off-by: OGAWA Hirofumi <[email protected]>
---

 drivers/block/loop.c |    5 +++--
 fs/nfsd/vfs.c        |    5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff -puN fs/nfsd/vfs.c~splice-fix-__splice_from_pipe-usage fs/nfsd/vfs.c
--- linux-2.6/fs/nfsd/vfs.c~splice-fix-__splice_from_pipe-usage	2007-07-16 09:30:10.000000000 +0900
+++ linux-2.6-hirofumi/fs/nfsd/vfs.c	2007-07-16 09:30:10.000000000 +0900
@@ -842,9 +842,10 @@ nfsd_splice_actor(struct pipe_inode_info
 }
 
 static int nfsd_direct_splice_actor(struct pipe_inode_info *pipe,
-				    struct splice_desc *sd)
+				    struct splice_desc *__sd)
 {
-	return __splice_from_pipe(pipe, sd, nfsd_splice_actor);
+	struct splice_desc sd = *__sd;
+	return __splice_from_pipe(pipe, &sd, nfsd_splice_actor);
 }
 
 static __be32
diff -puN drivers/block/loop.c~splice-fix-__splice_from_pipe-usage drivers/block/loop.c
--- linux-2.6/drivers/block/loop.c~splice-fix-__splice_from_pipe-usage	2007-07-16 09:30:10.000000000 +0900
+++ linux-2.6-hirofumi/drivers/block/loop.c	2007-07-16 09:30:10.000000000 +0900
@@ -437,9 +437,10 @@ lo_splice_actor(struct pipe_inode_info *
 }
 
 static int
-lo_direct_splice_actor(struct pipe_inode_info *pipe, struct splice_desc *sd)
+lo_direct_splice_actor(struct pipe_inode_info *pipe, struct splice_desc *__sd)
 {
-	return __splice_from_pipe(pipe, sd, lo_splice_actor);
+	struct splice_desc sd = *__sd;
+	return __splice_from_pipe(pipe, &sd, lo_splice_actor);
 }
 
 static int
_
#1 lore raw
Quoted 13 lines · OGAWA Hirofumi

Hi,

I've noticed the nfsd read corruption by recent change. And this patch fixes the problem for me, is this right fix?

Signature · 8 lines
OGAWA Hirofumi <[email protected]>


__splice_from_pipe() is updating the sd->pos for the actor, but those
functions are passing the sd of reader side directory. So, splice
updates sd->pos twice.

This fixes usage of __splice_from_pipe().

For sendfile() usage, or the nfsd path that uses splice to send?

Signature · 1 line
Jens Axboe
#2 lore raw
Quoted 9 lines · Jens Axboe
Quoted 8 lines · OGAWA Hirofumi

Hi,

I've noticed the nfsd read corruption by recent change. And this patch fixes the problem for me, is this right fix?

Signature · 1 line
OGAWA Hirofumi <[email protected]>
Quoted 7 lines
Quoted 5 lines

__splice_from_pipe() is updating the sd->pos for the actor, but those functions are passing the sd of reader side directory. So, splice updates sd->pos twice.

This fixes usage of __splice_from_pipe().

For sendfile() usage, or the nfsd path that uses splice to send?

nfsd_vfs_read() path.

nfsd_vfs_read()

    splice_direct_to_actor()
        while(len) {
            do_splice_to()                     [update sd->pos]
                -> generic_file_splice_read()  [read from sd->pos]
            nfsd_direct_splice_actor()
                -> __splice_from_pipe()        [update sd->pos]
        }

do_splice_to() updates sd->pos for read, and pass updated sd to __splice_from_pipe(), and __splice_from_pipe() updates sd->pos for write. So, next do_splice_to() read from wrong position.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#3 lore raw
Quoted 30 lines · OGAWA Hirofumi
Quoted 9 lines · Jens Axboe
Quoted 8 lines · OGAWA Hirofumi

Hi,

I've noticed the nfsd read corruption by recent change. And this patch fixes the problem for me, is this right fix?

Signature · 1 line
OGAWA Hirofumi <[email protected]>
Quoted 7 lines
Quoted 5 lines

__splice_from_pipe() is updating the sd->pos for the actor, but those functions are passing the sd of reader side directory. So, splice updates sd->pos twice.

This fixes usage of __splice_from_pipe().

For sendfile() usage, or the nfsd path that uses splice to send?

nfsd_vfs_read() path.

nfsd_vfs_read()

    splice_direct_to_actor()
        while(len) {
            do_splice_to()                     [update sd->pos]
                -> generic_file_splice_read()  [read from sd->pos]
            nfsd_direct_splice_actor()
                -> __splice_from_pipe()        [update sd->pos]
        }
Quoted 3 lines

do_splice_to() updates sd->pos for read, and pass updated sd to __splice_from_pipe(), and __splice_from_pipe() updates sd->pos for write. So, next do_splice_to() read from wrong position.

Ah, I see. Copying the structure over would work, but it seems like a big work-around for something that is essentially bad behaviour in the splice core for direct splicing.

Can you check if this works for you?

fs/splice.c +3 -1
index 6c98286..5e5071a 100644
@@ -1061,8 +1061,9 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
 
 	while (len) {
 		size_t read_len;
+		loff_t pos = sd->pos;
 
-		ret = do_splice_to(in, &sd->pos, pipe, len, flags);
+		ret = do_splice_to(in, &pos, pipe, len, flags);
 		if (unlikely(ret <= 0))
 			goto out_release;
 
@@ -1080,6 +1081,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
 
 		bytes += ret;
 		len -= ret;
+		sd->pos = pos;
 
 		if (ret < read_len)
 			goto out_release;
Signature · 1 line
Jens Axboe
#4 lore raw
Quoted 15 lines · Jens Axboe
Quoted 11 lines

nfsd_vfs_read() path.

nfsd_vfs_read()

    splice_direct_to_actor()
        while(len) {
            do_splice_to()                     [update sd->pos]
                -> generic_file_splice_read()  [read from sd->pos]
            nfsd_direct_splice_actor()
                -> __splice_from_pipe()        [update sd->pos]
        }
Quoted 3 lines

do_splice_to() updates sd->pos for read, and pass updated sd to __splice_from_pipe(), and __splice_from_pipe() updates sd->pos for write. So, next do_splice_to() read from wrong position.

Quoted 5 lines

Ah, I see. Copying the structure over would work, but it seems like a big work-around for something that is essentially bad behaviour in the splice core for direct splicing.

Can you check if this works for you?

Simple test was done. The patch works for me.

Thanks.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#5 lore raw
Quoted 17 lines · OGAWA Hirofumi
Quoted 15 lines · Jens Axboe
Quoted 14 lines

nfsd_vfs_read() path.

nfsd_vfs_read()

    splice_direct_to_actor()
        while(len) {
            do_splice_to()                     [update sd->pos]
                -> generic_file_splice_read()  [read from sd->pos]
            nfsd_direct_splice_actor()
                -> __splice_from_pipe()        [update sd->pos]
        }

do_splice_to() updates sd->pos for read, and pass updated sd to __splice_from_pipe(), and __splice_from_pipe() updates sd->pos for write. So, next do_splice_to() read from wrong position.

Quoted 7 lines
Quoted 5 lines

Ah, I see. Copying the structure over would work, but it seems like a big work-around for something that is essentially bad behaviour in the splice core for direct splicing.

Can you check if this works for you?

Simple test was done. The patch works for me.

Great, thanks a lot for retesting. I'll get the patch upstream asap.

Signature · 1 line
Jens Axboe