Skip to contentSkip to conversation

libbpf: Improve debug message when the base BTF cannot be found

PATCH Superseded Ben Olson 3 participants 8 messages Nov 21, 2024 – Nov 26, 2024

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Ben Olson

author
#0 lore raw

PATCH 1/1 libbpf: Improve debug message when the base BTF cannot be found

When running bpftool on a kernel module installed in /lib/modules..., this error is encountered if the user does not specify --base-btf to point to a valid base BTF (e.g. usually in /sys/kernel/btf/vmlinux). However, looking at the debug output to determine the cause of the error simply says Invalid BTF string section, which does not point to the actual source of the error. This just improves that debug message to tell users what happened.

---
 tools/lib/bpf/btf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/btf.c +1 -1
index 12468ae0d573..1a17de9d99e6 100644
@@ -283,7 +283,7 @@ static int btf_parse_str_sec(struct btf *btf)
 		return -EINVAL;
 	}
 	if (!btf->base_btf && start[0]) {
-		pr_debug("Invalid BTF string section\n");
+		pr_debug("Cannot find base BTF\n");
 		return -EINVAL;
 	}
 	return 0;
Signature · 1 line
2.47.0
#1 lore raw
Quoted 19 lines · Ben Olson

When running bpftool on a kernel module installed in /lib/modules..., this error is encountered if the user does not specify --base-btf to point to a valid base BTF (e.g. usually in /sys/kernel/btf/vmlinux). However, looking at the debug output to determine the cause of the error simply says Invalid BTF string section, which does not point to the actual source of the error. This just improves that debug message to tell users what happened.

---
 tools/lib/bpf/btf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/btf.c +0 -0
index 12468ae0d573..1a17de9d99e6 100644

tools/lib/bpf/btf.c static int btf_parse_str_sec(struct btf *btf) · line 286

Quoted 5 lines
tools/lib/bpf/btf.c +1 -1
@@ -283,7 +283,7 @@ static int btf_parse_str_sec(struct btf *btf)
                return -EINVAL;
        }
        if (!btf->base_btf && start[0]) {
-               pr_debug("Invalid BTF string section\n");
+               pr_debug("Cannot find base BTF\n");

Well, the check indeed checks the well-formedness of the BTF string section. It is specified that the first byte has to be zero ("empty string"), unless it's a split BTF.

Base BTF being missing is just one possible reason for this condition, so I'm not sure if it's completely accurate to specialize this error message so much. Perhaps maybe emitting "Malformed BTF string section, did you forget to provide base BTF?" would be a bit better.

pw-bot: cr

Quoted 5 lines
tools/lib/bpf/btf.c +0 -1
                return -EINVAL;
        }
        return 0;
--

2.47.0

#2 lore raw
Quoted 30 lines · Andrii Nakryiko
Quoted 19 lines · Ben Olson

When running bpftool on a kernel module installed in /lib/modules..., this error is encountered if the user does not specify --base-btf to point to a valid base BTF (e.g. usually in /sys/kernel/btf/vmlinux). However, looking at the debug output to determine the cause of the error simply says Invalid BTF string section, which does not point to the actual source of the error. This just improves that debug message to tell users what happened.

---
 tools/lib/bpf/btf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/btf.c +0 -0
index 12468ae0d573..1a17de9d99e6 100644

tools/lib/bpf/btf.c static int btf_parse_str_sec(struct btf *btf) · line 286

Quoted 5 lines
tools/lib/bpf/btf.c +1 -1
@@ -283,7 +283,7 @@ static int btf_parse_str_sec(struct btf *btf)
                return -EINVAL;
        }
        if (!btf->base_btf && start[0]) {
-               pr_debug("Invalid BTF string section\n");
+               pr_debug("Cannot find base BTF\n");

Well, the check indeed checks the well-formedness of the BTF string section. It is specified that the first byte has to be zero ("empty string"), unless it's a split BTF.

Quoted 4 lines

Base BTF being missing is just one possible reason for this condition, so I'm not sure if it's completely accurate to specialize this error message so much. Perhaps maybe emitting "Malformed BTF string section, did you forget to provide base BTF?" would be a bit better.

That sounds much better; as long as it hints that the user should check if they specified a base BTF or not, it's good with me! Thanks.

Quoted 9 lines

pw-bot: cr

Quoted 5 lines
tools/lib/bpf/btf.c +0 -1
                return -EINVAL;
        }
        return 0;
--

2.47.0

#3 lore raw
In reply to Ben Olson

From 22ed11ee2153fc921987eac7de24f564da9f9230 Mon Sep 17 00:00:00 2001
From: Ben Olson <[email protected]>
Date: Thu, 21 Nov 2024 11:26:35 -0600
Subject: [PATCH v2 bpf-next] libbpf: Improve debug message when the base BTF
cannot be found

When running bpftool on a kernel module installed in /lib/modules..., this error is encountered if the user does not specify --base-btf to point to a valid base BTF (e.g. usually in /sys/kernel/btf/vmlinux). However, looking at the debug output to determine the cause of the error simply says Invalid BTF string section, which does not point to the actual source of the error. This just improves that debug message to tell users what happened.

---

Changed in v2:
* Made error message better reflect the condition

 tools/lib/bpf/btf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/btf.c +1 -1
index 12468ae0d573..a4ae2df68b91 100644
@@ -283,7 +283,7 @@ static int btf_parse_str_sec(struct btf *btf)
     return -EINVAL;
   }
   if (!btf->base_btf && start[0]) {
-    pr_debug("Invalid BTF string section\n");
+    pr_debug("Malformed BTF string section, did you forget to provide base BTF?\n");
     return -EINVAL;
   }
   return 0;

--
2.47.0

#4 lore raw
Quoted 14 lines · Matthew

From 22ed11ee2153fc921987eac7de24f564da9f9230 Mon Sep 17 00:00:00 2001
From: Ben Olson <[email protected]>
Date: Thu, 21 Nov 2024 11:26:35 -0600
Subject: [PATCH v2 bpf-next] libbpf: Improve debug message when the base BTF
cannot be found

When running bpftool on a kernel module installed in /lib/modules..., this error is encountered if the user does not specify --base-btf to point to a valid base BTF (e.g. usually in /sys/kernel/btf/vmlinux). However, looking at the debug output to determine the cause of the error simply says Invalid BTF string section, which does not point to the actual source of the error. This just improves that debug message to tell users what happened.

Quoted 2 lines

---

LGTM

Quoted 22 lines

Changed in v2:
* Made error message better reflect the condition

 tools/lib/bpf/btf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/btf.c +1 -2
index 12468ae0d573..a4ae2df68b91 100644
@@ -283,7 +283,7 @@ static int btf_parse_str_sec(struct btf *btf)
     return -EINVAL;
   }
   if (!btf->base_btf && start[0]) {
-    pr_debug("Invalid BTF string section\n");
+    pr_debug("Malformed BTF string section, did you forget to provide base BTF?\n");
     return -EINVAL;
   }
   return 0;
--

2.47.0

#5 lore raw
In reply to Olson, Matthew
Quoted 29 lines · Matthew

From 22ed11ee2153fc921987eac7de24f564da9f9230 Mon Sep 17 00:00:00 2001
From: Ben Olson <[email protected]>
Date: Thu, 21 Nov 2024 11:26:35 -0600
Subject: [PATCH v2 bpf-next] libbpf: Improve debug message when the base BTF
cannot be found

When running bpftool on a kernel module installed in /lib/modules..., this error is encountered if the user does not specify --base-btf to point to a valid base BTF (e.g. usually in /sys/kernel/btf/vmlinux). However, looking at the debug output to determine the cause of the error simply says Invalid BTF string section, which does not point to the actual source of the error. This just improves that debug message to tell users what happened.

---

Changed in v2:
* Made error message better reflect the condition

 tools/lib/bpf/btf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/btf.c +0 -0
index 12468ae0d573..a4ae2df68b91 100644

tools/lib/bpf/btf.c static int btf_parse_str_sec(struct btf *btf) · line 286

Quoted 5 lines
tools/lib/bpf/btf.c +1 -1
@@ -283,7 +283,7 @@ static int btf_parse_str_sec(struct btf *btf)
     return -EINVAL;
   }
   if (!btf->base_btf && start[0]) {
-    pr_debug("Invalid BTF string section\n");
+    pr_debug("Malformed BTF string section, did you forget to provide base BTF?\n");

I'm not sure why, but this v2 didn't make it into patchworks, so I can't apply it. Can you please resend?

Also please make sure you don't change indentation (tabs -> spaces), because it looks like that's what happened here.

Quoted 5 lines
tools/lib/bpf/btf.c +0 -1
     return -EINVAL;
   }
   return 0;
--

2.47.0

#6 lore raw
Quoted 25 lines · Andrii Nakryiko
Quoted 24 lines · Matthew

From 22ed11ee2153fc921987eac7de24f564da9f9230 Mon Sep 17 00:00:00 2001
From: Ben Olson <[email protected]>
Date: Thu, 21 Nov 2024 11:26:35 -0600
Subject: [PATCH v2 bpf-next] libbpf: Improve debug message when the base BTF
cannot be found

When running bpftool on a kernel module installed in /lib/modules..., this error is encountered if the user does not specify --base-btf to point to a valid base BTF (e.g. usually in /sys/kernel/btf/vmlinux). However, looking at the debug output to determine the cause of the error simply says Invalid BTF string section, which does not point to the actual source of the error. This just improves that debug message to tell users what happened.

---

Changed in v2:
* Made error message better reflect the condition

 tools/lib/bpf/btf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

tools/lib/bpf/btf.c static int btf_parse_str_sec(struct btf *btf) · line 286

Quoted 10 lines
tools/lib/bpf/btf.c +1 -1
index 12468ae0d573..a4ae2df68b91 100644
@@ -283,7 +283,7 @@ static int btf_parse_str_sec(struct btf *btf)
     return -EINVAL;
   }
   if (!btf->base_btf && start[0]) {
-    pr_debug("Invalid BTF string section\n");
+    pr_debug("Malformed BTF string section, did you forget to provide base BTF?\n");

I'm not sure why, but this v2 didn't make it into patchworks, so I can't apply it. Can you please resend?

Sure thing. Thanks.

Quoted 3 lines

Also please make sure you don't change indentation (tabs -> spaces), because it looks like that's what happened here.

Ach, rookie mistake. I'll add clang-format to my git hooks.

Quoted 6 lines
Quoted 6 lines
tools/lib/bpf/btf.c +0 -1
     return -EINVAL;
   }
   return 0;
--

2.47.0

#7 lore raw
Quoted 40 lines · Matthew
Quoted 25 lines · Andrii Nakryiko
Quoted 24 lines · Matthew

From 22ed11ee2153fc921987eac7de24f564da9f9230 Mon Sep 17 00:00:00 2001
From: Ben Olson <[email protected]>
Date: Thu, 21 Nov 2024 11:26:35 -0600
Subject: [PATCH v2 bpf-next] libbpf: Improve debug message when the base BTF
cannot be found

When running bpftool on a kernel module installed in /lib/modules..., this error is encountered if the user does not specify --base-btf to point to a valid base BTF (e.g. usually in /sys/kernel/btf/vmlinux). However, looking at the debug output to determine the cause of the error simply says Invalid BTF string section, which does not point to the actual source of the error. This just improves that debug message to tell users what happened.

---

Changed in v2:
* Made error message better reflect the condition

 tools/lib/bpf/btf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

tools/lib/bpf/btf.c static int btf_parse_str_sec(struct btf *btf) · line 286

Quoted 10 lines
tools/lib/bpf/btf.c +1 -1
index 12468ae0d573..a4ae2df68b91 100644
@@ -283,7 +283,7 @@ static int btf_parse_str_sec(struct btf *btf)
     return -EINVAL;
   }
   if (!btf->base_btf && start[0]) {
-    pr_debug("Invalid BTF string section\n");
+    pr_debug("Malformed BTF string section, did you forget to provide base BTF?\n");

I'm not sure why, but this v2 didn't make it into patchworks, so I can't apply it. Can you please resend?

Quoted 1 line

Sure thing. Thanks.

Ah, I think I figured out why it didn't make it into patchworks; I'll resend yet again.

Quoted 14 lines
Quoted 4 lines

Also please make sure you don't change indentation (tabs -> spaces), because it looks like that's what happened here.

Ach, rookie mistake. I'll add clang-format to my git hooks.

Quoted 6 lines
Quoted 6 lines
tools/lib/bpf/btf.c +0 -1
     return -EINVAL;
   }
   return 0;
--

2.47.0