All of lore.kernel.org
 help / color / mirror / Atom feed
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 v7 3/7] bpf: Add BPF_F_CPU and BPF_F_ALL_CPUS flags support for percpu_array maps
Date: Wed, 17 Sep 2025 23:04:03 +0800	[thread overview]
Message-ID: <DCV61D159UAO.1Q81016E9ENBL@linux.dev> (raw)
In-Reply-To: <CAEf4Bzb2WMEbw0x7RQQh6v43_OUcXGX-W_uDPGc6zO6nO5ZdXQ@mail.gmail.com>

On Wed Sep 17, 2025 at 7:44 AM +08, Andrii Nakryiko wrote:
> On Wed, Sep 10, 2025 at 9:28 AM Leon Hwang <leon.hwang@linux.dev> wrote:
>>
>> Introduce support for the BPF_F_ALL_CPUS flag in percpu_array maps to
>> allow updating values for all CPUs with a single value for both
>> update_elem and update_batch APIs.
>>
>> Introduce support for the BPF_F_CPU flag in percpu_array maps to allow:
>>
>> * update value for specified CPU for both update_elem and update_batch
>> APIs.
>> * lookup value for specified CPU for both lookup_elem and lookup_batch
>> APIs.
>>
>> The BPF_F_CPU flag is passed via:
>>
>> * map_flags of lookup_elem and update_elem APIs along with embedded cpu
>> info.
>> * elem_flags of lookup_batch and update_batch APIs along with embedded
>> cpu info.
>>
>> Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
>> ---
>>  include/linux/bpf.h   |  9 +++++++--
>>  kernel/bpf/arraymap.c | 24 +++++++++++++++++++++---
>>  kernel/bpf/syscall.c  |  2 +-
>>  3 files changed, 29 insertions(+), 6 deletions(-)
>>
>
> [...]
>
>>
>> -int bpf_percpu_array_copy(struct bpf_map *map, void *key, void *value)
>> +int bpf_percpu_array_copy(struct bpf_map *map, void *key, void *value, u64 map_flags)
>>  {
>>         struct bpf_array *array = container_of(map, struct bpf_array, map);
>>         u32 index = *(u32 *)key;
>> @@ -313,11 +313,18 @@ int bpf_percpu_array_copy(struct bpf_map *map, void *key, void *value)
>>         size = array->elem_size;
>>         rcu_read_lock();
>>         pptr = array->pptrs[index & array->index_mask];
>> +       if (map_flags & BPF_F_CPU) {
>> +               cpu = map_flags >> 32;
>> +               copy_map_value_long(map, value, per_cpu_ptr(pptr, cpu));
>> +               check_and_init_map_value(map, value);
>> +               goto unlock;
>
> goto is not how I'd structure this logic, I think if/else is a more
> logical structure here, but this works, I suppose...
>

My intention is to avoid putting the existing code inside a new 'else'
block, even if it would only affect indentation.

This way, the original code block stays intact, and git-blame will still
point to the commit that introduced it.

>> +       }
>>         for_each_possible_cpu(cpu) {
>>                 copy_map_value_long(map, value + off, per_cpu_ptr(pptr, cpu));
>>                 check_and_init_map_value(map, value + off);
>>                 off += size;
>>         }
>> +unlock:
>>         rcu_read_unlock();
>>         return 0;
>>  }
>> @@ -390,7 +397,7 @@ int bpf_percpu_array_update(struct bpf_map *map, void *key, void *value,
>>         int cpu, off = 0;
>>         u32 size;
>>
>> -       if (unlikely(map_flags > BPF_EXIST))
>> +       if (unlikely((u32)map_flags > BPF_F_ALL_CPUS))
>
> this will let through BPF_F_LOCK, no? which is not what you intended,
> right? So you need to check for
>
> (map_flags & BPF_F_LOCK) || (u32)map_flags > BPF_F_ALL_CPUS
>

Right.

I'll update it in next revision.

Thanks,
Leon

  reply	other threads:[~2025-09-17 15:04 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-10 16:27 [PATCH bpf-next v7 0/7] bpf: Introduce BPF_F_CPU and BPF_F_ALL_CPUS flags for percpu maps Leon Hwang
2025-09-10 16:27 ` [PATCH bpf-next v7 1/7] bpf: Introduce internal bpf_map_check_op_flags helper function Leon Hwang
2025-09-16 23:44   ` Andrii Nakryiko
2025-09-10 16:27 ` [PATCH bpf-next v7 2/7] bpf: Introduce BPF_F_CPU and BPF_F_ALL_CPUS flags Leon Hwang
2025-09-16 23:44   ` Andrii Nakryiko
2025-09-10 16:27 ` [PATCH bpf-next v7 3/7] bpf: Add BPF_F_CPU and BPF_F_ALL_CPUS flags support for percpu_array maps Leon Hwang
2025-09-16 23:44   ` Andrii Nakryiko
2025-09-17 15:04     ` Leon Hwang [this message]
2025-09-10 16:27 ` [PATCH bpf-next v7 4/7] bpf: Add BPF_F_CPU and BPF_F_ALL_CPUS flags support for percpu_hash and lru_percpu_hash maps Leon Hwang
2025-09-16 23:44   ` Andrii Nakryiko
2025-09-17 15:20     ` Leon Hwang
2025-09-17 19:11       ` Andrii Nakryiko
2025-09-18 16:07         ` Leon Hwang
2025-09-18 19:52           ` Andrii Nakryiko
2025-09-19  5:25     ` Leon Hwang
2025-09-19 22:31       ` Andrii Nakryiko
2025-09-22 14:50         ` Leon Hwang
2025-09-22 16:13           ` Andrii Nakryiko
2025-09-23  2:45             ` Leon Hwang
2025-09-24 23:47               ` Andrii Nakryiko
2025-09-10 16:27 ` [PATCH bpf-next v7 5/7] bpf: Add BPF_F_CPU and BPF_F_ALL_CPUS flags support for percpu_cgroup_storage maps Leon Hwang
2025-09-16 23:44   ` Andrii Nakryiko
2025-09-17 15:07     ` Leon Hwang
2025-09-17 19:12       ` Andrii Nakryiko
2025-09-18 15:38         ` Leon Hwang
2025-09-10 16:27 ` [PATCH bpf-next v7 6/7] libbpf: Add BPF_F_CPU and BPF_F_ALL_CPUS flags support for percpu maps Leon Hwang
2025-09-16 23:44   ` Andrii Nakryiko
2025-09-17 15:25     ` Leon Hwang
2025-09-10 16:27 ` [PATCH bpf-next v7 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=DCV61D159UAO.1Q81016E9ENBL@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.