* [PATCH 0/5] Fix segfaults related to missing BTF support
@ 2024-11-18 20:41 Arnaldo Carvalho de Melo
0 siblings, 0 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2024-11-18 20:41 UTC (permalink / raw)
To: Alan Maguire
Cc: Jiri Olsa, Clark Williams, Kate Carcia, Arnaldo Carvalho de Melo,
Matthias Schwarzott, Andrii Nakryiko, Eduard Zingerman, Song Liu,
Yonghong Song, dwarves
Hi,
While looking for reports to fix before release 1.28 I got to
Matthias reports about segfaults in systems where BTF isn't present, so
I introduced a regression test and infrastructure to allow testing
handling such a system, please take a look.
Thanks,
- Arnaldo
Arnaldo Carvalho de Melo (5):
core: Add method to get the vmlinux BTF filename, allow overriding it via env var
tests default_vmlinux_btf: Introduce test for using BTF by default
pahole: Honour exclusive BTF loading
tests default_vmlinux_btf: Cover the no args segfault too
core, libctf: Check if constructor arguments are NULL before using them
dwarves.c | 33 ++++++++++++++++++++++++++++++---
dwarves.h | 2 ++
libctf.c | 3 +++
man-pages/pahole.1 | 4 ++++
pahole.c | 11 +++++++++--
tests/default_vmlinux_btf.sh | 32 ++++++++++++++++++++++++++++++++
6 files changed, 80 insertions(+), 5 deletions(-)
create mode 100755 tests/default_vmlinux_btf.sh
--
2.47.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 0/5] Fix segfaults related to missing BTF support
@ 2024-11-19 13:40 Arnaldo Carvalho de Melo
2024-11-19 13:40 ` [PATCH 1/5] core: Add method to get the vmlinux BTF filename, allow overriding it via env var Arnaldo Carvalho de Melo
` (4 more replies)
0 siblings, 5 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2024-11-19 13:40 UTC (permalink / raw)
To: Alan Maguire
Cc: Jiri Olsa, Clark Williams, Kate Carcia, dwarves,
Arnaldo Carvalho de Melo, Matthias Schwarzott, Andrii Nakryiko,
Eduard Zingerman, Song Liu, Yonghong Song
Sorry for the top post: Only the cover letter ended up reaching the
mailing list, so resending to have it there :-\
Hi,
While looking for reports to fix before release 1.28 I got to
Matthias reports about segfaults in systems where BTF isn't present, so
I introduced a regression test and infrastructure to allow testing
handling such a system, please take a look.
Thanks,
- Arnaldo
Arnaldo Carvalho de Melo (5):
core: Add method to get the vmlinux BTF filename, allow overriding it via env var
tests default_vmlinux_btf: Introduce test for using BTF by default
pahole: Honour exclusive BTF loading
tests default_vmlinux_btf: Cover the no args segfault too
core, libctf: Check if constructor arguments are NULL before using them
dwarves.c | 33 ++++++++++++++++++++++++++++++---
dwarves.h | 2 ++
libctf.c | 3 +++
man-pages/pahole.1 | 4 ++++
pahole.c | 11 +++++++++--
tests/default_vmlinux_btf.sh | 32 ++++++++++++++++++++++++++++++++
6 files changed, 80 insertions(+), 5 deletions(-)
create mode 100755 tests/default_vmlinux_btf.sh
--
2.47.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 1/5] core: Add method to get the vmlinux BTF filename, allow overriding it via env var
2024-11-19 13:40 [PATCH 0/5] Fix segfaults related to missing BTF support Arnaldo Carvalho de Melo
@ 2024-11-19 13:40 ` Arnaldo Carvalho de Melo
2024-11-19 13:40 ` [PATCH 2/5] tests default_vmlinux_btf: Introduce test for using BTF by default Arnaldo Carvalho de Melo
` (3 subsequent siblings)
4 siblings, 0 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2024-11-19 13:40 UTC (permalink / raw)
To: Alan Maguire
Cc: Jiri Olsa, Clark Williams, Kate Carcia, dwarves,
Arnaldo Carvalho de Melo, Matthias Schwarzott, Andrii Nakryiko,
Eduard Zingerman, Song Liu, Yonghong Song
From: Arnaldo Carvalho de Melo <acme@redhat.com>
In systems where BTF isn't available there were reports that the
simplest pahole call, without any args, segfaults.
To have a proper test before fixing this problem, allow overriding the
/sys/kernel/btf/vmlinux filename, so that even in systems with BTF we an
point it to a invalid location, making pahole think that there is no BTF
available and thus fallback to something that currently segfaults.
Using it:
$ pahole list_head
struct list_head {
struct list_head * next; /* 0 8 */
struct list_head * prev; /* 8 8 */
/* size: 16, cachelines: 1, members: 2 */
/* last cacheline: 16 bytes */
};
$
$ PAHOLE_VMLINUX_BTF_FILENAME=foobar pahole list_head
Segmentation fault (core dumped)
$
Reported-by: Matthias Schwarzott <zzam@gentoo.org>
Cc: Alan Maguire <alan.maguire@oracle.com>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Eduard Zingerman <eddyz87@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Song Liu <song@kernel.org>
Cc: Yonghong Song <yonghong.song@linux.dev>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
dwarves.c | 17 +++++++++++++++--
dwarves.h | 2 ++
man-pages/pahole.1 | 4 ++++
pahole.c | 2 +-
4 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/dwarves.c b/dwarves.c
index 14ba4f0c6dd7f90f..5b51b55191177e21 100644
--- a/dwarves.c
+++ b/dwarves.c
@@ -2807,6 +2807,19 @@ static int filename__sprintf_build_id(const char *pathname, char *sbuild_id)
static int vmlinux_path__nr_entries;
static char **vmlinux_path;
+const char *vmlinux_path__btf_filename(void)
+{
+ static const char *vmlinux_btf;
+
+ if (vmlinux_btf == NULL) {
+ vmlinux_btf = getenv("PAHOLE_VMLINUX_BTF_FILENAME");
+ if (vmlinux_btf == NULL)
+ vmlinux_btf = "/sys/kernel/btf/vmlinux";
+ }
+
+ return vmlinux_btf;
+}
+
static void vmlinux_path__exit(void)
{
while (--vmlinux_path__nr_entries >= 0)
@@ -2933,7 +2946,7 @@ static int cus__load_running_kernel(struct cus *cus, struct conf_load *conf)
int err = 0;
if ((!conf || conf->format_path == NULL || strncmp(conf->format_path, "btf", 3) == 0) &&
- access("/sys/kernel/btf/vmlinux", R_OK) == 0) {
+ access(vmlinux_path__btf_filename(), R_OK) == 0) {
int loader = debugging_formats__loader("btf");
if (loader == -1)
goto try_elf;
@@ -2941,7 +2954,7 @@ static int cus__load_running_kernel(struct cus *cus, struct conf_load *conf)
if (conf && conf->conf_fprintf)
conf->conf_fprintf->has_alignment_info = debug_fmt_table[loader]->has_alignment_info;
- if (debug_fmt_table[loader]->load_file(cus, conf, "/sys/kernel/btf/vmlinux") == 0)
+ if (debug_fmt_table[loader]->load_file(cus, conf, vmlinux_path__btf_filename()) == 0)
return 0;
}
try_elf:
diff --git a/dwarves.h b/dwarves.h
index 49988f1cf9d45be8..1cb0d629f5265523 100644
--- a/dwarves.h
+++ b/dwarves.h
@@ -1628,6 +1628,8 @@ void dwarves__resolve_cacheline_size(const struct conf_load *conf, uint16_t user
const char *dwarf_tag_name(const uint32_t tag);
+const char *vmlinux_path__btf_filename(void);
+
const char *vmlinux_path__find_running_kernel(void);
struct argp_state;
diff --git a/man-pages/pahole.1 b/man-pages/pahole.1
index bd28259b65429acc..39e7b465c64e7e2c 100644
--- a/man-pages/pahole.1
+++ b/man-pages/pahole.1
@@ -75,6 +75,10 @@ struct list_head {
};
$
.fi
+It is possible to override the /sys/kernel/btf/vmlinux file location by setting
+the PAHOLE_VMLINUX_BTF_FILENAME environment variable. This may be useful for
+testing, scripting when using a different BTF for vmlinux. Used in the pahole
+regression tests.
If BTF is not present and no file is passed, then a vmlinux that matches the
build-id for the running kernel will be looked up in the usual places,
diff --git a/pahole.c b/pahole.c
index 55d04cf82a3da683..b94cb1a979a6923d 100644
--- a/pahole.c
+++ b/pahole.c
@@ -3754,7 +3754,7 @@ try_sole_arg_as_class_names:
if (filename &&
strstarts(filename, "/sys/kernel/btf/") &&
strstr(filename, "/vmlinux") == NULL) {
- base_btf_file = "/sys/kernel/btf/vmlinux";
+ base_btf_file = vmlinux_path__btf_filename();
conf_load.base_btf = btf__parse(base_btf_file, NULL);
if (libbpf_get_error(conf_load.base_btf)) {
fprintf(stderr, "Failed to parse base BTF '%s': %ld\n",
--
2.47.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 2/5] tests default_vmlinux_btf: Introduce test for using BTF by default
2024-11-19 13:40 [PATCH 0/5] Fix segfaults related to missing BTF support Arnaldo Carvalho de Melo
2024-11-19 13:40 ` [PATCH 1/5] core: Add method to get the vmlinux BTF filename, allow overriding it via env var Arnaldo Carvalho de Melo
@ 2024-11-19 13:40 ` Arnaldo Carvalho de Melo
2024-11-19 13:40 ` [PATCH 3/5] pahole: Honour exclusive BTF loading Arnaldo Carvalho de Melo
` (2 subsequent siblings)
4 siblings, 0 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2024-11-19 13:40 UTC (permalink / raw)
To: Alan Maguire
Cc: Jiri Olsa, Clark Williams, Kate Carcia, dwarves,
Arnaldo Carvalho de Melo, Matthias Schwarzott, Andrii Nakryiko,
Eduard Zingerman, Song Liu, Yonghong Song
From: Arnaldo Carvalho de Melo <acme@redhat.com>
On a system without any debugging info or when one specifies BTF as the
only BTF info desired but no BTF is available (or invalidated using
PAHOLE_VMLINUX_BTF_FILENAME to an invalid/non-existent file), we're
getting a segfault:
root@x1:/home/acme/git/pahole# export PAHOLE_VMLINUX_BTF_FILENAME=non-existent
root@x1:/home/acme/git/pahole# pahole --running_kernel_vmlinux
pahole: couldn't find a vmlinux that matches the running kernel
HINT: Maybe you're inside a container or missing a debuginfo package?
root@x1:/home/acme/git/pahole# pahole
Segmentation fault (core dumped)
root@x1:/home/acme/git/pahole#
So add a test that checks for that before we fix it:
root@x1:/home/acme/git/pahole# tests/default_vmlinux_btf.sh
Default BTF on a system without BTF: FAILED
root@x1:/home/acme/git/pahole#
Reported-by: Matthias Schwarzott <zzam@gentoo.org>
Cc: Alan Maguire <alan.maguire@oracle.com>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Eduard Zingerman <eddyz87@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Song Liu <song@kernel.org>
Cc: Yonghong Song <yonghong.song@linux.dev>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tests/default_vmlinux_btf.sh | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
create mode 100755 tests/default_vmlinux_btf.sh
diff --git a/tests/default_vmlinux_btf.sh b/tests/default_vmlinux_btf.sh
new file mode 100755
index 0000000000000000..a9effa2d6d37e0ee
--- /dev/null
+++ b/tests/default_vmlinux_btf.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+echo -n "Default BTF on a system without BTF: "
+
+ulimit -c 0
+
+# To suppress the "Segmentation fault core dumped" message in bash we
+# pipe it to some other command, if it segfaults it will not produce any
+# lines and thus we can infer from the number of lines that the segfault
+# took place, tricky, but couldn't find any other way to check this
+# while suppressing the core dumped message. -acme
+
+nr_lines=$(PAHOLE_VMLINUX_BTF_FILENAME=foobar pahole -F btf list_head 2>&1 | wc -l)
+
+if [ $nr_lines -eq 0 ] ; then
+ echo "FAILED"
+ exit 1
+fi
+
+echo "Ok"
+exit 0
--
2.47.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 3/5] pahole: Honour exclusive BTF loading
2024-11-19 13:40 [PATCH 0/5] Fix segfaults related to missing BTF support Arnaldo Carvalho de Melo
2024-11-19 13:40 ` [PATCH 1/5] core: Add method to get the vmlinux BTF filename, allow overriding it via env var Arnaldo Carvalho de Melo
2024-11-19 13:40 ` [PATCH 2/5] tests default_vmlinux_btf: Introduce test for using BTF by default Arnaldo Carvalho de Melo
@ 2024-11-19 13:40 ` Arnaldo Carvalho de Melo
2024-11-19 17:47 ` Alan Maguire
2024-11-19 22:04 ` Eduard Zingerman
2024-11-19 13:40 ` [PATCH 4/5] tests default_vmlinux_btf: Cover the no args segfault too Arnaldo Carvalho de Melo
2024-11-19 13:40 ` [PATCH 5/5] core, libctf: Check if constructor arguments are NULL before using them Arnaldo Carvalho de Melo
4 siblings, 2 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2024-11-19 13:40 UTC (permalink / raw)
To: Alan Maguire
Cc: Jiri Olsa, Clark Williams, Kate Carcia, dwarves,
Arnaldo Carvalho de Melo, Matthias Schwarzott, Andrii Nakryiko,
Eduard Zingerman, Song Liu, Yonghong Song
From: Arnaldo Carvalho de Melo <acme@redhat.com>
When we specify 'btf' and BTF info is available in the system, in the
/sys/kernel/btf/vmlinux file, pahole will find it and use it to get the
type information asked for:
root@x1:~# perf trace -o /tmp/output -e openat pahole -F btf list_head ; tail -1 /tmp/output
struct list_head {
struct list_head * next; /* 0 8 */
struct list_head * prev; /* 8 8 */
/* size: 16, cachelines: 1, members: 2 */
/* last cacheline: 16 bytes */
};
1.579 ( 0.010 ms): pahole/764777 openat(dfd: CWD, filename: "/sys/kernel/btf/vmlinux", flags: RDONLY|CLOEXEC) = 3
root@x1:~#
But, if the system doesn't have BTF info, which we now can simulate by using an
environment variable it is tryng DWARF after failing for BTF, which isn't what
the user asked for having specified just btf in the -F pahole command line:
root@x1:~# export PAHOLE_VMLINUX_BTF_FILENAME=non-existent
root@x1:~# perf trace -o /tmp/output -e openat,access pahole -F btf list_head ; tail -12 /tmp/output
struct list_head {
struct list_head * next; /* 0 8 */
struct list_head * prev; /* 8 8 */
/* size: 16, cachelines: 1, members: 2 */
/* last cacheline: 16 bytes */
};
1.643 ( 0.003 ms): pahole/765220 access(filename: "list_head", mode: R) = -1 ENOENT (No such file or directory)
1.658 ( 0.002 ms): pahole/765220 access(filename: "non-existent", mode: R) = -1 ENOENT (No such file or directory)
1.697 ( 0.018 ms): pahole/765220 openat(dfd: CWD, filename: "/sys/kernel/notes") = 3
1.801 ( 0.004 ms): pahole/765220 openat(dfd: CWD, filename: "vmlinux") = -1 ENOENT (No such file or directory)
1.807 ( 0.005 ms): pahole/765220 openat(dfd: CWD, filename: "/boot/vmlinux") = -1 ENOENT (No such file or directory)
1.927 ( 0.005 ms): pahole/765220 openat(dfd: CWD, filename: "/usr/lib/debug/lib/modules/6.11.6-200.fc40.x86_64/vmlinux", flags: RDONLY|CLOEXEC) = 3
root@x1:~#
So honour the request and fails when just BTF is asked and no BTF file is
found:
# export PAHOLE_VMLINUX_BTF_FILENAME=non-existent
# pahole -F btf list_head
pahole: couldn't find any btf debug information on this system.
#
Reported-by: Matthias Schwarzott <zzam@gentoo.org>
Cc: Alan Maguire <alan.maguire@oracle.com>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Eduard Zingerman <eddyz87@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Song Liu <song@kernel.org>
Cc: Yonghong Song <yonghong.song@linux.dev>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
dwarves.c | 15 +++++++++++++--
pahole.c | 9 ++++++++-
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/dwarves.c b/dwarves.c
index 5b51b55191177e21..459311e64c8b45b2 100644
--- a/dwarves.c
+++ b/dwarves.c
@@ -2944,9 +2944,17 @@ const char *vmlinux_path__find_running_kernel(void)
static int cus__load_running_kernel(struct cus *cus, struct conf_load *conf)
{
int err = 0;
+ bool btf_only = false;
- if ((!conf || conf->format_path == NULL || strncmp(conf->format_path, "btf", 3) == 0) &&
- access(vmlinux_path__btf_filename(), R_OK) == 0) {
+ if (!conf || conf->format_path == NULL)
+ goto try_btf;
+
+ if (!strstr(conf->format_path, "btf"))
+ goto try_elf;
+
+ btf_only = strcmp(conf->format_path, "btf") == 0;
+try_btf:
+ if (access(vmlinux_path__btf_filename(), R_OK) == 0) {
int loader = debugging_formats__loader("btf");
if (loader == -1)
goto try_elf;
@@ -2958,6 +2966,9 @@ static int cus__load_running_kernel(struct cus *cus, struct conf_load *conf)
return 0;
}
try_elf:
+ if (btf_only)
+ return -1;
+
elf_version(EV_CURRENT);
vmlinux_path__init();
diff --git a/pahole.c b/pahole.c
index b94cb1a979a6923d..fa5d8c707bd4717d 100644
--- a/pahole.c
+++ b/pahole.c
@@ -3782,7 +3782,14 @@ try_sole_arg_as_class_names:
remaining = argc;
goto try_sole_arg_as_class_names;
}
- cus__fprintf_load_files_err(cus, "pahole", argv + remaining, err, stderr);
+ if (argv[remaining] != NULL) {
+ cus__fprintf_load_files_err(cus, "pahole", argv + remaining, err, stderr);
+ } else {
+ fprintf(stderr, "pahole: couldn't find any%s%s debug information on this system.\n",
+ conf_load.format_path ? " " : "",
+ conf_load.format_path ?: "");
+ }
+
goto out_cus_delete;
}
--
2.47.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 4/5] tests default_vmlinux_btf: Cover the no args segfault too
2024-11-19 13:40 [PATCH 0/5] Fix segfaults related to missing BTF support Arnaldo Carvalho de Melo
` (2 preceding siblings ...)
2024-11-19 13:40 ` [PATCH 3/5] pahole: Honour exclusive BTF loading Arnaldo Carvalho de Melo
@ 2024-11-19 13:40 ` Arnaldo Carvalho de Melo
2024-11-19 13:40 ` [PATCH 5/5] core, libctf: Check if constructor arguments are NULL before using them Arnaldo Carvalho de Melo
4 siblings, 0 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2024-11-19 13:40 UTC (permalink / raw)
To: Alan Maguire
Cc: Jiri Olsa, Clark Williams, Kate Carcia, dwarves,
Arnaldo Carvalho de Melo, Matthias Schwarzott, Andrii Nakryiko,
Eduard Zingerman, Song Liu, Yonghong Song
From: Arnaldo Carvalho de Melo <acme@redhat.com>
root@x1:/home/acme/git/pahole# pahole --running_kernel_vmlinux
pahole: couldn't find a vmlinux that matches the running kernel
HINT: Maybe you're inside a container or missing a debuginfo package?
root@x1:/home/acme/git/pahole# tests/default_vmlinux_btf.sh
Default BTF on a system without BTF: FAILED
root@x1:/home/acme/git/pahole# pahole
Segmentation fault (core dumped)
root@x1:/home/acme/git/pahole#
Now to fix this one as well.
Reported-by: Matthias Schwarzott <zzam@gentoo.org>
Cc: Alan Maguire <alan.maguire@oracle.com>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Eduard Zingerman <eddyz87@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Song Liu <song@kernel.org>
Cc: Yonghong Song <yonghong.song@linux.dev>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tests/default_vmlinux_btf.sh | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/tests/default_vmlinux_btf.sh b/tests/default_vmlinux_btf.sh
index a9effa2d6d37e0ee..a855ca7587380934 100755
--- a/tests/default_vmlinux_btf.sh
+++ b/tests/default_vmlinux_btf.sh
@@ -17,5 +17,16 @@ if [ $nr_lines -eq 0 ] ; then
exit 1
fi
+# There is also the case where no debugging info is available, be it DWARF of
+# BTF and it segfaults when calling just 'pahole', with no args, so check for
+# that as well
+#
+nr_lines=$(PAHOLE_VMLINUX_BTF_FILENAME=foobar pahole 2>&1 | wc -l)
+
+if [ $nr_lines -eq 0 ] ; then
+ echo "FAILED"
+ exit 1
+fi
+
echo "Ok"
exit 0
--
2.47.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 5/5] core, libctf: Check if constructor arguments are NULL before using them
2024-11-19 13:40 [PATCH 0/5] Fix segfaults related to missing BTF support Arnaldo Carvalho de Melo
` (3 preceding siblings ...)
2024-11-19 13:40 ` [PATCH 4/5] tests default_vmlinux_btf: Cover the no args segfault too Arnaldo Carvalho de Melo
@ 2024-11-19 13:40 ` Arnaldo Carvalho de Melo
4 siblings, 0 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2024-11-19 13:40 UTC (permalink / raw)
To: Alan Maguire
Cc: Jiri Olsa, Clark Williams, Kate Carcia, dwarves,
Arnaldo Carvalho de Melo, Matthias Schwarzott, Andrii Nakryiko,
Eduard Zingerman, Song Liu, Yonghong Song
From: Arnaldo Carvalho de Melo <acme@redhat.com>
# pahole
Segmentation fault (core dumped)
#
Now we have:
# ls -la bla
ls: cannot access 'bla': No such file or directory
# export PAHOLE_VMLINUX_BTF_FILENAME=bla
# pahole
pahole: couldn't find any debug information on this system.
# pahole list_head
pahole: couldn't find any debug information on this system.
# pahole -F btf list_head
pahole: couldn't find any btf debug information on this system.
# pahole -F dwarf list_head
pahole: couldn't find any dwarf debug information on this system.
# tests/default_vmlinux_btf.sh
Default BTF on a system without BTF: Ok
#
Reported-by: Matthias Schwarzott <zzam@gentoo.org>
Cc: Alan Maguire <alan.maguire@oracle.com>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Eduard Zingerman <eddyz87@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Song Liu <song@kernel.org>
Cc: Yonghong Song <yonghong.song@linux.dev>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
dwarves.c | 3 +++
libctf.c | 3 +++
2 files changed, 6 insertions(+)
diff --git a/dwarves.c b/dwarves.c
index 459311e64c8b45b2..ae512b9f46ddcc0a 100644
--- a/dwarves.c
+++ b/dwarves.c
@@ -777,6 +777,9 @@ struct cu *cu__new(const char *name, uint8_t addr_size,
if (cu->use_obstack)
obstack_init(&cu->obstack);
+ if (name == NULL || filename == NULL)
+ goto out_free;
+
cu->name = strdup(name);
if (cu->name == NULL)
goto out_free;
diff --git a/libctf.c b/libctf.c
index edb34dbf10de09e7..0641b10586527a6e 100644
--- a/libctf.c
+++ b/libctf.c
@@ -179,6 +179,9 @@ struct ctf *ctf__new(const char *filename, Elf *elf)
struct ctf *ctf = zalloc(sizeof(*ctf));
if (ctf != NULL) {
+ if (filename == NULL)
+ goto out_delete;
+
ctf->filename = strdup(filename);
if (ctf->filename == NULL)
goto out_delete;
--
2.47.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH 3/5] pahole: Honour exclusive BTF loading
2024-11-19 13:40 ` [PATCH 3/5] pahole: Honour exclusive BTF loading Arnaldo Carvalho de Melo
@ 2024-11-19 17:47 ` Alan Maguire
2024-11-19 20:18 ` Arnaldo Carvalho de Melo
2024-11-19 20:19 ` Arnaldo Carvalho de Melo
2024-11-19 22:04 ` Eduard Zingerman
1 sibling, 2 replies; 13+ messages in thread
From: Alan Maguire @ 2024-11-19 17:47 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Jiri Olsa, Clark Williams, Kate Carcia, dwarves,
Arnaldo Carvalho de Melo, Matthias Schwarzott, Andrii Nakryiko,
Eduard Zingerman, Song Liu, Yonghong Song
On 19/11/2024 13:40, Arnaldo Carvalho de Melo wrote:
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
>
> When we specify 'btf' and BTF info is available in the system, in the
> /sys/kernel/btf/vmlinux file, pahole will find it and use it to get the
> type information asked for:
>
> root@x1:~# perf trace -o /tmp/output -e openat pahole -F btf list_head ; tail -1 /tmp/output
> struct list_head {
> struct list_head * next; /* 0 8 */
> struct list_head * prev; /* 8 8 */
>
> /* size: 16, cachelines: 1, members: 2 */
> /* last cacheline: 16 bytes */
> };
>
> 1.579 ( 0.010 ms): pahole/764777 openat(dfd: CWD, filename: "/sys/kernel/btf/vmlinux", flags: RDONLY|CLOEXEC) = 3
> root@x1:~#
>
> But, if the system doesn't have BTF info, which we now can simulate by using an
> environment variable it is tryng DWARF after failing for BTF, which isn't what
> the user asked for having specified just btf in the -F pahole command line:
>
> root@x1:~# export PAHOLE_VMLINUX_BTF_FILENAME=non-existent
> root@x1:~# perf trace -o /tmp/output -e openat,access pahole -F btf list_head ; tail -12 /tmp/output
> struct list_head {
> struct list_head * next; /* 0 8 */
> struct list_head * prev; /* 8 8 */
>
> /* size: 16, cachelines: 1, members: 2 */
> /* last cacheline: 16 bytes */
> };
>
> 1.643 ( 0.003 ms): pahole/765220 access(filename: "list_head", mode: R) = -1 ENOENT (No such file or directory)
> 1.658 ( 0.002 ms): pahole/765220 access(filename: "non-existent", mode: R) = -1 ENOENT (No such file or directory)
> 1.697 ( 0.018 ms): pahole/765220 openat(dfd: CWD, filename: "/sys/kernel/notes") = 3
> 1.801 ( 0.004 ms): pahole/765220 openat(dfd: CWD, filename: "vmlinux") = -1 ENOENT (No such file or directory)
> 1.807 ( 0.005 ms): pahole/765220 openat(dfd: CWD, filename: "/boot/vmlinux") = -1 ENOENT (No such file or directory)
> 1.927 ( 0.005 ms): pahole/765220 openat(dfd: CWD, filename: "/usr/lib/debug/lib/modules/6.11.6-200.fc40.x86_64/vmlinux", flags: RDONLY|CLOEXEC) = 3
> root@x1:~#
>
> So honour the request and fails when just BTF is asked and no BTF file is
> found:
>
> # export PAHOLE_VMLINUX_BTF_FILENAME=non-existent
> # pahole -F btf list_head
> pahole: couldn't find any btf debug information on this system.
> #
>
> Reported-by: Matthias Schwarzott <zzam@gentoo.org>
> Cc: Alan Maguire <alan.maguire@oracle.com>
> Cc: Andrii Nakryiko <andrii@kernel.org>
> Cc: Eduard Zingerman <eddyz87@gmail.com>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Song Liu <song@kernel.org>
> Cc: Yonghong Song <yonghong.song@linux.dev>
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
For the series (since some of my replies didn't reach the list, apologies)
Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
Tested-by: Alan Maguire <alan.maguire@oracle.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 3/5] pahole: Honour exclusive BTF loading
2024-11-19 17:47 ` Alan Maguire
@ 2024-11-19 20:18 ` Arnaldo Carvalho de Melo
2024-11-19 20:19 ` Arnaldo Carvalho de Melo
1 sibling, 0 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2024-11-19 20:18 UTC (permalink / raw)
To: Alan Maguire
Cc: Jiri Olsa, Clark Williams, Kate Carcia, dwarves,
Arnaldo Carvalho de Melo, Matthias Schwarzott, Andrii Nakryiko,
Eduard Zingerman, Song Liu, Yonghong Song
On Tue, Nov 19, 2024 at 05:47:21PM +0000, Alan Maguire wrote:
> On 19/11/2024 13:40, Arnaldo Carvalho de Melo wrote:
> > From: Arnaldo Carvalho de Melo <acme@redhat.com>
> >
> > When we specify 'btf' and BTF info is available in the system, in the
> > /sys/kernel/btf/vmlinux file, pahole will find it and use it to get the
> > type information asked for:
> >
> > root@x1:~# perf trace -o /tmp/output -e openat pahole -F btf list_head ; tail -1 /tmp/output
> > struct list_head {
> > struct list_head * next; /* 0 8 */
> > struct list_head * prev; /* 8 8 */
> >
> > /* size: 16, cachelines: 1, members: 2 */
> > /* last cacheline: 16 bytes */
> > };
> >
> > 1.579 ( 0.010 ms): pahole/764777 openat(dfd: CWD, filename: "/sys/kernel/btf/vmlinux", flags: RDONLY|CLOEXEC) = 3
> > root@x1:~#
> >
> > But, if the system doesn't have BTF info, which we now can simulate by using an
> > environment variable it is tryng DWARF after failing for BTF, which isn't what
> > the user asked for having specified just btf in the -F pahole command line:
> >
> > root@x1:~# export PAHOLE_VMLINUX_BTF_FILENAME=non-existent
> > root@x1:~# perf trace -o /tmp/output -e openat,access pahole -F btf list_head ; tail -12 /tmp/output
> > struct list_head {
> > struct list_head * next; /* 0 8 */
> > struct list_head * prev; /* 8 8 */
> >
> > /* size: 16, cachelines: 1, members: 2 */
> > /* last cacheline: 16 bytes */
> > };
> >
> > 1.643 ( 0.003 ms): pahole/765220 access(filename: "list_head", mode: R) = -1 ENOENT (No such file or directory)
> > 1.658 ( 0.002 ms): pahole/765220 access(filename: "non-existent", mode: R) = -1 ENOENT (No such file or directory)
> > 1.697 ( 0.018 ms): pahole/765220 openat(dfd: CWD, filename: "/sys/kernel/notes") = 3
> > 1.801 ( 0.004 ms): pahole/765220 openat(dfd: CWD, filename: "vmlinux") = -1 ENOENT (No such file or directory)
> > 1.807 ( 0.005 ms): pahole/765220 openat(dfd: CWD, filename: "/boot/vmlinux") = -1 ENOENT (No such file or directory)
> > 1.927 ( 0.005 ms): pahole/765220 openat(dfd: CWD, filename: "/usr/lib/debug/lib/modules/6.11.6-200.fc40.x86_64/vmlinux", flags: RDONLY|CLOEXEC) = 3
> > root@x1:~#
> >
> > So honour the request and fails when just BTF is asked and no BTF file is
> > found:
> >
> > # export PAHOLE_VMLINUX_BTF_FILENAME=non-existent
> > # pahole -F btf list_head
> > pahole: couldn't find any btf debug information on this system.
> > #
> >
> > Reported-by: Matthias Schwarzott <zzam@gentoo.org>
> > Cc: Alan Maguire <alan.maguire@oracle.com>
> > Cc: Andrii Nakryiko <andrii@kernel.org>
> > Cc: Eduard Zingerman <eddyz87@gmail.com>
> > Cc: Jiri Olsa <jolsa@kernel.org>
> > Cc: Song Liu <song@kernel.org>
> > Cc: Yonghong Song <yonghong.song@linux.dev>
> > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
>
> For the series (since some of my replies didn't reach the list, apologies)
>
> Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
> Tested-by: Alan Maguire <alan.maguire@oracle.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 3/5] pahole: Honour exclusive BTF loading
2024-11-19 17:47 ` Alan Maguire
2024-11-19 20:18 ` Arnaldo Carvalho de Melo
@ 2024-11-19 20:19 ` Arnaldo Carvalho de Melo
1 sibling, 0 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2024-11-19 20:19 UTC (permalink / raw)
To: Alan Maguire
Cc: Jiri Olsa, Clark Williams, Kate Carcia, dwarves,
Arnaldo Carvalho de Melo, Matthias Schwarzott, Andrii Nakryiko,
Eduard Zingerman, Song Liu, Yonghong Song
On Tue, Nov 19, 2024 at 05:47:21PM +0000, Alan Maguire wrote:
> On 19/11/2024 13:40, Arnaldo Carvalho de Melo wrote:
> > From: Arnaldo Carvalho de Melo <acme@redhat.com>
> >
> > When we specify 'btf' and BTF info is available in the system, in the
> > /sys/kernel/btf/vmlinux file, pahole will find it and use it to get the
> > type information asked for:
> >
> > root@x1:~# perf trace -o /tmp/output -e openat pahole -F btf list_head ; tail -1 /tmp/output
> > struct list_head {
> > struct list_head * next; /* 0 8 */
> > struct list_head * prev; /* 8 8 */
> >
> > /* size: 16, cachelines: 1, members: 2 */
> > /* last cacheline: 16 bytes */
> > };
> >
> > 1.579 ( 0.010 ms): pahole/764777 openat(dfd: CWD, filename: "/sys/kernel/btf/vmlinux", flags: RDONLY|CLOEXEC) = 3
> > root@x1:~#
> >
> > But, if the system doesn't have BTF info, which we now can simulate by using an
> > environment variable it is tryng DWARF after failing for BTF, which isn't what
> > the user asked for having specified just btf in the -F pahole command line:
> >
> > root@x1:~# export PAHOLE_VMLINUX_BTF_FILENAME=non-existent
> > root@x1:~# perf trace -o /tmp/output -e openat,access pahole -F btf list_head ; tail -12 /tmp/output
> > struct list_head {
> > struct list_head * next; /* 0 8 */
> > struct list_head * prev; /* 8 8 */
> >
> > /* size: 16, cachelines: 1, members: 2 */
> > /* last cacheline: 16 bytes */
> > };
> >
> > 1.643 ( 0.003 ms): pahole/765220 access(filename: "list_head", mode: R) = -1 ENOENT (No such file or directory)
> > 1.658 ( 0.002 ms): pahole/765220 access(filename: "non-existent", mode: R) = -1 ENOENT (No such file or directory)
> > 1.697 ( 0.018 ms): pahole/765220 openat(dfd: CWD, filename: "/sys/kernel/notes") = 3
> > 1.801 ( 0.004 ms): pahole/765220 openat(dfd: CWD, filename: "vmlinux") = -1 ENOENT (No such file or directory)
> > 1.807 ( 0.005 ms): pahole/765220 openat(dfd: CWD, filename: "/boot/vmlinux") = -1 ENOENT (No such file or directory)
> > 1.927 ( 0.005 ms): pahole/765220 openat(dfd: CWD, filename: "/usr/lib/debug/lib/modules/6.11.6-200.fc40.x86_64/vmlinux", flags: RDONLY|CLOEXEC) = 3
> > root@x1:~#
> >
> > So honour the request and fails when just BTF is asked and no BTF file is
> > found:
> >
> > # export PAHOLE_VMLINUX_BTF_FILENAME=non-existent
> > # pahole -F btf list_head
> > pahole: couldn't find any btf debug information on this system.
> > #
> >
> > Reported-by: Matthias Schwarzott <zzam@gentoo.org>
> > Cc: Alan Maguire <alan.maguire@oracle.com>
> > Cc: Andrii Nakryiko <andrii@kernel.org>
> > Cc: Eduard Zingerman <eddyz87@gmail.com>
> > Cc: Jiri Olsa <jolsa@kernel.org>
> > Cc: Song Liu <song@kernel.org>
> > Cc: Yonghong Song <yonghong.song@linux.dev>
> > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
>
> For the series (since some of my replies didn't reach the list, apologies)
>
> Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
> Tested-by: Alan Maguire <alan.maguire@oracle.com>
Thanks, added to all csets,
- Arnaldo
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 3/5] pahole: Honour exclusive BTF loading
2024-11-19 13:40 ` [PATCH 3/5] pahole: Honour exclusive BTF loading Arnaldo Carvalho de Melo
2024-11-19 17:47 ` Alan Maguire
@ 2024-11-19 22:04 ` Eduard Zingerman
2024-11-19 22:28 ` Alan Maguire
1 sibling, 1 reply; 13+ messages in thread
From: Eduard Zingerman @ 2024-11-19 22:04 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Alan Maguire
Cc: Jiri Olsa, Clark Williams, Kate Carcia, dwarves,
Arnaldo Carvalho de Melo, Matthias Schwarzott, Andrii Nakryiko,
Song Liu, Yonghong Song
On Tue, 2024-11-19 at 10:40 -0300, Arnaldo Carvalho de Melo wrote:
[...]
I tried the following test on top of this patch-set:
----- 8< ----------------------------------------
#!/bin/bash
cat <<EOF | clang -o btf-and-dwarf.o -c -x c -g - || exit 1
struct test_val { int i; } g;
EOF
pahole --btf_encode btf-and-dwarf.o || exit 1
# Note: has to be llvm-strip, otherwise --no-strip-all is not available
llvm-strip -o only-dwarf.o --no-strip-all -R .BTF -R .BTF.ext btf-and-dwarf.o
llvm-strip -o only-btf.o --no-strip-all --strip-debug btf-and-dwarf.o
for fmt in none btf dwarf dwarf,btf; do
for file in no-such-file only-btf.o only-dwarf.o btf-and-dwarf.o; do
if [ "$fmt" == "none" ]; then
cmd="pahole"
else
cmd="pahole -F ${fmt}"
fi
printf -- "------ PAHOLE_VMLINUX_BTF_FILENAME=%-20s %-20s ------\n" "${file}" "${cmd}"
PAHOLE_VMLINUX_BTF_FILENAME=$file $cmd 2>&1 | grep -P '(test_val|pahole:)'
done
done
---------------------------------------- >8 -----
And there are a few surprising (to me) results, namely:
------ PAHOLE_VMLINUX_BTF_FILENAME=only-dwarf.o pahole ------
pahole: couldn't find any debug information on this system.
...
------ PAHOLE_VMLINUX_BTF_FILENAME=only-dwarf.o pahole -F dwarf ------
pahole: couldn't find any debug information on this system.
...
------ PAHOLE_VMLINUX_BTF_FILENAME=btf-and-dwarf.o pahole -F dwarf ------
pahole: couldn't find any debug information on this system.
...
------ PAHOLE_VMLINUX_BTF_FILENAME=only-dwarf.o pahole -F dwarf,btf ------
pahole: couldn't find any debug information on this system.
...
It looks like DWARF is never loaded.
llvm-dwarfdump shows that DWARF is indeed present in only-dwarf.o and
btf-and-dwarf.o. Is this an expected behaviour?
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 3/5] pahole: Honour exclusive BTF loading
2024-11-19 22:04 ` Eduard Zingerman
@ 2024-11-19 22:28 ` Alan Maguire
2024-11-19 22:33 ` Eduard Zingerman
0 siblings, 1 reply; 13+ messages in thread
From: Alan Maguire @ 2024-11-19 22:28 UTC (permalink / raw)
To: Eduard Zingerman, Arnaldo Carvalho de Melo
Cc: Jiri Olsa, Clark Williams, Kate Carcia, dwarves,
Arnaldo Carvalho de Melo, Matthias Schwarzott, Andrii Nakryiko,
Song Liu, Yonghong Song
On 19/11/2024 22:04, Eduard Zingerman wrote:
> On Tue, 2024-11-19 at 10:40 -0300, Arnaldo Carvalho de Melo wrote:
>
> [...]
>
> I tried the following test on top of this patch-set:
>
> ----- 8< ----------------------------------------
> #!/bin/bash
>
> cat <<EOF | clang -o btf-and-dwarf.o -c -x c -g - || exit 1
> struct test_val { int i; } g;
> EOF
> pahole --btf_encode btf-and-dwarf.o || exit 1
> # Note: has to be llvm-strip, otherwise --no-strip-all is not available
> llvm-strip -o only-dwarf.o --no-strip-all -R .BTF -R .BTF.ext btf-and-dwarf.o
> llvm-strip -o only-btf.o --no-strip-all --strip-debug btf-and-dwarf.o
>
> for fmt in none btf dwarf dwarf,btf; do
> for file in no-such-file only-btf.o only-dwarf.o btf-and-dwarf.o; do
> if [ "$fmt" == "none" ]; then
> cmd="pahole"
> else
> cmd="pahole -F ${fmt}"
> fi
> printf -- "------ PAHOLE_VMLINUX_BTF_FILENAME=%-20s %-20s ------\n" "${file}" "${cmd}"
> PAHOLE_VMLINUX_BTF_FILENAME=$file $cmd 2>&1 | grep -P '(test_val|pahole:)'
> done
> done
this is a nice test, maybe we could adapt it for inclusion. more below..
> ---------------------------------------- >8 -----
>
> And there are a few surprising (to me) results, namely:
>
> ------ PAHOLE_VMLINUX_BTF_FILENAME=only-dwarf.o pahole ------
> pahole: couldn't find any debug information on this system.
> ...
> ------ PAHOLE_VMLINUX_BTF_FILENAME=only-dwarf.o pahole -F dwarf ------
> pahole: couldn't find any debug information on this system.
> ...
> ------ PAHOLE_VMLINUX_BTF_FILENAME=btf-and-dwarf.o pahole -F dwarf ------
> pahole: couldn't find any debug information on this system.
> ...
> ------ PAHOLE_VMLINUX_BTF_FILENAME=only-dwarf.o pahole -F dwarf,btf ------
> pahole: couldn't find any debug information on this system.
> ...
>
> It looks like DWARF is never loaded.
> llvm-dwarfdump shows that DWARF is indeed present in only-dwarf.o and
> btf-and-dwarf.o. Is this an expected behaviour?
>
>
So my read of the current intent is for PAHOLE_VMLINUX_BTF_FILENAME to
provide an override path for BTF debug info only. In the above cases we
know where to find BTF but don't go on to assume there is DWARF there
too. I think this behaviour would be more surprising if the variable was
called something more generic like PAHOLE_VMLINUX_DEBUGINFO_FILENAME -
i.e. not specific to debug info type - but that's just my take.
We could certainly make the override mechanism more generic to other
debuginfo types, but I think that could be done in follow-ups. What do
you think? Thanks!
Alan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 3/5] pahole: Honour exclusive BTF loading
2024-11-19 22:28 ` Alan Maguire
@ 2024-11-19 22:33 ` Eduard Zingerman
0 siblings, 0 replies; 13+ messages in thread
From: Eduard Zingerman @ 2024-11-19 22:33 UTC (permalink / raw)
To: Alan Maguire, Arnaldo Carvalho de Melo
Cc: Jiri Olsa, Clark Williams, Kate Carcia, dwarves,
Arnaldo Carvalho de Melo, Matthias Schwarzott, Andrii Nakryiko,
Song Liu, Yonghong Song
On Tue, 2024-11-19 at 22:28 +0000, Alan Maguire wrote:
[...]
> So my read of the current intent is for PAHOLE_VMLINUX_BTF_FILENAME to
> provide an override path for BTF debug info only. In the above cases we
> know where to find BTF but don't go on to assume there is DWARF there
> too. I think this behaviour would be more surprising if the variable was
> called something more generic like PAHOLE_VMLINUX_DEBUGINFO_FILENAME -
> i.e. not specific to debug info type - but that's just my take.
Oh, right...
My bad, sorry for the noise.
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2024-11-19 22:33 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-19 13:40 [PATCH 0/5] Fix segfaults related to missing BTF support Arnaldo Carvalho de Melo
2024-11-19 13:40 ` [PATCH 1/5] core: Add method to get the vmlinux BTF filename, allow overriding it via env var Arnaldo Carvalho de Melo
2024-11-19 13:40 ` [PATCH 2/5] tests default_vmlinux_btf: Introduce test for using BTF by default Arnaldo Carvalho de Melo
2024-11-19 13:40 ` [PATCH 3/5] pahole: Honour exclusive BTF loading Arnaldo Carvalho de Melo
2024-11-19 17:47 ` Alan Maguire
2024-11-19 20:18 ` Arnaldo Carvalho de Melo
2024-11-19 20:19 ` Arnaldo Carvalho de Melo
2024-11-19 22:04 ` Eduard Zingerman
2024-11-19 22:28 ` Alan Maguire
2024-11-19 22:33 ` Eduard Zingerman
2024-11-19 13:40 ` [PATCH 4/5] tests default_vmlinux_btf: Cover the no args segfault too Arnaldo Carvalho de Melo
2024-11-19 13:40 ` [PATCH 5/5] core, libctf: Check if constructor arguments are NULL before using them Arnaldo Carvalho de Melo
-- strict thread matches above, loose matches on Subject: below --
2024-11-18 20:41 [PATCH 0/5] Fix segfaults related to missing BTF support Arnaldo Carvalho de Melo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox