RFC target/riscv: Check store permission before split AMOs with Zicfiss
Get series with b4
b4 am [email protected]Versions newest first
- v1 RFC Latest2 patches 0 repliesNew
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | accel/tcg: Add probe_access_perm()accel/ include/ | +31 | 0 replies | |
| 2/2 | target/riscv: Check store permission before split AMOs with Zicfisstarget/ target/ target/ +1 more | +67 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [RFC PATCH 0/2] target/riscv: Check store permission before split AMOs with Zicfiss
With Zicfiss, an ordinary AMO to a shadow-stack page must fault with a store/AMO access fault (cause 7). When TCG lowers the AMO to a load followed by a store (!CF_PARALLEL), the load runs first. That gives the wrong cause (15) when the PTE's A bit is clear under Svade, and it lets the load's side effects (e.g. a read watchpoint) happen when an earlier load has left a read-permitting TLB entry for the page.
Patch 1 adds probe_access_perm(), a permission-only lookup that takes the real access size and skips watchpoints, dirty marking and the plugin slow path. Patch 2 uses it from the RISC-V AMO/AMOCAS translation, only for TBs with shadow stacks enabled and !CF_PARALLEL (the parallel helpers already look up the store first).
Tested on RV64 system emulation (debug, ASan, UBSan build):
- cold-TLB AMO with A=D=0 on a shadow-stack page gives cause 7 (cause 15 on baseline), single-thread TCG
- read watchpoint after a warming load does not stop with the series, and stops on baseline, single-thread TCG
- page-crossing Zama16b, page-crossing PMP and PMP-boundary AMOs, single-thread TCG and MTTCG
- unit and qtest pass
- check-tcg: rv128-sstatus (UBSan, pmp.c) fails and the interruptedmemory plugin test times out, both identically on master
- check-functional (sanitized build): 4 timeouts, and three pass with a longer limit. sifive_u passes in about 5s on baseline and patched builds without sanitizers. I did not run check-functional on a sanitized master build.
Not tested: RV32 at runtime (including the amocas.d path in gen_cmpxchg64), and the cold-TLB A=D=0 case and the read watchpoint under MTTCG. riscv32-softmmu and the linux-user targets compile.
Open questions:
- Is a permission-only helper in accel/tcg acceptable? The alternative is a RISC-V-local helper built on probe_access_flags(), at the cost of early dirty marking.
- The probe is a store lookup, so with hardware A/D updates it may set D before the AMO's load phase runs. If that load then faults, D is set on a page the AMO never accessed. I have not tested this.
- The second-page probe for page-crossing Zama16b accesses mirrors what the real operation does today. A page-crossing access arguably should fault, since a granule cannot cross a page. Enforcing that would be a separate change.
Rishab Pradeep (2):
accel/tcg: Add probe_access_perm()
target/riscv: Check store permission before split AMOs with Zicfiss
accel/tcg/cputlb.c | 11 ++++++ include/accel/tcg/probe.h | 20 ++++++++++ target/riscv/helper.h | 5 +++ .../riscv/tcg/insn_trans/trans_rvzacas.c.inc | 2 + target/riscv/tcg/op_helper.c | 37 +++++++++++++++++++ target/riscv/tcg/translate.c | 23 ++++++++++++ 6 files changed, 98 insertions(+)
Signature · 1 line
2.56.0