Message ID | 20241008095109.99918-9-kerneljasonxing@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | net-timestamp: bpf extension to equip applications transparently | expand |
On Tue, 8 Oct 2024 17:51:08 +0800 Jason Xing wrote: > +static bool 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 true; > + > + return false; > +} > + > /* Similar to __sock_recv_timestamp, but does not require an skb */ > void tcp_recv_timestamp(struct msghdr *msg, const struct sock *sk, > struct scm_timestamping_internal *tss) > @@ -2284,6 +2294,9 @@ void tcp_recv_timestamp(struct msghdr *msg, const struct sock *sk, > u32 tsflags = READ_ONCE(sk->sk_tsflags); > bool has_timestamping = false; > > + if (tcp_bpf_recv_timestamp(sk, tss)) net/ipv4/tcp.c:2297:29: error: passing 'const struct sock *' to parameter of type 'struct sock *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers] 2297 | if (tcp_bpf_recv_timestamp(sk, tss)) | ^~ net/ipv4/tcp.c:2279:49: note: passing argument to parameter 'sk' here 2279 | static bool tcp_bpf_recv_timestamp(struct sock *sk, struct scm_timestamping_internal *tss) | ^
On Wed, Oct 9, 2024 at 8:22 AM Jakub Kicinski <kuba@kernel.org> wrote: > > On Tue, 8 Oct 2024 17:51:08 +0800 Jason Xing wrote: > > +static bool 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 true; > > + > > + return false; > > +} > > + > > /* Similar to __sock_recv_timestamp, but does not require an skb */ > > void tcp_recv_timestamp(struct msghdr *msg, const struct sock *sk, > > struct scm_timestamping_internal *tss) > > @@ -2284,6 +2294,9 @@ void tcp_recv_timestamp(struct msghdr *msg, const struct sock *sk, > > u32 tsflags = READ_ONCE(sk->sk_tsflags); > > bool has_timestamping = false; > > > > + if (tcp_bpf_recv_timestamp(sk, tss)) > > net/ipv4/tcp.c:2297:29: error: passing 'const struct sock *' to parameter of type 'struct sock *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers] > 2297 | if (tcp_bpf_recv_timestamp(sk, tss)) > | ^~ > net/ipv4/tcp.c:2279:49: note: passing argument to parameter 'sk' here > 2279 | static bool tcp_bpf_recv_timestamp(struct sock *sk, struct scm_timestamping_internal *tss) > | ^ Thanks, I will fix this.
Hi Jason, kernel test robot noticed the following build warnings: [auto build test WARNING on net-next/main] url: https://github.com/intel-lab-lkp/linux/commits/Jason-Xing/net-timestamp-add-bpf-infrastructure-to-allow-exposing-more-information-later/20241008-175458 base: net-next/main patch link: https://lore.kernel.org/r/20241008095109.99918-9-kerneljasonxing%40gmail.com patch subject: [PATCH net-next 8/9] net-timestamp: add bpf framework for rx timestamps config: openrisc-defconfig (https://download.01.org/0day-ci/archive/20241009/202410090912.5vZnvozX-lkp@intel.com/config) compiler: or1k-linux-gcc (GCC) 14.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241009/202410090912.5vZnvozX-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202410090912.5vZnvozX-lkp@intel.com/ All warnings (new ones prefixed by >>): net/ipv4/tcp.c: In function 'tcp_recv_timestamp': >> net/ipv4/tcp.c:2297:36: warning: passing argument 1 of 'tcp_bpf_recv_timestamp' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 2297 | if (tcp_bpf_recv_timestamp(sk, tss)) | ^~ net/ipv4/tcp.c:2279:49: note: expected 'struct sock *' but argument is of type 'const struct sock *' 2279 | static bool tcp_bpf_recv_timestamp(struct sock *sk, struct scm_timestamping_internal *tss) | ~~~~~~~~~~~~~^~ vim +2297 net/ipv4/tcp.c 2288 2289 /* Similar to __sock_recv_timestamp, but does not require an skb */ 2290 void tcp_recv_timestamp(struct msghdr *msg, const struct sock *sk, 2291 struct scm_timestamping_internal *tss) 2292 { 2293 int new_tstamp = sock_flag(sk, SOCK_TSTAMP_NEW); 2294 u32 tsflags = READ_ONCE(sk->sk_tsflags); 2295 bool has_timestamping = false; 2296 > 2297 if (tcp_bpf_recv_timestamp(sk, tss)) 2298 return; 2299 2300 if (tss->ts[0].tv_sec || tss->ts[0].tv_nsec) { 2301 if (sock_flag(sk, SOCK_RCVTSTAMP)) { 2302 if (sock_flag(sk, SOCK_RCVTSTAMPNS)) { 2303 if (new_tstamp) { 2304 struct __kernel_timespec kts = { 2305 .tv_sec = tss->ts[0].tv_sec, 2306 .tv_nsec = tss->ts[0].tv_nsec, 2307 }; 2308 put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMPNS_NEW, 2309 sizeof(kts), &kts); 2310 } else { 2311 struct __kernel_old_timespec ts_old = { 2312 .tv_sec = tss->ts[0].tv_sec, 2313 .tv_nsec = tss->ts[0].tv_nsec, 2314 }; 2315 put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMPNS_OLD, 2316 sizeof(ts_old), &ts_old); 2317 } 2318 } else { 2319 if (new_tstamp) { 2320 struct __kernel_sock_timeval stv = { 2321 .tv_sec = tss->ts[0].tv_sec, 2322 .tv_usec = tss->ts[0].tv_nsec / 1000, 2323 }; 2324 put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMP_NEW, 2325 sizeof(stv), &stv); 2326 } else { 2327 struct __kernel_old_timeval tv = { 2328 .tv_sec = tss->ts[0].tv_sec, 2329 .tv_usec = tss->ts[0].tv_nsec / 1000, 2330 }; 2331 put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMP_OLD, 2332 sizeof(tv), &tv); 2333 } 2334 } 2335 } 2336 2337 if (tsflags & SOF_TIMESTAMPING_SOFTWARE && 2338 (tsflags & SOF_TIMESTAMPING_RX_SOFTWARE || 2339 !(tsflags & SOF_TIMESTAMPING_OPT_RX_FILTER))) 2340 has_timestamping = true; 2341 else 2342 tss->ts[0] = (struct timespec64) {0}; 2343 } 2344 2345 if (tss->ts[2].tv_sec || tss->ts[2].tv_nsec) { 2346 if (tsflags & SOF_TIMESTAMPING_RAW_HARDWARE && 2347 (tsflags & SOF_TIMESTAMPING_RX_HARDWARE || 2348 !(tsflags & SOF_TIMESTAMPING_OPT_RX_FILTER))) 2349 has_timestamping = true; 2350 else 2351 tss->ts[2] = (struct timespec64) {0}; 2352 } 2353 2354 if (has_timestamping) { 2355 tss->ts[1] = (struct timespec64) {0}; 2356 if (sock_flag(sk, SOCK_TSTAMP_NEW)) 2357 put_cmsg_scm_timestamping64(msg, tss); 2358 else 2359 put_cmsg_scm_timestamping(msg, tss); 2360 } 2361 } 2362
Hi Jason, kernel test robot noticed the following build errors: [auto build test ERROR on net-next/main] url: https://github.com/intel-lab-lkp/linux/commits/Jason-Xing/net-timestamp-add-bpf-infrastructure-to-allow-exposing-more-information-later/20241008-175458 base: net-next/main patch link: https://lore.kernel.org/r/20241008095109.99918-9-kerneljasonxing%40gmail.com patch subject: [PATCH net-next 8/9] net-timestamp: add bpf framework for rx timestamps config: arm-exynos_defconfig (https://download.01.org/0day-ci/archive/20241009/202410091146.2OM6QWPq-lkp@intel.com/config) compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241009/202410091146.2OM6QWPq-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202410091146.2OM6QWPq-lkp@intel.com/ All errors (new ones prefixed by >>): >> net/ipv4/tcp.c:2297:29: error: passing 'const struct sock *' to parameter of type 'struct sock *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers] 2297 | if (tcp_bpf_recv_timestamp(sk, tss)) | ^~ net/ipv4/tcp.c:2279:49: note: passing argument to parameter 'sk' here 2279 | static bool tcp_bpf_recv_timestamp(struct sock *sk, struct scm_timestamping_internal *tss) | ^ 1 error generated. vim +2297 net/ipv4/tcp.c 2288 2289 /* Similar to __sock_recv_timestamp, but does not require an skb */ 2290 void tcp_recv_timestamp(struct msghdr *msg, const struct sock *sk, 2291 struct scm_timestamping_internal *tss) 2292 { 2293 int new_tstamp = sock_flag(sk, SOCK_TSTAMP_NEW); 2294 u32 tsflags = READ_ONCE(sk->sk_tsflags); 2295 bool has_timestamping = false; 2296 > 2297 if (tcp_bpf_recv_timestamp(sk, tss)) 2298 return; 2299 2300 if (tss->ts[0].tv_sec || tss->ts[0].tv_nsec) { 2301 if (sock_flag(sk, SOCK_RCVTSTAMP)) { 2302 if (sock_flag(sk, SOCK_RCVTSTAMPNS)) { 2303 if (new_tstamp) { 2304 struct __kernel_timespec kts = { 2305 .tv_sec = tss->ts[0].tv_sec, 2306 .tv_nsec = tss->ts[0].tv_nsec, 2307 }; 2308 put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMPNS_NEW, 2309 sizeof(kts), &kts); 2310 } else { 2311 struct __kernel_old_timespec ts_old = { 2312 .tv_sec = tss->ts[0].tv_sec, 2313 .tv_nsec = tss->ts[0].tv_nsec, 2314 }; 2315 put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMPNS_OLD, 2316 sizeof(ts_old), &ts_old); 2317 } 2318 } else { 2319 if (new_tstamp) { 2320 struct __kernel_sock_timeval stv = { 2321 .tv_sec = tss->ts[0].tv_sec, 2322 .tv_usec = tss->ts[0].tv_nsec / 1000, 2323 }; 2324 put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMP_NEW, 2325 sizeof(stv), &stv); 2326 } else { 2327 struct __kernel_old_timeval tv = { 2328 .tv_sec = tss->ts[0].tv_sec, 2329 .tv_usec = tss->ts[0].tv_nsec / 1000, 2330 }; 2331 put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMP_OLD, 2332 sizeof(tv), &tv); 2333 } 2334 } 2335 } 2336 2337 if (tsflags & SOF_TIMESTAMPING_SOFTWARE && 2338 (tsflags & SOF_TIMESTAMPING_RX_SOFTWARE || 2339 !(tsflags & SOF_TIMESTAMPING_OPT_RX_FILTER))) 2340 has_timestamping = true; 2341 else 2342 tss->ts[0] = (struct timespec64) {0}; 2343 } 2344 2345 if (tss->ts[2].tv_sec || tss->ts[2].tv_nsec) { 2346 if (tsflags & SOF_TIMESTAMPING_RAW_HARDWARE && 2347 (tsflags & SOF_TIMESTAMPING_RX_HARDWARE || 2348 !(tsflags & SOF_TIMESTAMPING_OPT_RX_FILTER))) 2349 has_timestamping = true; 2350 else 2351 tss->ts[2] = (struct timespec64) {0}; 2352 } 2353 2354 if (has_timestamping) { 2355 tss->ts[1] = (struct timespec64) {0}; 2356 if (sock_flag(sk, SOCK_TSTAMP_NEW)) 2357 put_cmsg_scm_timestamping64(msg, tss); 2358 else 2359 put_cmsg_scm_timestamping(msg, tss); 2360 } 2361 } 2362
Hi Jason, kernel test robot noticed the following build warnings: [auto build test WARNING on net-next/main] url: https://github.com/intel-lab-lkp/linux/commits/Jason-Xing/net-timestamp-add-bpf-infrastructure-to-allow-exposing-more-information-later/20241008-175458 base: net-next/main patch link: https://lore.kernel.org/r/20241008095109.99918-9-kerneljasonxing%40gmail.com patch subject: [PATCH net-next 8/9] net-timestamp: add bpf framework for rx timestamps config: x86_64-randconfig-122-20241009 (https://download.01.org/0day-ci/archive/20241009/202410091245.zCD0FszC-lkp@intel.com/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241009/202410091245.zCD0FszC-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202410091245.zCD0FszC-lkp@intel.com/ sparse warnings: (new ones prefixed by >>) >> net/ipv4/tcp.c:2297:36: sparse: sparse: incorrect type in argument 1 (different modifiers) @@ expected struct sock *sk @@ got struct sock const *sk @@ net/ipv4/tcp.c:2297:36: sparse: expected struct sock *sk net/ipv4/tcp.c:2297:36: sparse: got struct sock const *sk vim +2297 net/ipv4/tcp.c 2288 2289 /* Similar to __sock_recv_timestamp, but does not require an skb */ 2290 void tcp_recv_timestamp(struct msghdr *msg, const struct sock *sk, 2291 struct scm_timestamping_internal *tss) 2292 { 2293 int new_tstamp = sock_flag(sk, SOCK_TSTAMP_NEW); 2294 u32 tsflags = READ_ONCE(sk->sk_tsflags); 2295 bool has_timestamping = false; 2296 > 2297 if (tcp_bpf_recv_timestamp(sk, tss)) 2298 return; 2299 2300 if (tss->ts[0].tv_sec || tss->ts[0].tv_nsec) { 2301 if (sock_flag(sk, SOCK_RCVTSTAMP)) { 2302 if (sock_flag(sk, SOCK_RCVTSTAMPNS)) { 2303 if (new_tstamp) { 2304 struct __kernel_timespec kts = { 2305 .tv_sec = tss->ts[0].tv_sec, 2306 .tv_nsec = tss->ts[0].tv_nsec, 2307 }; 2308 put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMPNS_NEW, 2309 sizeof(kts), &kts); 2310 } else { 2311 struct __kernel_old_timespec ts_old = { 2312 .tv_sec = tss->ts[0].tv_sec, 2313 .tv_nsec = tss->ts[0].tv_nsec, 2314 }; 2315 put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMPNS_OLD, 2316 sizeof(ts_old), &ts_old); 2317 } 2318 } else { 2319 if (new_tstamp) { 2320 struct __kernel_sock_timeval stv = { 2321 .tv_sec = tss->ts[0].tv_sec, 2322 .tv_usec = tss->ts[0].tv_nsec / 1000, 2323 }; 2324 put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMP_NEW, 2325 sizeof(stv), &stv); 2326 } else { 2327 struct __kernel_old_timeval tv = { 2328 .tv_sec = tss->ts[0].tv_sec, 2329 .tv_usec = tss->ts[0].tv_nsec / 1000, 2330 }; 2331 put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMP_OLD, 2332 sizeof(tv), &tv); 2333 } 2334 } 2335 } 2336 2337 if (tsflags & SOF_TIMESTAMPING_SOFTWARE && 2338 (tsflags & SOF_TIMESTAMPING_RX_SOFTWARE || 2339 !(tsflags & SOF_TIMESTAMPING_OPT_RX_FILTER))) 2340 has_timestamping = true; 2341 else 2342 tss->ts[0] = (struct timespec64) {0}; 2343 } 2344 2345 if (tss->ts[2].tv_sec || tss->ts[2].tv_nsec) { 2346 if (tsflags & SOF_TIMESTAMPING_RAW_HARDWARE && 2347 (tsflags & SOF_TIMESTAMPING_RX_HARDWARE || 2348 !(tsflags & SOF_TIMESTAMPING_OPT_RX_FILTER))) 2349 has_timestamping = true; 2350 else 2351 tss->ts[2] = (struct timespec64) {0}; 2352 } 2353 2354 if (has_timestamping) { 2355 tss->ts[1] = (struct timespec64) {0}; 2356 if (sock_flag(sk, SOCK_TSTAMP_NEW)) 2357 put_cmsg_scm_timestamping64(msg, tss); 2358 else 2359 put_cmsg_scm_timestamping(msg, tss); 2360 } 2361 } 2362
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/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 6bf3f2892776..3c28d74d14ea 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/ipv4/tcp.c b/net/ipv4/tcp.c index 1d52640f9ff4..938e2bff4fa6 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2276,6 +2276,16 @@ static int tcp_zerocopy_receive(struct sock *sk, } #endif +static bool 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 true; + + return false; +} + /* Similar to __sock_recv_timestamp, but does not require an skb */ void tcp_recv_timestamp(struct msghdr *msg, const struct sock *sk, struct scm_timestamping_internal *tss) @@ -2284,6 +2294,9 @@ void tcp_recv_timestamp(struct msghdr *msg, const struct sock *sk, u32 tsflags = READ_ONCE(sk->sk_tsflags); bool has_timestamping = false; + if (tcp_bpf_recv_timestamp(sk, tss)) + return; + if (tss->ts[0].tv_sec || tss->ts[0].tv_nsec) { if (sock_flag(sk, SOCK_RCVTSTAMP)) { if (sock_flag(sk, SOCK_RCVTSTAMPNS)) { diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index d3bf538846da..ff17cd820bde 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -6902,8 +6902,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.