Linux Perf Users
 help / color / mirror / Atom feed
* [PATCH 5.10.y 0/2] Fixed perf abort when taken branch stack sampling enabled
@ 2024-11-04 11:27 Shuai Xue
  2024-11-04 11:27 ` [PATCH 5.10.y 1/2] Revert "perf hist: Add missing puts to hist__account_cycles" Shuai Xue
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Shuai Xue @ 2024-11-04 11:27 UTC (permalink / raw)
  To: stable, linux-kernel, linux-perf-users, acme, gregkh
  Cc: adrian.hunter, alexander.shishkin, irogers, mark.rutland,
	namhyung, peterz, acme, kprateek.nayak, ravi.bangoria,
	sandipan.das, anshuman.khandual, german.gomez, james.clark,
	terrelln, seanjc, changbin.du, liuwenyu7, yangjihong1, mhiramat,
	ojeda, song, leo.yan, kjain, ak, kan.liang, atrajeev, siyanteng,
	liam.howlett, pbonzini, jolsa

On x86 platform, kernel v5.10.228, perf-report command aborts due to "free():
invalid pointer" when perf-record command is run with taken branch stack
sampling enabled. This regression can be reproduced with the following steps:

	- sudo perf record -b
	- sudo perf report

The root cause is that bi[i].to.ms.maps does not always point to thread->maps,
which is a buffer dynamically allocated by maps_new(). Instead, it may point to
&machine->kmaps, while kmaps is not a pointer but a variable. The original
upstream commit c1149037f65b ("perf hist: Add missing puts to
hist__account_cycles") worked well because machine->kmaps had been refactored to
a pointer by the previous commit 1a97cee604dc ("perf maps: Use a pointer for
kmaps").

The memory leak issue, which the reverted patch intended to fix, has been solved
by commit cf96b8e45a9b ("perf session: Add missing evlist__delete when deleting
a session"). The root cause is that the evlist is not being deleted on exit in
perf-report, perf-script, and perf-data. Consequently, the reference count of
the thread increased by thread__get() in hist_entry__init() is not decremented
in hist_entry__delete(). As a result, thread->maps is not properly freed.

To this end,

- PATCH 1/2 reverts commit a83fc293acd5c5050a4828eced4a71d2b2fffdd3 to fix the
  abort regression.
- PATCH 2/2 backports cf96b8e45a9b ("perf session: Add missing evlist__delete
  when deleting a session") to fix memory leak issue.

Riccardo Mancini (1):
  perf session: Add missing evlist__delete when deleting a session

Shuai Xue (1):
  Revert "perf hist: Add missing puts to hist__account_cycles"

 tools/perf/util/hist.c    | 10 +++-------
 tools/perf/util/session.c |  5 ++++-
 2 files changed, 7 insertions(+), 8 deletions(-)

-- 
2.39.3


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

end of thread, other threads:[~2024-11-10 10:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-04 11:27 [PATCH 5.10.y 0/2] Fixed perf abort when taken branch stack sampling enabled Shuai Xue
2024-11-04 11:27 ` [PATCH 5.10.y 1/2] Revert "perf hist: Add missing puts to hist__account_cycles" Shuai Xue
2024-11-04 11:27 ` [PATCH 5.10.y 2/2] perf session: Add missing evlist__delete when deleting a session Shuai Xue
2024-11-10  5:12 ` [PATCH 5.10.y 0/2] Fixed perf abort when taken branch stack sampling enabled Greg KH
2024-11-10 10:26   ` Shuai Xue

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox