Successed two stage translation, but failed pmp check can cause guest page fault instead of regular page fault.
In case of execution ld instuction in VS mode we can face situation when two stages of translation was passed successfully, and if PMP check was failed first_stage_error variable going to be setted to false and raise_mmu_exception will raise RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT(scause == 21) instead of RISCV_EXCP_LOAD_ACCESS_FAULT(scause == 5) and this is wrong, according to RISCV privileged spec sect. 3.7: Attempting to execute a load or load-reserved instruction which accesses a physical address within a PMP region without read permissions raises a load access-fault exception. Signed-off-by: Alexei Filippov <alexei.filip...@syntacore.com> --- target/riscv/cpu_helper.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index bc70ab5abc..eaef1c2c62 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1408,9 +1408,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, __func__, pa, ret, prot_pmp, tlb_size); prot &= prot_pmp; - } - - if (ret != TRANSLATE_SUCCESS) { + } else { /* * Guest physical address translation failed, this is a HS * level exception -- 2.34.1