From: Yonghong Song <yhs@fb.com>
To: Cong Wang <xiyou.wangcong@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
kernel-team <kernel-team@fb.com>
Subject: Re: [PATCH bpf-next v3 04/11] bpf: add bpf_for_each_map_elem() helper
Date: Thu, 25 Feb 2021 19:27:58 -0800 [thread overview]
Message-ID: <0aa2660f-8d58-2a88-73f9-93b28e2a7a3f@fb.com> (raw)
In-Reply-To: <CAM_iQpUjQ1sD1pyk2GnCuoyMYBhDFcF0KY0Qg9uMtH8DRGGEMg@mail.gmail.com>
On 2/25/21 6:27 PM, Cong Wang wrote:
> On Wed, Feb 24, 2021 at 11:33 PM Yonghong Song <yhs@fb.com> wrote:
>> diff --git a/kernel/bpf/bpf_iter.c b/kernel/bpf/bpf_iter.c
>> index a0d9eade9c80..931870f9cf56 100644
>> --- a/kernel/bpf/bpf_iter.c
>> +++ b/kernel/bpf/bpf_iter.c
>> @@ -675,3 +675,19 @@ int bpf_iter_run_prog(struct bpf_prog *prog, void *ctx)
>> */
>> return ret == 0 ? 0 : -EAGAIN;
>> }
>> +
>> +BPF_CALL_4(bpf_for_each_map_elem, struct bpf_map *, map, void *, callback_fn,
>> + void *, callback_ctx, u64, flags)
>> +{
>> + return map->ops->map_for_each_callback(map, callback_fn, callback_ctx, flags);
>> +}
>
> A quick question: is ->map_for_each_callback() now mandatory for
> every map? I do not see you check for NULL here. Or you check map
> types somewhere I miss?
At the call site of bpf_for_each_map_elem(), verifier knows the map and
ensure check map->ops->map_for_each_callback() is not null. Otherwise,
it will reject the program. So we are fine here.
>
> At least some maps do not support iteration, for example, queue/stack.
> If you can document supported maps in bpf_for_each_map_elem() doc,
> it would be very nice.
Yes, will add more info in uapi/linux/bpf.h. Andrii suggested the same.
>
> Thanks for working on this!
You are welcome.
next prev parent reply other threads:[~2021-02-26 3:29 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-25 7:33 [PATCH bpf-next v3 00/11] bpf: add bpf_for_each_map_elem() helper Yonghong Song
2021-02-25 7:33 ` [PATCH bpf-next v3 01/11] bpf: factor out visit_func_call_insn() in check_cfg() Yonghong Song
2021-02-25 21:54 ` Andrii Nakryiko
2021-02-25 22:01 ` Alexei Starovoitov
2021-02-25 7:33 ` [PATCH bpf-next v3 02/11] bpf: factor out verbose_invalid_scalar() Yonghong Song
2021-02-25 21:56 ` Andrii Nakryiko
2021-02-25 7:33 ` [PATCH bpf-next v3 03/11] bpf: refactor check_func_call() to allow callback function Yonghong Song
2021-02-25 22:05 ` Andrii Nakryiko
2021-02-25 22:31 ` Andrii Nakryiko
2021-02-26 0:08 ` Yonghong Song
2021-02-26 1:18 ` Andrii Nakryiko
2021-02-26 0:05 ` Yonghong Song
2021-02-25 7:33 ` [PATCH bpf-next v3 04/11] bpf: add bpf_for_each_map_elem() helper Yonghong Song
2021-02-25 22:41 ` Andrii Nakryiko
2021-02-26 2:16 ` Yonghong Song
2021-02-26 3:22 ` Yonghong Song
2021-02-26 2:27 ` Cong Wang
2021-02-26 3:27 ` Yonghong Song [this message]
2021-02-25 7:33 ` [PATCH bpf-next v3 05/11] bpf: add hashtab support for " Yonghong Song
2021-02-25 22:44 ` Andrii Nakryiko
2021-02-25 7:33 ` [PATCH bpf-next v3 06/11] bpf: add arraymap " Yonghong Song
2021-02-25 22:48 ` Andrii Nakryiko
2021-02-25 7:33 ` [PATCH bpf-next v3 07/11] libbpf: move function is_ldimm64() earlier in libbpf.c Yonghong Song
2021-02-25 7:33 ` [PATCH bpf-next v3 08/11] libbpf: support subprog address relocation Yonghong Song
2021-02-25 23:04 ` Andrii Nakryiko
2021-02-25 7:33 ` [PATCH bpf-next v3 09/11] bpftool: print subprog address properly Yonghong Song
2021-02-25 23:04 ` Andrii Nakryiko
2021-02-25 7:33 ` [PATCH bpf-next v3 10/11] selftests/bpf: add hashmap test for bpf_for_each_map_elem() helper Yonghong Song
2021-02-25 23:25 ` Andrii Nakryiko
2021-02-26 3:24 ` Yonghong Song
2021-02-25 7:33 ` [PATCH bpf-next v3 11/11] selftests/bpf: add arraymap " Yonghong Song
2021-02-25 23:26 ` Andrii Nakryiko
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=0aa2660f-8d58-2a88-73f9-93b28e2a7a3f@fb.com \
--to=yhs@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=xiyou.wangcong@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