libbpf: Support raw btf placed in the default path
Subsystems (4)
PATCH 1/1 libbpf: Support raw btf placed in the default path
Now only elf btf can be placed in the default path, raw btf should also can be there.
--- tools/lib/bpf/btf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/lib/bpf/btf.c +2 -2
@@ -4661,7 +4661,7 @@ struct btf *btf__load_vmlinux_btf(void) } locations[] = {/* try canonical vmlinux BTF through sysfs first */ { "/sys/kernel/btf/vmlinux", true /* raw BTF */ }, -/* fall back to trying to find vmlinux ELF on disk otherwise */ +/* fall back to trying to find vmlinux RAW/ELF on disk otherwise */ { "/boot/vmlinux-%1$s" }, { "/lib/modules/%1$s/vmlinux-%1$s" }, { "/lib/modules/%1$s/build/vmlinux" },
@@ -4686,7 +4686,7 @@ struct btf *btf__load_vmlinux_btf(void)if (locations[i].raw_btf) btf =btf__parse_raw (path);else - btf =btf__parse_elf (path,NULL ); + btf =btf__parse (path,NULL ); err =libbpf_get_error (btf);pr_debug ("loading kernel BTF '%s': %d\n" , path, err);if (err)
Signature · 1 line
2.2.1
Quoted 4 lines · chentao.ct
Now only elf btf can be placed in the default path, raw btf should also can be there.
It's not clear what you are trying to achieve. Do you want libbpf to attempt to load /boot/vmlinux-%1$s as raw BTF as well (so you can sort of sneak in pregenerated BTF), or what exactly? btf__load_vmlinux_btf() code already supports loading raw BTF, it just needs to be explicitly specified in locations table.
So with your change locations[i].raw_btf check doesn't make sense and we need to clean this up.
But first, let's discuss the use case, instead of your specific solution.
Quoted 30 lines
Signed-off-by chentao.ct <[email protected]>--- tools/lib/bpf/btf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/lib/bpf/btf.c +2
-3@@ -4661,7 +4661,7 @@ struct btf *btf__load_vmlinux_btf(void) } locations[] = {/* try canonical vmlinux BTF through sysfs first */ { "/sys/kernel/btf/vmlinux", true /* raw BTF */ }, -/* fall back to trying to find vmlinux ELF on disk otherwise */ +/* fall back to trying to find vmlinux RAW/ELF on disk otherwise */ { "/boot/vmlinux-%1$s" }, { "/lib/modules/%1$s/vmlinux-%1$s" }, { "/lib/modules/%1$s/build/vmlinux" },@@ -4686,7 +4686,7 @@ struct btf *btf__load_vmlinux_btf(void)if (locations[i].raw_btf) btf =btf__parse_raw (path);else - btf =btf__parse_elf (path,NULL ); + btf =btf__parse (path,NULL ); err =libbpf_get_error (btf);pr_debug ("loading kernel BTF '%s': %d\n" , path, err);if (err) --2.2.1
Hi Nakryiko, thank you for your reply. Yes, i happed to put the raw BTF made by myself in /boot on kernel4.19, unluckly it reported error. So is it possible to allow the raw BTF in /boot directly, athough we can set the specified btf location again to solve the problem with the bpf_object_open_opts interface.
As you say, maybe we can remove the locations[i].raw_btf check, just use the btf__parse. It looks more concise.
Quoted 49 lines · Andrii Nakryiko
Quoted 4 lines · chentao.ct
Now only elf btf can be placed in the default path, raw btf should also can be there.
It's not clear what you are trying to achieve. Do you want libbpf to attempt to load /boot/vmlinux-%1$s as raw BTF as well (so you can sort of sneak in pregenerated BTF), or what exactly?
btf__load_vmlinux_btf()code already supports loading raw BTF, it just needs to be explicitly specified in locations table.So with your change locations[i].raw_btf check doesn't make sense and we need to clean this up.
But first, let's discuss the use case, instead of your specific solution.
Quoted 30 lines
Signed-off-by chentao.ct <[email protected]>--- tools/lib/bpf/btf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/lib/bpf/btf.c +2
-3@@ -4661,7 +4661,7 @@ struct btf *btf__load_vmlinux_btf(void) } locations[] = {/* try canonical vmlinux BTF through sysfs first */ { "/sys/kernel/btf/vmlinux", true /* raw BTF */ }, -/* fall back to trying to find vmlinux ELF on disk otherwise */ +/* fall back to trying to find vmlinux RAW/ELF on disk otherwise */ { "/boot/vmlinux-%1$s" }, { "/lib/modules/%1$s/vmlinux-%1$s" }, { "/lib/modules/%1$s/build/vmlinux" },@@ -4686,7 +4686,7 @@ struct btf *btf__load_vmlinux_btf(void)if (locations[i].raw_btf) btf =btf__parse_raw (path);else - btf =btf__parse_elf (path,NULL ); + btf =btf__parse (path,NULL ); err =libbpf_get_error (btf);pr_debug ("loading kernel BTF '%s': %d\n" , path, err);if (err) --2.2.1
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 9 lines · Tao Chen
Hi Nakryiko, thank you for your reply. Yes, i happed to put the raw BTF made by myself in /boot on kernel4.19, unluckly it reported error. So is it possible to allow the raw BTF in /boot directly, athough we can set the specified btf location again to solve the problem with the
bpf_object_open_optsinterface.As you say, maybe we can remove the locations[i].raw_btf check, just use the
btf__parse, It looks more concise.
Please don't top post, reply inline (that's kernel mail lists rules).
But yes, I think we can just use btf__parse and let libbpf figure out. Please send a patch.
Quoted 51 lines · Andrii Nakryiko
On Wed, Aug 24, 2022 at 7:05 AM chentao.ct
<[email protected]> wrote:Now only elf btf can be placed in the default path, raw btf should also can be there.
It's not clear what you are trying to achieve. Do you want libbpf to attempt to load /boot/vmlinux-%1$s as raw BTF as well (so you can sort of sneak in pregenerated BTF), or what exactly?
btf__load_vmlinux_btf()code already supports loading raw BTF, it just needs to be explicitly specified in locations table.So with your change locations[i].raw_btf check doesn't make sense and we need to clean this up.
But first, let's discuss the use case, instead of your specific solution.
Signed-off-by chentao.ct <[email protected]>--- tools/lib/bpf/btf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/lib/bpf/btf.c +2
-3@@ -4661,7 +4661,7 @@ struct btf *btf__load_vmlinux_btf(void) } locations[] = {/* try canonical vmlinux BTF through sysfs first */ { "/sys/kernel/btf/vmlinux", true /* raw BTF */ }, -/* fall back to trying to find vmlinux ELF on disk otherwise */ +/* fall back to trying to find vmlinux RAW/ELF on disk otherwise */ { "/boot/vmlinux-%1$s" }, { "/lib/modules/%1$s/vmlinux-%1$s" }, { "/lib/modules/%1$s/build/vmlinux" },@@ -4686,7 +4686,7 @@ struct btf *btf__load_vmlinux_btf(void)if (locations[i].raw_btf) btf =btf__parse_raw (path);else - btf =btf__parse_elf (path,NULL ); + btf =btf__parse (path,NULL ); err =libbpf_get_error (btf);pr_debug ("loading kernel BTF '%s': %d\n" , path, err);if (err) --2.2.1
Quoted 9 lines · Andrii Nakryiko
Quoted 7 lines · Tao Chen
Hi Nakryiko, thank you for your reply. Yes, i happed to put the raw BTF made by myself in /boot on kernel4.19, unluckly it reported error. So is it possible to allow the raw BTF in /boot directly, athough we can set the specified btf location again to solve the problem with the
bpf_object_open_optsinterface.
Quoted 8 lines
Quoted 2 lines
As you say, maybe we can remove the locations[i].raw_btf check, just use the
btf__parse, It looks more concise.Please don't top post, reply inline (that's kernel mail lists rules).
But yes, I think we can just use
btf__parseand let libbpf figure out. Please send a patch.
Thank you, i will send the patch in v2.
Quoted 51 lines
Quoted 51 lines · Andrii Nakryiko
On Wed, Aug 24, 2022 at 7:05 AM chentao.ct
<[email protected]> wrote:Now only elf btf can be placed in the default path, raw btf should also can be there.
It's not clear what you are trying to achieve. Do you want libbpf to attempt to load /boot/vmlinux-%1$s as raw BTF as well (so you can sort of sneak in pregenerated BTF), or what exactly?
btf__load_vmlinux_btf()code already supports loading raw BTF, it just needs to be explicitly specified in locations table.So with your change locations[i].raw_btf check doesn't make sense and we need to clean this up.
But first, let's discuss the use case, instead of your specific solution.
Signed-off-by chentao.ct <[email protected]>--- tools/lib/bpf/btf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/lib/bpf/btf.c +2
-3@@ -4661,7 +4661,7 @@ struct btf *btf__load_vmlinux_btf(void) } locations[] = {/* try canonical vmlinux BTF through sysfs first */ { "/sys/kernel/btf/vmlinux", true /* raw BTF */ }, -/* fall back to trying to find vmlinux ELF on disk otherwise */ +/* fall back to trying to find vmlinux RAW/ELF on disk otherwise */ { "/boot/vmlinux-%1$s" }, { "/lib/modules/%1$s/vmlinux-%1$s" }, { "/lib/modules/%1$s/build/vmlinux" },@@ -4686,7 +4686,7 @@ struct btf *btf__load_vmlinux_btf(void)if (locations[i].raw_btf) btf =btf__parse_raw (path);else - btf =btf__parse_elf (path,NULL ); + btf =btf__parse (path,NULL ); err =libbpf_get_error (btf);pr_debug ("loading kernel BTF '%s': %d\n" , path, err);if (err) --2.2.1