* [PATCH v1 1/3] perf machine: Avoid out of bounds LBR memory read
@ 2023-10-09 21:41 Ian Rogers
2023-10-09 21:41 ` [PATCH v1 2/3] libperf rc_check: Make implicit enabling work for GCC Ian Rogers
2023-10-09 21:41 ` [PATCH v1 3/3] perf hist: Add missing puts to hist__account_cycles Ian Rogers
0 siblings, 2 replies; 3+ messages in thread
From: Ian Rogers @ 2023-10-09 21:41 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ian Rogers, Adrian Hunter, Leo Yan, Ravi Bangoria, German Gomez,
Artem Savkov, Andi Kleen, Kan Liang, linux-perf-users,
linux-kernel
Running perf top with address sanitizer and "--call-graph=lbr" fails
due to reading sample 0 when no samples exist. Add a guard to prevent
this.
Fixes: e2b23483eb1d ("perf machine: Factor out lbr_callchain_add_lbr_ip()")
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/machine.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index addfae2f63ef..e0e2c4a943e4 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -2622,16 +2622,18 @@ static int lbr_callchain_add_lbr_ip(struct thread *thread,
save_lbr_cursor_node(thread, cursor, i);
}
- /* Add LBR ip from first entries.to */
- ip = entries[0].to;
- flags = &entries[0].flags;
- *branch_from = entries[0].from;
- err = add_callchain_ip(thread, cursor, parent,
- root_al, &cpumode, ip,
- true, flags, NULL,
- *branch_from);
- if (err)
- return err;
+ if (lbr_nr > 0) {
+ /* Add LBR ip from first entries.to */
+ ip = entries[0].to;
+ flags = &entries[0].flags;
+ *branch_from = entries[0].from;
+ err = add_callchain_ip(thread, cursor, parent,
+ root_al, &cpumode, ip,
+ true, flags, NULL,
+ *branch_from);
+ if (err)
+ return err;
+ }
return 0;
}
--
2.42.0.609.gbb76f46606-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v1 2/3] libperf rc_check: Make implicit enabling work for GCC
2023-10-09 21:41 [PATCH v1 1/3] perf machine: Avoid out of bounds LBR memory read Ian Rogers
@ 2023-10-09 21:41 ` Ian Rogers
2023-10-09 21:41 ` [PATCH v1 3/3] perf hist: Add missing puts to hist__account_cycles Ian Rogers
1 sibling, 0 replies; 3+ messages in thread
From: Ian Rogers @ 2023-10-09 21:41 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ian Rogers, Adrian Hunter, Leo Yan, Ravi Bangoria, German Gomez,
Artem Savkov, Andi Kleen, Kan Liang, linux-perf-users,
linux-kernel
Make the implicit REFCOUNT_CHECKING robust to when building with GCC.
Fixes: 9be6ab181b7b ("libperf rc_check: Enable implicitly with sanitizers")
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/lib/perf/include/internal/rc_check.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/tools/lib/perf/include/internal/rc_check.h b/tools/lib/perf/include/internal/rc_check.h
index d5d771ccdc7b..e88a6d8a0b0f 100644
--- a/tools/lib/perf/include/internal/rc_check.h
+++ b/tools/lib/perf/include/internal/rc_check.h
@@ -9,8 +9,12 @@
* Enable reference count checking implicitly with leak checking, which is
* integrated into address sanitizer.
*/
-#if defined(LEAK_SANITIZER) || defined(ADDRESS_SANITIZER)
+#if defined(__SANITIZE_ADDRESS__) || defined(LEAK_SANITIZER) || defined(ADDRESS_SANITIZER)
#define REFCNT_CHECKING 1
+#elif defined(__has_feature)
+#if __has_feature(address_sanitizer) || __has_feature(leak_sanitizer)
+#define REFCNT_CHECKING 1
+#endif
#endif
/*
--
2.42.0.609.gbb76f46606-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v1 3/3] perf hist: Add missing puts to hist__account_cycles
2023-10-09 21:41 [PATCH v1 1/3] perf machine: Avoid out of bounds LBR memory read Ian Rogers
2023-10-09 21:41 ` [PATCH v1 2/3] libperf rc_check: Make implicit enabling work for GCC Ian Rogers
@ 2023-10-09 21:41 ` Ian Rogers
1 sibling, 0 replies; 3+ messages in thread
From: Ian Rogers @ 2023-10-09 21:41 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ian Rogers, Adrian Hunter, Leo Yan, Ravi Bangoria, German Gomez,
Artem Savkov, Andi Kleen, Kan Liang, linux-perf-users,
linux-kernel
Caught using reference count checking on perf top with
"--call-graph=lbr". After this no memory leaks were detected.
Fixes: 57849998e2cd ("perf report: Add processing for cycle histograms")
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/hist.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 3dc8a4968beb..ac8c0ef48a7f 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -2676,8 +2676,6 @@ void hist__account_cycles(struct branch_stack *bs, struct addr_location *al,
/* If we have branch cycles always annotate them. */
if (bs && bs->nr && entries[0].flags.cycles) {
- int i;
-
bi = sample__resolve_bstack(sample, al);
if (bi) {
struct addr_map_symbol *prev = NULL;
@@ -2692,7 +2690,7 @@ void hist__account_cycles(struct branch_stack *bs, struct addr_location *al,
* Note that perf stores branches reversed from
* program order!
*/
- for (i = bs->nr - 1; i >= 0; i--) {
+ for (int i = bs->nr - 1; i >= 0; i--) {
addr_map_symbol__account_cycles(&bi[i].from,
nonany_branch_mode ? NULL : prev,
bi[i].flags.cycles);
@@ -2701,6 +2699,12 @@ void hist__account_cycles(struct branch_stack *bs, struct addr_location *al,
if (total_cycles)
*total_cycles += bi[i].flags.cycles;
}
+ for (unsigned int i = 0; i < bs->nr; i++) {
+ map__put(bi[i].to.ms.map);
+ maps__put(bi[i].to.ms.maps);
+ map__put(bi[i].from.ms.map);
+ maps__put(bi[i].from.ms.maps);
+ }
free(bi);
}
}
--
2.42.0.609.gbb76f46606-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-10-09 21:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-09 21:41 [PATCH v1 1/3] perf machine: Avoid out of bounds LBR memory read Ian Rogers
2023-10-09 21:41 ` [PATCH v1 2/3] libperf rc_check: Make implicit enabling work for GCC Ian Rogers
2023-10-09 21:41 ` [PATCH v1 3/3] perf hist: Add missing puts to hist__account_cycles Ian Rogers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®