From: sashiko-bot@kernel.org
To: "Charlie Jenkins" <thecharlesjenkins@gmail.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v3 15/17] riscv: kvm: Use generated instruction headers for csr emulation
Date: Wed, 08 Jul 2026 04:04:01 +0000 [thread overview]
Message-ID: <20260708040402.9EADE1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260707-riscv_insn_table-v3-15-3f8e5f75ba97@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] RVC (compressed) MMIO loads and stores read from and write to the wrong guest registers due to a missing architectural offset calculation.
- [Low] The CSR emulation code uses the `csrrwi` immediate extractor macro for a `csrrsi` instruction.
--
--- Patch [15]: [PATCH v3 15/17] riscv: kvm: Use generated instruction headers for csr emulation ---
commit 1deda6264dba206b7c5ef34e0d344daa8c535ddc
Author: Charlie Jenkins <thecharlesjenkins@gmail.com>
riscv: kvm: Use generated instruction headers for csr emulation
This commit migrates the CSR emulation code to use the generated instruction
headers instead of the hand-written instruction composition functions.
> diff --git a/arch/riscv/kvm/vcpu_insn.c b/arch/riscv/kvm/vcpu_insn.c
> index c3e4cf2cd44b7..51eb2c717bff3 100644
> --- a/arch/riscv/kvm/vcpu_insn.c
> +++ b/arch/riscv/kvm/vcpu_insn.c
[ ... ]
> @@ -166,26 +162,32 @@ static int csr_insn(struct kvm_vcpu *vcpu, struct kvm_run *run, ulong insn)
[ ... ]
> } else if (riscv_insn_is_csrrsi(insn)) {
> wr_mask = riscv_insn_csrrwi_extract_imm(insn);
> new_val = -1UL;
> csr_num = riscv_insn_csrrsi_extract_csr(insn);
> + rd = riscv_insn_csrrsi_extract_xd(insn);
[Severity: Low]
This isn't a bug, but is riscv_insn_csrrwi_extract_imm() mistakenly used here
for a csrrsi instruction instead of riscv_insn_csrrsi_extract_imm()?
> } else if (riscv_insn_is_csrrci(insn)) {
[ ... ]
commit 8d80090faef41d1000ad8ee985dcdaa3df7c12d3
Author: Charlie Jenkins <thecharlesjenkins@gmail.com>
riscv: kvm: Use generated instruction headers for mmio emulation
This commit migrates the MMIO emulation code to use the generated instruction
headers instead of the hand-written instruction composition functions.
> diff --git a/arch/riscv/kvm/vcpu_insn.c b/arch/riscv/kvm/vcpu_insn.c
> index a1898ab8bbe85..78adc28308193 100644
> --- a/arch/riscv/kvm/vcpu_insn.c
> +++ b/arch/riscv/kvm/vcpu_insn.c
[ ... ]
> @@ -411,44 +411,47 @@ int kvm_riscv_vcpu_mmio_load(struct kvm_vcpu *vcpu, struct kvm_run *run,
[ ... ]
> - } else if ((insn & INSN_MASK_C_LD) == INSN_MATCH_C_LD) {
> + } else if (riscv_insn_is_c_ld(insn)) {
> len = 8;
> shift = 8 * (sizeof(ulong) - len);
> - insn = RVC_RS2S(insn) << SH_RD;
> + rd = riscv_insn_c_ld_extract_xd(insn);
[Severity: High]
Does this code miss the + 8 offset calculation when extracting the register?
Previously, RVC_RS2S correctly added the 8 offset so compressed MMIO loads
would write to x8-x15. With the raw 3-bit extractor macro
riscv_insn_c_ld_extract_xd(insn), rd will be a raw 0-7 value, causing
compressed MMIO loads like c.ld to overwrite x0-x7 (corrupting SP, GP, etc.)
instead.
> - } else if ((insn & INSN_MASK_C_LDSP) == INSN_MATCH_C_LDSP &&
[ ... ]
> @@ -537,35 +536,30 @@ int kvm_riscv_vcpu_mmio_store(struct kvm_vcpu *vcpu, struct kvm_run *run,
[ ... ]
> - } else if ((insn & INSN_MASK_C_SD) == INSN_MATCH_C_SD) {
> + } else if (riscv_insn_is_c_sd(insn)) {
> len = 8;
> - data64 = GET_RS2S(insn, &vcpu->arch.guest_context);
> + rs2 = riscv_insn_c_sd_extract_xs2(insn);
[Severity: High]
Does this code leak the wrong register state to the emulated MMIO device?
Similar to the load case above, GET_RS2S correctly added the 8 offset, but
riscv_insn_c_sd_extract_xs2(insn) extracts only the raw 3-bit value. This
causes compressed MMIO stores like c.sd to read from x0-x7 instead of x8-x15,
leaking unintended guest state.
> - } else if ((insn & INSN_MASK_C_SDSP) == INSN_MATCH_C_SDSP &&
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260707-riscv_insn_table-v3-0-3f8e5f75ba97@gmail.com?part=15
next prev parent reply other threads:[~2026-07-08 4:04 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 3:34 [PATCH v3 00/17] riscv: Generate riscv instruction functions Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:34 ` [PATCH v3 01/17] riscv: Introduce instruction table generation Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:50 ` sashiko-bot
2026-07-09 6:23 ` Charlie Jenkins
2026-07-08 3:34 ` [PATCH v3 02/17] riscv: alternatives: Use generated instruction headers for patching code Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:45 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 03/17] riscv: kgdb: Use generated instruction headers Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:34 ` [PATCH v3 04/17] riscv: Add kprobes instruction simulation KUnit Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:51 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 05/17] riscv: kprobes: Use generated instruction headers Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:52 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 06/17] riscv: cfi: " Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:34 ` [PATCH v3 07/17] riscv: Maintain epc on misaligned emulation error Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:55 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 08/17] riscv: Use generated instruction headers for misaligned loads/stores Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:49 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 09/17] riscv: kvm: Use generated instruction headers for csr code Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:48 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 10/17] KVM: device: Add test device Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:48 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 11/17] KVM: riscv: selftests: Add mmio test Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:59 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 12/17] riscv: kvm: Use generated instruction headers for mmio emulation Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 4:01 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 13/17] riscv: kvm: Add emulated test csr Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 4:00 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 14/17] KVM: riscv: selftests: Add csr emulation test Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:58 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 15/17] riscv: kvm: Use generated instruction headers for csr emulation Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 4:04 ` sashiko-bot [this message]
2026-07-08 3:34 ` [PATCH v3 16/17] riscv: kexec: Use generated instruction headers for kexec relocations Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 4:01 ` sashiko-bot
2026-07-08 3:34 ` [PATCH v3 17/17] riscv: Remove unused instruction headers Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 3:34 ` Charlie Jenkins
2026-07-08 4:09 ` sashiko-bot
2026-07-09 6:26 ` [syzbot ci] Re: riscv: Generate riscv instruction functions syzbot ci
2026-07-09 6:26 ` syzbot ci
2026-07-09 6:26 ` syzbot ci
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=20260708040402.9EADE1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=thecharlesjenkins@gmail.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.