From: Xiaofeng Yuan <yuanxiaofeng@eswincomputing.com>
To: Nam Cao <namcao@linutronix.de>, Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>,
linux-riscv@lists.infradead.org,
Xiaofeng Yuan <yuanxiaofeng@eswincomputing.com>
Subject: [PATCH v4 0/2] riscv: kprobes: reject probes inside LR/SC sequences
Date: Fri, 28 Aug 2026 17:12:00 +0800 [thread overview]
Message-ID: <20260828091202.1124-1-yuanxiaofeng@eswincomputing.com> (raw)
A breakpoint 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.
This series makes the RISC-V kprobes implementation reject probes placed
inside an LR/SC sequence:
- patch 1 detects the sequences (insn.h decoding helpers, reject list
in decode-insn.c, and a forward scan from the function start in
kprobes.c).
- patch 2 adds a KUnit test that registers a probe inside and right
after a hand-written LR/SC loop and checks rejection/acceptance.
Changes in v4:
- v3 walked backwards from the probe to find an open LR. That was
wrong twice: the LR/SC state was toggled in the reverse order, and
worse, a backward walk is fundamentally ambiguous in RISC-V (the
halfword at addr-2 may be a compressed instruction or the upper
half of a 32-bit instruction, and the length bits cannot be
trusted). v4 walks forward from the function start instead, a
known instruction boundary.
- document the kallsyms_lookup_size_offset() offset-0 caveat in the
commit message, and test it with local (.L) labels so probe
addresses never coincide with kallsyms symbols inside the sequence.
- the KUnit test (patch 2) is new in v4. No earlier version had a
dedicated LR/SC test, which is why the backward-scan bugs went
unnoticed.
Link: https://lore.kernel.org/linux-riscv/REPLACE-WITH-V3-MSGID/
Xiaofeng Yuan (2):
riscv: probes: reject kprobes inside LR/SC sequences
riscv: kprobes: add KUnit test for LR/SC sequence rejection
arch/riscv/include/asm/insn.h | 18 +++++++
arch/riscv/kernel/probes/decode-insn.c | 2 +
arch/riscv/kernel/probes/kprobes.c | 54 +++++++++++++++++++
.../kernel/tests/kprobes/test-kprobes-asm.S | 19 +++++++
.../riscv/kernel/tests/kprobes/test-kprobes.c | 19 +++++++
.../riscv/kernel/tests/kprobes/test-kprobes.h | 6 +++
6 files changed, 118 insertions(+)
--
2.43.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next reply other threads:[~2026-08-28 9:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 9:12 Xiaofeng Yuan [this message]
2026-08-28 9:12 ` [PATCH v4 1/2] riscv: probes: reject kprobes inside LR/SC sequences Xiaofeng Yuan
2026-09-22 13:37 ` Nam Cao
2026-08-28 9:12 ` [PATCH v4 2/2] riscv: kprobes: add KUnit test for LR/SC sequence rejection Xiaofeng Yuan
2026-09-22 13:46 ` Nam Cao
2026-09-20 8:02 ` [PATCH v4 0/2] riscv: kprobes: reject probes inside LR/SC sequences Xiaofeng Yuan
2026-09-22 15:40 ` Nam Cao
2026-09-22 15:40 ` Nam Cao
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=20260828091202.1124-1-yuanxiaofeng@eswincomputing.com \
--to=yuanxiaofeng@eswincomputing.com \
--cc=aou@eecs.berkeley.edu \
--cc=linux-riscv@lists.infradead.org \
--cc=namcao@linutronix.de \
--cc=palmer@dabbelt.com \
--cc=pjw@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.