[PATCH bpf-next v5 0/4] bpf: support to track BPF_JNE

2023-12-19 Thread Menglong Dong
tment to the crafted cases that we added in the 2nd patch - add the 3rd patch Changes since v2: - fix a typo in the subject of the 1st patch - add some comments to the 1st patch, as Eduard advised - add some cases to the "crafted_cases" Changes since v1: - simplify the code in the

[PATCH bpf-next v5 1/4] bpf: make the verifier tracks the "not equal" for regs

2023-12-19 Thread Menglong Dong
lthrough(FALSE) branch, the dst_reg will not be handled, which makes the [min, max] for a is [0, 99], not [1, 99]. For BPF_JNE, we can reduce the range of the dst reg if the src reg is a const and is exactly the edge of the dst reg. Signed-off-by: Menglong Dong Acked-by: Andrii Nakryiko Acked-by: Sh

[PATCH bpf-next v5 2/4] selftests/bpf: remove reduplicated s32 casting in "crafted_cases"

2023-12-19 Thread Menglong Dong
The "S32_MIN" is already defined with s32 casting, so there is no need to do it again. Signed-off-by: Menglong Dong --- tools/testing/selftests/bpf/prog_tests/reg_bounds.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/bpf/

[PATCH bpf-next v5 3/4] selftests/bpf: activate the OP_NE logic in range_cond()

2023-12-19 Thread Menglong Dong
are mainly used to test the edge of the src reg and dst reg. All reg bounds testings has passed in the SLOW_TESTS mode: $ export SLOW_TESTS=1 && ./test_progs -t reg_bounds -j Summary: 65/18959832 PASSED, 0 SKIPPED, 0 FAILED Signed-off-by: Menglong Dong --- v5: - add "{U32, U32,

[PATCH bpf-next v5 4/4] selftests/bpf: add testcase to verifier_bounds.c for BPF_JNE

2023-12-19 Thread Menglong Dong
t; 0" here will be optimized to "a != 0" */ if (a > 0) { /* now the range of a should be [1, 7] */ bpf_skb_store_bytes(skb, 0, &b, a, 0); } Signed-off-by: Menglong Dong --- v5: - add some comments to the function that we add - add reg_not_equal_const() ---

[PATCH bpf-next 0/2] bpf: add csum/ip_summed fields to __sk_buff

2023-12-29 Thread Menglong Dong
n't need to call bpf helpers for csum update any more. In the second patch, we add some testcases for the read/write testing for skb->csum and skb->ip_summed. If this series is acceptable, we can define the inlined functions for csum update in libbpf in the next step. Menglong Do

[PATCH bpf-next 1/2] bpf: add csum/ip_summed fields to __sk_buff

2023-12-29 Thread Menglong Dong
f, which are much more efficient. Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 2 ++ include/uapi/linux/bpf.h | 2 ++ net/core/filter.c | 22 ++ tools/include/uapi/linux/bpf.h | 2 ++ 4 files changed, 28 insertions(+) diff --git a/includ

[PATCH bpf-next 2/2] testcases/bpf: add testcases for skb->csum to ctx_skb.c

2023-12-29 Thread Menglong Dong
The testcases for read/write access of skb->csum is added to ctx_skb.c. And the read access testing for skb->ip_summed is also added. Signed-off-by: Menglong Dong --- .../testing/selftests/bpf/verifier/ctx_skb.c | 43 +++ 1 file changed, 43 insertions(+) diff --git a

Re: [PATCH bpf-next 0/2] bpf: add csum/ip_summed fields to __sk_buff

2024-01-02 Thread Menglong Dong
On Wed, Jan 3, 2024 at 8:52 AM Martin KaFai Lau wrote: > > On 1/2/24 10:11 AM, Stanislav Fomichev wrote: > > On 12/29, Menglong Dong wrote: > >> For now, we have to call some helpers when we need to update the csum, > >> such as bpf_l4_csum_replace, bpf_l3_csum_r

Re: [PATCH bpf-next 0/2] bpf: add csum/ip_summed fields to __sk_buff

2024-01-02 Thread Menglong Dong
On Wed, Jan 3, 2024 at 11:55 AM Yonghong Song wrote: > > > On 1/2/24 6:54 PM, Menglong Dong wrote: > > On Wed, Jan 3, 2024 at 8:52 AM Martin KaFai Lau > > wrote: > >> On 1/2/24 10:11 AM, Stanislav Fomichev wrote: > >>> On 12/29, Menglong Dong wrote: &g

[PATCH bpf-next 0/5] bpf: make tracing program support multi-attach

2024-02-19 Thread Menglong Dong
roduce the function libbpf_find_kernel_btf_id() to libbpf to find the btf type id of the kernel function, and this function will be used in the next commit. In the 5th patch, we add the testcases for this series. Menglong Dong (5): bpf: tracing: add support to record and check the accessed

[PATCH bpf-next 1/5] bpf: tracing: add support to record and check the accessed args

2024-02-19 Thread Menglong Dong
s function will be used in the following commit. Signed-off-by: Menglong Dong --- include/linux/bpf.h | 4 ++ kernel/bpf/btf.c| 121 2 files changed, 125 insertions(+) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index c7aa99b44dbd..02

[PATCH bpf-next 2/5] bpf: tracing: support to attach program to multi hooks

2024-02-19 Thread Menglong Dong
as the origin target. Signed-off-by: Menglong Dong --- include/linux/bpf.h | 2 + include/uapi/linux/bpf.h | 1 + kernel/bpf/syscall.c | 117 +++ 3 files changed, 98 insertions(+), 22 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.

[PATCH bpf-next 3/5] libbpf: allow to set coookie when target_btf_id is set in bpf_link_create

2024-02-19 Thread Menglong Dong
As now we support to attach the tracing program to multiple target, we can set the bpf cookie even if the target btf id is offered in bpf_link_create(). Signed-off-by: Menglong Dong --- tools/lib/bpf/bpf.c | 17 - 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a

[PATCH bpf-next 4/5] libbpf: add the function libbpf_find_kernel_btf_id()

2024-02-19 Thread Menglong Dong
Add new function libbpf_find_kernel_btf_id() to find the btf type id of the kernel, including vmlinux and modules. Signed-off-by: Menglong Dong --- tools/lib/bpf/libbpf.c | 83 tools/lib/bpf/libbpf.h | 3 ++ tools/lib/bpf/libbpf.map | 1 + 3 files

[PATCH bpf-next 5/5] selftests/bpf: add test cases for multiple attach of tracing program

2024-02-19 Thread Menglong Dong
In this commit, we add the testcases for multiple attaching of tracing, include FENTRY, FEXIT, MODIFY_RETURN. Signed-off-by: Menglong Dong --- .../selftests/bpf/bpf_testmod/bpf_testmod.c | 49 ++ .../bpf/prog_tests/tracing_multi_attach.c | 155 ++ .../selftests/bpf

[PATCH bpf-next v2 0/9] bpf: make tracing program support multi-link

2024-03-11 Thread Menglong Dong
this series. Changes since v1: - According to the advice of Alexei, introduce multi-link for tracing instead of attaching a tracing program to multiple trampolines with creating multi instance of bpf_link. Menglong Dong (9): bpf: tracing: add support to record and check the accessed args

[PATCH bpf-next v2 1/9] bpf: tracing: add support to record and check the accessed args

2024-03-11 Thread Menglong Dong
s function will be used in the following commit. Signed-off-by: Menglong Dong --- include/linux/bpf.h | 4 ++ kernel/bpf/btf.c| 108 +++- 2 files changed, 110 insertions(+), 2 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 95

[PATCH bpf-next v2 2/9] bpf: refactor the modules_array to ptr_array

2024-03-11 Thread Menglong Dong
t sure where to add it now, and let's move it to kernel/bpf/syscall.c for now. Signed-off-by: Menglong Dong --- include/linux/bpf.h | 10 + kernel/bpf/syscall.c | 37 +++ kernel/trace/bpf_trace.c | 48 ++--

[PATCH bpf-next v2 3/9] bpf: trampoline: introduce struct bpf_tramp_link_conn

2024-03-11 Thread Menglong Dong
be the bridge between bpf_tramp_link and trampoline. And we also chang the type of links in struct bpf_tramp_links to struct bpf_tramp_link_conn. Signed-off-by: Menglong Dong --- arch/arm64/net/bpf_jit_comp.c | 4 ++-- arch/riscv/net/bpf_jit_comp64.c | 4 ++-- arch/s390/net/bpf_jit_comp.c|

[PATCH bpf-next v2 4/9] bpf: trampoline: introduce bpf_tramp_multi_link

2024-03-11 Thread Menglong Dong
Introduce the struct bpf_tramp_multi_link, which is used to attach a bpf_link to multi trampoline. Meanwhile, introduce corresponding function bpf_trampoline_multi_{link,unlink}_prog. Signed-off-by: Menglong Dong --- include/linux/bpf.h | 14 kernel/bpf/trampoline.c | 47

[PATCH bpf-next v2 5/9] bpf: verifier: add btf to the function args of bpf_check_attach_target

2024-03-11 Thread Menglong Dong
Add target btf to the function args of bpf_check_attach_target(), then the caller can specify the btf to check. Signed-off-by: Menglong Dong --- include/linux/bpf_verifier.h | 1 + kernel/bpf/syscall.c | 6 -- kernel/bpf/trampoline.c | 1 + kernel/bpf/verifier.c| 8

[PATCH bpf-next v2 6/9] bpf: tracing: add multi-link support

2024-03-11 Thread Menglong Dong
g loading, the first target is used for verification by the verifer. And during attaching, we check the consistency of all the targets with the target that we loaded, which is the first target. Signed-off-by: Menglong Dong --- include/linux/bpf.h| 11 + include/linux/bpf_types.h |

[PATCH bpf-next v2 7/9] libbpf: don't free btf if program of multi-link tracing existing

2024-03-11 Thread Menglong Dong
grams of the type multi-link tracing exist. Meanwhile, introduce the new api bpf_object__free_btf() to manually free the btfs after attaching. Signed-off-by: Menglong Dong --- tools/lib/bpf/libbpf.c | 47 ++-- tools/lib/bpf/libbpf.h | 2 ++ tools/li

[PATCH bpf-next v2 8/9] libbpf: add support for the multi-link of tracing

2024-03-11 Thread Menglong Dong
Add support for the attach types of: BPF_TRACE_FENTRY_MULTI BPF_TRACE_FEXIT_MULTI BPF_MODIFY_RETURN_MULTI Signed-off-by: Menglong Dong --- tools/bpf/bpftool/common.c | 3 + tools/lib/bpf/bpf.c| 10 +++ tools/lib/bpf/bpf.h| 6 ++ tools/lib/bpf/libbpf.c | 168

[PATCH bpf-next v2 9/9] selftests/bpf: add testcases for multi-link of tracing

2024-03-11 Thread Menglong Dong
In this commit, we add some testcases for the following attach types: BPF_TRACE_FENTRY_MULTI BPF_TRACE_FEXIT_MULTI BPF_MODIFY_RETURN_MULTI Signed-off-by: Menglong Dong --- net/bpf/test_run.c| 3 + .../selftests/bpf/bpf_testmod/bpf_testmod.c | 49 .../bpf