All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: "yukuai (C)" <yukuai3@huawei.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>,
	Shuah Khan <shuah@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	"open list:KERNEL SELFTEST FRAMEWORK" 
	<linux-kselftest@vger.kernel.org>,
	Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	yi.zhang@huawei.com
Subject: Re: [PATCH] selftests/bpf: Fix return value check in attach_bpf()
Date: Sat, 29 May 2021 18:17:26 -0700	[thread overview]
Message-ID: <CAEf4BzZN_r_7AVrBwEW5qxiCr4ej1AkyY=4gWX3LufdhyL7Sgw@mail.gmail.com> (raw)
In-Reply-To: <b22eac4a-aad5-917d-5f26-7955b798779b@huawei.com>

On Fri, May 28, 2021 at 6:25 PM yukuai (C) <yukuai3@huawei.com> wrote:
>
> On 2021/05/29 4:46, Daniel Borkmann wrote:
> > On 5/28/21 11:07 AM, Yu Kuai wrote:
> >> use libbpf_get_error() to check the return value of
> >> bpf_program__attach().
> >>
> >> Reported-by: Hulk Robot <hulkci@huawei.com>
> >> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> >> ---
> >>   tools/testing/selftests/bpf/benchs/bench_rename.c | 2 +-
> >>   1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/tools/testing/selftests/bpf/benchs/bench_rename.c
> >> b/tools/testing/selftests/bpf/benchs/bench_rename.c
> >> index c7ec114eca56..b7d4a1d74fca 100644
> >> --- a/tools/testing/selftests/bpf/benchs/bench_rename.c
> >> +++ b/tools/testing/selftests/bpf/benchs/bench_rename.c
> >> @@ -65,7 +65,7 @@ static void attach_bpf(struct bpf_program *prog)
> >>       struct bpf_link *link;
> >>       link = bpf_program__attach(prog);
> >> -    if (!link) {
> >> +    if (libbpf_get_error(link)) {
> >>           fprintf(stderr, "failed to attach program!\n");
> >>           exit(1);
> >>       }
> >
> > Could you explain the rationale of this patch? bad2e478af3b
> > ("selftests/bpf: Turn
> > on libbpf 1.0 mode and fix all IS_ERR checks") explains: 'Fix all the
> > explicit
> > IS_ERR checks that now will be broken because libbpf returns NULL on
> > error (and
> > sets errno).' So the !link check looks totally reasonable to me.
> > Converting to
> > libbpf_get_error() is not wrong in itself, but given you don't make any
> > use of
> > the err code, there is also no point in this diff here.
> Hi,
>
> I was thinking that bpf_program__attach() can return error code
> theoretically(for example -ESRCH), and such case need to be handled.
>

I explicitly changed to NULL check + libbpf 1.0 error reporting mode
because I don't care about specific error in benchmarks. So as Daniel
and John pointed out, existing code is correct and doesn't need
adjustment.

You are right, though, that error code is indeed returned, but you can
check errno directly (but need to enable libbpf 1.0 mode) or use
libbpf_get_error() (which will get deprecated some time before libbpf
1.0) if you don't know which mode your code will be run in.


> Thanks,
> Yu Kuai
> >
> > Thanks,
> > Daniel
> > .
> >

  reply	other threads:[~2021-05-30  1:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-28  9:07 [PATCH] selftests/bpf: Fix return value check in attach_bpf() Yu Kuai
2021-05-28 20:46 ` Daniel Borkmann
2021-05-29  1:25   ` yukuai (C)
2021-05-30  1:17     ` Andrii Nakryiko [this message]
2021-05-28 21:16 ` John Fastabend
2021-05-28 21:19   ` John Fastabend

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAEf4BzZN_r_7AVrBwEW5qxiCr4ej1AkyY=4gWX3LufdhyL7Sgw@mail.gmail.com' \
    --to=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=yi.zhang@huawei.com \
    --cc=yukuai3@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.