From: Geliang Tang <geliang@kernel.org>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>
Cc: Geliang Tang <tanggeliang@kylinos.cn>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 2/2] libbpf: handle ENOTSUPP in libbpf_strerror_r
Date: Fri, 12 Jul 2024 22:10:13 +0800 [thread overview]
Message-ID: <83163d7e8162988e5235cca5d79ef3dba2d54565.camel@kernel.org> (raw)
In-Reply-To: <2437275bb988da5c187b4d0223e5c0c9843fdc76.1720778831.git.tanggeliang@kylinos.cn>
On Fri, 2024-07-12 at 18:14 +0800, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
>
> The errno 95 (ENOTSUP or EOPNOTSUPP) can be recognized by
> strerror_r(),
> but 524 (ENOTSUPP) can't:
>
> prog 'basic_alloc3': BPF program load failed: Operation not
> supported
> prog 'basic_alloc3': failed to load: -95
> failed to load object 'verifier_arena'
> FAIL:unexpected_load_failure unexpected error: -95 (errno 95)
>
> prog 'inner_map': BPF program load failed: unknown error (-524)
> prog 'inner_map': failed to load: -524
> failed to load object 'bloom_filter_map'
> failed to load BPF skeleton 'bloom_filter_map': -524
> FAIL:bloom_filter_map__open_and_load unexpected error: -524
>
> This patch fixes this by handling ENOTSUPP in libbpf_strerror_r().
> With
> this change, the new error string looks like:
>
> prog 'inner_map': BPF program load failed: Operation not supported
> (-524)
>
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
> tools/lib/bpf/str_error.c | 11 +++++++----
> tools/lib/bpf/str_error.h | 4 ++++
> 2 files changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/tools/lib/bpf/str_error.c b/tools/lib/bpf/str_error.c
> index 5e6a1e27ddf9..10597d5124cd 100644
> --- a/tools/lib/bpf/str_error.c
> +++ b/tools/lib/bpf/str_error.c
> @@ -23,10 +23,13 @@ char *libbpf_strerror_r(int err, char *dst, int
> len)
> if (ret == -1)
> ret = errno;
> if (ret) {
> - if (ret == EINVAL)
> - /* strerror_r() doesn't recognize this
> specific error */
> - snprintf(dst, len, "unknown error (%d)", err
> < 0 ? err : -err);
> - else
> + if (ret == EINVAL) {
> + if (err == ENOTSUPP)
Shouldn't use "err" directly here, should use "err < 0 ? -err : err"
instead. I prefer to add an unsigned variable "no" in v2:
unsigned int no = err < 0 ? -err : err;
And use "switch-case" for future expansion:
switch (no) {
case ENOTSUPP:
> + snprintf(dst, len, "Operation not
> supported (%d)", -err);
No need to use "Operation not supported (-524)" here, just "Operation
not supported" is better.
snprintf(dst, len, "Operation not supported");
> + else
> + /* strerror_r() doesn't recognize
> this specific error */
> + snprintf(dst, len, "unknown error
> (%d)", err < 0 ? err : -err);
Then here:
snprintf(dst, len, "unknown error (-%u)", no);
Changes Requested.
Will send a v2 soon.
Thanks,
-Geliang
> + } else
> snprintf(dst, len, "ERROR:
> strerror_r(%d)=%d", err, ret);
> }
> return dst;
> diff --git a/tools/lib/bpf/str_error.h b/tools/lib/bpf/str_error.h
> index 626d7ffb03d6..c41f6ba133cf 100644
> --- a/tools/lib/bpf/str_error.h
> +++ b/tools/lib/bpf/str_error.h
> @@ -4,6 +4,10 @@
>
> #define STRERR_BUFSIZE 128
>
> +#ifndef ENOTSUPP
> +#define ENOTSUPP 524
> +#endif
> +
> char *libbpf_strerror_r(int err, char *dst, int len);
>
> #endif /* __LIBBPF_STR_ERROR_H */
next prev parent reply other threads:[~2024-07-12 14:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-12 10:14 [PATCH bpf-next 0/2] handle errno ENOTSUPP Geliang Tang
2024-07-12 10:14 ` [PATCH bpf-next 1/2] bpf: verifier: Fix return value of fixup_call_args Geliang Tang
2024-07-12 15:56 ` Alexei Starovoitov
2024-07-12 10:14 ` [PATCH bpf-next 2/2] libbpf: handle ENOTSUPP in libbpf_strerror_r Geliang Tang
2024-07-12 14:10 ` Geliang Tang [this message]
2024-07-12 15:57 ` Alexei Starovoitov
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=83163d7e8162988e5235cca5d79ef3dba2d54565.camel@kernel.org \
--to=geliang@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=tanggeliang@kylinos.cn \
--cc=yonghong.song@linux.dev \
/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