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

From: Alexei Starovoitov
Date: Wed Jul 06 2022 - 00:20:14 EST


On Mon, Jul 4, 2022 at 6:55 AM Alan Maguire <alan.maguire@xxxxxxxxxx> wrote:
> static inline int kallsyms_for_perf(void)
> {
> #ifdef CONFIG_PERF_EVENTS
> @@ -885,6 +967,18 @@ const char *kdb_walk_kallsyms(loff_t *pos)
> static int __init kallsyms_init(void)
> {
> proc_create("kallsyms", 0444, NULL, &kallsyms_proc_ops);
> +#if defined(CONFIG_BPF_SYSCALL)
> + {
> + 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);
> + return ret;
> + }
> + }
> +#endif

The ifdef-s inside the function body are not pretty.
I feel the v2 version was cleaner.
static void __init bpf_ksym_iter_register()
were only missing late_initcall(bpf_ksym_iter_register);
to make it single #ifdef CONFIG_BPF_SYSCALL for everything.
wdyt?