Re: [PATCH v4 bpf-next 1/2] bpf: add a ksym BPF iterator

From: Andrii Nakryiko
Date: Fri Jul 08 2022 - 18:26:24 EST


On Wed, Jul 6, 2022 at 6:17 AM Alan Maguire <alan.maguire@xxxxxxxxxx> wrote:
>
> add a "ksym" iterator which provides access to a "struct kallsym_iter"
> for each symbol. Intent is to support more flexible symbol parsing
> as discussed in [1].
>
> [1] https://lore.kernel.org/all/YjRPZj6Z8vuLeEZo@krava/
>
> Suggested-by: Alexei Starovoitov <alexei.starovoitov@xxxxxxxxx>
> Signed-off-by: Alan Maguire <alan.maguire@xxxxxxxxxx>
> Acked-by: Yonghong Song <yhs@xxxxxx>
> ---
> kernel/kallsyms.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 95 insertions(+)
>

LGTM, except for unnecessary pr_warn(), see below


[...]

> +
> +BTF_ID_LIST(btf_ksym_iter_id)
> +BTF_ID(struct, kallsym_iter)
> +
> +static int __init bpf_ksym_iter_register(void)
> +{
> + int ret;
> +
> + ksym_iter_reg_info.ctx_arg_info[0].btf_id = *btf_ksym_iter_id;
> + ret = bpf_iter_reg_target(&ksym_iter_reg_info);
> + if (ret)
> + pr_warn("Warning: could not register bpf ksym iterator: %d\n", ret);

we don't emit such warnings for some other iterators I checked (map,
link, etc). Do we really need this? It's very unlikely to happen
anyways.

> + return ret;
> +}
> +
> +late_initcall(bpf_ksym_iter_register);
> +
> +#endif /* CONFIG_BPF_SYSCALL */
> +
> static inline int kallsyms_for_perf(void)
> {
> #ifdef CONFIG_PERF_EVENTS
> --
> 1.8.3.1
>