* [PATCH v2 bpf-next 0/3] bpf: Add hwtstamp field for the sockops prog
@ 2022-11-07 23:04 Martin KaFai Lau
2022-11-07 23:04 ` [PATCH v2 bpf-next 1/3] " Martin KaFai Lau
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Martin KaFai Lau @ 2022-11-07 23:04 UTC (permalink / raw)
To: bpf
Cc: 'Alexei Starovoitov ', 'Andrii Nakryiko ',
'Daniel Borkmann ', netdev, kernel-team
From: Martin KaFai Lau <martin.lau@kernel.org>
The bpf-tc prog has already been able to access the
skb_hwtstamps(skb)->hwtstamp. This set extends the same hwtstamp
access to the sockops prog.
v2:
- Fixed the btf_dump selftest which depends on the
last member of 'struct bpf_sock_ops'.
Martin KaFai Lau (3):
bpf: Add hwtstamp field for the sockops prog
selftests/bpf: Fix incorrect ASSERT in the tcp_hdr_options test
selftests/bpf: Test skops->skb_hwtstamp
include/uapi/linux/bpf.h | 1 +
net/core/filter.c | 39 +++++++++++++++----
tools/include/uapi/linux/bpf.h | 1 +
.../selftests/bpf/prog_tests/btf_dump.c | 4 +-
.../bpf/prog_tests/tcp_hdr_options.c | 6 ++-
.../bpf/progs/test_misc_tcp_hdr_options.c | 4 ++
6 files changed, 43 insertions(+), 12 deletions(-)
--
2.30.2
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v2 bpf-next 1/3] bpf: Add hwtstamp field for the sockops prog 2022-11-07 23:04 [PATCH v2 bpf-next 0/3] bpf: Add hwtstamp field for the sockops prog Martin KaFai Lau @ 2022-11-07 23:04 ` Martin KaFai Lau 2022-11-07 23:04 ` [PATCH v2 bpf-next 2/3] selftests/bpf: Fix incorrect ASSERT in the tcp_hdr_options test Martin KaFai Lau ` (3 subsequent siblings) 4 siblings, 0 replies; 7+ messages in thread From: Martin KaFai Lau @ 2022-11-07 23:04 UTC (permalink / raw) To: bpf Cc: 'Alexei Starovoitov ', 'Andrii Nakryiko ', 'Daniel Borkmann ', netdev, kernel-team From: Martin KaFai Lau <martin.lau@kernel.org> The bpf-tc prog has already been able to access the skb_hwtstamps(skb)->hwtstamp. This patch extends the same hwtstamp access to the sockops prog. In sockops, the skb is also available to the bpf prog during the BPF_SOCK_OPS_PARSE_HDR_OPT_CB event. There is a use case that the hwtstamp will be useful to the sockops prog to better measure the one-way-delay when the sender has put the tx timestamp in the tcp header option. Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org> --- include/uapi/linux/bpf.h | 1 + net/core/filter.c | 39 +++++++++++++++++++++++++++------- tools/include/uapi/linux/bpf.h | 1 + 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 94659f6b3395..fb4c911d2a03 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -6445,6 +6445,7 @@ struct bpf_sock_ops { * the outgoing header has not * been written yet. */ + __u64 skb_hwtstamp; }; /* Definitions for bpf_sock_ops_cb_flags */ diff --git a/net/core/filter.c b/net/core/filter.c index cb3b635e35be..cd667cdbdb26 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -8925,6 +8925,10 @@ static bool sock_ops_is_valid_access(int off, int size, bpf_ctx_record_field_size(info, size_default); return bpf_ctx_narrow_access_ok(off, size, size_default); + case offsetof(struct bpf_sock_ops, skb_hwtstamp): + if (size != sizeof(__u64)) + return false; + break; default: if (size != size_default) return false; @@ -9108,21 +9112,21 @@ static struct bpf_insn *bpf_convert_tstamp_type_read(const struct bpf_insn *si, return insn; } -static struct bpf_insn *bpf_convert_shinfo_access(const struct bpf_insn *si, +static struct bpf_insn *bpf_convert_shinfo_access(__u8 dst_reg, __u8 skb_reg, struct bpf_insn *insn) { /* si->dst_reg = skb_shinfo(SKB); */ #ifdef NET_SKBUFF_DATA_USES_OFFSET *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct sk_buff, end), - BPF_REG_AX, si->src_reg, + BPF_REG_AX, skb_reg, offsetof(struct sk_buff, end)); *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct sk_buff, head), - si->dst_reg, si->src_reg, + dst_reg, skb_reg, offsetof(struct sk_buff, head)); - *insn++ = BPF_ALU64_REG(BPF_ADD, si->dst_reg, BPF_REG_AX); + *insn++ = BPF_ALU64_REG(BPF_ADD, dst_reg, BPF_REG_AX); #else *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct sk_buff, end), - si->dst_reg, si->src_reg, + dst_reg, skb_reg, offsetof(struct sk_buff, end)); #endif @@ -9515,7 +9519,7 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type, break; case offsetof(struct __sk_buff, gso_segs): - insn = bpf_convert_shinfo_access(si, insn); + insn = bpf_convert_shinfo_access(si->dst_reg, si->src_reg, insn); *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct skb_shared_info, gso_segs), si->dst_reg, si->dst_reg, bpf_target_off(struct skb_shared_info, @@ -9523,7 +9527,7 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type, target_size)); break; case offsetof(struct __sk_buff, gso_size): - insn = bpf_convert_shinfo_access(si, insn); + insn = bpf_convert_shinfo_access(si->dst_reg, si->src_reg, insn); *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct skb_shared_info, gso_size), si->dst_reg, si->dst_reg, bpf_target_off(struct skb_shared_info, @@ -9550,7 +9554,7 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type, BUILD_BUG_ON(sizeof_field(struct skb_shared_hwtstamps, hwtstamp) != 8); BUILD_BUG_ON(offsetof(struct skb_shared_hwtstamps, hwtstamp) != 0); - insn = bpf_convert_shinfo_access(si, insn); + insn = bpf_convert_shinfo_access(si->dst_reg, si->src_reg, insn); *insn++ = BPF_LDX_MEM(BPF_DW, si->dst_reg, si->dst_reg, bpf_target_off(struct skb_shared_info, @@ -10400,6 +10404,25 @@ static u32 sock_ops_convert_ctx_access(enum bpf_access_type type, tcp_flags), si->dst_reg, si->dst_reg, off); break; + case offsetof(struct bpf_sock_ops, skb_hwtstamp): { + struct bpf_insn *jmp_on_null_skb; + + *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct bpf_sock_ops_kern, + skb), + si->dst_reg, si->src_reg, + offsetof(struct bpf_sock_ops_kern, + skb)); + /* Reserve one insn to test skb == NULL */ + jmp_on_null_skb = insn++; + insn = bpf_convert_shinfo_access(si->dst_reg, si->dst_reg, insn); + *insn++ = BPF_LDX_MEM(BPF_DW, si->dst_reg, si->dst_reg, + bpf_target_off(struct skb_shared_info, + hwtstamps, 8, + target_size)); + *jmp_on_null_skb = BPF_JMP_IMM(BPF_JEQ, si->dst_reg, 0, + insn - jmp_on_null_skb - 1); + break; + } } return insn - insn_buf; } diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 94659f6b3395..fb4c911d2a03 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -6445,6 +6445,7 @@ struct bpf_sock_ops { * the outgoing header has not * been written yet. */ + __u64 skb_hwtstamp; }; /* Definitions for bpf_sock_ops_cb_flags */ -- 2.30.2 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 bpf-next 2/3] selftests/bpf: Fix incorrect ASSERT in the tcp_hdr_options test 2022-11-07 23:04 [PATCH v2 bpf-next 0/3] bpf: Add hwtstamp field for the sockops prog Martin KaFai Lau 2022-11-07 23:04 ` [PATCH v2 bpf-next 1/3] " Martin KaFai Lau @ 2022-11-07 23:04 ` Martin KaFai Lau 2022-11-08 3:07 ` wangyufen 2022-11-07 23:04 ` [PATCH v2 bpf-next 3/3] selftests/bpf: Test skops->skb_hwtstamp Martin KaFai Lau ` (2 subsequent siblings) 4 siblings, 1 reply; 7+ messages in thread From: Martin KaFai Lau @ 2022-11-07 23:04 UTC (permalink / raw) To: bpf Cc: 'Alexei Starovoitov ', 'Andrii Nakryiko ', 'Daniel Borkmann ', netdev, kernel-team, Wang Yufen From: Martin KaFai Lau <martin.lau@kernel.org> This patch fixes the incorrect ASSERT test in tcp_hdr_options during the CHECK to ASSERT macro cleanup. Cc: Wang Yufen <wangyufen@huawei.com> Fixes: 3082f8cd4ba3 ("selftests/bpf: Convert tcp_hdr_options test to ASSERT_* macros") Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org> --- tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c b/tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c index 617bbce6ef8f..57191773572a 100644 --- a/tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c +++ b/tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c @@ -485,7 +485,7 @@ static void misc(void) goto check_linum; ret = read(sk_fds.passive_fd, recv_msg, sizeof(recv_msg)); - if (ASSERT_EQ(ret, sizeof(send_msg), "read(msg)")) + if (!ASSERT_EQ(ret, sizeof(send_msg), "read(msg)")) goto check_linum; } @@ -539,7 +539,7 @@ void test_tcp_hdr_options(void) goto skel_destroy; cg_fd = test__join_cgroup(CG_NAME); - if (ASSERT_GE(cg_fd, 0, "join_cgroup")) + if (!ASSERT_GE(cg_fd, 0, "join_cgroup")) goto skel_destroy; for (i = 0; i < ARRAY_SIZE(tests); i++) { -- 2.30.2 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 bpf-next 2/3] selftests/bpf: Fix incorrect ASSERT in the tcp_hdr_options test 2022-11-07 23:04 ` [PATCH v2 bpf-next 2/3] selftests/bpf: Fix incorrect ASSERT in the tcp_hdr_options test Martin KaFai Lau @ 2022-11-08 3:07 ` wangyufen 0 siblings, 0 replies; 7+ messages in thread From: wangyufen @ 2022-11-08 3:07 UTC (permalink / raw) To: Martin KaFai Lau, bpf Cc: 'Alexei Starovoitov ', 'Andrii Nakryiko ', 'Daniel Borkmann ', netdev, kernel-team 在 2022/11/8 7:04, Martin KaFai Lau 写道: > From: Martin KaFai Lau <martin.lau@kernel.org> > > This patch fixes the incorrect ASSERT test in tcp_hdr_options during > the CHECK to ASSERT macro cleanup. > > Cc: Wang Yufen <wangyufen@huawei.com> > Fixes: 3082f8cd4ba3 ("selftests/bpf: Convert tcp_hdr_options test to ASSERT_* macros") > Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org> > --- > tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c b/tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c > index 617bbce6ef8f..57191773572a 100644 > --- a/tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c > +++ b/tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c > @@ -485,7 +485,7 @@ static void misc(void) > goto check_linum; > > ret = read(sk_fds.passive_fd, recv_msg, sizeof(recv_msg)); > - if (ASSERT_EQ(ret, sizeof(send_msg), "read(msg)")) > + if (!ASSERT_EQ(ret, sizeof(send_msg), "read(msg)")) > goto check_linum; > } > > @@ -539,7 +539,7 @@ void test_tcp_hdr_options(void) > goto skel_destroy; > > cg_fd = test__join_cgroup(CG_NAME); > - if (ASSERT_GE(cg_fd, 0, "join_cgroup")) > + if (!ASSERT_GE(cg_fd, 0, "join_cgroup")) > goto skel_destroy; > > for (i = 0; i < ARRAY_SIZE(tests); i++) { LGTM. Sorry for the breakage. Acked-by: Wang Yufen <wangyufen@huawei.com> ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 bpf-next 3/3] selftests/bpf: Test skops->skb_hwtstamp 2022-11-07 23:04 [PATCH v2 bpf-next 0/3] bpf: Add hwtstamp field for the sockops prog Martin KaFai Lau 2022-11-07 23:04 ` [PATCH v2 bpf-next 1/3] " Martin KaFai Lau 2022-11-07 23:04 ` [PATCH v2 bpf-next 2/3] selftests/bpf: Fix incorrect ASSERT in the tcp_hdr_options test Martin KaFai Lau @ 2022-11-07 23:04 ` Martin KaFai Lau 2022-11-08 1:03 ` [PATCH v2 bpf-next 0/3] bpf: Add hwtstamp field for the sockops prog Yonghong Song 2022-11-11 21:20 ` patchwork-bot+netdevbpf 4 siblings, 0 replies; 7+ messages in thread From: Martin KaFai Lau @ 2022-11-07 23:04 UTC (permalink / raw) To: bpf Cc: 'Alexei Starovoitov ', 'Andrii Nakryiko ', 'Daniel Borkmann ', netdev, kernel-team From: Martin KaFai Lau <martin.lau@kernel.org> This patch tests reading the skops->skb_hwtstamp field. A local test was also done such that the shinfo hwtstamp was temporary set to a non zero value in the kernel bpf_skops_parse_hdr() and the same value can be read by the skops test. An adjustment is needed to the btf_dump selftest because the changes in the 'struct bpf_sock_ops'. Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org> --- tools/testing/selftests/bpf/prog_tests/btf_dump.c | 4 ++-- tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c | 2 ++ tools/testing/selftests/bpf/progs/test_misc_tcp_hdr_options.c | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/btf_dump.c b/tools/testing/selftests/bpf/prog_tests/btf_dump.c index 24da335482d4..0ba2e8b9c6ac 100644 --- a/tools/testing/selftests/bpf/prog_tests/btf_dump.c +++ b/tools/testing/selftests/bpf/prog_tests/btf_dump.c @@ -791,11 +791,11 @@ static void test_btf_dump_struct_data(struct btf *btf, struct btf_dump *d, TEST_BTF_DUMP_DATA_OVER(btf, d, "struct", str, struct bpf_sock_ops, sizeof(struct bpf_sock_ops) - 1, "(struct bpf_sock_ops){\n\t.op = (__u32)1,\n", - { .op = 1, .skb_tcp_flags = 2}); + { .op = 1, .skb_hwtstamp = 2}); TEST_BTF_DUMP_DATA_OVER(btf, d, "struct", str, struct bpf_sock_ops, sizeof(struct bpf_sock_ops) - 1, "(struct bpf_sock_ops){\n\t.op = (__u32)1,\n", - { .op = 1, .skb_tcp_flags = 0}); + { .op = 1, .skb_hwtstamp = 0}); } static void test_btf_dump_var_data(struct btf *btf, struct btf_dump *d, diff --git a/tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c b/tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c index 57191773572a..5cf85d0f9827 100644 --- a/tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c +++ b/tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c @@ -505,6 +505,8 @@ static void misc(void) ASSERT_EQ(misc_skel->bss->nr_fin, 1, "unexpected nr_fin"); + ASSERT_EQ(misc_skel->bss->nr_hwtstamp, 0, "nr_hwtstamp"); + check_linum: ASSERT_FALSE(check_error_linum(&sk_fds), "check_error_linum"); sk_fds_close(&sk_fds); diff --git a/tools/testing/selftests/bpf/progs/test_misc_tcp_hdr_options.c b/tools/testing/selftests/bpf/progs/test_misc_tcp_hdr_options.c index 2c121c5d66a7..d487153a839d 100644 --- a/tools/testing/selftests/bpf/progs/test_misc_tcp_hdr_options.c +++ b/tools/testing/selftests/bpf/progs/test_misc_tcp_hdr_options.c @@ -27,6 +27,7 @@ unsigned int nr_pure_ack = 0; unsigned int nr_data = 0; unsigned int nr_syn = 0; unsigned int nr_fin = 0; +unsigned int nr_hwtstamp = 0; /* Check the header received from the active side */ static int __check_active_hdr_in(struct bpf_sock_ops *skops, bool check_syn) @@ -146,6 +147,9 @@ static int check_active_hdr_in(struct bpf_sock_ops *skops) if (th->ack && !th->fin && tcp_hdrlen(th) == skops->skb_len) nr_pure_ack++; + if (skops->skb_hwtstamp) + nr_hwtstamp++; + return CG_OK; } -- 2.30.2 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 bpf-next 0/3] bpf: Add hwtstamp field for the sockops prog 2022-11-07 23:04 [PATCH v2 bpf-next 0/3] bpf: Add hwtstamp field for the sockops prog Martin KaFai Lau ` (2 preceding siblings ...) 2022-11-07 23:04 ` [PATCH v2 bpf-next 3/3] selftests/bpf: Test skops->skb_hwtstamp Martin KaFai Lau @ 2022-11-08 1:03 ` Yonghong Song 2022-11-11 21:20 ` patchwork-bot+netdevbpf 4 siblings, 0 replies; 7+ messages in thread From: Yonghong Song @ 2022-11-08 1:03 UTC (permalink / raw) To: Martin KaFai Lau, bpf Cc: 'Alexei Starovoitov ', 'Andrii Nakryiko ', 'Daniel Borkmann ', netdev, kernel-team On 11/7/22 3:04 PM, Martin KaFai Lau wrote: > From: Martin KaFai Lau <martin.lau@kernel.org> > > The bpf-tc prog has already been able to access the > skb_hwtstamps(skb)->hwtstamp. This set extends the same hwtstamp > access to the sockops prog. > > v2: > - Fixed the btf_dump selftest which depends on the > last member of 'struct bpf_sock_ops'. > > Martin KaFai Lau (3): > bpf: Add hwtstamp field for the sockops prog > selftests/bpf: Fix incorrect ASSERT in the tcp_hdr_options test > selftests/bpf: Test skops->skb_hwtstamp > > include/uapi/linux/bpf.h | 1 + > net/core/filter.c | 39 +++++++++++++++---- > tools/include/uapi/linux/bpf.h | 1 + > .../selftests/bpf/prog_tests/btf_dump.c | 4 +- > .../bpf/prog_tests/tcp_hdr_options.c | 6 ++- > .../bpf/progs/test_misc_tcp_hdr_options.c | 4 ++ > 6 files changed, 43 insertions(+), 12 deletions(-) LGTM for the whole series: Acked-by: Yonghong Song <yhs@fb.com> ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 bpf-next 0/3] bpf: Add hwtstamp field for the sockops prog 2022-11-07 23:04 [PATCH v2 bpf-next 0/3] bpf: Add hwtstamp field for the sockops prog Martin KaFai Lau ` (3 preceding siblings ...) 2022-11-08 1:03 ` [PATCH v2 bpf-next 0/3] bpf: Add hwtstamp field for the sockops prog Yonghong Song @ 2022-11-11 21:20 ` patchwork-bot+netdevbpf 4 siblings, 0 replies; 7+ messages in thread From: patchwork-bot+netdevbpf @ 2022-11-11 21:20 UTC (permalink / raw) To: Martin KaFai Lau; +Cc: bpf, ast, andrii, daniel, netdev, kernel-team Hello: This series was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <andrii@kernel.org>: On Mon, 7 Nov 2022 15:04:17 -0800 you wrote: > From: Martin KaFai Lau <martin.lau@kernel.org> > > The bpf-tc prog has already been able to access the > skb_hwtstamps(skb)->hwtstamp. This set extends the same hwtstamp > access to the sockops prog. > > v2: > - Fixed the btf_dump selftest which depends on the > last member of 'struct bpf_sock_ops'. > > [...] Here is the summary with links: - [v2,bpf-next,1/3] bpf: Add hwtstamp field for the sockops prog https://git.kernel.org/bpf/bpf-next/c/9bb053490f1a - [v2,bpf-next,2/3] selftests/bpf: Fix incorrect ASSERT in the tcp_hdr_options test https://git.kernel.org/bpf/bpf-next/c/52929912d7bd - [v2,bpf-next,3/3] selftests/bpf: Test skops->skb_hwtstamp https://git.kernel.org/bpf/bpf-next/c/8cac7a59b252 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:[~2022-11-11 21:20 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-11-07 23:04 [PATCH v2 bpf-next 0/3] bpf: Add hwtstamp field for the sockops prog Martin KaFai Lau 2022-11-07 23:04 ` [PATCH v2 bpf-next 1/3] " Martin KaFai Lau 2022-11-07 23:04 ` [PATCH v2 bpf-next 2/3] selftests/bpf: Fix incorrect ASSERT in the tcp_hdr_options test Martin KaFai Lau 2022-11-08 3:07 ` wangyufen 2022-11-07 23:04 ` [PATCH v2 bpf-next 3/3] selftests/bpf: Test skops->skb_hwtstamp Martin KaFai Lau 2022-11-08 1:03 ` [PATCH v2 bpf-next 0/3] bpf: Add hwtstamp field for the sockops prog Yonghong Song 2022-11-11 21:20 ` 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).