Skip to content

Commit caf8a0d

Browse files
committed
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 <[email protected]> Cc: David Ahern <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Milian Wolff <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Wang Nan <[email protected]> Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 45e9005 commit caf8a0d

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

tools/perf/builtin-trace.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,24 @@ static int trace__tool_process(struct perf_tool *tool,
11601160
return trace__process_event(trace, machine, event, sample);
11611161
}
11621162

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+
11631181
static int trace__symbols_init(struct trace *trace, struct perf_evlist *evlist)
11641182
{
11651183
int err = symbol__init(NULL);
@@ -1171,7 +1189,7 @@ static int trace__symbols_init(struct trace *trace, struct perf_evlist *evlist)
11711189
if (trace->host == NULL)
11721190
return -ENOMEM;
11731191

1174-
if (trace_event__register_resolver(trace->host, machine__resolve_kernel_addr) < 0)
1192+
if (trace_event__register_resolver(trace->host, trace__machine__resolve_kernel_addr) < 0)
11751193
return -errno;
11761194

11771195
err = __machine__synthesize_threads(trace->host, &trace->tool, &trace->opts.target,

tools/perf/util/machine.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
4343

4444
machine->symbol_filter = NULL;
4545
machine->id_hdr_size = 0;
46+
machine->kptr_restrict_warned = false;
4647
machine->comm_exec = false;
4748
machine->kernel_start = 0;
4849

tools/perf/util/machine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct machine {
2828
pid_t pid;
2929
u16 id_hdr_size;
3030
bool comm_exec;
31+
bool kptr_restrict_warned;
3132
char *root_dir;
3233
struct rb_root threads;
3334
pthread_rwlock_t threads_lock;

0 commit comments

Comments
 (0)