* [PATCH] splice, net: Fix splice_to_socket() for O_NONBLOCK socket
@ 2023-07-19 9:07 Jan Stancek
2023-07-24 10:12 ` David Howells
0 siblings, 1 reply; 6+ messages in thread
From: Jan Stancek @ 2023-07-19 9:07 UTC (permalink / raw)
To: dhowells, kuba, linux-fsdevel; +Cc: linux-kernel, brauner, viro, jstancek
LTP sendfile07 [1], which expects sendfile() to return EAGAIN when
transferring data from regular file to a "full" O_NONBLOCK socket,
started failing after commit 2dc334f1a63a ("splice, net: Use
sendmsg(MSG_SPLICE_PAGES) rather than ->sendpage()").
sendfile() no longer immediately returns, but now blocks.
Removed sock_sendpage() handled this case by setting a MSG_DONTWAIT
flag, fix new splice_to_socket() to do the same for O_NONBLOCK sockets.
[1] https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/syscalls/sendfile/sendfile07.c
Fixes: 2dc334f1a63a ("splice, net: Use sendmsg(MSG_SPLICE_PAGES) rather than ->sendpage()")
Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
fs/splice.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/splice.c b/fs/splice.c
index 004eb1c4ce31..3e2a31e1ce6a 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -876,6 +876,8 @@ ssize_t splice_to_socket(struct pipe_inode_info *pipe, struct file *out,
msg.msg_flags |= MSG_MORE;
if (remain && pipe_occupancy(pipe->head, tail) > 0)
msg.msg_flags |= MSG_MORE;
+ if (out->f_flags & O_NONBLOCK)
+ msg.msg_flags |= MSG_DONTWAIT;
iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, bvec, bc,
len - remain);
--
2.31.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] splice, net: Fix splice_to_socket() for O_NONBLOCK socket
2023-07-19 9:07 [PATCH] splice, net: Fix splice_to_socket() for O_NONBLOCK socket Jan Stancek
@ 2023-07-24 10:12 ` David Howells
2023-07-24 14:51 ` Jan Stancek
2023-07-24 15:44 ` David Howells
0 siblings, 2 replies; 6+ messages in thread
From: David Howells @ 2023-07-24 10:12 UTC (permalink / raw)
To: Jan Stancek; +Cc: dhowells, kuba, linux-fsdevel, linux-kernel, brauner, viro
Jan Stancek <jstancek@redhat.com> wrote:
> LTP sendfile07 [1], which expects sendfile() to return EAGAIN when
> transferring data from regular file to a "full" O_NONBLOCK socket,
> started failing after commit 2dc334f1a63a ("splice, net: Use
> sendmsg(MSG_SPLICE_PAGES) rather than ->sendpage()").
> sendfile() no longer immediately returns, but now blocks.
>
> Removed sock_sendpage() handled this case by setting a MSG_DONTWAIT
> flag, fix new splice_to_socket() to do the same for O_NONBLOCK sockets.
Does this actually work correctly in all circumstances?
The problem might come if you have a splice from a non-rewindable source
through a temporary pipe (eg. sendfile() using splice_direct_to_actor()).
David
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] splice, net: Fix splice_to_socket() for O_NONBLOCK socket
2023-07-24 10:12 ` David Howells
@ 2023-07-24 14:51 ` Jan Stancek
2023-07-24 15:44 ` David Howells
1 sibling, 0 replies; 6+ messages in thread
From: Jan Stancek @ 2023-07-24 14:51 UTC (permalink / raw)
To: David Howells; +Cc: kuba, linux-fsdevel, linux-kernel, brauner, viro
On Mon, Jul 24, 2023 at 12:12 PM David Howells <dhowells@redhat.com> wrote:
>
> Jan Stancek <jstancek@redhat.com> wrote:
>
> > LTP sendfile07 [1], which expects sendfile() to return EAGAIN when
> > transferring data from regular file to a "full" O_NONBLOCK socket,
> > started failing after commit 2dc334f1a63a ("splice, net: Use
> > sendmsg(MSG_SPLICE_PAGES) rather than ->sendpage()").
> > sendfile() no longer immediately returns, but now blocks.
> >
> > Removed sock_sendpage() handled this case by setting a MSG_DONTWAIT
> > flag, fix new splice_to_socket() to do the same for O_NONBLOCK sockets.
>
> Does this actually work correctly in all circumstances?
>
> The problem might come if you have a splice from a non-rewindable source
> through a temporary pipe (eg. sendfile() using splice_direct_to_actor()).
I assumed this was safe, since sendfile / splice_direct_to_actor()
requires input to be seekable.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] splice, net: Fix splice_to_socket() for O_NONBLOCK socket
2023-07-24 10:12 ` David Howells
2023-07-24 14:51 ` Jan Stancek
@ 2023-07-24 15:44 ` David Howells
2023-07-24 17:09 ` Jakub Kicinski
1 sibling, 1 reply; 6+ messages in thread
From: David Howells @ 2023-07-24 15:44 UTC (permalink / raw)
To: Jan Stancek; +Cc: dhowells, kuba, linux-fsdevel, linux-kernel, brauner, viro
Jan Stancek <jstancek@redhat.com> wrote:
> On Mon, Jul 24, 2023 at 12:12 PM David Howells <dhowells@redhat.com> wrote:
> >
> > Jan Stancek <jstancek@redhat.com> wrote:
> >
> > > LTP sendfile07 [1], which expects sendfile() to return EAGAIN when
> > > transferring data from regular file to a "full" O_NONBLOCK socket,
> > > started failing after commit 2dc334f1a63a ("splice, net: Use
> > > sendmsg(MSG_SPLICE_PAGES) rather than ->sendpage()").
> > > sendfile() no longer immediately returns, but now blocks.
> > >
> > > Removed sock_sendpage() handled this case by setting a MSG_DONTWAIT
> > > flag, fix new splice_to_socket() to do the same for O_NONBLOCK sockets.
> >
> > Does this actually work correctly in all circumstances?
> >
> > The problem might come if you have a splice from a non-rewindable source
> > through a temporary pipe (eg. sendfile() using splice_direct_to_actor()).
>
> I assumed this was safe, since sendfile / splice_direct_to_actor()
> requires input to be seekable.
Ah! The test isn't where I was looking for it (in sendfile()) - it's in
splice_direct_to_actor().
I wonder if it's worth making that explicit in do_sendfile() as the
requirement doesn't hold if the output is a pipe (though in such a case,
there's an explicit buffer, so it's not actually a problem).
Anyway, did you want to post this to netdev too so that the networking tree
picks it up? Feel free to add:
Acked-by: David Howells <dhowells@redhat.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] splice, net: Fix splice_to_socket() for O_NONBLOCK socket
2023-07-24 15:44 ` David Howells
@ 2023-07-24 17:09 ` Jakub Kicinski
2023-07-24 17:37 ` Jan Stancek
0 siblings, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2023-07-24 17:09 UTC (permalink / raw)
To: David Howells; +Cc: Jan Stancek, linux-fsdevel, linux-kernel, brauner, viro
On Mon, 24 Jul 2023 16:44:07 +0100 David Howells wrote:
> Anyway, did you want to post this to netdev too so that the networking tree
> picks it up? Feel free to add:
+1, no preference which tree this goes thru, but if no one else claims
it please repost CCing netdev@vger.kernel.org
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] splice, net: Fix splice_to_socket() for O_NONBLOCK socket
2023-07-24 17:09 ` Jakub Kicinski
@ 2023-07-24 17:37 ` Jan Stancek
0 siblings, 0 replies; 6+ messages in thread
From: Jan Stancek @ 2023-07-24 17:37 UTC (permalink / raw)
To: Jakub Kicinski; +Cc: David Howells, linux-fsdevel, linux-kernel, brauner, viro
On Mon, Jul 24, 2023 at 7:09 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Mon, 24 Jul 2023 16:44:07 +0100 David Howells wrote:
> > Anyway, did you want to post this to netdev too so that the networking tree
> > picks it up? Feel free to add:
>
> +1, no preference which tree this goes thru, but if no one else claims
> it please repost CCing netdev@vger.kernel.org
I'll repost, thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-07-24 17:37 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-19 9:07 [PATCH] splice, net: Fix splice_to_socket() for O_NONBLOCK socket Jan Stancek
2023-07-24 10:12 ` David Howells
2023-07-24 14:51 ` Jan Stancek
2023-07-24 15:44 ` David Howells
2023-07-24 17:09 ` Jakub Kicinski
2023-07-24 17:37 ` Jan Stancek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).