Skip to contentSkip to conversation

perf/urgent fixes

GIT PULL New Arnaldo Carvalho de Melo 2 participants 4 messages Sep 22, 2015 – Sep 23, 2015

Subsystems (2)
lore
Share & tools
lore

Arnaldo Carvalho de Melo

author maintainer
#0 lore raw

Hi Ingo,

Please consider pulling,

- Arnaldo

The following changes since commit f73e22ab450140830005581c2c7ec389791a1b8d:

perf: Fix races in computing the header sizes (2015-09-18 09:20:26 +0200)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-urgent-for-mingo

for you to fetch changes up to c2e4b24ff848bb180f9b9cd873a38327cd219ad2:

tools lib traceevent: Fix string handling in heterogeneous arch environments (2015-09-22 11:57:04 -0300)

----------------------------------------------------------------
perf/urgent fixes:

User visible:

- Fix libtraceevent string handling in heterogeneous arch environments (Kapileshwar Singh)

- Avoid infinite loop at buildid processing with no samples in 'perf record' (Mark Rutland)

----------------------------------------------------------------
Kapileshwar Singh (1):
tools lib traceevent: Fix string handling in heterogeneous arch environments

Mark Rutland (1):
perf record: Avoid infinite loop at buildid processing with no samples

 tools/lib/traceevent/event-parse.c | 23 ++++++++++++++++++++---
 tools/perf/util/session.c          |  5 ++++-
 2 files changed, 24 insertions(+), 4 deletions(-)
author maintainer
#1 lore raw

PATCH 1/2 perf record: Avoid infinite loop at buildid processing with no samples

From: Mark Rutland <[email protected]>

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).

Commiter note:

I only managed to reproduce this when setting /proc/sys/kernel/kptr_restrict to '1' and changing the code to purposefully not process any samples and no synthesized samples, i.e. kptr_restrict prevents 'record' from synthesizing the kernel mmaps for vmlinux + modules and since it is a workload started from perf, we don't synthesize mmap/comm records for existing threads.

Adrian Hunter managed to reproduce it in his environment tho.

---
 tools/perf/util/session.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/session.c +4 -1
index 8a4537ee9bc3..fc3f7c922f99 100644
@@ -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...");
Signature · 1 line
2.1.0
author maintainer
#2 lore raw

PATCH 2/2 tools lib traceevent: Fix string handling in heterogeneous arch environments

In reply to Arnaldo Carvalho de Melo

From: Kapileshwar Singh <[email protected]>

When a trace recorded on a 32-bit device is processed with a 64-bit binary, the higher 32-bits of the address need to ignored.

The lack of this results in the output of the 64-bit pointer value to the trace as the 32-bit address lookup fails in find_printk().

Before:

burn-1778 [003] 548.600305: bputs: 0xc0046db2s: 2cec5c058d98c

After:

burn-1778 [003] 548.600305: bputs: 0xc0046db2s: RT throttling activated

The problem occurs in PRINT_FIELD when the field is recognized as a pointer to a string (of the type const char *)

Heterogeneous architectures cases below can arise and should be handled:

* Traces recorded using 32-bit addresses processed on a 64-bit machine
* Traces recorded using 64-bit addresses processed on a 32-bit machine

---
 tools/lib/traceevent/event-parse.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)
tools/lib/traceevent/event-parse.c +20 -3
index 4d885934b919..cf42b090477b 100644
@@ -3795,7 +3795,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
 	struct format_field *field;
 	struct printk_map *printk;
 	long long val, fval;
-	unsigned long addr;
+	unsigned long long addr;
 	char *str;
 	unsigned char *hex;
 	int print;
@@ -3828,13 +3828,30 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
 		 */
 		if (!(field->flags & FIELD_IS_ARRAY) &&
 		    field->size == pevent->long_size) {
-			addr = *(unsigned long *)(data + field->offset);
+
+			/* Handle heterogeneous recording and processing
+			 * architectures
+			 *
+			 * CASE I:
+			 * Traces recorded on 32-bit devices (32-bit
+			 * addressing) and processed on 64-bit devices:
+			 * In this case, only 32 bits should be read.
+			 *
+			 * CASE II:
+			 * Traces recorded on 64 bit devices and processed
+			 * on 32-bit devices:
+			 * In this case, 64 bits must be read.
+			 */
+			addr = (pevent->long_size == 8) ?
+				*(unsigned long long *)(data + field->offset) :
+				(unsigned long long)*(unsigned int *)(data + field->offset);
+
 			/* Check if it matches a print format */
 			printk = find_printk(pevent, addr);
 			if (printk)
 				trace_seq_puts(s, printk->printk);
 			else
-				trace_seq_printf(s, "%lx", addr);
+				trace_seq_printf(s, "%llx", addr);
 			break;
 		}
 		str = malloc(len + 1);
Signature · 1 line
2.1.0
#3 lore raw
In reply to Arnaldo Carvalho de Melo
Quoted 33 lines · Arnaldo Carvalho de Melo

Hi Ingo,

Please consider pulling,

- Arnaldo

The following changes since commit f73e22ab450140830005581c2c7ec389791a1b8d:

perf: Fix races in computing the header sizes (2015-09-18 09:20:26 +0200)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-urgent-for-mingo

for you to fetch changes up to c2e4b24ff848bb180f9b9cd873a38327cd219ad2:

tools lib traceevent: Fix string handling in heterogeneous arch environments (2015-09-22 11:57:04 -0300)

----------------------------------------------------------------
perf/urgent fixes:

User visible:

- Fix libtraceevent string handling in heterogeneous arch environments (Kapileshwar Singh)

- Avoid infinite loop at buildid processing with no samples in 'perf record' (Mark Rutland)

----------------------------------------------------------------
Kapileshwar Singh (1):
tools lib traceevent: Fix string handling in heterogeneous arch environments

Quoted 6 lines

Mark Rutland (1):
perf record: Avoid infinite loop at buildid processing with no samples

 tools/lib/traceevent/event-parse.c | 23 ++++++++++++++++++++---
 tools/perf/util/session.c          |  5 ++++-
 2 files changed, 24 insertions(+), 4 deletions(-)

Pulled, thanks Arnaldo!

Ingo