From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Pu Hu <hupu@transsion.com>
Cc: "ada.coupriediaz@arm.com" <ada.coupriediaz@arm.com>,
"catalin.marinas@arm.com" <catalin.marinas@arm.com>,
"davem@davemloft.net" <davem@davemloft.net>,
Hongyan Xia <hongyan.xia@transsion.com>,
Jiazi Li <jiazi.li@transsion.com>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-trace-kernel@vger.kernel.org"
<linux-trace-kernel@vger.kernel.org>,
"naveen@kernel.org" <naveen@kernel.org>,
"will@kernel.org" <will@kernel.org>,
"yang@os.amperecomputing.com" <yang@os.amperecomputing.com>
Subject: Re: [RFC v2 1/3] arm64: kprobes: Only handle faults originating from XOL slot
Date: Fri, 10 Jul 2026 13:10:47 +0900 [thread overview]
Message-ID: <20260710131047.1806f8477422f9c1703471eb@kernel.org> (raw)
In-Reply-To: <20260709142215.226872-2-hupu@transsion.com>
On Thu, 9 Jul 2026 14:22:23 +0000
Pu Hu <hupu@transsion.com> wrote:
> From: Pu Hu <hupu@transsion.com>
>
> kprobe_fault_handler() currently treats any page fault taken while in
> KPROBE_HIT_SS or KPROBE_REENTER state as a kprobe single-step fault. This
> assumption does not hold: perf or tracing code may run from the debug
> exception path during the single-step window and take its own page fault.
>
> When the fault is handled as a kprobe fault, the PC is rewritten to the
> probe address, corrupting the exception recovery context for the real
> fault. A typical reproducer is running perf with preemptirq tracepoints
> and dwarf callchains while a kprobe is installed on a frequently
> executed function.
>
> Fix this in two layers:
>
> 1. At function entry, bail out immediately for simulated kprobes
> (ainsn.xol_insn == NULL), since they have no XOL slot and any fault
> taken during their execution cannot be a single-step fault.
>
> 2. For kprobes with an XOL slot, only handle the fault when the
> faulting PC matches the XOL instruction address. Faults from any
> other PC are left to the normal page fault handler.
>
> This follows the same principle as the x86 fix in commit 6381c24cd6d5
> ("kprobes/x86: Fix page-fault handling logic").
>
> Signed-off-by: Pu Hu <hupu@transsion.com>
> Signed-off-by: Hongyan Xia <hongyan.xia@transsion.com>
This looks good to me.
Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Thanks,
> ---
> arch/arm64/kernel/probes/kprobes.c | 22 ++++++++++++++++++++++
> 1 file changed, 22 insertions(+)
>
> diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c
> index 43a0361a8bf0..798e4b091d1a 100644
> --- a/arch/arm64/kernel/probes/kprobes.c
> +++ b/arch/arm64/kernel/probes/kprobes.c
> @@ -282,9 +282,31 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr)
> struct kprobe *cur = kprobe_running();
> struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
>
> + /*
> + * Simulated kprobes execute in the debug trap context and have no
> + * XOL slot. Any page fault taken while a simulated kprobe is in
> + * progress cannot have been caused by kprobe single-stepping and
> + * must be left alone for the normal page fault handler, including
> + * fixup_exception.
> + */
> + if (cur && !cur->ainsn.xol_insn)
> + return 0;
> +
> switch (kcb->kprobe_status) {
> case KPROBE_HIT_SS:
> case KPROBE_REENTER:
> + /*
> + * A page fault taken while in KPROBE_HIT_SS or
> + * KPROBE_REENTER state is only attributable to kprobe
> + * single-stepping if the faulting PC points to the
> + * current kprobe's XOL instruction. If the fault occurred
> + * elsewhere (e.g. in perf or tracing code invoked from the
> + * debug exception path), leave it for the normal page fault
> + * handler to process.
> + */
> + if (instruction_pointer(regs) != (unsigned long)cur->ainsn.xol_insn)
> + break;
> +
> /*
> * We are here because the instruction being single
> * stepped caused a page fault. We reset the current
> --
> 2.43.0
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2026-07-10 4:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 14:22 [RFC v2 0/3] arm64: kprobes: Fix single-step fault and reentry handling Pu Hu
2026-07-09 14:22 ` [RFC v2 1/3] arm64: kprobes: Only handle faults originating from XOL slot Pu Hu
2026-07-10 4:10 ` Masami Hiramatsu [this message]
2026-07-09 14:22 ` [RFC v2 2/3] arm64: kprobes: Allow reentering kprobes while single-stepping Pu Hu
2026-07-10 5:09 ` Masami Hiramatsu
2026-07-10 6:13 ` Pu Hu
2026-07-09 14:22 ` [RFC v2 3/3] arm64: kprobes: Save and restore saved_irqflag in prev_kprobe Pu Hu
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=20260710131047.1806f8477422f9c1703471eb@kernel.org \
--to=mhiramat@kernel.org \
--cc=ada.coupriediaz@arm.com \
--cc=catalin.marinas@arm.com \
--cc=davem@davemloft.net \
--cc=hongyan.xia@transsion.com \
--cc=hupu@transsion.com \
--cc=jiazi.li@transsion.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=naveen@kernel.org \
--cc=will@kernel.org \
--cc=yang@os.amperecomputing.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