* [PATCH 0/2] Perf fix two memory leakage
@ 2023-12-07 8:16 Yicong Yang
2023-12-07 8:16 ` [PATCH 1/2] perf header: Fix one memory leakage in perf_event__fprintf_event_update() Yicong Yang
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Yicong Yang @ 2023-12-07 8:16 UTC (permalink / raw)
To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
namhyung, irogers, adrian.hunter, linux-perf-users, linux-kernel
Cc: jonathan.cameron, hejunhao3, yangyicong, linuxarm
From: Yicong Yang <yangyicong@hisilicon.com>
ASan reports two memory leakage in the raw trace dump mode `perf report -D`.
One is in the framework and can be reproduced when using hisi_ptt and
arm_spe, which is fixed in Patch 1/2. Another is in the hisi_ptt parser
and fixed in Patch 2/2.
Yicong Yang (2):
perf header: Fix one memory leakage in
perf_event__fprintf_event_update()
perf hisi-ptt: Fix one memory leakage in
hisi_ptt_process_auxtrace_event()
tools/perf/util/header.c | 5 +++--
tools/perf/util/hisi-ptt.c | 1 +
2 files changed, 4 insertions(+), 2 deletions(-)
--
2.24.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] perf header: Fix one memory leakage in perf_event__fprintf_event_update()
2023-12-07 8:16 [PATCH 0/2] Perf fix two memory leakage Yicong Yang
@ 2023-12-07 8:16 ` Yicong Yang
2023-12-13 1:17 ` Namhyung Kim
2023-12-07 8:16 ` [PATCH 2/2] perf hisi-ptt: Fix one memory leakage in hisi_ptt_process_auxtrace_event() Yicong Yang
2023-12-07 18:45 ` [PATCH 0/2] Perf fix two memory leakage Ian Rogers
2 siblings, 1 reply; 6+ messages in thread
From: Yicong Yang @ 2023-12-07 8:16 UTC (permalink / raw)
To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
namhyung, irogers, adrian.hunter, linux-perf-users, linux-kernel
Cc: jonathan.cameron, hejunhao3, yangyicong, linuxarm
From: Yicong Yang <yangyicong@hisilicon.com>
When dump the raw trace by `perf report -D` ASan reports a memory
leakage in perf_event__fprintf_event_update(). It shows that we
allocated a temporary cpumap for dumping the CPUs but doesn't
release it and it's not used elsewhere. Fix this by free the
cpumap after the dumping.
Fixes: c853f9394b7b ("perf tools: Add perf_event__fprintf_event_update function")
Cc: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
---
| 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index e86b9439ffee..7190f39ccd13 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -4369,9 +4369,10 @@ size_t perf_event__fprintf_event_update(union perf_event *event, FILE *fp)
ret += fprintf(fp, "... ");
map = cpu_map__new_data(&ev->cpus.cpus);
- if (map)
+ if (map) {
ret += cpu_map__fprintf(map, fp);
- else
+ perf_cpu_map__put(map);
+ } else
ret += fprintf(fp, "failed to get cpus\n");
break;
default:
--
2.24.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] perf hisi-ptt: Fix one memory leakage in hisi_ptt_process_auxtrace_event()
2023-12-07 8:16 [PATCH 0/2] Perf fix two memory leakage Yicong Yang
2023-12-07 8:16 ` [PATCH 1/2] perf header: Fix one memory leakage in perf_event__fprintf_event_update() Yicong Yang
@ 2023-12-07 8:16 ` Yicong Yang
2023-12-13 1:20 ` Namhyung Kim
2023-12-07 18:45 ` [PATCH 0/2] Perf fix two memory leakage Ian Rogers
2 siblings, 1 reply; 6+ messages in thread
From: Yicong Yang @ 2023-12-07 8:16 UTC (permalink / raw)
To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
namhyung, irogers, adrian.hunter, linux-perf-users, linux-kernel
Cc: jonathan.cameron, hejunhao3, yangyicong, linuxarm
From: Yicong Yang <yangyicong@hisilicon.com>
ASan complains a memory leakage in hisi_ptt_process_auxtrace_event()
that the data buffer is not freed. Since currently we only support
the raw dump trace mode, the data buffer is used only within this
function. So fix this by freeing the data buffer before going out.
Fixes: 5e91e57e6809 ("perf auxtrace arm64: Add support for parsing HiSilicon PCIe Trace packet")
Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
---
tools/perf/util/hisi-ptt.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/perf/util/hisi-ptt.c b/tools/perf/util/hisi-ptt.c
index 43bd1ca62d58..52d0ce302ca0 100644
--- a/tools/perf/util/hisi-ptt.c
+++ b/tools/perf/util/hisi-ptt.c
@@ -123,6 +123,7 @@ static int hisi_ptt_process_auxtrace_event(struct perf_session *session,
if (dump_trace)
hisi_ptt_dump_event(ptt, data, size);
+ free(data);
return 0;
}
--
2.24.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] Perf fix two memory leakage
2023-12-07 8:16 [PATCH 0/2] Perf fix two memory leakage Yicong Yang
2023-12-07 8:16 ` [PATCH 1/2] perf header: Fix one memory leakage in perf_event__fprintf_event_update() Yicong Yang
2023-12-07 8:16 ` [PATCH 2/2] perf hisi-ptt: Fix one memory leakage in hisi_ptt_process_auxtrace_event() Yicong Yang
@ 2023-12-07 18:45 ` Ian Rogers
2 siblings, 0 replies; 6+ messages in thread
From: Ian Rogers @ 2023-12-07 18:45 UTC (permalink / raw)
To: Yicong Yang
Cc: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
namhyung, adrian.hunter, linux-perf-users, linux-kernel,
jonathan.cameron, hejunhao3, yangyicong, linuxarm
On Thu, Dec 7, 2023 at 12:20 AM Yicong Yang <yangyicong@huawei.com> wrote:
>
> From: Yicong Yang <yangyicong@hisilicon.com>
>
> ASan reports two memory leakage in the raw trace dump mode `perf report -D`.
> One is in the framework and can be reproduced when using hisi_ptt and
> arm_spe, which is fixed in Patch 1/2. Another is in the hisi_ptt parser
> and fixed in Patch 2/2.
>
> Yicong Yang (2):
> perf header: Fix one memory leakage in
> perf_event__fprintf_event_update()
> perf hisi-ptt: Fix one memory leakage in
> hisi_ptt_process_auxtrace_event()
>
> tools/perf/util/header.c | 5 +++--
> tools/perf/util/hisi-ptt.c | 1 +
> 2 files changed, 4 insertions(+), 2 deletions(-)
The series:
Reviewed-by: Ian Rogers <irogers@google.com>
Thanks,
Ian
> --
> 2.24.0
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] perf header: Fix one memory leakage in perf_event__fprintf_event_update()
2023-12-07 8:16 ` [PATCH 1/2] perf header: Fix one memory leakage in perf_event__fprintf_event_update() Yicong Yang
@ 2023-12-13 1:17 ` Namhyung Kim
0 siblings, 0 replies; 6+ messages in thread
From: Namhyung Kim @ 2023-12-13 1:17 UTC (permalink / raw)
To: Yicong Yang
Cc: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
irogers, adrian.hunter, linux-perf-users, linux-kernel,
jonathan.cameron, hejunhao3, yangyicong, linuxarm
Hello,
On Thu, Dec 7, 2023 at 12:20 AM Yicong Yang <yangyicong@huawei.com> wrote:
>
> From: Yicong Yang <yangyicong@hisilicon.com>
>
> When dump the raw trace by `perf report -D` ASan reports a memory
> leakage in perf_event__fprintf_event_update(). It shows that we
> allocated a temporary cpumap for dumping the CPUs but doesn't
> release it and it's not used elsewhere. Fix this by free the
> cpumap after the dumping.
>
> Fixes: c853f9394b7b ("perf tools: Add perf_event__fprintf_event_update function")
> Cc: Jiri Olsa <jolsa@kernel.org>
> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Thanks,
Namhyung
> ---
> tools/perf/util/header.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index e86b9439ffee..7190f39ccd13 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -4369,9 +4369,10 @@ size_t perf_event__fprintf_event_update(union perf_event *event, FILE *fp)
> ret += fprintf(fp, "... ");
>
> map = cpu_map__new_data(&ev->cpus.cpus);
> - if (map)
> + if (map) {
> ret += cpu_map__fprintf(map, fp);
> - else
> + perf_cpu_map__put(map);
> + } else
> ret += fprintf(fp, "failed to get cpus\n");
> break;
> default:
> --
> 2.24.0
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] perf hisi-ptt: Fix one memory leakage in hisi_ptt_process_auxtrace_event()
2023-12-07 8:16 ` [PATCH 2/2] perf hisi-ptt: Fix one memory leakage in hisi_ptt_process_auxtrace_event() Yicong Yang
@ 2023-12-13 1:20 ` Namhyung Kim
0 siblings, 0 replies; 6+ messages in thread
From: Namhyung Kim @ 2023-12-13 1:20 UTC (permalink / raw)
To: Yicong Yang
Cc: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
irogers, adrian.hunter, linux-perf-users, linux-kernel,
jonathan.cameron, hejunhao3, yangyicong, linuxarm
On Thu, Dec 7, 2023 at 12:20 AM Yicong Yang <yangyicong@huawei.com> wrote:
>
> From: Yicong Yang <yangyicong@hisilicon.com>
>
> ASan complains a memory leakage in hisi_ptt_process_auxtrace_event()
> that the data buffer is not freed. Since currently we only support
> the raw dump trace mode, the data buffer is used only within this
> function. So fix this by freeing the data buffer before going out.
>
> Fixes: 5e91e57e6809 ("perf auxtrace arm64: Add support for parsing HiSilicon PCIe Trace packet")
> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
Acked-by: Namhyung Kim <Namhyung@kernel.org>
Thanks,
Namhyung
> ---
> tools/perf/util/hisi-ptt.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/tools/perf/util/hisi-ptt.c b/tools/perf/util/hisi-ptt.c
> index 43bd1ca62d58..52d0ce302ca0 100644
> --- a/tools/perf/util/hisi-ptt.c
> +++ b/tools/perf/util/hisi-ptt.c
> @@ -123,6 +123,7 @@ static int hisi_ptt_process_auxtrace_event(struct perf_session *session,
> if (dump_trace)
> hisi_ptt_dump_event(ptt, data, size);
>
> + free(data);
> return 0;
> }
>
> --
> 2.24.0
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-12-13 1:20 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-07 8:16 [PATCH 0/2] Perf fix two memory leakage Yicong Yang
2023-12-07 8:16 ` [PATCH 1/2] perf header: Fix one memory leakage in perf_event__fprintf_event_update() Yicong Yang
2023-12-13 1:17 ` Namhyung Kim
2023-12-07 8:16 ` [PATCH 2/2] perf hisi-ptt: Fix one memory leakage in hisi_ptt_process_auxtrace_event() Yicong Yang
2023-12-13 1:20 ` Namhyung Kim
2023-12-07 18:45 ` [PATCH 0/2] Perf fix two memory leakage Ian Rogers
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).