mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] perf, tools: Fix perf record as non root with kptr_restrict == 1
@ 2014-09-24 21:39 Andi Kleen
  2014-09-27  7:24 ` [tip:perf/core] perf " tip-bot for Andi Kleen
  0 siblings, 1 reply; 2+ messages in thread
From: Andi Kleen @ 2014-09-24 21:39 UTC (permalink / raw)
  To: jolsa; +Cc: linux-kernel, namhyung, acme, mingo, peterz, Andi Kleen

From: Andi Kleen <ak@linux.intel.com>

Currently perf record always errors out when you run it as non-root
with kptr_restrict == 1, which is often the default.

Make it only warn instead and fix the kernel resolve code
to not segfault later. Profiling works still fine, except
kernel symbols are not resolved.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 tools/perf/util/event.c   | 8 ++++++--
 tools/perf/util/session.c | 2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index ed55819..4af6b27 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -558,13 +558,17 @@ int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
 	struct map *map;
 	struct kmap *kmap;
 	int err;
+	union perf_event *event;
+
+	if (machine->vmlinux_maps[0] == NULL)
+		return -1;
+
 	/*
 	 * We should get this from /sys/kernel/sections/.text, but till that is
 	 * available use this, and after it is use this as a fallback for older
 	 * kernels.
 	 */
-	union perf_event *event = zalloc((sizeof(event->mmap) +
-					  machine->id_hdr_size));
+	event = zalloc((sizeof(event->mmap) + machine->id_hdr_size));
 	if (event == NULL) {
 		pr_debug("Not enough memory synthesizing mmap event "
 			 "for kernel modules\n");
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 6d2d50d..883406f 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -119,7 +119,7 @@ struct perf_session *perf_session__new(struct perf_data_file *file,
 		 * kernel MMAP event, in perf_event__process_mmap().
 		 */
 		if (perf_session__create_kernel_maps(session) < 0)
-			goto out_delete;
+			pr_warning("Cannot read kernel map\n");
 	}
 
 	if (tool && tool->ordering_requires_timestamps &&
-- 
1.9.3


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

* [tip:perf/core] perf tools: Fix perf record as non root with kptr_restrict == 1
  2014-09-24 21:39 [PATCH] perf, tools: Fix perf record as non root with kptr_restrict == 1 Andi Kleen
@ 2014-09-27  7:24 ` tip-bot for Andi Kleen
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot for Andi Kleen @ 2014-09-27  7:24 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, hpa, mingo, peterz, namhyung, jolsa, ak, tglx

Commit-ID:  a5c2a4c9561cbbd374231bd341936dae716df9dd
Gitweb:     http://git.kernel.org/tip/a5c2a4c9561cbbd374231bd341936dae716df9dd
Author:     Andi Kleen <ak@linux.intel.com>
AuthorDate: Wed, 24 Sep 2014 14:39:54 -0700
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 26 Sep 2014 10:51:41 -0300

perf tools: Fix perf record as non root with kptr_restrict == 1

Currently perf record always errors out when you run it as non-root with
kptr_restrict == 1, which is often the default.

Make it only warn instead and fix the kernel resolve code to not
segfault later. Profiling works still fine, except kernel symbols are
not resolved.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1411594794-7229-1-git-send-email-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/event.c   | 8 ++++++--
 tools/perf/util/session.c | 2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index ed55819..4af6b27 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -558,13 +558,17 @@ int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
 	struct map *map;
 	struct kmap *kmap;
 	int err;
+	union perf_event *event;
+
+	if (machine->vmlinux_maps[0] == NULL)
+		return -1;
+
 	/*
 	 * We should get this from /sys/kernel/sections/.text, but till that is
 	 * available use this, and after it is use this as a fallback for older
 	 * kernels.
 	 */
-	union perf_event *event = zalloc((sizeof(event->mmap) +
-					  machine->id_hdr_size));
+	event = zalloc((sizeof(event->mmap) + machine->id_hdr_size));
 	if (event == NULL) {
 		pr_debug("Not enough memory synthesizing mmap event "
 			 "for kernel modules\n");
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 6d2d50d..883406f 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -119,7 +119,7 @@ struct perf_session *perf_session__new(struct perf_data_file *file,
 		 * kernel MMAP event, in perf_event__process_mmap().
 		 */
 		if (perf_session__create_kernel_maps(session) < 0)
-			goto out_delete;
+			pr_warning("Cannot read kernel map\n");
 	}
 
 	if (tool && tool->ordering_requires_timestamps &&

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

end of thread, other threads:[~2014-09-27  7:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-24 21:39 [PATCH] perf, tools: Fix perf record as non root with kptr_restrict == 1 Andi Kleen
2014-09-27  7:24 ` [tip:perf/core] perf " tip-bot for Andi Kleen

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

Powered by JetHome