From: Leon Hwang <leon.hwang@linux.dev>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org,
daniel@iogearbox.net, menglong8.dong@gmail.com
Subject: Re: [RFC PATCH bpf-next v2 5/6] libbpf: Add common attr support for map_create
Date: Wed, 24 Sep 2025 00:40:01 +0800 [thread overview]
Message-ID: <2e8a73a9-67b9-4d87-844a-c43571055605@linux.dev> (raw)
In-Reply-To: <CAEf4BzY233bt3NdVu8tp7VVmyNWVk-DQB+wQ-uchBJA4Ya3p-g@mail.gmail.com>
On 2025/9/18 05:46, Andrii Nakryiko wrote:
> On Wed, Sep 17, 2025 at 2:45 PM Andrii Nakryiko
> <andrii.nakryiko@gmail.com> wrote:
>>
>> On Thu, Sep 11, 2025 at 9:33 AM Leon Hwang <leon.hwang@linux.dev> wrote:
>>>
>>> With the previous patch adding common attribute support for
>>> BPF_MAP_CREATE, it is now possible to retrieve detailed error messages
>>> when map creation fails by using the 'log_buf' field from the common
>>> attributes.
>>>
>>> This patch extends 'bpf_map_create_opts' with two new fields, 'log_buf'
>>> and 'log_size', allowing users to capture and inspect these log messages.
>>>
>>> Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
>>> ---
>>> tools/lib/bpf/bpf.c | 16 +++++++++++++++-
>>> tools/lib/bpf/bpf.h | 5 ++++-
>>> 2 files changed, 19 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
>>> index 27845e287dd5c..5b58e981a7669 100644
>>> --- a/tools/lib/bpf/bpf.c
>>> +++ b/tools/lib/bpf/bpf.c
>>> @@ -218,7 +218,9 @@ int bpf_map_create(enum bpf_map_type map_type,
>>> const struct bpf_map_create_opts *opts)
>>> {
>>> const size_t attr_sz = offsetofend(union bpf_attr, map_token_fd);
>>> + struct bpf_common_attr common_attrs;
>>> union bpf_attr attr;
>>> + __u64 log_buf;
>>
>>
>> const char *
>>
Ack.
>>> int fd;
>>>
>>> bump_rlimit_memlock();
>>> @@ -249,7 +251,19 @@ int bpf_map_create(enum bpf_map_type map_type,
>>>
>>> attr.map_token_fd = OPTS_GET(opts, token_fd, 0);
>>>
>>> - fd = sys_bpf_fd(BPF_MAP_CREATE, &attr, attr_sz);
>>> + log_buf = (__u64) OPTS_GET(opts, log_buf, NULL);
>>
>> no u64 casting just yet
>>
Ack.
>>> + if (log_buf) {
>>> + if (!feat_supported(NULL, FEAT_EXTENDED_SYSCALL))
>>> + return libbpf_err(-EOPNOTSUPP);
>>
>> um.. I'm thinking that it would be better usability for libbpf to
>> ignore provided log if kernel doesn't support this feature just yet.
>> Then users don't have to care, they will just opportunistically
>> provide buffer and get extra error log, if kernel supports this
>> feature. Otherwise, log won't be touched, instead of failing an API
>> call.
>>
Agreed.
These two 'if's will be merged into one:
if (log_buf && feat_supported(NULL, FEAT_EXTENDED_SYSCALL)) {
...
}
>>> +
>>> + memset(&common_attrs, 0, sizeof(common_attrs));
>>> + common_attrs.log_buf = log_buf;
>>
>> ptr_to_u64(log_buf) here
>>
Ack.
>>> + common_attrs.log_size = OPTS_GET(opts, log_size, 0);
>>> + fd = sys_bpf_extended(BPF_MAP_CREATE, &attr, attr_sz, &common_attrs,
>>> + sizeof(common_attrs));
>>> + } else {
>>> + fd = sys_bpf_fd(BPF_MAP_CREATE, &attr, attr_sz);
>>> + }
>>> return libbpf_err_errno(fd);
>>> }
>>>
>>> diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
>>> index 38819071ecbe7..3b54d6feb5842 100644
>>> --- a/tools/lib/bpf/bpf.h
>>> +++ b/tools/lib/bpf/bpf.h
>>> @@ -55,9 +55,12 @@ struct bpf_map_create_opts {
>>> __s32 value_type_btf_obj_fd;
>>>
>>> __u32 token_fd;
>>> +
>>> + const char *log_buf;
>>> + __u32 log_size;
>
> also, what about that log_level ?
>
Should we really introduce log_level here?
I don’t think it makes sense, because logging in map_create is too
simple for different log levels on the kernel side to have any
meaningful effect.
Thanks,
Leon
next prev parent reply other threads:[~2025-09-23 16:40 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-11 16:33 [RFC PATCH bpf-next v2 0/6] bpf: Extend bpf syscall with common attributes support Leon Hwang
2025-09-11 16:33 ` [RFC PATCH bpf-next v2 1/6] " Leon Hwang
2025-09-17 0:06 ` Andrii Nakryiko
2025-09-23 15:23 ` Leon Hwang
2025-09-11 16:33 ` [RFC PATCH bpf-next v2 2/6] libbpf: Add support for extended bpf syscall Leon Hwang
2025-09-17 0:06 ` Andrii Nakryiko
2025-09-23 15:36 ` Leon Hwang
2025-09-24 23:57 ` Andrii Nakryiko
2025-09-11 16:33 ` [RFC PATCH bpf-next v2 3/6] bpf: Add common attr support for prog_load and btf_load Leon Hwang
2025-09-17 21:12 ` Andrii Nakryiko
2025-09-23 15:50 ` Leon Hwang
2025-09-25 0:00 ` Andrii Nakryiko
2025-09-11 16:33 ` [RFC PATCH bpf-next v2 4/6] bpf: Add common attr support for map_create Leon Hwang
2025-09-17 21:39 ` Andrii Nakryiko
2025-09-17 21:49 ` Alexei Starovoitov
2025-09-23 15:52 ` Leon Hwang
2025-09-23 16:27 ` Leon Hwang
2025-09-18 23:29 ` Eduard Zingerman
2025-09-23 16:31 ` Leon Hwang
2025-09-11 16:33 ` [RFC PATCH bpf-next v2 5/6] libbpf: " Leon Hwang
2025-09-17 21:45 ` Andrii Nakryiko
2025-09-17 21:46 ` Andrii Nakryiko
2025-09-23 16:40 ` Leon Hwang [this message]
2025-09-25 0:02 ` Andrii Nakryiko
2025-09-11 16:33 ` [RFC PATCH bpf-next v2 6/6] selftests/bpf: Add cases to test map create failure log Leon Hwang
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=2e8a73a9-67b9-4d87-844a-c43571055605@linux.dev \
--to=leon.hwang@linux.dev \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=menglong8.dong@gmail.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