]> git.proxmox.com Git - mirror_qemu.git/commitdiff
RISC-V: Only Check PMP if MMU translation succeeds
authorHesham Almatary <Hesham.Almatary@cl.cam.ac.uk>
Thu, 30 May 2019 13:51:30 +0000 (14:51 +0100)
committerPalmer Dabbelt <palmer@sifive.com>
Mon, 24 Jun 2019 06:44:41 +0000 (23:44 -0700)
The current implementation unnecessarily checks for PMP even if MMU translation
failed. This may trigger a wrong PMP access exception instead of
a page exception.

For example, the very first instruction fetched after the first satp write in
S-Mode will trigger a PMP access fault instead of an instruction fetch page
fault.

This patch prioritises MMU exceptions over PMP exceptions and only checks for
PMP if MMU translation succeeds. This patch is required for future commits
that properly report PMP exception violations if PTW succeeds.

Signed-off-by: Hesham Almatary <Hesham.Almatary@cl.cam.ac.uk>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
target/riscv/cpu_helper.c

index 0bbfb7f48b794f7afb7ec1d0101683d437985493..a45b05ef8395ffb995b1a670ea9c7f17eb404be3 100644 (file)
@@ -436,6 +436,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
                   " prot %d\n", __func__, address, ret, pa, prot);
 
     if (riscv_feature(env, RISCV_FEATURE_PMP) &&
+        (ret == TRANSLATE_SUCCESS) &&
         !pmp_hart_has_privs(env, pa, TARGET_PAGE_SIZE, 1 << access_type)) {
         ret = TRANSLATE_FAIL;
     }