Skip to contentSkip to conversation

libbpf: Fix incorrect module BTF fd index in warning

PATCH In review Rahad Bhuiya 2 participants 2 messages Nov 11

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libbpf: Fix incorrect module BTF fd index in warning

When the number of used module BTF slots in fd_array reaches INT16_MAX, resolving an extern func ksym fails with -E2BIG. However, the warning message logs mod_btf->fd_array_idx, which is guaranteed to be 0 at this point because it has not yet been assigned from obj->fd_array_used.

Use obj->fd_array_used with the %zu format specifier instead so that the actual overflowing index is logged.

Fixes 9dbe6015636c ("libbpf: Support kernel module function calls")
---
 tools/lib/bpf/libbpf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/lib/bpf/libbpf.c +2 -2
index 0e2a93a42908..d71e8ca199bc 100644
@@ -9553,8 +9553,8 @@ static int bpf_object__resolve_ksym_func_btf_id(struct bpf_object *obj,
 	if (mod_btf && !mod_btf->fd_array_idx) {
 		/* insn->off is s16 */
 		if (obj->fd_array_used == INT16_MAX) {
-			pr_warn("extern (func ksym) '%s': module BTF fd index %d too big to fit in bpf_insn offset\n",
-				ext->name, mod_btf->fd_array_idx);
+			pr_warn("extern (func ksym) '%s': module BTF fd index %zu too big to fit in bpf_insn offset\n",
+				ext->name, obj->fd_array_used);
 			return -E2BIG;
 		}
 		/* Cannot use index 0 for module BTF fd */
Signature · 1 line
2.55.0.windows.3
#1 lore raw
Quoted 1 line · Rahad Bhuiya
Fixes 9dbe6015636c ("libbpf: Support kernel module function calls")

That's not a fix. Nothing is broken.
One object has to call kfuncs from more than 32766 modules to see this message.

pw-bot: cr