RISC-V: Convert to do_transaction_failed hook
cover RISC-V: Convert to do_transaction_failed hook
The do_unassigned_access hook has been deprecated and RISC-V is the last user of it. Let's instead update the RISC-V implementation to use do_transaction_failed instead.
After this series I used the 'git grep' regexes in docs/devel/loads-stores.rst and these are the memory accesses inside target/riscv:
monitor.c:102: cpu_physical_memory_read(pte_addr, &pte, ptesize);
cpu_helper.c:262: target_ulong pte = address_space_ldl(cs->as, pte_addr, attrs, &res);
cpu_helper.c:264: target_ulong pte = address_space_ldq(cs->as, pte_addr, attrs, &res);
translate.c:782: ctx->opcode = cpu_ldl_code(env, ctx->base.pc_next);
gdbstub.c:328: env->fpr[n] = ldq_p(mem_buf); /* always 64-bit */
All of these look safe to me.
Palmer Dabbelt (2):
RISC-V: Handle bus errors in the page table walker
RISC-V: Implement cpu_do_transaction_failed
target/riscv/cpu.c | 2 +- target/riscv/cpu.h | 7 +++++-- target/riscv/cpu_helper.c | 23 ++++++++++++++++------- 3 files changed, 22 insertions(+), 10 deletions(-)
Signature · 1 line
2.23.0
PATCH 1/2 RISC-V: Handle bus errors in the page table walker
From: Palmer Dabbelt <[email protected]>
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.
--- target/riscv/cpu_helper.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
target/riscv/cpu_helper.c +9 -3
@@ -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 ) {
@@ -256,11 +257,16 @@ restart: 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 )) {
Signature · 1 line
2.23.0
Re: [Qemu-devel] [PATCH v1 1/2] RISC-V: Handle bus errors in the page table walker
Quoted 37 lines · Alistair Francis
From: Palmer Dabbelt <[email protected]>
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 <[email protected]>Signed-off-by Alistair Francis <[email protected]>--- target/riscv/cpu_helper.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)target/riscv/cpu_helper.c +4
-2@@ -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 ) {@@ -256,11 +257,16 @@ restart: 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/riscv/cpu_helper.c restart: · line 272
Quoted 10 lines
target/riscv/cpu_helper.c +5
-1-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 )) {
PATCH 2/2 RISC-V: Implement cpu_do_transaction_failed
In reply to Alistair FrancisFrom: Palmer Dabbelt <[email protected]>
This converts our port over from cpu_do_unassigned_access to cpu_do_transaction_failed, as cpu_do_unassigned_access has been deprecated.
--- target/riscv/cpu.c | 2 +- target/riscv/cpu.h | 7 +++++-- target/riscv/cpu_helper.c | 11 +++++++---- 3 files changed, 13 insertions(+), 7 deletions(-)
target/riscv/cpu.c +1 -1
@@ -484,7 +484,7 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) cc->gdb_stop_before_watchpoint = true; cc->disas_set_info = riscv_cpu_disas_set_info;#ifndef CONFIG_USER_ONLY - cc->do_unassigned_access = riscv_cpu_unassigned_access; + cc->do_transaction_failed = riscv_cpu_do_transaction_failed; cc->do_unaligned_access = riscv_cpu_do_unaligned_access; cc->get_phys_page_debug = riscv_cpu_get_phys_page_debug;#endif
target/riscv/cpu.h +5 -2
@@ -264,8 +264,11 @@ void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr,bool riscv_cpu_tlb_fill (CPUState *cs,vaddr address,int size,MMUAccessType access_type,int mmu_idx,bool probe,uintptr_t retaddr); -void riscv_cpu_unassigned_access (CPUState *cpu,hwaddr addr,bool is_write, -bool is_exec,int unused,unsigned size); +void riscv_cpu_do_transaction_failed (CPUState *cs,hwaddr physaddr, +vaddr addr,unsigned size, +MMUAccessType access_type, +int mmu_idx,MemTxAttrs attrs, +MemTxResult response,uintptr_t retaddr);char *riscv_isa_string (RISCVCPU *cpu);void riscv_cpu_list (void );
target/riscv/cpu_helper.c +7 -4
@@ -408,20 +408,23 @@ hwaddr riscv_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)return phys_addr; } -void riscv_cpu_unassigned_access (CPUState *cs,hwaddr addr,bool is_write, -bool is_exec,int unused,unsigned size) +void riscv_cpu_do_transaction_failed (CPUState *cs,hwaddr physaddr, +vaddr addr,unsigned size, +MMUAccessType access_type, +int mmu_idx,MemTxAttrs attrs, +MemTxResult response,uintptr_t retaddr) {RISCVCPU *cpu =RISCV_CPU (cs);CPURISCVState *env = &cpu->env; -if (is_write) { +if (access_type ==MMU_DATA_STORE ) { cs->exception_index =RISCV_EXCP_STORE_AMO_ACCESS_FAULT ; }else { cs->exception_index =RISCV_EXCP_LOAD_ACCESS_FAULT ; } env->badaddr = addr; -riscv_raise_exception (&cpu->env, cs->exception_index,GETPC ()); +riscv_raise_exception (&cpu->env, cs->exception_index, retaddr); } void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr,
Signature · 1 line
2.23.0
Re: [Qemu-devel] [PATCH v1 2/2] RISC-V: Implement cpu_do_transaction_failed
Quoted 68 lines · Alistair Francis
From: Palmer Dabbelt <[email protected]>
This converts our port over from
cpu_do_unassigned_accesstocpu_do_transaction_failed, ascpu_do_unassigned_accesshas been deprecated.Signed-off-by Palmer Dabbelt <[email protected]>Signed-off-by Alistair Francis <[email protected]>--- target/riscv/cpu.c | 2 +- target/riscv/cpu.h | 7 +++++-- target/riscv/cpu_helper.c | 11 +++++++---- 3 files changed, 13 insertions(+), 7 deletions(-)target/riscv/cpu.c +1
-1@@ -484,7 +484,7 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) cc->gdb_stop_before_watchpoint = true; cc->disas_set_info = riscv_cpu_disas_set_info;#ifndef CONFIG_USER_ONLY - cc->do_unassigned_access = riscv_cpu_unassigned_access; + cc->do_transaction_failed = riscv_cpu_do_transaction_failed; cc->do_unaligned_access = riscv_cpu_do_unaligned_access; cc->get_phys_page_debug = riscv_cpu_get_phys_page_debug;#endif target/riscv/cpu.h +5
-2@@ -264,8 +264,11 @@ void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr,bool riscv_cpu_tlb_fill (CPUState *cs,vaddr address,int size,MMUAccessType access_type,int mmu_idx,bool probe,uintptr_t retaddr); -void riscv_cpu_unassigned_access (CPUState *cpu,hwaddr addr,bool is_write, -bool is_exec,int unused,unsigned size); +void riscv_cpu_do_transaction_failed (CPUState *cs,hwaddr physaddr, +vaddr addr,unsigned size, +MMUAccessType access_type, +int mmu_idx,MemTxAttrs attrs, +MemTxResult response,uintptr_t retaddr);char *riscv_isa_string (RISCVCPU *cpu);void riscv_cpu_list (void );target/riscv/cpu_helper.c +6
-3@@ -408,20 +408,23 @@ hwaddr riscv_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)return phys_addr; } -void riscv_cpu_unassigned_access (CPUState *cs,hwaddr addr,bool is_write, -bool is_exec,int unused,unsigned size) +void riscv_cpu_do_transaction_failed (CPUState *cs,hwaddr physaddr, +vaddr addr,unsigned size, +MMUAccessType access_type, +int mmu_idx,MemTxAttrs attrs, +MemTxResult response,uintptr_t retaddr) {RISCVCPU *cpu =RISCV_CPU (cs);CPURISCVState *env = &cpu->env; -if (is_write) { +if (access_type ==MMU_DATA_STORE ) { cs->exception_index =RISCV_EXCP_STORE_AMO_ACCESS_FAULT ;
target/riscv/cpu_helper.c hwaddr riscv_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) · line 430
Quoted 10 lines
target/riscv/cpu_helper.c +1
-1}else { cs->exception_index =RISCV_EXCP_LOAD_ACCESS_FAULT ; } env->badaddr = addr; -riscv_raise_exception (&cpu->env, cs->exception_index,GETPC ()); +riscv_raise_exception (&cpu->env, cs->exception_index, retaddr); } void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr,
Quoted 3 lines · Alistair Francis
Palmer Dabbelt (2):
RISC-V: Handle bus errors in the page table walker
RISC-V: Implementcpu_do_transaction_failed
r~
Quoted 15 lines · Alistair Francis
The
do_unassigned_accesshook has been deprecated and RISC-V is the last user of it. Let's instead update the RISC-V implementation to usedo_transaction_failedinstead.After this series I used the 'git grep' regexes in
docs/devel/loads-stores.rstand these are the memory accesses inside target/riscv:monitor.c:102:
cpu_physical_memory_read(pte_addr, &pte, ptesize);cpu_helper.c:262:
target_ulongpte =address_space_ldl(cs->as, pte_addr, attrs, &res);
cpu_helper.c:264:target_ulongpte =address_space_ldq(cs->as, pte_addr, attrs, &res);translate.c:782:
ctx->opcode=cpu_ldl_code(env, ctx->base.pc_next);
Quoted 7 lines
gdbstub.c:328: env->fpr[n] =
ldq_p(mem_buf); /* always 64-bit */All of these look safe to me.
Palmer Dabbelt (2):
RISC-V: Handle bus errors in the page table walker
RISC-V: Implementcpu_do_transaction_failed
Can you Reviewed-By these, as they've still got my Author on them? That way I can pull them in :)
Quoted 5 lines
target/riscv/cpu.c | 2 +- target/riscv/cpu.h | 7 +++++-- target/riscv/cpu_helper.c | 23 ++++++++++++++++------- 3 files changed, 22 insertions(+), 10 deletions(-)
Quoted 19 lines · Palmer Dabbelt
Quoted 17 lines · Alistair Francis
The
do_unassigned_accesshook has been deprecated and RISC-V is the last user of it. Let's instead update the RISC-V implementation to usedo_transaction_failedinstead.After this series I used the 'git grep' regexes in
docs/devel/loads-stores.rstand these are the memory accesses inside target/riscv:monitor.c:102:
cpu_physical_memory_read(pte_addr, &pte, ptesize);cpu_helper.c:262:
target_ulongpte =address_space_ldl(cs->as, pte_addr, attrs, &res);
cpu_helper.c:264:target_ulongpte =address_space_ldq(cs->as, pte_addr, attrs, &res);translate.c:782:
ctx->opcode=cpu_ldl_code(env, ctx->base.pc_next);gdbstub.c:328: env->fpr[n] =
ldq_p(mem_buf); /* always 64-bit */
Quoted 8 lines
Quoted 5 lines
All of these look safe to me.
Palmer Dabbelt (2):
RISC-V: Handle bus errors in the page table walker
RISC-V: Implementcpu_do_transaction_failedCan you Reviewed-By these, as they've still got my Author on them? That way I can pull them in :)
Richard and Philippe have both reviewed it, that should be enough. I'm not sure if I can review it with my SOB as well.
Alistair
Quoted 6 lines
Quoted 6 lines
target/riscv/cpu.c | 2 +- target/riscv/cpu.h | 7 +++++-- target/riscv/cpu_helper.c | 23 ++++++++++++++++------- 3 files changed, 22 insertions(+), 10 deletions(-)