[PATCH] perf-probe: Failback to symbol-base probe for probes on module

From: Masami Hiramatsu
Date: Mon Feb 22 2021 - 20:49:57 EST


If an error occurs on post processing (this converts probe point to
_text relative address for identifying non-unique symbols) for the
probes on module, failback to symbol-base probe.

There are many non-unique name symbols (local static functions can
be in the different name spaces) in the kernel. If perf-probe uses
a symbol-based probe definition, it can be put on an unintended
symbol. To avoid such mistake, perf-probe tries to convert the
address to the _text relative address expression.

However, such symbol duplication is rare for only one module. Thus
even if the conversion fails, perf probe can failback to the symbol
based probe.

Signed-off-by: Masami Hiramatsu <mhiramat@xxxxxxxxxx>
---
tools/perf/util/probe-event.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index a9cff3a50ddf..af946f68e32e 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -779,16 +779,16 @@ post_process_module_probe_trace_events(struct probe_trace_event *tevs,

map = get_target_map(module, NULL, false);
if (!map || debuginfo__get_text_offset(dinfo, &text_offs, true) < 0) {
- pr_warning("Failed to get ELF symbols for %s\n", module);
- return -EINVAL;
+ pr_info("NOTE: Failed to get ELF symbols for %s. Use symbol based probe.\n", module);
+ return 0;
}

mod_name = find_module_name(module);
for (i = 0; i < ntevs; i++) {
- ret = post_process_probe_trace_point(&tevs[i].point,
- map, (unsigned long)text_offs);
- if (ret < 0)
- break;
+ if (post_process_probe_trace_point(&tevs[i].point,
+ map, (unsigned long)text_offs) < 0)
+ pr_info("NOTE: %s is not in the symbol map. Use symbol based probe.\n",
+ tevs[i].point.symbol);
tevs[i].point.module =
strdup(mod_name ? mod_name : module);
if (!tevs[i].point.module) {