notes

The CPU-model matrix

Every RISC-V result this project had before 2026-08-01 was taken on one emulated CPU: qemu-system-riscv64 -machine virt -cpu rv64. rv64 is QEMU's maximalist model. It turns on essentially every ratified extension QEMU implements, so the machine we tested against had never told the kernel no about anything.

The VisionFive 2's JH7110 is a SiFive U74, which is RV64GC. It is a much smaller machine. This note is what happened when we ran the same suite against the narrow models, and what that does and does not prove.

Milestone 59 built it. The question that started it was calef's, on 2026-08-01: should we modify QEMU to match the chip? No. A forked emulator is a machine that exists nowhere, so it proves nothing about the real chip and nothing about the standard emulator. We pin QEMU (.qemu-version, and CI builds it from source) for benchmark determinism, so a fork multiplies that maintenance. QEMU already lets us narrow with -cpu, and narrowing is the whole idea.

How to run it

script/cpu-matrix                      # every model in the default list
script/cpu-matrix sifive-u54           # just these
script/test --arch riscv64 --cpu sifive-u54    # one model, by hand
NIFE_CPU=sifive-u54 cargo run -p kernel --target riscv64imac-unknown-none-elf

--cpu reaches the QEMU runners as NIFE_CPU, which both helpers/qemu-runner-riscv64.sh and helpers/qemu-runner-aarch64.sh read. Unset, they use what they always used: rv64 on riscv64, cortex-a72 on aarch64. Nothing that existed before this flag changed its meaning.

--arch aarch64|riscv64 runs one ISA leg instead of both, which is what makes the matrix cheap (about 50 seconds per model on a warm tree, against about ten minutes for a full script/test). --arch did not exist before this milestone, despite the brief saying it did; cargo xtask test ran both legs unconditionally. Its default is still both, so the parity gate (DECISIONS ยง19) cannot be weakened by forgetting to pass it.

Under HVF (--hvf) there is no CPU model to pick: the guest runs the physical Apple core, so -cpu host is mandatory. NIFE_CPU set to anything else there is a hard error, not silently ignored.

The result: the suite passes on all five models

2026-08-01, QEMU 11.0.2 (the pin in .qemu-version), macOS on Apple Silicon, load average 4.5 falling to 2.9 across the run, about four minutes for all five. 211 kernel tests, 211 passed, on every model. Each row was produced by exactly the command shown.

model script/test --arch riscv64 --cpu <model> riscv,isa the machine advertises
rv64 211 passed rv64imafdch_... (42 named extensions after the base, incl. svadu, sstc, zba/zbb/zbc/zbs, and h)
sifive-u54 211 passed rv64imafdc_zicntr_zicsr_zifencei_zihpm_sdtrig
rva22s64 211 passed rv64imafdcb_... (RVA22 S profile, svade, svinval, svpbmt)
rva23s64 211 passed rv64imafdcbvh_... (RVA23 S profile, vector, zicond, pointer masking)
thead-c906 211 passed rv64imafdc_..._xtheadba_xtheadbb_xtheadbs_xtheadcmo_...

The riscv,isa column is QEMU's own, and reproducible without booting anything:

$ qemu-system-riscv64 -machine virt,dumpdtb=u54.dtb -cpu sifive-u54 -bios none -display none
$ strings u54.dtb | grep '^rv64i.'
rv64imafdc_zicntr_zicsr_zifencei_zihpm_sdtrig
$ strings u54.dtb | grep 'riscv,sv'
riscv,sv39

As the roadmap predicted, and now measured rather than argued: we are already portable to the board's ISA. sifive-u54 advertises RV64GC and nothing else, and the whole suite runs on it, userspace and virtio and the IOMMU included.

Two things make that result mean something.

We build for riscv64imac. No F, no D. RV64GC is IMAFDC, so the compiler is already forbidden from emitting an instruction the U74 lacks. That predates this milestone and is why it was expected to be cheap. What it never covered is the hand-written part: the asm! in kernel/src/arch/riscv64/, and the CSRs, which QEMU may accept more permissively than SiFive does. That is what the matrix exercises.

The narrowing is enforced, not just advertised. See the preflight below.

The preflight, and why the matrix would otherwise be theater

QEMU's virt machine writes a riscv,isa string into the device tree per CPU model. That string is a claim. If a future QEMU kept the claim but stopped trapping instructions the model does not have, all five runs would still go green, proving nothing, and nothing else in the matrix would notice. This project has been bitten by that shape twice: script/fmt accepted --check and ignored it for months, and the hand-maintained test list in xtask quietly covered 82 fewer tests than it claimed.

So script/cpu-matrix measures it before it runs anything. Five instructions at 0x8000_0000, entered in M-mode with -bios none:

auipc  t0, 0            t0 = 0x8000_0000
addi   t0, t0, 16       t0 = the wfi below
csrw   mtvec, t0        so a trap lands somewhere harmless
sh1add a1, a0, a0       0x20a525b3, a Zba instruction
wfi                     the landing pad, for the trap and the fall-through alike

-d int then logs the exception, or does not:

$ cat target/cpu-matrix/preflight-sifive-u54.log
riscv_cpu_do_interrupt: hart:0, async:0, cause:0000000000000002, epc:0x000000008000000c,
                        tval:0x0000000020a525b3, desc=illegal_instruction
$ cat target/cpu-matrix/preflight-rv64.log
(empty)

rv64 executes it, sifive-u54 refuses it. The assertion is two-sided on purpose: a check that only looked for the trap would pass silently if the log format ever changed, which is the failure it exists to catch.

Pointing mtvec at the wfi first is not decoration. Without it the trap goes to mtvec = 0, the fetch there faults, and the fault storm writes 200 MB of log in three seconds. With it the log is one line, and wfi is a real vCPU halt, so QEMU sits at 0% host CPU either way (CLAUDE.md, "Never leave QEMU running").

The check discriminates. Run against the other three models it reports rva22s64 executed, rva23s64 executed, thead-c906 trapped, which demonstrates both directions; the C906 is a genuinely different machine: it has no standard bitmanip at all, only its own xtheadba/xtheadbb/xtheadbs.

What the narrow models would have caught, and did not have to

A green run is only interesting if you can say what it ruled out.

Hardware A/D update (svadu). rv64 has it: the machine sets a page table entry's Accessed and Dirty bits itself. sifive-u54 and thead-c906 do not have it, and rva22s64/rva23s64 advertise svade, its opposite (the machine faults and software must set them). A kernel that left A and D clear would work on rv64 and page-fault forever on the board. crates/page_tables/src/sv39.rs sets both eagerly, with a comment saying why, so this was already closed; the matrix turns "we think we handled that" into a machine that would have punished us and did not.

Sv57 versus Sv39. rv64 advertises mmu-type = riscv,sv57. Every narrow model advertises riscv,sv39, which is what the U74 has. We run Sv39 on all of them.

The sstc extension, which rv64 and rva23s64 have and sifive-u54 does not: it puts the timer compare in a CSR (stimecmp) instead of behind an SBI call. arch/riscv64/timer.rs goes through SBI, so it works on both.

BUGS

Where it sits in CI

Its own job (cpu-matrix in .github/workflows/ci.yml), not extra work inside script/test. The matrix is the same riscv64 suite five times over, so folding it into the main gate would make every run four times longer for a check whose whole point is that it rarely changes anything. On its own runner it costs nothing a developer waits for.

Since 2026-10-06 it is two cpu-matrix-shard jobs under an aggregate holding the required name; a failure's logs are on the shard.

It runs on every push and pull request rather than nightly. The change that breaks this arrives in a pull request touching kernel/src/arch/riscv64/, and a nightly would report it a day after the merge.