Re: [selftest/bpf] 472547778d: WARNING:at_kernel/bpf/verifier.c:#resolve_pseudo_ldimm64

2020-11-02 Thread Hao Luo
May I ask what's the map that fd 0 is mapped to? IIUC, it looks like the tests (of tracing programs) access the map of fd 0 and the verifier complains the map is not preallocated. I think it's faster just ask here. Thanks, Hao On Thu, Oct 29, 2020 at 1:49 PM Hao Luo wrote: > > S

Re: [selftest/bpf] 472547778d: WARNING:at_kernel/bpf/verifier.c:#resolve_pseudo_ldimm64

2020-10-29 Thread Hao Luo
Sure, let me take a look at it. On Thu, Oct 29, 2020 at 1:43 PM Andrii Nakryiko wrote: > > Hao, > > This seems to be coming from resolve_pseudo_ldimm64(), could you > please take a look? Thanks! > > -- Andrii > > On Thu, Oct 29, 2020 at 5:58 AM kernel test robot wrote: > > > > Greeting, > > > >

Re: Segfault in pahole 1.18 when building kernel 5.9.1 for arm64

2020-10-20 Thread Hao Luo
On Tue, Oct 20, 2020 at 10:10 AM Andrii Nakryiko wrote: > > On Tue, Oct 20, 2020 at 10:05 AM Hao Luo wrote: > > > > Thanks for reporting this and cc'ing me. I forgot to update the error > > messages when renaming the flags. I will send a patch to fix the error &g

Re: Segfault in pahole 1.18 when building kernel 5.9.1 for arm64

2020-10-20 Thread Hao Luo
Thanks for reporting this and cc'ing me. I forgot to update the error messages when renaming the flags. I will send a patch to fix the error message. The commit commit f3d9054ba8ff1df0fc44e507e3a01c0964cabd42 Author: Hao Luo AuthorDate: Wed Jul 8 13:44:10 2020 -0700 btf_encoder:

Re: [PATCH v2] selftests/bpf: Fix test_verifier after introducing resolve_pseudo_ldimm64

2020-10-06 Thread Hao Luo
Ack. Sent one with just deletion. Hao On Tue, Oct 6, 2020 at 7:04 PM Alexei Starovoitov wrote: > > On Tue, Oct 06, 2020 at 06:23:13PM -0700, Hao Luo wrote: > > Commit 4976b718c355 ("bpf: Introduce pseudo_btf_id") switched > > the order of check_subprogs() a

[PATCH v3] selftests/bpf: Fix test_verifier after introducing resolve_pseudo_ldimm64

2020-10-06 Thread Hao Luo
k for subprogs comes first. It's now pointless to validate that half of ldimm64 won't be the last instruction. Tested: # ./test_verifier Summary: 1129 PASSED, 537 SKIPPED, 0 FAILED and the full set of bpf selftests. Fixes: 4976b718c355 ("bpf: Introduce pseudo_btf_id") Sig

[PATCH v2] selftests/bpf: Fix test_verifier after introducing resolve_pseudo_ldimm64

2020-10-06 Thread Hao Luo
k for subprogs comes first. It's now pointless to validate that half of ldimm64 won't be the last instruction. Tested: # ./test_verifier Summary: 1129 PASSED, 537 SKIPPED, 0 FAILED and the full set of bpf selftests. Fixes: 4976b718c355 ("bpf: Introduce pseudo_btf_id") Sig

Re: [PATCH] bpf: Fix test_verifier after introducing resolve_pseudo_ldimm64

2020-10-06 Thread Hao Luo
On Tue, Oct 6, 2020 at 5:43 PM Andrii Nakryiko wrote: > > On Tue, Oct 6, 2020 at 4:45 PM Hao Luo wrote: > > > > Commit 4976b718c355 ("bpf: Introduce pseudo_btf_id") switched > > the order of check_subprogs() and resolve_pseudo_ldimm() in > > the verif

[PATCH] bpf: Fix test_verifier after introducing resolve_pseudo_ldimm64

2020-10-06 Thread Hao Luo
k for subprogs comes first. Fix the expection of the error message. Tested: # ./test_verifier Summary: 1130 PASSED, 538 SKIPPED, 0 FAILED and the full set of bpf selftests. Fixes: 4976b718c355 ("bpf: Introduce pseudo_btf_id") Signed-off-by: Hao Luo --- tools/testing/selftests/bpf/ver

Re: [PATCH bpf-next v4 1/6] bpf: Introduce pseudo_btf_id

2020-10-06 Thread Hao Luo
Ack. Will do. On Tue, Oct 6, 2020 at 12:05 PM Alexei Starovoitov wrote: > > On Tue, Sep 29, 2020 at 4:50 PM Hao Luo wrote: > > > > - ret = replace_map_fd_with_map_ptr(env); > > - if (ret < 0) > > - goto skip_full_check; > > - &g

Re: [PATCH bpf-next v4 0/6] bpf: BTF support for ksyms

2020-10-02 Thread Hao Luo
Thanks, Alexei and Andrii and other reviewers for the comments. It's a pleasure to work with you and contribute to bpf. Hao On Fri, Oct 2, 2020 at 3:16 PM Alexei Starovoitov wrote: > > On Tue, Sep 29, 2020 at 11:48 PM Hao Luo wrote: > > > > Ah, this is the bug in pahole

Re: [PATCH bpf-next v4 0/6] bpf: BTF support for ksyms

2020-09-29 Thread Hao Luo
PM Alexei Starovoitov wrote: > > On Tue, Sep 29, 2020 at 4:50 PM Hao Luo wrote: > > > > v3 -> v4: > > - Rebasing > > - Cast bpf_[per|this]_cpu_ptr's parameter to void __percpu * before > >passing into per_cpu_ptr. > &g

Re: [PATCH bpf-next v3 4/6] bpf: Introduce bpf_per_cpu_ptr()

2020-09-29 Thread Hao Luo
On Mon, Sep 21, 2020 at 11:11 AM Andrii Nakryiko wrote: > > On Thu, Sep 17, 2020 at 12:14 PM Hao Luo wrote: > > > > I need to cast the pointer to "const void __percpu *" before passing > > into per_cpu_ptr. I will update and resend. > > You can try jus

Re: [PATCH bpf-next v3 4/6] bpf: Introduce bpf_per_cpu_ptr()

2020-09-29 Thread Hao Luo
Hi, Andrii, Thanks for taking a look. Sorry for the late reply. Spent some time on rebasing and fixing a build issue in my development environment that started happening in v5.9. On Mon, Sep 21, 2020 at 11:09 AM Andrii Nakryiko wrote: > > On Wed, Sep 16, 2020 at 3:39 PM Hao Luo

[PATCH bpf-next v4 3/6] selftests/bpf: ksyms_btf to test typed ksyms

2020-09-29 Thread Hao Luo
: Hao Luo --- .../testing/selftests/bpf/prog_tests/ksyms.c | 38 -- .../selftests/bpf/prog_tests/ksyms_btf.c | 70 +++ .../selftests/bpf/progs/test_ksyms_btf.c | 23 ++ tools/testing/selftests/bpf/trace_helpers.c | 27 +++ tools/testing/selftests/bpf

[PATCH bpf-next v4 1/6] bpf: Introduce pseudo_btf_id

2020-09-29 Thread Hao Luo
y: Andrii Nakryiko Signed-off-by: Hao Luo --- include/linux/bpf_verifier.h | 7 ++ include/linux/btf.h| 15 include/uapi/linux/bpf.h | 36 +++--- kernel/bpf/btf.c | 15 kernel/bpf/verifier.c | 125 +

[PATCH bpf-next v4 2/6] bpf/libbpf: BTF support for typed ksyms

2020-09-29 Thread Hao Luo
void') will not have such btf_id, but it has the symbol's address (read from kallsyms) and its value is treated as a raw pointer. Acked-by: Andrii Nakryiko Signed-off-by: Hao Luo --- tools/lib/bpf/libbpf.c | 112 - 1 file changed, 99 insertions(

[PATCH bpf-next v4 5/6] bpf: Introducte bpf_this_cpu_ptr()

2020-09-29 Thread Hao Luo
program. Acked-by: Andrii Nakryiko Signed-off-by: Hao Luo --- include/linux/bpf.h| 2 ++ include/uapi/linux/bpf.h | 13 + kernel/bpf/helpers.c | 14 ++ kernel/bpf/verifier.c | 11 --- kernel/trace/bpf_trace.c | 2

[PATCH bpf-next v4 0/6] bpf: BTF support for ksyms

2020-09-29 Thread Hao Luo
or kernel BTF that does not have VARs encoded, the selftests will be skipped. [1] https://git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?id=f3d9054ba8ff1df0fc44e507e3a01c0964cabd42 [2] https://www.spinics.net/lists/dwarves/msg00451.html Hao Luo (6): bpf: Introduce pseudo_btf_id b

[PATCH bpf-next v4 4/6] bpf: Introduce bpf_per_cpu_ptr()

2020-09-29 Thread Hao Luo
-off-by: Hao Luo --- include/linux/bpf.h| 4 +++ include/linux/btf.h| 11 ++ include/uapi/linux/bpf.h | 18 ++ kernel/bpf/btf.c | 10 -- kernel/bpf/helpers.c | 18 ++ kernel/bpf/verifier.c | 64

[PATCH bpf-next v4 6/6] bpf/selftests: Test for bpf_per_cpu_ptr() and bpf_this_cpu_ptr()

2020-09-29 Thread Hao Luo
type PTR_TO_MEM, which also supports direct pointer dereference. Acked-by: Andrii Nakryiko Signed-off-by: Hao Luo --- .../selftests/bpf/prog_tests/ksyms_btf.c | 18 +++ .../selftests/bpf/progs/test_ksyms_btf.c | 32 +++ 2 files changed, 50 insertions(+) diff --git a/

Re: [PATCH bpf-next v3 4/6] bpf: Introduce bpf_per_cpu_ptr()

2020-09-17 Thread Hao Luo
t WARNING on bpf-next/master] > > url: > https://github.com/0day-ci/linux/commits/Hao-Luo/bpf-BTF-support-for-ksyms/20200917-064052 > base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git > master > config: powerpc-randconfig-s032-20200916 (attached as .confi

[PATCH bpf-next v3 3/6] selftests/bpf: ksyms_btf to test typed ksyms

2020-09-16 Thread Hao Luo
Selftests for typed ksyms. Tests two types of ksyms: one is a struct, the other is a plain int. This tests two paths in the kernel. Struct ksyms will be converted into PTR_TO_BTF_ID by the verifier while int typed ksyms will be converted into PTR_TO_MEM. Signed-off-by: Hao Luo --- .../testing

[PATCH bpf-next v3 5/6] bpf: Introduce bpf_this_cpu_ptr()

2020-09-16 Thread Hao Luo
program. Acked-by: Andrii Nakryiko Signed-off-by: Hao Luo --- include/linux/bpf.h| 2 ++ include/uapi/linux/bpf.h | 13 + kernel/bpf/helpers.c | 14 ++ kernel/bpf/verifier.c | 11 --- kernel/trace/bpf_trace.c | 2

[PATCH bpf-next v3 1/6] bpf: Introduce pseudo_btf_id

2020-09-16 Thread Hao Luo
can also read the address of the ksym's corresponding kernel var from kallsyms and use that to fill dst_reg. Therefore, the proper functionality of pseudo_btf_id depends on (1) kallsyms and (2) the encoding of kernel global VARs in pahole, which should be available since pahole v1.18. Sign

[PATCH bpf-next v3 6/6] bpf/selftests: Test for bpf_per_cpu_ptr() and bpf_this_cpu_ptr()

2020-09-16 Thread Hao Luo
type PTR_TO_MEM, which also supports direct pointer dereference. Acked-by: Andrii Nakryiko Signed-off-by: Hao Luo --- .../selftests/bpf/prog_tests/ksyms_btf.c | 18 +++ .../selftests/bpf/progs/test_ksyms_btf.c | 32 +++ 2 files changed, 50 insertions(+) diff --git a/

[PATCH bpf-next v3 4/6] bpf: Introduce bpf_per_cpu_ptr()

2020-09-16 Thread Hao Luo
-off-by: Hao Luo --- include/linux/bpf.h| 4 +++ include/linux/btf.h| 11 ++ include/uapi/linux/bpf.h | 18 ++ kernel/bpf/btf.c | 10 -- kernel/bpf/helpers.c | 18 ++ kernel/bpf/verifier.c | 64

[PATCH bpf-next v3 2/6] bpf/libbpf: BTF support for typed ksyms

2020-09-16 Thread Hao Luo
void') will not have such btf_id, but it has the symbol's address (read from kallsyms) and its value is treated as a raw pointer. Signed-off-by: Hao Luo --- tools/lib/bpf/libbpf.c | 112 - 1 file changed, 99 insertions(+), 13 deletions(-) d

[PATCH bpf-next v3 0/6] bpf: BTF support for ksyms

2020-09-16 Thread Hao Luo
le/pahole.git/commit/?id=f3d9054ba8ff1df0fc44e507e3a01c0964cabd42 [2] https://www.spinics.net/lists/dwarves/msg00451.html Hao Luo (6): bpf: Introduce pseudo_btf_id bpf/libbpf: BTF support for typed ksyms selftests/bpf: ksyms_btf to test typed ksyms bpf: Introduce bpf_per_cpu_ptr() bpf: In

Re: [PATCH bpf-next v2 6/6] bpf/selftests: Test for bpf_per_cpu_ptr() and bpf_this_cpu_ptr()

2020-09-14 Thread Hao Luo
Thanks for taking a look! On Fri, Sep 4, 2020 at 1:15 PM Andrii Nakryiko wrote: > > On Thu, Sep 3, 2020 at 3:35 PM Hao Luo wrote: > > > > Test bpf_per_cpu_ptr() and bpf_this_cpu_ptr(). Test two paths in the > > kernel. If the base pointer points to a struct, the ret

Re: [PATCH bpf-next v2 5/6] bpf: Introduce bpf_this_cpu_ptr()

2020-09-13 Thread Hao Luo
Thanks for taking a look! On Fri, Sep 4, 2020 at 1:09 PM Andrii Nakryiko wrote: > > On Thu, Sep 3, 2020 at 3:35 PM Hao Luo wrote: > > > > Add bpf_this_cpu_ptr() to help access percpu var on this cpu. This > > helper always returns a valid pointer, therefore no need to

Re: [PATCH bpf-next v2 4/6] bpf: Introduce bpf_per_cpu_ptr()

2020-09-13 Thread Hao Luo
Thanks for review, Andrii. One question, should I add bpf_{per, this}_cpu_ptr() to the bpf_base_func_proto() in kernel/bpf/helpers.c? On Fri, Sep 4, 2020 at 1:04 PM Andrii Nakryiko wrote: > > On Thu, Sep 3, 2020 at 3:35 PM Hao Luo wrote: > > > > Add bpf_per_cpu_ptr() to

Re: [PATCH bpf-next v2 3/6] bpf/selftests: ksyms_btf to test typed ksyms

2020-09-13 Thread Hao Luo
Thanks for taking a look, Andrii. On Fri, Sep 4, 2020 at 12:49 PM Andrii Nakryiko wrote: > > On Thu, Sep 3, 2020 at 3:35 PM Hao Luo wrote: > > > > Selftests for typed ksyms. Tests two types of ksyms: one is a struct, > > the other is a plain int. This tests two pat

Re: [PATCH bpf-next v2 2/6] bpf/libbpf: BTF support for typed ksyms

2020-09-13 Thread Hao Luo
Will follow the libbpf logging convention. Thanks for the suggestions. On Fri, Sep 4, 2020 at 12:34 PM Andrii Nakryiko wrote: > > On Thu, Sep 3, 2020 at 3:34 PM Hao Luo wrote: > > > > If a ksym is defined with a type, libbpf will try to find the ksym's btf > > info

Re: [PATCH bpf-next v2 1/6] bpf: Introduce pseudo_btf_id

2020-09-13 Thread Hao Luo
Andrii, Sorry for the late reply. Your suggestions are concrete and helpful. I can apply them in v3. Thanks! Hao On Fri, Sep 4, 2020 at 12:05 PM Andrii Nakryiko wrote: > > On Thu, Sep 3, 2020 at 3:34 PM Hao Luo wrote: > > > > Pseudo_btf_id is a type of ld_imm insn that asso

[PATCH bpf-next v2 3/6] bpf/selftests: ksyms_btf to test typed ksyms

2020-09-03 Thread Hao Luo
Selftests for typed ksyms. Tests two types of ksyms: one is a struct, the other is a plain int. This tests two paths in the kernel. Struct ksyms will be converted into PTR_TO_BTF_ID by the verifier while int typed ksyms will be converted into PTR_TO_MEM. Signed-off-by: Hao Luo --- .../testing

[PATCH bpf-next v2 5/6] bpf: Introduce bpf_this_cpu_ptr()

2020-09-03 Thread Hao Luo
program. Signed-off-by: Hao Luo --- include/linux/bpf.h| 1 + include/uapi/linux/bpf.h | 14 ++ kernel/bpf/verifier.c | 10 +++--- kernel/trace/bpf_trace.c | 14 ++ tools/include/uapi/linux/bpf.h | 14 ++ 5 files changed, 50

[PATCH bpf-next v2 2/6] bpf/libbpf: BTF support for typed ksyms

2020-09-03 Thread Hao Luo
void') will not have such btf_id, but it has the symbol's address (read from kallsyms) and its value is treated as a raw pointer. Signed-off-by: Hao Luo --- tools/lib/bpf/libbpf.c | 116 - 1 file changed, 102 insertions(+), 14 deletions(-) d

[PATCH bpf-next v2 4/6] bpf: Introduce bpf_per_cpu_ptr()

2020-09-03 Thread Hao Luo
-off-by: Hao Luo --- include/linux/bpf.h| 3 ++ include/linux/btf.h| 11 ++ include/uapi/linux/bpf.h | 17 + kernel/bpf/btf.c | 10 -- kernel/bpf/verifier.c | 66 +++--- kernel/trace/bpf_trace.c

[PATCH bpf-next v2 0/6] bpf: BTF support for ksyms

2020-09-03 Thread Hao Luo
dwarves/msg00451.html Hao Luo (6): bpf: Introduce pseudo_btf_id bpf/libbpf: BTF support for typed ksyms bpf/selftests: ksyms_btf to test typed ksyms bpf: Introduce bpf_per_cpu_ptr() bpf: Introduce bpf_this_cpu_ptr() bpf/selftests: Test for bpf_per_cpu_ptr() and bpf_this_cpu_ptr()

[PATCH bpf-next v2 1/6] bpf: Introduce pseudo_btf_id

2020-09-03 Thread Hao Luo
can also read the address of the ksym's corresponding kernel var from kallsyms and use that to fill dst_reg. Therefore, the proper functionality of pseudo_btf_id depends on (1) kallsyms and (2) the encoding of kernel global VARs in pahole, which should be available since pahole v1.18. Sign

[PATCH bpf-next v2 6/6] bpf/selftests: Test for bpf_per_cpu_ptr() and bpf_this_cpu_ptr()

2020-09-03 Thread Hao Luo
type PTR_TO_MEM, which also supports direct pointer dereference. Acked-by: Andrii Nakryiko Signed-off-by: Hao Luo --- .../selftests/bpf/prog_tests/ksyms_btf.c | 10 +++ .../selftests/bpf/progs/test_ksyms_btf.c | 26 +++ 2 files changed, 36 insertions(+) diff --git a/

[PATCH] selftests/bpf: Fix check in global_data_init.

2020-09-03 Thread Hao Luo
The returned value of bpf_object__open_file() should be checked with libbpf_get_error() rather than NULL. This fix prevents test_progs from crash when test_global_data.o is not present. Signed-off-by: Hao Luo --- tools/testing/selftests/bpf/prog_tests/global_data_init.c | 3 ++- 1 file changed

Re: [PATCH] selftests/bpf: Fix check in global_data_init.

2020-09-03 Thread Hao Luo
No problem! Let me update and resend. On Thu, Sep 3, 2020 at 11:50 AM Andrii Nakryiko wrote: > > On Thu, Sep 3, 2020 at 11:02 AM Hao Luo wrote: > > > > The returned value of bpf_object__open_file() should be checked with > > IS_ERR() rather than NULL. This fix makes t

[PATCH] selftests/bpf: Fix check in global_data_init.

2020-09-03 Thread Hao Luo
The returned value of bpf_object__open_file() should be checked with IS_ERR() rather than NULL. This fix makes test_progs not crash when test_global_data.o is not present. Signed-off-by: Hao Luo --- tools/testing/selftests/bpf/prog_tests/global_data_init.c | 2 +- 1 file changed, 1 insertion

Re: [PATCH bpf-next v1 4/8] bpf/libbpf: BTF support for typed ksyms

2020-09-01 Thread Hao Luo
On Tue, Sep 1, 2020 at 4:55 PM Andrii Nakryiko wrote: > > On Tue, Sep 1, 2020 at 1:35 PM Hao Luo wrote: > > > > On Tue, Sep 1, 2020 at 11:11 AM Andrii Nakryiko > > wrote: > > > > > > On Thu, Aug 27, 2020 at 3:29 PM Hao Luo wrote: > > > > &

Re: [PATCH bpf-next v1 4/8] bpf/libbpf: BTF support for typed ksyms

2020-09-01 Thread Hao Luo
On Tue, Sep 1, 2020 at 11:11 AM Andrii Nakryiko wrote: > > On Thu, Aug 27, 2020 at 3:29 PM Hao Luo wrote: > > > > On Fri, Aug 21, 2020 at 3:37 PM Andrii Nakryiko > > wrote: > > > > > > On Wed, Aug 19, 2020 at 3:42 PM Hao Luo wrote: > > > >

Re: [PATCH bpf-next v1 8/8] bpf/selftests: Test for bpf_per_cpu_ptr()

2020-09-01 Thread Hao Luo
On Tue, Sep 1, 2020 at 11:12 AM Andrii Nakryiko wrote: > > On Thu, Aug 27, 2020 at 8:42 PM Hao Luo wrote: > > [...] > > > > > > > > -extern const struct rq runqueues __ksym; /* struct type global var. */ > > > > +extern const struc

Re: [PATCH bpf-next v1 8/8] bpf/selftests: Test for bpf_per_cpu_ptr()

2020-08-27 Thread Hao Luo
Thanks for taking a look! On Fri, Aug 21, 2020 at 8:30 PM Andrii Nakryiko wrote: > > On Wed, Aug 19, 2020 at 3:42 PM Hao Luo wrote: > > > > Test bpf_per_cpu_ptr(). Test two paths in the kernel. If the base > > pointer points to a struct, the returned reg is of type P

Re: [PATCH bpf-next v1 4/8] bpf/libbpf: BTF support for typed ksyms

2020-08-27 Thread Hao Luo
On Fri, Aug 21, 2020 at 3:37 PM Andrii Nakryiko wrote: > > On Wed, Aug 19, 2020 at 3:42 PM Hao Luo wrote: > > > > If a ksym is defined with a type, libbpf will try to find the ksym's btf > > information from kernel btf. If a valid btf entry for the ksym is found, >

Re: [PATCH bpf-next v1 6/8] bpf: Introduce bpf_per_cpu_ptr()

2020-08-24 Thread Hao Luo
On Sat, Aug 22, 2020 at 12:55 AM Andrii Nakryiko wrote: > > On Sat, Aug 22, 2020 at 12:49 AM Hao Luo wrote: > > > > On Fri, Aug 21, 2020 at 8:31 PM Andrii Nakryiko > > wrote: > > > > > > On Fri, Aug 21, 2020 at 8:26 PM Andrii Nakryiko > > >

Re: [PATCH bpf-next v1 1/8] bpf: Introduce pseudo_btf_id

2020-08-24 Thread Hao Luo
Yonghong, An update on this thread. I successfully reproduced this issue on a 8.2.0 gcc compiler, It looks like gcc 4.9 did not have this issue. I was also using clang which did not show this bug. It seems having a DW_AT_specification that refers to another DW_TAG_variable isn't handled in pahole

Re: [PATCH bpf-next v1 6/8] bpf: Introduce bpf_per_cpu_ptr()

2020-08-22 Thread Hao Luo
On Fri, Aug 21, 2020 at 8:31 PM Andrii Nakryiko wrote: > > On Fri, Aug 21, 2020 at 8:26 PM Andrii Nakryiko > wrote: > > > > On Wed, Aug 19, 2020 at 3:42 PM Hao Luo wrote: > > > > > > Add bpf_per_cpu_ptr() to help bpf programs access percpu vars. > >

Re: [PATCH bpf-next v1 5/8] bpf/selftests: ksyms_btf to test typed ksyms

2020-08-22 Thread Hao Luo
On Fri, Aug 21, 2020 at 4:03 PM Andrii Nakryiko wrote: > > On Thu, Aug 20, 2020 at 10:32 AM Yonghong Song wrote: > > > > > > > > On 8/19/20 3:40 PM, Hao Luo wrote: > > > Selftests for typed ksyms. Tests two types of ksyms: one is a struct, > > > t

Re: [PATCH bpf-next v1 3/8] bpf: Introduce help function to validate ksym's type.

2020-08-22 Thread Hao Luo
ublic APIs. Hao On Fri, Aug 21, 2020 at 7:43 PM Andrii Nakryiko wrote: > > On Fri, Aug 21, 2020 at 5:43 PM Hao Luo wrote: > > > > On Fri, Aug 21, 2020 at 2:50 PM Andrii Nakryiko > > wrote: > > > > > > On Thu, Aug 20, 2020 at 10:22 AM Yonghong Song wrote:

Re: [PATCH bpf-next v1 3/8] bpf: Introduce help function to validate ksym's type.

2020-08-21 Thread Hao Luo
On Fri, Aug 21, 2020 at 2:50 PM Andrii Nakryiko wrote: > > On Thu, Aug 20, 2020 at 10:22 AM Yonghong Song wrote: > > > > > > > > On 8/19/20 3:40 PM, Hao Luo wrote: > > > For a ksym to be safely dereferenced and accessed, its type defined in > >

Re: [PATCH bpf-next v1 1/8] bpf: Introduce pseudo_btf_id

2020-08-20 Thread Hao Luo
On Thu, Aug 20, 2020 at 2:53 PM Alexei Starovoitov wrote: > > Why did you choose to do it during main do_check() walk instead of this > pre-pass ? > check_ld_imm() can be called multiple times for the same insn, > so it's faster and less surprising to do it during > replace_map_fd_with_map_ptr()

Re: [PATCH bpf-next v1 1/8] bpf: Introduce pseudo_btf_id

2020-08-20 Thread Hao Luo
Yonghong, Thank you for taking a look. Explicitly cc'ing Arnaldo to see if he has any immediate insights. In the meantime, I'll dedicate time to investigate this issue you found. Thanks, Hao On Thu, Aug 20, 2020 at 8:23 AM Yonghong Song wrote: > > > > On 8/19/20

[PATCH bpf-next v1 2/8] bpf: Propagate BPF_PSEUDO_BTF_ID to uapi headers in /tools

2020-08-19 Thread Hao Luo
Propagate BPF_PSEUDO_BTF_ID from include/linux/uapi/bpf.h to tools/include/linux/uapi/bpf.h. Signed-off-by: Hao Luo --- tools/include/uapi/linux/bpf.h | 38 ++ 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/tools/include/uapi/linux/bpf.h b/tools

[PATCH bpf-next v1 6/8] bpf: Introduce bpf_per_cpu_ptr()

2020-08-19 Thread Hao Luo
Add bpf_per_cpu_ptr() to help bpf programs access percpu vars. bpf_per_cpu_ptr() has the same semantic as per_cpu_ptr() in the kernel except that it may return NULL. This happens when the cpu parameter is out of range. So the caller must check the returned value. Signed-off-by: Hao Luo

[PATCH bpf-next v1 4/8] bpf/libbpf: BTF support for typed ksyms

2020-08-19 Thread Hao Luo
void') will not have such btf_id, but it has the symbol's address (read from kallsyms) and its value is treated as a raw pointer. Signed-off-by: Hao Luo --- tools/lib/bpf/libbpf.c | 130 - 1 file changed, 114 insertions(+), 16 deletions(-) d

[PATCH bpf-next v1 8/8] bpf/selftests: Test for bpf_per_cpu_ptr()

2020-08-19 Thread Hao Luo
also supports direct pointer dereference. Signed-off-by: Hao Luo --- .../testing/selftests/bpf/prog_tests/ksyms_btf.c | 4 .../testing/selftests/bpf/progs/test_ksyms_btf.c | 15 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/prog_

[PATCH bpf-next v1 3/8] bpf: Introduce help function to validate ksym's type.

2020-08-19 Thread Hao Luo
For a ksym to be safely dereferenced and accessed, its type defined in bpf program should basically match its type defined in kernel. Implement a help function for a quick matching, which is used by libbpf when resolving the kernel btf_id of a ksym. Signed-off-by: Hao Luo --- tools/lib/bpf

[PATCH bpf-next v1 7/8] bpf: Propagate bpf_per_cpu_ptr() to /tools

2020-08-19 Thread Hao Luo
Sync tools/include/linux/uapi/bpf.h with include/linux/uapi/bpf.h Signed-off-by: Hao Luo --- tools/include/uapi/linux/bpf.h | 15 +++ 1 file changed, 15 insertions(+) diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 468376f2910b..7e3dfb2bbb86

[PATCH bpf-next v1 5/8] bpf/selftests: ksyms_btf to test typed ksyms

2020-08-19 Thread Hao Luo
Selftests for typed ksyms. Tests two types of ksyms: one is a struct, the other is a plain int. This tests two paths in the kernel. Struct ksyms will be converted into PTR_TO_BTF_ID by the verifier while int typed ksyms will be converted into PTR_TO_MEM. Signed-off-by: Hao Luo --- .../selftests

[PATCH bpf-next v1 0/8] bpf: BTF support for ksyms

2020-08-19 Thread Hao Luo
VAR, its name and type. - Checks in libbpf on type compatibility of ksyms. - Add bpf_per_cpu_ptr() to access kernel percpu vars. Introduced new ARG and RET types for this helper. Hao Luo (8): bpf: Introduce pseudo_btf_id bpf: Propagate BPF_PSEUDO_BTF_ID to uapi headers in /tools bpf: I

[PATCH bpf-next v1 1/8] bpf: Introduce pseudo_btf_id

2020-08-19 Thread Hao Luo
can also read the address of the ksym's corresponding kernel var from kallsyms and use that to fill dst_reg. Therefore, the proper functionality of pseudo_btf_id depends on (1) kallsyms and (2) the encoding of kernel global VARs in pahole, which should be available since pahole v1.18. Sign

Re: [RFC PATCH bpf-next 2/2] selftests/bpf: Test __ksym externs with BTF

2020-07-21 Thread Hao Luo
Ack. Will have that in v2. Hao On Mon, Jul 20, 2020 at 7:37 PM Andrii Nakryiko wrote: > > On Mon, Jul 20, 2020 at 1:28 PM Hao Luo wrote: > > > > > > > > This should ideally look like a real global variable extern: > > > > > > extern const s

Re: [RFC PATCH bpf-next 2/2] selftests/bpf: Test __ksym externs with BTF

2020-07-20 Thread Hao Luo
> > This should ideally look like a real global variable extern: > > extern const struct rq runqueues __ksym; > > > But that's the case for non-per-cpu variables. You didn't seem to > address per-CPU variables in this patch set. How did you intend to > handle that? We should look at a possible BPF

Re: [RFC PATCH bpf-next 1/2] bpf: BTF support for __ksym externs

2020-07-20 Thread Hao Luo
Andrii, Thanks for taking a look at this. You comments are clear, I will fix them in v2. > Also, in the next version, please split kernel part and libbpf part > into separate patches. > Got it. Will do. > I don't think that's the right approach. It can't be the best effort. > It's actually pret

[RFC PATCH bpf-next 2/2] selftests/bpf: Test __ksym externs with BTF

2020-07-15 Thread Hao Luo
Extend ksyms.c selftest to make sure BTF enables direct loads of ksyms. Note that test is done against the kernel btf extended with kernel VARs. Signed-off-by: Hao Luo --- tools/testing/selftests/bpf/prog_tests/ksyms.c | 2 ++ tools/testing/selftests/bpf/progs/test_ksyms.c | 14

[RFC PATCH bpf-next 1/2] bpf: BTF support for __ksym externs

2020-07-15 Thread Hao Luo
o carry the ksym's address (64bits) as well as its btf_id (32bits), pseudo_btf_id uses ld_imm64's both imm and off fields. Signed-off-by: Hao Luo --- include/uapi/linux/bpf.h | 37 +++-- kernel/bpf/verifier.c | 26 +++--- tools/include/ua

[RFC PATCH bpf-next 0/2] BTF support for ksyms

2020-07-15 Thread Hao Luo
pahole changes that encode kernel vars into btf. Hao Luo (2): bpf: BTF support for __ksym externs selftests/bpf: Test __ksym externs with BTF include/uapi/linux/bpf.h | 37 ++ kernel/bpf/verifier.c | 26 -- tools/incl

[PATCH bpf-next v2] selftests/bpf: Switch test_vmlinux to use hrtimer_range_start_ns.

2020-07-01 Thread Hao Luo
l_attach 0 nsec test_vmlinux:PASS:tp 0 nsec test_vmlinux:PASS:raw_tp 0 nsec test_vmlinux:PASS:tp_btf 0 nsec test_vmlinux:PASS:kprobe 0 nsec test_vmlinux:PASS:fentry 0 nsec Signed-off-by: Hao Luo Acked-by: Andrii Nakryiko --- Changelog since v1: - More accurate commit messages tools/testing/self

Re: [PATCH bpf-next] selftests/bpf: Switch test_vmlinux to use hrtimer_range_start_ns.

2020-07-01 Thread Hao Luo
On Tue, Jun 30, 2020 at 7:26 PM Yonghong Song wrote: > > > > On 6/30/20 5:10 PM, Hao Luo wrote: > > Ok, with the help of my colleague Ian Rogers, I think we solved the > > mystery. Clang actually inlined hrtimer_nanosleep() inside > > SyS_nanosleep(), so the

Re: [PATCH bpf-next] selftests/bpf: Switch test_vmlinux to use hrtimer_range_start_ns.

2020-06-30 Thread Hao Luo
quite some time, but clearly overlooked the caller of hrtimer_nanosleep. hrtimer_nanosleep is pretty short and there are many constants, inlining would not be too surprising. Sigh... Hao On Tue, Jun 30, 2020 at 3:48 PM Hao Luo wrote: > > On Tue, Jun 30, 2020 at 1:37 PM Yonghong Song wrote: &

Re: [PATCH bpf-next] selftests/bpf: Switch test_vmlinux to use hrtimer_range_start_ns.

2020-06-30 Thread Hao Luo
On Tue, Jun 30, 2020 at 1:37 PM Yonghong Song wrote: > > On 6/30/20 11:49 AM, Hao Luo wrote: > > The test_vmlinux test uses hrtimer_nanosleep as hook to test tracing > > programs. But it seems Clang may have done an aggressive optimization, > > causing fentry and kp

[PATCH bpf-next] selftests/bpf: Switch test_vmlinux to use hrtimer_range_start_ns.

2020-06-30 Thread Hao Luo
nsec test_vmlinux:PASS:raw_tp 0 nsec test_vmlinux:PASS:tp_btf 0 nsec test_vmlinux:PASS:kprobe 0 nsec test_vmlinux:PASS:fentry 0 nsec Signed-off-by: Hao Luo --- tools/testing/selftests/bpf/progs/test_vmlinux.c | 16 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/testing/self