From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Xiaofeng Yuan <yuanxiaofeng@eswincomputing.com>
Cc: Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>, Nam Cao <namcao@linutronix.de>,
Naveen N Rao <naveen@kernel.org>,
"David S . Miller" <davem@davemloft.net>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v5 1/2] riscv: kprobes: reject probes inside LR/SC sequences
Date: Thu, 15 Oct 2026 22:19:54 +0900 [thread overview]
Message-ID: <20261015131956.183661F000C4@smtp.kernel.org> (raw)
In-Reply-To: <20261014094415.374-2-yuanxiaofeng@eswincomputing.com>
On Wed, 14 Oct 2026 17:44:14 +0800, Xiaofeng Yuan <yuanxiaofeng@eswincomputing.com> wrote:
> A trap taken in the middle of an LR/SC sequence clears the load
> reservation, so an SC following the probed instruction always fails and
> the enclosing retry loop re-enters the breakpoint, livelocking the CPU.
> Reject probes of the LR/SC instructions themselves and of any address
> between them.
>
> arm64's kprobes rejects its equivalent exclusive load/store instructions
> and, in arm_kprobe_decode_insn(), walks backward from the probe address
> (bounded by the enclosing symbol) to reject any address inside an
> exclusive sequence. RISC-V cannot walk backward because
> variable-length instructions make instruction boundaries ambiguous, so
> walk forward from the enclosing symbol, a known instruction boundary, up
> to the probe address and track whether an LR is still outstanding.
>
> A Zalrsc-constrained LR/SC retry loop holds at most 16 instructions, so
> an LR more than MAX_LRSC_GAP instructions ahead of the probe cannot
> start a sequence containing it. Count instructions, not bytes:
> compressed instructions would make a byte window ambiguous.
>
> The LR/SC instructions themselves are rejected in
> riscv_probe_decode_insn(), and an address inside a sequence is rejected
> in arch_check_kprobe().
>
Looks good to me from kprobes maintainer's viewpoint.
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Thanks!
> Signed-off-by: Xiaofeng Yuan <yuanxiaofeng@eswincomputing.com>
> ---
> arch/riscv/include/asm/insn.h | 33 ++++++++++++++
> arch/riscv/kernel/probes/decode-insn.c | 2 +
> arch/riscv/kernel/probes/kprobes.c | 63 +++++++++++++++++++++-----
> 3 files changed, 86 insertions(+), 12 deletions(-)
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2026-10-15 13:19 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260828091202.1124-1-yuanxiaofeng@eswincomputing.com>
2026-09-22 15:40 ` [PATCH v4 0/2] riscv: kprobes: reject probes inside LR/SC sequences Nam Cao
2026-10-14 9:44 ` [PATCH v5 " Xiaofeng Yuan
2026-10-15 13:10 ` Masami Hiramatsu
2026-10-14 9:44 ` [PATCH v5 1/2] " Xiaofeng Yuan
2026-10-15 13:19 ` Masami Hiramatsu [this message]
2026-10-14 9:44 ` [PATCH v5 2/2] riscv: kprobes: add KUnit test for LR/SC sequence rejection Xiaofeng Yuan
2026-10-14 9:54 ` sashiko-bot
2026-10-15 13:22 ` Masami Hiramatsu
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=20261015131956.183661F000C4@smtp.kernel.org \
--to=mhiramat@kernel.org \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=namcao@linutronix.de \
--cc=naveen@kernel.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=yuanxiaofeng@eswincomputing.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