From: Nam Cao <namcao@linutronix.de>
To: Xiaofeng Yuan <yuanxiaofeng@eswincomputing.com>,
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: Re: [PATCH v2 1/2] riscv: kprobes: simulate nop and c.nop instructions
Date: Wed, 26 Aug 2026 15:04:26 +0200 [thread overview]
Message-ID: <87wltdt4md.fsf@yellow.woof> (raw)
In-Reply-To: <20260825122020.1192-2-yuanxiaofeng@eswincomputing.com>
Xiaofeng Yuan <yuanxiaofeng@eswincomputing.com> writes:
> nop and c.nop have no architectural effect, so allocating an
> out-of-line instruction slot and single-stepping through them is
> pure overhead. Simulate them directly in the breakpoint handler
> by advancing the program counter, following the approach already
> used on arm64.
That is not the reason why arm64 simulate nop. And how is single
stepping slower than simulating?
> This avoids slot allocation, text patching, IRQ flag save/restore
> and the single-step exception for these instructions.
>
> riscv_probe_decode_insn() is shared by kprobes and uprobes, so the
> simulation also applies to uprobes placed on nop instructions. This
> is relevant for USDT probe sites in user-space binaries, which are
> nop/c.nop instructions, the same use case that motivated the arm64
> implementation.
I can only find https://github.com/chrisa/libusdt, which does not have
riscv support. Which USDT are you referring to?
> In kernel text, nops are also found at ftrace mcount call sites and
> disabled jump_label sites.
Not sure about mcount, but isn't installing kprobe on jump labels forbidden?
> Measured on QEMU (RISC-V virt, emulated), this reduces the per-hit
> cost of a kprobe on a nop by roughly 40% compared to single-stepping
> through the out-of-line slot.
Reading the arm64's commit, simulating nop should only improve uprobe,
not kprobe; or am I confused somewhere?
Nam
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2026-08-26 13:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-25 12:20 [PATCH v2 0/2] riscv: kprobes: simulate nop and c.nop instructions Xiaofeng Yuan
2026-08-25 12:20 ` [PATCH v2 1/2] " Xiaofeng Yuan
2026-08-26 13:04 ` Nam Cao [this message]
2026-09-02 8:43 ` 袁晓峰
2026-08-25 12:20 ` [PATCH v2 2/2] riscv: kprobes: add nop and c.nop to the KUnit test Xiaofeng Yuan
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=87wltdt4md.fsf@yellow.woof \
--to=namcao@linutronix.de \
--cc=aou@eecs.berkeley.edu \
--cc=linux-riscv@lists.infradead.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 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.