Re: [PATCH bpf-next 2/3] bpf: map: Thread null elision metadata to map_gen_lookup
From: Alexei Starovoitov
Date: Wed Jan 22 2025 - 19:29:58 EST
On Mon, Jan 20, 2025 at 8:35 PM Daniel Xu <dxu@xxxxxxxxx> wrote:
>
> Add an extra parameter to map_gen_lookup callback so that if the lookup
> is known to be inbounds, the bounds check can be omitted.
>
> The next commit will take advantage of this new information.
>
> Signed-off-by: Daniel Xu <dxu@xxxxxxxxx>
> ---
> include/linux/bpf.h | 2 +-
> kernel/bpf/arraymap.c | 11 ++++++++---
> kernel/bpf/hashtab.c | 14 ++++++++++----
> kernel/bpf/verifier.c | 2 +-
> net/xdp/xskmap.c | 4 +++-
> 5 files changed, 23 insertions(+), 10 deletions(-)
>
> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index feda0ce90f5a..da8b420095c9 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -117,7 +117,7 @@ struct bpf_map_ops {
> * may manipulate it, exists.
> */
> void (*map_fd_put_ptr)(struct bpf_map *map, void *ptr, bool need_defer);
> - int (*map_gen_lookup)(struct bpf_map *map, struct bpf_insn *insn_buf);
> + int (*map_gen_lookup)(struct bpf_map *map, struct bpf_insn *insn_buf, bool inbounds);
The next time around we'd need another bool and more churn.
Let's use 'enum map_gen_flags flags' right away.
Also don't you want to pass an actual const_map_key
since its already known?
And the whole array_map_gen_lookup will become
single ld_imm64 insn.