Skip to content

Commit

Permalink
fprobe: Resolve symbols with ftrace_lookup_symbols
Browse files Browse the repository at this point in the history
Using ftrace_lookup_symbols to speed up symbols lookup
in register_fprobe_syms API.

Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20220510122616.2652285-4-jolsa@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
  • Loading branch information
Jiri Olsa authored and Alexei Starovoitov committed May 10, 2022
1 parent bed0d9a commit 8be9253
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions kernel/trace/fprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,39 +85,31 @@ static void fprobe_exit_handler(struct rethook_node *rh, void *data,
}
NOKPROBE_SYMBOL(fprobe_exit_handler);

static int symbols_cmp(const void *a, const void *b)
{
const char **str_a = (const char **) a;
const char **str_b = (const char **) b;

return strcmp(*str_a, *str_b);
}

/* Convert ftrace location address from symbols */
static unsigned long *get_ftrace_locations(const char **syms, int num)
{
unsigned long addr, size;
unsigned long *addrs;
int i;

/* Convert symbols to symbol address */
addrs = kcalloc(num, sizeof(*addrs), GFP_KERNEL);
if (!addrs)
return ERR_PTR(-ENOMEM);

for (i = 0; i < num; i++) {
addr = kallsyms_lookup_name(syms[i]);
if (!addr) /* Maybe wrong symbol */
goto error;

/* Convert symbol address to ftrace location. */
if (!kallsyms_lookup_size_offset(addr, &size, NULL) || !size)
goto error;
/* ftrace_lookup_symbols expects sorted symbols */
sort(syms, num, sizeof(*syms), symbols_cmp, NULL);

addr = ftrace_location_range(addr, addr + size - 1);
if (!addr) /* No dynamic ftrace there. */
goto error;
if (!ftrace_lookup_symbols(syms, num, addrs))
return addrs;

addrs[i] = addr;
}

return addrs;

error:
kfree(addrs);

return ERR_PTR(-ENOENT);
}

Expand Down

0 comments on commit 8be9253

Please sign in to comment.