All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] perf: Fixed perf trace, 32bit return values to 64bit
@ 2014-09-26 12:54 Chang Hyun Park
  2014-09-29 18:28 ` Arnaldo Carvalho de Melo
  2014-10-03  5:25 ` [tip:perf/core] perf trace: Fix mmap return address truncation to 32-bit tip-bot for Chang Hyun Park
  0 siblings, 2 replies; 3+ messages in thread
From: Chang Hyun Park @ 2014-09-26 12:54 UTC (permalink / raw)
  To: linux-kernel; +Cc: tglx, mingo, hpa

perf trace for syscalls resulted in mmap return values being stripped of
the top 32 bits, and actually printing only the lower 32 bits. This was
because the ret value was of an 'int' type and not a 'long' type.

The Problem:
991258501.244 ( 0.004 ms): mmap(len: 40001536, prot: READ|WRITE, flags:
		PRIVATE|ANONYMOUS, fd: -1) = 0x56691000
991258501.257 ( 0.000 ms): minfault [_int_malloc+0x1038] =>
			    //anon@0x7fa056691008 //(d.)

The first line shows an mmap, which succeeds and returns 0x56691000.
However the next line shows a memory access to that virtual memory area,
specifically to 0x7fa056691008. The upper 32 bit is lost due to the
problem mentioned above, and thus mmap's return value didn't have the
upper 0x7fa0.

Tested on 3.17-rc5 from the linus's tree, and the HEAD of tip/master

Signed-off-by: Chang Hyun Park <heartinpiece@gmail.com>
---
 tools/perf/builtin-trace.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index a6c3752..31a7b69 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1669,7 +1669,7 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
 			   union perf_event *event __maybe_unused,
 			   struct perf_sample *sample)
 {
-	int ret;
+	long ret;
 	u64 duration = 0;
 	struct thread *thread;
 	int id = perf_evsel__sc_tp_uint(evsel, id, sample);
@@ -1722,7 +1722,7 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
 
 	if (sc->fmt == NULL) {
 signed_print:
-		fprintf(trace->output, ") = %d", ret);
+		fprintf(trace->output, ") = %ld", ret);
 	} else if (ret < 0 && sc->fmt->errmsg) {
 		char bf[256];
 		const char *emsg = strerror_r(-ret, bf, sizeof(bf)),
@@ -1732,7 +1732,7 @@ signed_print:
 	} else if (ret == 0 && sc->fmt->timeout)
 		fprintf(trace->output, ") = 0 Timeout");
 	else if (sc->fmt->hexret)
-		fprintf(trace->output, ") = %#x", ret);
+		fprintf(trace->output, ") = %#lx", ret);
 	else
 		goto signed_print;
 
-- 
1.9.1


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

* Re: [PATCH 1/1] perf: Fixed perf trace, 32bit return values to 64bit
  2014-09-26 12:54 [PATCH 1/1] perf: Fixed perf trace, 32bit return values to 64bit Chang Hyun Park
@ 2014-09-29 18:28 ` Arnaldo Carvalho de Melo
  2014-10-03  5:25 ` [tip:perf/core] perf trace: Fix mmap return address truncation to 32-bit tip-bot for Chang Hyun Park
  1 sibling, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2014-09-29 18:28 UTC (permalink / raw)
  To: Chang Hyun Park; +Cc: linux-kernel, tglx, mingo, hpa

Em Fri, Sep 26, 2014 at 09:54:01PM +0900, Chang Hyun Park escreveu:
> perf trace for syscalls resulted in mmap return values being stripped of
> the top 32 bits, and actually printing only the lower 32 bits. This was
> because the ret value was of an 'int' type and not a 'long' type.
> 
> The Problem:
> 991258501.244 ( 0.004 ms): mmap(len: 40001536, prot: READ|WRITE, flags:
> 		PRIVATE|ANONYMOUS, fd: -1) = 0x56691000
> 991258501.257 ( 0.000 ms): minfault [_int_malloc+0x1038] =>
> 			    //anon@0x7fa056691008 //(d.)
> 
> The first line shows an mmap, which succeeds and returns 0x56691000.
> However the next line shows a memory access to that virtual memory area,
> specifically to 0x7fa056691008. The upper 32 bit is lost due to the
> problem mentioned above, and thus mmap's return value didn't have the
> upper 0x7fa0.

Thanks, applied to my perf/core branch.

- Arnaldo

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

* [tip:perf/core] perf trace: Fix mmap return address truncation to 32-bit
  2014-09-26 12:54 [PATCH 1/1] perf: Fixed perf trace, 32bit return values to 64bit Chang Hyun Park
  2014-09-29 18:28 ` Arnaldo Carvalho de Melo
@ 2014-10-03  5:25 ` tip-bot for Chang Hyun Park
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Chang Hyun Park @ 2014-10-03  5:25 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, mingo, hpa, mingo, heartinpiece, tglx

Commit-ID:  2c82c3ad56921c47f28af9eb8ed96b6d99b47623
Gitweb:     http://git.kernel.org/tip/2c82c3ad56921c47f28af9eb8ed96b6d99b47623
Author:     Chang Hyun Park <heartinpiece@gmail.com>
AuthorDate: Fri, 26 Sep 2014 21:54:01 +0900
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 29 Sep 2014 15:25:36 -0300

perf trace: Fix mmap return address truncation to 32-bit

Using 'perf trace' for mmap is truncating return values by stripping the
top 32 bits, actually printing only the lower 32 bits.

This was because the ret value was of an 'int' type and not a 'long'
type.

  The Problem:

  991258501.244 ( 0.004 ms): mmap(len: 40001536, prot: READ|WRITE, flags: PRIVATE|ANONYMOUS, fd: -1) = 0x56691000
  991258501.257 ( 0.000 ms): minfault [_int_malloc+0x1038] => //anon@0x7fa056691008 //(d.)

The first line shows an mmap, which succeeds and returns 0x56691000.

However the next line shows a memory access to that virtual memory area,
specifically to 0x7fa056691008. The upper 32 bit is lost due to the
problem mentioned above, and thus mmap's return value didn't have the
upper 0x7fa0.

Tested on 3.17-rc5 from the linus's tree, and the HEAD of tip/master

Signed-off-by: Chang Hyun Park <heartinpiece@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1411736041-8017-1-git-send-email-heartinpiece@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-trace.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index c70e69e..09bcf23 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1695,7 +1695,7 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
 			   union perf_event *event __maybe_unused,
 			   struct perf_sample *sample)
 {
-	int ret;
+	long ret;
 	u64 duration = 0;
 	struct thread *thread;
 	int id = perf_evsel__sc_tp_uint(evsel, id, sample);
@@ -1748,7 +1748,7 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
 
 	if (sc->fmt == NULL) {
 signed_print:
-		fprintf(trace->output, ") = %d", ret);
+		fprintf(trace->output, ") = %ld", ret);
 	} else if (ret < 0 && sc->fmt->errmsg) {
 		char bf[STRERR_BUFSIZE];
 		const char *emsg = strerror_r(-ret, bf, sizeof(bf)),
@@ -1758,7 +1758,7 @@ signed_print:
 	} else if (ret == 0 && sc->fmt->timeout)
 		fprintf(trace->output, ") = 0 Timeout");
 	else if (sc->fmt->hexret)
-		fprintf(trace->output, ") = %#x", ret);
+		fprintf(trace->output, ") = %#lx", ret);
 	else
 		goto signed_print;
 

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

end of thread, other threads:[~2014-10-03  5:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-26 12:54 [PATCH 1/1] perf: Fixed perf trace, 32bit return values to 64bit Chang Hyun Park
2014-09-29 18:28 ` Arnaldo Carvalho de Melo
2014-10-03  5:25 ` [tip:perf/core] perf trace: Fix mmap return address truncation to 32-bit tip-bot for Chang Hyun Park

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.