Skip to contentSkip to conversation

lib/bpf: fix verbose flag when using libbpf

PATCH In review Paul Chaignon 2 participants 2 messages Dec 16, 2021 – Dec 17, 2021

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

PATCH 1/1 lib/bpf: fix verbose flag when using libbpf

Since commit 6d61a2b55799 ("lib: add libbpf support"), passing the verbose flag to tc filter doesn't dump the verifier logs anymore in case of successful loading.

This commit fixes it by setting the log_level attribute before loading. To that end, we need to call bpf_object__load_xattr directly instead of relying on bpf_object__load.

Fixes 6d61a2b55799 ("lib: add libbpf support")
---
 lib/bpf_libbpf.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
lib/bpf_libbpf.c +6 -1
index dbec2cb5..b992a62c 100644
@@ -246,6 +246,7 @@ static int handle_legacy_maps(struct bpf_object *obj)
 
 static int load_bpf_object(struct bpf_cfg_in *cfg)
 {
+	struct bpf_object_load_attr attr = {};
 	struct bpf_program *p, *prog = NULL;
 	struct bpf_object *obj;
 	char root_path[PATH_MAX];
@@ -302,7 +303,11 @@ static int load_bpf_object(struct bpf_cfg_in *cfg)
 	if (ret)
 		goto unload_obj;
 
-	ret = bpf_object__load(obj);
+	attr.obj = obj;
+	if (cfg->verbose) {
+		attr.log_level = 2;
+	}
+	ret = bpf_object__load_xattr(&attr);
 	if (ret)
 		goto unload_obj;
 
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw
Quoted 27 lines · Paul Chaignon

Since commit 6d61a2b55799 ("lib: add libbpf support"), passing the verbose flag to tc filter doesn't dump the verifier logs anymore in case of successful loading.

This commit fixes it by setting the log_level attribute before loading. To that end, we need to call bpf_object__load_xattr directly instead of relying on bpf_object__load.

Fixes 6d61a2b55799 ("lib: add libbpf support")
---
 lib/bpf_libbpf.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
lib/bpf_libbpf.c +1 -0
index dbec2cb5..b992a62c 100644
@@ -246,6 +246,7 @@ static int handle_legacy_maps(struct bpf_object *obj)
 
 static int load_bpf_object(struct bpf_cfg_in *cfg)
 {
+	struct bpf_object_load_attr attr = {};
 	struct bpf_program *p, *prog = NULL;
 	struct bpf_object *obj;
 	char root_path[PATH_MAX];

lib/bpf_libbpf.c static int load_bpf_object(struct bpf_cfg_in *cfg) · line 309

Quoted 8 lines
lib/bpf_libbpf.c +4 -1
@@ -302,7 +303,11 @@ static int load_bpf_object(struct bpf_cfg_in *cfg)
 	if (ret)
 		goto unload_obj;
 
-	ret = bpf_object__load(obj);
+	attr.obj = obj;
+	if (cfg->verbose) {
+		attr.log_level = 2;
+	}

nit: no need the curly braces when this is only 1 line

lib/bpf_libbpf.c static int load_bpf_object(struct bpf_cfg_in *cfg) · line 313

Quoted 4 lines
lib/bpf_libbpf.c +1 -0
+	ret = bpf_object__load_xattr(&attr);
 	if (ret)
 		goto unload_obj;
 

Thanks for the fixes.