Re: [PATCH bpf-next v11 04/13] bpf: add struct_ops_tab to btf.

Martin KaFai Lau
2023-11-10T01:35:41Z

On 11/6/23 12:12 PM, thinker.li@gmail.com wrote:
> From: Kui-Feng Lee <thinker.li@gmail.com>
>
> Maintain a registry of registered struct_ops types in the per-btf (module)
> struct_ops_tab. This registry allows for easy lookup of struct_ops types
> that are registered by a specific module.
>
> It is a preparation work for supporting kernel module struct_ops in a
> latter patch. Each struct_ops will be registered under its own kernel
> module btf and will be stored in the newly added btf->struct_ops_tab. The
> bpf verifier and bpf syscall (e.g. prog and map cmd) can find the
> struct_ops and its btf type/size/id... information from
> btf->struct_ops_tab.
>
> Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com>
> ---
> include/linux/btf.h | 8 +++++
> kernel/bpf/btf.c | 83 +++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 91 insertions(+)
>
> diff --git a/include/linux/btf.h b/include/linux/btf.h
> index c2231c64d60b..07ee6740e06a 100644
> --- a/include/linux/btf.h
> +++ b/include/linux/btf.h
> @@ -572,4 +572,12 @@ static inline bool btf_type_is_struct_ptr(struct btf *btf, const struct btf_type
> return btf_type_is_struct(t);
> }
>
> +#ifdef CONFIG_BPF_JIT

There are many new ifdef CONFIG_BPF_JIT in btf.{h,c}. Could it be avoided? For
example, having an empty bpf_struct_ops_desc_init() for the not CONFIG_BPF_JIT
case, is it enough?

> +struct bpf_struct_ops_desc;
> +
> +const struct bpf_struct_ops_desc *
> +btf_get_struct_ops(struct btf *btf, u32 *ret_cnt);
> +
> +#endif /* CONFIG_BPF_JIT */
> +
> #endif