[PATCH 0/6] target/riscv: Fix wrong behavior when G-Stage PMP/PMA fails

LIU Zhiwei posted 6 patches 1 day, 17 hours ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20261126075350.13022-1-zhiwei._5Fliu@linux.alibaba.com
Maintainers: Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Chao Liu <chao.liu@processmission.com>
target/riscv/tcg/cpu_helper.c                |  15 +-
tests/tcg/riscv64/system/meson.build         |   7 +
tests/tcg/riscv64/test-gstage-access-fault.S | 247 +++++++++++++++++++
3 files changed, 267 insertions(+), 2 deletions(-)
create mode 100644 tests/tcg/riscv64/test-gstage-access-fault.S
[PATCH 0/6] target/riscv: Fix wrong behavior when G-Stage PMP/PMA fails
Posted by LIU Zhiwei 1 day, 17 hours ago
When I am working on SMMPT v0.9.0 support, I found some wrong behaviors
when G-Stage translation PMP/PMA fails.

This six-patch series examines physical access-fault propagation during
RISC-V two-stage address translation. It contains three fixes, each
followed by a regression test.

The fixes address three paths:

1. VS PTE reads

   The VS walker invokes G-stage translation before reading a VS PTE.
   PMP and PMA failures from that recursive translation are currently
   converted into G-stage translation failures. Preserve these physical
   access errors so the original guest load, store or instruction fetch
   receives the corresponding access fault.

2. VS PTE A/D updates

   Writing updated A/D bits to a VS PTE requires another G-stage
   translation with store access. This translation can itself require
   updating a G-stage PTE's D bit. Preserve physical access failures
   from this path, while selecting the final exception cause according
   to the original guest operation.

3. Direct G-stage fault metadata

   A PMA failure during direct G-stage translation already produces an
   access fault, but can also populate the guest fault address.
   Exclude both PMP and PMA failures from that address assignment,
   leaving the field zero for trap delivery.

The regression runs on the virt machine with the H extension. It checks
PMP and PMA failures during nested PTE reads, a PMP-denied G-stage D-bit
update during VS A/D handling, and a direct G-stage PMA failure with
VS-stage translation set to Bare. The checks cover exception causes,
the original virtual address in mtval, and zero mtval2 for access faults.
Controls for genuine G-stage mapping failures remain in place, along
with a final successful load after restoring the translation state.

The A/D-update case injects a PMP failure. The direct G-stage case
checks a load and observes mtval2 through the M-mode trap handler;
delegated HS-mode traps and htval are outside this test's coverage.

LIU Zhiwei (6):
  target/riscv: Preserve access faults while translating VS PTE reads
  tests/tcg/riscv64: Add nested-PTE-read access-fault regression
  target/riscv: Preserve access faults during VS PTE A/D translation
  tests/tcg/riscv64: Check access faults during VS A/D updates
  target/riscv: Keep the guest fault address zero for G-stage PMA errors
  tests/tcg/riscv64: Check PMA fault metadata with VS-stage Bare

 target/riscv/tcg/cpu_helper.c                |  15 +-
 tests/tcg/riscv64/system/meson.build         |   7 +
 tests/tcg/riscv64/test-gstage-access-fault.S | 247 +++++++++++++++++++
 3 files changed, 267 insertions(+), 2 deletions(-)
 create mode 100644 tests/tcg/riscv64/test-gstage-access-fault.S


base-commit: 71f25c75417d31c214ba2cd26b273c114fc99987
-- 
2.43.0