From: Charlie Jenkins via B4 Relay <devnull+thecharlesjenkins.gmail.com@kernel.org>
To: "Paul Walmsley" <pjw@kernel.org>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Nam Cao" <namcao@linutronix.de>,
"Alexandre Ghiti" <alex@ghiti.fr>,
"Anup Patel" <anup@brainfault.org>,
"Atish Patra" <atish.patra@linux.dev>,
"Conor Dooley" <conor@kernel.org>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Shuah Khan" <shuah@kernel.org>,
"Radim Krčmář" <radim.krcmar@oss.qualcomm.com>
Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
kvm@vger.kernel.org, kvm-riscv@lists.infradead.org,
linux-kselftest@vger.kernel.org,
Charlie Jenkins <thecharlesjenkins@gmail.com>
Subject: [PATCH v2 00/16] riscv: Generate riscv instruction functions
Date: Sun, 21 Jun 2026 21:01:18 -0700 [thread overview]
Message-ID: <20260621-riscv_insn_table-v2-0-7f0810ee2274@gmail.com> (raw)
There is a lot of code that is manually manipulating riscv instructions.
Constructing these headers for new instructions is time consuming and
error prone.
The first patch in this series introduces the instruction definition
table along with a script that runs at compile time to create all of the
associated instruction manipulation functions. The remaining patches
migrate all of the manual instruction code to use these generated
functions.
The instruction definition table is generated from the
riscv-unified-db[1], an open source RVI project for instruction
specifications. I got this table generation merged into
riscv-unified-db, that PR can be accessed on github [2].
A lot of the validation for these changes is from running all possible
32-bit or 16-bit integers through these functions to see that any given
instruction will produce to expected result. I give more detail on the
test cases in the notes of the first couple of patches.
For the KVM patches, I also introduce two test cases to ensure that the
instruction manipulation is working as expected.
[1] https://github.com/riscv/riscv-unified-db
[2] https://github.com/riscv/riscv-unified-db/pull/1780
Signed-off-by: Charlie Jenkins <thecharlesjenkins@gmail.com>
---
Changes in v2:
- rebased on v7.1
- I dropped the patch fixing the mmio bug in kvm because in the
meantime that bug has been fixed in a different patch
- Calls to panic() for instructions not support on current hardware have
been changed into BUG_ON()
- Fixed incorrect handling of branches in simulate_*()
- Added CONFIG_RISCV_KPROBES_SIMULATE_KUNIT for more detailed
simulate_*() testing
- Updated insn.tbl based on new merged in changes to riscv-unified-db
- Link to v1: https://lore.kernel.org/r/20260407-riscv_insn_table-v1-0-54b4736a1e77@gmail.com
---
Charlie Jenkins (16):
riscv: Introduce instruction table generation
riscv: alternatives: Use generated instruction headers for patching code
riscv: kgdb: Use generated instruction headers
riscv: Add kprobes instruction simulation KUnit
riscv: kprobes: Use generated instruction headers
riscv: cfi: Use generated instruction headers
riscv: Use generated instruction headers for misaligned loads/stores
riscv: kvm: Use generated instruction headers for csr code
KVM: device: Add test device
KVM: riscv: selftests: Add mmio test
riscv: kvm: Use generated instruction headers for mmio emulation
riscv: kvm: Add emulated test csr
KVM: riscv: selftests: Add csr emulation test
riscv: kvm: Use generated instruction headers for csr emulation
riscv: kexec: Use generated instruction headers for kexec relocations
riscv: Remove unused instruction headers
arch/riscv/Kconfig.debug | 1 +
arch/riscv/Makefile | 3 +
arch/riscv/include/asm/Kbuild | 1 +
arch/riscv/include/asm/insn.h | 563 +-------
arch/riscv/include/asm/kvm_host.h | 10 +
arch/riscv/include/asm/kvm_vcpu_insn.h | 5 +-
arch/riscv/include/asm/kvm_vcpu_test_csr.h | 15 +
arch/riscv/kernel/alternative.c | 23 +-
arch/riscv/kernel/cfi.c | 6 +-
arch/riscv/kernel/kgdb.c | 102 +-
arch/riscv/kernel/machine_kexec_file.c | 55 +-
arch/riscv/kernel/probes/decode-insn.c | 7 +-
arch/riscv/kernel/probes/simulate-insn.c | 253 ++--
arch/riscv/kernel/probes/simulate-insn.h | 7 +-
arch/riscv/kernel/tests/Kconfig.debug | 13 +
arch/riscv/kernel/tests/kprobes/Makefile | 2 +
.../kernel/tests/kprobes/test-kprobes-simulate.c | 250 ++++
arch/riscv/kernel/tests/kprobes/test-kprobes.h | 6 +
arch/riscv/kernel/traps_misaligned.c | 183 ++-
arch/riscv/kvm/Kconfig.debug | 16 +
arch/riscv/kvm/Makefile | 1 +
arch/riscv/kvm/vcpu_insn.c | 232 ++--
arch/riscv/kvm/vcpu_test_csr.c | 21 +
arch/riscv/tools/Makefile | 22 +
arch/riscv/tools/insn.tbl | 1392 ++++++++++++++++++++
arch/riscv/tools/insn_tbl.sh | 256 ++++
include/uapi/linux/kvm.h | 2 +
lib/Kconfig.debug | 6 +
tools/testing/selftests/kvm/Makefile.kvm | 2 +
tools/testing/selftests/kvm/riscv/csr_test.c | 126 ++
tools/testing/selftests/kvm/riscv/mmio_test.c | 184 +++
virt/kvm/Kconfig.debug | 16 +
virt/kvm/Makefile.kvm | 1 +
virt/kvm/kvm_main.c | 8 +
virt/kvm/mmio_test.c | 95 ++
virt/kvm/mmio_test.h | 18 +
36 files changed, 2897 insertions(+), 1006 deletions(-)
---
base-commit: 8cd9520d35a6c38db6567e97dd93b1f11f185dc6
change-id: 20260114-riscv_insn_table-38495495dfd3
Best regards,
--
Charlie Jenkins <thecharlesjenkins@gmail.com>
next reply other threads:[~2026-06-22 4:01 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-22 4:01 Charlie Jenkins via B4 Relay [this message]
2026-06-22 4:01 ` [PATCH v2 01/16] riscv: Introduce instruction table generation Charlie Jenkins via B4 Relay
2026-06-30 16:45 ` Radim Krčmář
2026-07-01 1:17 ` Charlie Jenkins
2026-06-22 4:01 ` [PATCH v2 02/16] riscv: alternatives: Use generated instruction headers for patching code Charlie Jenkins via B4 Relay
2026-06-29 18:07 ` Jesse Taube
2026-06-22 4:01 ` [PATCH v2 03/16] riscv: kgdb: Use generated instruction headers Charlie Jenkins via B4 Relay
2026-06-22 4:01 ` [PATCH v2 04/16] riscv: Add kprobes instruction simulation KUnit Charlie Jenkins via B4 Relay
2026-06-22 4:01 ` [PATCH v2 05/16] riscv: kprobes: Use generated instruction headers Charlie Jenkins via B4 Relay
2026-06-22 4:01 ` [PATCH v2 06/16] riscv: cfi: " Charlie Jenkins via B4 Relay
2026-06-22 4:01 ` [PATCH v2 07/16] riscv: Use generated instruction headers for misaligned loads/stores Charlie Jenkins via B4 Relay
2026-06-29 20:20 ` Jesse T
2026-06-30 6:14 ` Charlie Jenkins
2026-06-22 4:01 ` [PATCH v2 08/16] riscv: kvm: Use generated instruction headers for csr code Charlie Jenkins via B4 Relay
2026-06-29 20:25 ` Jesse T
2026-06-30 6:17 ` Charlie Jenkins
2026-06-22 4:01 ` [PATCH v2 09/16] KVM: device: Add test device Charlie Jenkins via B4 Relay
2026-06-22 4:01 ` [PATCH v2 10/16] KVM: riscv: selftests: Add mmio test Charlie Jenkins via B4 Relay
2026-06-22 4:01 ` [PATCH v2 11/16] riscv: kvm: Use generated instruction headers for mmio emulation Charlie Jenkins via B4 Relay
2026-06-22 4:01 ` [PATCH v2 12/16] riscv: kvm: Add emulated test csr Charlie Jenkins via B4 Relay
2026-06-22 4:01 ` [PATCH v2 13/16] KVM: riscv: selftests: Add csr emulation test Charlie Jenkins via B4 Relay
2026-06-22 4:01 ` [PATCH v2 14/16] riscv: kvm: Use generated instruction headers for csr emulation Charlie Jenkins via B4 Relay
2026-06-22 4:01 ` [PATCH v2 15/16] riscv: kexec: Use generated instruction headers for kexec relocations Charlie Jenkins via B4 Relay
2026-06-22 4:01 ` [PATCH v2 16/16] riscv: Remove unused instruction headers Charlie Jenkins via B4 Relay
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=20260621-riscv_insn_table-v2-0-7f0810ee2274@gmail.com \
--to=devnull+thecharlesjenkins.gmail.com@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=alex@ghiti.fr \
--cc=anup@brainfault.org \
--cc=atish.patra@linux.dev \
--cc=conor@kernel.org \
--cc=kvm-riscv@lists.infradead.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=namcao@linutronix.de \
--cc=palmer@dabbelt.com \
--cc=pbonzini@redhat.com \
--cc=pjw@kernel.org \
--cc=radim.krcmar@oss.qualcomm.com \
--cc=shuah@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®