On Mon, 2026-11-02 at 23:29 -0800, tewaro wrote:
> Hi,
>
> This series is about the traps taken when the G-stage refuses one of
> the
> implicit accesses that VS-stage address translation makes. It follows
> up on
> commit 366b4fba0fae ("target/riscv: check G-stage write permission
> for
> VS-stage A/D updates"), which made the A/D write respect G-stage
> permission,
> and fixes what is still reported wrong on such a trap.
>
> Patch 2 adds a test, test-gstage-tinst (19 cases), master fails 8.
> Built for
> Spike's HTIF console instead of semihosting, all 19 cases pass on
> upstream
> Spike.
>
> Patch 1 fixes the read/write pseudoinstruction in mtinst/htinst
> (0x3000 or
> 0x3020) [1]. 366b4fba0fae sets the write bit when the trap cause is a
> store
> guest-page fault, but the cause is the original access type [2],
> while the
> pseudoinstruction describes the implicit access that failed:
>
> original access, what failed Spike master
> load or fetch, A/D write 0x3020 0x3000
> store, A/D write 0x3020 0x3020
> store, read of a non-leaf PTE 0x3000 0x3020
>
> The commit was checked against Spike for the store case, where both
> agree.
> Patch 1 fixes all 8 failures of test-gstage-tinst.
>
> Results on master (1c1f512972), with make check-tcg for riscv64-
> softmmu:
>
> applied test-gstage-tinst check-tcg
> patch 2 only 8 of 19 fail 29/37
> patches 1-2 all pass 37/37
>
> The test is last so that every commit passes check-tcg.
>
> This bug was found during formal verification of a sandbox on top of
> the xv6
> OS where tests passed on qemu but verification against Sail failed.
> Claude
> was used to diagnose the issue. All commits were human written.
>
> [1] Privileged ISA v1.12, 8.6.3, Table 8.12
> [2] Privileged ISA v1.12, 8.5.1 "Guest Physical Address Translation"
> https://github.com/riscv/riscv-isa-manual/releases/tag/Priv-v1.12
>
> tewaro (2):
> target/riscv: report the write pseudoinstruction for a failed VS-
> stage
> A/D update
> tests/tcg/riscv64: test faults on implicit VS-stage page-table
> accesses
Can you please use the `./scripts/get_maintainer.pl` script on your
patches to find the complete list of email addresses to send this to
Alistair
>
> target/riscv/cpu.h | 1 +
> target/riscv/tcg/cpu_helper.c | 8 +-
> tests/tcg/riscv64/hyp-guest.S | 110 +++++++++++++++++++++
> tests/tcg/riscv64/hyp-guest.h | 71 ++++++++++++++
> tests/tcg/riscv64/system/meson.build | 77 +++++++++++++++
> tests/tcg/riscv64/test-gstage-tinst.S | 135
> ++++++++++++++++++++++++++
> 6 files changed, 401 insertions(+), 1 deletion(-)
> create mode 100644 tests/tcg/riscv64/hyp-guest.S
> create mode 100644 tests/tcg/riscv64/hyp-guest.h
> create mode 100644 tests/tcg/riscv64/test-gstage-tinst.S