linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Jiri Olsa <jolsa@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	netdev@vger.kernel.org, bpf@vger.kernel.org,
	lkml <linux-kernel@vger.kernel.org>,
	Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
	Yonghong Song <yhs@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@chromium.org>,
	Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [PATCHv4 bpf-next 3/5] fprobe: Resolve symbols with ftrace_lookup_symbols
Date: Fri, 29 Apr 2022 23:54:40 +0900	[thread overview]
Message-ID: <20220429235440.58aa5045a507e79230a7ac86@kernel.org> (raw)
In-Reply-To: <20220428201207.954552-4-jolsa@kernel.org>

On Thu, 28 Apr 2022 22:12:05 +0200
Jiri Olsa <jolsa@kernel.org> wrote:

> Using ftrace_lookup_symbols to speed up symbols lookup
> in register_fprobe_syms API.
> 
> This requires syms array to be alphabetically sorted.

This line is no more needed because get_ftrace_locations sorts the syms.
Except for that, this looks good to me.

Acked-by: Masami Hiramatsu <mhiramat@kernel.org>

Thanks!

> 
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  kernel/trace/fprobe.c | 32 ++++++++++++--------------------
>  1 file changed, 12 insertions(+), 20 deletions(-)
> 
> diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
> index 89d9f994ebb0..aac63ca9c3d1 100644
> --- a/kernel/trace/fprobe.c
> +++ b/kernel/trace/fprobe.c
> @@ -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);
>  }
>  
> -- 
> 2.35.1
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

  reply	other threads:[~2022-04-29 14:54 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-28 20:12 [PATCHv4 bpf-next 0/5] bpf: Speed up symbol resolving in kprobe multi link Jiri Olsa
2022-04-28 20:12 ` [PATCHv4 bpf-next 1/5] kallsyms: Fully export kallsyms_on_each_symbol function Jiri Olsa
2022-04-29 14:51   ` Masami Hiramatsu
2022-04-28 20:12 ` [PATCHv4 bpf-next 2/5] ftrace: Add ftrace_lookup_symbols function Jiri Olsa
2022-04-29 14:56   ` Masami Hiramatsu
2022-04-28 20:12 ` [PATCHv4 bpf-next 3/5] fprobe: Resolve symbols with ftrace_lookup_symbols Jiri Olsa
2022-04-29 14:54   ` Masami Hiramatsu [this message]
2022-04-28 20:12 ` [PATCHv4 bpf-next 4/5] bpf: Resolve symbols with ftrace_lookup_symbols for kprobe multi link Jiri Olsa
2022-04-28 20:12 ` [PATCHv4 bpf-next 5/5] selftests/bpf: Add attach bench test Jiri Olsa
2022-04-29 14:28 ` [PATCHv4 bpf-next 0/5] bpf: Speed up symbol resolving in kprobe multi link Andrii Nakryiko
2022-04-30 12:14   ` Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220429235440.58aa5045a507e79230a7ac86@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kafai@fb.com \
    --cc=kpsingh@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=songliubraving@fb.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).