Skip to contentSkip to conversation

splice: fix updating sd->pos wrongly

PATCH In review Changli Gao 3 participants 10 messages May 26, 2010 – May 29, 2010 VFS

lore
Share & tools
lore
#0 lore raw

PATCH v2 4/4 splice: fix updating sd->pos wrongly

fix updating sd->pos wrongly.

In error path, we don't need to updating sd->pos, if the file isn't seekable.

----

 fs/splice.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/splice.c +2 -1
index 57172ca..c69b241 100644
@@ -1185,7 +1185,8 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
 		sd->pos = pos;
 
 		if (ret < read_len) {
-			sd->pos = prev_pos + ret;
+			if (sd->pos)
+				sd->pos = prev_pos + ret;
 			goto out_release;
 		}
 	}
#1 lore raw
Quoted 3 lines · Changli Gao

fix updating sd->pos wrongly.

In error path, we don't need to updating sd->pos, if the file isn't seekable.

This patch is nonsense. Why should we handle sd->pos != 0 case differently?

Quoted 24 lines

----

 fs/splice.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/splice.c +2 -2
index 57172ca..c69b241 100644
@@ -1185,7 +1185,8 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
 		sd->pos = pos;
 
 		if (ret < read_len) {
-			sd->pos = prev_pos + ret;
+			if (sd->pos)
+				sd->pos = prev_pos + ret;
 			goto out_release;
 		}
 	}
--

To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 8 lines · Miklos Szeredi
Quoted 3 lines · Changli Gao

fix updating sd->pos wrongly.

In error path, we don't need to updating sd->pos, if the file isn't seekable.

This patch is nonsense.  Why should we handle sd->pos != 0 case differently?

If the in file isn't seekable, its splice_read won't update *ppos, so in the error path, we'd better not change it too. Otherwise, some assumption will go wrong.

ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos,
struct pipe_inode_info *pipe, size_t len, unsigned int flags)

{
        struct sock *sk = sock->sk;
        struct tcp_splice_state tss = {
                .pipe = pipe,
                .len = len,
                .flags = flags,
        };
        long timeo;
        ssize_t spliced;
        int ret;

        /*
         * We can't seek on a socket input
         */
        if (unlikely(*ppos))
                return -ESPIPE;
Signature · 2 lines
Regards,
Changli Gao([email protected])
#3 lore raw
Quoted 6 lines · Changli Gao
Quoted 5 lines · Miklos Szeredi
Quoted 3 lines · Changli Gao

fix updating sd->pos wrongly.

In error path, we don't need to updating sd->pos, if the file isn't seekable.

Quoted 7 lines
Quoted 3 lines

This patch is nonsense.  Why should we handle sd->pos != 0 case differently?

If the in file isn't seekable, its splice_read won't update *ppos, so in the error path, we'd better not change it too. Otherwise, some assumption will go wrong.

That may be true, but the patch is still nonsense.

Look, your patch is updating/not updating sd->pos based on whether it is zero or not. It will prevent updating the position for sockets, but it will also prevent updating the position for regular files if the position is zero, which is really not what we want.

Since these patches modify the behavior of splice in subtle ways, it would be good if you had some test program to verify that you aren't breaking something.

Thanks,
Miklos
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 15 lines · Miklos Szeredi
Quoted 6 lines · Changli Gao
Quoted 5 lines · Miklos Szeredi
Quoted 3 lines · Changli Gao

fix updating sd->pos wrongly.

In error path, we don't need to updating sd->pos, if the file isn't seekable.

Quoted 7 lines
Quoted 3 lines

This patch is nonsense.  Why should we handle sd->pos != 0 case differently?

If the in file isn't seekable, its splice_read won't update *ppos, so in the error path, we'd better not change it too. Otherwise, some assumption will go wrong.

Quoted 6 lines

That may be true, but the patch is still nonsense.

Look, your patch is updating/not updating sd->pos based on whether it is zero or not.  It will prevent updating the position for sockets, but it will also prevent updating the position for regular files if the position is zero, which is really not what we want.

I think you misread my patch. Before checking the sd->pos, sd->pos already is updated with the value returned by splice_read(), so if in file is seekabble, sd->pos is non-zero when I checking it.

Signature · 6 lines
Regards,
Changli Gao([email protected])
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#5 lore raw
Quoted 16 lines · Changli Gao
Quoted 15 lines · Miklos Szeredi
Quoted 13 lines · Changli Gao
Quoted 8 lines · Miklos Szeredi
Quoted 3 lines · Changli Gao

fix updating sd->pos wrongly.

In error path, we don't need to updating sd->pos, if the file isn't seekable.

This patch is nonsense.  Why should we handle sd->pos != 0 case differently?

If the in file isn't seekable, its splice_read won't update *ppos, so in the error path, we'd better not change it too. Otherwise, some assumption will go wrong.

Quoted 8 lines
Quoted 6 lines

That may be true, but the patch is still nonsense.

Look, your patch is updating/not updating sd->pos based on whether it is zero or not.  It will prevent updating the position for sockets, but it will also prevent updating the position for regular files if the position is zero, which is really not what we want.

I think you misread my patch.

Right :)

Quoted 3 lines

Before checking the sd->pos, sd->pos
already is updated with the value returned by splice_read(), so if in file is seekabble, sd->pos is non-zero when I checking it.

I see the logic now. But it's really confusing, at least some comments would be needed.

But I think it would be better not to try reusing sd->pos for reading, but supplying an "loff_t *read_ppos" to splice_direct_to_actor and leaving sd->pos alone (for the write side to use and update as necessary).

Thanks,
Miklos

#6 lore raw
Quoted 5 lines · Miklos Szeredi
Quoted 3 lines · Changli Gao

 Before checking the sd->pos, sd->pos
already is updated with the value returned by splice_read(), so if in file is seekabble, sd->pos is non-zero when I checking it.

Quoted 8 lines

I see the logic now.  But it's really confusing, at least some comments would be needed.

But I think it would be better not to try reusing sd->pos for reading, but supplying an "loff_t *read_ppos" to splice_direct_to_actor and leaving sd->pos alone (for the write side to use and update as necessary).

               if (ret < read_len) {

I think is much like a hack too. :)

- sd->pos = prev_pos + ret;
+ if (sd->pos)

+                               sd->pos = prev_pos + ret;
                       goto out_release;
               }

Anyway, it can fix the issue I mentioned above. Any future cleanup should not be mixed in, IMO.

Signature · 2 lines
Regards,
Changli Gao([email protected])
#7 lore raw
Quoted 25 lines · Changli Gao
Quoted 5 lines · Miklos Szeredi
Quoted 3 lines · Changli Gao

 Before checking the sd->pos, sd->pos
already is updated with the value returned by splice_read(), so if in file is seekabble, sd->pos is non-zero when I checking it.

Quoted 8 lines

I see the logic now.  But it's really confusing, at least some comments would be needed.

But I think it would be better not to try reusing sd->pos for reading, but supplying an "loff_t *read_ppos" to splice_direct_to_actor and leaving sd->pos alone (for the write side to use and update as necessary).

               if (ret < read_len) {

I think is much like a hack too. :)

(quoted diff) +2 -1
-                       sd->pos = prev_pos + ret;
+                       if (sd->pos)
+                               sd->pos = prev_pos + ret;
                       goto out_release;
               }
Quoted 2 lines

Anyway, it can fix the issue I mentioned above. Any future cleanup should not be mixed in, IMO.

Okay, but please add a comment and explaing in the patch header, because others are going to look a that code and go "WTF???"

Thanks,
Miklos

#8 lore raw
In reply to Changli Gao
Quoted 18 lines · Changli Gao
Quoted 17 lines · Miklos Szeredi
Quoted 6 lines · Changli Gao
Quoted 5 lines · Miklos Szeredi
Quoted 3 lines · Changli Gao

fix updating sd->pos wrongly.

In error path, we don't need to updating sd->pos, if the file isn't seekable.

Quoted 7 lines
Quoted 3 lines

This patch is nonsense.  Why should we handle sd->pos != 0 case differently?

If the in file isn't seekable, its splice_read won't update *ppos, so in the error path, we'd better not change it too. Otherwise, some assumption will go wrong.

That may be true, but the patch is still nonsense.

Quoted 8 lines
Quoted 4 lines

Look, your patch is updating/not updating sd->pos based on whether it is zero or not.  It will prevent updating the position for sockets, but it will also prevent updating the position for regular files if the position is zero, which is really not what we want.

I think you misread my patch. Before checking the sd->pos, sd->pos already is updated with the value returned by splice_read(), so if in file is seekabble, sd->pos is non-zero when I checking it.

Not true if the "file" is /dev/mem or /dev/kmem. The starting offset can be negative, so can end at zero.

It's an obscure case and I don't know if you can sendfile from /dev/{,k}mem anyway :-) but illustrates why sd->pos != 0 is dubious.

-- Jamie
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#9 lore raw
Quoted 7 lines · Jamie Lokier

Not true if the "file" is /dev/mem or /dev/kmem.  The starting offset can be negative, so can end at zero.

It's an obscure case and I don't know if you can sendfile from /dev/{,k}mem anyway :-) but illustrates why sd->pos != 0 is dubious.

So the safe way is checking if splice_read() updates pos or not, isn't it?

if (sd->pos != prev_pos)

    sd->pos = prev_pos + ret;
Signature · 2 lines
Regards,
Changli Gao([email protected])