Skip to content

Commit

Permalink
RISC-V: Handle bus errors in the page table walker
Browse files Browse the repository at this point in the history
We directly access physical memory while walking the page tables on
RISC-V, but while doing so we were using cpu_ld*() which does not report
bus errors.  This patch converts the page table walker over to use
address_space_ld*(), which allows bus errors to be detected.

Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
  • Loading branch information
palmer-dabbelt committed Oct 28, 2019
1 parent e6e03dc commit aacb578
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions target/riscv/cpu_helper.c
Expand Up @@ -169,7 +169,8 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,
/* NOTE: the env->pc value visible here will not be
* correct, but the value visible to the exception handler
* (riscv_cpu_do_interrupt) is correct */

MemTxResult res;
MemTxAttrs attrs = MEMTXATTRS_UNSPECIFIED;
int mode = mmu_idx;

if (mode == PRV_M && access_type != MMU_INST_FETCH) {
Expand Down Expand Up @@ -256,11 +257,16 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,
1 << MMU_DATA_LOAD, PRV_S)) {
return TRANSLATE_PMP_FAIL;
}

#if defined(TARGET_RISCV32)
target_ulong pte = ldl_phys(cs->as, pte_addr);
target_ulong pte = address_space_ldl(cs->as, pte_addr, attrs, &res);
#elif defined(TARGET_RISCV64)
target_ulong pte = ldq_phys(cs->as, pte_addr);
target_ulong pte = address_space_ldq(cs->as, pte_addr, attrs, &res);
#endif
if (res != MEMTX_OK) {
return TRANSLATE_FAIL;
}

hwaddr ppn = pte >> PTE_PPN_SHIFT;

if (!(pte & PTE_V)) {
Expand Down

0 comments on commit aacb578

Please sign in to comment.