target/riscv: qtest accelerator does not update mip interrupt-pending state
Host environment
-
Operating system: NixOS
-
OS/kernel version: Linux 6.18.63 x86_64
-
Architecture: x86_64
-
QEMU flavor: qemu-system-riscv64
-
QEMU version: 11.1.91 (v11.2.0-rc1), commit 08c9bbb8, built from source
-
QEMU command line:
./qemu-system-riscv64 \ -M virt,aia=none,aclint=on -cpu rv64 -smp 1 \ -accel qtest -display none -nodefaults \ -serial none -monitor none -bios none -qtest stdioThe qtest commands in the reproduction steps below are written to stdin.
Emulated/Virtualized environment
- Operating system: N/A
- OS/kernel version: N/A
- Architecture: RISC-V 64-bit
- Machine: virt
Description of problem
Since commit 6c91b423a9a4 ("target/riscv: gate riscv_cpu_update_mip with
tcg_enabled()"), updates to the architectural interrupt-pending state are
gated by tcg_enabled().
The qtest accelerator is neither TCG nor KVM, so both tcg_enabled() and
kvm_enabled() are false. Device models still update their interrupt state
(for example ACLINT MSIP/MTIMER, APLIC and IMSIC), but the CPU-visible mip
CSR is not updated.
The skipped mip update is observable in riscv_cpu_set_irq() and in the
timer callback path through riscv_accel_set_irq().
Expected behavior: after an interrupt is injected or a timer expires, the
corresponding mip bit is set (MSIP = 0x8, MTIP = 0x80).
Actual behavior: mip reads as 0.
This is a qtest-only regression. TCG and KVM guest execution are not affected, and there is no security impact.
As a consequence, qtest-based tests that rely on reading mip after device IRQ
injection (e.g. ACLINT/APLIC/IMSIC tests) will observe stale mip values.
Steps to reproduce
-
Build current upstream master with TCG:
./configure --target-list=riscv64-softmmu ninja qemu-system-riscv64 -
Trigger a software interrupt (MSIP):
printf 'writeq 0x2004000 0xffffffffffffffff\nwritel 0x2000000 1\ncsr get_csr 0 0x344 0\n' | \ timeout 5 ./qemu-system-riscv64 \ -M virt,aia=none,aclint=on -cpu rv64 -smp 1 \ -accel qtest -display none -nodefaults \ -serial none -monitor none -bios none -qtest stdio 2>/dev/nullThe first
writeqsetsmtimecmpto its maximum value so that MTIP is not raised beforemipis read; this isolates the MSIP bit.Observed:
OK OK OK 0 0Expected: the final field is
mipin hex, with MSIP set:OK OK OK 0 8 -
Trigger a machine timer interrupt (MTIP):
printf 'writeq 0x2004000 1\nclock_step 1000000\ncsr get_csr 0 0x344 0\n' | \ timeout 5 ./qemu-system-riscv64 \ -M virt,aia=none,aclint=on -cpu rv64 -smp 1 \ -accel qtest -display none -nodefaults \ -serial none -monitor none -bios none -qtest stdio 2>/dev/nullObserved:
OK OK 1000000 OK 0 0Expected: MTIP set:
OK OK 1000000 OK 0 80timeoutexits with status 124 because QEMU keeps running after the commands are consumed; the lastOKline is the relevant result.
Additional information
-
The qtest
csrcommand used above is only available in a build withCONFIG_TCG; this report is for a TCG-enabled build running the qtest accelerator. -
-bios noneis not strictly required under qtest, but is kept to ensure no firmware is loaded. -
The regression boundary was confirmed with
git bisectusing the same upstream-onlyvirt+ ACLINT MSIP test (readmipCSR0x344):good endpoint 8eaa5b73ab mip = 0x8 (MSIP set) good e26e53b4ab mip = 0x8 (MSIP set) good 705fe3819b mip = 0x8 (MSIP set) good 5fa9e8597b mip = 0x8 (MSIP set) first bad 6c91b423a9 mip = 0x0Building the first bad commit directly also produced
mip = 0x0. The fullgit bisectlog is available.