Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'trace-add-tracepoint-for-tcp_sendmsg_locked'

Breno Leitao says:

====================
trace: add tracepoint for tcp_sendmsg_locked()

Meta has been using BPF programs to monitor tcp_sendmsg() for years,
indicating significant interest in observing this important
functionality. Adding a proper tracepoint provides a stable API for all
users who need visibility into TCP message transmission.

David Ahern is using a similar functionality with a custom patch[1]. So,
this means we have more than a single use case for this request, and it
might be a good idea to have such feature upstream.

Link: https://lore.kernel.org/all/70168c8f-bf52-4279-b4c4-be64527aa1ac@kernel.org/ [1]

v2: https://lore.kernel.org/20250407-tcpsendmsg-v2-0-9f0ea843ef99@debian.org
v1: https://lore.kernel.org/20250224-tcpsendmsg-v1-1-bac043c59cc8@debian.org
====================

Link: https://patch.msgid.link/20250408-tcpsendmsg-v3-0-208b87064c28@debian.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+28 -1
+1 -1
include/linux/socket.h
··· 168 168 return __cmsg_nxthdr(__msg->msg_control, __msg->msg_controllen, __cmsg); 169 169 } 170 170 171 - static inline size_t msg_data_left(struct msghdr *msg) 171 + static inline size_t msg_data_left(const struct msghdr *msg) 172 172 { 173 173 return iov_iter_count(&msg->msg_iter); 174 174 }
+24
include/trace/events/tcp.h
··· 259 259 __entry->saddr_v6, __entry->daddr_v6) 260 260 ); 261 261 262 + TRACE_EVENT(tcp_sendmsg_locked, 263 + TP_PROTO(const struct sock *sk, const struct msghdr *msg, 264 + const struct sk_buff *skb, int size_goal), 265 + 266 + TP_ARGS(sk, msg, skb, size_goal), 267 + 268 + TP_STRUCT__entry( 269 + __field(const void *, skb_addr) 270 + __field(int, skb_len) 271 + __field(int, msg_left) 272 + __field(int, size_goal) 273 + ), 274 + 275 + TP_fast_assign( 276 + __entry->skb_addr = skb; 277 + __entry->skb_len = skb ? skb->len : 0; 278 + __entry->msg_left = msg_data_left(msg); 279 + __entry->size_goal = size_goal; 280 + ), 281 + 282 + TP_printk("skb_addr %p skb_len %d msg_left %d size_goal %d", 283 + __entry->skb_addr, __entry->skb_len, __entry->msg_left, 284 + __entry->size_goal)); 285 + 262 286 DECLARE_TRACE(tcp_cwnd_reduction_tp, 263 287 TP_PROTO(const struct sock *sk, int newly_acked_sacked, 264 288 int newly_lost, int flag),
+1
kernel/bpf/btf.c
··· 6541 6541 { "xprt_put_cong", 0x10 }, 6542 6542 /* tcp */ 6543 6543 { "tcp_send_reset", 0x11 }, 6544 + { "tcp_sendmsg_locked", 0x100 }, 6544 6545 /* tegra_apb_dma */ 6545 6546 { "tegra_dma_tx_status", 0x100 }, 6546 6547 /* timer_migration */
+2
net/ipv4/tcp.c
··· 1160 1160 if (skb) 1161 1161 copy = size_goal - skb->len; 1162 1162 1163 + trace_tcp_sendmsg_locked(sk, msg, skb, size_goal); 1164 + 1163 1165 if (copy <= 0 || !tcp_skb_can_collapse_to(skb)) { 1164 1166 bool first_skb; 1165 1167