Skip to contentSkip to conversation

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

PATCH New Andi Kleen 2 participants 2 messages Sep 24, 2014 – Sep 27, 2014 perf events

lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

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

From: Andi Kleen <[email protected]>

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.

---
 tools/perf/util/event.c   | 8 ++++++--
 tools/perf/util/session.c | 2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)
tools/perf/util/event.c +6 -2
index ed55819..4af6b27 100644
@@ -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");
tools/perf/util/session.c +1 -1
index 6d2d50d..883406f 100644
@@ -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 &&
Signature · 1 line
1.9.3
#1 lore raw

[tip:perf/core] perf tools: Fix perf record as non root with kptr_restrict == 1

perf tools: Fix perf record as non root with kptr_restrict == 1
Commit-ID:  a5c2a4c9561cbbd374231bd341936dae716df9dd
Gitweb:     http://git.kernel.org/tip/a5c2a4c9561cbbd374231bd341936dae716df9dd
Author:     Andi Kleen <[email protected]>
AuthorDate: Wed, 24 Sep 2014 14:39:54 -0700
Committer:  Arnaldo Carvalho de Melo <[email protected]>
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.

---
 tools/perf/util/event.c   | 8 ++++++--
 tools/perf/util/session.c | 2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)
tools/perf/util/event.c +6 -2
index ed55819..4af6b27 100644
@@ -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");
tools/perf/util/session.c +1 -1
index 6d2d50d..883406f 100644
@@ -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 &&