Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Failure to short-circuit BTF loading when the requested module list is empty.
--
--- Patch [1]: [PATCH bpf-next v4 1/2] libbpf: support selective kernel module BTF loading via bpf_object_open_opts ---
commit 45ee1cea8b0fa604bfa594a065030f18301877c5
Author: Fuyu Zhao <[email protected]>
libbpf: support selective kernel module BTF loading via bpf_object_open_opts
This commit adds btf_module_names and nr_btf_module_names to
bpf_object_open_opts, allowing selective loading of kernel module BTFs. When a
list is provided, libbpf will skip module BTFs not in the list to reduce BPF
object loading time.
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index b749c01742ee0..d8ef6ecc6f5dd 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
[ ... ]
> @@ -5851,6 +5854,94 @@ int bpf_core_add_cands(struct bpf_core_cand *local_cand,
[ ... ]
> +static bool all_needed_module_btfs_loaded(const struct bpf_object *obj)
> +{
> + return obj->btf_module_names &&
> + obj->nr_btf_module_names == obj->btf_module_cnt;
> +}
> +
> static int load_module_btfs(struct bpf_object *obj)
> {
[Severity: Medium]
Could we short-circuit this function earlier when the requested module list is
empty?
If a user passes a non-NULL btf_module_names with nr_btf_module_names = 0
(meaning no module BTFs should be loaded), this function still proceeds into
the while (true) loop, issuing system calls for every BTF object on the
system.
[ ... ]
> @@ -5915,6 +6006,11 @@ static int load_module_btfs(struct bpf_object *obj)
> continue;
> }
>
> + if (!is_module_btf_needed(obj, name)) {
> + close(fd);
> + continue;
> + }
> +
[Severity: Medium]
Does this continue bypass the early exit check when nr_btf_module_names is 0?
When the requested list is empty, is_module_btf_needed() always returns false,
triggering this continue on every iteration. This skips the
all_needed_module_btfs_loaded() check at the bottom of the loop entirely,
causing the loop to exhaustively iterate all BTFs unnecessarily.
> btf = btf_get_from_fd(fd, obj->btf_vmlinux);
> err = libbpf_get_error(btf);
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.