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>, <jolsa@kernel.org>,
<yonghong.song@linux.dev>, <song@kernel.org>, <eddyz87@gmail.com>,
<dxu@dxuuu.xyz>, <deso@posteo.net>, <kernel-patches-bot@fb.com>
Subject: Re: [PATCH bpf-next v4 1/7] bpf: Introduce internal bpf_map_check_op_flags helper function
Date: Wed, 03 Sep 2025 22:39:16 +0800 [thread overview]
Message-ID: <DCJ8QRHELLM0.2A30YCC5EUXUQ@linux.dev> (raw)
In-Reply-To: <CAEf4BzbuhaWSE6-1fnxYhUX_6iaBvrr6Q1Mq05MhuxE7U4_63A@mail.gmail.com>
On Thu Aug 28, 2025 at 7:17 AM +08, Andrii Nakryiko wrote:
> On Wed, Aug 27, 2025 at 9:45 AM Leon Hwang <leon.hwang@linux.dev> wrote:
>>
>> It is to unify map flags checking for lookup_elem, update_elem,
>> lookup_batch and update_batch APIs.
>>
>> Therefore, it will be convenient to check BPF_F_CPU and BPF_F_ALL_CPUS
>> flags in it for these APIs in next patch.
>>
>> Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
>> ---
>> include/linux/bpf.h | 28 ++++++++++++++++++++++++++++
>> kernel/bpf/syscall.c | 34 +++++++++++-----------------------
>> 2 files changed, 39 insertions(+), 23 deletions(-)
>>
>> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
>> index 8f6e87f0f3a89..512717d442c09 100644
>> --- a/include/linux/bpf.h
>> +++ b/include/linux/bpf.h
>> @@ -3709,4 +3709,32 @@ int bpf_prog_get_file_line(struct bpf_prog *prog, unsigned long ip, const char *
>> const char **linep, int *nump);
>> struct bpf_prog *bpf_prog_find_from_stack(void);
>>
>> +static inline int bpf_map_check_op_flags(struct bpf_map *map, u64 flags, u64 extra_flags_mask)
>> +{
>> + if (extra_flags_mask && (flags & extra_flags_mask))
>
> doh, Leon... when extra_flags_mask == 0, `flags & extra_flags_mask` is
> always false, so just:
>
> if (flags & extra_flags_mask)
> return -EINVAL;
>
> But it feels more natural to reverse the meaning of this and treat it
> as extra *allowed flags*. So zero would mean no extra flags should be
> there (most strict case) and ~0 would mean "we don't care or will
> check later". And so in the code you'd have
>
> if (flags & ~extra_flags) /* check for any unsupported flags */
> return -EINVAL;
>
> But I need someone else to do a reality check on me here at this point.
>
It seems clearer to handle this as additional *allowed flags*. That would
make it more understandable.
Thanks,
Leon
next prev parent reply other threads:[~2025-09-03 14:39 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-27 16:45 [PATCH bpf-next v4 0/7] bpf: Introduce BPF_F_CPU and BPF_F_ALL_CPUS flags for percpu maps Leon Hwang
2025-08-27 16:45 ` [PATCH bpf-next v4 1/7] bpf: Introduce internal bpf_map_check_op_flags helper function Leon Hwang
2025-08-27 23:17 ` Andrii Nakryiko
2025-09-03 14:39 ` Leon Hwang [this message]
2025-08-27 16:45 ` [PATCH bpf-next v4 2/7] bpf: Introduce BPF_F_CPU and BPF_F_ALL_CPUS flags Leon Hwang
2025-08-27 23:18 ` Andrii Nakryiko
2025-09-03 14:26 ` Leon Hwang
2025-09-03 23:53 ` Andrii Nakryiko
2025-09-04 2:36 ` Leon Hwang
2025-08-27 16:45 ` [PATCH bpf-next v4 3/7] bpf: Introduce BPF_F_CPU and BPF_F_ALL_CPUS flags for percpu_array maps Leon Hwang
2025-08-27 16:45 ` [PATCH bpf-next v4 4/7] bpf: Introduce BPF_F_CPU and BPF_F_ALL_CPUS flags for percpu_hash and lru_percpu_hash maps Leon Hwang
2025-08-27 23:18 ` Andrii Nakryiko
2025-09-03 14:30 ` Leon Hwang
2025-08-27 16:45 ` [PATCH bpf-next v4 5/7] bpf: Introduce BPF_F_CPU and BPF_F_ALL_CPUS flags for percpu_cgroup_storage maps Leon Hwang
2025-08-27 16:45 ` [PATCH bpf-next v4 6/7] libbpf: Support BPF_F_CPU and BPF_F_ALL_CPUS flags for percpu maps Leon Hwang
2025-08-27 23:18 ` Andrii Nakryiko
2025-09-03 14:33 ` Leon Hwang
2025-08-27 16:45 ` [PATCH bpf-next v4 7/7] selftests/bpf: Add cases to test BPF_F_CPU and BPF_F_ALL_CPUS flags 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=DCJ8QRHELLM0.2A30YCC5EUXUQ@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=deso@posteo.net \
--cc=dxu@dxuuu.xyz \
--cc=eddyz87@gmail.com \
--cc=jolsa@kernel.org \
--cc=kernel-patches-bot@fb.com \
--cc=song@kernel.org \
--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 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.