* [PATCH -next v2] bpf/benchs: Fix return value check of bpf_program__attach()
@ 2021-11-01 12:43 Yang Yingliang
2021-11-01 22:00 ` Alexei Starovoitov
0 siblings, 1 reply; 5+ messages in thread
From: Yang Yingliang @ 2021-11-01 12:43 UTC (permalink / raw)
To: linux-kernel, bpf; +Cc: linux-kselftest, shuah, ast, yhs
If bpf_program__attach() fails, it never returns NULL,
we should use libbpf_get_error() to check the return value.
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Acked-by: Yonghong Song <yhs@fb.com>
---
v2:
don't use 'int err'
---
.../selftests/bpf/benchs/bench_bloom_filter_map.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c b/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
index 6eeeed2913e6..4afaa4adb327 100644
--- a/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
+++ b/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
@@ -304,7 +304,7 @@ static void bloom_lookup_setup(void)
populate_maps();
link = bpf_program__attach(ctx.skel->progs.bloom_lookup);
- if (!link) {
+ if (libbpf_get_error(link)) {
fprintf(stderr, "failed to attach program!\n");
exit(1);
}
@@ -321,7 +321,7 @@ static void bloom_update_setup(void)
populate_maps();
link = bpf_program__attach(ctx.skel->progs.bloom_update);
- if (!link) {
+ if (libbpf_get_error(link)) {
fprintf(stderr, "failed to attach program!\n");
exit(1);
}
@@ -340,7 +340,7 @@ static void false_positive_setup(void)
populate_maps();
link = bpf_program__attach(ctx.skel->progs.bloom_hashmap_lookup);
- if (!link) {
+ if (libbpf_get_error(link)) {
fprintf(stderr, "failed to attach program!\n");
exit(1);
}
@@ -358,7 +358,7 @@ static void hashmap_with_bloom_setup(void)
populate_maps();
link = bpf_program__attach(ctx.skel->progs.bloom_hashmap_lookup);
- if (!link) {
+ if (libbpf_get_error(link)) {
fprintf(stderr, "failed to attach program!\n");
exit(1);
}
@@ -375,7 +375,7 @@ static void hashmap_no_bloom_setup(void)
populate_maps();
link = bpf_program__attach(ctx.skel->progs.bloom_hashmap_lookup);
- if (!link) {
+ if (libbpf_get_error(link)) {
fprintf(stderr, "failed to attach program!\n");
exit(1);
}
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH -next v2] bpf/benchs: Fix return value check of bpf_program__attach()
2021-11-01 12:43 [PATCH -next v2] bpf/benchs: Fix return value check of bpf_program__attach() Yang Yingliang
@ 2021-11-01 22:00 ` Alexei Starovoitov
2021-11-01 22:21 ` Yonghong Song
0 siblings, 1 reply; 5+ messages in thread
From: Alexei Starovoitov @ 2021-11-01 22:00 UTC (permalink / raw)
To: Yang Yingliang, Joanne Koong, Andrii Nakryiko
Cc: LKML, bpf, open list:KERNEL SELFTEST FRAMEWORK, Shuah Khan,
Alexei Starovoitov, Yonghong Song
On Mon, Nov 1, 2021 at 5:35 AM Yang Yingliang <yangyingliang@huawei.com> wrote:
>
> If bpf_program__attach() fails, it never returns NULL,
> we should use libbpf_get_error() to check the return value.
>
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> Acked-by: Yonghong Song <yhs@fb.com>
> ---
> v2:
> don't use 'int err'
> ---
> .../selftests/bpf/benchs/bench_bloom_filter_map.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c b/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
> index 6eeeed2913e6..4afaa4adb327 100644
> --- a/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
> +++ b/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
> @@ -304,7 +304,7 @@ static void bloom_lookup_setup(void)
> populate_maps();
>
> link = bpf_program__attach(ctx.skel->progs.bloom_lookup);
> - if (!link) {
> + if (libbpf_get_error(link)) {
Please use ASSERT_OK_PTR() instead.
See how other tests are doing it.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH -next v2] bpf/benchs: Fix return value check of bpf_program__attach()
2021-11-01 22:00 ` Alexei Starovoitov
@ 2021-11-01 22:21 ` Yonghong Song
2021-11-01 22:30 ` Alexei Starovoitov
0 siblings, 1 reply; 5+ messages in thread
From: Yonghong Song @ 2021-11-01 22:21 UTC (permalink / raw)
To: Alexei Starovoitov, Yang Yingliang, Joanne Koong, Andrii Nakryiko
Cc: LKML, bpf, open list:KERNEL SELFTEST FRAMEWORK, Shuah Khan,
Alexei Starovoitov
On 11/1/21 3:00 PM, Alexei Starovoitov wrote:
> On Mon, Nov 1, 2021 at 5:35 AM Yang Yingliang <yangyingliang@huawei.com> wrote:
>>
>> If bpf_program__attach() fails, it never returns NULL,
>> we should use libbpf_get_error() to check the return value.
>>
>> Reported-by: Hulk Robot <hulkci@huawei.com>
>> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
>> Acked-by: Yonghong Song <yhs@fb.com>
>> ---
>> v2:
>> don't use 'int err'
>> ---
>> .../selftests/bpf/benchs/bench_bloom_filter_map.c | 10 +++++-----
>> 1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c b/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
>> index 6eeeed2913e6..4afaa4adb327 100644
>> --- a/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
>> +++ b/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
>> @@ -304,7 +304,7 @@ static void bloom_lookup_setup(void)
>> populate_maps();
>>
>> link = bpf_program__attach(ctx.skel->progs.bloom_lookup);
>> - if (!link) {
>> + if (libbpf_get_error(link)) {
>
> Please use ASSERT_OK_PTR() instead.
> See how other tests are doing it.
I actually looked at this. ASSERT_OK_PTR() is defined in test_progs.h
and test_progs.h is ONLY included in files which eventually linked to
test_progs. That is why I didn't recommend to use ASSERT_OK_PTR().
Maybe it is okay to include test_progs.h in benchs/*.c. Or we may
want to refactor to a separate header file to contain these macros
which can be used for test_progs.h and other applications.
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH -next v2] bpf/benchs: Fix return value check of bpf_program__attach()
2021-11-01 22:21 ` Yonghong Song
@ 2021-11-01 22:30 ` Alexei Starovoitov
2021-11-02 2:46 ` Andrii Nakryiko
0 siblings, 1 reply; 5+ messages in thread
From: Alexei Starovoitov @ 2021-11-01 22:30 UTC (permalink / raw)
To: Yonghong Song
Cc: Yang Yingliang, Joanne Koong, Andrii Nakryiko, LKML, bpf,
open list:KERNEL SELFTEST FRAMEWORK, Shuah Khan,
Alexei Starovoitov
On Mon, Nov 1, 2021 at 3:21 PM Yonghong Song <yhs@fb.com> wrote:
>
>
>
> On 11/1/21 3:00 PM, Alexei Starovoitov wrote:
> > On Mon, Nov 1, 2021 at 5:35 AM Yang Yingliang <yangyingliang@huawei.com> wrote:
> >>
> >> If bpf_program__attach() fails, it never returns NULL,
> >> we should use libbpf_get_error() to check the return value.
> >>
> >> Reported-by: Hulk Robot <hulkci@huawei.com>
> >> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> >> Acked-by: Yonghong Song <yhs@fb.com>
> >> ---
> >> v2:
> >> don't use 'int err'
> >> ---
> >> .../selftests/bpf/benchs/bench_bloom_filter_map.c | 10 +++++-----
> >> 1 file changed, 5 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c b/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
> >> index 6eeeed2913e6..4afaa4adb327 100644
> >> --- a/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
> >> +++ b/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
> >> @@ -304,7 +304,7 @@ static void bloom_lookup_setup(void)
> >> populate_maps();
> >>
> >> link = bpf_program__attach(ctx.skel->progs.bloom_lookup);
> >> - if (!link) {
> >> + if (libbpf_get_error(link)) {
> >
> > Please use ASSERT_OK_PTR() instead.
> > See how other tests are doing it.
>
> I actually looked at this. ASSERT_OK_PTR() is defined in test_progs.h
> and test_progs.h is ONLY included in files which eventually linked to
> test_progs. That is why I didn't recommend to use ASSERT_OK_PTR().
>
> Maybe it is okay to include test_progs.h in benchs/*.c. Or we may
> want to refactor to a separate header file to contain these macros
> which can be used for test_progs.h and other applications.
hmm.
Looks like bench_ringbufs.c has the same issue doing:
if (!link)
and bench_rename.c too.
Probably would be good to fix in all bench-s.
If test_progs.h cannot be included directly
copy-pasting ASSERT_OK_PTR in a reduced form into bench.h
is probably cleaner than open coding libbpf_get_error.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH -next v2] bpf/benchs: Fix return value check of bpf_program__attach()
2021-11-01 22:30 ` Alexei Starovoitov
@ 2021-11-02 2:46 ` Andrii Nakryiko
0 siblings, 0 replies; 5+ messages in thread
From: Andrii Nakryiko @ 2021-11-02 2:46 UTC (permalink / raw)
To: Alexei Starovoitov
Cc: Yonghong Song, Yang Yingliang, Joanne Koong, Andrii Nakryiko,
LKML, bpf, open list:KERNEL SELFTEST FRAMEWORK, Shuah Khan,
Alexei Starovoitov
On Mon, Nov 1, 2021 at 3:30 PM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Mon, Nov 1, 2021 at 3:21 PM Yonghong Song <yhs@fb.com> wrote:
> >
> >
> >
> > On 11/1/21 3:00 PM, Alexei Starovoitov wrote:
> > > On Mon, Nov 1, 2021 at 5:35 AM Yang Yingliang <yangyingliang@huawei.com> wrote:
> > >>
> > >> If bpf_program__attach() fails, it never returns NULL,
> > >> we should use libbpf_get_error() to check the return value.
> > >>
> > >> Reported-by: Hulk Robot <hulkci@huawei.com>
> > >> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> > >> Acked-by: Yonghong Song <yhs@fb.com>
> > >> ---
> > >> v2:
> > >> don't use 'int err'
> > >> ---
> > >> .../selftests/bpf/benchs/bench_bloom_filter_map.c | 10 +++++-----
> > >> 1 file changed, 5 insertions(+), 5 deletions(-)
> > >>
> > >> diff --git a/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c b/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
> > >> index 6eeeed2913e6..4afaa4adb327 100644
> > >> --- a/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
> > >> +++ b/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
> > >> @@ -304,7 +304,7 @@ static void bloom_lookup_setup(void)
> > >> populate_maps();
> > >>
> > >> link = bpf_program__attach(ctx.skel->progs.bloom_lookup);
> > >> - if (!link) {
> > >> + if (libbpf_get_error(link)) {
> > >
> > > Please use ASSERT_OK_PTR() instead.
> > > See how other tests are doing it.
> >
> > I actually looked at this. ASSERT_OK_PTR() is defined in test_progs.h
> > and test_progs.h is ONLY included in files which eventually linked to
> > test_progs. That is why I didn't recommend to use ASSERT_OK_PTR().
> >
> > Maybe it is okay to include test_progs.h in benchs/*.c. Or we may
> > want to refactor to a separate header file to contain these macros
> > which can be used for test_progs.h and other applications.
>
> hmm.
> Looks like bench_ringbufs.c has the same issue doing:
> if (!link)
> and bench_rename.c too.
bench.c does:
libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
and so on error all the pointers will be NULL. So it's ok to check if
(!link) and not use libbpf_get_error() at all.
>
> Probably would be good to fix in all bench-s.
>
> If test_progs.h cannot be included directly
> copy-pasting ASSERT_OK_PTR in a reduced form into bench.h
> is probably cleaner than open coding libbpf_get_error.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-11-02 2:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-01 12:43 [PATCH -next v2] bpf/benchs: Fix return value check of bpf_program__attach() Yang Yingliang
2021-11-01 22:00 ` Alexei Starovoitov
2021-11-01 22:21 ` Yonghong Song
2021-11-01 22:30 ` Alexei Starovoitov
2021-11-02 2:46 ` Andrii Nakryiko
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).