From: Jason Xing <kerneljasonxing@gmail.com>
To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, willemb@google.com,
kuniyu@google.com, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com,
memxor@gmail.com, song@kernel.org, yonghong.song@linux.dev,
jolsa@kernel.org, john.fastabend@gmail.com, sdf@fomichev.me
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org,
Jason Xing <kernelxing@tencent.com>
Subject: [PATCH net-next 3/6] bpf: support bpf_setsockopt for bpf timestamping rx feature
Date: Mon, 18 May 2026 16:23:41 +0800 [thread overview]
Message-ID: <20260518082344.96647-4-kerneljasonxing@gmail.com> (raw)
In-Reply-To: <20260518082344.96647-1-kerneljasonxing@gmail.com>
From: Jason Xing <kernelxing@tencent.com>
Add SK_BPF_CB_RX_TIMESTAMPING callback flag to enable RX timestamping
via bpf_setsockopt(SK_BPF_CB_FLAGS).
Add SOCK_BPF_TIMESTAMPING_RX into enum sock_flags that is used as
centralized management of net_enable/disable_timestamp. Note that only
one of them (timestamp, so_timestamping and bpf timestamping rx) can
enable and disable the global time record of skbs.
In addition, include SOCK_BPF_TIMESTAMPING_RX in SK_FLAGS_TIMESTAMP so
that __sk_destruct() calling sock_disable_timestamp() to thoroughly turn
off the global time record.
Signed-off-by: Jason Xing <kernelxing@tencent.com>
---
include/net/sock.h | 5 ++++-
include/uapi/linux/bpf.h | 5 +++--
net/core/filter.c | 8 ++++++++
3 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/include/net/sock.h b/include/net/sock.h
index a579d5b09207..cf0e82e46482 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1022,9 +1022,12 @@ enum sock_flags {
SOCK_RCVMARK, /* Receive SO_MARK ancillary data with packet */
SOCK_RCVPRIORITY, /* Receive SO_PRIORITY ancillary data with packet */
SOCK_TIMESTAMPING_ANY, /* Copy of sk_tsflags & TSFLAGS_ANY */
+ SOCK_BPF_TIMESTAMPING_RX, /* BPF RX timestamping enabled */
};
-#define SK_FLAGS_TIMESTAMP ((1UL << SOCK_TIMESTAMP) | (1UL << SOCK_TIMESTAMPING_RX_SOFTWARE))
+#define SK_FLAGS_TIMESTAMP ((1UL << SOCK_TIMESTAMP) | \
+ (1UL << SOCK_TIMESTAMPING_RX_SOFTWARE) | \
+ (1UL << SOCK_BPF_TIMESTAMPING_RX))
/*
* The highest bit of sk_tsflags is reserved for kernel-internal
* SOCKCM_FLAG_TS_OPT_ID. There is a check in core/sock.c to control that
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 552bc5d9afbd..1e09b5cd7a39 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -7029,8 +7029,9 @@ enum {
enum {
SK_BPF_CB_TX_TIMESTAMPING = 1<<0,
- SK_BPF_CB_MASK = (SK_BPF_CB_TX_TIMESTAMPING - 1) |
- SK_BPF_CB_TX_TIMESTAMPING
+ SK_BPF_CB_RX_TIMESTAMPING = 1<<1,
+ SK_BPF_CB_MASK = (SK_BPF_CB_RX_TIMESTAMPING - 1) |
+ SK_BPF_CB_RX_TIMESTAMPING
};
/* List of known BPF sock_ops operators.
diff --git a/net/core/filter.c b/net/core/filter.c
index 9590877b0714..08ad102f204e 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -5304,6 +5304,14 @@ static int sk_bpf_set_get_cb_flags(struct sock *sk, char *optval, bool getopt)
if (sk_bpf_cb_flags & ~SK_BPF_CB_MASK)
return -EINVAL;
+ if ((sk_bpf_cb_flags ^ sk->sk_bpf_cb_flags) & SK_BPF_CB_RX_TIMESTAMPING) {
+ if (sk_bpf_cb_flags & SK_BPF_CB_RX_TIMESTAMPING)
+ sock_enable_timestamp(sk, SOCK_BPF_TIMESTAMPING_RX);
+ else
+ sock_disable_timestamp(sk,
+ (1UL << SOCK_BPF_TIMESTAMPING_RX));
+ }
+
sk->sk_bpf_cb_flags = sk_bpf_cb_flags;
return 0;
--
2.43.7
next prev parent reply other threads:[~2026-05-18 8:24 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-18 8:23 [PATCH net-next 0/6] bpf-timetamp: support rx side Jason Xing
2026-05-18 8:23 ` [PATCH net-next 1/6] bpf: Add bpf_ktime_get_real_ns() kfunc Jason Xing
2026-05-18 11:57 ` Jesper Dangaard Brouer
2026-05-18 12:35 ` Jason Xing
2026-05-18 8:23 ` [PATCH net-next 2/6] net: export sock_disable_timestamp() declaration Jason Xing
2026-05-18 8:23 ` Jason Xing [this message]
2026-05-18 8:23 ` [PATCH net-next 4/6] bpf: add BPF_SOCK_OPS_TSTAMP_RCV_CB callback Jason Xing
2026-05-18 8:23 ` [PATCH net-next 5/6] bpf: enable bpf timestamping rx in TCP layer Jason Xing
2026-05-18 13:01 ` Jesper Dangaard Brouer
2026-05-18 13:53 ` Jason Xing
2026-05-18 16:40 ` Jesper Dangaard Brouer
2026-05-18 23:16 ` Jason Xing
2026-05-18 23:24 ` Jason Xing
2026-05-19 9:57 ` Toke Høiland-Jørgensen
2026-05-18 15:34 ` Stanislav Fomichev
2026-05-18 23:56 ` Jason Xing
2026-05-18 8:23 ` [PATCH net-next 6/6] selftests/bpf: Add RX latency tests for bpf timestamping Jason Xing
2026-05-18 11:46 ` [PATCH net-next 0/6] bpf-timetamp: support rx side Jesper Dangaard Brouer
2026-05-18 12:32 ` 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=20260518082344.96647-4-kerneljasonxing@gmail.com \
--to=kerneljasonxing@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kernelxing@tencent.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--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