Skip to contentSkip to conversation

libbpf: Stop setting -1 to value_type_btf_obj_fd which breaks backward compatibility

PATCH In review Martin KaFai Lau 2 participants 2 messages Jan 24, 2024

Subsystems (2)
lore
Share & tools
lore

Martin KaFai Lau

author reviewer
#0 lore raw

PATCH 1/1 libbpf: Stop setting -1 to value_type_btf_obj_fd which breaks backward compatibility

From: Martin KaFai Lau <[email protected]>

Passing -1 in value_type_btf_obj_fd to the kernel will break backward compatibility. This patch fixes it by using 0 as the default.

Cc Kui-Feng Lee <[email protected]>
Fixes 9e926acda0c2 ("libbpf: Find correct module BTFs for struct_ops maps and progs.")
---
 tools/lib/bpf/bpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/bpf.c +1 -1
index 3a35472a17c5..b133acfe08fb 100644
@@ -192,7 +192,7 @@ int bpf_map_create(enum bpf_map_type map_type,
 	attr.btf_key_type_id = OPTS_GET(opts, btf_key_type_id, 0);
 	attr.btf_value_type_id = OPTS_GET(opts, btf_value_type_id, 0);
 	attr.btf_vmlinux_value_type_id = OPTS_GET(opts, btf_vmlinux_value_type_id, 0);
-	attr.value_type_btf_obj_fd = OPTS_GET(opts, value_type_btf_obj_fd, -1);
+	attr.value_type_btf_obj_fd = OPTS_GET(opts, value_type_btf_obj_fd, 0);
 
 	attr.inner_map_fd = OPTS_GET(opts, inner_map_fd, 0);
 	attr.map_flags = OPTS_GET(opts, map_flags, 0);
Signature · 1 line
2.34.1
#1 lore raw
Quoted 19 lines · Martin KaFai Lau

From: Martin KaFai Lau <[email protected]>

Passing -1 in value_type_btf_obj_fd to the kernel will break backward compatibility. This patch fixes it by using 0 as the default.

Cc Kui-Feng Lee <[email protected]>
Fixes 9e926acda0c2 ("libbpf: Find correct module BTFs for struct_ops maps and progs.")
---
 tools/lib/bpf/bpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/bpf.c +0 -0
index 3a35472a17c5..b133acfe08fb 100644

tools/lib/bpf/bpf.c int bpf_map_create(enum bpf_map_type map_type, · line 195

Quoted 5 lines
tools/lib/bpf/bpf.c +1 -1
@@ -192,7 +192,7 @@ int bpf_map_create(enum bpf_map_type map_type,
        attr.btf_key_type_id = OPTS_GET(opts, btf_key_type_id, 0);
        attr.btf_value_type_id = OPTS_GET(opts, btf_value_type_id, 0);
        attr.btf_vmlinux_value_type_id = OPTS_GET(opts, btf_vmlinux_value_type_id, 0);
-       attr.value_type_btf_obj_fd = OPTS_GET(opts, value_type_btf_obj_fd, -1);
+       attr.value_type_btf_obj_fd = OPTS_GET(opts, value_type_btf_obj_fd, 0);

imo the commit log is too vague why it's ok to set this field to zero when it's not specified in opts.
It took me some time to go through the kernel and libbpf bits to see that there is a BPF_F_VTYPE_BTF_OBJ_FD flag that gates the use of value_type_btf_obj_fd and fd=0 is not special.
Please improve commit log and respin.

Thanks