Skip to content

target/riscv: preserve interrupt-pending state under qtest

Zixin Wang qemu-devel qemu-riscv 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2target/riscv: preserve interrupt-pending state under qtesttarget/riscv/cpu.c target/riscv/time_helper.c+14 -40 replies
2/2tests/qtest: add a RISC-V mip regression testtests/qtest/meson.build tests/qtest/riscv-mip-test.c+72 -00 replies

Reviews trailers per patch

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

Read the v1 thread

Cover letter [PATCH 0/2] target/riscv: preserve interrupt-pending state under qtest

Commit 6c91b423a9a4 ("target/riscv: gate riscv_cpu_update_mip with tcg_enabled()") gated the architectural mip updates with tcg_enabled(). The qtest accelerator is neither TCG nor KVM, so device models still inject interrupts but mip is never updated. qtests that drive ACLINT, APLIC or IMSIC inputs therefore observe stale mip values.

Patch 1/2 updates the call sites in riscv_cpu_set_irq() and riscv_accel_set_irq() to use "tcg_enabled() || qtest_enabled()", matching the existing virt_aclint_allowed() logic. The update blocks are wrapped in "#ifdef CONFIG_TCG" because riscv_cpu_update_mip() is only built with TCG; without this compile-time guard, the new qtest_enabled() runtime check keeps the call in the link and breaks --disable-tcg builds. In --disable-tcg builds the update remains compiled out; the qtest "csr" command is unavailable there as well, so those builds keep their previous behavior.

Patch 2/2 adds a qtest regression that drives the ACLINT MSIP and MTIMER inputs and checks mip through the qtest "csr" command. It fails with mip == 0 without patch 1/2 and passes with it. The "csr" command is only registered in TCG-enabled builds, so the test is only registered when TCG is enabled.

Validation on 08c9bbb825 (v11.2.0-rc1):

- TCG build, qtest reproducers from the report:
MSIP: OK / OK / OK 0 8
MTIP: OK / OK 1000000 / OK 0 80
(both read mip as 0 without patch 1/2)

- TCG build, new regression test:
/riscv64/riscv/mip/msip and /riscv64/riscv/mip/mtip pass with patch 1/2; without it, the MSIP assertion fails with mip == 0.

- Full riscv64 qtest suite:
18 tests passed, 1 skipped (cdrom-test, registers no subtests in this configuration), 0 failed; 375 subtests passed in total. This includes the K230, MilkV Duo, IOMMU, riscv-csr, ACPI and virt device tests.

- --disable-tcg build:
without the CONFIG_TCG guard, the link fails with undefined references to riscv_cpu_update_mip from target/riscv/cpu.c and target/riscv/time_helper.c;
with the guard, qemu-system-riscv64 links successfully.

The test host is x86_64, where KVM cannot be enabled for riscv64, so the link test used a local no-accelerator configure; the compile-time condition (CONFIG_TCG undefined, target/riscv/tcg/ excluded) is the same as in a RISC-V KVM-only build. I can re-test on a RISC-V host if that is preferred.

Reported as: https://gitlab.com/qemu-project/qemu/-/issues/4929

Zixin Wang (2):
target/riscv: preserve interrupt-pending state under qtest tests/qtest: add a RISC-V mip regression test

 target/riscv/cpu.c           | 13 +++++--
 target/riscv/time_helper.c   |  5 ++-
 tests/qtest/meson.build      |  1 +
 tests/qtest/riscv-mip-test.c | 71 ++++++++++++++++++++++++++++++++++++
 4 files changed, 86 insertions(+), 4 deletions(-)
 create mode 100644 tests/qtest/riscv-mip-test.c
Signature · 1 line
2.54.0