diff mbox series

[bpf-next,2/2] selftests: bpf: Add a new test for bare tracepoints

Message ID 20210111182027.1448538-3-qais.yousef@arm.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series Allow attaching to bare tracepoints | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 11 maintainers not CCed: kafai@fb.com kpsingh@kernel.org yhs@fb.com linux-kselftest@vger.kernel.org songliubraving@fb.com alexandre.torgue@st.com mcoquelin.stm32@gmail.com shuah@kernel.org john.fastabend@gmail.com linux-stm32@st-md-mailman.stormreply.com linux-arm-kernel@lists.infradead.org
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit fail Errors and warnings before: 30 this patch: 17
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch fail CHECK: Alignment should match open parenthesis CHECK: spaces preferred around that '+' (ctx:VxV) ERROR: do not initialise globals to 0 WARNING: line length of 82 exceeds 80 columns
netdev/build_allmodconfig_warn fail Errors and warnings before: 17 this patch: 17
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Qais Yousef Jan. 11, 2021, 6:20 p.m. UTC
Reuse module_attach infrastructure to add a new bare tracepoint to check
we can attach to it as a raw tracepoint.

Signed-off-by: Qais Yousef <qais.yousef@arm.com>
---

Andrii

I was getting the error below when I was trying to run the test.
I had to comment out all related fentry* code to be able to test the raw_tp
stuff. Not sure something I've done wrong or it's broken for some reason.
I was on v5.11-rc2.

	$ sudo ./test_progs -v -t module_attach
	bpf_testmod.ko is already unloaded.
	Loading bpf_testmod.ko...
	Successfully loaded bpf_testmod.ko.
	test_module_attach:PASS:skel_open 0 nsec
	test_module_attach:PASS:set_attach_target 0 nsec
	test_module_attach:PASS:skel_load 0 nsec
	libbpf: prog 'handle_fentry': failed to attach: ERROR: strerror_r(-524)=22
	libbpf: failed to auto-attach program 'handle_fentry': -524
	test_module_attach:FAIL:skel_attach skeleton attach failed: -524
	#58 module_attach:FAIL
	Successfully unloaded bpf_testmod.ko.
	Summary: 0/0 PASSED, 0 SKIPPED, 1 FAILED


 .../selftests/bpf/bpf_testmod/bpf_testmod-events.h     |  6 ++++++
 tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c  |  2 ++
 tools/testing/selftests/bpf/prog_tests/module_attach.c |  1 +
 tools/testing/selftests/bpf/progs/test_module_attach.c | 10 ++++++++++
 4 files changed, 19 insertions(+)

Comments

Andrii Nakryiko Jan. 12, 2021, 7:26 a.m. UTC | #1
On Mon, Jan 11, 2021 at 10:20 AM Qais Yousef <qais.yousef@arm.com> wrote:
>
> Reuse module_attach infrastructure to add a new bare tracepoint to check
> we can attach to it as a raw tracepoint.
>
> Signed-off-by: Qais Yousef <qais.yousef@arm.com>
> ---
>
> Andrii
>
> I was getting the error below when I was trying to run the test.
> I had to comment out all related fentry* code to be able to test the raw_tp
> stuff. Not sure something I've done wrong or it's broken for some reason.
> I was on v5.11-rc2.

Check that you have all the required Kconfig options from
tools/testing/selftests/bpf/config. And also you will need to build
pahole from master, 1.19 doesn't have some fixes that add kernel
module support. I think pahole is the reasons why you have the failure
below.

>
>         $ sudo ./test_progs -v -t module_attach

use -vv when debugging stuff like that with test_progs, it will output
libbpf detailed logs, that often are very helpful

>         bpf_testmod.ko is already unloaded.
>         Loading bpf_testmod.ko...
>         Successfully loaded bpf_testmod.ko.
>         test_module_attach:PASS:skel_open 0 nsec
>         test_module_attach:PASS:set_attach_target 0 nsec
>         test_module_attach:PASS:skel_load 0 nsec
>         libbpf: prog 'handle_fentry': failed to attach: ERROR: strerror_r(-524)=22
>         libbpf: failed to auto-attach program 'handle_fentry': -524
>         test_module_attach:FAIL:skel_attach skeleton attach failed: -524
>         #58 module_attach:FAIL
>         Successfully unloaded bpf_testmod.ko.
>         Summary: 0/0 PASSED, 0 SKIPPED, 1 FAILED
>

But even apart from test failure, there seems to be kernel build
failure. See [0] for what fails in kernel-patches CI.

   [0] https://travis-ci.com/github/kernel-patches/bpf/builds/212730017


>
>  .../selftests/bpf/bpf_testmod/bpf_testmod-events.h     |  6 ++++++
>  tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c  |  2 ++
>  tools/testing/selftests/bpf/prog_tests/module_attach.c |  1 +
>  tools/testing/selftests/bpf/progs/test_module_attach.c | 10 ++++++++++
>  4 files changed, 19 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h
> index b83ea448bc79..e1ada753f10c 100644
> --- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h
> +++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h
> @@ -28,6 +28,12 @@ TRACE_EVENT(bpf_testmod_test_read,
>                   __entry->pid, __entry->comm, __entry->off, __entry->len)
>  );
>
> +/* A bare tracepoint with no event associated with it */
> +DECLARE_TRACE(bpf_testmod_test_read_bare,
> +       TP_PROTO(struct task_struct *task, struct bpf_testmod_test_read_ctx *ctx),
> +       TP_ARGS(task, ctx)
> +);
> +
>  #endif /* _BPF_TESTMOD_EVENTS_H */
>
>  #undef TRACE_INCLUDE_PATH
> diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
> index 2df19d73ca49..d63cebdaca44 100644
> --- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
> +++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
> @@ -22,6 +22,8 @@ bpf_testmod_test_read(struct file *file, struct kobject *kobj,
>         };
>
>         trace_bpf_testmod_test_read(current, &ctx);
> +       ctx.len++;
> +       trace_bpf_testmod_test_read_bare(current, &ctx);

It's kind of boring to have two read tracepoints :) Do you mind adding
a write tracepoint and use bare tracepoint there? You won't need this
ctx.len++ hack as well. Feel free to add identical
bpf_testmod_test_write_ctx (renaming it is more of a pain).

>
>         return -EIO; /* always fail */
>  }
> diff --git a/tools/testing/selftests/bpf/prog_tests/module_attach.c b/tools/testing/selftests/bpf/prog_tests/module_attach.c
> index 50796b651f72..7085a118f38c 100644
> --- a/tools/testing/selftests/bpf/prog_tests/module_attach.c
> +++ b/tools/testing/selftests/bpf/prog_tests/module_attach.c
> @@ -50,6 +50,7 @@ void test_module_attach(void)
>         ASSERT_OK(trigger_module_test_read(READ_SZ), "trigger_read");
>
>         ASSERT_EQ(bss->raw_tp_read_sz, READ_SZ, "raw_tp");
> +       ASSERT_EQ(bss->raw_tp_bare_read_sz, READ_SZ+1, "raw_tp_bare");
>         ASSERT_EQ(bss->tp_btf_read_sz, READ_SZ, "tp_btf");
>         ASSERT_EQ(bss->fentry_read_sz, READ_SZ, "fentry");
>         ASSERT_EQ(bss->fentry_manual_read_sz, READ_SZ, "fentry_manual");
> diff --git a/tools/testing/selftests/bpf/progs/test_module_attach.c b/tools/testing/selftests/bpf/progs/test_module_attach.c
> index efd1e287ac17..08aa157afa1d 100644
> --- a/tools/testing/selftests/bpf/progs/test_module_attach.c
> +++ b/tools/testing/selftests/bpf/progs/test_module_attach.c
> @@ -17,6 +17,16 @@ int BPF_PROG(handle_raw_tp,
>         return 0;
>  }
>
> +__u32 raw_tp_bare_read_sz = 0;
> +
> +SEC("raw_tp/bpf_testmod_test_read_bare")
> +int BPF_PROG(handle_raw_tp_bare,
> +            struct task_struct *task, struct bpf_testmod_test_read_ctx *read_ctx)
> +{
> +       raw_tp_bare_read_sz = BPF_CORE_READ(read_ctx, len);
> +       return 0;
> +}
> +
>  __u32 tp_btf_read_sz = 0;
>
>  SEC("tp_btf/bpf_testmod_test_read")
> --
> 2.25.1
>
Qais Yousef Jan. 12, 2021, 7:27 p.m. UTC | #2
On 01/11/21 23:26, Andrii Nakryiko wrote:
> On Mon, Jan 11, 2021 at 10:20 AM Qais Yousef <qais.yousef@arm.com> wrote:
> >
> > Reuse module_attach infrastructure to add a new bare tracepoint to check
> > we can attach to it as a raw tracepoint.
> >
> > Signed-off-by: Qais Yousef <qais.yousef@arm.com>
> > ---
> >
> > Andrii
> >
> > I was getting the error below when I was trying to run the test.
> > I had to comment out all related fentry* code to be able to test the raw_tp
> > stuff. Not sure something I've done wrong or it's broken for some reason.
> > I was on v5.11-rc2.
> 
> Check that you have all the required Kconfig options from
> tools/testing/selftests/bpf/config. And also you will need to build

Yep I have merged this config snippet using merge_config.sh script.

> pahole from master, 1.19 doesn't have some fixes that add kernel
> module support. I think pahole is the reasons why you have the failure
> below.

I am using pahole 1.19. I have built it from tip of master though.

/trying using v1.19 tag

Still fails the same.

> 
> >
> >         $ sudo ./test_progs -v -t module_attach
> 
> use -vv when debugging stuff like that with test_progs, it will output
> libbpf detailed logs, that often are very helpful

I tried that but it didn't help me. Full output is here

	https://paste.debian.net/1180846

> 
> >         bpf_testmod.ko is already unloaded.
> >         Loading bpf_testmod.ko...
> >         Successfully loaded bpf_testmod.ko.
> >         test_module_attach:PASS:skel_open 0 nsec
> >         test_module_attach:PASS:set_attach_target 0 nsec
> >         test_module_attach:PASS:skel_load 0 nsec
> >         libbpf: prog 'handle_fentry': failed to attach: ERROR: strerror_r(-524)=22
> >         libbpf: failed to auto-attach program 'handle_fentry': -524
> >         test_module_attach:FAIL:skel_attach skeleton attach failed: -524
> >         #58 module_attach:FAIL
> >         Successfully unloaded bpf_testmod.ko.
> >         Summary: 0/0 PASSED, 0 SKIPPED, 1 FAILED
> >
> 
> But even apart from test failure, there seems to be kernel build
> failure. See [0] for what fails in kernel-patches CI.
> 
>    [0] https://travis-ci.com/github/kernel-patches/bpf/builds/212730017

Sorry about that. I did a last minute change because of checkpatch.pl error and
it seems I either forgot to rebuild or missed that the rebuild failed :/

> 
> 
> >
> >  .../selftests/bpf/bpf_testmod/bpf_testmod-events.h     |  6 ++++++
> >  tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c  |  2 ++
> >  tools/testing/selftests/bpf/prog_tests/module_attach.c |  1 +
> >  tools/testing/selftests/bpf/progs/test_module_attach.c | 10 ++++++++++
> >  4 files changed, 19 insertions(+)
> >
> > diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h
> > index b83ea448bc79..e1ada753f10c 100644
> > --- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h
> > +++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h
> > @@ -28,6 +28,12 @@ TRACE_EVENT(bpf_testmod_test_read,
> >                   __entry->pid, __entry->comm, __entry->off, __entry->len)
> >  );
> >
> > +/* A bare tracepoint with no event associated with it */
> > +DECLARE_TRACE(bpf_testmod_test_read_bare,
> > +       TP_PROTO(struct task_struct *task, struct bpf_testmod_test_read_ctx *ctx),
> > +       TP_ARGS(task, ctx)
> > +);
> > +
> >  #endif /* _BPF_TESTMOD_EVENTS_H */
> >
> >  #undef TRACE_INCLUDE_PATH
> > diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
> > index 2df19d73ca49..d63cebdaca44 100644
> > --- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
> > +++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
> > @@ -22,6 +22,8 @@ bpf_testmod_test_read(struct file *file, struct kobject *kobj,
> >         };
> >
> >         trace_bpf_testmod_test_read(current, &ctx);
> > +       ctx.len++;
> > +       trace_bpf_testmod_test_read_bare(current, &ctx);
> 
> It's kind of boring to have two read tracepoints :) Do you mind adding

Hehe boring is good :p

> a write tracepoint and use bare tracepoint there? You won't need this
> ctx.len++ hack as well. Feel free to add identical
> bpf_testmod_test_write_ctx (renaming it is more of a pain).

It was easy to get this done. So I think it should be easy to make it a write
too :)

Thanks

--
Qais Yousef

> 
> >
> >         return -EIO; /* always fail */
> >  }
> > diff --git a/tools/testing/selftests/bpf/prog_tests/module_attach.c b/tools/testing/selftests/bpf/prog_tests/module_attach.c
> > index 50796b651f72..7085a118f38c 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/module_attach.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/module_attach.c
> > @@ -50,6 +50,7 @@ void test_module_attach(void)
> >         ASSERT_OK(trigger_module_test_read(READ_SZ), "trigger_read");
> >
> >         ASSERT_EQ(bss->raw_tp_read_sz, READ_SZ, "raw_tp");
> > +       ASSERT_EQ(bss->raw_tp_bare_read_sz, READ_SZ+1, "raw_tp_bare");
> >         ASSERT_EQ(bss->tp_btf_read_sz, READ_SZ, "tp_btf");
> >         ASSERT_EQ(bss->fentry_read_sz, READ_SZ, "fentry");
> >         ASSERT_EQ(bss->fentry_manual_read_sz, READ_SZ, "fentry_manual");
> > diff --git a/tools/testing/selftests/bpf/progs/test_module_attach.c b/tools/testing/selftests/bpf/progs/test_module_attach.c
> > index efd1e287ac17..08aa157afa1d 100644
> > --- a/tools/testing/selftests/bpf/progs/test_module_attach.c
> > +++ b/tools/testing/selftests/bpf/progs/test_module_attach.c
> > @@ -17,6 +17,16 @@ int BPF_PROG(handle_raw_tp,
> >         return 0;
> >  }
> >
> > +__u32 raw_tp_bare_read_sz = 0;
> > +
> > +SEC("raw_tp/bpf_testmod_test_read_bare")
> > +int BPF_PROG(handle_raw_tp_bare,
> > +            struct task_struct *task, struct bpf_testmod_test_read_ctx *read_ctx)
> > +{
> > +       raw_tp_bare_read_sz = BPF_CORE_READ(read_ctx, len);
> > +       return 0;
> > +}
> > +
> >  __u32 tp_btf_read_sz = 0;
> >
> >  SEC("tp_btf/bpf_testmod_test_read")
> > --
> > 2.25.1
> >
Andrii Nakryiko Jan. 12, 2021, 8:07 p.m. UTC | #3
On Tue, Jan 12, 2021 at 11:27 AM Qais Yousef <qais.yousef@arm.com> wrote:
>
> On 01/11/21 23:26, Andrii Nakryiko wrote:
> > On Mon, Jan 11, 2021 at 10:20 AM Qais Yousef <qais.yousef@arm.com> wrote:
> > >
> > > Reuse module_attach infrastructure to add a new bare tracepoint to check
> > > we can attach to it as a raw tracepoint.
> > >
> > > Signed-off-by: Qais Yousef <qais.yousef@arm.com>
> > > ---
> > >
> > > Andrii
> > >
> > > I was getting the error below when I was trying to run the test.
> > > I had to comment out all related fentry* code to be able to test the raw_tp
> > > stuff. Not sure something I've done wrong or it's broken for some reason.
> > > I was on v5.11-rc2.
> >
> > Check that you have all the required Kconfig options from
> > tools/testing/selftests/bpf/config. And also you will need to build
>
> Yep I have merged this config snippet using merge_config.sh script.
>
> > pahole from master, 1.19 doesn't have some fixes that add kernel
> > module support. I think pahole is the reasons why you have the failure
> > below.
>
> I am using pahole 1.19. I have built it from tip of master though.
>
> /trying using v1.19 tag
>
> Still fails the same.
>
> >
> > >
> > >         $ sudo ./test_progs -v -t module_attach
> >
> > use -vv when debugging stuff like that with test_progs, it will output
> > libbpf detailed logs, that often are very helpful
>
> I tried that but it didn't help me. Full output is here
>
>         https://paste.debian.net/1180846
>

It did help a bit for me to make sure that you have bpf_testmod
properly loaded and its BTF was found, so the problem is somewhere
else. Also, given load succeeded and attach failed with OPNOTSUPP, I
suspect you are missing some of FTRACE configs, which seems to be
missing from selftests's config as well. Check that you have
CONFIG_FTRACE=y and CONFIG_DYNAMIC_FTRACE=y, and you might need some
more. See [0] for a real config we are using to run all tests in
libbpf CI. If you figure out what you were missing, please also
contribute a patch to selftests' config.

  [0] https://github.com/libbpf/libbpf/blob/master/travis-ci/vmtest/configs/latest.config

> >
> > >         bpf_testmod.ko is already unloaded.
> > >         Loading bpf_testmod.ko...
> > >         Successfully loaded bpf_testmod.ko.
> > >         test_module_attach:PASS:skel_open 0 nsec
> > >         test_module_attach:PASS:set_attach_target 0 nsec
> > >         test_module_attach:PASS:skel_load 0 nsec
> > >         libbpf: prog 'handle_fentry': failed to attach: ERROR: strerror_r(-524)=22
> > >         libbpf: failed to auto-attach program 'handle_fentry': -524
> > >         test_module_attach:FAIL:skel_attach skeleton attach failed: -524
> > >         #58 module_attach:FAIL
> > >         Successfully unloaded bpf_testmod.ko.
> > >         Summary: 0/0 PASSED, 0 SKIPPED, 1 FAILED
> > >
> >
> > But even apart from test failure, there seems to be kernel build
> > failure. See [0] for what fails in kernel-patches CI.
> >
> >    [0] https://travis-ci.com/github/kernel-patches/bpf/builds/212730017
>
> Sorry about that. I did a last minute change because of checkpatch.pl error and
> it seems I either forgot to rebuild or missed that the rebuild failed :/
>

no worries, just fix and re-submit. Good that we have CI that caught
this early on.

> >
> >
> > >
> > >  .../selftests/bpf/bpf_testmod/bpf_testmod-events.h     |  6 ++++++
> > >  tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c  |  2 ++
> > >  tools/testing/selftests/bpf/prog_tests/module_attach.c |  1 +
> > >  tools/testing/selftests/bpf/progs/test_module_attach.c | 10 ++++++++++
> > >  4 files changed, 19 insertions(+)
> > >
> > > diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h
> > > index b83ea448bc79..e1ada753f10c 100644
> > > --- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h
> > > +++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h
> > > @@ -28,6 +28,12 @@ TRACE_EVENT(bpf_testmod_test_read,
> > >                   __entry->pid, __entry->comm, __entry->off, __entry->len)
> > >  );
> > >
> > > +/* A bare tracepoint with no event associated with it */
> > > +DECLARE_TRACE(bpf_testmod_test_read_bare,
> > > +       TP_PROTO(struct task_struct *task, struct bpf_testmod_test_read_ctx *ctx),
> > > +       TP_ARGS(task, ctx)
> > > +);
> > > +
> > >  #endif /* _BPF_TESTMOD_EVENTS_H */
> > >
> > >  #undef TRACE_INCLUDE_PATH
> > > diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
> > > index 2df19d73ca49..d63cebdaca44 100644
> > > --- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
> > > +++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
> > > @@ -22,6 +22,8 @@ bpf_testmod_test_read(struct file *file, struct kobject *kobj,
> > >         };
> > >
> > >         trace_bpf_testmod_test_read(current, &ctx);
> > > +       ctx.len++;
> > > +       trace_bpf_testmod_test_read_bare(current, &ctx);
> >
> > It's kind of boring to have two read tracepoints :) Do you mind adding
>
> Hehe boring is good :p
>
> > a write tracepoint and use bare tracepoint there? You won't need this
> > ctx.len++ hack as well. Feel free to add identical
> > bpf_testmod_test_write_ctx (renaming it is more of a pain).
>
> It was easy to get this done. So I think it should be easy to make it a write
> too :)

yep, having two tracepoints allow more flexibility over longer term,
so I think it's good to do (regardless of boring or not ;) )

>
> Thanks
>
> --
> Qais Yousef
>
> >
> > >
> > >         return -EIO; /* always fail */
> > >  }
> > > diff --git a/tools/testing/selftests/bpf/prog_tests/module_attach.c b/tools/testing/selftests/bpf/prog_tests/module_attach.c
> > > index 50796b651f72..7085a118f38c 100644
> > > --- a/tools/testing/selftests/bpf/prog_tests/module_attach.c
> > > +++ b/tools/testing/selftests/bpf/prog_tests/module_attach.c
> > > @@ -50,6 +50,7 @@ void test_module_attach(void)
> > >         ASSERT_OK(trigger_module_test_read(READ_SZ), "trigger_read");
> > >
> > >         ASSERT_EQ(bss->raw_tp_read_sz, READ_SZ, "raw_tp");
> > > +       ASSERT_EQ(bss->raw_tp_bare_read_sz, READ_SZ+1, "raw_tp_bare");
> > >         ASSERT_EQ(bss->tp_btf_read_sz, READ_SZ, "tp_btf");
> > >         ASSERT_EQ(bss->fentry_read_sz, READ_SZ, "fentry");
> > >         ASSERT_EQ(bss->fentry_manual_read_sz, READ_SZ, "fentry_manual");
> > > diff --git a/tools/testing/selftests/bpf/progs/test_module_attach.c b/tools/testing/selftests/bpf/progs/test_module_attach.c
> > > index efd1e287ac17..08aa157afa1d 100644
> > > --- a/tools/testing/selftests/bpf/progs/test_module_attach.c
> > > +++ b/tools/testing/selftests/bpf/progs/test_module_attach.c
> > > @@ -17,6 +17,16 @@ int BPF_PROG(handle_raw_tp,
> > >         return 0;
> > >  }
> > >
> > > +__u32 raw_tp_bare_read_sz = 0;
> > > +
> > > +SEC("raw_tp/bpf_testmod_test_read_bare")
> > > +int BPF_PROG(handle_raw_tp_bare,
> > > +            struct task_struct *task, struct bpf_testmod_test_read_ctx *read_ctx)
> > > +{
> > > +       raw_tp_bare_read_sz = BPF_CORE_READ(read_ctx, len);
> > > +       return 0;
> > > +}
> > > +
> > >  __u32 tp_btf_read_sz = 0;
> > >
> > >  SEC("tp_btf/bpf_testmod_test_read")
> > > --
> > > 2.25.1
> > >
Qais Yousef Jan. 13, 2021, 10:21 a.m. UTC | #4
On 01/12/21 12:07, Andrii Nakryiko wrote:
> > > >         $ sudo ./test_progs -v -t module_attach
> > >
> > > use -vv when debugging stuff like that with test_progs, it will output
> > > libbpf detailed logs, that often are very helpful
> >
> > I tried that but it didn't help me. Full output is here
> >
> >         https://paste.debian.net/1180846
> >
> 
> It did help a bit for me to make sure that you have bpf_testmod
> properly loaded and its BTF was found, so the problem is somewhere
> else. Also, given load succeeded and attach failed with OPNOTSUPP, I
> suspect you are missing some of FTRACE configs, which seems to be
> missing from selftests's config as well. Check that you have
> CONFIG_FTRACE=y and CONFIG_DYNAMIC_FTRACE=y, and you might need some
> more. See [0] for a real config we are using to run all tests in
> libbpf CI. If you figure out what you were missing, please also
> contribute a patch to selftests' config.
> 
>   [0] https://github.com/libbpf/libbpf/blob/master/travis-ci/vmtest/configs/latest.config

Yeah that occurred to me too. I do have all necessary FTRACE options enabled,
including DYNAMIC_FTRACE. I think I did try enabling fault injection too just
in case. I have CONFIG_FAULT_INJECTION=y and CONFIG_FUNCTION_ERROR_INJECTION=y.

I will look at the CI config and see if I can figure it out.

I will likely get a chance to look at all of this and send v2  over the
weekend.

Thanks

--
Qais Yousef
Jean-Philippe Brucker Jan. 13, 2021, 4:40 p.m. UTC | #5
On Wed, Jan 13, 2021 at 10:21:31AM +0000, Qais Yousef wrote:
> On 01/12/21 12:07, Andrii Nakryiko wrote:
> > > > >         $ sudo ./test_progs -v -t module_attach
> > > >
> > > > use -vv when debugging stuff like that with test_progs, it will output
> > > > libbpf detailed logs, that often are very helpful
> > >
> > > I tried that but it didn't help me. Full output is here
> > >
> > >         https://paste.debian.net/1180846
> > >
> > 
> > It did help a bit for me to make sure that you have bpf_testmod
> > properly loaded and its BTF was found, so the problem is somewhere
> > else. Also, given load succeeded and attach failed with OPNOTSUPP, I
> > suspect you are missing some of FTRACE configs, which seems to be
> > missing from selftests's config as well. Check that you have
> > CONFIG_FTRACE=y and CONFIG_DYNAMIC_FTRACE=y, and you might need some
> > more. See [0] for a real config we are using to run all tests in
> > libbpf CI. If you figure out what you were missing, please also
> > contribute a patch to selftests' config.
> > 
> >   [0] https://github.com/libbpf/libbpf/blob/master/travis-ci/vmtest/configs/latest.config
> 
> Yeah that occurred to me too. I do have all necessary FTRACE options enabled,
> including DYNAMIC_FTRACE. I think I did try enabling fault injection too just
> in case. I have CONFIG_FAULT_INJECTION=y and CONFIG_FUNCTION_ERROR_INJECTION=y.

Could it come from lack of fentry support on arm64 (or are you testing on
x86?) Since the arm64 JIT doesn't have trampoline support at the moment, a
lot of bpf selftests fail with ENOTSUPP.

Thanks,
Jean
Qais Yousef Jan. 14, 2021, 12:58 p.m. UTC | #6
On 01/13/21 17:40, Jean-Philippe Brucker wrote:
> On Wed, Jan 13, 2021 at 10:21:31AM +0000, Qais Yousef wrote:
> > On 01/12/21 12:07, Andrii Nakryiko wrote:
> > > > > >         $ sudo ./test_progs -v -t module_attach
> > > > >
> > > > > use -vv when debugging stuff like that with test_progs, it will output
> > > > > libbpf detailed logs, that often are very helpful
> > > >
> > > > I tried that but it didn't help me. Full output is here
> > > >
> > > >         https://paste.debian.net/1180846
> > > >
> > > 
> > > It did help a bit for me to make sure that you have bpf_testmod
> > > properly loaded and its BTF was found, so the problem is somewhere
> > > else. Also, given load succeeded and attach failed with OPNOTSUPP, I
> > > suspect you are missing some of FTRACE configs, which seems to be
> > > missing from selftests's config as well. Check that you have
> > > CONFIG_FTRACE=y and CONFIG_DYNAMIC_FTRACE=y, and you might need some
> > > more. See [0] for a real config we are using to run all tests in
> > > libbpf CI. If you figure out what you were missing, please also
> > > contribute a patch to selftests' config.
> > > 
> > >   [0] https://github.com/libbpf/libbpf/blob/master/travis-ci/vmtest/configs/latest.config
> > 
> > Yeah that occurred to me too. I do have all necessary FTRACE options enabled,
> > including DYNAMIC_FTRACE. I think I did try enabling fault injection too just
> > in case. I have CONFIG_FAULT_INJECTION=y and CONFIG_FUNCTION_ERROR_INJECTION=y.
> 
> Could it come from lack of fentry support on arm64 (or are you testing on
> x86?) Since the arm64 JIT doesn't have trampoline support at the moment, a
> lot of bpf selftests fail with ENOTSUPP.

I am on arm64. I honestly have no clue about this. I'll try to dig out.

Thanks

--
Qais Yousef
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h
index b83ea448bc79..e1ada753f10c 100644
--- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h
+++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h
@@ -28,6 +28,12 @@  TRACE_EVENT(bpf_testmod_test_read,
 		  __entry->pid, __entry->comm, __entry->off, __entry->len)
 );
 
+/* A bare tracepoint with no event associated with it */
+DECLARE_TRACE(bpf_testmod_test_read_bare,
+	TP_PROTO(struct task_struct *task, struct bpf_testmod_test_read_ctx *ctx),
+	TP_ARGS(task, ctx)
+);
+
 #endif /* _BPF_TESTMOD_EVENTS_H */
 
 #undef TRACE_INCLUDE_PATH
diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
index 2df19d73ca49..d63cebdaca44 100644
--- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
+++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
@@ -22,6 +22,8 @@  bpf_testmod_test_read(struct file *file, struct kobject *kobj,
 	};
 
 	trace_bpf_testmod_test_read(current, &ctx);
+	ctx.len++;
+	trace_bpf_testmod_test_read_bare(current, &ctx);
 
 	return -EIO; /* always fail */
 }
diff --git a/tools/testing/selftests/bpf/prog_tests/module_attach.c b/tools/testing/selftests/bpf/prog_tests/module_attach.c
index 50796b651f72..7085a118f38c 100644
--- a/tools/testing/selftests/bpf/prog_tests/module_attach.c
+++ b/tools/testing/selftests/bpf/prog_tests/module_attach.c
@@ -50,6 +50,7 @@  void test_module_attach(void)
 	ASSERT_OK(trigger_module_test_read(READ_SZ), "trigger_read");
 
 	ASSERT_EQ(bss->raw_tp_read_sz, READ_SZ, "raw_tp");
+	ASSERT_EQ(bss->raw_tp_bare_read_sz, READ_SZ+1, "raw_tp_bare");
 	ASSERT_EQ(bss->tp_btf_read_sz, READ_SZ, "tp_btf");
 	ASSERT_EQ(bss->fentry_read_sz, READ_SZ, "fentry");
 	ASSERT_EQ(bss->fentry_manual_read_sz, READ_SZ, "fentry_manual");
diff --git a/tools/testing/selftests/bpf/progs/test_module_attach.c b/tools/testing/selftests/bpf/progs/test_module_attach.c
index efd1e287ac17..08aa157afa1d 100644
--- a/tools/testing/selftests/bpf/progs/test_module_attach.c
+++ b/tools/testing/selftests/bpf/progs/test_module_attach.c
@@ -17,6 +17,16 @@  int BPF_PROG(handle_raw_tp,
 	return 0;
 }
 
+__u32 raw_tp_bare_read_sz = 0;
+
+SEC("raw_tp/bpf_testmod_test_read_bare")
+int BPF_PROG(handle_raw_tp_bare,
+	     struct task_struct *task, struct bpf_testmod_test_read_ctx *read_ctx)
+{
+	raw_tp_bare_read_sz = BPF_CORE_READ(read_ctx, len);
+	return 0;
+}
+
 __u32 tp_btf_read_sz = 0;
 
 SEC("tp_btf/bpf_testmod_test_read")