From: Steven Rostedt <rostedt@goodmis.org>
To: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
Naveen N Rao <naveen@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
x86@kernel.org, linux-trace-kernel@vger.kernel.org,
linux-kernel@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCHv2 2/2] x86/kprobes: Use ftrace_location_range in __recover_probed_insn
Date: Mon, 23 Nov 2026 13:07:28 -0500 [thread overview]
Message-ID: <20261123130728.6e1e9f89@gandalf.local.home> (raw)
In-Reply-To: <20261122200239.1481088-3-jolsa@kernel.org>
On Sun, 22 Nov 2026 21:02:39 +0100
Jiri Olsa <jolsa@kernel.org> wrote:
> The __recover_probed_insn function is called for every instruction
> decoded on the way to the probed address and it uses ftrace_location
> to find out whether the instruction is the ftrace location.
>
> When the address is not ftrace location, ftrace_location does also
> the symbol lookup to map the sym+0 address to its ftrace location.
> But __recover_probed_insn only checks if the returned location is
> the address itself, and that can't be the result of the mapping
> after the lookup of the address failed, so the symbol lookup is
> done for nothing for almost every decoded instruction.
>
> Using ftrace_location_range for the address instead, which does
> just the lookup of the address.
>
> Adding the missing ftrace_location_range stub for the config
> without dynamic ftrace.
>
> Registering 20587 kprobes (as disabled) with the kprobe_many_example
> sample module [1] in qemu with 8 CPUs goes from 4.02s to 3.70s.
>
> The sample module was posted as the last patch of the kprobes
> lookup cost series [1] only to demonstrate the testing, it is not
> merged and is not going to be.
>
> [1] https://lore.kernel.org/bpf/20261109195827.1091410-1-jolsa@kernel.org/
>
Hmm, we probably should create a bool ftrace_location_addr() helper
function that does this internally. But that could come later as a clean up.
Reviewed-by: Steven Rostedt <rostedt@goodmis.org>
-- Steve
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
> arch/x86/kernel/kprobes/core.c | 6 +++++-
> include/linux/ftrace.h | 4 ++++
> 2 files changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
> index 133ff20caccd..34d71907e6d1 100644
> --- a/arch/x86/kernel/kprobes/core.c
> +++ b/arch/x86/kernel/kprobes/core.c
> @@ -207,7 +207,11 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
> bool faddr;
>
> kp = get_kprobe((void *)addr);
> - faddr = ftrace_location(addr) == addr;
> + /*
> + * Only the exact ftrace location matters, so skip the symbol
> + * lookup ftrace_location() does to map sym+0 to its location.
> + */
> + faddr = ftrace_location_range(addr, addr) == addr;
> /*
> * Use the current code if it is not modified by Kprobe
> * and it cannot be modified by ftrace.
> diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
> index 1c2056a1a68b..255751899682 100644
> --- a/include/linux/ftrace.h
> +++ b/include/linux/ftrace.h
> @@ -1075,6 +1075,10 @@ static inline unsigned long ftrace_location(unsigned long ip)
> {
> return 0;
> }
> +static inline unsigned long ftrace_location_range(unsigned long start, unsigned long end)
> +{
> + return 0;
> +}
>
> /*
> * Again users of functions that have ftrace_ops may not
prev parent reply other threads:[~2026-11-23 18:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 20:02 [PATCHv2 0/2] kprobes: Reduce registration lookup costs Jiri Olsa
2026-11-22 20:02 ` [PATCHv2 1/2] kprobes: Increase the kprobe hash table size Jiri Olsa
2026-11-23 23:49 ` Masami Hiramatsu (Google)
2026-11-24 14:19 ` Jiri Olsa
2026-11-22 20:02 ` [PATCHv2 2/2] x86/kprobes: Use ftrace_location_range in __recover_probed_insn Jiri Olsa
2026-11-23 18:07 ` Steven Rostedt [this message]
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=20261123130728.6e1e9f89@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=naveen@kernel.org \
--cc=peterz@infradead.org \
--cc=x86@kernel.org \
/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