diff mbox series

[net] splice: do not checksum AF_UNIX sockets

Message ID Z0pMLtmaGPPSR3Ea@xiberoa (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series [net] splice: do not checksum AF_UNIX sockets | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 3 this patch: 3
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers fail 1 blamed authors not CCed: kuba@kernel.org; 4 maintainers not CCed: kuba@kernel.org edumazet@google.com horms@kernel.org pabeni@redhat.com
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 304 this patch: 304
netdev/checkpatch warning WARNING: line length of 93 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 54 this patch: 54
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2024-11-30--00-00 (tests: 761)

Commit Message

Frederik Deweerdt Nov. 29, 2024, 11:20 p.m. UTC
When `skb_splice_from_iter` was introduced, it inadvertently added
checksumming for AF_UNIX sockets. This resulted in significant
slowdowns, as when using sendfile over unix sockets.

Using the test code [1] in my test setup (2G, single core x86_64 qemu),
the client receives a 1000M file in:
- without the patch: 1577ms (+/- 36.1ms)
- with the patch: 725ms (+/- 28.3ms)

This commit skips addresses the issue by skipping checksumming when
splice occurs a AF_UNIX socket.

[1] https://gist.github.com/deweerdt/a3ee2477d1d87524cf08618d3c179f06

Signed-off-by: Frederik Deweerdt <deweerdt.lkml@gmail.com>
Fixes: 2e910b95329c ("net: Add a function to splice pages into an skbuff for MSG_SPLICE_PAGES")
---
 net/core/skbuff.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Cong Wang Nov. 30, 2024, 1:43 a.m. UTC | #1
On Fri, Nov 29, 2024 at 03:20:14PM -0800, Frederik Deweerdt wrote:
> When `skb_splice_from_iter` was introduced, it inadvertently added
> checksumming for AF_UNIX sockets. This resulted in significant
> slowdowns, as when using sendfile over unix sockets.
> 
> Using the test code [1] in my test setup (2G, single core x86_64 qemu),
> the client receives a 1000M file in:
> - without the patch: 1577ms (+/- 36.1ms)
> - with the patch: 725ms (+/- 28.3ms)
> 
> This commit skips addresses the issue by skipping checksumming when
> splice occurs a AF_UNIX socket.
> 
> [1] https://gist.github.com/deweerdt/a3ee2477d1d87524cf08618d3c179f06
> 
> Signed-off-by: Frederik Deweerdt <deweerdt.lkml@gmail.com>
> Fixes: 2e910b95329c ("net: Add a function to splice pages into an skbuff for MSG_SPLICE_PAGES")
> ---
>  net/core/skbuff.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> index 6841e61a6bd0..49e4f9ab625f 100644
> --- a/net/core/skbuff.c
> +++ b/net/core/skbuff.c
> @@ -7233,7 +7233,7 @@ ssize_t skb_splice_from_iter(struct sk_buff *skb, struct iov_iter *iter,
>  				goto out;
>  			}
>  
> -			if (skb->ip_summed == CHECKSUM_NONE)
> +			if (skb->ip_summed == CHECKSUM_NONE && skb->sk->sk_family != AF_UNIX)

Are you sure it is always safe to dereferene skb->sk here? I am not sure
about the KCM socket case.

Instead of checking skb->sk->sk_family, why not just pass an additional
boolean parameter to this function?

Thanks.
diff mbox series

Patch

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 6841e61a6bd0..49e4f9ab625f 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -7233,7 +7233,7 @@  ssize_t skb_splice_from_iter(struct sk_buff *skb, struct iov_iter *iter,
 				goto out;
 			}
 
-			if (skb->ip_summed == CHECKSUM_NONE)
+			if (skb->ip_summed == CHECKSUM_NONE && skb->sk->sk_family != AF_UNIX)
 				skb_splice_csum_page(skb, page, off, part);
 
 			off = 0;