Commit b031220d authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Arnaldo Carvalho de Melo

perf probe: Fix to return error if no probe is added

Fix perf probe to return an error if no probe is added due to the given
probe point being on the blacklist.

To fix this problem, this moves the blacklist checking to right after
finding symbols/probe-points and marks them as skipped.

If all the symbols are skipped, "perf probe"  returns an error as it
fails to find the corresponding probe address.

E.g. currently if a blacklisted probe is given:

  # perf probe do_trap && echo 'succeed'
  Added new event:
  Warning: Skipped probing on blacklisted function: sync_regs
  succeed

No! It must fail! With this patch, it correctly fails:

  # perf probe do_trap && echo 'succeed'
  do_trap is blacklisted function, skip it.
  Probe point 'do_trap' not found.
    Error: Failed to add events.
Signed-off-by: default avatarMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Naohiro Aota <naota@elisp.net>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20150616115055.19906.31359.stgit@localhost.localdomainSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent f005813a
...@@ -246,6 +246,20 @@ static void clear_probe_trace_events(struct probe_trace_event *tevs, int ntevs) ...@@ -246,6 +246,20 @@ static void clear_probe_trace_events(struct probe_trace_event *tevs, int ntevs)
clear_probe_trace_event(tevs + i); clear_probe_trace_event(tevs + i);
} }
static bool kprobe_blacklist__listed(unsigned long address);
static bool kprobe_warn_out_range(const char *symbol, unsigned long address)
{
/* Get the address of _etext for checking non-probable text symbol */
if (kernel_get_symbol_address_by_name("_etext", false) < address)
pr_warning("%s is out of .text, skip it.\n", symbol);
else if (kprobe_blacklist__listed(address))
pr_warning("%s is blacklisted function, skip it.\n", symbol);
else
return false;
return true;
}
#ifdef HAVE_DWARF_SUPPORT #ifdef HAVE_DWARF_SUPPORT
static int kernel_get_module_dso(const char *module, struct dso **pdso) static int kernel_get_module_dso(const char *module, struct dso **pdso)
...@@ -559,7 +573,6 @@ static int post_process_probe_trace_events(struct probe_trace_event *tevs, ...@@ -559,7 +573,6 @@ static int post_process_probe_trace_events(struct probe_trace_event *tevs,
bool uprobe) bool uprobe)
{ {
struct ref_reloc_sym *reloc_sym; struct ref_reloc_sym *reloc_sym;
u64 etext_addr;
char *tmp; char *tmp;
int i, skipped = 0; int i, skipped = 0;
...@@ -575,15 +588,13 @@ static int post_process_probe_trace_events(struct probe_trace_event *tevs, ...@@ -575,15 +588,13 @@ static int post_process_probe_trace_events(struct probe_trace_event *tevs,
pr_warning("Relocated base symbol is not found!\n"); pr_warning("Relocated base symbol is not found!\n");
return -EINVAL; return -EINVAL;
} }
/* Get the address of _etext for checking non-probable text symbol */
etext_addr = kernel_get_symbol_address_by_name("_etext", false);
for (i = 0; i < ntevs; i++) { for (i = 0; i < ntevs; i++) {
if (tevs[i].point.address && !tevs[i].point.retprobe) { if (!tevs[i].point.address || tevs[i].point.retprobe)
continue;
/* If we found a wrong one, mark it by NULL symbol */ /* If we found a wrong one, mark it by NULL symbol */
if (etext_addr < tevs[i].point.address) { if (kprobe_warn_out_range(tevs[i].point.symbol,
pr_warning("%s+%lu is out of .text, skip it.\n", tevs[i].point.address)) {
tevs[i].point.symbol, tevs[i].point.offset);
tmp = NULL; tmp = NULL;
skipped++; skipped++;
} else { } else {
...@@ -600,7 +611,6 @@ static int post_process_probe_trace_events(struct probe_trace_event *tevs, ...@@ -600,7 +611,6 @@ static int post_process_probe_trace_events(struct probe_trace_event *tevs,
tevs[i].point.offset = tevs[i].point.address - tevs[i].point.offset = tevs[i].point.address -
reloc_sym->unrelocated_addr; reloc_sym->unrelocated_addr;
} }
}
return skipped; return skipped;
} }
...@@ -2126,6 +2136,27 @@ kprobe_blacklist__find_by_address(struct list_head *blacklist, ...@@ -2126,6 +2136,27 @@ kprobe_blacklist__find_by_address(struct list_head *blacklist,
return NULL; return NULL;
} }
static LIST_HEAD(kprobe_blacklist);
static void kprobe_blacklist__init(void)
{
if (!list_empty(&kprobe_blacklist))
return;
if (kprobe_blacklist__load(&kprobe_blacklist) < 0)
pr_debug("No kprobe blacklist support, ignored\n");
}
static void kprobe_blacklist__release(void)
{
kprobe_blacklist__delete(&kprobe_blacklist);
}
static bool kprobe_blacklist__listed(unsigned long address)
{
return !!kprobe_blacklist__find_by_address(&kprobe_blacklist, address);
}
static int perf_probe_event__sprintf(struct perf_probe_event *pev, static int perf_probe_event__sprintf(struct perf_probe_event *pev,
const char *module, const char *module,
struct strbuf *result) struct strbuf *result)
...@@ -2409,8 +2440,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev, ...@@ -2409,8 +2440,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
char buf[64]; char buf[64];
const char *event, *group; const char *event, *group;
struct strlist *namelist; struct strlist *namelist;
LIST_HEAD(blacklist);
struct kprobe_blacklist_node *node;
bool safename; bool safename;
if (pev->uprobes) if (pev->uprobes)
...@@ -2430,28 +2459,15 @@ static int __add_probe_trace_events(struct perf_probe_event *pev, ...@@ -2430,28 +2459,15 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
ret = -ENOMEM; ret = -ENOMEM;
goto close_out; goto close_out;
} }
/* Get kprobe blacklist if exists */
if (!pev->uprobes) {
ret = kprobe_blacklist__load(&blacklist);
if (ret < 0)
pr_debug("No kprobe blacklist support, ignored\n");
}
safename = (pev->point.function && !strisglob(pev->point.function)); safename = (pev->point.function && !strisglob(pev->point.function));
ret = 0; ret = 0;
pr_info("Added new event%s\n", (ntevs > 1) ? "s:" : ":"); pr_info("Added new event%s\n", (ntevs > 1) ? "s:" : ":");
for (i = 0; i < ntevs; i++) { for (i = 0; i < ntevs; i++) {
tev = &tevs[i]; tev = &tevs[i];
/* Skip if the symbol is out of .text (marked previously) */ /* Skip if the symbol is out of .text or blacklisted */
if (!tev->point.symbol) if (!tev->point.symbol)
continue; continue;
/* Ensure that the address is NOT blacklisted */
node = kprobe_blacklist__find_by_address(&blacklist,
tev->point.address);
if (node) {
pr_warning("Warning: Skipped probing on blacklisted function: %s\n", node->symbol);
continue;
}
if (pev->event) if (pev->event)
event = pev->event; event = pev->event;
...@@ -2513,7 +2529,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev, ...@@ -2513,7 +2529,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
tev->event); tev->event);
} }
kprobe_blacklist__delete(&blacklist);
strlist__delete(namelist); strlist__delete(namelist);
close_out: close_out:
close(fd); close(fd);
...@@ -2563,7 +2578,7 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev, ...@@ -2563,7 +2578,7 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
struct perf_probe_point *pp = &pev->point; struct perf_probe_point *pp = &pev->point;
struct probe_trace_point *tp; struct probe_trace_point *tp;
int num_matched_functions; int num_matched_functions;
int ret, i, j; int ret, i, j, skipped = 0;
map = get_target_map(pev->target, pev->uprobes); map = get_target_map(pev->target, pev->uprobes);
if (!map) { if (!map) {
...@@ -2631,7 +2646,12 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev, ...@@ -2631,7 +2646,12 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
} }
/* Add one probe point */ /* Add one probe point */
tp->address = map->unmap_ip(map, sym->start) + pp->offset; tp->address = map->unmap_ip(map, sym->start) + pp->offset;
if (reloc_sym) { /* If we found a wrong one, mark it by NULL symbol */
if (!pev->uprobes &&
kprobe_warn_out_range(sym->name, tp->address)) {
tp->symbol = NULL; /* Skip it */
skipped++;
} else if (reloc_sym) {
tp->symbol = strdup_or_goto(reloc_sym->name, nomem_out); tp->symbol = strdup_or_goto(reloc_sym->name, nomem_out);
tp->offset = tp->address - reloc_sym->addr; tp->offset = tp->address - reloc_sym->addr;
} else { } else {
...@@ -2667,6 +2687,10 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev, ...@@ -2667,6 +2687,10 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
} }
arch__fix_tev_from_maps(pev, tev, map); arch__fix_tev_from_maps(pev, tev, map);
} }
if (ret == skipped) {
ret = -ENOENT;
goto err_out;
}
out: out:
put_target_map(map, pev->uprobes); put_target_map(map, pev->uprobes);
...@@ -2737,6 +2761,9 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs) ...@@ -2737,6 +2761,9 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs)
/* Loop 1: convert all events */ /* Loop 1: convert all events */
for (i = 0; i < npevs; i++) { for (i = 0; i < npevs; i++) {
pkgs[i].pev = &pevs[i]; pkgs[i].pev = &pevs[i];
/* Init kprobe blacklist if needed */
if (!pkgs[i].pev->uprobes)
kprobe_blacklist__init();
/* Convert with or without debuginfo */ /* Convert with or without debuginfo */
ret = convert_to_probe_trace_events(pkgs[i].pev, ret = convert_to_probe_trace_events(pkgs[i].pev,
&pkgs[i].tevs); &pkgs[i].tevs);
...@@ -2744,6 +2771,8 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs) ...@@ -2744,6 +2771,8 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs)
goto end; goto end;
pkgs[i].ntevs = ret; pkgs[i].ntevs = ret;
} }
/* This just release blacklist only if allocated */
kprobe_blacklist__release();
/* Loop 2: add all events */ /* Loop 2: add all events */
for (i = 0; i < npevs; i++) { for (i = 0; i < npevs; i++) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment