Netdev List
 help / color / mirror / Atom feed
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Jason Xing <kerneljasonxing@gmail.com>,
	 davem@davemloft.net,  edumazet@google.com,  kuba@kernel.org,
	 pabeni@redhat.com,  dsahern@kernel.org,
	 willemdebruijn.kernel@gmail.com,  willemb@google.com,
	 ast@kernel.org,  daniel@iogearbox.net,  andrii@kernel.org,
	 martin.lau@linux.dev,  eddyz87@gmail.com,  song@kernel.org,
	 yonghong.song@linux.dev,  john.fastabend@gmail.com,
	 kpsingh@kernel.org,  sdf@fomichev.me,  haoluo@google.com,
	 jolsa@kernel.org
Cc: bpf@vger.kernel.org,  netdev@vger.kernel.org,
	 Jason Xing <kernelxing@tencent.com>
Subject: Re: [PATCH net-next v2 11/12] net-timestamp: add bpf framework for rx timestamps
Date: Mon, 14 Oct 2024 21:44:17 -0400	[thread overview]
Message-ID: <670dc8f1c9e3d_2e1742294ad@willemb.c.googlers.com.notmuch> (raw)
In-Reply-To: <20241012040651.95616-12-kerneljasonxing@gmail.com>

Jason Xing wrote:
> From: Jason Xing <kernelxing@tencent.com>
> 
> Prepare for later changes in this series. Here I use u32 for
> bpf_sock_ops_cb_flags for better extension and introduce a new
> rx bpf flag to control separately.
> 
> Main change is let userside set through bpf_setsockopt() for
> SO_TIMESTAMPING feature.
> 
> Signed-off-by: Jason Xing <kernelxing@tencent.com>
> ---
>  include/linux/tcp.h            |  2 +-
>  include/net/tcp.h              |  2 +-
>  include/uapi/linux/bpf.h       |  5 ++++-
>  net/core/filter.c              |  6 +++++-
>  net/ipv4/tcp.c                 | 13 ++++++++++++-
>  tools/include/uapi/linux/bpf.h |  5 ++++-
>  6 files changed, 27 insertions(+), 6 deletions(-)
> 
> diff --git a/include/linux/tcp.h b/include/linux/tcp.h
> index 6a5e08b937b3..e21fd3035962 100644
> --- a/include/linux/tcp.h
> +++ b/include/linux/tcp.h
> @@ -446,7 +446,7 @@ struct tcp_sock {
>  
>  /* Sock_ops bpf program related variables */
>  #ifdef CONFIG_BPF
> -	u8	bpf_sock_ops_cb_flags;  /* Control calling BPF programs
> +	u32	bpf_sock_ops_cb_flags;  /* Control calling BPF programs
>  					 * values defined in uapi/linux/tcp.h
>  					 */
>  	u8	bpf_chg_cc_inprogress:1; /* In the middle of
> diff --git a/include/net/tcp.h b/include/net/tcp.h
> index 739a9fb83d0c..728db7107074 100644
> --- a/include/net/tcp.h
> +++ b/include/net/tcp.h
> @@ -423,7 +423,7 @@ int tcp_set_rcvlowat(struct sock *sk, int val);
>  int tcp_set_window_clamp(struct sock *sk, int val);
>  void tcp_update_recv_tstamps(struct sk_buff *skb,
>  			     struct scm_timestamping_internal *tss);
> -void tcp_recv_timestamp(struct msghdr *msg, const struct sock *sk,
> +void tcp_recv_timestamp(struct msghdr *msg, struct sock *sk,
>  			struct scm_timestamping_internal *tss);
>  void tcp_data_ready(struct sock *sk);
>  #ifdef CONFIG_MMU
> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> index 1b478ec18ac2..d2754f155cf7 100644
> --- a/include/uapi/linux/bpf.h
> +++ b/include/uapi/linux/bpf.h
> @@ -6903,8 +6903,11 @@ enum {
>  	/* Call bpf when the kernel is generating tx timestamps.
>  	 */
>  	BPF_SOCK_OPS_TX_TIMESTAMPING_OPT_CB_FLAG = (1<<7),
> +	/* Call bpf when the kernel is generating rx timestamps.
> +	 */
> +	BPF_SOCK_OPS_RX_TIMESTAMPING_OPT_CB_FLAG = (1<<8),
>  /* Mask of all currently supported cb flags */
> -	BPF_SOCK_OPS_ALL_CB_FLAGS       = 0xFF,
> +	BPF_SOCK_OPS_ALL_CB_FLAGS       = 0x1FF,
>  };
>  
>  /* List of known BPF sock_ops operators.
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 3b4afaa273d9..36b357b76f4a 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -5216,14 +5216,18 @@ static int bpf_sock_set_timestamping(struct sock *sk,
>  		return -EINVAL;
>  
>  	if (!(flags & (SOF_TIMESTAMPING_TX_SCHED | SOF_TIMESTAMPING_TX_SOFTWARE |
> -	      SOF_TIMESTAMPING_TX_ACK)))
> +	      SOF_TIMESTAMPING_TX_ACK | SOF_TIMESTAMPING_RX_SOFTWARE)))
>  		return -EINVAL;
>  
>  	ret = sock_set_tskey(sk, flags, BPFPROG_TS_REQUESTOR);
>  	if (ret)
>  		return ret;
>  
> +	if (flags & SOF_TIMESTAMPING_RX_SOFTWARE)
> +		sock_enable_timestamp(sk, SOCK_TIMESTAMPING_RX_SOFTWARE);
> +
>  	WRITE_ONCE(sk->sk_tsflags[BPFPROG_TS_REQUESTOR], flags);
> +
>  	static_branch_enable(&bpf_tstamp_control);
>  
>  	return 0;
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index d37e231b2737..0891b41bc745 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -2260,14 +2260,25 @@ static int tcp_zerocopy_receive(struct sock *sk,
>  }
>  #endif
>  
> +static void tcp_bpf_recv_timestamp(struct sock *sk, struct scm_timestamping_internal *tss)
> +{
> +	struct tcp_sock *tp = tcp_sk(sk);
> +
> +	if (BPF_SOCK_OPS_TEST_FLAG(tp, BPF_SOCK_OPS_RX_TIMESTAMPING_OPT_CB_FLAG))
> +		return;
> +}
> +
>  /* Similar to __sock_recv_timestamp, but does not require an skb */
> -void tcp_recv_timestamp(struct msghdr *msg, const struct sock *sk,
> +void tcp_recv_timestamp(struct msghdr *msg, struct sock *sk,
>  			struct scm_timestamping_internal *tss)
>  {
>  	int new_tstamp = sock_flag(sk, SOCK_TSTAMP_NEW);
>  	u32 tsflags = READ_ONCE(sk->sk_tsflags[SOCKETOPT_TS_REQUESTOR]);
>  	bool has_timestamping = false;
>  
> +	if (static_branch_unlikely(&bpf_tstamp_control))
> +		tcp_bpf_recv_timestamp(sk, tss);
> +
>  	if (tss->ts[0].tv_sec || tss->ts[0].tv_nsec) {
>  		if (sock_flag(sk, SOCK_RCVTSTAMP)) {
>  			if (sock_flag(sk, SOCK_RCVTSTAMPNS)) {

tcp_recv_timestamp is called from tcp_recvmsg only conditionally:

        if ((cmsg_flags || msg->msg_get_inq) && ret >= 0) {
                if (cmsg_flags & TCP_CMSG_TS)
                        tcp_recv_timestamp(msg, sk, &tss);

How do you get this triggered for your BPF program?

And also check the other caller, tcp_zc_finalize_rx_tstamp.

  reply	other threads:[~2024-10-15  1:44 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-12  4:06 [PATCH net-next v2 00/12] net-timestamp: bpf extension to equip applications transparently Jason Xing
2024-10-12  4:06 ` [PATCH net-next v2 01/12] net-timestamp: introduce socket tsflag requestors Jason Xing
2024-10-15  1:30   ` Willem de Bruijn
2024-10-15  1:50     ` Jason Xing
2024-10-12  4:06 ` [PATCH net-next v2 02/12] net-timestamp: open gate for bpf_setsockopt Jason Xing
2024-10-15  1:34   ` Willem de Bruijn
2024-10-15  2:05     ` Jason Xing
2024-10-15 21:32   ` Martin KaFai Lau
2024-10-15 21:55     ` Willem de Bruijn
2024-10-22 13:22       ` Jason Xing
2024-10-23  0:06         ` Willem de Bruijn
2024-10-23  3:49           ` Jason Xing
2024-10-16  0:45     ` Jason Xing
2024-10-15 23:54   ` Martin KaFai Lau
2024-10-16  0:49     ` Jason Xing
2024-10-12  4:06 ` [PATCH net-next v2 03/12] net-timestamp: reorganize in skb_tstamp_tx_output() Jason Xing
2024-10-12  4:06 ` [PATCH net-next v2 04/12] net-timestamp: add static key to control the whole bpf extension Jason Xing
2024-10-15  1:36   ` Willem de Bruijn
2024-10-15  2:25     ` Jason Xing
2024-10-16  0:09   ` Martin KaFai Lau
2024-10-16  1:04     ` Jason Xing
2024-10-16  1:32       ` Jason Xing
2024-10-16  6:13         ` Martin KaFai Lau
2024-10-16  6:30           ` Jason Xing
2024-10-16  7:01             ` Martin KaFai Lau
2024-10-16  7:54               ` Jason Xing
2024-10-16  8:31                 ` Martin KaFai Lau
2024-10-16 10:36                   ` Jason Xing
2024-10-17  0:48                     ` Martin KaFai Lau
2024-10-17  2:28                       ` Jason Xing
2024-10-17 20:43                         ` Martin KaFai Lau
2024-10-18  2:52                           ` Jason Xing
2024-10-18  3:05                             ` Jason Xing
2024-10-16  6:31       ` Martin KaFai Lau
2024-10-16  6:45         ` Jason Xing
2024-10-16 13:13           ` Willem de Bruijn
2024-10-16 13:22             ` Jason Xing
2024-10-20 21:51   ` Willem de Bruijn
2024-10-21  3:21     ` Jason Xing
2024-10-21 14:49       ` Willem de Bruijn
2024-10-21 15:05         ` Jason Xing
2024-10-22  0:53     ` Martin KaFai Lau
2024-10-22  2:30       ` Jason Xing
2024-10-23  0:17       ` Willem de Bruijn
2024-10-23  2:31         ` Willem de Bruijn
2024-10-12  4:06 ` [PATCH net-next v2 05/12] net-timestamp: add bpf infrastructure to allow exposing timestamp later Jason Xing
2024-10-12  4:06 ` [PATCH net-next v2 06/12] net-timestamp: introduce TS_SCHED_OPT_CB to generate dev xmit timestamp Jason Xing
2024-10-16  1:01   ` Martin KaFai Lau
2024-10-16  1:24     ` Jason Xing
2024-10-16  5:35       ` Martin KaFai Lau
2024-10-16  6:08         ` Jason Xing
2024-10-12  4:06 ` [PATCH net-next v2 07/12] net-timestamp: introduce TS_SW_OPT_CB to generate driver timestamp Jason Xing
2024-10-12  4:06 ` [PATCH net-next v2 08/12] net-timestamp: introduce TS_ACK_OPT_CB to generate tcp acked timestamp Jason Xing
2024-10-12  4:06 ` [PATCH net-next v2 09/12] net-timestamp: add tx OPT_ID_TCP support for bpf case Jason Xing
2024-10-15  1:38   ` Willem de Bruijn
2024-10-15  2:25     ` Jason Xing
2024-10-15  2:38       ` Willem de Bruijn
2024-10-15  2:59         ` Jason Xing
2024-10-15  8:40   ` kernel test robot
2024-10-15  9:36     ` Jason Xing
2024-10-12  4:06 ` [PATCH net-next v2 10/12] net-timestamp: make bpf for tx timestamp work Jason Xing
2024-10-12  4:06 ` [PATCH net-next v2 11/12] net-timestamp: add bpf framework for rx timestamps Jason Xing
2024-10-15  1:44   ` Willem de Bruijn [this message]
2024-10-15  2:18     ` Jason Xing
2024-10-12  4:06 ` [PATCH net-next v2 12/12] net-timestamp: add bpf support for rx software/hardware timestamp Jason Xing
2024-10-12 17:48 ` [PATCH net-next v2 00/12] net-timestamp: bpf extension to equip applications transparently Willem de Bruijn
2024-10-13  3:28   ` Jason Xing
2024-10-13  3:43     ` Jason Xing
2024-10-13  6:05       ` Jason Xing
2024-10-15  1:28     ` Willem de Bruijn
2024-10-15  2:52       ` Jason Xing
2024-10-15  2:59         ` Willem de Bruijn
2024-10-15  3:02           ` Jason Xing

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=670dc8f1c9e3d_2e1742294ad@willemb.c.googlers.com.notmuch \
    --to=willemdebruijn.kernel@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=eddyz87@gmail.com \
    --cc=edumazet@google.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kerneljasonxing@gmail.com \
    --cc=kernelxing@tencent.com \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=willemb@google.com \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox