diff mbox series

[bpf-next] selftests/bpf: Hardcode /sys/kernel/btf/vmlinux in fewer places

Message ID 20220512234332.2852918-1-deso@posteo.net (mailing list archive)
State Rejected
Delegated to: BPF
Headers show
Series [bpf-next] selftests/bpf: Hardcode /sys/kernel/btf/vmlinux in fewer places | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR pending PR summary
bpf/vmtest-bpf-next-VM_Test-1 pending Logs for Kernel LATEST on ubuntu-latest + selftests
bpf/vmtest-bpf-next-VM_Test-2 pending Logs for Kernel LATEST on z15 + selftests
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 9 maintainers not CCed: netdev@vger.kernel.org kafai@fb.com john.fastabend@gmail.com shuah@kernel.org yhs@fb.com kpsingh@kernel.org davemarchevsky@fb.com linux-kselftest@vger.kernel.org songliubraving@fb.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 20 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Daniel Müller May 12, 2022, 11:43 p.m. UTC
Two of the BPF selftests hardcode the path to /sys/kernel/btf/vmlinux.
The kernel image could potentially exist at a different location.
libbpf_find_kernel_btf(), as introduced by commit fb2426ad00b1 ("libbpf:
Expose bpf_find_kernel_btf as a LIBBPF_API"), knows about said
locations.

This change switches these two tests over to using this function
instead, making the tests more likely to be runnable when
/sys/kernel/btf/vmlinux may not be present and setting better precedent.

Signed-off-by: Daniel Müller <deso@posteo.net>
---
 tools/testing/selftests/bpf/prog_tests/libbpf_probes.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Andrii Nakryiko May 13, 2022, 12:08 a.m. UTC | #1
On Thu, May 12, 2022 at 4:44 PM Daniel Müller <deso@posteo.net> wrote:
>
> Two of the BPF selftests hardcode the path to /sys/kernel/btf/vmlinux.
> The kernel image could potentially exist at a different location.
> libbpf_find_kernel_btf(), as introduced by commit fb2426ad00b1 ("libbpf:
> Expose bpf_find_kernel_btf as a LIBBPF_API"), knows about said
> locations.
>
> This change switches these two tests over to using this function
> instead, making the tests more likely to be runnable when
> /sys/kernel/btf/vmlinux may not be present and setting better precedent.
>
> Signed-off-by: Daniel Müller <deso@posteo.net>
> ---
>  tools/testing/selftests/bpf/prog_tests/libbpf_probes.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c b/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c
> index 9f766dd..61c81a9 100644
> --- a/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c
> +++ b/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c
> @@ -11,8 +11,8 @@ void test_libbpf_probe_prog_types(void)
>         const struct btf_enum *e;
>         int i, n, id;
>
> -       btf = btf__parse("/sys/kernel/btf/vmlinux", NULL);

Selftests go hand in hand with kernel and generally assume specific
kernel features enabled (like BTF and sysfs) and having very recent
(if not latest) kernel. So there is nothing bad about loading
/sys/kernel/btf/vmlinux, I think, it's actually more straightforward
to follow the code when it is used explicitly. Libbpf's logic for
finding kernel BTF in other places is for older systems. So I'd leave
it as is.

> -       if (!ASSERT_OK_PTR(btf, "btf_parse"))
> +       btf = libbpf_find_kernel_btf();
> +       if (!ASSERT_OK_PTR(btf, "libbpf_find_kernel_btf"))
>                 return;
>
>         /* find enum bpf_prog_type and enumerate each value */
> @@ -49,8 +49,8 @@ void test_libbpf_probe_map_types(void)
>         const struct btf_enum *e;
>         int i, n, id;
>
> -       btf = btf__parse("/sys/kernel/btf/vmlinux", NULL);
> -       if (!ASSERT_OK_PTR(btf, "btf_parse"))
> +       btf = libbpf_find_kernel_btf();
> +       if (!ASSERT_OK_PTR(btf, "libbpf_find_kernel_btf"))
>                 return;
>
>         /* find enum bpf_map_type and enumerate each value */
> --
> 2.30.2
>
Daniel Müller May 13, 2022, 12:45 a.m. UTC | #2
On Thu, May 12, 2022 at 05:08:29PM -0700, Andrii Nakryiko wrote:
> On Thu, May 12, 2022 at 4:44 PM Daniel Müller <deso@posteo.net> wrote:
> >
> > Two of the BPF selftests hardcode the path to /sys/kernel/btf/vmlinux.
> > The kernel image could potentially exist at a different location.
> > libbpf_find_kernel_btf(), as introduced by commit fb2426ad00b1 ("libbpf:
> > Expose bpf_find_kernel_btf as a LIBBPF_API"), knows about said
> > locations.
> >
> > This change switches these two tests over to using this function
> > instead, making the tests more likely to be runnable when
> > /sys/kernel/btf/vmlinux may not be present and setting better precedent.
> >
> > Signed-off-by: Daniel Müller <deso@posteo.net>
> > ---
> >  tools/testing/selftests/bpf/prog_tests/libbpf_probes.c | 8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c b/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c
> > index 9f766dd..61c81a9 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c
> > @@ -11,8 +11,8 @@ void test_libbpf_probe_prog_types(void)
> >         const struct btf_enum *e;
> >         int i, n, id;
> >
> > -       btf = btf__parse("/sys/kernel/btf/vmlinux", NULL);
> 
> Selftests go hand in hand with kernel and generally assume specific
> kernel features enabled (like BTF and sysfs) and having very recent
> (if not latest) kernel. So there is nothing bad about loading
> /sys/kernel/btf/vmlinux, I think, it's actually more straightforward
> to follow the code when it is used explicitly. Libbpf's logic for
> finding kernel BTF in other places is for older systems. So I'd leave
> it as is.

Sounds good to me. Feel free to ignore the patch then.

Daniel
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c b/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c
index 9f766dd..61c81a9 100644
--- a/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c
+++ b/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c
@@ -11,8 +11,8 @@  void test_libbpf_probe_prog_types(void)
 	const struct btf_enum *e;
 	int i, n, id;
 
-	btf = btf__parse("/sys/kernel/btf/vmlinux", NULL);
-	if (!ASSERT_OK_PTR(btf, "btf_parse"))
+	btf = libbpf_find_kernel_btf();
+	if (!ASSERT_OK_PTR(btf, "libbpf_find_kernel_btf"))
 		return;
 
 	/* find enum bpf_prog_type and enumerate each value */
@@ -49,8 +49,8 @@  void test_libbpf_probe_map_types(void)
 	const struct btf_enum *e;
 	int i, n, id;
 
-	btf = btf__parse("/sys/kernel/btf/vmlinux", NULL);
-	if (!ASSERT_OK_PTR(btf, "btf_parse"))
+	btf = libbpf_find_kernel_btf();
+	if (!ASSERT_OK_PTR(btf, "libbpf_find_kernel_btf"))
 		return;
 
 	/* find enum bpf_map_type and enumerate each value */