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
Subject: Re: [RFC PATCH bpf-next v3 02/10] libbpf: Add support for extended bpf syscall
Date: Thu, 9 Oct 2025 13:15:01 +0800 [thread overview]
Message-ID: <e8580e7e-05f5-4b28-9709-1b46712469a2@linux.dev> (raw)
In-Reply-To: <CAEf4BzZm+51H6hRq1UOTyXi7UtRX9o3Y8Fr_GS_UkaqJJX4d1g@mail.gmail.com>
On 7/10/25 07:08, Andrii Nakryiko wrote:
> On Thu, Oct 2, 2025 at 8:49 AM Leon Hwang <leon.hwang@linux.dev> wrote:
>>
>> To support the extended 'bpf()' syscall introduced in the previous commit,
>> introduce the following internal APIs:
>>
>> * 'sys_bpf_ext()'
>> * 'sys_bpf_ext_fd()'
>> They wrap the raw 'syscall()' interface to support passing extended
>> attributes.
>> * 'probe_sys_bpf_ext()'
>> Check whether current kernel supports the extended attributes.
>>
>> Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
>> ---
>> tools/lib/bpf/bpf.c | 33 +++++++++++++++++++++++++++++++++
>> tools/lib/bpf/features.c | 8 ++++++++
>> tools/lib/bpf/libbpf_internal.h | 3 +++
>> 3 files changed, 44 insertions(+)
>>
>> diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
>> index 339b197972374..9cd79beb13a2d 100644
>> --- a/tools/lib/bpf/bpf.c
>> +++ b/tools/lib/bpf/bpf.c
>> @@ -69,6 +69,39 @@ static inline __u64 ptr_to_u64(const void *ptr)
>> return (__u64) (unsigned long) ptr;
>> }
>>
>> +static inline int sys_bpf_ext(enum bpf_cmd cmd, union bpf_attr *attr,
>> + unsigned int size,
>> + struct bpf_common_attr *common_attrs,
>> + unsigned int size_common)
>> +{
>> + cmd = common_attrs ? cmd | BPF_COMMON_ATTRS : cmd & ~BPF_COMMON_ATTRS;
>
> nit: put those () two branches of ternary operator, there is no need
> to rely on obscure C operator precedence order here
>
Ack.
>> + return syscall(__NR_bpf, cmd, attr, size, common_attrs, size_common);
>> +}
>> +
>> +static inline int sys_bpf_ext_fd(enum bpf_cmd cmd, union bpf_attr *attr,
>> + unsigned int size,
>> + struct bpf_common_attr *common_attrs,
>> + unsigned int size_common)
>> +{
>> + int fd;
>> +
>> + fd = sys_bpf_ext(cmd, attr, size, common_attrs, size_common);
>> + return ensure_good_fd(fd);
>> +}
>> +
>> +int probe_sys_bpf_ext(void)
>> +{
>> + const size_t attr_sz = offsetofend(union bpf_attr, prog_token_fd);
>> + union bpf_attr attr;
>> + int fd;
>> +
>> + memset(&attr, 0, attr_sz);
>> + fd = syscall(__NR_bpf, BPF_PROG_LOAD | BPF_COMMON_ATTRS, &attr, attr_sz, NULL,
>> + sizeof(struct bpf_common_attr));
>> + fd = errno == EFAULT ? syscall(__NR_memfd_create, "fd", 0) : fd;
>> + return ensure_good_fd(fd);
>
> why do we need to create FD?..
>
>> +}
>> +
>> static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr,
>> unsigned int size)
>> {
>> diff --git a/tools/lib/bpf/features.c b/tools/lib/bpf/features.c
>> index 760657f5224c2..d01df62394f89 100644
>> --- a/tools/lib/bpf/features.c
>> +++ b/tools/lib/bpf/features.c
>> @@ -507,6 +507,11 @@ static int probe_kern_arg_ctx_tag(int token_fd)
>> return probe_fd(prog_fd);
>> }
>>
>> +static int probe_kern_extended_syscall(int token_fd)
>> +{
>> + return probe_fd(probe_sys_bpf_ext());
>> +}
>> +
>
> just do that feature detection right here without creating any new
> FDs... make sys_bpf_ext() exposed just like we do that with sys_bpf()
> and use this here
>
Ack.
Then I'll expose sys_bpf_ext() directly without creating any new FDs.
Thanks,
Leon
[...]
next prev parent reply other threads:[~2025-10-09 5:15 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-02 15:48 [RFC PATCH bpf-next v3 00/10] bpf: Extend bpf syscall with common attributes support Leon Hwang
2025-10-02 15:48 ` [RFC PATCH bpf-next v3 01/10] " Leon Hwang
2025-10-02 15:48 ` [RFC PATCH bpf-next v3 02/10] libbpf: Add support for extended bpf syscall Leon Hwang
2025-10-06 23:08 ` Andrii Nakryiko
2025-10-09 5:15 ` Leon Hwang [this message]
2025-10-02 15:48 ` [RFC PATCH bpf-next v3 03/10] bpf: Refactor reporting log_true_size for prog_load Leon Hwang
2025-10-02 18:34 ` Alexei Starovoitov
2025-10-03 2:06 ` Leon Hwang
2025-10-02 15:48 ` [RFC PATCH bpf-next v3 04/10] bpf: Add common attr support " Leon Hwang
2025-10-02 23:51 ` Alexei Starovoitov
2025-10-03 2:25 ` Leon Hwang
2025-10-02 15:48 ` [RFC PATCH bpf-next v3 05/10] bpf: Refactor reporting btf_log_true_size for btf_load Leon Hwang
2025-10-02 15:48 ` [RFC PATCH bpf-next v3 06/10] bpf: Add common attr support " Leon Hwang
2025-10-02 15:48 ` [RFC PATCH bpf-next v3 07/10] bpf: Add warnings for internal bugs in map_create Leon Hwang
2025-10-03 0:06 ` Alexei Starovoitov
2025-10-03 2:31 ` Leon Hwang
2025-10-02 15:48 ` [RFC PATCH bpf-next v3 08/10] bpf: Add common attr support for map_create Leon Hwang
2025-10-02 15:48 ` [RFC PATCH bpf-next v3 09/10] libbpf: " Leon Hwang
2025-10-06 23:08 ` Andrii Nakryiko
2025-10-09 5:35 ` Leon Hwang
2025-10-02 15:48 ` [RFC PATCH bpf-next v3 10/10] selftests/bpf: Add cases to test map create failure log Leon Hwang
2025-10-03 6:38 ` [syzbot ci] Re: bpf: Extend bpf syscall with common attributes support syzbot ci
2025-10-03 6:44 ` 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=e8580e7e-05f5-4b28-9709-1b46712469a2@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 \
/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