* [PATCH net] kcm: Fix splice support
@ 2025-07-25 10:33 Michal Luczaj
2025-07-31 1:02 ` Jakub Kicinski
2025-07-31 1:10 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 6+ messages in thread
From: Michal Luczaj @ 2025-07-25 10:33 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Cong Wang, Tom Herbert
Cc: netdev, linux-kernel, Michal Luczaj
Flags passed in for splice() syscall should not end up in
skb_recv_datagram(). As SPLICE_F_NONBLOCK == MSG_PEEK, kernel gets
confused: skb isn't unlinked from a receive queue, while strp_msg::offset
and strp_msg::full_len are updated.
Unbreak the logic a bit more by mapping both O_NONBLOCK and
SPLICE_F_NONBLOCK to MSG_DONTWAIT. This way we align with man splice(2) in
regard to errno EAGAIN:
SPLICE_F_NONBLOCK was specified in flags or one of the file descriptors
had been marked as nonblocking (O_NONBLOCK), and the operation would
block.
Fixes: 5121197ecc5d ("kcm: close race conditions on sk_receive_queue")
Fixes: 91687355b927 ("kcm: Splice support")
Signed-off-by: Michal Luczaj <mhal@rbox.co>
---
net/kcm/kcmsock.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/net/kcm/kcmsock.c b/net/kcm/kcmsock.c
index 24aec295a51cf737912f1aefe81556bd9f23331e..c05047dad62d7e201c950ab98af6dc7f0d48276c 100644
--- a/net/kcm/kcmsock.c
+++ b/net/kcm/kcmsock.c
@@ -19,6 +19,7 @@
#include <linux/rculist.h>
#include <linux/skbuff.h>
#include <linux/socket.h>
+#include <linux/splice.h>
#include <linux/uaccess.h>
#include <linux/workqueue.h>
#include <linux/syscalls.h>
@@ -1030,6 +1031,11 @@ static ssize_t kcm_splice_read(struct socket *sock, loff_t *ppos,
ssize_t copied;
struct sk_buff *skb;
+ if (sock->file->f_flags & O_NONBLOCK || flags & SPLICE_F_NONBLOCK)
+ flags = MSG_DONTWAIT;
+ else
+ flags = 0;
+
/* Only support splice for SOCKSEQPACKET */
skb = skb_recv_datagram(sk, flags, &err);
---
base-commit: c8f13134349b4385ae739f1efe403d5d3949ef92
change-id: 20250619-kcm-splice-01cb39a5997b
Best regards,
--
Michal Luczaj <mhal@rbox.co>
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net] kcm: Fix splice support
2025-07-25 10:33 [PATCH net] kcm: Fix splice support Michal Luczaj
@ 2025-07-31 1:02 ` Jakub Kicinski
2025-08-03 10:00 ` Michal Luczaj
2025-07-31 1:10 ` patchwork-bot+netdevbpf
1 sibling, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2025-07-31 1:02 UTC (permalink / raw)
To: Michal Luczaj
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Cong Wang, Tom Herbert, netdev, linux-kernel
On Fri, 25 Jul 2025 12:33:04 +0200 Michal Luczaj wrote:
> Flags passed in for splice() syscall should not end up in
> skb_recv_datagram(). As SPLICE_F_NONBLOCK == MSG_PEEK, kernel gets
> confused: skb isn't unlinked from a receive queue, while strp_msg::offset
> and strp_msg::full_len are updated.
>
> Unbreak the logic a bit more by mapping both O_NONBLOCK and
> SPLICE_F_NONBLOCK to MSG_DONTWAIT. This way we align with man splice(2) in
> regard to errno EAGAIN:
>
> SPLICE_F_NONBLOCK was specified in flags or one of the file descriptors
> had been marked as nonblocking (O_NONBLOCK), and the operation would
> block.
Coincidentally looks like we're not honoring
sock->file->f_flags & O_NONBLOCK
in TLS..
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] kcm: Fix splice support
2025-07-25 10:33 [PATCH net] kcm: Fix splice support Michal Luczaj
2025-07-31 1:02 ` Jakub Kicinski
@ 2025-07-31 1:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-07-31 1:10 UTC (permalink / raw)
To: Michal Luczaj
Cc: davem, edumazet, kuba, pabeni, horms, cong.wang, tom, netdev,
linux-kernel
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Fri, 25 Jul 2025 12:33:04 +0200 you wrote:
> Flags passed in for splice() syscall should not end up in
> skb_recv_datagram(). As SPLICE_F_NONBLOCK == MSG_PEEK, kernel gets
> confused: skb isn't unlinked from a receive queue, while strp_msg::offset
> and strp_msg::full_len are updated.
>
> Unbreak the logic a bit more by mapping both O_NONBLOCK and
> SPLICE_F_NONBLOCK to MSG_DONTWAIT. This way we align with man splice(2) in
> regard to errno EAGAIN:
>
> [...]
Here is the summary with links:
- [net] kcm: Fix splice support
https://git.kernel.org/netdev/net/c/9063de636cee
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] kcm: Fix splice support
2025-07-31 1:02 ` Jakub Kicinski
@ 2025-08-03 10:00 ` Michal Luczaj
2025-08-04 23:51 ` Jakub Kicinski
0 siblings, 1 reply; 6+ messages in thread
From: Michal Luczaj @ 2025-08-03 10:00 UTC (permalink / raw)
To: Jakub Kicinski
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Cong Wang, Tom Herbert, netdev, linux-kernel
On 7/31/25 03:02, Jakub Kicinski wrote:
> On Fri, 25 Jul 2025 12:33:04 +0200 Michal Luczaj wrote:
>> Flags passed in for splice() syscall should not end up in
>> skb_recv_datagram(). As SPLICE_F_NONBLOCK == MSG_PEEK, kernel gets
>> confused: skb isn't unlinked from a receive queue, while strp_msg::offset
>> and strp_msg::full_len are updated.
>>
>> Unbreak the logic a bit more by mapping both O_NONBLOCK and
>> SPLICE_F_NONBLOCK to MSG_DONTWAIT. This way we align with man splice(2) in
>> regard to errno EAGAIN:
>>
>> SPLICE_F_NONBLOCK was specified in flags or one of the file descriptors
>> had been marked as nonblocking (O_NONBLOCK), and the operation would
>> block.
>
> Coincidentally looks like we're not honoring
>
> sock->file->f_flags & O_NONBLOCK
>
> in TLS..
I'm a bit confused.
Comparing AF_UNIX and pure (non-TLS) TCP, I see two non-blocking-splice
interpretations. Unix socket doesn't block on `f_flags & O_NONBLOCK ||
flags & SPLICE_F_NONBLOCK` (which this patch follows), while TCP, after
commit 42324c627043 ("net: splice() from tcp to pipe should take into
account O_NONBLOCK"), honours O_NONBLOCK and ignores SPLICE_F_NONBLOCK.
Should KCM (and TLS) follow TCP behaviour instead?
Thanks,
Michal
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] kcm: Fix splice support
2025-08-03 10:00 ` Michal Luczaj
@ 2025-08-04 23:51 ` Jakub Kicinski
2025-08-06 21:15 ` Michal Luczaj
0 siblings, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2025-08-04 23:51 UTC (permalink / raw)
To: Michal Luczaj
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Cong Wang, Tom Herbert, netdev, linux-kernel
On Sun, 3 Aug 2025 12:00:38 +0200 Michal Luczaj wrote:
> On 7/31/25 03:02, Jakub Kicinski wrote:
> > On Fri, 25 Jul 2025 12:33:04 +0200 Michal Luczaj wrote:
> >> Flags passed in for splice() syscall should not end up in
> >> skb_recv_datagram(). As SPLICE_F_NONBLOCK == MSG_PEEK, kernel gets
> >> confused: skb isn't unlinked from a receive queue, while strp_msg::offset
> >> and strp_msg::full_len are updated.
> >>
> >> Unbreak the logic a bit more by mapping both O_NONBLOCK and
> >> SPLICE_F_NONBLOCK to MSG_DONTWAIT. This way we align with man splice(2) in
> >> regard to errno EAGAIN:
> >>
> >> SPLICE_F_NONBLOCK was specified in flags or one of the file descriptors
> >> had been marked as nonblocking (O_NONBLOCK), and the operation would
> >> block.
> >
> > Coincidentally looks like we're not honoring
> >
> > sock->file->f_flags & O_NONBLOCK
> >
> > in TLS..
>
> I'm a bit confused.
>
> Comparing AF_UNIX and pure (non-TLS) TCP, I see two non-blocking-splice
> interpretations. Unix socket doesn't block on `f_flags & O_NONBLOCK ||
> flags & SPLICE_F_NONBLOCK` (which this patch follows), while TCP, after
> commit 42324c627043 ("net: splice() from tcp to pipe should take into
> account O_NONBLOCK"), honours O_NONBLOCK and ignores SPLICE_F_NONBLOCK.
>
> Should KCM (and TLS) follow TCP behaviour instead?
I didn't look closely, but FWIW - yes, in principle KCM and TLS should
copy TCP.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] kcm: Fix splice support
2025-08-04 23:51 ` Jakub Kicinski
@ 2025-08-06 21:15 ` Michal Luczaj
0 siblings, 0 replies; 6+ messages in thread
From: Michal Luczaj @ 2025-08-06 21:15 UTC (permalink / raw)
To: Jakub Kicinski
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Cong Wang, Tom Herbert, netdev, linux-kernel
On 8/5/25 01:51, Jakub Kicinski wrote:
> On Sun, 3 Aug 2025 12:00:38 +0200 Michal Luczaj wrote:
>> On 7/31/25 03:02, Jakub Kicinski wrote:
>>> On Fri, 25 Jul 2025 12:33:04 +0200 Michal Luczaj wrote:
>>>> Flags passed in for splice() syscall should not end up in
>>>> skb_recv_datagram(). As SPLICE_F_NONBLOCK == MSG_PEEK, kernel gets
>>>> confused: skb isn't unlinked from a receive queue, while strp_msg::offset
>>>> and strp_msg::full_len are updated.
>>>>
>>>> Unbreak the logic a bit more by mapping both O_NONBLOCK and
>>>> SPLICE_F_NONBLOCK to MSG_DONTWAIT. This way we align with man splice(2) in
>>>> regard to errno EAGAIN:
>>>>
>>>> SPLICE_F_NONBLOCK was specified in flags or one of the file descriptors
>>>> had been marked as nonblocking (O_NONBLOCK), and the operation would
>>>> block.
>>>
>>> Coincidentally looks like we're not honoring
>>>
>>> sock->file->f_flags & O_NONBLOCK
>>>
>>> in TLS..
>>
>> I'm a bit confused.
>>
>> Comparing AF_UNIX and pure (non-TLS) TCP, I see two non-blocking-splice
>> interpretations. Unix socket doesn't block on `f_flags & O_NONBLOCK ||
>> flags & SPLICE_F_NONBLOCK` (which this patch follows), while TCP, after
>> commit 42324c627043 ("net: splice() from tcp to pipe should take into
>> account O_NONBLOCK"), honours O_NONBLOCK and ignores SPLICE_F_NONBLOCK.
>>
>> Should KCM (and TLS) follow TCP behaviour instead?
>
> I didn't look closely, but FWIW - yes, in principle KCM and TLS should
> copy TCP.
Ugh, so this KCM patch is incorrect. Sorry, I'll submit a follow up
tweaking KCM and TLS, as suggested.
Note about SPLICE_F_NONBLOCK: besides AF_UNIX, it is also honoured in
AF_SMC and tracefs.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-08-06 21:15 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-25 10:33 [PATCH net] kcm: Fix splice support Michal Luczaj
2025-07-31 1:02 ` Jakub Kicinski
2025-08-03 10:00 ` Michal Luczaj
2025-08-04 23:51 ` Jakub Kicinski
2025-08-06 21:15 ` Michal Luczaj
2025-07-31 1:10 ` patchwork-bot+netdevbpf
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).