Skip to content

RISC-V: Refactor instructions

Charlie Jenkins bpf kvm kvm-riscv linux-riscv lkml oe-kbuild-all 1 version In review

Get series with b4
b4 am 20230803-master-refactor-instructions-v4-v1-0-2128e61fa4ff@rivosinc.com change-id 20230801-master-refactor-instructions-v4-433aa040da03

Versions newest first

  1. v1 Latest10 patches 12 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/10RISC-V: Expand instruction definitionsarch/riscv/include/asm/insn.h arch/riscv/include/asm/reg.h arch/riscv/kernel/kgdb.c +2 more+2629 -2462 replies
2/10RISC-V: vector: Refactor instructionsarch/riscv/kernel/vector.c+1 -20 replies
3/10RISC-V: Refactor jump label instructionsarch/riscv/include/asm/insn.h arch/riscv/kernel/jump_label.c+5 -100 replies
4/10RISC-V: KGDB: Refactor instructionsarch/riscv/kernel/kgdb.c+5 -60 replies
5/10RISC-V: module: Refactor instructionsarch/riscv/kernel/module.c+18 -620 replies
6/10RISC-V: Refactor patch instructionsarch/riscv/kernel/patch.c arch/riscv/kernel/probes/kprobes.c arch/riscv/kernel/probes/simulate-insn.c +1 more+25 -570 replies
7/10RISC-V: nommu: Refactor instructionsarch/riscv/kernel/traps_misaligned.c+45 -1730 replies
8/10RISC-V: kvm: Refactor instructionsarch/riscv/kvm/vcpu_insn.c+86 -1950 replies
9/10RISC-V: bpf: Refactor instructionsarch/riscv/net/bpf_jit.h+2 -7050 replies
10/10RISC-V: Refactor bug and traps instructionsarch/riscv/include/asm/bug.h arch/riscv/kernel/traps.c+10 -170 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 00/10] RISC-V: Refactor instructions

There are numerous systems in the kernel that rely on directly modifying, creating, and reading instructions. Many of these systems have rewritten code to do this. This patch will delegate all instruction handling into insn.h and reg.h. All of the compressed instructions, RVI, Zicsr, M, A instructions are included, as well as a subset of the F,D,Q extensions.

---
This is modifying code that https://lore.kernel.org/lkml/20230731183925.152145-1-namcaov at gmail.com/ is also touching.

---
Testing:

There are a lot of subsystems touched and I have not tested every individual instruction. I did a lot of copy-pasting from the RISC-V spec so opcodes and such should be correct, but the construction of every instruction is not fully tested.

vector: Compiled and booted

jump_label: Ensured static keys function as expected.

kgdb: Attempted to run the provided tests but they failed even without my changes

module: Loaded and unloaded modules

patch.c: Ensured kernel booted

kprobes: Used a kprobing module to probe jalr, auipc, and branch instructions

nommu misaligned addresses: Kernel boots

kvm: Ran KVM selftests

bpf: Kernel boots. Most of the instructions are exclusively used by BPF but I am unsure of the best way of testing BPF.

---
Charlie Jenkins (10):
RISC-V: Expand instruction definitions
RISC-V: vector: Refactor instructions
RISC-V: Refactor jump label instructions
RISC-V: KGDB: Refactor instructions
RISC-V: module: Refactor instructions
RISC-V: Refactor patch instructions
RISC-V: nommu: Refactor instructions
RISC-V: kvm: Refactor instructions
RISC-V: bpf: Refactor instructions
RISC-V: Refactor bug and traps instructions

 arch/riscv/include/asm/bug.h             |   18 +-
 arch/riscv/include/asm/insn.h            | 2744 +++++++++++++++++++++++++++---
 arch/riscv/include/asm/reg.h             |   88 +
 arch/riscv/kernel/jump_label.c           |   13 +-
 arch/riscv/kernel/kgdb.c                 |   13 +-
 arch/riscv/kernel/module.c               |   80 +-
 arch/riscv/kernel/patch.c                |    3 +-
 arch/riscv/kernel/probes/kprobes.c       |   13 +-
 arch/riscv/kernel/probes/simulate-insn.c |  100 +-
 arch/riscv/kernel/probes/uprobes.c       |    5 +-
 arch/riscv/kernel/traps.c                |    9 +-
 arch/riscv/kernel/traps_misaligned.c     |  218 +--
 arch/riscv/kernel/vector.c               |    5 +-
 arch/riscv/kvm/vcpu_insn.c               |  281 +--
 arch/riscv/net/bpf_jit.h                 |  707 +-------
 15 files changed, 2825 insertions(+), 1472 deletions(-)

---
base-commit: 5d0c230f1de8c7515b6567d9afba1f196fb4e2f4
change-id: 20230801-master-refactor-instructions-v4-433aa040da03

Signature · 1 line
- Charlie