Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf trace: Warn when trying to resolve kernel addresses with kptr_restrict=1

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>

+21 -1
+19 -1
tools/perf/builtin-trace.c
··· 1160 1160 return trace__process_event(trace, machine, event, sample); 1161 1161 } 1162 1162 1163 + static char *trace__machine__resolve_kernel_addr(void *vmachine, unsigned long long *addrp, char **modp) 1164 + { 1165 + struct machine *machine = vmachine; 1166 + 1167 + if (machine->kptr_restrict_warned) 1168 + return NULL; 1169 + 1170 + if (symbol_conf.kptr_restrict) { 1171 + pr_warning("Kernel address maps (/proc/{kallsyms,modules}) are restricted.\n\n" 1172 + "Check /proc/sys/kernel/kptr_restrict.\n\n" 1173 + "Kernel samples will not be resolved.\n"); 1174 + machine->kptr_restrict_warned = true; 1175 + return NULL; 1176 + } 1177 + 1178 + return machine__resolve_kernel_addr(vmachine, addrp, modp); 1179 + } 1180 + 1163 1181 static int trace__symbols_init(struct trace *trace, struct perf_evlist *evlist) 1164 1182 { 1165 1183 int err = symbol__init(NULL); ··· 1189 1171 if (trace->host == NULL) 1190 1172 return -ENOMEM; 1191 1173 1192 - if (trace_event__register_resolver(trace->host, machine__resolve_kernel_addr) < 0) 1174 + if (trace_event__register_resolver(trace->host, trace__machine__resolve_kernel_addr) < 0) 1193 1175 return -errno; 1194 1176 1195 1177 err = __machine__synthesize_threads(trace->host, &trace->tool, &trace->opts.target,
+1
tools/perf/util/machine.c
··· 43 43 44 44 machine->symbol_filter = NULL; 45 45 machine->id_hdr_size = 0; 46 + machine->kptr_restrict_warned = false; 46 47 machine->comm_exec = false; 47 48 machine->kernel_start = 0; 48 49
+1
tools/perf/util/machine.h
··· 28 28 pid_t pid; 29 29 u16 id_hdr_size; 30 30 bool comm_exec; 31 + bool kptr_restrict_warned; 31 32 char *root_dir; 32 33 struct rb_root threads; 33 34 pthread_rwlock_t threads_lock;