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, 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 2/3] bpf, libbpf: Support BPF_F_CPU for percpu_array map
Date: Tue, 22 Jul 2025 01:13:09 +0800	[thread overview]
Message-ID: <f05cb3d9-b9dd-4ef6-9943-b98224be2f13@linux.dev> (raw)
In-Reply-To: <CAEf4BzYNRwgqbBN3QiPxMbsbtYOoV1Da3mqMhtgE8jPw6eYUXw@mail.gmail.com>



On 2025/7/18 23:57, Andrii Nakryiko wrote:
> On Thu, Jul 17, 2025 at 12:38 PM Leon Hwang <leon.hwang@linux.dev> wrote:
>>
>> This patch adds libbpf support for the BPF_F_CPU flag in percpu_array maps,
>> introducing the following APIs:
>>
>> 1. bpf_map_update_elem_opts(): update with struct bpf_map_update_elem_opts
>> 2. bpf_map_lookup_elem_opts(): lookup with struct bpf_map_lookup_elem_opts
>> 3. bpf_map__update_elem_opts(): high-level wrapper with input validation
>> 4. bpf_map__lookup_elem_opts(): high-level wrapper with input validation
>>
>> Behavior:
>>
>> * If opts->cpu == (u32)~0, the update is applied to all CPUs.
>> * Otherwise, it applies only to the specified CPU.
>> * Lookup APIs retrieve values from the target CPU when BPF_F_CPU is used.
>>
>> Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
>> ---
> 
> please use "libbpf: " prefix, not "bpf,libbpf:"
> 

Ack.

> 
> Then see my comment on flags vs separate field for cpu passing. If we
> go with just using flags, then I'd probably drop all the new libbpf
> APIs, because we already have bpf_map_lookup_elem_flags() and
> bpf_map_update_elem() (the latter accepts flags), so as far as
> low-level API we are good.
> 

All the new libbpf APIs are unnecessary when pass the cpu through flags.

> The comment describing the new BPF_F_CPU flag is good, so let's add
> it, but place it into bpf_map__lookup_elem() description (which, btw,
> also accepts flags, so no changes to API itself is necessary). Same
> for bpf_map__update_elem().
> 

No problem.

> validate_map_op() logic will stay, but just will extract cpu from flags, right?
> 

Yes, it is.

> So overall less API churn, but same possibilities for users (plus we
> get better documentation, which is always nice).
> 

When users want to use this feature, they should follow the libbpf API's
documentation, no matter whether the cpu is separated or flags-embedded.

Thanks,
Leon

>>  tools/lib/bpf/bpf.c           | 23 ++++++++++++++
>>  tools/lib/bpf/bpf.h           | 36 +++++++++++++++++++++-
>>  tools/lib/bpf/libbpf.c        | 56 +++++++++++++++++++++++++++++++----
>>  tools/lib/bpf/libbpf.h        | 53 ++++++++++++++++++++++++++++-----
>>  tools/lib/bpf/libbpf.map      |  5 ++++
>>  tools/lib/bpf/libbpf_common.h | 14 +++++++++
>>  6 files changed, 173 insertions(+), 14 deletions(-)
>>
> 
> [...]


  reply	other threads:[~2025-07-21 17:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-17 19:37 [PATCH bpf-next 0/3] bpf: Introduce BPF_F_CPU flag for percpu_array map Leon Hwang
2025-07-17 19:37 ` [PATCH bpf-next 1/3] " Leon Hwang
2025-07-18 15:52   ` Andrii Nakryiko
2025-07-21 17:08     ` Leon Hwang
2025-07-21 17:11       ` Eduard Zingerman
2025-07-22 14:29         ` Leon Hwang
2025-07-17 19:37 ` [PATCH bpf-next 2/3] bpf, libbpf: Support BPF_F_CPU " Leon Hwang
2025-07-18 15:57   ` Andrii Nakryiko
2025-07-21 17:13     ` Leon Hwang [this message]
2025-07-17 19:37 ` [PATCH bpf-next 3/3] selftests/bpf: Add case to test BPF_F_CPU 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=f05cb3d9-b9dd-4ef6-9943-b98224be2f13@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=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.