* [PATCH v2] perf tools: perf_event_paranoid and kptr_restrict may crash on 'perf top'
@ 2021-02-25 6:25 Jackie Liu
2021-02-25 16:11 ` Jiri Olsa
0 siblings, 1 reply; 3+ messages in thread
From: Jackie Liu @ 2021-02-25 6:25 UTC (permalink / raw)
To: linux-kernel
Cc: Jackie Liu, Jiri Olsa, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
Namhyung Kim
After install the libelf-dev package and compiling perf, kptr_restrict=2
and perf_event_paranoid=3 will cause perf top to crash, because the
value of /proc/kallsyms cannot be obtained, which leads to
info->jited_ksyms == NULL. In order to solve this problem, Add a
judgment before use.
Suggested-by: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
tools/perf/util/bpf-event.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c
index 57d58c81a5f8..b1ce2d189d37 100644
--- a/tools/perf/util/bpf-event.c
+++ b/tools/perf/util/bpf-event.c
@@ -225,6 +225,11 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session,
perf_env__fetch_btf(env, info->btf_id, btf);
}
+ if (!info->jited_ksyms) {
+ err = -1;
+ goto out;
+ }
+
/* Synthesize PERF_RECORD_KSYMBOL */
for (i = 0; i < sub_prog_cnt; i++) {
__u32 *prog_lens = (__u32 *)(uintptr_t)(info->jited_func_lens);
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] perf tools: perf_event_paranoid and kptr_restrict may crash on 'perf top'
2021-02-25 6:25 [PATCH v2] perf tools: perf_event_paranoid and kptr_restrict may crash on 'perf top' Jackie Liu
@ 2021-02-25 16:11 ` Jiri Olsa
2021-02-26 0:54 ` JackieLiu
0 siblings, 1 reply; 3+ messages in thread
From: Jiri Olsa @ 2021-02-25 16:11 UTC (permalink / raw)
To: Jackie Liu
Cc: linux-kernel, Jackie Liu, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
Namhyung Kim
On Thu, Feb 25, 2021 at 02:25:30PM +0800, Jackie Liu wrote:
> After install the libelf-dev package and compiling perf, kptr_restrict=2
> and perf_event_paranoid=3 will cause perf top to crash, because the
> value of /proc/kallsyms cannot be obtained, which leads to
> info->jited_ksyms == NULL. In order to solve this problem, Add a
> judgment before use.
>
> Suggested-by: Jiri Olsa <jolsa@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
> ---
> tools/perf/util/bpf-event.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c
> index 57d58c81a5f8..b1ce2d189d37 100644
> --- a/tools/perf/util/bpf-event.c
> +++ b/tools/perf/util/bpf-event.c
> @@ -225,6 +225,11 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session,
> perf_env__fetch_btf(env, info->btf_id, btf);
> }
>
> + if (!info->jited_ksyms) {
> + err = -1;
> + goto out;
> + }
> +
I think this check should be moved above, right after line:
info = &info_linear->info;
so we don't do those extra btf checks
thanks,
jirka
> /* Synthesize PERF_RECORD_KSYMBOL */
> for (i = 0; i < sub_prog_cnt; i++) {
> __u32 *prog_lens = (__u32 *)(uintptr_t)(info->jited_func_lens);
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] perf tools: perf_event_paranoid and kptr_restrict may crash on 'perf top'
2021-02-25 16:11 ` Jiri Olsa
@ 2021-02-26 0:54 ` JackieLiu
0 siblings, 0 replies; 3+ messages in thread
From: JackieLiu @ 2021-02-26 0:54 UTC (permalink / raw)
To: Jiri Olsa
Cc: linux-kernel, Jackie Liu, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
Namhyung Kim
Thanks jirka, I will check again, and I saw another crash after this
patch, so I need to debug again.
BR, Jackie Liu
Jiri Olsa <jolsa@redhat.com> 于2021年2月26日周五 上午12:11写道:
>
> On Thu, Feb 25, 2021 at 02:25:30PM +0800, Jackie Liu wrote:
> > After install the libelf-dev package and compiling perf, kptr_restrict=2
> > and perf_event_paranoid=3 will cause perf top to crash, because the
> > value of /proc/kallsyms cannot be obtained, which leads to
> > info->jited_ksyms == NULL. In order to solve this problem, Add a
> > judgment before use.
> >
> > Suggested-by: Jiri Olsa <jolsa@redhat.com>
> > Cc: Peter Zijlstra <peterz@infradead.org>
> > Cc: Ingo Molnar <mingo@redhat.com>
> > Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> > Cc: Mark Rutland <mark.rutland@arm.com>
> > Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> > Cc: Namhyung Kim <namhyung@kernel.org>
> > Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
> > ---
> > tools/perf/util/bpf-event.c | 5 +++++
> > 1 file changed, 5 insertions(+)
> >
> > diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c
> > index 57d58c81a5f8..b1ce2d189d37 100644
> > --- a/tools/perf/util/bpf-event.c
> > +++ b/tools/perf/util/bpf-event.c
> > @@ -225,6 +225,11 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session,
> > perf_env__fetch_btf(env, info->btf_id, btf);
> > }
> >
> > + if (!info->jited_ksyms) {
> > + err = -1;
> > + goto out;
> > + }
> > +
>
> I think this check should be moved above, right after line:
>
> info = &info_linear->info;
>
> so we don't do those extra btf checks
>
> thanks,
> jirka
>
> > /* Synthesize PERF_RECORD_KSYMBOL */
> > for (i = 0; i < sub_prog_cnt; i++) {
> > __u32 *prog_lens = (__u32 *)(uintptr_t)(info->jited_func_lens);
> > --
> > 2.25.1
> >
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-02-26 0:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-25 6:25 [PATCH v2] perf tools: perf_event_paranoid and kptr_restrict may crash on 'perf top' Jackie Liu
2021-02-25 16:11 ` Jiri Olsa
2021-02-26 0:54 ` JackieLiu
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).