public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf tools: session: avoid infinite loop
@ 2015-09-16 17:18 Mark Rutland
  2015-09-16 20:54 ` Arnaldo Carvalho de Melo
  2015-09-23  8:42 ` [tip:perf/core] perf record: Avoid infinite loop at buildid processing with no samples tip-bot for Mark Rutland
  0 siblings, 2 replies; 12+ messages in thread
From: Mark Rutland @ 2015-09-16 17:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: Mark Rutland, Adrian Hunter, Arnaldo Carvalho de Melo,
	Ingo Molnar, Jiri Olsa, Peter Zijlstra

If a session contains no events, we can get stuck in an infinite loop in
__perf_session__process_events, with a non-zero file_size and
data_offset, but a zero data_size.

In this case, we can mmap the entirety of the file (consisting of the
file and attribute headers), and fetch_mmaped_event will correctly
refuse to read any (unmapped and non-existent) event headers. This
causes __perf_session__process_events to unmap the file and retry with
the exact same parameters, getting stuck in an infinite loop.

This has been observed to result in an exit-time hang when counting
rare/unschedulable events with perf record, and can be triggered
artificially with the script below:

----
#!/bin/sh
printf "REPRO: launching perf\n";
./perf record -e software/config=9/ sleep 1 &
PERF_PID=$!;
sleep 0.002;
kill -2 $PERF_PID;
printf "REPRO: waiting for perf (%d) to exit...\n" "$PERF_PID";
wait $PERF_PID;
printf "REPRO: perf exited\n";
----

To avoid this, have __perf_session__process_events bail out early when
the file has no data (i.e. it has no events).

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
---
 tools/perf/util/session.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 8a4537e..fc3f7c9 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1580,7 +1580,10 @@ static int __perf_session__process_events(struct perf_session *session,
 	file_offset = page_offset;
 	head = data_offset - page_offset;
 
-	if (data_size && (data_offset + data_size < file_size))
+	if (data_size == 0)
+		goto out;
+
+	if (data_offset + data_size < file_size)
 		file_size = data_offset + data_size;
 
 	ui_progress__init(&prog, file_size, "Processing events...");
-- 
1.9.1


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

end of thread, other threads:[~2015-09-23  8:43 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-16 17:18 [PATCH] perf tools: session: avoid infinite loop Mark Rutland
2015-09-16 20:54 ` Arnaldo Carvalho de Melo
2015-09-17 15:41   ` Mark Rutland
2015-09-18  6:09     ` Adrian Hunter
2015-09-18  9:51       ` Mark Rutland
2015-09-18 10:55         ` Adrian Hunter
2015-09-18 13:37           ` Mark Rutland
2015-09-18 15:00             ` Arnaldo Carvalho de Melo
2015-09-18 15:18               ` Mark Rutland
2015-09-18 15:29                 ` Arnaldo Carvalho de Melo
2015-09-21 12:33                   ` Adrian Hunter
2015-09-23  8:42 ` [tip:perf/core] perf record: Avoid infinite loop at buildid processing with no samples tip-bot for Mark Rutland

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