linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/20] perf: fix several memory leaks reported by ASan on perf-test
@ 2021-07-15 16:07 Riccardo Mancini
  2021-07-15 16:07 ` [PATCH 01/20] perf nsinfo: fix refcounting Riccardo Mancini
                   ` (19 more replies)
  0 siblings, 20 replies; 50+ messages in thread
From: Riccardo Mancini @ 2021-07-15 16:07 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Ian Rogers, Namhyung Kim, Peter Zijlstra, Ingo Molnar,
	Mark Rutland, Jiri Olsa, linux-kernel, linux-perf-users,
	Riccardo Mancini

This patchset fixes several memory leaks found using ASan on perf-test. 
After this patch, all memory leaks in perf-test that were found on my machine 
are fixed.
This does not mean that there are no longer memory leaks in perf (just running
perf report or perf top raises a few), but that now it is possible to run the 
perf tests with ASan to catch future memory errors.

While many of these leaks have little to no effect on the daily use of perf 
(some were inside the test itself, other were just a missing cleanup on exit), 
other were (slightly) more serious, namely:
 - nsinfo refcounting was broken since it was not decreased when a reference was
   replaced, causing many nsinfos to never being deallocated.
 - dso__new_map refcounting was wrong, missing a __put
 - lzma stream was never closed

Below are the results of perf-test before and after this patchset. Only failed
and skipped tests are reported for brevity.

The perf binary has been compiled using
make DEBUG=1 EXTRA_CFLAGS='-fno-omit-frame-pointer -fsanitize=address'
compilation using clang shows same results.

Tests are run on my laptop: 
Intel(R) Core(TM) i7-5500U CPU @ 2.40GHz (2 cores + hyperthreading)
Fedora 34 w/ kernel 5.12.14-300.fc34.x86_64

Before this patchset:
 1: vmlinux symtab matches kallsyms                                 : FAILED!
19: 'import perf' in python                                         : FAILED!
23.1: Read Only Watchpoint                                          : Skip (missing hardware support)
31: Lookup mmap thread                                              : FAILED!
41: Session topology                                                : FAILED!
42.1: Basic BPF filtering                                           : FAILED!
42.2: BPF pinning                                                   : Skip
42.3: BPF prologue generation                                       : Skip
49: Synthesize attr update                                          : FAILED!
58: builtin clang support                                           : Skip (not compiled in)
63: Test libpfm4 support                                            : Skip (not compiled in)
65: maps__merge_in                                                  : FAILED!
73: DWARF unwind                                                    : FAILED!
78: build id cache operations                                       : FAILED!
82: Use vfs_getname probe to get syscall args filenames             : FAILED!
83: Zstd perf.data compression/decompression                        : FAILED!
86: perf stat --bpf-counters test                                   : Skip
87: Check Arm CoreSight trace data recording and synthesized samples: Skip
88: Check open filename arg using perf trace + vfs_getname          : FAILED!

After this patchset:
19: 'import perf' in python                                         : FAILED!
23.1: Read Only Watchpoint                                          : Skip (missing hardware support)
58: builtin clang support                                           : Skip (not compiled in)
63: Test libpfm4 support                                            : Skip (not compiled in)
73: DWARF unwind                                                    : FAILED!
86: perf stat --bpf-counters test                                   : Skip
87: Check Arm CoreSight trace data recording and synthesized samples: Skip

After this patchset, without ASan:
23.1: Read Only Watchpoint                                          : Skip (missing hardware support)
58: builtin clang support                                           : Skip (not compiled in)
63: Test libpfm4 support                                            : Skip (not compiled in)
86: perf stat --bpf-counters test                                   : Skip
87: Check Arm CoreSight trace data recording and synthesized samples: Skip

The two failing tests are false positives and can be skipped:
 - "19: 'import perf' in python" fails since there are memory leaks inside the 
   python library.
 - "73: DWARF unwind" fails due to stack buffer underflow, since it's unwinding
   the stack.

Riccardo

Riccardo Mancini (20):
  perf nsinfo: fix refcounting
  perf env: fix sibling_dies memory leak
  perf test: session_topology: delete session->evlist
  perf test: event_update: fix memory leak of evlist
  perf test: event_update: fix memory leak of unit
  perf dso: fix memory leak in dso__new_map
  perf test: maps__merge_in: fix memory leak of maps
  perf env: fix memory leak of cpu_pmu_caps
  perf report: free generated help strings for sort option
  perf inject: close inject.output
  perf session: cleanup trace_event
  perf script: release zstd data
  perf script: fix memory leaks in perf_script
  perf util/lzma: close lzma stream
  perf trace: free malloc'd trace fields on exit
  perf trace: free syscall->arg_fmt
  perf trace: free syscall tp fields in evsel->priv
  perf trace: free strings in trace__parse_events_option
  perf test: bpf: free obj_buf
  perf util/probe-file: delete namelist on error in del_events

 tools/perf/builtin-inject.c     | 13 ++++++---
 tools/perf/builtin-report.c     | 33 ++++++++++++++-------
 tools/perf/builtin-script.c     |  8 ++++++
 tools/perf/builtin-trace.c      | 51 +++++++++++++++++++++++++++++++--
 tools/perf/tests/bpf.c          |  1 +
 tools/perf/tests/event_update.c |  6 ++--
 tools/perf/tests/maps.c         |  2 ++
 tools/perf/tests/topology.c     |  1 +
 tools/perf/util/dso.c           |  4 ++-
 tools/perf/util/env.c           |  2 ++
 tools/perf/util/lzma.c          |  8 ++++--
 tools/perf/util/map.c           |  2 ++
 tools/perf/util/probe-event.c   |  4 ++-
 tools/perf/util/probe-file.c    |  4 +--
 tools/perf/util/session.c       |  1 +
 tools/perf/util/sort.c          |  2 +-
 tools/perf/util/sort.h          |  2 +-
 17 files changed, 116 insertions(+), 28 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 50+ messages in thread

end of thread, other threads:[~2022-01-06 20:34 UTC | newest]

Thread overview: 50+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-15 16:07 [PATCH 00/20] perf: fix several memory leaks reported by ASan on perf-test Riccardo Mancini
2021-07-15 16:07 ` [PATCH 01/20] perf nsinfo: fix refcounting Riccardo Mancini
2021-07-15 19:02   ` Arnaldo Carvalho de Melo
2021-07-15 19:07     ` Arnaldo Carvalho de Melo
2021-07-15 19:20     ` Arnaldo Carvalho de Melo
2022-01-05  6:19       ` Krister Johansen
2022-01-06 20:27         ` Arnaldo Carvalho de Melo
2022-01-06 20:34           ` Arnaldo Carvalho de Melo
2021-07-15 19:44     ` Arnaldo Carvalho de Melo
2021-07-15 16:07 ` [PATCH 02/20] perf env: fix sibling_dies memory leak Riccardo Mancini
2021-07-15 19:49   ` Arnaldo Carvalho de Melo
2021-07-16 13:13     ` Riccardo Mancini
2021-07-15 16:07 ` [PATCH 03/20] perf test: session_topology: delete session->evlist Riccardo Mancini
2021-07-15 19:51   ` Arnaldo Carvalho de Melo
2021-07-15 16:07 ` [PATCH 04/20] perf test: event_update: fix memory leak of evlist Riccardo Mancini
2021-07-15 19:54   ` Arnaldo Carvalho de Melo
2021-07-15 16:07 ` [PATCH 05/20] perf test: event_update: fix memory leak of unit Riccardo Mancini
2021-07-15 19:58   ` Arnaldo Carvalho de Melo
2021-07-15 16:07 ` [PATCH 06/20] perf dso: fix memory leak in dso__new_map Riccardo Mancini
2021-07-15 20:01   ` Arnaldo Carvalho de Melo
2021-07-15 20:07   ` Arnaldo Carvalho de Melo
2021-07-15 16:07 ` [PATCH 07/20] perf test: maps__merge_in: fix memory leak of maps Riccardo Mancini
2021-07-15 20:10   ` Arnaldo Carvalho de Melo
2021-07-15 16:07 ` [PATCH 08/20] perf env: fix memory leak of cpu_pmu_caps Riccardo Mancini
2021-07-15 20:12   ` Arnaldo Carvalho de Melo
2021-07-15 16:07 ` [PATCH 09/20] perf report: free generated help strings for sort option Riccardo Mancini
2021-07-15 20:15   ` Arnaldo Carvalho de Melo
2021-07-15 16:07 ` [PATCH 10/20] perf inject: close inject.output Riccardo Mancini
2021-07-15 20:17   ` Arnaldo Carvalho de Melo
2021-07-15 16:07 ` [PATCH 11/20] perf session: cleanup trace_event Riccardo Mancini
2021-07-15 20:21   ` Arnaldo Carvalho de Melo
2021-07-15 16:07 ` [PATCH 12/20] perf script: release zstd data Riccardo Mancini
2021-07-15 20:23   ` Arnaldo Carvalho de Melo
2021-07-15 16:07 ` [PATCH 13/20] perf script: fix memory leaks in perf_script Riccardo Mancini
2021-07-15 20:25   ` Arnaldo Carvalho de Melo
2021-07-15 16:07 ` [PATCH 14/20] perf util/lzma: close lzma stream Riccardo Mancini
2021-07-15 20:31   ` Arnaldo Carvalho de Melo
2021-07-15 16:07 ` [PATCH 15/20] perf trace: free malloc'd trace fields on exit Riccardo Mancini
2021-07-15 20:32   ` Arnaldo Carvalho de Melo
2021-07-15 16:07 ` [PATCH 16/20] perf trace: free syscall->arg_fmt Riccardo Mancini
2021-07-15 20:35   ` Arnaldo Carvalho de Melo
2021-07-15 16:07 ` [PATCH 17/20] perf trace: free syscall tp fields in evsel->priv Riccardo Mancini
2021-07-15 20:35   ` Arnaldo Carvalho de Melo
2021-07-15 16:07 ` [PATCH 18/20] perf trace: free strings in trace__parse_events_option Riccardo Mancini
2021-07-15 20:36   ` Arnaldo Carvalho de Melo
2021-07-15 16:07 ` [PATCH 19/20] perf test: bpf: free obj_buf Riccardo Mancini
2021-07-15 20:39   ` Arnaldo Carvalho de Melo
2021-07-16 16:50   ` Arnaldo Carvalho de Melo
2021-07-15 16:07 ` [PATCH 20/20] perf util/probe-file: delete namelist on error in del_events Riccardo Mancini
2021-07-15 20:41   ` 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;
as well as URLs for NNTP newsgroup(s).