bpf: store both map ptr and state in bpf_insn_aux_data
authorPhilo Lu <lulie@linux.alibaba.com>
Fri, 5 Apr 2024 02:55:34 +0000 (10:55 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 5 Apr 2024 17:31:17 +0000 (10:31 -0700)
commit0a525621b7e5b49202b19d8f75382c6778fdd0c1
tree15aca0b681bfa152ff7768390965942dcbe6026b
parent58babe27180c8d4cb54d831589cf801bd9268876
bpf: store both map ptr and state in bpf_insn_aux_data

Currently, bpf_insn_aux_data->map_ptr_state is used to store either
map_ptr or its poison state (i.e., BPF_MAP_PTR_POISON). Thus
BPF_MAP_PTR_POISON must be checked before reading map_ptr. In certain
cases, we may need valid map_ptr even in case of poison state.
This will be explained in next patch with bpf_for_each_map_elem()
helper.

This patch changes map_ptr_state into a new struct including both map
pointer and its state (poison/unpriv). It's in the same union with
struct bpf_loop_inline_state, so there is no extra memory overhead.
Besides, macros BPF_MAP_PTR_UNPRIV/BPF_MAP_PTR_POISON/BPF_MAP_PTR are no
longer needed.

This patch does not change any existing functionality.

Signed-off-by: Philo Lu <lulie@linux.alibaba.com>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20240405025536.18113-2-lulie@linux.alibaba.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/bpf_verifier.h
kernel/bpf/verifier.c