Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1403988

[PATCH 03/11] perf trace: Warn when trying to resolve kernel addresses with kptr_restrict=1

From Arnaldo Carvalho de Melo <acme@kernel.org>
Newsgroups linux.kernel
Subject [PATCH 03/11] perf trace: Warn when trying to resolve kernel addresses with kptr_restrict=1
Date 2016-05-20 00:30 +0200
Message-ID <rAEC6-5K2-19@gated-at.bofh.it> (permalink)
References <rAEC5-5K2-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Arnaldo Carvalho de Melo <acme@redhat.com>

Hook into the libtraceevent plugin kernel symbol resolver to warn the
user that that can't happen with kptr_restrict=1.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Milian Wolff <milian.wolff@kdab.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-9gc412xx1gl0lvqj1d1xwlyb@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-trace.c | 20 +++++++++++++++++++-
 tools/perf/util/machine.c  |  1 +
 tools/perf/util/machine.h  |  1 +
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 6e5c325148e4..e488ac756f39 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1160,6 +1160,24 @@ static int trace__tool_process(struct perf_tool *tool,
 	return trace__process_event(trace, machine, event, sample);
 }
 
+static char *trace__machine__resolve_kernel_addr(void *vmachine, unsigned long long *addrp, char **modp)
+{
+	struct machine *machine = vmachine;
+
+	if (machine->kptr_restrict_warned)
+		return NULL;
+
+	if (symbol_conf.kptr_restrict) {
+		pr_warning("Kernel address maps (/proc/{kallsyms,modules}) are restricted.\n\n"
+			   "Check /proc/sys/kernel/kptr_restrict.\n\n"
+			   "Kernel samples will not be resolved.\n");
+		machine->kptr_restrict_warned = true;
+		return NULL;
+	}
+
+	return machine__resolve_kernel_addr(vmachine, addrp, modp);
+}
+
 static int trace__symbols_init(struct trace *trace, struct perf_evlist *evlist)
 {
 	int err = symbol__init(NULL);
@@ -1171,7 +1189,7 @@ static int trace__symbols_init(struct trace *trace, struct perf_evlist *evlist)
 	if (trace->host == NULL)
 		return -ENOMEM;
 
-	if (trace_event__register_resolver(trace->host, machine__resolve_kernel_addr) < 0)
+	if (trace_event__register_resolver(trace->host, trace__machine__resolve_kernel_addr) < 0)
 		return -errno;
 
 	err = __machine__synthesize_threads(trace->host, &trace->tool, &trace->opts.target,
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index b277984aaa93..bdc33ce40bdc 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -43,6 +43,7 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
 
 	machine->symbol_filter = NULL;
 	machine->id_hdr_size = 0;
+	machine->kptr_restrict_warned = false;
 	machine->comm_exec = false;
 	machine->kernel_start = 0;
 
diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h
index 83f46790c52f..41ac9cfd416b 100644
--- a/tools/perf/util/machine.h
+++ b/tools/perf/util/machine.h
@@ -28,6 +28,7 @@ struct machine {
 	pid_t		  pid;
 	u16		  id_hdr_size;
 	bool		  comm_exec;
+	bool		  kptr_restrict_warned;
 	char		  *root_dir;
 	struct rb_root	  threads;
 	pthread_rwlock_t  threads_lock;
-- 
2.5.5

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[GIT PULL 00/11] perf/core improvements and fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  [PATCH 04/11] perf top: Use machine->kptr_restrict_warned Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  [PATCH 02/11] perf machine: Do not bail out if not managing to read ref reloc symbol Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  [PATCH 10/11] perf trace: Only auto set call-graph to "dwarf" when syscalls are being traced Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  [PATCH 03/11] perf trace: Warn when trying to resolve kernel addresses with kptr_restrict=1 Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  [PATCH 09/11] perf annotate: Sort list of recognised instructions Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  [PATCH 08/11] perf annotate: Fix identification of ARM blt and bls instructions Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  [PATCH 06/11] perf callchain: Stop validating callchains by the max_stack sysctl Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  [PATCH 01/11] perf tools: Find vdso supporting cross-platform analysis Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  [PATCH 07/11] perf tools: Fix usage of max_stack sysctl Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  [PATCH 11/11] perf tools: Set buildid dir under symfs when --symfs is provided Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  [PATCH 05/11] perf trace: Fix exit_group() formatting Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  Re: [GIT PULL 00/11] perf/core improvements and fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 17:10 +0200
    Re: [GIT PULL 00/11] perf/core improvements and fixes Ingo Molnar <mingo@kernel.org> - 2016-05-20 19:40 +0200

csiph-web