From: Daniel Borkmann <daniel@iogearbox.net>
To: Yonghong Song <yhs@fb.com>, Eelco Chaudron <echaudro@redhat.com>,
bpf@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org, ast@kernel.org,
kafai@fb.com, songliubraving@fb.com, andriin@fb.com,
toke@redhat.com
Subject: Re: [PATCH bpf-next v3] libbpf: fix probe code to return EPERM if encountered
Date: Mon, 11 May 2020 23:08:27 +0200 [thread overview]
Message-ID: <625c343a-6554-a6e9-fb04-ca0a80554a91@iogearbox.net> (raw)
In-Reply-To: <7008d545-ac78-3e22-aeaa-1d6639611225@fb.com>
On 5/11/20 10:43 PM, Yonghong Song wrote:
> On 5/11/20 5:40 AM, Eelco Chaudron wrote:
>> When the probe code was failing for any reason ENOTSUP was returned, even
>> if this was due to no having enough lock space. This patch fixes this by
>> returning EPERM to the user application, so it can respond and increase
>> the RLIMIT_MEMLOCK size.
>>
>> Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
>> ---
>> v3: Updated error message to be more specific as suggested by Andrii
>> v2: Split bpf_object__probe_name() in two functions as suggested by Andrii
>>
>> tools/lib/bpf/libbpf.c | 31 ++++++++++++++++++++++++++-----
>> 1 file changed, 26 insertions(+), 5 deletions(-)
>>
>> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
>> index 8f480e29a6b0..ad3043c5db13 100644
>> --- a/tools/lib/bpf/libbpf.c
>> +++ b/tools/lib/bpf/libbpf.c
>> @@ -3149,7 +3149,7 @@ int bpf_map__resize(struct bpf_map *map, __u32 max_entries)
>> }
>> static int
>> -bpf_object__probe_name(struct bpf_object *obj)
>> +bpf_object__probe_loading(struct bpf_object *obj)
>> {
>> struct bpf_load_program_attr attr;
>> char *cp, errmsg[STRERR_BUFSIZE];
>> @@ -3170,14 +3170,34 @@ bpf_object__probe_name(struct bpf_object *obj)
>> ret = bpf_load_program_xattr(&attr, NULL, 0);
>> if (ret < 0) {
>> cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg));
>> - pr_warn("Error in %s():%s(%d). Couldn't load basic 'r0 = 0' BPF program.\n",
>> - __func__, cp, errno);
>> + pr_warn("Error in %s():%s(%d). Couldn't load trivial BPF "
>> + "program. Make sure your kernel supports BPF "
>> + "(CONFIG_BPF_SYSCALL=y) and/or that RLIMIT_MEMLOCK is "
>> + "set to big enough value.\n", __func__, cp, errno);
>> return -errno;
>
> Just curious. Did "errno" always survive pr_warn() here? pr_warn() may call user supplied print function which it outside libbpf control.
> Maybe should cache errno before calling pr_warn()?
+1, I think right now it's a bit of a mess in libbpf. Plenty of cases where we cache errno
before pr_warn() and plenty of cases where we don't. I think we should avoid any surprises
and do cache it on these occasions everywhere. Maybe a cocci script would help to fix the
remaining sites for good.
Thanks,
Daniel
next prev parent reply other threads:[~2020-05-11 21:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-11 12:40 [PATCH bpf-next v3] libbpf: fix probe code to return EPERM if encountered Eelco Chaudron
2020-05-11 20:43 ` Yonghong Song
2020-05-11 21:08 ` Daniel Borkmann [this message]
2020-05-12 9:06 ` Eelco Chaudron
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=625c343a-6554-a6e9-fb04-ca0a80554a91@iogearbox.net \
--to=daniel@iogearbox.net \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=echaudro@redhat.com \
--cc=kafai@fb.com \
--cc=netdev@vger.kernel.org \
--cc=songliubraving@fb.com \
--cc=toke@redhat.com \
--cc=yhs@fb.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox