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 stdio

    The 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

  1. Build current upstream master with TCG:

    ./configure --target-list=riscv64-softmmu
    ninja qemu-system-riscv64
  2. 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/null

    The first writeq sets mtimecmp to its maximum value so that MTIP is not raised before mip is read; this isolates the MSIP bit.

    Observed:

    OK
    OK
    OK 0 0

    Expected: the final field is mip in hex, with MSIP set:

    OK
    OK
    OK 0 8
  3. 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/null

    Observed:

    OK
    OK 1000000
    OK 0 0

    Expected: MTIP set:

    OK
    OK 1000000
    OK 0 80

    timeout exits with status 124 because QEMU keeps running after the commands are consumed; the last OK line is the relevant result.

Additional information

  • The qtest csr command used above is only available in a build with CONFIG_TCG; this report is for a TCG-enabled build running the qtest accelerator.

  • -bios none is not strictly required under qtest, but is kept to ensure no firmware is loaded.

  • The regression boundary was confirmed with git bisect using the same upstream-only virt + ACLINT MSIP test (read mip CSR 0x344):

    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 = 0x0

    Building the first bad commit directly also produced mip = 0x0. The full git bisect log is available.

Edited by Zixin Wang