* [PATCH] tools/perf: Fix segfault during perf record --off-cpu when debuginfo is not enabled
@ 2024-12-23 13:58 Athira Rajeev
2024-12-27 10:48 ` Athira Rajeev
0 siblings, 1 reply; 6+ messages in thread
From: Athira Rajeev @ 2024-12-23 13:58 UTC (permalink / raw)
To: acme, jolsa, adrian.hunter, irogers, namhyung, hbathini
Cc: linux-kernel, linux-perf-users, linuxppc-dev, maddy, atrajeev,
kjain, disgoel
When kernel is built without debuginfo, running perf record with
--off-cpu results in segfault as below:
./perf record --off-cpu -e dummy sleep 1
libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', was CONFIG_DEBUG_INFO_BTF enabled?
libbpf: failed to find '.BTF' ELF section in /lib/modules/6.13.0-rc3+/build/vmlinux
libbpf: failed to find valid kernel BTF
Segmentation fault (core dumped)
The backtrace pointed to:
#0 0x00000000100fb17c in btf.type_cnt ()
#1 0x00000000100fc1a8 in btf_find_by_name_kind ()
#2 0x00000000100fc38c in btf.find_by_name_kind ()
#3 0x00000000102ee3ac in off_cpu_prepare ()
#4 0x000000001002f78c in cmd_record ()
#5 0x00000000100aee78 in run_builtin ()
#6 0x00000000100af3e4 in handle_internal_command ()
#7 0x000000001001004c in main ()
Code sequence is:
static void check_sched_switch_args(void)
{
struct btf *btf = btf__load_vmlinux_btf();
const struct btf_type *t1, *t2, *t3;
u32 type_id;
type_id = btf__find_by_name_kind(btf, "btf_trace_sched_switch",
BTF_KIND_TYPEDEF);
btf__load_vmlinux_btf fails when CONFIG_DEBUG_INFO_BTF is not enabled.
Here bpf__find_by_name_kind calls btf__type_cnt with NULL btf
value and results in segfault. To fix this, add a check to see if
btf is not NULL before invoking bpf__find_by_name_kind
Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
---
tools/perf/util/bpf_off_cpu.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tools/perf/util/bpf_off_cpu.c b/tools/perf/util/bpf_off_cpu.c
index a590a8ac1f9d..4269b41d1771 100644
--- a/tools/perf/util/bpf_off_cpu.c
+++ b/tools/perf/util/bpf_off_cpu.c
@@ -100,6 +100,11 @@ static void check_sched_switch_args(void)
const struct btf_type *t1, *t2, *t3;
u32 type_id;
+ if (!btf) {
+ pr_debug("Missing btf, check if CONFIG_DEBUG_INFO_BTF is enabled\n");
+ goto cleanup;
+ }
+
type_id = btf__find_by_name_kind(btf, "btf_trace_sched_switch",
BTF_KIND_TYPEDEF);
if ((s32)type_id < 0)
--
2.43.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] tools/perf: Fix segfault during perf record --off-cpu when debuginfo is not enabled
2024-12-23 13:58 [PATCH] tools/perf: Fix segfault during perf record --off-cpu when debuginfo is not enabled Athira Rajeev
@ 2024-12-27 10:48 ` Athira Rajeev
2025-01-06 21:25 ` Namhyung Kim
0 siblings, 1 reply; 6+ messages in thread
From: Athira Rajeev @ 2024-12-27 10:48 UTC (permalink / raw)
To: acme, jolsa, adrian.hunter, irogers, namhyung, hbathini
Cc: linux-kernel, linux-perf-users, linuxppc-dev, maddy, kjain,
disgoel
> On 23 Dec 2024, at 7:28 PM, Athira Rajeev <atrajeev@linux.vnet.ibm.com> wrote:
>
> When kernel is built without debuginfo, running perf record with
> --off-cpu results in segfault as below:
>
> ./perf record --off-cpu -e dummy sleep 1
> libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', was CONFIG_DEBUG_INFO_BTF enabled?
> libbpf: failed to find '.BTF' ELF section in /lib/modules/6.13.0-rc3+/build/vmlinux
> libbpf: failed to find valid kernel BTF
> Segmentation fault (core dumped)
>
> The backtrace pointed to:
>
> #0 0x00000000100fb17c in btf.type_cnt ()
> #1 0x00000000100fc1a8 in btf_find_by_name_kind ()
> #2 0x00000000100fc38c in btf.find_by_name_kind ()
> #3 0x00000000102ee3ac in off_cpu_prepare ()
> #4 0x000000001002f78c in cmd_record ()
> #5 0x00000000100aee78 in run_builtin ()
> #6 0x00000000100af3e4 in handle_internal_command ()
> #7 0x000000001001004c in main ()
>
> Code sequence is:
> static void check_sched_switch_args(void)
> {
> struct btf *btf = btf__load_vmlinux_btf();
> const struct btf_type *t1, *t2, *t3;
> u32 type_id;
>
> type_id = btf__find_by_name_kind(btf, "btf_trace_sched_switch",
> BTF_KIND_TYPEDEF);
>
> btf__load_vmlinux_btf fails when CONFIG_DEBUG_INFO_BTF is not enabled.
> Here bpf__find_by_name_kind calls btf__type_cnt with NULL btf
> value and results in segfault. To fix this, add a check to see if
> btf is not NULL before invoking bpf__find_by_name_kind
>
> Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
> ---
> tools/perf/util/bpf_off_cpu.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/tools/perf/util/bpf_off_cpu.c b/tools/perf/util/bpf_off_cpu.c
> index a590a8ac1f9d..4269b41d1771 100644
> --- a/tools/perf/util/bpf_off_cpu.c
> +++ b/tools/perf/util/bpf_off_cpu.c
> @@ -100,6 +100,11 @@ static void check_sched_switch_args(void)
> const struct btf_type *t1, *t2, *t3;
> u32 type_id;
>
> + if (!btf) {
> + pr_debug("Missing btf, check if CONFIG_DEBUG_INFO_BTF is enabled\n");
> + goto cleanup;
> + }
> +
Hi,
Looking for review comments on this
Athira
> type_id = btf__find_by_name_kind(btf, "btf_trace_sched_switch",
> BTF_KIND_TYPEDEF);
> if ((s32)type_id < 0)
> --
> 2.43.5
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] tools/perf: Fix segfault during perf record --off-cpu when debuginfo is not enabled
2024-12-27 10:48 ` Athira Rajeev
@ 2025-01-06 21:25 ` Namhyung Kim
2025-01-10 7:42 ` Athira Rajeev
2025-01-13 15:29 ` Arnaldo Carvalho de Melo
0 siblings, 2 replies; 6+ messages in thread
From: Namhyung Kim @ 2025-01-06 21:25 UTC (permalink / raw)
To: Athira Rajeev
Cc: acme, jolsa, adrian.hunter, irogers, hbathini, linux-kernel,
linux-perf-users, linuxppc-dev, maddy, kjain, disgoel
On Fri, Dec 27, 2024 at 04:18:32PM +0530, Athira Rajeev wrote:
>
>
> > On 23 Dec 2024, at 7:28 PM, Athira Rajeev <atrajeev@linux.vnet.ibm.com> wrote:
> >
> > When kernel is built without debuginfo, running perf record with
> > --off-cpu results in segfault as below:
> >
> > ./perf record --off-cpu -e dummy sleep 1
> > libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', was CONFIG_DEBUG_INFO_BTF enabled?
> > libbpf: failed to find '.BTF' ELF section in /lib/modules/6.13.0-rc3+/build/vmlinux
> > libbpf: failed to find valid kernel BTF
> > Segmentation fault (core dumped)
> >
> > The backtrace pointed to:
> >
> > #0 0x00000000100fb17c in btf.type_cnt ()
> > #1 0x00000000100fc1a8 in btf_find_by_name_kind ()
> > #2 0x00000000100fc38c in btf.find_by_name_kind ()
> > #3 0x00000000102ee3ac in off_cpu_prepare ()
> > #4 0x000000001002f78c in cmd_record ()
> > #5 0x00000000100aee78 in run_builtin ()
> > #6 0x00000000100af3e4 in handle_internal_command ()
> > #7 0x000000001001004c in main ()
> >
> > Code sequence is:
> > static void check_sched_switch_args(void)
> > {
> > struct btf *btf = btf__load_vmlinux_btf();
> > const struct btf_type *t1, *t2, *t3;
> > u32 type_id;
> >
> > type_id = btf__find_by_name_kind(btf, "btf_trace_sched_switch",
> > BTF_KIND_TYPEDEF);
> >
> > btf__load_vmlinux_btf fails when CONFIG_DEBUG_INFO_BTF is not enabled.
> > Here bpf__find_by_name_kind calls btf__type_cnt with NULL btf
> > value and results in segfault. To fix this, add a check to see if
> > btf is not NULL before invoking bpf__find_by_name_kind
> >
> > Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Thanks,
Namhyung
> > ---
> > tools/perf/util/bpf_off_cpu.c | 5 +++++
> > 1 file changed, 5 insertions(+)
> >
> > diff --git a/tools/perf/util/bpf_off_cpu.c b/tools/perf/util/bpf_off_cpu.c
> > index a590a8ac1f9d..4269b41d1771 100644
> > --- a/tools/perf/util/bpf_off_cpu.c
> > +++ b/tools/perf/util/bpf_off_cpu.c
> > @@ -100,6 +100,11 @@ static void check_sched_switch_args(void)
> > const struct btf_type *t1, *t2, *t3;
> > u32 type_id;
> >
> > + if (!btf) {
> > + pr_debug("Missing btf, check if CONFIG_DEBUG_INFO_BTF is enabled\n");
> > + goto cleanup;
> > + }
> > +
>
> Hi,
>
> Looking for review comments on this
>
> Athira
> > type_id = btf__find_by_name_kind(btf, "btf_trace_sched_switch",
> > BTF_KIND_TYPEDEF);
> > if ((s32)type_id < 0)
> > --
> > 2.43.5
> >
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] tools/perf: Fix segfault during perf record --off-cpu when debuginfo is not enabled
2025-01-06 21:25 ` Namhyung Kim
@ 2025-01-10 7:42 ` Athira Rajeev
2025-01-13 15:29 ` Arnaldo Carvalho de Melo
1 sibling, 0 replies; 6+ messages in thread
From: Athira Rajeev @ 2025-01-10 7:42 UTC (permalink / raw)
To: Namhyung Kim, Arnaldo Carvalho de Melo
Cc: jolsa, adrian.hunter, irogers, hbathini, linux-kernel,
linux-perf-users, linuxppc-dev, maddy, kjain, disgoel
> On 7 Jan 2025, at 2:55 AM, Namhyung Kim <namhyung@kernel.org> wrote:
>
> On Fri, Dec 27, 2024 at 04:18:32PM +0530, Athira Rajeev wrote:
>>
>>
>>> On 23 Dec 2024, at 7:28 PM, Athira Rajeev <atrajeev@linux.vnet.ibm.com> wrote:
>>>
>>> When kernel is built without debuginfo, running perf record with
>>> --off-cpu results in segfault as below:
>>>
>>> ./perf record --off-cpu -e dummy sleep 1
>>> libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', was CONFIG_DEBUG_INFO_BTF enabled?
>>> libbpf: failed to find '.BTF' ELF section in /lib/modules/6.13.0-rc3+/build/vmlinux
>>> libbpf: failed to find valid kernel BTF
>>> Segmentation fault (core dumped)
>>>
>>> The backtrace pointed to:
>>>
>>> #0 0x00000000100fb17c in btf.type_cnt ()
>>> #1 0x00000000100fc1a8 in btf_find_by_name_kind ()
>>> #2 0x00000000100fc38c in btf.find_by_name_kind ()
>>> #3 0x00000000102ee3ac in off_cpu_prepare ()
>>> #4 0x000000001002f78c in cmd_record ()
>>> #5 0x00000000100aee78 in run_builtin ()
>>> #6 0x00000000100af3e4 in handle_internal_command ()
>>> #7 0x000000001001004c in main ()
>>>
>>> Code sequence is:
>>> static void check_sched_switch_args(void)
>>> {
>>> struct btf *btf = btf__load_vmlinux_btf();
>>> const struct btf_type *t1, *t2, *t3;
>>> u32 type_id;
>>>
>>> type_id = btf__find_by_name_kind(btf, "btf_trace_sched_switch",
>>> BTF_KIND_TYPEDEF);
>>>
>>> btf__load_vmlinux_btf fails when CONFIG_DEBUG_INFO_BTF is not enabled.
>>> Here bpf__find_by_name_kind calls btf__type_cnt with NULL btf
>>> value and results in segfault. To fix this, add a check to see if
>>> btf is not NULL before invoking bpf__find_by_name_kind
>>>
>>> Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
>
> Reviewed-by: Namhyung Kim <namhyung@kernel.org>
>
> Thanks,
> Namhyung
>
Thanks Namhyung for reviewing the patch
Athira
>>> ---
>>> tools/perf/util/bpf_off_cpu.c | 5 +++++
>>> 1 file changed, 5 insertions(+)
>>>
>>> diff --git a/tools/perf/util/bpf_off_cpu.c b/tools/perf/util/bpf_off_cpu.c
>>> index a590a8ac1f9d..4269b41d1771 100644
>>> --- a/tools/perf/util/bpf_off_cpu.c
>>> +++ b/tools/perf/util/bpf_off_cpu.c
>>> @@ -100,6 +100,11 @@ static void check_sched_switch_args(void)
>>> const struct btf_type *t1, *t2, *t3;
>>> u32 type_id;
>>>
>>> + if (!btf) {
>>> + pr_debug("Missing btf, check if CONFIG_DEBUG_INFO_BTF is enabled\n");
>>> + goto cleanup;
>>> + }
>>> +
>>
>> Hi,
>>
>> Looking for review comments on this
>>
>> Athira
>>> type_id = btf__find_by_name_kind(btf, "btf_trace_sched_switch",
>>> BTF_KIND_TYPEDEF);
>>> if ((s32)type_id < 0)
>>> --
>>> 2.43.5
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] tools/perf: Fix segfault during perf record --off-cpu when debuginfo is not enabled
2025-01-06 21:25 ` Namhyung Kim
2025-01-10 7:42 ` Athira Rajeev
@ 2025-01-13 15:29 ` Arnaldo Carvalho de Melo
2025-01-14 7:56 ` Athira Rajeev
1 sibling, 1 reply; 6+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-01-13 15:29 UTC (permalink / raw)
To: Namhyung Kim
Cc: Athira Rajeev, jolsa, adrian.hunter, irogers, hbathini,
linux-kernel, linux-perf-users, linuxppc-dev, maddy, kjain,
disgoel
On Mon, Jan 06, 2025 at 01:25:32PM -0800, Namhyung Kim wrote:
> On Fri, Dec 27, 2024 at 04:18:32PM +0530, Athira Rajeev wrote:
> >
> >
> > > On 23 Dec 2024, at 7:28 PM, Athira Rajeev <atrajeev@linux.vnet.ibm.com> wrote:
> > >
> > > When kernel is built without debuginfo, running perf record with
> > > --off-cpu results in segfault as below:
> > >
> > > ./perf record --off-cpu -e dummy sleep 1
> > > libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', was CONFIG_DEBUG_INFO_BTF enabled?
> > > libbpf: failed to find '.BTF' ELF section in /lib/modules/6.13.0-rc3+/build/vmlinux
> > > libbpf: failed to find valid kernel BTF
> > > Segmentation fault (core dumped)
> > >
> > > The backtrace pointed to:
> > >
> > > #0 0x00000000100fb17c in btf.type_cnt ()
> > > #1 0x00000000100fc1a8 in btf_find_by_name_kind ()
> > > #2 0x00000000100fc38c in btf.find_by_name_kind ()
> > > #3 0x00000000102ee3ac in off_cpu_prepare ()
> > > #4 0x000000001002f78c in cmd_record ()
> > > #5 0x00000000100aee78 in run_builtin ()
> > > #6 0x00000000100af3e4 in handle_internal_command ()
> > > #7 0x000000001001004c in main ()
> > >
> > > Code sequence is:
> > > static void check_sched_switch_args(void)
> > > {
> > > struct btf *btf = btf__load_vmlinux_btf();
> > > const struct btf_type *t1, *t2, *t3;
> > > u32 type_id;
> > >
> > > type_id = btf__find_by_name_kind(btf, "btf_trace_sched_switch",
> > > BTF_KIND_TYPEDEF);
> > >
> > > btf__load_vmlinux_btf fails when CONFIG_DEBUG_INFO_BTF is not enabled.
> > > Here bpf__find_by_name_kind calls btf__type_cnt with NULL btf
> > > value and results in segfault. To fix this, add a check to see if
> > > btf is not NULL before invoking bpf__find_by_name_kind
> > >
> > > Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
>
> Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Thanks, applied to perf-tools-next,
- Arnaldo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] tools/perf: Fix segfault during perf record --off-cpu when debuginfo is not enabled
2025-01-13 15:29 ` Arnaldo Carvalho de Melo
@ 2025-01-14 7:56 ` Athira Rajeev
0 siblings, 0 replies; 6+ messages in thread
From: Athira Rajeev @ 2025-01-14 7:56 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Namhyung Kim
Cc: Namhyung Kim, jolsa, adrian.hunter, irogers, hbathini,
linux-kernel, linux-perf-users, linuxppc-dev, maddy, kjain,
disgoel
> On 13 Jan 2025, at 8:59 PM, Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
>
> On Mon, Jan 06, 2025 at 01:25:32PM -0800, Namhyung Kim wrote:
>> On Fri, Dec 27, 2024 at 04:18:32PM +0530, Athira Rajeev wrote:
>>>
>>>
>>>> On 23 Dec 2024, at 7:28 PM, Athira Rajeev <atrajeev@linux.vnet.ibm.com> wrote:
>>>>
>>>> When kernel is built without debuginfo, running perf record with
>>>> --off-cpu results in segfault as below:
>>>>
>>>> ./perf record --off-cpu -e dummy sleep 1
>>>> libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', was CONFIG_DEBUG_INFO_BTF enabled?
>>>> libbpf: failed to find '.BTF' ELF section in /lib/modules/6.13.0-rc3+/build/vmlinux
>>>> libbpf: failed to find valid kernel BTF
>>>> Segmentation fault (core dumped)
>>>>
>>>> The backtrace pointed to:
>>>>
>>>> #0 0x00000000100fb17c in btf.type_cnt ()
>>>> #1 0x00000000100fc1a8 in btf_find_by_name_kind ()
>>>> #2 0x00000000100fc38c in btf.find_by_name_kind ()
>>>> #3 0x00000000102ee3ac in off_cpu_prepare ()
>>>> #4 0x000000001002f78c in cmd_record ()
>>>> #5 0x00000000100aee78 in run_builtin ()
>>>> #6 0x00000000100af3e4 in handle_internal_command ()
>>>> #7 0x000000001001004c in main ()
>>>>
>>>> Code sequence is:
>>>> static void check_sched_switch_args(void)
>>>> {
>>>> struct btf *btf = btf__load_vmlinux_btf();
>>>> const struct btf_type *t1, *t2, *t3;
>>>> u32 type_id;
>>>>
>>>> type_id = btf__find_by_name_kind(btf, "btf_trace_sched_switch",
>>>> BTF_KIND_TYPEDEF);
>>>>
>>>> btf__load_vmlinux_btf fails when CONFIG_DEBUG_INFO_BTF is not enabled.
>>>> Here bpf__find_by_name_kind calls btf__type_cnt with NULL btf
>>>> value and results in segfault. To fix this, add a check to see if
>>>> btf is not NULL before invoking bpf__find_by_name_kind
>>>>
>>>> Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
>>
>> Reviewed-by: Namhyung Kim <namhyung@kernel.org>
>
> Thanks, applied to perf-tools-next,
>
> - Arnaldo
Thanks Namhyung and Arnaldo
Athira.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-01-14 7:57 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-23 13:58 [PATCH] tools/perf: Fix segfault during perf record --off-cpu when debuginfo is not enabled Athira Rajeev
2024-12-27 10:48 ` Athira Rajeev
2025-01-06 21:25 ` Namhyung Kim
2025-01-10 7:42 ` Athira Rajeev
2025-01-13 15:29 ` Arnaldo Carvalho de Melo
2025-01-14 7:56 ` Athira Rajeev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).