Skip to content

target/riscv: fix mtinst/htinst for G-stage faults on VS-stage A/D updates

tewaro qemu-devel qemu-riscv 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 3 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2target/riscv: report the write pseudoinstruction for a failed VS-stage A/D updatetarget/riscv/cpu.h target/riscv/tcg/cpu_helper.c+8 -11 reply
2/2tests/tcg/riscv64: test faults on implicit VS-stage page-table accessestests/tcg/riscv64/hyp-guest.S tests/tcg/riscv64/hyp-guest.h tests/tcg/riscv64/system/meson.build +1 more+393 -01 reply

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchDaniel Henrique Barboza
1/2R-b
2/2R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/2] target/riscv: fix mtinst/htinst for G-stage faults on VS-stage A/D updates

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

 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
Signature · 1 line
2.54.0 (Apple Git-157)