diff mbox series

[net-next,1/7] tcp: only initialize sockcm tsflags field

Message ID 20250206193521.2285488-2-willemdebruijn.kernel@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: deduplicate cookie logic | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 3 maintainers not CCed: horms@kernel.org ncardwell@google.com dsahern@kernel.org
netdev/build_clang success Errors and warnings before: 2 this patch: 2
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 No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 1 this patch: 1
netdev/source_inline success Was 0 now: 0

Commit Message

Willem de Bruijn Feb. 6, 2025, 7:34 p.m. UTC
From: Willem de Bruijn <willemb@google.com>

TCP only reads the tsflags field. Don't bother initializing others.

Signed-off-by: Willem de Bruijn <willemb@google.com>

---

Another option is to entirely avoid sockcm_cookie in the tcp hot path.
Limit its use to the sock_cmsg_send branch:

	@@ -1123,13 +1123,17 @@ int tcp_sendmsg_locked(struct sock *sk, struct
	msghdr *msg, size_t size)
			/* 'common' sending to sendq */
		}

	-       sockcm_init(&sockc, sk);
	+       tsflags = READ_ONCE(sk->sk_tsflags);
		if (msg->msg_controllen) {
	+               struct sockcm_cookie sockc = { .tsflags = tsflags };
	+
			err = sock_cmsg_send(sk, msg, &sockc);
			if (unlikely(err)) {
				err = -EINVAL;
				goto out_err;
			}
	+
	+               tsflags = sockc.tsflags;

This involves a bit more rework, to have sock_tx_timestamp take a u32
tsflags directly.
---
 net/ipv4/tcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 0d704bda6c41..1f94b4e6c7ec 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1123,7 +1123,7 @@  int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
 		/* 'common' sending to sendq */
 	}
 
-	sockcm_init(&sockc, sk);
+	sockc = (struct sockcm_cookie) { .tsflags = READ_ONCE(sk->sk_tsflags)};
 	if (msg->msg_controllen) {
 		err = sock_cmsg_send(sk, msg, &sockc);
 		if (unlikely(err)) {