netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v3 0/2] trace: add tracepoint for tcp_sendmsg_locked()
@ 2025-04-08 18:32 Breno Leitao
  2025-04-08 18:32 ` [PATCH net-next v3 1/2] net: pass const to msg_data_left() Breno Leitao
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Breno Leitao @ 2025-04-08 18:32 UTC (permalink / raw)
  To: David Ahern, Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima,
	Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
	David S. Miller, David Ahern, Jakub Kicinski, Paolo Abeni,
	Simon Horman
  Cc: Song Liu, Yonghong Song, netdev, linux-kernel, linux-trace-kernel,
	Breno Leitao, kernel-team

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]

Signed-off-by: Breno Leitao <leitao@debian.org>
---
Changes in v3:
- Fixed identation (Kuniyuki Iwashi)
- Removed duplicated entry in the commit message (Kuniyuki Iwashi)
- Added tcp_sendmsg_locked in bpf_raw_tp_null_args[] (Kuniyuki Iwashi)
- Link to v2: https://lore.kernel.org/r/20250407-tcpsendmsg-v2-0-9f0ea843ef99@debian.org

Changes in v2:
- Change to a full tracepoint inside tcp_sendmsg_locked(), heavily
  inspired in David's patch
- Link to v1: https://lore.kernel.org/r/20250224-tcpsendmsg-v1-1-bac043c59cc8@debian.org

---
Breno Leitao (2):
      net: pass const to msg_data_left()
      trace: tcp: Add tracepoint for tcp_sendmsg_locked()

 include/linux/socket.h     |  2 +-
 include/trace/events/tcp.h | 24 ++++++++++++++++++++++++
 kernel/bpf/btf.c           |  1 +
 net/ipv4/tcp.c             |  2 ++
 4 files changed, 28 insertions(+), 1 deletion(-)
---
base-commit: 1a9239bb4253f9076b5b4b2a1a4e8d7defd77a95
change-id: 20250224-tcpsendmsg-4f0a236751d7

Best regards,
-- 
Breno Leitao <leitao@debian.org>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next v3 1/2] net: pass const to msg_data_left()
  2025-04-08 18:32 [PATCH net-next v3 0/2] trace: add tracepoint for tcp_sendmsg_locked() Breno Leitao
@ 2025-04-08 18:32 ` Breno Leitao
  2025-04-08 18:32 ` [PATCH net-next v3 2/2] trace: tcp: Add tracepoint for tcp_sendmsg_locked() Breno Leitao
  2025-04-11  2:20 ` [PATCH net-next v3 0/2] trace: add " patchwork-bot+netdevbpf
  2 siblings, 0 replies; 7+ messages in thread
From: Breno Leitao @ 2025-04-08 18:32 UTC (permalink / raw)
  To: David Ahern, Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima,
	Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
	David S. Miller, David Ahern, Jakub Kicinski, Paolo Abeni,
	Simon Horman
  Cc: Song Liu, Yonghong Song, netdev, linux-kernel, linux-trace-kernel,
	Breno Leitao, kernel-team

The msg_data_left() function doesn't modify the struct msghdr parameter,
so mark it as const. This allows the function to be used with const
references, improving type safety and making the API more flexible.

Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
---
 include/linux/socket.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/socket.h b/include/linux/socket.h
index c3322eb3d6865..3b262487ec060 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -168,7 +168,7 @@ static inline struct cmsghdr * cmsg_nxthdr (struct msghdr *__msg, struct cmsghdr
 	return __cmsg_nxthdr(__msg->msg_control, __msg->msg_controllen, __cmsg);
 }
 
-static inline size_t msg_data_left(struct msghdr *msg)
+static inline size_t msg_data_left(const struct msghdr *msg)
 {
 	return iov_iter_count(&msg->msg_iter);
 }

-- 
2.47.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next v3 2/2] trace: tcp: Add tracepoint for tcp_sendmsg_locked()
  2025-04-08 18:32 [PATCH net-next v3 0/2] trace: add tracepoint for tcp_sendmsg_locked() Breno Leitao
  2025-04-08 18:32 ` [PATCH net-next v3 1/2] net: pass const to msg_data_left() Breno Leitao
@ 2025-04-08 18:32 ` Breno Leitao
  2025-04-08 19:32   ` David Ahern
                     ` (2 more replies)
  2025-04-11  2:20 ` [PATCH net-next v3 0/2] trace: add " patchwork-bot+netdevbpf
  2 siblings, 3 replies; 7+ messages in thread
From: Breno Leitao @ 2025-04-08 18:32 UTC (permalink / raw)
  To: David Ahern, Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima,
	Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
	David S. Miller, David Ahern, Jakub Kicinski, Paolo Abeni,
	Simon Horman
  Cc: Song Liu, Yonghong Song, netdev, linux-kernel, linux-trace-kernel,
	Breno Leitao, kernel-team

Add a tracepoint to monitor TCP send operations, enabling detailed
visibility into TCP message transmission.

Create a new tracepoint within the tcp_sendmsg_locked function,
capturing traditional fields along with size_goal, which indicates the
optimal data size for a single TCP segment. Additionally, a reference to
the struct sock sk is passed, allowing direct access for BPF programs.
The implementation is largely based on David's patch[1] and suggestions.

Link: https://lore.kernel.org/all/70168c8f-bf52-4279-b4c4-be64527aa1ac@kernel.org/ [1]
Signed-off-by: Breno Leitao <leitao@debian.org>
---
 include/trace/events/tcp.h | 24 ++++++++++++++++++++++++
 kernel/bpf/btf.c           |  1 +
 net/ipv4/tcp.c             |  2 ++
 3 files changed, 27 insertions(+)

diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
index 1a40c41ff8c30..75d3d53a3832c 100644
--- a/include/trace/events/tcp.h
+++ b/include/trace/events/tcp.h
@@ -259,6 +259,30 @@ TRACE_EVENT(tcp_retransmit_synack,
 		  __entry->saddr_v6, __entry->daddr_v6)
 );
 
+TRACE_EVENT(tcp_sendmsg_locked,
+	TP_PROTO(const struct sock *sk, const struct msghdr *msg,
+		 const struct sk_buff *skb, int size_goal),
+
+	TP_ARGS(sk, msg, skb, size_goal),
+
+	TP_STRUCT__entry(
+		__field(const void *, skb_addr)
+		__field(int, skb_len)
+		__field(int, msg_left)
+		__field(int, size_goal)
+	),
+
+	TP_fast_assign(
+		__entry->skb_addr = skb;
+		__entry->skb_len = skb ? skb->len : 0;
+		__entry->msg_left = msg_data_left(msg);
+		__entry->size_goal = size_goal;
+	),
+
+	TP_printk("skb_addr %p skb_len %d msg_left %d size_goal %d",
+		  __entry->skb_addr, __entry->skb_len, __entry->msg_left,
+		  __entry->size_goal));
+
 DECLARE_TRACE(tcp_cwnd_reduction_tp,
 	TP_PROTO(const struct sock *sk, int newly_acked_sacked,
 		 int newly_lost, int flag),
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index eacb701bc2be2..475a1317ad275 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -6518,6 +6518,7 @@ static const struct bpf_raw_tp_null_args raw_tp_null_args[] = {
 	{ "xprt_put_cong", 0x10 },
 	/* tcp */
 	{ "tcp_send_reset", 0x11 },
+	{ "tcp_sendmsg_locked", 0x100 },
 	/* tegra_apb_dma */
 	{ "tegra_dma_tx_status", 0x100 },
 	/* timer_migration */
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index ea8de00f669d0..270ce2c8c2d54 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1160,6 +1160,8 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
 		if (skb)
 			copy = size_goal - skb->len;
 
+		trace_tcp_sendmsg_locked(sk, msg, skb, size_goal);
+
 		if (copy <= 0 || !tcp_skb_can_collapse_to(skb)) {
 			bool first_skb;
 

-- 
2.47.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v3 2/2] trace: tcp: Add tracepoint for tcp_sendmsg_locked()
  2025-04-08 18:32 ` [PATCH net-next v3 2/2] trace: tcp: Add tracepoint for tcp_sendmsg_locked() Breno Leitao
@ 2025-04-08 19:32   ` David Ahern
  2025-04-08 20:54   ` Kuniyuki Iwashima
  2025-04-09  7:13   ` Eric Dumazet
  2 siblings, 0 replies; 7+ messages in thread
From: David Ahern @ 2025-04-08 19:32 UTC (permalink / raw)
  To: Breno Leitao, Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima,
	Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
	David S. Miller, Jakub Kicinski, Paolo Abeni, Simon Horman
  Cc: Song Liu, Yonghong Song, netdev, linux-kernel, linux-trace-kernel,
	kernel-team

On 4/8/25 12:32 PM, Breno Leitao wrote:
> Add a tracepoint to monitor TCP send operations, enabling detailed
> visibility into TCP message transmission.
> 
> Create a new tracepoint within the tcp_sendmsg_locked function,
> capturing traditional fields along with size_goal, which indicates the
> optimal data size for a single TCP segment. Additionally, a reference to
> the struct sock sk is passed, allowing direct access for BPF programs.
> The implementation is largely based on David's patch[1] and suggestions.
> 
> Link: https://lore.kernel.org/all/70168c8f-bf52-4279-b4c4-be64527aa1ac@kernel.org/ [1]
> Signed-off-by: Breno Leitao <leitao@debian.org>
> ---
>  include/trace/events/tcp.h | 24 ++++++++++++++++++++++++
>  kernel/bpf/btf.c           |  1 +
>  net/ipv4/tcp.c             |  2 ++
>  3 files changed, 27 insertions(+)
> 

Reviewed-by: David Ahern <dsahern@kernel.org>



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v3 2/2] trace: tcp: Add tracepoint for tcp_sendmsg_locked()
  2025-04-08 18:32 ` [PATCH net-next v3 2/2] trace: tcp: Add tracepoint for tcp_sendmsg_locked() Breno Leitao
  2025-04-08 19:32   ` David Ahern
@ 2025-04-08 20:54   ` Kuniyuki Iwashima
  2025-04-09  7:13   ` Eric Dumazet
  2 siblings, 0 replies; 7+ messages in thread
From: Kuniyuki Iwashima @ 2025-04-08 20:54 UTC (permalink / raw)
  To: leitao
  Cc: davem, dsahern, edumazet, horms, kernel-team, kuba, kuniyu,
	linux-kernel, linux-trace-kernel, mathieu.desnoyers, mhiramat,
	ncardwell, netdev, pabeni, rostedt, song, yonghong.song

From: Breno Leitao <leitao@debian.org>
Date: Tue, 08 Apr 2025 11:32:02 -0700
> Add a tracepoint to monitor TCP send operations, enabling detailed
> visibility into TCP message transmission.
> 
> Create a new tracepoint within the tcp_sendmsg_locked function,
> capturing traditional fields along with size_goal, which indicates the
> optimal data size for a single TCP segment. Additionally, a reference to
> the struct sock sk is passed, allowing direct access for BPF programs.
> The implementation is largely based on David's patch[1] and suggestions.
> 
> Link: https://lore.kernel.org/all/70168c8f-bf52-4279-b4c4-be64527aa1ac@kernel.org/ [1]
> Signed-off-by: Breno Leitao <leitao@debian.org>

Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v3 2/2] trace: tcp: Add tracepoint for tcp_sendmsg_locked()
  2025-04-08 18:32 ` [PATCH net-next v3 2/2] trace: tcp: Add tracepoint for tcp_sendmsg_locked() Breno Leitao
  2025-04-08 19:32   ` David Ahern
  2025-04-08 20:54   ` Kuniyuki Iwashima
@ 2025-04-09  7:13   ` Eric Dumazet
  2 siblings, 0 replies; 7+ messages in thread
From: Eric Dumazet @ 2025-04-09  7:13 UTC (permalink / raw)
  To: Breno Leitao
  Cc: David Ahern, Neal Cardwell, Kuniyuki Iwashima, Steven Rostedt,
	Masami Hiramatsu, Mathieu Desnoyers, David S. Miller,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Song Liu,
	Yonghong Song, netdev, linux-kernel, linux-trace-kernel,
	kernel-team

On Tue, Apr 8, 2025 at 8:32 PM Breno Leitao <leitao@debian.org> wrote:
>
> Add a tracepoint to monitor TCP send operations, enabling detailed
> visibility into TCP message transmission.
>
> Create a new tracepoint within the tcp_sendmsg_locked function,
> capturing traditional fields along with size_goal, which indicates the
> optimal data size for a single TCP segment. Additionally, a reference to
> the struct sock sk is passed, allowing direct access for BPF programs.
> The implementation is largely based on David's patch[1] and suggestions.
>
> Link: https://lore.kernel.org/all/70168c8f-bf52-4279-b4c4-be64527aa1ac@kernel.org/ [1]
> Signed-off-by: Breno Leitao <leitao@debian.org>

Reviewed-by: Eric Dumazet <edumazet@google.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v3 0/2] trace: add tracepoint for tcp_sendmsg_locked()
  2025-04-08 18:32 [PATCH net-next v3 0/2] trace: add tracepoint for tcp_sendmsg_locked() Breno Leitao
  2025-04-08 18:32 ` [PATCH net-next v3 1/2] net: pass const to msg_data_left() Breno Leitao
  2025-04-08 18:32 ` [PATCH net-next v3 2/2] trace: tcp: Add tracepoint for tcp_sendmsg_locked() Breno Leitao
@ 2025-04-11  2:20 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-04-11  2:20 UTC (permalink / raw)
  To: Breno Leitao
  Cc: dsahern, edumazet, ncardwell, kuniyu, rostedt, mhiramat,
	mathieu.desnoyers, davem, kuba, pabeni, horms, song,
	yonghong.song, netdev, linux-kernel, linux-trace-kernel,
	kernel-team

Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 08 Apr 2025 11:32:00 -0700 you wrote:
> 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.
> 
> [...]

Here is the summary with links:
  - [net-next,v3,1/2] net: pass const to msg_data_left()
    https://git.kernel.org/netdev/net-next/c/b1e904999542
  - [net-next,v3,2/2] trace: tcp: Add tracepoint for tcp_sendmsg_locked()
    https://git.kernel.org/netdev/net-next/c/0f08335ade71

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] 7+ messages in thread

end of thread, other threads:[~2025-04-11  2:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-08 18:32 [PATCH net-next v3 0/2] trace: add tracepoint for tcp_sendmsg_locked() Breno Leitao
2025-04-08 18:32 ` [PATCH net-next v3 1/2] net: pass const to msg_data_left() Breno Leitao
2025-04-08 18:32 ` [PATCH net-next v3 2/2] trace: tcp: Add tracepoint for tcp_sendmsg_locked() Breno Leitao
2025-04-08 19:32   ` David Ahern
2025-04-08 20:54   ` Kuniyuki Iwashima
2025-04-09  7:13   ` Eric Dumazet
2025-04-11  2:20 ` [PATCH net-next v3 0/2] trace: add " 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).