Commit b32a5dae authored by Dave Marchevsky's avatar Dave Marchevsky Committed by Alexei Starovoitov

bpf: verifier: Rename kernel_type_name helper to btf_type_name

kernel_type_name was introduced in commit 9e15db66 ("bpf: Implement accurate raw_tp context access via BTF")
with type signature:

  const char *kernel_type_name(u32 id)

At that time the function used global btf_vmlinux BTF for all id lookups. Later,
in commit 22dc4a0f ("bpf: Remove hard-coded btf_vmlinux assumption from BPF verifier"),
the type signature was changed to:

  static const char *kernel_type_name(const struct btf* btf, u32 id)

With the btf parameter used for lookups instead of global btf_vmlinux.

The helper will function as expected for type name lookup using non-kernel BTFs,
and will be used for such in further patches in the series. Let's rename it to
avoid incorrect assumptions that might arise when seeing the current name.
Signed-off-by: default avatarDave Marchevsky <davemarchevsky@fb.com>
Link: https://lore.kernel.org/r/20230309180111.1618459-2-davemarchevsky@fb.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 4659fba1
...@@ -752,7 +752,7 @@ static int iter_get_spi(struct bpf_verifier_env *env, struct bpf_reg_state *reg, ...@@ -752,7 +752,7 @@ static int iter_get_spi(struct bpf_verifier_env *env, struct bpf_reg_state *reg,
return stack_slot_obj_get_spi(env, reg, "iter", nr_slots); return stack_slot_obj_get_spi(env, reg, "iter", nr_slots);
} }
static const char *kernel_type_name(const struct btf* btf, u32 id) static const char *btf_type_name(const struct btf *btf, u32 id)
{ {
return btf_name_by_offset(btf, btf_type_by_id(btf, id)->name_off); return btf_name_by_offset(btf, btf_type_by_id(btf, id)->name_off);
} }
...@@ -782,7 +782,7 @@ static const char *iter_type_str(const struct btf *btf, u32 btf_id) ...@@ -782,7 +782,7 @@ static const char *iter_type_str(const struct btf *btf, u32 btf_id)
return "<invalid>"; return "<invalid>";
/* we already validated that type is valid and has conforming name */ /* we already validated that type is valid and has conforming name */
return kernel_type_name(btf, btf_id) + sizeof(ITER_PREFIX) - 1; return btf_type_name(btf, btf_id) + sizeof(ITER_PREFIX) - 1;
} }
static const char *iter_state_str(enum bpf_iter_state state) static const char *iter_state_str(enum bpf_iter_state state)
...@@ -1349,7 +1349,7 @@ static void print_verifier_state(struct bpf_verifier_env *env, ...@@ -1349,7 +1349,7 @@ static void print_verifier_state(struct bpf_verifier_env *env,
verbose(env, "%s", reg_type_str(env, t)); verbose(env, "%s", reg_type_str(env, t));
if (base_type(t) == PTR_TO_BTF_ID) if (base_type(t) == PTR_TO_BTF_ID)
verbose(env, "%s", kernel_type_name(reg->btf, reg->btf_id)); verbose(env, "%s", btf_type_name(reg->btf, reg->btf_id));
verbose(env, "("); verbose(env, "(");
/* /*
* _a stands for append, was shortened to avoid multiline statements below. * _a stands for append, was shortened to avoid multiline statements below.
...@@ -4518,7 +4518,7 @@ static int map_kptr_match_type(struct bpf_verifier_env *env, ...@@ -4518,7 +4518,7 @@ static int map_kptr_match_type(struct bpf_verifier_env *env,
struct btf_field *kptr_field, struct btf_field *kptr_field,
struct bpf_reg_state *reg, u32 regno) struct bpf_reg_state *reg, u32 regno)
{ {
const char *targ_name = kernel_type_name(kptr_field->kptr.btf, kptr_field->kptr.btf_id); const char *targ_name = btf_type_name(kptr_field->kptr.btf, kptr_field->kptr.btf_id);
int perm_flags = PTR_MAYBE_NULL | PTR_TRUSTED | MEM_RCU; int perm_flags = PTR_MAYBE_NULL | PTR_TRUSTED | MEM_RCU;
const char *reg_name = ""; const char *reg_name = "";
...@@ -4534,7 +4534,7 @@ static int map_kptr_match_type(struct bpf_verifier_env *env, ...@@ -4534,7 +4534,7 @@ static int map_kptr_match_type(struct bpf_verifier_env *env,
return -EINVAL; return -EINVAL;
} }
/* We need to verify reg->type and reg->btf, before accessing reg->btf */ /* We need to verify reg->type and reg->btf, before accessing reg->btf */
reg_name = kernel_type_name(reg->btf, reg->btf_id); reg_name = btf_type_name(reg->btf, reg->btf_id);
/* For ref_ptr case, release function check should ensure we get one /* For ref_ptr case, release function check should ensure we get one
* referenced PTR_TO_BTF_ID, and that its fixed offset is 0. For the * referenced PTR_TO_BTF_ID, and that its fixed offset is 0. For the
...@@ -7177,8 +7177,8 @@ static int check_reg_type(struct bpf_verifier_env *env, u32 regno, ...@@ -7177,8 +7177,8 @@ static int check_reg_type(struct bpf_verifier_env *env, u32 regno,
btf_vmlinux, *arg_btf_id, btf_vmlinux, *arg_btf_id,
strict_type_match)) { strict_type_match)) {
verbose(env, "R%d is of type %s but %s is expected\n", verbose(env, "R%d is of type %s but %s is expected\n",
regno, kernel_type_name(reg->btf, reg->btf_id), regno, btf_type_name(reg->btf, reg->btf_id),
kernel_type_name(btf_vmlinux, *arg_btf_id)); btf_type_name(btf_vmlinux, *arg_btf_id));
return -EACCES; return -EACCES;
} }
} }
...@@ -7248,7 +7248,7 @@ int check_func_arg_reg_off(struct bpf_verifier_env *env, ...@@ -7248,7 +7248,7 @@ int check_func_arg_reg_off(struct bpf_verifier_env *env,
verbose(env, "R%d must have zero offset when passed to release func\n", verbose(env, "R%d must have zero offset when passed to release func\n",
regno); regno);
verbose(env, "No graph node or root found at R%d type:%s off:%d\n", regno, verbose(env, "No graph node or root found at R%d type:%s off:%d\n", regno,
kernel_type_name(reg->btf, reg->btf_id), reg->off); btf_type_name(reg->btf, reg->btf_id), reg->off);
return -EINVAL; return -EINVAL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment