bpf: Move __kfunc_param_match_suffix() to btf.c.
Move __kfunc_param_match_suffix() to btf.c and rename it as btf_param_match_suffix(). It can be reused by bpf_struct_ops later. Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com> Link: https://lore.kernel.org/r/20240209023750.1153905-3-thinker.li@gmail.com Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
This commit is contained in:
parent
77c0208e19
commit
6115a0aeef
@ -495,6 +495,10 @@ static inline void *btf_id_set8_contains(const struct btf_id_set8 *set, u32 id)
|
||||
return bsearch(&id, set->pairs, set->cnt, sizeof(set->pairs[0]), btf_id_cmp_func);
|
||||
}
|
||||
|
||||
bool btf_param_match_suffix(const struct btf *btf,
|
||||
const struct btf_param *arg,
|
||||
const char *suffix);
|
||||
|
||||
struct bpf_verifier_log;
|
||||
|
||||
#if defined(CONFIG_BPF_JIT) && defined(CONFIG_BPF_SYSCALL)
|
||||
|
@ -8904,3 +8904,21 @@ errout:
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(__register_bpf_struct_ops);
|
||||
#endif
|
||||
|
||||
bool btf_param_match_suffix(const struct btf *btf,
|
||||
const struct btf_param *arg,
|
||||
const char *suffix)
|
||||
{
|
||||
int suffix_len = strlen(suffix), len;
|
||||
const char *param_name;
|
||||
|
||||
/* In the future, this can be ported to use BTF tagging */
|
||||
param_name = btf_name_by_offset(btf, arg->name_off);
|
||||
if (str_is_empty(param_name))
|
||||
return false;
|
||||
len = strlen(param_name);
|
||||
if (len <= suffix_len)
|
||||
return false;
|
||||
param_name += len - suffix_len;
|
||||
return !strncmp(param_name, suffix, suffix_len);
|
||||
}
|
||||
|
@ -10682,24 +10682,6 @@ static bool is_kfunc_rcu_protected(struct bpf_kfunc_call_arg_meta *meta)
|
||||
return meta->kfunc_flags & KF_RCU_PROTECTED;
|
||||
}
|
||||
|
||||
static bool __kfunc_param_match_suffix(const struct btf *btf,
|
||||
const struct btf_param *arg,
|
||||
const char *suffix)
|
||||
{
|
||||
int suffix_len = strlen(suffix), len;
|
||||
const char *param_name;
|
||||
|
||||
/* In the future, this can be ported to use BTF tagging */
|
||||
param_name = btf_name_by_offset(btf, arg->name_off);
|
||||
if (str_is_empty(param_name))
|
||||
return false;
|
||||
len = strlen(param_name);
|
||||
if (len < suffix_len)
|
||||
return false;
|
||||
param_name += len - suffix_len;
|
||||
return !strncmp(param_name, suffix, suffix_len);
|
||||
}
|
||||
|
||||
static bool is_kfunc_arg_mem_size(const struct btf *btf,
|
||||
const struct btf_param *arg,
|
||||
const struct bpf_reg_state *reg)
|
||||
@ -10710,7 +10692,7 @@ static bool is_kfunc_arg_mem_size(const struct btf *btf,
|
||||
if (!btf_type_is_scalar(t) || reg->type != SCALAR_VALUE)
|
||||
return false;
|
||||
|
||||
return __kfunc_param_match_suffix(btf, arg, "__sz");
|
||||
return btf_param_match_suffix(btf, arg, "__sz");
|
||||
}
|
||||
|
||||
static bool is_kfunc_arg_const_mem_size(const struct btf *btf,
|
||||
@ -10723,47 +10705,47 @@ static bool is_kfunc_arg_const_mem_size(const struct btf *btf,
|
||||
if (!btf_type_is_scalar(t) || reg->type != SCALAR_VALUE)
|
||||
return false;
|
||||
|
||||
return __kfunc_param_match_suffix(btf, arg, "__szk");
|
||||
return btf_param_match_suffix(btf, arg, "__szk");
|
||||
}
|
||||
|
||||
static bool is_kfunc_arg_optional(const struct btf *btf, const struct btf_param *arg)
|
||||
{
|
||||
return __kfunc_param_match_suffix(btf, arg, "__opt");
|
||||
return btf_param_match_suffix(btf, arg, "__opt");
|
||||
}
|
||||
|
||||
static bool is_kfunc_arg_constant(const struct btf *btf, const struct btf_param *arg)
|
||||
{
|
||||
return __kfunc_param_match_suffix(btf, arg, "__k");
|
||||
return btf_param_match_suffix(btf, arg, "__k");
|
||||
}
|
||||
|
||||
static bool is_kfunc_arg_ignore(const struct btf *btf, const struct btf_param *arg)
|
||||
{
|
||||
return __kfunc_param_match_suffix(btf, arg, "__ign");
|
||||
return btf_param_match_suffix(btf, arg, "__ign");
|
||||
}
|
||||
|
||||
static bool is_kfunc_arg_alloc_obj(const struct btf *btf, const struct btf_param *arg)
|
||||
{
|
||||
return __kfunc_param_match_suffix(btf, arg, "__alloc");
|
||||
return btf_param_match_suffix(btf, arg, "__alloc");
|
||||
}
|
||||
|
||||
static bool is_kfunc_arg_uninit(const struct btf *btf, const struct btf_param *arg)
|
||||
{
|
||||
return __kfunc_param_match_suffix(btf, arg, "__uninit");
|
||||
return btf_param_match_suffix(btf, arg, "__uninit");
|
||||
}
|
||||
|
||||
static bool is_kfunc_arg_refcounted_kptr(const struct btf *btf, const struct btf_param *arg)
|
||||
{
|
||||
return __kfunc_param_match_suffix(btf, arg, "__refcounted_kptr");
|
||||
return btf_param_match_suffix(btf, arg, "__refcounted_kptr");
|
||||
}
|
||||
|
||||
static bool is_kfunc_arg_nullable(const struct btf *btf, const struct btf_param *arg)
|
||||
{
|
||||
return __kfunc_param_match_suffix(btf, arg, "__nullable");
|
||||
return btf_param_match_suffix(btf, arg, "__nullable");
|
||||
}
|
||||
|
||||
static bool is_kfunc_arg_const_str(const struct btf *btf, const struct btf_param *arg)
|
||||
{
|
||||
return __kfunc_param_match_suffix(btf, arg, "__str");
|
||||
return btf_param_match_suffix(btf, arg, "__str");
|
||||
}
|
||||
|
||||
static bool is_kfunc_arg_scalar_with_name(const struct btf *btf,
|
||||
|
Loading…
Reference in New Issue
Block a user