tcg: Add CPUClass::tlb_fill
cover tcg: Add CPUClass::tlb_fill
There is currently a lot of confusion between foo_cpu_handle_mmu_fault and tlb_fill.
In particular, foo_cpu_handle_mmu_fault was only defined for user-only, and its only valid action was to set up the cpu for cpu_loop_exit so that we can deliver a SIGSEGV to the guest. And yet, we had code that tried to return from the host SIGSEGV handler to retry the instruction.
We had, for some targets, a definition of foo_cpu_handle_mmu_fault for softmmu. Sometimes this was called from tlb_fill, sometimes not.
Finally, we have a use case for SVE that wants a non-faulting tlb_fill, so while we're changing the interface, let's go ahead and include that.
r~
Richard Henderson (26):
tcg: Assert h2g_valid for 32-bit guest on 64-bit host
tcg: Add CPUClass::tlb_fill
target/alpha: Convert to CPUClass::tlb_fill target/arm: Convert to CPUClass::tlb_fill target/cris: Convert to CPUClass::tlb_fill target/hppa: Convert to CPUClass::tlb_fill target/i386: Convert to CPUClass::tlb_fill target/lm32: Convert to CPUClass::tlb_fill target/m68k: Convert to CPUClass::tlb_fill target/microblaze: Convert to CPUClass::tlb_fill target/mips: Convert to CPUClass::tlb_fill target/moxie: Convert to CPUClass::tlb_fill target/nios2: Convert to CPUClass::tlb_fill target/openrisc: Convert to CPUClass::tlb_fill target/ppc: Convert to CPUClass::tlb_fill target/riscv: Convert to CPUClass::tlb_fill target/s390x: Convert to CPUClass::tlb_fill target/sh4: Convert to CPUClass::tlb_fill target/sparc: Convert to CPUClass::tlb_fill target/tilegx: Convert to CPUClass::tlb_fill target/tricore: Convert to CPUClass::tlb_fill target/unicore32: Convert to CPUClass::tlb_fill target/xtensa: Convert to CPUClass::tlb_fill
tcg: Use CPUClass::tlb_fill in cputlb.c
tcg: Remove CPUClass::handle_mmu_fault
tcg: Use tlb_fill probe from tlb_vaddr_to_host
include/exec/cpu_ldst.h | 40 +------ include/exec/exec-all.h | 9 -- include/qom/cpu.h | 12 +- target/alpha/cpu.h | 5 +- target/arm/internals.h | 10 +- target/cris/cpu.h | 5 +- target/hppa/cpu.h | 8 +- target/i386/cpu.h | 5 +- target/lm32/cpu.h | 5 +- target/m68k/cpu.h | 5 +- target/microblaze/cpu.h | 5 +- target/mips/internal.h | 5 +- target/moxie/cpu.h | 5 +- target/nios2/cpu.h | 5 +- target/openrisc/cpu.h | 5 +- target/ppc/cpu.h | 7 +- target/riscv/cpu.h | 5 +- target/s390x/internal.h | 5 +- target/sh4/cpu.h | 5 +- target/sparc/cpu.h | 5 +- target/tricore/cpu.h | 6 +- target/unicore32/cpu.h | 5 +- target/xtensa/cpu.h | 5 +- accel/tcg/cputlb.c | 88 +++++++++++++-- accel/tcg/user-exec.c | 46 +++----- target/alpha/cpu.c | 5 +- target/alpha/helper.c | 42 +++---- target/alpha/mem_helper.c | 16 --- target/arm/cpu.c | 22 +--- target/arm/helper.c | 89 ++++++++------- target/arm/op_helper.c | 29 +---- target/arm/sve_helper.c | 6 +- target/cris/cpu.c | 5 +- target/cris/helper.c | 61 ++++++----- target/cris/op_helper.c | 28 ----- target/hppa/cpu.c | 5 +- target/hppa/mem_helper.c | 16 ++- target/i386/cpu.c | 5 +- target/i386/excp_helper.c | 53 +++++---- target/i386/mem_helper.c | 21 ---- target/lm32/cpu.c | 5 +- target/lm32/helper.c | 8 +- target/lm32/op_helper.c | 16 --- target/m68k/cpu.c | 2 +- target/m68k/helper.c | 89 ++++++++------- target/m68k/op_helper.c | 15 --- target/microblaze/cpu.c | 5 +- target/microblaze/helper.c | 134 +++++++++++----------- target/microblaze/op_helper.c | 19 ---- target/mips/cpu.c | 5 +- target/mips/helper.c | 109 +++++++++--------- target/mips/op_helper.c | 15 --- target/moxie/cpu.c | 5 +- target/moxie/helper.c | 65 +++-------- target/nios2/cpu.c | 5 +- target/nios2/helper.c | 173 +++++++++++++---------------- target/nios2/mmu.c | 12 -- target/openrisc/cpu.c | 5 +- target/openrisc/mmu.c | 69 ++++++------ target/ppc/mmu_helper.c | 13 ++- target/ppc/translate_init.inc.c | 5 +- target/ppc/user_only_helper.c | 14 ++- target/riscv/cpu.c | 5 +- target/riscv/cpu_helper.c | 50 ++++----- target/s390x/cpu.c | 5 +- target/s390x/excp_helper.c | 150 ++++++++++++++----------- target/s390x/mem_helper.c | 29 ----- target/sh4/cpu.c | 5 +- target/sh4/helper.c | 189 +++++++++++++++----------------- target/sh4/op_helper.c | 12 -- target/sparc/cpu.c | 5 +- target/sparc/ldst_helper.c | 15 --- target/sparc/mmu_helper.c | 167 ++++++++++++++-------------- target/tilegx/cpu.c | 11 +- target/tricore/cpu.c | 1 + target/tricore/helper.c | 23 ++-- target/tricore/op_helper.c | 26 ----- target/unicore32/cpu.c | 5 +- target/unicore32/helper.c | 23 ---- target/unicore32/op_helper.c | 14 --- target/unicore32/softmmu.c | 13 ++- target/xtensa/cpu.c | 5 +- target/xtensa/helper.c | 70 ++++++------ 83 files changed, 1000 insertions(+), 1320 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/26 tcg: Assert h2g_valid for 32-bit guest on 64-bit host
For this combination, we can tell whether or not the address being accessed is within the 4GB range that is accessible by the guest. Otherwise the fault must be elsewhere in qemu, accessing qemu data structures.
--- accel/tcg/user-exec.c | 9 +++++++++ 1 file changed, 9 insertions(+)
accel/tcg/user-exec.c +9 -0
@@ -143,6 +143,15 @@ static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, } } +/* +* For a 32-bit guest on a 64-bit host, the set of addresses that we +* access on behalf of the guest is constrained. Anything outside +* that range is a bug elsewhere in QEMU. +*/ +#if TARGET_LONG_BITS ==32 &&HOST_LONG_BITS ==64 +g_assert (h2g_valid (address)); +#endif +/* Convert forcefully to guest address space, invalid addresses are still valid segv ones */ address =h2g_nocheck (address);
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 01/26] tcg: Assert h2g_valid for 32-bit guest on 64-bit host
Quoted 17 lines · Richard Henderson
For this combination, we can tell whether or not the address being accessed is within the 4GB range that is accessible by the guest. Otherwise the fault must be elsewhere in qemu, accessing qemu data structures.
Signed-off-by Richard Henderson <[email protected]>--- accel/tcg/user-exec.c | 9 +++++++++ 1 file changed, 9 insertions(+)accel/tcg/user-exec.c +0
-0@@ -143,6 +143,15 @@ static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, }
accel/tcg/user-exec.c static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, · line 153
Quoted 10 lines
accel/tcg/user-exec.c +8
-0} +/* +* For a 32-bit guest on a 64-bit host, the set of addresses that we +* access on behalf of the guest is constrained. Anything outside +* that range is a bug elsewhere in QEMU. +*/ +#if TARGET_LONG_BITS ==32 &&HOST_LONG_BITS ==64 +g_assert (h2g_valid (address)); +#endif
I'm not sure this is right. h2g_valid() will check whether the guest address is below GUEST_ADDR_MAX. For architectures which set TARGET_VIRT_ADDR_SPACE_BITS to something less than 32 there are address values which aren't h2g_valid() but which we still want to cause a guest exception rather than asserting, aren't there ?
thanks
-- PMM
Re: [Qemu-devel] [PATCH 01/26] tcg: Assert h2g_valid for 32-bit guest on 64-bit host
Quoted 9 lines · Peter Maydell
accel/tcg/user-exec.c static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, · line 153
Quoted 3 lines
accel/tcg/user-exec.c +3
-0+#if TARGET_LONG_BITS ==32 &&HOST_LONG_BITS ==64 +g_assert (h2g_valid (address)); +#endif I'm not sure this is right.
h2g_valid()will check whether the guest address is belowGUEST_ADDR_MAX. For architectures which setTARGET_VIRT_ADDR_SPACE_BITSto something less than 32 there are address values which aren'th2g_valid()but which we still want to cause a guest exception rather than asserting, aren't there ?
Hmm, you're right, this should test something else. I'll drop this for now...
r~
PATCH 2/26 tcg: Add CPUClass::tlb_fill
In reply to Richard HendersonThis hook will replace the (user-only mode specific) handle_mmu_fault hook, and the (system mode specific) tlb_fill function.
The handle_mmu_fault hook was written as if there was a valid way to recover from an mmu fault, and had 3 possible return states. In reality, the only valid action is to raise an exception, return to the main loop, and delver the SIGSEGV to the guest.
Using the hook for system mode requires that all targets be converted, so for now the hook is (optionally) used only from user-only mode.
--- include/qom/cpu.h | 9 +++++++++ accel/tcg/user-exec.c | 42 ++++++++++++++---------------------------- 2 files changed, 23 insertions(+), 28 deletions(-)
include/qom/cpu.h +9 -0
@@ -119,6 +119,12 @@ struct TranslationBlock;* will need to do more. If this hook is not implemented then the * default is to call @set_pc(tb->pc). * @handle_mmu_fault: Callback for handling an MMU fault. +* @tlb_fill: Callback for handling a softmmu tlb miss or user-only +* address fault. For system mode, if the access is valid, call +* tlb_set_page and return true; if the access is invalid, and +* probe is true, return false; otherwise raise an exception and +* do not return. For user-only mode, always raise an exception +* and do not return. * @get_phys_page_debug: Callback for obtaining a physical address. * @get_phys_page_attrs_debug: Callback for obtaining a physical address and the * associated memory transaction attributes to use for the access.
@@ -194,6 +200,9 @@ typedef struct CPUClass {void (*synchronize_from_tb)(CPUState *cpu,struct TranslationBlock *tb);int (*handle_mmu_fault)(CPUState *cpu,vaddr address,int size,int rw,int mmu_index); +bool (*tlb_fill)(CPUState *cpu,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);hwaddr (*get_phys_page_debug)(CPUState *cpu,vaddr addr);hwaddr (*get_phys_page_attrs_debug)(CPUState *cpu,vaddr addr,MemTxAttrs *attrs);
accel/tcg/user-exec.c +14 -28
60 lines not on this page · raw message
Signature · 1 line
2.17.1
Quoted 8 lines · Richard Henderson
This hook will replace the (user-only mode specific)
handle_mmu_faulthook, and the (system mode specific)tlb_fillfunction.The
handle_mmu_faulthook was written as if there was a valid way to recover from an mmu fault, and had 3 possible return states. In reality, the only valid action is to raise an exception, return to the main loop, and delver the SIGSEGV to the guest.
"deliver"
You might also mention here that all of the implementations of handle_mmu_fault for guest architectures which support linux-user do in fact only ever return 1.
Quoted 50 lines
Using the hook for system mode requires that all targets be converted, so for now the hook is (optionally) used only from user-only mode.
Signed-off-by Richard Henderson <[email protected]>--- include/qom/cpu.h | 9 +++++++++ accel/tcg/user-exec.c | 42 ++++++++++++++---------------------------- 2 files changed, 23 insertions(+), 28 deletions(-)include/qom/cpu.h +9
-0@@ -119,6 +119,12 @@ struct TranslationBlock;* will need to do more. If this hook is not implemented then the * default is to call @set_pc(tb->pc). * @handle_mmu_fault: Callback for handling an MMU fault. +* @tlb_fill: Callback for handling a softmmu tlb miss or user-only +* address fault. For system mode, if the access is valid, call +* tlb_set_page and return true; if the access is invalid, and +* probe is true, return false; otherwise raise an exception and +* do not return. For user-only mode, always raise an exception +* and do not return. * @get_phys_page_debug: Callback for obtaining a physical address. * @get_phys_page_attrs_debug: Callback for obtaining a physical address and the * associated memory transaction attributes to use for the access. @@ -194,6 +200,9 @@ typedef struct CPUClass {void (*synchronize_from_tb)(CPUState *cpu,struct TranslationBlock *tb);int (*handle_mmu_fault)(CPUState *cpu,vaddr address,int size,int rw,int mmu_index); +bool (*tlb_fill)(CPUState *cpu,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);hwaddr (*get_phys_page_debug)(CPUState *cpu,vaddr addr);hwaddr (*get_phys_page_attrs_debug)(CPUState *cpu,vaddr addr,MemTxAttrs *attrs);accel/tcg/user-exec.c +1
-0@@ -65,6 +65,7 @@ static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info,CPUClass *cc;int ret;unsigned long address = (unsigned long )info->si_addr; +MMUAccessType access_type;/* We must handle PC addresses from two different sources: * a call return address and a signal frame address.
accel/tcg/user-exec.c static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, · line 156
Quoted 6 lines
accel/tcg/user-exec.c +0
-3@@ -151,40 +152,25 @@ static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info,#if TARGET_LONG_BITS ==32 &&HOST_LONG_BITS ==64 g_assert (h2g_valid (address));#endif - -/* Convert forcefully to guest address space, invalid addresses -are still valid segv ones */
This comment is still valid so I don't think it should be deleted.
accel/tcg/user-exec.c static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, · line 155
Quoted 1 line
accel/tcg/user-exec.c +0
-0address =h2g_nocheck (address);
Otherwise
thanks
-- PMM
Philippe Mathieu-Daudé
Reviewed-byQuoted 76 lines · Peter Maydell
Quoted 8 lines · Richard Henderson
This hook will replace the (user-only mode specific)
handle_mmu_faulthook, and the (system mode specific)tlb_fillfunction.The
handle_mmu_faulthook was written as if there was a valid way to recover from an mmu fault, and had 3 possible return states. In reality, the only valid action is to raise an exception, return to the main loop, and delver the SIGSEGV to the guest."deliver"
You might also mention here that all of the implementations of
handle_mmu_faultfor guest architectures which support linux-user do in fact only ever return 1.Quoted 50 lines
Using the hook for system mode requires that all targets be converted, so for now the hook is (optionally) used only from user-only mode.
Signed-off-by Richard Henderson <[email protected]>--- include/qom/cpu.h | 9 +++++++++ accel/tcg/user-exec.c | 42 ++++++++++++++---------------------------- 2 files changed, 23 insertions(+), 28 deletions(-)include/qom/cpu.h +9
-0@@ -119,6 +119,12 @@ struct TranslationBlock;* will need to do more. If this hook is not implemented then the * default is to call @set_pc(tb->pc). * @handle_mmu_fault: Callback for handling an MMU fault. +* @tlb_fill: Callback for handling a softmmu tlb miss or user-only +* address fault. For system mode, if the access is valid, call +* tlb_set_page and return true; if the access is invalid, and +* probe is true, return false; otherwise raise an exception and +* do not return. For user-only mode, always raise an exception +* and do not return. * @get_phys_page_debug: Callback for obtaining a physical address. * @get_phys_page_attrs_debug: Callback for obtaining a physical address and the * associated memory transaction attributes to use for the access. @@ -194,6 +200,9 @@ typedef struct CPUClass {void (*synchronize_from_tb)(CPUState *cpu,struct TranslationBlock *tb);int (*handle_mmu_fault)(CPUState *cpu,vaddr address,int size,int rw,int mmu_index); +bool (*tlb_fill)(CPUState *cpu,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);hwaddr (*get_phys_page_debug)(CPUState *cpu,vaddr addr);hwaddr (*get_phys_page_attrs_debug)(CPUState *cpu,vaddr addr,MemTxAttrs *attrs);accel/tcg/user-exec.c +1
-0@@ -65,6 +65,7 @@ static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info,CPUClass *cc;int ret;unsigned long address = (unsigned long )info->si_addr; +MMUAccessType access_type;/* We must handle PC addresses from two different sources: * a call return address and a signal frame address. accel/tcg/user-exec.c static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, · line 156
Quoted 6 lines
accel/tcg/user-exec.c +0
-3@@ -151,40 +152,25 @@ static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info,#if TARGET_LONG_BITS ==32 &&HOST_LONG_BITS ==64 g_assert (h2g_valid (address));#endif - -/* Convert forcefully to guest address space, invalid addresses -are still valid segv ones */ This comment is still valid so I don't think it should be deleted.
Quoted 5 lines
accel/tcg/user-exec.c static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, · line 155
Quoted 1 line
accel/tcg/user-exec.c +0
-0address =h2g_nocheck (address);Otherwise
Reviewed-by Peter Maydell <[email protected]>
PATCH 3/26 target/alpha: Convert to CPUClass::tlb_fill
In reply to Richard Henderson--- target/alpha/cpu.h | 5 ++-- target/alpha/cpu.c | 5 ++-- target/alpha/helper.c | 50 +++++++++++++++++++++++---------------- target/alpha/mem_helper.c | 16 ------------- 4 files changed, 35 insertions(+), 41 deletions(-)
target/alpha/cpu.h +3 -2
@@ -476,8 +476,9 @@ void alpha_cpu_list(FILE *f, fprintf_function cpu_fprintf);is returned if the signal was handled by the virtual CPU. */ int cpu_alpha_signal_handler (int host_signum,void *pinfo,void *puc); -int alpha_cpu_handle_mmu_fault (CPUState *cpu,vaddr address,int size,int rw, -int mmu_idx); +bool alpha_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr); void QEMU_NORETURN dynamic_excp(CPUAlphaState *, uintptr_t, int, int); void QEMU_NORETURN arith_excp(CPUAlphaState *, uintptr_t, int, uint64_t);
target/alpha/cpu.c +2 -3
@@ -230,9 +230,8 @@ static void alpha_cpu_class_init(ObjectClass *oc, void *data) cc->set_pc = alpha_cpu_set_pc; cc->gdb_read_register = alpha_cpu_gdb_read_register; cc->gdb_write_register = alpha_cpu_gdb_write_register; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = alpha_cpu_handle_mmu_fault; -#else + cc->tlb_fill = alpha_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->do_transaction_failed = alpha_cpu_do_transaction_failed; cc->do_unaligned_access = alpha_cpu_do_unaligned_access; cc->get_phys_page_debug = alpha_cpu_get_phys_page_debug;
target/alpha/helper.c +30 -20
76 lines not on this page · raw message
target/alpha/mem_helper.c +0 -16
@@ -62,20 +62,4 @@ void alpha_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, env->error_code =0 ; cpu_loop_exit_restore(cs, retaddr); } - -/* try to fill the TLB and return an exception if error. If retaddr is -NULL, it means that the function was called in C code (i.e. not -from generated code or from helper.c) */ -/* XXX: fix it to restore all registers */ -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -int ret; - - ret =alpha_cpu_handle_mmu_fault (cs, addr, size, access_type, mmu_idx); -if (unlikely (ret !=0 )) { -/* Exception index and error code are already set */ -cpu_loop_exit_restore (cs, retaddr); - } -}#endif /* CONFIG_USER_ONLY */
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 03/26] target/alpha: Convert to CPUClass::tlb_fill
Quoted 8 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/alpha/cpu.h | 5 ++-- target/alpha/cpu.c | 5 ++-- target/alpha/helper.c | 50 +++++++++++++++++++++++---------------- target/alpha/mem_helper.c | 16 ------------- 4 files changed, 35 insertions(+), 41 deletions(-)
thanks
-- PMM
Re: [Qemu-devel] [PATCH 03/26] target/alpha: Convert to CPUClass::tlb_fill
In reply to Richard HendersonQuoted 138 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/alpha/cpu.h | 5 ++-- target/alpha/cpu.c | 5 ++-- target/alpha/helper.c | 50 +++++++++++++++++++++++---------------- target/alpha/mem_helper.c | 16 ------------- 4 files changed, 35 insertions(+), 41 deletions(-)target/alpha/cpu.h +3
-2@@ -476,8 +476,9 @@ void alpha_cpu_list(FILE *f, fprintf_function cpu_fprintf);is returned if the signal was handled by the virtual CPU. */ int cpu_alpha_signal_handler (int host_signum,void *pinfo,void *puc); -int alpha_cpu_handle_mmu_fault (CPUState *cpu,vaddr address,int size,int rw, -int mmu_idx); +bool alpha_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr); void QEMU_NORETURN dynamic_excp(CPUAlphaState *, uintptr_t, int, int); void QEMU_NORETURN arith_excp(CPUAlphaState *, uintptr_t, int, uint64_t);target/alpha/cpu.c +2
-3@@ -230,9 +230,8 @@ static void alpha_cpu_class_init(ObjectClass *oc, void *data) cc->set_pc = alpha_cpu_set_pc; cc->gdb_read_register = alpha_cpu_gdb_read_register; cc->gdb_write_register = alpha_cpu_gdb_write_register; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = alpha_cpu_handle_mmu_fault; -#else + cc->tlb_fill = alpha_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->do_transaction_failed = alpha_cpu_do_transaction_failed; cc->do_unaligned_access = alpha_cpu_do_unaligned_access; cc->get_phys_page_debug = alpha_cpu_get_phys_page_debug;target/alpha/helper.c +30
-20@@ -102,17 +102,7 @@ void cpu_alpha_store_gr(CPUAlphaState *env, unsigned reg, uint64_t val) *cpu_alpha_addr_gr (env, reg) = val; } -#if defined(CONFIG_USER_ONLY ) -int alpha_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int size, -int rw,int mmu_idx) -{ -AlphaCPU *cpu =ALPHA_CPU (cs); - - cs->exception_index =EXCP_MMFAULT ; - cpu->env.trap_arg0 = address; -return 1 ; -} -#else +#ifndef CONFIG_USER_ONLY /* Returns the OSF/1 entMM failure indication, or -1 on success. */ static int get_physical_address(CPUAlphaState *env, target_ulong addr, int prot_need, int mmu_idx,@@ -246,29 +236,49 @@ hwaddr alpha_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) fail =get_physical_address (&cpu->env, addr,0 ,0 , &phys, &prot);return (fail >=0 ?-1 : phys); } +#endif /* !USER_ONLY */ -int alpha_cpu_handle_mmu_fault (CPUState *cs,vaddr addr,int size,int rw, -int mmu_idx) +bool alpha_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr) {AlphaCPU *cpu =ALPHA_CPU (cs); + +#ifdef CONFIG_USER_ONLY + cs->exception_index =EXCP_MMFAULT ; + cpu->env.trap_arg0 = address; +cpu_loop_exit_restore (cs, retaddr); +#else CPUAlphaState *env = &cpu->env;target_ulong phys;int prot, fail; - fail =get_physical_address (env, addr,1 << rw, mmu_idx, &phys, &prot); + fail =get_physical_address (env, address,1 << access_type, + mmu_idx, &phys, &prot);if (unlikely (fail >=0 )) { +if (probe) { +return false; + } cs->exception_index =EXCP_MMFAULT ; - env->trap_arg0 = addr; + env->trap_arg0 = address; env->trap_arg1 = fail; - env->trap_arg2 = (rw ==2 ?-1 : rw); -return 1 ; + env->trap_arg2 = (access_type ==MMU_INST_FETCH ?-1 : access_type); +cpu_loop_exit_restore (cs, retaddr); } -tlb_set_page (cs, addr &TARGET_PAGE_MASK , phys &TARGET_PAGE_MASK , +tlb_set_page (cs, address &TARGET_PAGE_MASK , phys &TARGET_PAGE_MASK , prot, mmu_idx,TARGET_PAGE_SIZE ); -return 0 ; +return true; +#endif } -#endif /* USER_ONLY */ + +#ifndef CONFIG_USER_ONLY +void tlb_fill (CPUState *cs,target_ulong addr,int size, +MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) +{ +alpha_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); +} +#endif void alpha_cpu_do_interrupt (CPUState *cs) {target/alpha/mem_helper.c +0
-7@@ -62,20 +62,4 @@ void alpha_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, env->error_code =0 ;cpu_loop_exit_restore (cs, retaddr); } - -/* try to fill the TLB and return an exception if error. If retaddr is -NULL, it means that the function was called in C code (i.e. not -from generated code or from helper.c) */ -/* XXX: fix it to restore all registers */ -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr)
target/alpha/mem_helper.c void alpha_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, · line 65
Quoted 10 lines
target/alpha/mem_helper.c +0
-9-{ -int ret; - - ret =alpha_cpu_handle_mmu_fault (cs, addr, size, access_type, mmu_idx); -if (unlikely (ret !=0 )) { -/* Exception index and error code are already set */ -cpu_loop_exit_restore (cs, retaddr); - } -}#endif /* CONFIG_USER_ONLY */
PATCH 4/26 target/arm: Convert to CPUClass::tlb_fill
In reply to Richard Henderson--- target/arm/internals.h | 10 +++-- target/arm/cpu.c | 22 +--------- target/arm/helper.c | 97 ++++++++++++++++++++++++++---------------- target/arm/op_helper.c | 29 ++----------- 4 files changed, 72 insertions(+), 86 deletions(-)
target/arm/internals.h +6 -4
@@ -761,10 +761,12 @@ static inline bool arm_extabort_type(MemTxResult result)return result !=MEMTX_DECODE_ERROR ; } -/* Do a page table walk and add page to TLB if possible */ -bool arm_tlb_fill (CPUState *cpu,vaddr address, -MMUAccessType access_type,int mmu_idx, -ARMMMUFaultInfo *fi); +bool arm_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr); + +void arm_deliver_fault(ARMCPU *cpu, vaddr addr, MMUAccessType access_type, + int mmu_idx, ARMMMUFaultInfo *fi) QEMU_NORETURN;/* Return true if the stage 1 translation regime is using LPAE format page * tables */
target/arm/cpu.c +2 -20
@@ -2114,23 +2114,6 @@ static Property arm_cpu_properties[] = { DEFINE_PROP_END_OF_LIST() }; -#ifdef CONFIG_USER_ONLY -static int arm_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int size, -int rw,int mmu_idx) -{ -ARMCPU *cpu =ARM_CPU (cs); -CPUARMState *env = &cpu->env; - - env->exception.vaddress = address; -if (rw ==2 ) { - cs->exception_index =EXCP_PREFETCH_ABORT ; - }else { - cs->exception_index =EXCP_DATA_ABORT ; - } -return 1 ; -} -#endif -static gchar *arm_gdb_arch_name (CPUState *cs) {ARMCPU *cpu =ARM_CPU (cs);
@@ -2163,9 +2146,8 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) cc->synchronize_from_tb = arm_cpu_synchronize_from_tb; cc->gdb_read_register = arm_cpu_gdb_read_register; cc->gdb_write_register = arm_cpu_gdb_write_register; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = arm_cpu_handle_mmu_fault; -#else + cc->tlb_fill = arm_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->do_interrupt = arm_cpu_do_interrupt; cc->do_unaligned_access = arm_cpu_do_unaligned_access; cc->do_transaction_failed = arm_cpu_do_transaction_failed;
target/arm/helper.c +60 -37
109 lines not on this page · raw message
target/arm/op_helper.c +4 -25
@@ -126,8 +126,8 @@ static inline uint32_t merge_syn_data_abort(uint32_t template_syn,return syn; } -static void deliver_fault (ARMCPU *cpu,vaddr addr,MMUAccessType access_type, -int mmu_idx,ARMMMUFaultInfo *fi) +void arm_deliver_fault (ARMCPU *cpu,vaddr addr,MMUAccessType access_type, +int mmu_idx,ARMMMUFaultInfo *fi) {CPUARMState *env = &cpu->env;int target_el;
@@ -179,27 +179,6 @@ static void deliver_fault(ARMCPU *cpu, vaddr addr, MMUAccessType access_type,raise_exception (env, exc, syn, target_el); } -/* try to fill the TLB and return an exception if error. If retaddr is -* NULL, it means that the function was called in C code (i.e. not -* from generated code or from helper.c) -*/ -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -bool ret; -ARMMMUFaultInfo fi = {}; - - ret =arm_tlb_fill (cs, addr, access_type, mmu_idx, &fi); -if (unlikely (ret)) { -ARMCPU *cpu =ARM_CPU (cs); - -/* now we have a real cpu fault */ -cpu_restore_state (cs, retaddr, true); - -deliver_fault (cpu, addr, access_type, mmu_idx, &fi); - } -} -/* Raise a data fault alignment exception for the specified virtual address */ void arm_cpu_do_unaligned_access(CPUState *cs, vaddr vaddr, MMUAccessType access_type,
@@ -212,7 +191,7 @@ void arm_cpu_do_unaligned_access(CPUState *cs, vaddr vaddr,cpu_restore_state (cs, retaddr, true); fi.type = ARMFault_Alignment; -deliver_fault (cpu, vaddr, access_type, mmu_idx, &fi); +arm_deliver_fault (cpu, vaddr, access_type, mmu_idx, &fi); }/* arm_cpu_do_transaction_failed: handle a memory system error response
@@ -233,7 +212,7 @@ void arm_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, fi.ea =arm_extabort_type (response); fi.type = ARMFault_SyncExternal; - deliver_fault(cpu, addr, access_type, mmu_idx, &fi); + arm_deliver_fault(cpu, addr, access_type, mmu_idx, &fi); }#endif /* !defined(CONFIG_USER_ONLY) */
Signature · 1 line
2.17.1
Re: [Qemu-devel] [Qemu-arm] [PATCH 04/26] target/arm: Convert to CPUClass::tlb_fill
Quoted 16 lines · Richard Henderson
target/arm/helper.c +16
-0+bool arm_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr) +{ +ARMCPU *cpu =ARM_CPU (cs); + +#ifdef CONFIG_USER_ONLY + cpu->env.exception.vaddress = address; +if (access_type ==MMU_INST_FETCH ) { + cs->exception_index =EXCP_PREFETCH_ABORT ; + }else { + cs->exception_index =EXCP_DATA_ABORT ; + } +cpu_loop_exit_restore (cs, retaddr); +#else +hwaddr phys_addr;
target/arm/helper.c uint32_t HELPER(v7m_tt)(CPUARMState *env, uint32_t addr, uint32_t op) · line 12380
Quoted 10 lines
target/arm/helper.c +10
-0+target_ulong page_size; +int prot, ret; +MemTxAttrs attrs = {}; +ARMMMUFaultInfo fi = {}; + +/* +* Walk the page table and (if the mapping exists) add the page +* to the TLB. Return false on success, or true on failure. Populate +* fsr with ARM DFSR/IFSR fault register format value on failure. +*/
This comment about what we return doesn't seem to match what the code is doing.
thanks
-- PMM
Re: [Qemu-arm] [PATCH 04/26] target/arm: Convert to CPUClass::tlb_fill
Quoted 24 lines · Peter Maydell
Quoted 21 lines · Richard Henderson
target/arm/helper.c +21
-0+bool arm_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr) +{ +ARMCPU *cpu =ARM_CPU (cs); + +#ifdef CONFIG_USER_ONLY + cpu->env.exception.vaddress = address; +if (access_type ==MMU_INST_FETCH ) { + cs->exception_index =EXCP_PREFETCH_ABORT ; + }else { + cs->exception_index =EXCP_DATA_ABORT ; + } +cpu_loop_exit_restore (cs, retaddr); +#else +hwaddr phys_addr; +target_ulong page_size; +int prot, ret; +MemTxAttrs attrs = {}; +ARMMMUFaultInfo fi = {}; +
Quoted 8 lines
target/arm/helper.c uint32_t HELPER(v7m_tt)(CPUARMState *env, uint32_t addr, uint32_t op) · line 12380
Quoted 5 lines
target/arm/helper.c +5
-0+/* +* Walk the page table and (if the mapping exists) add the page +* to the TLB. Return false on success, or true on failure. Populate +* fsr with ARM DFSR/IFSR fault register format value on failure. +*/ This comment about what we return doesn't seem to match what the code is doing.
Bah. The perils of copying comments while changing the function signature.
r~
Peter Maydell
Reviewed-byRe: [Qemu-devel] [Qemu-arm] [PATCH 04/26] target/arm: Convert to CPUClass::tlb_fill
In reply to Peter MaydellQuoted 25 lines · Peter Maydell
Quoted 21 lines · Richard Henderson
target/arm/helper.c +21
-0+bool arm_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr) +{ +ARMCPU *cpu =ARM_CPU (cs); + +#ifdef CONFIG_USER_ONLY + cpu->env.exception.vaddress = address; +if (access_type ==MMU_INST_FETCH ) { + cs->exception_index =EXCP_PREFETCH_ABORT ; + }else { + cs->exception_index =EXCP_DATA_ABORT ; + } +cpu_loop_exit_restore (cs, retaddr); +#else +hwaddr phys_addr; +target_ulong page_size; +int prot, ret; +MemTxAttrs attrs = {}; +ARMMMUFaultInfo fi = {}; +
Quoted 8 lines
target/arm/helper.c uint32_t HELPER(v7m_tt)(CPUARMState *env, uint32_t addr, uint32_t op) · line 12380
Quoted 5 lines
target/arm/helper.c +5
-0+/* +* Walk the page table and (if the mapping exists) add the page +* to the TLB. Return false on success, or true on failure. Populate +* fsr with ARM DFSR/IFSR fault register format value on failure. +*/ This comment about what we return doesn't seem to match what the code is doing.
Other than fixing up the comment,
thanks
-- PMM
PATCH 5/26 target/cris: Convert to CPUClass::tlb_fill
In reply to Richard Henderson--- target/cris/cpu.h | 5 +-- target/cris/cpu.c | 5 ++- target/cris/helper.c | 67 +++++++++++++++++++++++------------------ target/cris/op_helper.c | 28 ----------------- 4 files changed, 42 insertions(+), 63 deletions(-)
target/cris/cpu.h +3 -2
@@ -282,8 +282,9 @@ static inline int cpu_mmu_index (CPUCRISState *env, bool ifetch)return !!(env->pregs[PR_CCS ] &U_FLAG ); } -int cris_cpu_handle_mmu_fault (CPUState *cpu,vaddr address,int size,int rw, -int mmu_idx); +bool cris_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);/* Support function regs. */ #define SFR_RW_GC_CFG 0][0
target/cris/cpu.c +2 -3
@@ -273,9 +273,8 @@ static void cris_cpu_class_init(ObjectClass *oc, void *data) cc->set_pc = cris_cpu_set_pc; cc->gdb_read_register = cris_cpu_gdb_read_register; cc->gdb_write_register = cris_cpu_gdb_write_register; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = cris_cpu_handle_mmu_fault; -#else + cc->tlb_fill = cris_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->get_phys_page_debug = cris_cpu_get_phys_page_debug; dc->vmsd = &vmstate_cris_cpu;#endif
target/cris/helper.c +37 -30
106 lines not on this page · raw message
target/cris/op_helper.c +0 -28
@@ -37,34 +37,6 @@#define D_LOG (...) do { } while (0)#endif -#if !defined(CONFIG_USER_ONLY ) -/* Try to fill the TLB and return an exception if error. If retaddr is -NULL, it means that the function was called in C code (i.e. not -from generated code or from helper.c) */ -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -CRISCPU *cpu =CRIS_CPU (cs); -CPUCRISState *env = &cpu->env; -int ret; - -D_LOG ("%s pc=%x tpc=%x ra=%p\n" , __func__, - env->pc, env->pregs[PR_EDA ], (void *)retaddr); - ret =cris_cpu_handle_mmu_fault (cs, addr, size, access_type, mmu_idx); -if (unlikely (ret)) { -if (retaddr) { -/* now we have a real cpu fault */ -if (cpu_restore_state (cs, retaddr, true)) { -/* Evaluate flags after retranslation. */ -helper_top_evaluate_flags (env); - } - } -cpu_loop_exit (cs); - } -} - -#endif -void helper_raise_exception (CPUCRISState *env,uint32_t index) {CPUState *cs =CPU (cris_env_get_cpu (env));
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 05/26] target/cris: Convert to CPUClass::tlb_fill
Quoted 13 lines · Richard Henderson
Cc Edgar E. Iglesias <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- target/cris/cpu.h | 5 +-- target/cris/cpu.c | 5 ++- target/cris/helper.c | 67 +++++++++++++++++++++++------------------ target/cris/op_helper.c | 28 ----------------- 4 files changed, 42 insertions(+), 63 deletions(-)target/cris/helper.c +1
-2-int cris_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int size,int rw, -int mmu_idx) +bool cris_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
target/cris/helper.c void crisv10_cpu_do_interrupt(CPUState *cs) · line 65
Quoted 10 lines
target/cris/helper.c +3
-2+ MMUAccessType access_type, int mmu_idx, + bool probe, uintptr_t retaddr) { CRISCPU *cpu = CRIS_CPU(cs); cs->exception_index =0xaa ; cpu->env.pregs[PR_EDA ] = address; -cpu_dump_state (cs, stderr, fprintf,0 ); -return 1 ; +cpu_loop_exit_restore (cs, retaddr);
You might mention in the commit message that we removed the cpu_dump_state().
target/cris/helper.c int cris_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int size, int rw, · line 120
Quoted 7 lines
target/cris/helper.c +7
-0+ env->pregs[PR_EDA ] = address; + cs->exception_index =EXCP_BUSFAULT ; + env->fault_vector = res.bf_vec; +if (retaddr) { +if (cpu_restore_state (cs, retaddr, true)) { +/* Evaluate flags after retranslation. */ +helper_top_evaluate_flags (env);
Side note because the old code does the same thing, but it seems weird that we have to manually recalculate the flags here -- I would expect cpu_restore_state() to actually restore the state (presumably by having restore_state_to_opc() do the fixing up of the flags?).
target/cris/helper.c int cris_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int size, int rw, · line 124
Quoted 4 lines
target/cris/helper.c +4
-0+ } + } +cpu_loop_exit (cs); +}
thanks
-- PMM
PATCH 6/26 target/hppa: Convert to CPUClass::tlb_fill
In reply to Richard Henderson--- target/hppa/cpu.h | 8 ++++---- target/hppa/cpu.c | 5 ++--- target/hppa/mem_helper.c | 22 +++++++++++++++++----- 3 files changed, 23 insertions(+), 12 deletions(-)
target/hppa/cpu.h +4 -4
@@ -360,10 +360,10 @@ int hppa_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);void hppa_cpu_do_interrupt (CPUState *cpu);bool hppa_cpu_exec_interrupt (CPUState *cpu,int int_req);void hppa_cpu_dump_state (CPUState *cs,FILE *f,fprintf_function ,int ); -#ifdef CONFIG_USER_ONLY -int hppa_cpu_handle_mmu_fault (CPUState *cpu,vaddr address,int size, -int rw,int midx); -#else +bool hppa_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr); +#ifndef CONFIG_USER_ONLY int hppa_get_physical_address (CPUHPPAState *env,vaddr addr,int mmu_idx,int type,hwaddr *pphys,int *pprot);extern const MemoryRegionOps hppa_io_eir_ops;
target/hppa/cpu.c +2 -3
@@ -167,9 +167,8 @@ static void hppa_cpu_class_init(ObjectClass *oc, void *data) cc->synchronize_from_tb = hppa_cpu_synchronize_from_tb; cc->gdb_read_register = hppa_cpu_gdb_read_register; cc->gdb_write_register = hppa_cpu_gdb_write_register; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = hppa_cpu_handle_mmu_fault; -#else + cc->tlb_fill = hppa_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->get_phys_page_debug = hppa_cpu_get_phys_page_debug; dc->vmsd = &vmstate_hppa_cpu;#endif
target/hppa/mem_helper.c +17 -5
@@ -25,8 +25,9 @@#include "trace.h" #ifdef CONFIG_USER_ONLY -int hppa_cpu_handle_mmu_fault (CPUState *cs,vaddr address, -int size,int rw,int mmu_idx) +bool hppa_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr) {HPPACPU *cpu =HPPA_CPU (cs);
@@ -34,7 +35,7 @@ int hppa_cpu_handle_mmu_fault(CPUState *cs, vaddr address,which would affect si_code. */ cs->exception_index =EXCP_DMP ; cpu->env.cr[CR_IOR ] = address; - return 1; + cpu_loop_exit_restore(cs, retaddr); }#else static hppa_tlb_entry *hppa_find_tlb (CPUHPPAState *env,vaddr addr)
@@ -214,8 +215,9 @@ hwaddr hppa_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)return excp ==EXCP_DTLB_MISS ?-1 : phys; } -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType type,int mmu_idx,uintptr_t retaddr) +bool hppa_cpu_tlb_fill (CPUState *cs,vaddr addr,int size, +MMUAccessType type,int mmu_idx, +bool probe,uintptr_t retaddr) {HPPACPU *cpu =HPPA_CPU (cs);CPUHPPAState *env = &cpu->env;
@@ -237,6 +239,9 @@ void tlb_fill(CPUState *cs, target_ulong addr, int size, excp =hppa_get_physical_address (env, addr, mmu_idx, a_prot, &phys, &prot);if (unlikely (excp >=0 )) { +if (probe) { +return false; + }trace_hppa_tlb_fill_excp (env, addr, size, type, mmu_idx);/* Failure. Raise the indicated exception. */ cs->exception_index = excp;
@@ -253,6 +258,13 @@ void tlb_fill(CPUState *cs, target_ulong addr, int size,/* Success! Store the translation into the QEMU TLB. */ tlb_set_page (cs, addr &TARGET_PAGE_MASK , phys &TARGET_PAGE_MASK , prot, mmu_idx,TARGET_PAGE_SIZE ); +return true; +} + +void tlb_fill (CPUState *cs,target_ulong addr,int size, +MMUAccessType type,int mmu_idx,uintptr_t retaddr) +{ +hppa_cpu_tlb_fill (cs, addr, size, type, mmu_idx, false, retaddr); }/* Insert (Insn/Data) TLB Address. Note this is PA 1.1 only. */
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 06/26] target/hppa: Convert to CPUClass::tlb_fill
Quoted 8 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/hppa/cpu.h | 8 ++++---- target/hppa/cpu.c | 5 ++--- target/hppa/mem_helper.c | 22 +++++++++++++++++----- 3 files changed, 23 insertions(+), 12 deletions(-)
thanks
-- PMM
Re: [Qemu-devel] [PATCH 06/26] target/hppa: Convert to CPUClass::tlb_fill
In reply to Richard HendersonQuoted 59 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/hppa/cpu.h | 8 ++++---- target/hppa/cpu.c | 5 ++--- target/hppa/mem_helper.c | 22 +++++++++++++++++----- 3 files changed, 23 insertions(+), 12 deletions(-)target/hppa/cpu.h +4
-4@@ -360,10 +360,10 @@ int hppa_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);void hppa_cpu_do_interrupt (CPUState *cpu);bool hppa_cpu_exec_interrupt (CPUState *cpu,int int_req);void hppa_cpu_dump_state (CPUState *cs,FILE *f,fprintf_function ,int ); -#ifdef CONFIG_USER_ONLY -int hppa_cpu_handle_mmu_fault (CPUState *cpu,vaddr address,int size, -int rw,int midx); -#else +bool hppa_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr); +#ifndef CONFIG_USER_ONLY int hppa_get_physical_address (CPUHPPAState *env,vaddr addr,int mmu_idx,int type,hwaddr *pphys,int *pprot);extern const MemoryRegionOps hppa_io_eir_ops;target/hppa/cpu.c +2
-3@@ -167,9 +167,8 @@ static void hppa_cpu_class_init(ObjectClass *oc, void *data) cc->synchronize_from_tb = hppa_cpu_synchronize_from_tb; cc->gdb_read_register = hppa_cpu_gdb_read_register; cc->gdb_write_register = hppa_cpu_gdb_write_register; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = hppa_cpu_handle_mmu_fault; -#else + cc->tlb_fill = hppa_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->get_phys_page_debug = hppa_cpu_get_phys_page_debug; dc->vmsd = &vmstate_hppa_cpu;#endif target/hppa/mem_helper.c +3
-2@@ -25,8 +25,9 @@#include "trace.h" #ifdef CONFIG_USER_ONLY -int hppa_cpu_handle_mmu_fault (CPUState *cs,vaddr address, -int size,int rw,int mmu_idx) +bool hppa_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr) {HPPACPU *cpu =HPPA_CPU (cs);
target/hppa/mem_helper.c int hppa_cpu_handle_mmu_fault(CPUState *cs, vaddr address, · line 38
Quoted 5 lines
target/hppa/mem_helper.c +1
-1@@ -34,7 +35,7 @@ int hppa_cpu_handle_mmu_fault(CPUState *cs, vaddr address,which would affect si_code. */ cs->exception_index =EXCP_DMP ; cpu->env.cr[CR_IOR ] = address; -return 1 ; +cpu_loop_exit_restore (cs, retaddr);
Quoted 40 lines
target/hppa/mem_helper.c +13
-2}#else static hppa_tlb_entry *hppa_find_tlb (CPUHPPAState *env,vaddr addr)@@ -214,8 +215,9 @@ hwaddr hppa_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)return excp ==EXCP_DTLB_MISS ?-1 : phys; } -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType type,int mmu_idx,uintptr_t retaddr) +bool hppa_cpu_tlb_fill (CPUState *cs,vaddr addr,int size, +MMUAccessType type,int mmu_idx, +bool probe,uintptr_t retaddr) {HPPACPU *cpu =HPPA_CPU (cs);CPUHPPAState *env = &cpu->env;@@ -237,6 +239,9 @@ void tlb_fill(CPUState *cs, target_ulong addr, int size, excp =hppa_get_physical_address (env, addr, mmu_idx, a_prot, &phys, &prot);if (unlikely (excp >=0 )) { +if (probe) { +return false; + }trace_hppa_tlb_fill_excp (env, addr, size, type, mmu_idx);/* Failure. Raise the indicated exception. */ cs->exception_index = excp;@@ -253,6 +258,13 @@ void tlb_fill(CPUState *cs, target_ulong addr, int size,/* Success! Store the translation into the QEMU TLB. */ tlb_set_page (cs, addr &TARGET_PAGE_MASK , phys &TARGET_PAGE_MASK , prot, mmu_idx,TARGET_PAGE_SIZE ); +return true; +} + +void tlb_fill (CPUState *cs,target_ulong addr,int size, +MMUAccessType type,int mmu_idx,uintptr_t retaddr) +{ +hppa_cpu_tlb_fill (cs, addr, size, type, mmu_idx, false, retaddr); }/* Insert (Insn/Data) TLB Address. Note this is PA 1.1 only. */
PATCH 7/26 target/i386: Convert to CPUClass::tlb_fill
In reply to Richard HendersonWe do not support probing, but we do not need it yet either.
--- target/i386/cpu.h | 5 ++-- target/i386/cpu.c | 5 ++-- target/i386/excp_helper.c | 61 +++++++++++++++++++++++++-------------- target/i386/mem_helper.c | 21 -------------- 4 files changed, 44 insertions(+), 48 deletions(-)
target/i386/cpu.h +3 -2
@@ -1655,8 +1655,9 @@ void host_cpuid(uint32_t function, uint32_t count,void host_vendor_fms (char *vendor,int *family,int *model,int *stepping);/* helper.c */ -int x86_cpu_handle_mmu_fault (CPUState *cpu,vaddr addr,int size, -int is_write,int mmu_idx); +bool x86_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);void x86_cpu_set_a20 (X86CPU *cpu,int a20_state);#ifndef CONFIG_USER_ONLY
target/i386/cpu.c +2 -3
@@ -5866,9 +5866,8 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data) cc->gdb_write_register = x86_cpu_gdb_write_register; cc->get_arch_id = x86_cpu_get_arch_id; cc->get_paging_enabled = x86_cpu_get_paging_enabled; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = x86_cpu_handle_mmu_fault; -#else + cc->tlb_fill = x86_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->asidx_from_attrs = x86_asidx_from_attrs; cc->get_memory_mapping = x86_cpu_get_memory_mapping; cc->get_phys_page_debug = x86_cpu_get_phys_page_debug;
target/i386/excp_helper.c +39 -22
76 lines not on this page · raw message
target/i386/mem_helper.c +0 -21
@@ -191,24 +191,3 @@ void helper_boundl(CPUX86State *env, target_ulong a0, int v)raise_exception_ra (env,EXCP05_BOUND ,GETPC ()); } } - -#if !defined(CONFIG_USER_ONLY ) -/* try to fill the TLB and return an exception if error. If retaddr is -* NULL, it means that the function was called in C code (i.e. not -* from generated code or from helper.c) -*/ -/* XXX: fix it to restore all registers */ -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -X86CPU *cpu =X86_CPU (cs); -CPUX86State *env = &cpu->env; -int ret; - - env->retaddr = retaddr; - ret =x86_cpu_handle_mmu_fault (cs, addr, size, access_type, mmu_idx); -if (ret) { -raise_exception_err_ra (env, cs->exception_index, env->error_code, retaddr); - } -} -#endif
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 07/26] target/i386: Convert to CPUClass::tlb_fill
target/i386/excp_helper.c do_check_protect_pse36: · line 695
Quoted 11 lines · Richard Henderson
We do not support probing, but we do not need it yet either.
Cc Paolo Bonzini <[email protected]>Cc Eduardo Habkost <[email protected]>Signed-off-by Richard Henderson <[email protected]>target/i386/excp_helper.c +3
-0+ env->retaddr = retaddr; +if (handle_mmu_fault (cs, addr, size, access_type, mmu_idx)) { +/* FIXME: On error in get_hphys we have already jumpped out. */
"jumped"
Quoted 5 lines
target/i386/excp_helper.c +1
-0+g_assert (!probe);
target/i386/mem_helper.c void helper_boundl(CPUX86State *env, target_ulong a0, int v) · line 200
Quoted 10 lines
target/i386/mem_helper.c +0
-7@@ -191,24 +191,3 @@ void helper_boundl(CPUX86State *env, target_ulong a0, int v)raise_exception_ra (env,EXCP05_BOUND ,GETPC ()); } } - -#if !defined(CONFIG_USER_ONLY ) -/* try to fill the TLB and return an exception if error. If retaddr is -* NULL, it means that the function was called in C code (i.e. not -* from generated code or from helper.c) -*/ -/* XXX: fix it to restore all registers */
Is this XXX comment definitely stale ?
target/i386/mem_helper.c void helper_boundl(CPUX86State *env, target_ulong a0, int v) · line 213
Quoted 13 lines
target/i386/mem_helper.c +0
-13-void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -X86CPU *cpu =X86_CPU (cs); -CPUX86State *env = &cpu->env; -int ret; - - env->retaddr = retaddr; - ret =x86_cpu_handle_mmu_fault (cs, addr, size, access_type, mmu_idx); -if (ret) { -raise_exception_err_ra (env, cs->exception_index, env->error_code, retaddr); - } -}
Otherwise
thanks
-- PMM
Re: [Qemu-devel] [PATCH 07/26] target/i386: Convert to CPUClass::tlb_fill
Quoted 7 lines · Peter Maydell
Quoted 7 lines
target/i386/mem_helper.c +0
-1@@ -191,24 +191,3 @@ void helper_boundl(CPUX86State *env, target_ulong a0, int v)raise_exception_ra (env,EXCP05_BOUND ,GETPC ()); } } -
Quoted 8 lines
target/i386/mem_helper.c void helper_boundl(CPUX86State *env, target_ulong a0, int v) · line 200
Quoted 6 lines
target/i386/mem_helper.c +0
-6-#if !defined(CONFIG_USER_ONLY ) -/* try to fill the TLB and return an exception if error. If retaddr is -* NULL, it means that the function was called in C code (i.e. not -* from generated code or from helper.c) -*/ -/* XXX: fix it to restore all registers */ Is this XXX comment definitely stale ?
This is a pre-TCG comment, from 61382a500a9 ("full softmmu support"), from 2003. It has only been moved around since. I can only imagine what problem Fabrice might have been reminding himself.
r~
PATCH 8/26 target/lm32: Convert to CPUClass::tlb_fill
In reply to Richard Henderson--- target/lm32/cpu.h | 5 +++-- target/lm32/cpu.c | 5 ++--- target/lm32/helper.c | 12 +++++++++--- target/lm32/op_helper.c | 16 ---------------- 4 files changed, 14 insertions(+), 24 deletions(-)
target/lm32/cpu.h +3 -2
@@ -262,8 +262,9 @@ bool lm32_cpu_do_semihosting(CPUState *cs);#define cpu_list lm32_cpu_list#define cpu_signal_handler cpu_lm32_signal_handler -int lm32_cpu_handle_mmu_fault (CPUState *cpu,vaddr address,int size,int rw, -int mmu_idx); +bool lm32_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);#include "exec/cpu-all.h"
target/lm32/cpu.c +2 -3
@@ -235,9 +235,8 @@ static void lm32_cpu_class_init(ObjectClass *oc, void *data) cc->set_pc = lm32_cpu_set_pc; cc->gdb_read_register = lm32_cpu_gdb_read_register; cc->gdb_write_register = lm32_cpu_gdb_write_register; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = lm32_cpu_handle_mmu_fault; -#else + cc->tlb_fill = lm32_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->get_phys_page_debug = lm32_cpu_get_phys_page_debug; cc->vmsd = &vmstate_lm32_cpu;#endif
target/lm32/helper.c +9 -3
@@ -25,8 +25,9 @@#include "exec/semihost.h" #include "exec/log.h" -int lm32_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int size,int rw, -int mmu_idx) +bool lm32_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr) {LM32CPU *cpu =LM32_CPU (cs);CPULM32State *env = &cpu->env;
@@ -40,8 +41,13 @@ int lm32_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int size, int rw, }else {tlb_set_page (cs, address, address, prot, mmu_idx,TARGET_PAGE_SIZE ); } +return true; +} -return 0 ; +void tlb_fill (CPUState *cs,target_ulong addr,int size, +MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) +{ +lm32_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); }hwaddr lm32_cpu_get_phys_page_debug (CPUState *cs,vaddr addr)
target/lm32/op_helper.c +0 -16
@@ -143,21 +143,5 @@ uint32_t HELPER(rcsr_jrx)(CPULM32State *env) {return lm32_juart_get_jrx (env->juart_state); } - -/* Try to fill the TLB and return an exception if error. If retaddr is -* NULL, it means that the function was called in C code (i.e. not -* from generated code or from helper.c) -*/ -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -int ret; - - ret =lm32_cpu_handle_mmu_fault (cs, addr, size, access_type, mmu_idx); -if (unlikely (ret)) { -/* now we have a real cpu fault */ -cpu_loop_exit_restore (cs, retaddr); - } -}#endif
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 08/26] target/lm32: Convert to CPUClass::tlb_fill
Quoted 3 lines · Richard Henderson
Cc Michael Walle <[email protected]>Signed-off-by Richard Henderson <[email protected]>
thanks
-- PMM
PATCH 9/26 target/m68k: Convert to CPUClass::tlb_fill
In reply to Richard Henderson--- target/m68k/cpu.h | 5 ++- target/m68k/cpu.c | 2 +- target/m68k/helper.c | 87 ++++++++++++++++++++++------------------- target/m68k/op_helper.c | 15 ------- 4 files changed, 50 insertions(+), 59 deletions(-)
target/m68k/cpu.h +3 -2
@@ -543,8 +543,9 @@ static inline int cpu_mmu_index (CPUM68KState *env, bool ifetch)return (env->sr &SR_S ) ==0 ?1 :0 ; } -int m68k_cpu_handle_mmu_fault (CPUState *cpu,vaddr address,int size,int rw, -int mmu_idx); +bool m68k_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);void m68k_cpu_unassigned_access (CPUState *cs,hwaddr addr,bool is_write,bool is_exec,int is_asi,unsigned size);
target/m68k/cpu.c +1 -1
@@ -269,7 +269,7 @@ static void m68k_cpu_class_init(ObjectClass *c, void *data) cc->set_pc = m68k_cpu_set_pc; cc->gdb_read_register = m68k_cpu_gdb_read_register; cc->gdb_write_register = m68k_cpu_gdb_write_register; - cc->handle_mmu_fault = m68k_cpu_handle_mmu_fault; + cc->tlb_fill = m68k_cpu_tlb_fill;#if defined(CONFIG_SOFTMMU ) cc->do_unassigned_access = m68k_cpu_unassigned_access; cc->get_phys_page_debug = m68k_cpu_get_phys_page_debug;
target/m68k/helper.c +46 -41
138 lines not on this page · raw message
target/m68k/op_helper.c +0 -15
@@ -36,21 +36,6 @@ static inline void do_interrupt_m68k_hardirq(CPUM68KState *env)#else -/* Try to fill the TLB and return an exception if error. If retaddr is -NULL, it means that the function was called in C code (i.e. not -from generated code or from helper.c) */ -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -int ret; - - ret =m68k_cpu_handle_mmu_fault (cs, addr, size, access_type, mmu_idx); -if (unlikely (ret)) { -/* now we have a real cpu fault */ -cpu_loop_exit_restore (cs, retaddr); - } -} -static void cf_rte (CPUM68KState *env) {uint32_t sp;
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 09/26] target/m68k: Convert to CPUClass::tlb_fill
Quoted 12 lines · Richard Henderson
Cc Laurent Vivier <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- target/m68k/cpu.h | 5 ++- target/m68k/cpu.c | 2 +- target/m68k/helper.c | 87 ++++++++++++++++++++++------------------- target/m68k/op_helper.c | 15 ------- 4 files changed, 50 insertions(+), 59 deletions(-)target/m68k/helper.c +0
-0@@ -804,11 +791,36 @@ hwaddr m68k_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)return phys_addr;
target/m68k/helper.c hwaddr m68k_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) · line 799
Quoted 10 lines
target/m68k/helper.c +6
-2} -int m68k_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int size,int rw, -int mmu_idx) +/* +* Notify CPU of a pending interrupt. Prioritization and vectoring should +* be handled by the interrupt controller. Real hardware only requests +* the vector when the interrupt is acknowledged by the CPU. For +* simplicitly we calculate it when the interrupt is signalled. +*/
I know this is just code motion, but perhaps we could fix the typo in passing ("simplicity").
In any case
thanks
-- PMM
PATCH 10/26 target/microblaze: Convert to CPUClass::tlb_fill
In reply to Richard Henderson--- target/microblaze/cpu.h | 5 +- target/microblaze/cpu.c | 5 +- target/microblaze/helper.c | 142 +++++++++++++++++----------------- target/microblaze/op_helper.c | 19 ----- 4 files changed, 78 insertions(+), 93 deletions(-)
target/microblaze/cpu.h +3 -2
@@ -375,8 +375,9 @@ static inline int cpu_mmu_index (CPUMBState *env, bool ifetch)return MMU_KERNEL_IDX ; } -int mb_cpu_handle_mmu_fault (CPUState *cpu,vaddr address,int size,int rw, -int mmu_idx); +bool mb_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);#include "exec/cpu-all.h"
target/microblaze/cpu.c +2 -3
@@ -304,9 +304,8 @@ static void mb_cpu_class_init(ObjectClass *oc, void *data) cc->set_pc = mb_cpu_set_pc; cc->gdb_read_register = mb_cpu_gdb_read_register; cc->gdb_write_register = mb_cpu_gdb_write_register; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = mb_cpu_handle_mmu_fault; -#else + cc->tlb_fill = mb_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->do_transaction_failed = mb_cpu_transaction_failed; cc->get_phys_page_debug = mb_cpu_get_phys_page_debug;#endif
target/microblaze/helper.c +73 -69
154 lines not on this page · raw message
target/microblaze/op_helper.c +0 -19
@@ -28,25 +28,6 @@#define D (x) -#if !defined(CONFIG_USER_ONLY ) - -/* Try to fill the TLB and return an exception if error. If retaddr is -* NULL, it means that the function was called in C code (i.e. not -* from generated code or from helper.c) -*/ -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -int ret; - - ret =mb_cpu_handle_mmu_fault (cs, addr, size, access_type, mmu_idx); -if (unlikely (ret)) { -/* now we have a real cpu fault */ -cpu_loop_exit_restore (cs, retaddr); - } -} -#endif -void helper_put (uint32_t id,uint32_t ctrl,uint32_t data) {int test = ctrl &STREAM_TEST ;
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 10/26] target/microblaze: Convert to CPUClass::tlb_fill
Quoted 70 lines · Richard Henderson
Cc Edgar E. Iglesias <[email protected]>Signed-off-by Richard Henderson <[email protected]>target/microblaze/helper.c +62
-1-#if defined(CONFIG_USER_ONLY ) +bool mb_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr) +{ +MicroBlazeCPU *cpu =MICROBLAZE_CPU (cs); +CPUMBState *env = &cpu->env; + +#ifndef CONFIG_USER_ONLY +uint32_t vaddr, paddr; +struct microblaze_mmu_lookup lu; +unsigned int hit; +int prot; + +if (mmu_idx ==MMU_NOMMU_IDX ) { +/* MMU disabled or not available. */ + address &=TARGET_PAGE_MASK ; + prot =PAGE_BITS ; +tlb_set_page (cs, address, address, prot, mmu_idx,TARGET_PAGE_SIZE ); +return true; + } + + hit =mmu_translate (&env->mmu, &lu, address, access_type, mmu_idx); +if (likely (hit)) { + vaddr = address &TARGET_PAGE_MASK ; + paddr = lu.paddr + vaddr - lu.vaddr; + +qemu_log_mask (CPU_LOG_MMU ,"MMU map mmu=%d v=%x p=%x prot=%x\n" , + mmu_idx, vaddr, paddr, lu.prot); +tlb_set_page (cs, vaddr, paddr, lu.prot, mmu_idx,TARGET_PAGE_SIZE ); +return true; + } + +/* TLB miss. */ +if (probe) { +return false; + } + +qemu_log_mask (CPU_LOG_MMU ,"mmu=%d miss v=%" VADDR_PRIx"\n" , + mmu_idx, address); + +switch (lu.err) { +case ERR_PROT : + env->sregs[SR_ESR ] = access_type ==MMU_INST_FETCH ?17 :16 ; + env->sregs[SR_ESR ] |= (access_type ==MMU_DATA_STORE ) <<10 ; +break ; +case ERR_MISS : + env->sregs[SR_ESR ] = access_type ==MMU_INST_FETCH ?19 :18 ; + env->sregs[SR_ESR ] |= (access_type ==MMU_DATA_STORE ) <<10 ; +break ; +default : +g_assert_not_reached (); + } + +if (cs->exception_index ==EXCP_MMU ) { +cpu_abort (cs,"recursive faults\n" ); + } +#endif + + env->sregs[SR_EAR ] = address; + cs->exception_index =EXCP_MMU ; +cpu_loop_exit_restore (cs, retaddr); +}
target/microblaze/helper.c
Quoted 10 lines
target/microblaze/helper.c +0
-9-int mb_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int size,int rw, -int mmu_idx) -{ - cs->exception_index =0xaa ; -cpu_dump_state (cs, stderr, fprintf,0 ); -return 1 ; -} - -#else /* !CONFIG_USER_ONLY */
For the user-mode case we used to set cs->exception_state to 0xaa, but now we set it to EXCP_MMU. We also set SR_EAR which we didn't previously.
Otherwise the refactoring looks ok.
thanks
-- PMM
PATCH 11/26 target/mips: Convert to CPUClass::tlb_fill
In reply to Richard HendersonNote that env->active_tc.PC is removed from the qemu_log as that value is garbage. The PC isn't recovered until cpu_restore_state, called from cpu_loop_exit_restore, called from do_raise_exception_err.
--- target/mips/internal.h | 5 +- target/mips/cpu.c | 5 +- target/mips/helper.c | 115 +++++++++++++++++++--------------------- target/mips/op_helper.c | 15 ------ 4 files changed, 61 insertions(+), 79 deletions(-)
target/mips/internal.h +3 -2
@@ -203,8 +203,9 @@ void cpu_mips_start_count(CPUMIPSState *env);void cpu_mips_stop_count (CPUMIPSState *env);/* helper.c */ -int mips_cpu_handle_mmu_fault (CPUState *cpu,vaddr address,int size,int rw, -int mmu_idx); +bool mips_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);/* op_helper.c */ uint32_t float_class_s (uint32_t arg,float_status *fst);
target/mips/cpu.c +2 -3
@@ -197,9 +197,8 @@ static void mips_cpu_class_init(ObjectClass *c, void *data) cc->synchronize_from_tb = mips_cpu_synchronize_from_tb; cc->gdb_read_register = mips_cpu_gdb_read_register; cc->gdb_write_register = mips_cpu_gdb_write_register; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = mips_cpu_handle_mmu_fault; -#else + cc->tlb_fill = mips_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->do_unassigned_access = mips_cpu_unassigned_access; cc->do_unaligned_access = mips_cpu_do_unaligned_access; cc->get_phys_page_debug = mips_cpu_get_phys_page_debug;
target/mips/helper.c +56 -59
141 lines not on this page · raw message
target/mips/op_helper.c +0 -15
@@ -2669,21 +2669,6 @@ void mips_cpu_do_unaligned_access(CPUState *cs, vaddr addr,do_raise_exception_err (env, excp, error_code, retaddr); } -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -int ret; - - ret =mips_cpu_handle_mmu_fault (cs, addr, size, access_type, mmu_idx); -if (ret) { -MIPSCPU *cpu =MIPS_CPU (cs); -CPUMIPSState *env = &cpu->env; - -do_raise_exception_err (env, cs->exception_index, - env->error_code, retaddr); - } -} -void mips_cpu_unassigned_access (CPUState *cs,hwaddr addr,bool is_write,bool is_exec,int unused,unsigned size)
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 11/26] target/mips: Convert to CPUClass::tlb_fill
Quoted 136 lines · Richard Henderson
Note that
env->active_tc.PCis removed from theqemu_logas that value is garbage. The PC isn't recovered untilcpu_restore_state, called fromcpu_loop_exit_restore, called fromdo_raise_exception_err.Cc Aleksandar Markovic <[email protected]>Cc Aleksandar Rikalo <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- target/mips/internal.h | 5 +- target/mips/cpu.c | 5 +- target/mips/helper.c | 115 +++++++++++++++++++--------------------- target/mips/op_helper.c | 15 ------ 4 files changed, 61 insertions(+), 79 deletions(-)target/mips/internal.h +3
-2@@ -203,8 +203,9 @@ void cpu_mips_start_count(CPUMIPSState *env);void cpu_mips_stop_count (CPUMIPSState *env);/* helper.c */ -int mips_cpu_handle_mmu_fault (CPUState *cpu,vaddr address,int size,int rw, -int mmu_idx); +bool mips_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);/* op_helper.c */ uint32_t float_class_s (uint32_t arg,float_status *fst);target/mips/cpu.c +2
-3@@ -197,9 +197,8 @@ static void mips_cpu_class_init(ObjectClass *c, void *data) cc->synchronize_from_tb = mips_cpu_synchronize_from_tb; cc->gdb_read_register = mips_cpu_gdb_read_register; cc->gdb_write_register = mips_cpu_gdb_write_register; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = mips_cpu_handle_mmu_fault; -#else + cc->tlb_fill = mips_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->do_unassigned_access = mips_cpu_unassigned_access; cc->do_unaligned_access = mips_cpu_do_unaligned_access; cc->get_phys_page_debug = mips_cpu_get_phys_page_debug;target/mips/helper.c +12
-53@@ -874,85 +874,82 @@ refill:#endif #endif -int mips_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int size,int rw, -int mmu_idx) +bool mips_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr) {MIPSCPU *cpu =MIPS_CPU (cs);CPUMIPSState *env = &cpu->env; -#if !defined(CONFIG_USER_ONLY ) +int ret =TLBRET_NOMATCH ; + +#ifndef CONFIG_USER_ONLY hwaddr physical;int prot; -int access_type; -#endif -int ret =0 ; +int mips_access_type =ACCESS_INT ; -#if 0 -log_cpu_state (cs,0 ); -#endif qemu_log_mask (CPU_LOG_MMU , -"%s pc " TARGET_FMT_lx" ad %" VADDR_PRIx" rw %d mmu_idx %d\n" , - __func__, env->active_tc.PC, address, rw, mmu_idx); +"%s ad %" VADDR_PRIx" rw %d mmu_idx %d\n" , + __func__, address, access_type, mmu_idx);/* data access */ -#if !defined(CONFIG_USER_ONLY )/* XXX: put correct access by using cpu_restore_state() correctly */ - access_type =ACCESS_INT ; - ret =get_physical_address (env, &physical, &prot, - address, rw, access_type, mmu_idx); -switch (ret) { -case TLBRET_MATCH : + ret =get_physical_address (env, &physical, &prot, address, + access_type, mips_access_type, mmu_idx); +if (ret ==TLBRET_MATCH ) {qemu_log_mask (CPU_LOG_MMU ,"%s address=%" VADDR_PRIx" physical " TARGET_FMT_plx" prot %d\n" , __func__, address, physical, prot); -break ; -default : -qemu_log_mask (CPU_LOG_MMU , -"%s address=%" VADDR_PRIx" ret %d\n" , __func__, address, - ret); -break ; - } -if (ret ==TLBRET_MATCH ) {tlb_set_page (cs, address &TARGET_PAGE_MASK , physical &TARGET_PAGE_MASK , prot |PAGE_EXEC , mmu_idx,TARGET_PAGE_SIZE ); - ret =0 ; - } else if (ret < 0) -#endif - { -#if !defined(CONFIG_USER_ONLY ) -#if !defined(TARGET_MIPS64 ) -if ((ret ==TLBRET_NOMATCH ) && (env->tlb->nb_tlb >1 )) { -/* -* Memory reads during hardware page table walking are performed -* as if they were kernel-mode load instructions. -*/ -int mode = (env->hflags &MIPS_HFLAG_KSU ); -bool ret_walker; - env->hflags &= ~MIPS_HFLAG_KSU ; - ret_walker =page_table_walk_refill (env, address, rw, mmu_idx); - env->hflags |= mode; -if (ret_walker) { - ret =get_physical_address (env, &physical, &prot, - address, rw, access_type, mmu_idx); -if (ret ==TLBRET_MATCH ) { -tlb_set_page (cs, address &TARGET_PAGE_MASK , - physical &TARGET_PAGE_MASK , prot |PAGE_EXEC , - mmu_idx,TARGET_PAGE_SIZE ); - ret =0 ; -return ret; - } - } - }
target/mips/helper.c refill: · line 909
Quoted 10 lines
target/mips/helper.c +3
-5-#endif -#endif -raise_mmu_exception (env, address, rw, ret); - ret =1 ; +return true; } -return ret; +qemu_log_mask (CPU_LOG_MMU ,"%s address=%" VADDR_PRIx" ret %d\n" , + __func__, address, ret);
I think this patch is right, but it was too awkward to review because it's got a bunch of other changes mixed up with the refactoring. For instance the old code has a fairly straightforward "switch (ret) { ... }" where it does a qemu_log_mask() either for the TLBRET_MATCH case or for the failure case, whereas I think this code now prints the failure case logging of 'ret' in both cases. If you want to change the logging can you do that as a separate patch so that the refactor patch is a no-behaviour-change one ?
thanks
-- PMM
Re: [Qemu-devel] [PATCH 11/26] target/mips: Convert to CPUClass::tlb_fill
In reply to Richard HendersonQuoted 7 lines · Richard Henderson
Note that
env->active_tc.PCis removed from theqemu_logas that value is garbage. The PC isn't recovered untilcpu_restore_state, called fromcpu_loop_exit_restore, called fromdo_raise_exception_err.Cc Aleksandar Markovic <[email protected]>Cc Aleksandar Rikalo <[email protected]>Signed-off-by Richard Henderson <[email protected]>
Quoted 212 lines
--- target/mips/internal.h | 5 +- target/mips/cpu.c | 5 +- target/mips/helper.c | 115 +++++++++++++++++++--------------------- target/mips/op_helper.c | 15 ------ 4 files changed, 61 insertions(+), 79 deletions(-)target/mips/internal.h +3
-2@@ -203,8 +203,9 @@ void cpu_mips_start_count(CPUMIPSState *env);void cpu_mips_stop_count (CPUMIPSState *env);/* helper.c */ -int mips_cpu_handle_mmu_fault (CPUState *cpu,vaddr address,int size,int rw, -int mmu_idx); +bool mips_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);/* op_helper.c */ uint32_t float_class_s (uint32_t arg,float_status *fst);target/mips/cpu.c +2
-3@@ -197,9 +197,8 @@ static void mips_cpu_class_init(ObjectClass *c, void *data) cc->synchronize_from_tb = mips_cpu_synchronize_from_tb; cc->gdb_read_register = mips_cpu_gdb_read_register; cc->gdb_write_register = mips_cpu_gdb_write_register; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = mips_cpu_handle_mmu_fault; -#else + cc->tlb_fill = mips_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->do_unassigned_access = mips_cpu_unassigned_access; cc->do_unaligned_access = mips_cpu_do_unaligned_access; cc->get_phys_page_debug = mips_cpu_get_phys_page_debug;target/mips/helper.c +56
-59@@ -874,85 +874,82 @@ refill:#endif #endif -int mips_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int size,int rw, -int mmu_idx) +bool mips_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr) {MIPSCPU *cpu =MIPS_CPU (cs);CPUMIPSState *env = &cpu->env; -#if !defined(CONFIG_USER_ONLY ) +int ret =TLBRET_NOMATCH ; + +#ifndef CONFIG_USER_ONLY hwaddr physical;int prot; -int access_type; -#endif -int ret =0 ; +int mips_access_type =ACCESS_INT ; -#if 0 -log_cpu_state (cs,0 ); -#endif qemu_log_mask (CPU_LOG_MMU , -"%s pc " TARGET_FMT_lx" ad %" VADDR_PRIx" rw %d mmu_idx %d\n" , - __func__, env->active_tc.PC, address, rw, mmu_idx); +"%s ad %" VADDR_PRIx" rw %d mmu_idx %d\n" , + __func__, address, access_type, mmu_idx);/* data access */ -#if !defined(CONFIG_USER_ONLY )/* XXX: put correct access by using cpu_restore_state() correctly */ - access_type =ACCESS_INT ; - ret =get_physical_address (env, &physical, &prot, - address, rw, access_type, mmu_idx); -switch (ret) { -case TLBRET_MATCH : + ret =get_physical_address (env, &physical, &prot, address, + access_type, mips_access_type, mmu_idx); +if (ret ==TLBRET_MATCH ) {qemu_log_mask (CPU_LOG_MMU ,"%s address=%" VADDR_PRIx" physical " TARGET_FMT_plx" prot %d\n" , __func__, address, physical, prot); -break ; -default : -qemu_log_mask (CPU_LOG_MMU , -"%s address=%" VADDR_PRIx" ret %d\n" , __func__, address, - ret); -break ; - } -if (ret ==TLBRET_MATCH ) {tlb_set_page (cs, address &TARGET_PAGE_MASK , physical &TARGET_PAGE_MASK , prot |PAGE_EXEC , mmu_idx,TARGET_PAGE_SIZE ); - ret =0 ; - } else if (ret < 0) -#endif - { -#if !defined(CONFIG_USER_ONLY ) -#if !defined(TARGET_MIPS64 ) -if ((ret ==TLBRET_NOMATCH ) && (env->tlb->nb_tlb >1 )) { -/* -* Memory reads during hardware page table walking are performed -* as if they were kernel-mode load instructions. -*/ -int mode = (env->hflags &MIPS_HFLAG_KSU ); -bool ret_walker; - env->hflags &= ~MIPS_HFLAG_KSU ; - ret_walker =page_table_walk_refill (env, address, rw, mmu_idx); - env->hflags |= mode; -if (ret_walker) { - ret =get_physical_address (env, &physical, &prot, - address, rw, access_type, mmu_idx); -if (ret ==TLBRET_MATCH ) { -tlb_set_page (cs, address &TARGET_PAGE_MASK , - physical &TARGET_PAGE_MASK , prot |PAGE_EXEC , - mmu_idx,TARGET_PAGE_SIZE ); - ret =0 ; -return ret; - } - } - } -#endif -#endif -raise_mmu_exception (env, address, rw, ret); - ret =1 ; +return true; } -return ret; +qemu_log_mask (CPU_LOG_MMU ,"%s address=%" VADDR_PRIx" ret %d\n" , + __func__, address, ret); + +#ifndef TARGET_MIPS64 +if ((ret ==TLBRET_NOMATCH ) && (env->tlb->nb_tlb >1 )) { +/* +* Memory reads during hardware page table walking are performed +* as if they were kernel-mode load instructions. +*/ +int mode = (env->hflags &MIPS_HFLAG_KSU ); +bool ret_walker; + + env->hflags &= ~MIPS_HFLAG_KSU ; + ret_walker =page_table_walk_refill (env, address, access_type, mmu_idx); + env->hflags |= mode; + +if (ret_walker) { + ret =get_physical_address (env, &physical, &prot, address, + access_type, mips_access_type, mmu_idx); +if (ret ==TLBRET_MATCH ) { +tlb_set_page (cs, address &TARGET_PAGE_MASK , + physical &TARGET_PAGE_MASK , prot |PAGE_EXEC , + mmu_idx,TARGET_PAGE_SIZE ); +return true; + } + } + } +#endif + +if (probe) { +return false; + } +#endif /* !CONFIG_USER_ONLY */ + +raise_mmu_exception (env, address, access_type, ret); +do_raise_exception_err (env, cs->exception_index, env->error_code, retaddr); +} + +#ifndef CONFIG_USER_ONLY +void tlb_fill (CPUState *cs,target_ulong addr,int size, +MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) +{ +mips_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); } -#if !defined(CONFIG_USER_ONLY )hwaddr cpu_mips_translate_address (CPUMIPSState *env,target_ulong address,int rw) {hwaddr physical;target/mips/op_helper.c +0
-15@@ -2669,21 +2669,6 @@ void mips_cpu_do_unaligned_access(CPUState *cs, vaddr addr,do_raise_exception_err (env, excp, error_code, retaddr); } -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -int ret; - - ret =mips_cpu_handle_mmu_fault (cs, addr, size, access_type, mmu_idx); -if (ret) { -MIPSCPU *cpu =MIPS_CPU (cs); -CPUMIPSState *env = &cpu->env; - -do_raise_exception_err (env, cs->exception_index, - env->error_code, retaddr); - } -} -void mips_cpu_unassigned_access (CPUState *cs,hwaddr addr,bool is_write,bool is_exec,int unused,unsigned size)
PATCH 12/26 target/moxie: Convert to CPUClass::tlb_fill
In reply to Richard Henderson--- target/moxie/cpu.h | 5 ++-- target/moxie/cpu.c | 5 ++-- target/moxie/helper.c | 61 ++++++++++--------------------------------- 3 files changed, 19 insertions(+), 52 deletions(-)
target/moxie/cpu.h +3 -2
@@ -140,7 +140,8 @@ static inline void cpu_get_tb_cpu_state(CPUMoxieState *env, target_ulong *pc, *flags = 0; } -int moxie_cpu_handle_mmu_fault (CPUState *cpu,vaddr address,int size, -int rw,int mmu_idx); +bool moxie_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);#endif /* MOXIE_CPU_H */
target/moxie/cpu.c +2 -3
@@ -112,9 +112,8 @@ static void moxie_cpu_class_init(ObjectClass *oc, void *data) cc->do_interrupt = moxie_cpu_do_interrupt; cc->dump_state = moxie_cpu_dump_state; cc->set_pc = moxie_cpu_set_pc; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = moxie_cpu_handle_mmu_fault; -#else + cc->tlb_fill = moxie_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->get_phys_page_debug = moxie_cpu_get_phys_page_debug; cc->vmsd = &vmstate_moxie_cpu;#endif
target/moxie/helper.c +14 -47
89 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 12/26] target/moxie: Convert to CPUClass::tlb_fill
Quoted 15 lines · Richard Henderson
Cc Anthony Green <[email protected]>Signed-off-by Richard Henderson <[email protected]>---
target/moxie/helper.c +0
-9-#if defined(CONFIG_USER_ONLY ) - -void moxie_cpu_do_interrupt (CPUState *cs) -{ -CPUState *cs =CPU (moxie_env_get_cpu (env)); - - cs->exception_index =-1 ; -} -
target/moxie/helper.c void helper_debug(CPUMoxieState *env) · line 106
Quoted 10 lines
target/moxie/helper.c +0
-10-int moxie_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int size, -int rw,int mmu_idx) -{ -MoxieCPU *cpu =MOXIE_CPU (cs); - - cs->exception_index =0xaa ; - cpu->env.debug1 = address; -cpu_dump_state (cs, stderr, fprintf,0 ); -return 1 ; -}
The commit message should say that we can just delete the old user-only code because we don't have a moxie-linux-user config.
Quoted 31 lines
target/moxie/helper.c +8
-15- -#else /* !CONFIG_USER_ONLY */ - -int moxie_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int size, -int rw,int mmu_idx) +bool moxie_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr) {MoxieCPU *cpu =MOXIE_CPU (cs);CPUMoxieState *env = &cpu->env;MoxieMMUResult res;int prot, miss; -target_ulong phy; -int r =1 ; address &=TARGET_PAGE_MASK ; prot =PAGE_READ |PAGE_WRITE |PAGE_EXEC ; - miss =moxie_mmu_translate (&res, env, address, rw, mmu_idx); -if (miss) { -/* handle the miss. */ - phy =0 ; - cs->exception_index =MOXIE_EX_MMU_MISS ; - }else { - phy = res.phy; - r =0 ; + miss =moxie_mmu_translate (&res, env, address, access_type, mmu_idx); +if (likely (!miss)) { +tlb_set_page (cs, address, res.phy, prot, mmu_idx,TARGET_PAGE_SIZE ); +return true; + }
target/moxie/helper.c void helper_debug(CPUMoxieState *env) · line 102
Quoted 10 lines
target/moxie/helper.c +5
-3+if (probe) { +return false; } -tlb_set_page (cs, address, phy, prot, mmu_idx,TARGET_PAGE_SIZE ); -return r; -} + cs->exception_index =MOXIE_EX_MMU_MISS ; +cpu_loop_exit_restore (cs, retaddr); +}
The old code was calling tlb_set_page() even on an MMU miss, and the new could doesn't do that. This looks like it was a bug to me, but if we're fixing bugs we should mention them in the commit message, at least.
Otherwise
thanks
-- PMM
PATCH 13/26 target/nios2: Convert to CPUClass::tlb_fill
In reply to Richard Henderson--- target/nios2/cpu.h | 5 +- target/nios2/cpu.c | 5 +- target/nios2/helper.c | 181 ++++++++++++++++++++---------------------- target/nios2/mmu.c | 12 --- 4 files changed, 92 insertions(+), 111 deletions(-)
target/nios2/cpu.h +3 -2
@@ -251,8 +251,9 @@ static inline int cpu_mmu_index(CPUNios2State *env, bool ifetch)MMU_SUPERVISOR_IDX ; } -int nios2_cpu_handle_mmu_fault (CPUState *env,vaddr address,int size, -int rw,int mmu_idx); +bool nios2_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);static inline int cpu_interrupts_enabled (CPUNios2State *env) {
target/nios2/cpu.c +2 -3
@@ -200,9 +200,8 @@ static void nios2_cpu_class_init(ObjectClass *oc, void *data) cc->dump_state = nios2_cpu_dump_state; cc->set_pc = nios2_cpu_set_pc; cc->disas_set_info = nios2_cpu_disas_set_info; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = nios2_cpu_handle_mmu_fault; -#else + cc->tlb_fill = nios2_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->do_unaligned_access = nios2_cpu_do_unaligned_access; cc->get_phys_page_debug = nios2_cpu_get_phys_page_debug;#endif
target/nios2/helper.c +87 -94
197 lines not on this page · raw message
target/nios2/mmu.c +0 -12
@@ -35,18 +35,6 @@#define MMU_LOG (x)#endif -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -int ret; - - ret =nios2_cpu_handle_mmu_fault (cs, addr, size, access_type, mmu_idx); -if (unlikely (ret)) { -/* now we have a real cpu fault */ -cpu_loop_exit_restore (cs, retaddr); - } -} -void mmu_read_debug (CPUNios2State *env,uint32_t rn) {switch (rn) {
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 13/26] target/nios2: Convert to CPUClass::tlb_fill
Quoted 16 lines · Richard Henderson
Cc Chris Wulff <[email protected]>Cc Marek Vasut <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- target/nios2/cpu.h | 5 +- target/nios2/cpu.c | 5 +- target/nios2/helper.c | 181 ++++++++++++++++++++---------------------- target/nios2/mmu.c | 12 --- 4 files changed, 92 insertions(+), 111 deletions(-)target/nios2/helper.c +0
-0@@ -36,17 +36,6 @@ void nios2_cpu_do_interrupt(CPUState *cs) env->regs[R_EA ] = env->regs[R_PC ] +4 ; }
target/nios2/helper.c void nios2_cpu_do_interrupt(CPUState *cs) · line 48
Quoted 10 lines
target/nios2/helper.c +0
-10-int nios2_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int size, -int rw,int mmu_idx) -{ - cs->exception_index =0xaa ; -/* Page 0x1000 is kuser helper */ -if (address <0x1000 || address >=0x2000 ) { -cpu_dump_state (cs, stderr, fprintf,0 ); - } -return 1 ; -}
For user mode we used to set cs->exception_index to 0xaa...
target/nios2/helper.c void nios2_cpu_do_unaligned_access(CPUState *cs, vaddr addr, · line 225
Quoted 7 lines
target/nios2/helper.c +7
-0+bool nios2_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr) +{ +Nios2CPU *cpu =NIOS2_CPU (cs); +CPUNios2State *env = &cpu->env; +unsigned int excp =EXCP_TLBD ;
...but in the new code we end up setting it toEXCP_TLBD, which is 12.
Quoted 2 lines
target/nios2/helper.c +2
-0+ +#ifndef CONFIG_USER_ONLY
[...]
target/nios2/helper.c void nios2_cpu_do_unaligned_access(CPUState *cs, vaddr addr, · line 296
Quoted 6 lines
#endif /* !CONFIG_USER_ONLY */
target/nios2/helper.c +5
-0+ + cs->exception_index = excp; + env->regs[CR_BADADDR ] = address; +cpu_loop_exit_restore (cs, retaddr); +}
We also set env->regs[CR_BADADDR], which we weren't doing before.
We've lost the cpu_dump_state() as well (though I'm not sure why that was there -- maybe stray debug printing?)
Otherwise the changes look OK (ie no-behaviour-change).
thanks
-- PMM
PATCH 14/26 target/openrisc: Convert to CPUClass::tlb_fill
In reply to Richard Henderson--- target/openrisc/cpu.h | 5 ++-- target/openrisc/cpu.c | 5 ++-- target/openrisc/mmu.c | 65 ++++++++++++++++++++++--------------------- 3 files changed, 39 insertions(+), 36 deletions(-)
target/openrisc/cpu.h +3 -2
@@ -345,8 +345,9 @@ hwaddr openrisc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);int openrisc_cpu_gdb_read_register (CPUState *cpu,uint8_t *buf,int reg);int openrisc_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg);void openrisc_translate_init (void ); -int openrisc_cpu_handle_mmu_fault (CPUState *cpu,vaddr address,int size, -int rw,int mmu_idx); +bool openrisc_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);int cpu_openrisc_signal_handler (int host_signum,void *pinfo,void *puc);int print_insn_or1k (bfd_vma addr,disassemble_info *info);
target/openrisc/cpu.c +2 -3
@@ -148,9 +148,8 @@ static void openrisc_cpu_class_init(ObjectClass *oc, void *data) cc->set_pc = openrisc_cpu_set_pc; cc->gdb_read_register = openrisc_cpu_gdb_read_register; cc->gdb_write_register = openrisc_cpu_gdb_write_register; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = openrisc_cpu_handle_mmu_fault; -#else + cc->tlb_fill = openrisc_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->get_phys_page_debug = openrisc_cpu_get_phys_page_debug; dc->vmsd = &vmstate_openrisc_cpu;#endif
target/openrisc/mmu.c +34 -31
79 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 14/26] target/openrisc: Convert to CPUClass::tlb_fill
Quoted 13 lines · Richard Henderson
Cc Stafford Horne <[email protected]>Signed-off-by Richard Henderson <[email protected]>target/openrisc/mmu.c +1
-2@@ -107,16 +107,42 @@ static void raise_mmu_exception(OpenRISCCPU *cpu, target_ulong address, cpu->env.lock_addr =-1 ; } -int openrisc_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int size, -int rw,int mmu_idx) +bool openrisc_cpu_tlb_fill(CPUState *cs, vaddr addr, int size,
target/openrisc/mmu.c static void raise_mmu_exception(OpenRISCCPU *cpu, target_ulong address, · line 115
Quoted 10 lines
target/openrisc/mmu.c +3
-5+ MMUAccessType access_type, int mmu_idx, + bool probe, uintptr_t retaddr) { -#ifdef CONFIG_USER_ONLY OpenRISCCPU *cpu = OPENRISC_CPU(cs); -raise_mmu_exception (cpu, address,EXCP_DPF ); -return 1 ; -#else -g_assert_not_reached (); +int excp =EXCP_DPF ;
Let's hope no compilers complain that this assignment is never used in the softmmu configuration (where the following code always sets it to something else)...
thanks
-- PMM
PATCH 15/26 target/ppc: Convert to CPUClass::tlb_fill
In reply to Richard Henderson--- target/ppc/cpu.h | 7 +++---- target/ppc/mmu_helper.c | 19 +++++++++++++------ target/ppc/translate_init.inc.c | 5 ++--- target/ppc/user_only_helper.c | 14 ++++++++------ 4 files changed, 26 insertions(+), 19 deletions(-)
target/ppc/cpu.h +3 -4
@@ -1297,10 +1297,9 @@ void ppc_translate_init(void);is returned if the signal was handled by the virtual CPU. */ int cpu_ppc_signal_handler (int host_signum,void *pinfo,void *puc); -#if defined(CONFIG_USER_ONLY ) -int ppc_cpu_handle_mmu_fault (CPUState *cpu,vaddr address,int size,int rw, -int mmu_idx); -#endif +bool ppc_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);#if !defined(CONFIG_USER_ONLY )void ppc_store_sdr1 (CPUPPCState *env,target_ulong value);
target/ppc/mmu_helper.c +13 -6
@@ -3026,12 +3026,9 @@ void helper_check_tlb_flush_global(CPUPPCState *env)/*****************************************************************************/ -/* try to fill the TLB and return an exception if error. If retaddr is -NULL, it means that the function was called in C code (i.e. not -from generated code or from helper.c) */ -/* XXX: fix it to restore all registers */ -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) +bool ppc_cpu_tlb_fill (CPUState *cs,vaddr addr,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr) {PowerPCCPU *cpu =POWERPC_CPU (cs);PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cs);
@@ -3044,7 +3041,17 @@ void tlb_fill(CPUState *cs, target_ulong addr, int size, ret =cpu_ppc_handle_mmu_fault (env, addr, access_type, mmu_idx); }if (unlikely (ret !=0 )) { +if (probe) { +return false; + }raise_exception_err_ra (env, cs->exception_index, env->error_code, retaddr); } +return true; +} + +void tlb_fill (CPUState *cs,target_ulong addr,int size, +MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) +{ +ppc_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); }
target/ppc/translate_init.inc.c +2 -3
@@ -10545,9 +10545,8 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data) cc->gdb_read_register = ppc_cpu_gdb_read_register; cc->gdb_write_register = ppc_cpu_gdb_write_register; cc->do_unaligned_access = ppc_cpu_do_unaligned_access; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = ppc_cpu_handle_mmu_fault; -#else + cc->tlb_fill = ppc_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->get_phys_page_debug = ppc_cpu_get_phys_page_debug; cc->vmsd = &vmstate_ppc_cpu;#endif
target/ppc/user_only_helper.c +8 -6
@@ -20,21 +20,24 @@#include "qemu/osdep.h" #include "cpu.h" +#include "exec/exec-all.h" -int ppc_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int size,int rw, -int mmu_idx) + +bool ppc_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr) {PowerPCCPU *cpu =POWERPC_CPU (cs);CPUPPCState *env = &cpu->env;int exception, error_code; -if (rw ==2 ) { +if (access_type ==MMU_INST_FETCH ) { exception =POWERPC_EXCP_ISI ; error_code =0x40000000 ; }else { exception =POWERPC_EXCP_DSI ; error_code =0x40000000 ; -if (rw) { +if (access_type ==MMU_DATA_STORE ) { error_code |=0x02000000 ; } env->spr[SPR_DAR ] = address;
@@ -42,6 +45,5 @@ int ppc_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int size, int rw, } cs->exception_index = exception; env->error_code = error_code; - -return 1 ; +cpu_loop_exit_restore (cs, retaddr); }
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 15/26] target/ppc: Convert to CPUClass::tlb_fill
Quoted 34 lines · Richard Henderson
Cc David Gibson <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- target/ppc/cpu.h | 7 +++---- target/ppc/mmu_helper.c | 19 +++++++++++++------ target/ppc/translate_init.inc.c | 5 ++--- target/ppc/user_only_helper.c | 14 ++++++++------ 4 files changed, 26 insertions(+), 19 deletions(-)target/ppc/cpu.h +3
-4@@ -1297,10 +1297,9 @@ void ppc_translate_init(void);is returned if the signal was handled by the virtual CPU. */ int cpu_ppc_signal_handler (int host_signum,void *pinfo,void *puc); -#if defined(CONFIG_USER_ONLY ) -int ppc_cpu_handle_mmu_fault (CPUState *cpu,vaddr address,int size,int rw, -int mmu_idx); -#endif +bool ppc_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);#if !defined(CONFIG_USER_ONLY )void ppc_store_sdr1 (CPUPPCState *env,target_ulong value);target/ppc/mmu_helper.c +0
-0
target/ppc/mmu_helper.c void helper_check_tlb_flush_global(CPUPPCState *env) · line 3032
Quoted 7 lines
target/ppc/mmu_helper.c +0
-4@@ -3026,12 +3026,9 @@ void helper_check_tlb_flush_global(CPUPPCState *env)/*****************************************************************************/ -/* try to fill the TLB and return an exception if error. If retaddr is -NULL, it means that the function was called in C code (i.e. not -from generated code or from helper.c) */ -/* XXX: fix it to restore all registers */
Is this XXX comment definitely no longer relevant ?
target/ppc/mmu_helper.c void helper_check_tlb_flush_global(CPUPPCState *env) · line 3034
Quoted 8 lines
target/ppc/mmu_helper.c +3
-2-void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) +bool ppc_cpu_tlb_fill (CPUState *cs,vaddr addr,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr) {PowerPCCPU *cpu =POWERPC_CPU (cs);PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cs);
Otherwise
thanks
-- PMM
PATCH 16/26 target/riscv: Convert to CPUClass::tlb_fill
In reply to Richard HendersonNote that env->pc is removed from the qemu_log as that value is garbage. The PC isn't recovered until cpu_restore_state, called from cpu_loop_exit_restore, called from riscv_raise_exception.
--- target/riscv/cpu.h | 5 +++-- target/riscv/cpu.c | 5 ++--- target/riscv/cpu_helper.c | 46 ++++++++++++++++++--------------------- 3 files changed, 26 insertions(+), 30 deletions(-)
target/riscv/cpu.h +3 -2
@@ -261,8 +261,9 @@ hwaddr riscv_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);void riscv_cpu_do_unaligned_access (CPUState *cs,vaddr addr,MMUAccessType access_type,int mmu_idx,uintptr_t retaddr); -int riscv_cpu_handle_mmu_fault (CPUState *cpu,vaddr address,int size, -int rw,int mmu_idx); +bool riscv_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);char *riscv_isa_string (RISCVCPU *cpu);void riscv_cpu_list (FILE *f,fprintf_function cpu_fprintf);
target/riscv/cpu.c +2 -3
@@ -355,9 +355,8 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)#endif cc->gdb_stop_before_watchpoint = true; cc->disas_set_info = riscv_cpu_disas_set_info; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = riscv_cpu_handle_mmu_fault; -#else + cc->tlb_fill = riscv_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->do_unaligned_access = riscv_cpu_do_unaligned_access; cc->get_phys_page_debug = riscv_cpu_get_phys_page_debug;#endif
target/riscv/cpu_helper.c +21 -25
82 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 16/26] target/riscv: Convert to CPUClass::tlb_fill
Quoted 9 lines · Richard Henderson
Note that
env->pcis removed from theqemu_logas that value is garbage. The PC isn't recovered untilcpu_restore_state, called fromcpu_loop_exit_restore, called fromriscv_raise_exception.Cc Palmer Dabbelt <[email protected]>Cc Alistair Francis <[email protected]>Signed-off-by Richard Henderson <[email protected]>
This is going to conflict with some two-stage MMU work I have, but it shouldn't be too bad.
Alistair
Quoted 130 lines
--- target/riscv/cpu.h | 5 +++-- target/riscv/cpu.c | 5 ++--- target/riscv/cpu_helper.c | 46 ++++++++++++++++++--------------------- 3 files changed, 26 insertions(+), 30 deletions(-)target/riscv/cpu.h +3
-2@@ -261,8 +261,9 @@ hwaddr riscv_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);void riscv_cpu_do_unaligned_access (CPUState *cs,vaddr addr,MMUAccessType access_type,int mmu_idx,uintptr_t retaddr); -int riscv_cpu_handle_mmu_fault (CPUState *cpu,vaddr address,int size, -int rw,int mmu_idx); +bool riscv_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);char *riscv_isa_string (RISCVCPU *cpu);void riscv_cpu_list (FILE *f,fprintf_function cpu_fprintf);target/riscv/cpu.c +2
-3@@ -355,9 +355,8 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)#endif cc->gdb_stop_before_watchpoint = true; cc->disas_set_info = riscv_cpu_disas_set_info; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = riscv_cpu_handle_mmu_fault; -#else + cc->tlb_fill = riscv_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->do_unaligned_access = riscv_cpu_do_unaligned_access; cc->get_phys_page_debug = riscv_cpu_get_phys_page_debug;#endif target/riscv/cpu_helper.c +21
-26@@ -379,53 +379,49 @@ void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr,riscv_raise_exception (env, cs->exception_index, retaddr); } -/* called by qemu's softmmu to fill the qemu tlb */ void tlb_fill (CPUState *cs,target_ulong addr,int size,MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) { -int ret; - ret =riscv_cpu_handle_mmu_fault (cs, addr, size, access_type, mmu_idx); -if (ret ==TRANSLATE_FAIL ) { -RISCVCPU *cpu =RISCV_CPU (cs); -CPURISCVState *env = &cpu->env; -riscv_raise_exception (env, cs->exception_index, retaddr); - } +riscv_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); } -#endif -int riscv_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int size, -int rw,int mmu_idx) +bool riscv_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr) { +#ifndef CONFIG_USER_ONLY RISCVCPU *cpu =RISCV_CPU (cs);CPURISCVState *env = &cpu->env; -#if !defined(CONFIG_USER_ONLY )hwaddr pa =0 ;int prot; -#endif int ret =TRANSLATE_FAIL ; -qemu_log_mask (CPU_LOG_MMU , -"%s pc " TARGET_FMT_lx" ad %" VADDR_PRIx" rw %d mmu_idx \ -%d\n" , __func__, env->pc, address, rw, mmu_idx); +qemu_log_mask (CPU_LOG_MMU ,"%s ad %" VADDR_PRIx" rw %d mmu_idx %d\n" , + __func__, address, access_type, mmu_idx); + + ret =get_physical_address (env, &pa, &prot, address, access_type, mmu_idx); -#if !defined(CONFIG_USER_ONLY ) - ret =get_physical_address (env, &pa, &prot, address, rw, mmu_idx);qemu_log_mask (CPU_LOG_MMU , -"%s address=%" VADDR_PRIx" ret %d physical " TARGET_FMT_plx -" prot %d\n" , __func__, address, ret, pa, prot); +"%s address=%" VADDR_PRIx" ret %d physical " TARGET_FMT_plx +" prot %d\n" , __func__, address, ret, pa, prot); +if (riscv_feature (env,RISCV_FEATURE_PMP ) && - !pmp_hart_has_privs (env, pa,TARGET_PAGE_SIZE ,1 << rw)) { + !pmp_hart_has_privs (env, pa,TARGET_PAGE_SIZE ,1 << access_type)) { ret =TRANSLATE_FAIL ; }if (ret ==TRANSLATE_SUCCESS ) {tlb_set_page (cs, address &TARGET_PAGE_MASK , pa &TARGET_PAGE_MASK , prot, mmu_idx,TARGET_PAGE_SIZE ); - }else if (ret ==TRANSLATE_FAIL ) { -raise_mmu_exception (env, address, rw); +return true; + }else if (probe) { +return false; + }else { +raise_mmu_exception (env, address, access_type); +riscv_raise_exception (env, cs->exception_index, retaddr); }#else -switch (rw) { +switch (access_type) {case MMU_INST_FETCH : cs->exception_index =RISCV_EXCP_INST_PAGE_FAULT ;break ;@@ -436,8 +432,8 @@ int riscv_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int size, cs->exception_index =RISCV_EXCP_STORE_PAGE_FAULT ; break; } +cpu_loop_exit_restore (cs, retaddr);#endif -return ret; }/* -- 2.17.1
PATCH 17/26 target/s390x: Convert to CPUClass::tlb_fill
In reply to Richard Henderson--- target/s390x/internal.h | 5 +- target/s390x/cpu.c | 5 +- target/s390x/excp_helper.c | 156 +++++++++++++++++++++---------------- target/s390x/mem_helper.c | 29 ------- 4 files changed, 94 insertions(+), 101 deletions(-)
target/s390x/internal.h +3 -2
@@ -263,8 +263,9 @@ ObjectClass *s390_cpu_class_by_name(const char *name);void s390x_cpu_debug_excp_handler (CPUState *cs);void s390_cpu_do_interrupt (CPUState *cpu);bool s390_cpu_exec_interrupt (CPUState *cpu,int int_req); -int s390_cpu_handle_mmu_fault (CPUState *cpu,vaddr address,int size,int rw, -int mmu_idx); +bool s390_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);void s390x_cpu_do_unaligned_access (CPUState *cs,vaddr addr,MMUAccessType access_type,int mmu_idx,uintptr_t retaddr);
target/s390x/cpu.c +2 -3
@@ -471,9 +471,8 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data) cc->set_pc = s390_cpu_set_pc; cc->gdb_read_register = s390_cpu_gdb_read_register; cc->gdb_write_register = s390_cpu_gdb_write_register; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = s390_cpu_handle_mmu_fault; -#else + cc->tlb_fill = s390_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->get_phys_page_debug = s390_cpu_get_phys_page_debug; cc->vmsd = &vmstate_s390_cpu; cc->write_elf64_note = s390_cpu_write_elf64_note;
target/s390x/excp_helper.c +89 -67
173 lines not on this page · raw message
target/s390x/mem_helper.c +0 -29
@@ -34,35 +34,6 @@/*****************************************************************************/ /* Softmmu support */ -#if !defined(CONFIG_USER_ONLY ) - -/* try to fill the TLB and return an exception if error. If retaddr is -NULL, it means that the function was called in C code (i.e. not -from generated code or from helper.c) */ -/* XXX: fix it to restore all registers */ -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -int ret =s390_cpu_handle_mmu_fault (cs, addr, size, access_type, mmu_idx); -if (unlikely (ret !=0 )) { -cpu_restore_state (cs, retaddr, true); - -/* -* Note that handle_mmu_fault sets ilen to either 2 (for code) -* or AUTO (for data). We can resolve AUTO now, as if it was -* set to UNWIND -- that will have been done via assignment -* in cpu_restore_state. Otherwise re-examine access_type. -*/ -if (access_type ==MMU_INST_FETCH ) { -CPUS390XState *env = cs->env_ptr; - env->int_pgm_ilen =2 ; - } - -cpu_loop_exit (cs); - } -} - -#endif /* #define DEBUG_HELPER */ #ifdef DEBUG_HELPER
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 17/26] target/s390x: Convert to CPUClass::tlb_fill
Quoted 62 lines
#endif /*
CONFIG_USER_ONLY*/target/s390x/excp_helper.c +61
-0+ +bool s390_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr) +{ +S390CPU *cpu =S390_CPU (cs); + +#ifndef CONFIG_USER_ONLY +CPUS390XState *env = &cpu->env; +target_ulong vaddr, raddr; +uint64_t asc; +int prot, fail; + +qemu_log_mask (CPU_LOG_MMU ,"%s: addr 0x%" VADDR_PRIx" rw %d mmu_idx %d\n" , + __func__, address, access_type, mmu_idx); + + vaddr = address; + +if (mmu_idx <MMU_REAL_IDX ) { + asc =cpu_mmu_idx_to_asc (mmu_idx); +/* 31-Bit mode */ +if (!(env->psw.mask &PSW_MASK_64 )) { + vaddr &=0x7fffffff ; + } + fail =mmu_translate (env, vaddr, access_type, asc, &raddr, &prot, true); + }else if (mmu_idx ==MMU_REAL_IDX ) { +/* 31-Bit mode */ +if (!(env->psw.mask &PSW_MASK_64 )) { + vaddr &=0x7fffffff ; + } + fail =mmu_translate_real (env, vaddr, access_type, &raddr, &prot); + }else { +g_assert_not_reached (); + } + +/* check out of RAM access */ +if (!fail && + !address_space_access_valid (&address_space_memory, raddr, +TARGET_PAGE_SIZE , access_type, +MEMTXATTRS_UNSPECIFIED )) { +qemu_log_mask (CPU_LOG_MMU , +"%s: raddr %" PRIx64" > ram_size %" PRIx64"\n" , + __func__, (uint64_t )raddr, (uint64_t )ram_size); +trigger_pgm_exception (env,PGM_ADDRESSING ,ILEN_AUTO ); + fail =1 ; + } + +if (!fail) { +qemu_log_mask (CPU_LOG_MMU , +"%s: set tlb %" PRIx64" -> %" PRIx64" (%x)\n" , + __func__, (uint64_t )vaddr, (uint64_t )raddr, prot); +tlb_set_page (cs, address &TARGET_PAGE_MASK , raddr, prot, + mmu_idx,TARGET_PAGE_SIZE ); +return true; + } +if (probe) { +return false; + } +#else +trigger_pgm_exception (&cpu->env,PGM_ADDRESSING ,ILEN_AUTO ); +/*
target/s390x/excp_helper.c void s390x_cpu_do_unaligned_access(CPUState *cs, vaddr addr, · line 589
Quoted 10 lines
target/s390x/excp_helper.c +10
-0+* On real machines this value is dropped into LowMem. Since this +* is userland, simply put this someplace that cpu_loop can find it. +*/ + cpu->env.__excp_addr = address; +#endif + +cpu_restore_state (cs, retaddr, true); + +/* +* Note that handle_mmu_fault sets ilen to either 2 (for code)
This comment no longer matches.
target/s390x/excp_helper.c void s390x_cpu_do_unaligned_access(CPUState *cs, vaddr addr, · line 601
Quoted 12 lines
target/s390x/excp_helper.c +12
-0+* or AUTO (for data). We can resolve AUTO now, as if it was +* set to UNWIND -- that will have been done via assignment +* in cpu_restore_state. Otherwise re-examine access_type. +*/ +if (access_type ==MMU_INST_FETCH ) { +CPUS390XState *env = cs->env_ptr; + env->int_pgm_ilen =2 ; + } + +cpu_loop_exit (cs); +} +
Apart from that, looks good to me.
Signature · 3 lines
Thanks, David / dhildenb
Re: [Qemu-devel] [PATCH 17/26] target/s390x: Convert to CPUClass::tlb_fill
Quoted 12 lines · David Hildenbrand
Review
Quoted 2 lines
(quoted diff) +2
-0+ /* + * Note that handle_mmu_fault sets ilen to either 2 (for code)This comment no longer matches.
Quoted 8 lines
target/s390x/excp_helper.c +8
-0+* or AUTO (for data). We can resolve AUTO now, as if it was +* set to UNWIND -- that will have been done via assignment +* in cpu_restore_state. Otherwise re-examine access_type. +*/ +if (access_type ==MMU_INST_FETCH ) { +CPUS390XState *env = cs->env_ptr; + env->int_pgm_ilen =2 ; + }
Indeed it doesn't. It's also confusingly written. I've tried again as
/*
* The ILC value for code accesses is undefined. The important
* thing here is to *not* leave env->int_pgm_ilen set to ILEN_AUTO,
* which would cause do_program_interrupt to attempt to read from
* env->psw.addr again. C.f. the condition in trigger_page_fault,
* but is not universally applied.
*
* ??? If we remove ILEN_AUTO, by moving the computation of ILEN
* into cpu_restore_state, then we may remove this entirely. */
if (access_type == MMU_INST_FETCH) {
env->int_pgm_ilen = 2;
}
I'll just note in passing that the ??? part of the comment alludes to
https://lists.gnu.org/archive/html/qemu-devel/2019-04/msg00063.html
to which I ought to return at some point.
r~
PATCH 18/26 target/sh4: Convert to CPUClass::tlb_fill
In reply to Richard Henderson--- target/sh4/cpu.h | 5 +- target/sh4/cpu.c | 5 +- target/sh4/helper.c | 197 ++++++++++++++++++++--------------------- target/sh4/op_helper.c | 12 --- 4 files changed, 101 insertions(+), 118 deletions(-)
target/sh4/cpu.h +3 -2
@@ -244,8 +244,9 @@ void superh_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,void sh4_translate_init (void );int cpu_sh4_signal_handler (int host_signum,void *pinfo,void *puc); -int superh_cpu_handle_mmu_fault (CPUState *cpu,vaddr address,int size,int rw, -int mmu_idx); +bool superh_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);void sh4_cpu_list (FILE *f,fprintf_function cpu_fprintf);#if !defined(CONFIG_USER_ONLY )
target/sh4/cpu.c +2 -3
@@ -238,9 +238,8 @@ static void superh_cpu_class_init(ObjectClass *oc, void *data) cc->synchronize_from_tb = superh_cpu_synchronize_from_tb; cc->gdb_read_register = superh_cpu_gdb_read_register; cc->gdb_write_register = superh_cpu_gdb_write_register; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = superh_cpu_handle_mmu_fault; -#else + cc->tlb_fill = superh_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->do_unaligned_access = superh_cpu_do_unaligned_access; cc->get_phys_page_debug = superh_cpu_get_phys_page_debug;#endif
target/sh4/helper.c +96 -101
224 lines not on this page · raw message
target/sh4/op_helper.c +0 -12
@@ -41,18 +41,6 @@ void superh_cpu_do_unaligned_access(CPUState *cs, vaddr addr, cpu_loop_exit_restore(cs, retaddr); } -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -int ret; - - ret =superh_cpu_handle_mmu_fault (cs, addr, size, access_type, mmu_idx); -if (ret) { -/* now we have a real cpu fault */ -cpu_loop_exit_restore (cs, retaddr); - } -} -#endif void helper_ldtlb (CPUSH4State *env)
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 18/26] target/sh4: Convert to CPUClass::tlb_fill
Quoted 4 lines · Richard Henderson
Cc Aurelien Jarno <[email protected]>Signed-off-by Richard Henderson <[email protected]>---
thanks
-- PMM
PATCH 19/26 target/sparc: Convert to CPUClass::tlb_fill
In reply to Richard Henderson--- target/sparc/cpu.h | 5 +- target/sparc/cpu.c | 5 +- target/sparc/ldst_helper.c | 15 ---- target/sparc/mmu_helper.c | 175 +++++++++++++++++++------------------ 4 files changed, 93 insertions(+), 107 deletions(-)
target/sparc/cpu.h +3 -2
@@ -580,8 +580,9 @@ void cpu_raise_exception_ra(CPUSPARCState *, int, uintptr_t) QEMU_NORETURN;void cpu_sparc_set_id (CPUSPARCState *env,unsigned int cpu);void sparc_cpu_list (FILE *f,fprintf_function cpu_fprintf);/* mmu_helper.c */ -int sparc_cpu_handle_mmu_fault (CPUState *cpu,vaddr address,int size,int rw, -int mmu_idx); +bool sparc_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);target_ulong mmu_probe (CPUSPARCState *env,target_ulong address,int mmulev);void dump_mmu (FILE *f,fprintf_function cpu_fprintf,CPUSPARCState *env);
target/sparc/cpu.c +2 -3
@@ -880,9 +880,8 @@ static void sparc_cpu_class_init(ObjectClass *oc, void *data) cc->synchronize_from_tb = sparc_cpu_synchronize_from_tb; cc->gdb_read_register = sparc_cpu_gdb_read_register; cc->gdb_write_register = sparc_cpu_gdb_write_register; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = sparc_cpu_handle_mmu_fault; -#else + cc->tlb_fill = sparc_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->do_unassigned_access = sparc_cpu_unassigned_access; cc->do_unaligned_access = sparc_cpu_do_unaligned_access; cc->get_phys_page_debug = sparc_cpu_get_phys_page_debug;
target/sparc/ldst_helper.c +0 -15
@@ -1924,19 +1924,4 @@ void QEMU_NORETURN sparc_cpu_do_unaligned_access(CPUState *cs, vaddr addr,#endif cpu_raise_exception_ra(env, TT_UNALIGNED, retaddr); } - -/* try to fill the TLB and return an exception if error. If retaddr is -NULL, it means that the function was called in C code (i.e. not -from generated code or from helper.c) */ -/* XXX: fix it to restore all registers */ -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -int ret; - - ret =sparc_cpu_handle_mmu_fault (cs, addr, size, access_type, mmu_idx); -if (ret) { -cpu_loop_exit_restore (cs, retaddr); - } -}#endif
target/sparc/mmu_helper.c +88 -87
214 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 19/26] target/sparc: Convert to CPUClass::tlb_fill
Quoted 9 lines · Richard Henderson
Cc Artyom Tarasenko <[email protected]>Cc Mark Cave-Ayland <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- target/sparc/cpu.h | 5 +- target/sparc/cpu.c | 5 +- target/sparc/ldst_helper.c | 15 ---- target/sparc/mmu_helper.c | 175 +++++++++++++++++++------------------ 4 files changed, 93 insertions(+), 107 deletions(-)
Bah, failed to test this one, and it hangs.
For v2 I'll not try to combine SPARC64 and SPARC32 paths.
r~
PATCH 20/26 target/tilegx: Convert to CPUClass::tlb_fill
In reply to Richard Henderson--- target/tilegx/cpu.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
target/tilegx/cpu.c +7 -4
@@ -24,6 +24,8 @@#include "qemu-common.h" #include "hw/qdev-properties.h" #include "linux-user/syscall_defs.h" +#include "exec/exec-all.h" +static void tilegx_cpu_dump_state (CPUState *cs,FILE *f,fprintf_function cpu_fprintf,int flags)
@@ -111,8 +113,9 @@ static void tilegx_cpu_do_interrupt(CPUState *cs) cs->exception_index =-1 ; } -static int tilegx_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int size, -int rw,int mmu_idx) +static bool tilegx_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr) {TileGXCPU *cpu =TILEGX_CPU (cs);
@@ -122,7 +125,7 @@ static int tilegx_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int size, cpu->env.signo =TARGET_SIGSEGV ; cpu->env.sigcode =0 ; -return 1 ; +cpu_loop_exit_restore (cs, retaddr); }static bool tilegx_cpu_exec_interrupt (CPUState *cs,int interrupt_request)
@@ -152,7 +155,7 @@ static void tilegx_cpu_class_init(ObjectClass *oc, void *data) cc->cpu_exec_interrupt = tilegx_cpu_exec_interrupt; cc->dump_state = tilegx_cpu_dump_state; cc->set_pc = tilegx_cpu_set_pc; - cc->handle_mmu_fault = tilegx_cpu_handle_mmu_fault; + cc->tlb_fill = tilegx_cpu_tlb_fill; cc->gdb_num_core_regs =0 ; cc->tcg_initialize = tilegx_tcg_init; }
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 20/26] target/tilegx: Convert to CPUClass::tlb_fill
Quoted 5 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/tilegx/cpu.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
thanks
-- PMM
PATCH 21/26 target/tricore: Convert to CPUClass::tlb_fill
In reply to Richard Henderson--- target/tricore/cpu.h | 6 +++--- target/tricore/cpu.c | 1 + target/tricore/helper.c | 27 +++++++++++++++++++-------- target/tricore/op_helper.c | 26 -------------------------- 4 files changed, 23 insertions(+), 37 deletions(-)
target/tricore/cpu.h +3 -3
@@ -418,8 +418,8 @@ static inline void cpu_get_tb_cpu_state(CPUTriCoreState *env, target_ulong *pc,#define CPU_RESOLVING_TYPE TYPE_TRICORE_CPU/* helpers.c */ -int cpu_tricore_handle_mmu_fault (CPUState *cpu,target_ulong address, -int rw,int mmu_idx); -#define cpu_handle_mmu_fault cpu_tricore_handle_mmu_fault +bool tricore_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);#endif /* TRICORE_CPU_H */
target/tricore/cpu.c +1 -0
@@ -166,6 +166,7 @@ static void tricore_cpu_class_init(ObjectClass *c, void *data) cc->synchronize_from_tb = tricore_cpu_synchronize_from_tb; cc->get_phys_page_attrs_debug = tricore_cpu_get_phys_page_attrs_debug; cc->tcg_initialize = tricore_tcg_init; + cc->tlb_fill = tricore_cpu_tlb_fill; }#define DEFINE_TRICORE_CPU_TYPE (cpu_model, initfn) \
target/tricore/helper.c +19 -8
@@ -49,8 +49,9 @@ static void raise_mmu_exception(CPUTriCoreState *env, target_ulong address, { } -int cpu_tricore_handle_mmu_fault (CPUState *cs,target_ulong address, -int rw,int mmu_idx) +bool tricore_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType rw,int mmu_idx, +bool probe,uintptr_t retaddr) {TriCoreCPU *cpu =TRICORE_CPU (cs);CPUTriCoreState *env = &cpu->env;
@@ -63,20 +64,30 @@ int cpu_tricore_handle_mmu_fault(CPUState *cs, target_ulong address, access_type =ACCESS_INT ; ret =get_physical_address (env, &physical, &prot, address, rw, access_type); -qemu_log_mask (CPU_LOG_MMU ,"%s address=" TARGET_FMT_lx" ret %d physical " TARGET_FMT_plx -" prot %d\n" , __func__, address, ret, physical, prot); + +qemu_log_mask (CPU_LOG_MMU ,"%s address=" TARGET_FMT_lx" ret %d physical " + TARGET_FMT_plx" prot %d\n" , + __func__, (target_ulong )address, ret, physical, prot);if (ret ==TLBRET_MATCH ) {tlb_set_page (cs, address &TARGET_PAGE_MASK , physical &TARGET_PAGE_MASK , prot |PAGE_EXEC , mmu_idx,TARGET_PAGE_SIZE ); - ret =0 ; - }else if (ret <0 ) { +return true; + }else { +assert (ret <0 ); +if (probe) { +return false; + }raise_mmu_exception (env, address, rw, ret); - ret =1 ; +cpu_loop_exit_restore (cs, retaddr); } +} -return ret; +void tlb_fill (CPUState *cs,target_ulong addr,int size, +MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) +{ +tricore_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); }static void tricore_cpu_list_entry (gpointer data,gpointer user_data)
target/tricore/op_helper.c +0 -26
@@ -2793,29 +2793,3 @@ uint32_t helper_psw_read(CPUTriCoreState *env) {return psw_read (env); } - - -static inline void QEMU_NORETURN do_raise_exception_err(CPUTriCoreState *env, -uint32_t exception, -int error_code, -uintptr_t pc) -{ -CPUState *cs =CPU (tricore_env_get_cpu (env)); - cs->exception_index = exception; - env->error_code = error_code; -/* now we have a real cpu fault */ -cpu_loop_exit_restore (cs, pc); -} - -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -int ret; - ret =cpu_tricore_handle_mmu_fault (cs, addr, access_type, mmu_idx); -if (ret) { -TriCoreCPU *cpu =TRICORE_CPU (cs); -CPUTriCoreState *env = &cpu->env; -do_raise_exception_err (env, cs->exception_index, - env->error_code, retaddr); - } -}
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 21/26] target/tricore: Convert to CPUClass::tlb_fill
Quoted 10 lines · Richard Henderson
Cc Bastian Koppelmann <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- target/tricore/cpu.h | 6 +++--- target/tricore/cpu.c | 1 + target/tricore/helper.c | 27 +++++++++++++++++++-------- target/tricore/op_helper.c | 26 -------------------------- 4 files changed, 23 insertions(+), 37 deletions(-)
thanks
-- PMM
PATCH 22/26 target/unicore32: Convert to CPUClass::tlb_fill
In reply to Richard Henderson--- target/unicore32/cpu.h | 5 +++-- target/unicore32/cpu.c | 5 +---- target/unicore32/helper.c | 23 ----------------------- target/unicore32/op_helper.c | 14 -------------- target/unicore32/softmmu.c | 19 +++++++++++++++---- 5 files changed, 19 insertions(+), 47 deletions(-)
target/unicore32/cpu.h +3 -2
@@ -179,8 +179,9 @@ static inline void cpu_get_tb_cpu_state(CPUUniCore32State *env, target_ulong *pc } } -int uc32_cpu_handle_mmu_fault (CPUState *cpu,vaddr address,int size,int rw, -int mmu_idx); +bool uc32_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);void uc32_translate_init (void );void switch_mode (CPUUniCore32State *,int );
target/unicore32/cpu.c +1 -4
@@ -138,11 +138,8 @@ static void uc32_cpu_class_init(ObjectClass *oc, void *data) cc->cpu_exec_interrupt = uc32_cpu_exec_interrupt; cc->dump_state = uc32_cpu_dump_state; cc->set_pc = uc32_cpu_set_pc; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = uc32_cpu_handle_mmu_fault; -#else + cc->tlb_fill = uc32_cpu_tlb_fill; cc->get_phys_page_debug = uc32_cpu_get_phys_page_debug; -#endif cc->tcg_initialize = uc32_translate_init; dc->vmsd = &vmstate_uc32_cpu; }
target/unicore32/helper.c +0 -23
@@ -215,29 +215,6 @@ void helper_cp1_putc(target_ulong x) }#endif -#ifdef CONFIG_USER_ONLY -void switch_mode (CPUUniCore32State *env,int mode) -{ -UniCore32CPU *cpu =uc32_env_get_cpu (env); - -if (mode !=ASR_MODE_USER ) { -cpu_abort (CPU (cpu),"Tried to switch out of user mode\n" ); - } -} - -void uc32_cpu_do_interrupt (CPUState *cs) -{ -cpu_abort (cs,"NO interrupt in user mode\n" ); -} - -int uc32_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int size, -int access_type,int mmu_idx) -{ -cpu_abort (cs,"NO mmu fault in user mode\n" ); -return 1 ; -} -#endif -bool uc32_cpu_exec_interrupt (CPUState *cs,int interrupt_request) {if (interrupt_request &CPU_INTERRUPT_HARD ) {
target/unicore32/op_helper.c +0 -14
@@ -242,17 +242,3 @@ uint32_t HELPER(ror_cc)(CPUUniCore32State *env, uint32_t x, uint32_t i)return ((uint32_t )x >> shift) | (x << (32 - shift)); } } - -#ifndef CONFIG_USER_ONLY -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -int ret; - - ret =uc32_cpu_handle_mmu_fault (cs, addr, size, access_type, mmu_idx); -if (unlikely (ret)) { -/* now we have a real cpu fault */ -cpu_loop_exit_restore (cs, retaddr); - } -} -#endif
target/unicore32/softmmu.c +15 -4
@@ -215,8 +215,9 @@ do_fault:return code; } -int uc32_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int size, -int access_type,int mmu_idx) +bool uc32_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr) {UniCore32CPU *cpu =UNICORE32_CPU (cs);CPUUniCore32State *env = &cpu->env;
@@ -257,7 +258,11 @@ int uc32_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int size, phys_addr &=TARGET_PAGE_MASK ; address &=TARGET_PAGE_MASK ;tlb_set_page (cs, address, phys_addr, prot, mmu_idx, page_size); -return 0 ; +return true; + } + +if (probe) { +return false; } env->cp0.c3_faultstatus = ret;
@@ -267,7 +272,13 @@ int uc32_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int size, }else { cs->exception_index =UC32_EXCP_DTRAP ; } -return ret; +cpu_loop_exit_restore (cs, retaddr); +} + +void tlb_fill (CPUState *cs,target_ulong addr,int size, +MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) +{ +uc32_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); }hwaddr uc32_cpu_get_phys_page_debug (CPUState *cs,vaddr addr)
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 22/26] target/unicore32: Convert to CPUClass::tlb_fill
Quoted 10 lines · Richard Henderson
Cc Guan Xuetao <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- target/unicore32/cpu.h | 5 +++-- target/unicore32/cpu.c | 5 +---- target/unicore32/helper.c | 23 ----------------------- target/unicore32/op_helper.c | 14 -------------- target/unicore32/softmmu.c | 19 +++++++++++++++---- 5 files changed, 19 insertions(+), 47 deletions(-)
You might note in the commit message that we can just delete the user-mode (non-)handling of tlb fill because we don't support unicore32 linux-user any more.
thanks
-- PMM
Re: [Qemu-devel] [PATCH 22/26] target/unicore32: Convert to CPUClass::tlb_fill
It's OK for unicore32 codes.
Thanks.
Guan Xuetao
Quoted 28 lines
-----Original Messages-----
From: "Peter Maydell" <[email protected]>
Sent Time: 2019-04-30 18:06:03 (Tuesday)
To: "Richard Henderson" <[email protected]>
Cc: "QEMU Developers" <[email protected]>, "Guan Xuetao" <[email protected]>
Subject: Re: [Qemu-devel] [PATCH 22/26] target/unicore32: Convert toCPUClass::tlb_fillQuoted 10 lines · Richard Henderson
Cc Guan Xuetao <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- target/unicore32/cpu.h | 5 +++-- target/unicore32/cpu.c | 5 +---- target/unicore32/helper.c | 23 ----------------------- target/unicore32/op_helper.c | 14 -------------- target/unicore32/softmmu.c | 19 +++++++++++++++---- 5 files changed, 19 insertions(+), 47 deletions(-)Reviewed-by Peter Maydell <[email protected]>You might note in the commit message that we can just delete the user-mode (non-)handling of tlb fill because we don't support unicore32 linux-user any more.
thanks
-- PMM
PATCH 23/26 target/xtensa: Convert to CPUClass::tlb_fill
In reply to Richard Henderson--- target/xtensa/cpu.h | 5 +-- target/xtensa/cpu.c | 5 ++- target/xtensa/helper.c | 74 +++++++++++++++++++++--------------------- 3 files changed, 42 insertions(+), 42 deletions(-)
target/xtensa/cpu.h +3 -2
@@ -552,8 +552,9 @@ static inline XtensaCPU *xtensa_env_get_cpu(const CPUXtensaState *env)#define ENV_OFFSET offsetof(XtensaCPU, env) -int xtensa_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int rw,int size, -int mmu_idx); +bool xtensa_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr);void xtensa_cpu_do_interrupt (CPUState *cpu);bool xtensa_cpu_exec_interrupt (CPUState *cpu,int interrupt_request); void xtensa_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, vaddr addr,
target/xtensa/cpu.c +2 -3
@@ -181,9 +181,8 @@ static void xtensa_cpu_class_init(ObjectClass *oc, void *data) cc->gdb_read_register = xtensa_cpu_gdb_read_register; cc->gdb_write_register = xtensa_cpu_gdb_write_register; cc->gdb_stop_before_watchpoint = true; -#ifdef CONFIG_USER_ONLY - cc->handle_mmu_fault = xtensa_cpu_handle_mmu_fault; -#else + cc->tlb_fill = xtensa_cpu_tlb_fill; +#ifndef CONFIG_USER_ONLY cc->do_unaligned_access = xtensa_cpu_do_unaligned_access; cc->get_phys_page_debug = xtensa_cpu_get_phys_page_debug; cc->do_transaction_failed = xtensa_cpu_do_transaction_failed;
target/xtensa/helper.c +37 -37
92 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 23/26] target/xtensa: Convert to CPUClass::tlb_fill
Quoted 19 lines · Richard Henderson
Cc Max Filippov <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- target/xtensa/cpu.h | 5 +-- target/xtensa/cpu.c | 5 ++- target/xtensa/helper.c | 74 +++++++++++++++++++++--------------------- 3 files changed, 42 insertions(+), 42 deletions(-)target/xtensa/helper.c +3
-4-#ifdef CONFIG_USER_ONLY - -int xtensa_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int size,int rw, -int mmu_idx) +bool xtensa_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr) {XtensaCPU *cpu =XTENSA_CPU (cs);CPUXtensaState *env = &cpu->env;
target/xtensa/helper.c void xtensa_cpu_list(FILE *f, fprintf_function cpu_fprintf) · line 254
Quoted 10 lines
target/xtensa/helper.c +2
-7+target_ulong vaddr = address; +int ret; -qemu_log_mask (CPU_LOG_INT , -"%s: rw = %d, address = 0x%08" VADDR_PRIx", size = %d\n" , - __func__, rw, address, size); - env->sregs[EXCVADDR ] = address; - env->sregs[EXCCAUSE ] = rw ?STORE_PROHIBITED_CAUSE :LOAD_PROHIBITED_CAUSE ; - cs->exception_index =EXC_USER ; -return 1 ;
Previously we set exception_index to EXC_USER...
Quoted 16 lines
target/xtensa/helper.c +16
-0+#ifdef CONFIG_USER_ONLY + ret = (access_type ==MMU_DATA_STORE ? +STORE_PROHIBITED_CAUSE :LOAD_PROHIBITED_CAUSE ); +#else +uint32_t paddr; +uint32_t page_size; +unsigned access; + + ret =xtensa_get_physical_addr (env, true, vaddr, access_type, mmu_idx, + &paddr, &page_size, &access); + +qemu_log_mask (CPU_LOG_MMU ,"%s(%08x, %d, %d) -> %08x, ret = %d\n" , + __func__, vaddr, access_type, mmu_idx, paddr, ret); + +if (ret ==0 ) { + tlb_set_page(cs, vaddr & TARGET_PAGE_MASK, paddr & TARGET_PAGE_MASK,
target/xtensa/helper.c void xtensa_cpu_list(FILE *f, fprintf_function cpu_fprintf) · line 274
Quoted 10 lines
target/xtensa/helper.c +10
-0+ access, mmu_idx, page_size); + return true; + } +if (probe) { +return false; + } +#endif + +cpu_restore_state (cs, retaddr, true); +HELPER (exception_cause_vaddr)(env, env->pc, ret, vaddr);
...but now we'll set it to whatever exception_cause_vaddr does, which is something more complicated based on the state of env->sregs[PS].
We'll also end up setting env->sregs[PS] bits and env->pc, which the old code did not. (In particular since we set the PS_EXCM bit, the second time we take an exception won't we then end up setting exception_index to EXC_DOUBLE, not EXC_USER ?)
thanks
-- PMM
Re: [Qemu-devel] [PATCH 23/26] target/xtensa: Convert to CPUClass::tlb_fill
Quoted 66 lines · Peter Maydell
Quoted 19 lines · Richard Henderson
Cc Max Filippov <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- target/xtensa/cpu.h | 5 +-- target/xtensa/cpu.c | 5 ++- target/xtensa/helper.c | 74 +++++++++++++++++++++--------------------- 3 files changed, 42 insertions(+), 42 deletions(-)target/xtensa/helper.c +3
-4-#ifdef CONFIG_USER_ONLY - -int xtensa_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int size,int rw, -int mmu_idx) +bool xtensa_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr) {XtensaCPU *cpu =XTENSA_CPU (cs);CPUXtensaState *env = &cpu->env;target/xtensa/helper.c void xtensa_cpu_list(FILE *f, fprintf_function cpu_fprintf) · line 254
Quoted 10 lines
target/xtensa/helper.c +2
-7+target_ulong vaddr = address; +int ret; -qemu_log_mask (CPU_LOG_INT , -"%s: rw = %d, address = 0x%08" VADDR_PRIx", size = %d\n" , - __func__, rw, address, size); - env->sregs[EXCVADDR ] = address; - env->sregs[EXCCAUSE ] = rw ?STORE_PROHIBITED_CAUSE :LOAD_PROHIBITED_CAUSE ; - cs->exception_index =EXC_USER ; -return 1 ;Previously we set
exception_indextoEXC_USER...Quoted 16 lines
target/xtensa/helper.c +16
-0+#ifdef CONFIG_USER_ONLY + ret = (access_type ==MMU_DATA_STORE ? +STORE_PROHIBITED_CAUSE :LOAD_PROHIBITED_CAUSE ); +#else +uint32_t paddr; +uint32_t page_size; +unsigned access; + + ret =xtensa_get_physical_addr (env, true, vaddr, access_type, mmu_idx, + &paddr, &page_size, &access); + +qemu_log_mask (CPU_LOG_MMU ,"%s(%08x, %d, %d) -> %08x, ret = %d\n" , + __func__, vaddr, access_type, mmu_idx, paddr, ret); + +if (ret ==0 ) { + tlb_set_page(cs, vaddr & TARGET_PAGE_MASK, paddr & TARGET_PAGE_MASK,target/xtensa/helper.c void xtensa_cpu_list(FILE *f, fprintf_function cpu_fprintf) · line 274
Quoted 10 lines
target/xtensa/helper.c +10
-0+ access, mmu_idx, page_size); + return true; + } +if (probe) { +return false; + } +#endif + +cpu_restore_state (cs, retaddr, true); +HELPER (exception_cause_vaddr)(env, env->pc, ret, vaddr);...but now we'll set it to whatever
exception_cause_vaddrdoes, which is something more complicated based on the state of env->sregs[PS].
Quoted 4 lines
We'll also end up setting env->sregs[PS] bits and
env->pc, which the old code did not. (In particular since we set thePS_EXCMbit, the second time we take an exception won't we then end up settingexception_indextoEXC_DOUBLE, notEXC_USER?)
I guess it doesn't matter, because linux-user userspace never handles exceptions. PS, PC and similar must be fixed up by the linux-user exception handler. But I haven't tested it.
Richard, is there a branch with this series available somewhere?
Signature · 2 lines
Thanks. -- Max
Re: [Qemu-devel] [PATCH 23/26] target/xtensa: Convert to CPUClass::tlb_fill
Quoted 67 lines · Max Filippov
Quoted 66 lines · Peter Maydell
Quoted 19 lines · Richard Henderson
Cc Max Filippov <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- target/xtensa/cpu.h | 5 +-- target/xtensa/cpu.c | 5 ++- target/xtensa/helper.c | 74 +++++++++++++++++++++--------------------- 3 files changed, 42 insertions(+), 42 deletions(-)target/xtensa/helper.c +3
-4-#ifdef CONFIG_USER_ONLY - -int xtensa_cpu_handle_mmu_fault (CPUState *cs,vaddr address,int size,int rw, -int mmu_idx) +bool xtensa_cpu_tlb_fill (CPUState *cs,vaddr address,int size, +MMUAccessType access_type,int mmu_idx, +bool probe,uintptr_t retaddr) {XtensaCPU *cpu =XTENSA_CPU (cs);CPUXtensaState *env = &cpu->env;target/xtensa/helper.c void xtensa_cpu_list(FILE *f, fprintf_function cpu_fprintf) · line 254
Quoted 10 lines
target/xtensa/helper.c +2
-7+target_ulong vaddr = address; +int ret; -qemu_log_mask (CPU_LOG_INT , -"%s: rw = %d, address = 0x%08" VADDR_PRIx", size = %d\n" , - __func__, rw, address, size); - env->sregs[EXCVADDR ] = address; - env->sregs[EXCCAUSE ] = rw ?STORE_PROHIBITED_CAUSE :LOAD_PROHIBITED_CAUSE ; - cs->exception_index =EXC_USER ; -return 1 ;Previously we set
exception_indextoEXC_USER...Quoted 16 lines
target/xtensa/helper.c +16
-0+#ifdef CONFIG_USER_ONLY + ret = (access_type ==MMU_DATA_STORE ? +STORE_PROHIBITED_CAUSE :LOAD_PROHIBITED_CAUSE ); +#else +uint32_t paddr; +uint32_t page_size; +unsigned access; + + ret =xtensa_get_physical_addr (env, true, vaddr, access_type, mmu_idx, + &paddr, &page_size, &access); + +qemu_log_mask (CPU_LOG_MMU ,"%s(%08x, %d, %d) -> %08x, ret = %d\n" , + __func__, vaddr, access_type, mmu_idx, paddr, ret); + +if (ret ==0 ) { + tlb_set_page(cs, vaddr & TARGET_PAGE_MASK, paddr & TARGET_PAGE_MASK,target/xtensa/helper.c void xtensa_cpu_list(FILE *f, fprintf_function cpu_fprintf) · line 274
Quoted 10 lines
target/xtensa/helper.c +10
-0+ access, mmu_idx, page_size); + return true; + } +if (probe) { +return false; + } +#endif + +cpu_restore_state (cs, retaddr, true); +HELPER (exception_cause_vaddr)(env, env->pc, ret, vaddr);...but now we'll set it to whatever
exception_cause_vaddrdoes, which is something more complicated based on the state of env->sregs[PS].
Quoted 8 lines
Quoted 4 lines
We'll also end up setting env->sregs[PS] bits and
env->pc, which the old code did not. (In particular since we set thePS_EXCMbit, the second time we take an exception won't we then end up settingexception_indextoEXC_DOUBLE, notEXC_USER?)I guess it doesn't matter, because linux-user userspace never handles exceptions. PS, PC and similar must be fixed up by the linux-user exception handler. But I haven't tested it.
It does handle exceptions, in linux-user/xtensa/cpu_loop.c. And Peter's right that I should have kept EXC_USER.
Quoted 1 line
Richard, is there a branch with this series available somewhere?
https://github.com/rth7680/qemu/tree/tcg-tlb-fill
r~
Re: [Qemu-devel] [PATCH 23/26] target/xtensa: Convert to CPUClass::tlb_fill
Quoted 11 lines · Richard Henderson
Quoted 10 lines · Max Filippov
Quoted 8 lines · Peter Maydell
...but now we'll set it to whatever
exception_cause_vaddrdoes, which is something more complicated based on the state of env->sregs[PS].We'll also end up setting env->sregs[PS] bits and
env->pc, which the old code did not. (In particular since we set thePS_EXCMbit, the second time we take an exception won't we then end up settingexception_indextoEXC_DOUBLE, notEXC_USER?)
Quoted 6 lines
Quoted 3 lines
I guess it doesn't matter, because linux-user userspace never handles exceptions. PS, PC and similar must be fixed up by the linux-user exception handler. But I haven't tested it.
It does handle exceptions, in
linux-user/xtensa/cpu_loop.c. And Peter's right that I should have keptEXC_USER.
PC must also either be preserved or restored from the EPC1 in the cpu_loop for the SYSCALL_CAUSE.
Quoted 2 lines
Quoted 1 line
Richard, is there a branch with this series available somewhere?
Thanks, I'll try it.
Signature · 2 lines
Thanks. -- Max
Re: [Qemu-devel] [PATCH 23/26] target/xtensa: Convert to CPUClass::tlb_fill
Quoted 2 lines · Max Filippov
On Tue, Apr 30, 2019 at 10:44 AM Richard Henderson
Quoted 1 line
And Peter's right that I should have kept
EXC_USER.
It appears to work as is: the EXC_USER is set up by the exception_cause helper because there's always PS_U in the PS, PS_EXCM is cleared in the cpu_loop and the current PC is preserved by the xtensa_cpu_tlb_fill. I'll play with it some more...
Signature · 2 lines
Thanks. -- Max
Re: [Qemu-devel] [PATCH 23/26] target/xtensa: Convert to CPUClass::tlb_fill
Quoted 9 lines · Max Filippov
Quoted 2 lines · Max Filippov
On Tue, Apr 30, 2019 at 10:44 AM Richard Henderson
Quoted 1 line
And Peter's right that I should have kept
EXC_USER.It appears to work as is: the
EXC_USERis set up by theexception_causehelper because there's alwaysPS_Uin the PS,PS_EXCMis cleared in thecpu_loopand the current PC is preserved by thextensa_cpu_tlb_fill. I'll play with it some more...
I've run gcc/uclibc testsuites for xtensa-linux with this series as is, got no new regressions.
Signature · 2 lines
Thanks. -- Max
PATCH 24/26 tcg: Use CPUClass::tlb_fill in cputlb.c
In reply to Richard HendersonWe can now use the CPUClass hook instead of a named function.
Create a static tlb_fill function to avoid other changes within cputlb.c. This also which also isolates the asserts implied. Remove the named tlb_fill function from all of the targets.
--- include/exec/exec-all.h | 9 --------- accel/tcg/cputlb.c | 19 +++++++++++++++++++ target/alpha/helper.c | 8 -------- target/arm/helper.c | 8 -------- target/cris/helper.c | 6 ------ target/hppa/mem_helper.c | 6 ------ target/i386/excp_helper.c | 8 -------- target/lm32/helper.c | 6 ------ target/m68k/helper.c | 8 -------- target/microblaze/helper.c | 8 -------- target/mips/helper.c | 6 ------ target/moxie/helper.c | 6 ------ target/nios2/helper.c | 8 -------- target/openrisc/mmu.c | 6 ------ target/ppc/mmu_helper.c | 6 ------ target/riscv/cpu_helper.c | 6 ------ target/s390x/excp_helper.c | 6 ------ target/sh4/helper.c | 8 -------- target/sparc/mmu_helper.c | 8 -------- target/tricore/helper.c | 6 ------ target/unicore32/softmmu.c | 6 ------ target/xtensa/helper.c | 6 ------ 22 files changed, 19 insertions(+), 145 deletions(-)
include/exec/exec-all.h +0 -9
@@ -474,15 +474,6 @@ static inline void assert_no_pages_locked(void)*/ struct MemoryRegionSection *iotlb_to_section (CPUState *cpu,hwaddr index,MemTxAttrs attrs); - -/* -* Note: tlb_fill() can trigger a resize of the TLB. This means that all of the -* caller's prior references to the TLB table (e.g. CPUTLBEntry pointers) must -* be discarded and looked up again (e.g. via tlb_entry()). -*/ -void tlb_fill (CPUState *cpu,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr); -#endif #if defined(CONFIG_USER_ONLY )
accel/tcg/cputlb.c +19 -0
@@ -855,6 +855,25 @@ static inline ram_addr_t qemu_ram_addr_from_host_nofail(void *ptr)return ram_addr; } +/* +* Note: tlb_fill() can trigger a resize of the TLB. This means that all of the +* caller's prior references to the TLB table (e.g. CPUTLBEntry pointers) must +* be discarded and looked up again (e.g. via tlb_entry()). +*/ +static void tlb_fill (CPUState *cpu,target_ulong addr,int size, +MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); +bool ok; + +/* +* This is not a probe, so only valid return is success; failure +* should result in exception + longjmp to the cpu loop. +*/ + ok = cc->tlb_fill (cpu, addr, size, access_type, mmu_idx, false, retaddr); +g_assert (ok); +} + static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry, int mmu_idx, target_ulong addr, uintptr_t retaddr,
target/alpha/helper.c +0 -8
@@ -272,14 +272,6 @@ bool alpha_cpu_tlb_fill(CPUState *cs, vaddr address, int size,#endif } -#ifndef CONFIG_USER_ONLY -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -alpha_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); -} -#endif -void alpha_cpu_do_interrupt (CPUState *cs) {AlphaCPU *cpu =ALPHA_CPU (cs);
target/arm/helper.c +0 -8
@@ -12404,14 +12404,6 @@ bool arm_cpu_tlb_fill(CPUState *cs, vaddr address, int size,#endif } -#ifndef CONFIG_USER_ONLY -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -arm_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); -} -#endif -void HELPER (dc_zva )(CPUARMState *env,uint64_t vaddr_in) {/* Implement DC ZVA, which zeroes a fixed-length block of memory.
target/cris/helper.c +0 -6
@@ -123,12 +123,6 @@ bool cris_cpu_tlb_fill(CPUState *cs, vaddr address, int size,cpu_loop_exit (cs); } -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -cris_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); -} -void crisv10_cpu_do_interrupt (CPUState *cs) {CRISCPU *cpu =CRIS_CPU (cs);
target/hppa/mem_helper.c +0 -6
@@ -261,12 +261,6 @@ bool hppa_cpu_tlb_fill(CPUState *cs, vaddr addr, int size,return true; } -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType type,int mmu_idx,uintptr_t retaddr) -{ -hppa_cpu_tlb_fill (cs, addr, size, type, mmu_idx, false, retaddr); -} -/* Insert (Insn/Data) TLB Address. Note this is PA 1.1 only. */ void HELPER (itlba )(CPUHPPAState *env,target_ulong addr,target_ureg reg) {
target/i386/excp_helper.c +0 -8
@@ -700,11 +700,3 @@ bool x86_cpu_tlb_fill(CPUState *cs, vaddr addr, int size,return true;#endif } - -#if !defined(CONFIG_USER_ONLY ) -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -x86_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); -} -#endif
target/lm32/helper.c +0 -6
@@ -44,12 +44,6 @@ bool lm32_cpu_tlb_fill(CPUState *cs, vaddr address, int size,return true; } -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -lm32_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); -} -hwaddr lm32_cpu_get_phys_page_debug (CPUState *cs,vaddr addr) {LM32CPU *cpu =LM32_CPU (cs);
target/m68k/helper.c +0 -8
@@ -893,14 +893,6 @@ bool m68k_cpu_tlb_fill(CPUState *cs, vaddr address, int size,cpu_loop_exit_restore (cs, retaddr); } -#ifndef CONFIG_USER_ONLY -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -m68k_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); -} -#endif -uint32_t HELPER (bitrev )(uint32_t x) { x = ((x >>1 ) &0x55555555u ) | ((x <<1 ) &0xaaaaaaaau );
target/microblaze/helper.c +0 -8
@@ -89,14 +89,6 @@ bool mb_cpu_tlb_fill(CPUState *cs, vaddr address, int size,cpu_loop_exit_restore (cs, retaddr); } -#ifndef CONFIG_USER_ONLY -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -mb_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); -} -#endif -#ifdef CONFIG_USER_ONLY void mb_cpu_do_interrupt (CPUState *cs)
target/mips/helper.c +0 -6
@@ -944,12 +944,6 @@ bool mips_cpu_tlb_fill(CPUState *cs, vaddr address, int size, }#ifndef CONFIG_USER_ONLY -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -mips_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); -} -hwaddr cpu_mips_translate_address (CPUMIPSState *env,target_ulong address,int rw) {hwaddr physical;
target/moxie/helper.c +0 -6
@@ -26,12 +26,6 @@#include "qemu/host-utils.h" #include "exec/helper-proto.h" -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -moxie_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); -} -void helper_raise_exception (CPUMoxieState *env,int ex) {CPUState *cs =CPU (moxie_env_get_cpu (env));
target/nios2/helper.c +0 -8
@@ -294,11 +294,3 @@ bool nios2_cpu_tlb_fill(CPUState *cs, vaddr address, int size, env->regs[CR_BADADDR ] = address;cpu_loop_exit_restore (cs, retaddr); } - -#ifndef CONFIG_USER_ONLY -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -nios2_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); -} -#endif
target/openrisc/mmu.c +0 -6
@@ -178,10 +178,4 @@ hwaddr openrisc_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) return phys_addr; } } - -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -openrisc_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx,0 , retaddr); -}#endif
target/ppc/mmu_helper.c +0 -6
@@ -3049,9 +3049,3 @@ bool ppc_cpu_tlb_fill(CPUState *cs, vaddr addr, int size, }return true; } - -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -ppc_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); -}
target/riscv/cpu_helper.c +0 -6
@@ -378,12 +378,6 @@ void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr, env->badaddr = addr;riscv_raise_exception (env, cs->exception_index, retaddr); } - -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -riscv_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); -}#endif bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
target/s390x/excp_helper.c +0 -6
@@ -76,12 +76,6 @@ void s390_cpu_do_interrupt(CPUState *cs)#else /* !CONFIG_USER_ONLY */ -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -s390_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); -} -static inline uint64_t cpu_mmu_idx_to_asc (int mmu_idx) {switch (mmu_idx) {
target/sh4/helper.c +0 -8
@@ -872,11 +872,3 @@ bool superh_cpu_tlb_fill(CPUState *cs, vaddr address, int size, }cpu_loop_exit_restore (cs, retaddr); } - -#ifndef CONFIG_USER_ONLY -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -superh_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); -} -#endif
target/sparc/mmu_helper.c +0 -8
@@ -858,11 +858,3 @@ bool sparc_cpu_tlb_fill(CPUState *cs, vaddr address, int size,cpu_loop_exit_restore (cs, retaddr); } - -#ifndef CONFIG_USER_ONLY -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -sparc_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); -} -#endif
target/tricore/helper.c +0 -6
@@ -84,12 +84,6 @@ bool tricore_cpu_tlb_fill(CPUState *cs, vaddr address, int size, } } -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -tricore_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); -} -static void tricore_cpu_list_entry (gpointer data,gpointer user_data) {ObjectClass *oc = data;
target/unicore32/softmmu.c +0 -6
@@ -275,12 +275,6 @@ bool uc32_cpu_tlb_fill(CPUState *cs, vaddr address, int size,cpu_loop_exit_restore (cs, retaddr); } -void tlb_fill (CPUState *cs,target_ulong addr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -uc32_cpu_tlb_fill (cs, addr, size, access_type, mmu_idx, false, retaddr); -} -hwaddr uc32_cpu_get_phys_page_debug (CPUState *cs,vaddr addr) { error_report("function uc32_cpu_get_phys_page_debug not "
target/xtensa/helper.c +0 -6
@@ -275,12 +275,6 @@ bool xtensa_cpu_tlb_fill(CPUState *cs, vaddr address, int size, }#ifndef CONFIG_USER_ONLY -void tlb_fill (CPUState *cs,target_ulong vaddr,int size, -MMUAccessType access_type,int mmu_idx,uintptr_t retaddr) -{ -xtensa_cpu_tlb_fill (cs, vaddr, size, access_type, mmu_idx, false, retaddr); -} -void xtensa_cpu_do_unaligned_access (CPUState *cs,vaddr addr,MMUAccessType access_type,int mmu_idx,uintptr_t retaddr)
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 24/26] tcg: Use CPUClass::tlb_fill in cputlb.c
Quoted 5 lines · Richard Henderson
We can now use the CPUClass hook instead of a named function.
Create a static
tlb_fillfunction to avoid other changes withincputlb.c. This also which also isolates the asserts implied.
I'm not sure what this sentence is trying to say ?
Quoted 3 lines
Remove the named
tlb_fillfunction from all of the targets.Signed-off-by Richard Henderson <[email protected]>
otherwise
thanks
-- PMM
Philippe Mathieu-Daudé
Reviewed-byRe: [Qemu-devel] [PATCH 24/26] tcg: Use CPUClass::tlb_fill in cputlb.c
Quoted 9 lines · Peter Maydell
Quoted 5 lines · Richard Henderson
We can now use the CPUClass hook instead of a named function.
Create a static
tlb_fillfunction to avoid other changes withincputlb.c. This also which also isolates the asserts implied.I'm not sure what this sentence is trying to say ?
s/which also// ?
Quoted 7 lines
Quoted 4 lines
Remove the named
tlb_fillfunction from all of the targets.Signed-off-by Richard Henderson <[email protected]>otherwise
Reviewed-by Peter Maydell <[email protected]>
PATCH 25/26 tcg: Remove CPUClass::handle_mmu_fault
In reply to Richard HendersonThis hook is now completely replaced by tlb_fill.
--- include/qom/cpu.h | 3 --- accel/tcg/user-exec.c | 13 +++---------- 2 files changed, 3 insertions(+), 13 deletions(-)
include/qom/cpu.h +0 -3
@@ -118,7 +118,6 @@ struct TranslationBlock;* This always includes at least the program counter; some targets * will need to do more. If this hook is not implemented then the * default is to call @set_pc(tb->pc). -* @handle_mmu_fault: Callback for handling an MMU fault. * @tlb_fill: Callback for handling a softmmu tlb miss or user-only * address fault. For system mode, if the access is valid, call * tlb_set_page and return true; if the access is invalid, and
@@ -198,8 +197,6 @@ typedef struct CPUClass { Error **errp);void (*set_pc)(CPUState *cpu,vaddr value);void (*synchronize_from_tb)(CPUState *cpu,struct TranslationBlock *tb); -int (*handle_mmu_fault)(CPUState *cpu,vaddr address,int size,int rw, -int mmu_index);bool (*tlb_fill)(CPUState *cpu,vaddr address,int size,MMUAccessType access_type,int mmu_idx,bool probe,uintptr_t retaddr);
accel/tcg/user-exec.c +3 -10
@@ -63,7 +63,6 @@ static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, {CPUState *cpu = current_cpu;CPUClass *cc; -int ret;unsigned long address = (unsigned long )info->si_addr;MMUAccessType access_type;
@@ -162,15 +161,9 @@ static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, helper_retaddr =0 ; cc =CPU_GET_CLASS (cpu); -if (cc->tlb_fill) { - access_type = is_write ?MMU_DATA_STORE :MMU_DATA_LOAD ; - cc->tlb_fill (cpu, address,0 , access_type,MMU_USER_IDX , false, pc); -g_assert_not_reached (); - }else { - ret = cc->handle_mmu_fault (cpu, address,0 , is_write,MMU_USER_IDX ); -g_assert (ret >0 ); -cpu_loop_exit_restore (cpu, pc); - } + access_type = is_write ?MMU_DATA_STORE :MMU_DATA_LOAD ; + cc->tlb_fill (cpu, address,0 , access_type,MMU_USER_IDX , false, pc); +g_assert_not_reached (); }#if defined(__i386__)
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 25/26] tcg: Remove CPUClass::handle_mmu_fault
Quoted 4 lines · Richard Henderson
This hook is now completely replaced by
tlb_fill.Signed-off-by Richard Henderson <[email protected]>
thanks
-- PMM
Re: [Qemu-devel] [PATCH 25/26] tcg: Remove CPUClass::handle_mmu_fault
In reply to Richard HendersonQuoted 3 lines · Richard Henderson
This hook is now completely replaced by
tlb_fill.Signed-off-by Richard Henderson <[email protected]>
Quoted 58 lines
--- include/qom/cpu.h | 3 --- accel/tcg/user-exec.c | 13 +++---------- 2 files changed, 3 insertions(+), 13 deletions(-)include/qom/cpu.h +0
-3@@ -118,7 +118,6 @@ struct TranslationBlock;* This always includes at least the program counter; some targets * will need to do more. If this hook is not implemented then the * default is to call @set_pc(tb->pc). -* @handle_mmu_fault: Callback for handling an MMU fault. * @tlb_fill: Callback for handling a softmmu tlb miss or user-only * address fault. For system mode, if the access is valid, call * tlb_set_page and return true; if the access is invalid, and @@ -198,8 +197,6 @@ typedef struct CPUClass { Error **errp);void (*set_pc)(CPUState *cpu,vaddr value);void (*synchronize_from_tb)(CPUState *cpu,struct TranslationBlock *tb); -int (*handle_mmu_fault)(CPUState *cpu,vaddr address,int size,int rw, -int mmu_index);bool (*tlb_fill)(CPUState *cpu,vaddr address,int size,MMUAccessType access_type,int mmu_idx,bool probe,uintptr_t retaddr);accel/tcg/user-exec.c +3
-10@@ -63,7 +63,6 @@ static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, {CPUState *cpu = current_cpu;CPUClass *cc; -int ret;unsigned long address = (unsigned long )info->si_addr;MMUAccessType access_type;@@ -162,15 +161,9 @@ static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, helper_retaddr =0 ; cc =CPU_GET_CLASS (cpu); -if (cc->tlb_fill) { - access_type = is_write ?MMU_DATA_STORE :MMU_DATA_LOAD ; - cc->tlb_fill (cpu, address,0 , access_type,MMU_USER_IDX , false, pc); -g_assert_not_reached (); - }else { - ret = cc->handle_mmu_fault (cpu, address,0 , is_write,MMU_USER_IDX ); -g_assert (ret >0 ); -cpu_loop_exit_restore (cpu, pc); - } + access_type = is_write ?MMU_DATA_STORE :MMU_DATA_LOAD ; + cc->tlb_fill (cpu, address,0 , access_type,MMU_USER_IDX , false, pc); +g_assert_not_reached (); }#if defined(__i386__)
PATCH 26/26 tcg: Use tlb_fill probe from tlb_vaddr_to_host
In reply to Richard HendersonMost of the existing users would continue around a loop which would fault the tlb entry in via a normal load/store. But for SVE we have a true non-faulting case which requires the new probing form of tlb_fill.
--- include/exec/cpu_ldst.h | 40 ++++-------------------- accel/tcg/cputlb.c | 69 ++++++++++++++++++++++++++++++++++++----- target/arm/sve_helper.c | 6 +--- 3 files changed, 68 insertions(+), 47 deletions(-)
include/exec/cpu_ldst.h +6 -34
@@ -440,43 +440,15 @@ static inline CPUTLBEntry *tlb_entry(CPUArchState *env, uintptr_t mmu_idx,* This is the equivalent of the initial fast-path code used by * TCG backends for guest load and store accesses. */ +#ifdef CONFIG_USER_ONLY static inline void *tlb_vaddr_to_host (CPUArchState *env,abi_ptr addr, -int access_type,int mmu_idx) +MMUAccessType access_type,int mmu_idx) { -#if defined(CONFIG_USER_ONLY )return g2h (addr); -#else -CPUTLBEntry *tlbentry =tlb_entry (env, mmu_idx, addr); -abi_ptr tlb_addr; -uintptr_t haddr; - -switch (access_type) { -case 0 : - tlb_addr = tlbentry->addr_read; -break ; -case 1 : - tlb_addr =tlb_addr_write (tlbentry); -break ; -case 2 : - tlb_addr = tlbentry->addr_code; -break ; -default : -g_assert_not_reached (); - } - -if (!tlb_hit (tlb_addr, addr)) { -/* TLB entry is for a different page */ -return NULL ; - } - -if (tlb_addr & ~TARGET_PAGE_MASK ) { -/* IO access */ -return NULL ; - } - - haddr = addr + tlbentry->addend; -return (void *)haddr; -#endif /* defined(CONFIG_USER_ONLY) */ } +#else +void *tlb_vaddr_to_host (CPUArchState *env,abi_ptr addr, +MMUAccessType access_type,int mmu_idx); +#endif #endif /* CPU_LDST_H */
accel/tcg/cputlb.c +61 -8
87 lines not on this page · raw message
target/arm/sve_helper.c +1 -5
@@ -4598,11 +4598,7 @@ static void sve_ldnf1_r(CPUARMState *env, void *vg, const target_ulong addr,* in the real world, obviously.) * * Then there are the annoying special cases with watchpoints... -* -* TODO: Add a form of tlb_fill that does not raise an exception, -* with a form of tlb_vaddr_to_host and a set of loads to match. -* The non_fault_vaddr_to_host would handle everything, usually, -* and the loads would handle the iomem path for watchpoints. +* TODO: Add a form of non-faulting loads using cc->tlb_fill(probe=true). */ host =tlb_vaddr_to_host (env, addr + mem_off,MMU_DATA_LOAD , mmu_idx); split =max_for_page (addr, mem_off, mem_max);
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 26/26] tcg: Use tlb_fill probe from tlb_vaddr_to_host
Quoted 5 lines · Richard Henderson
Most of the existing users would continue around a loop which would fault the tlb entry in via a normal load/store. But for SVE we have a true non-faulting case which requires the new probing form of
tlb_fill.
So am I right in thinking that this fixes a bug where we previously would mark a load as faulted if the memory happened not to be in the TLB, whereas now we will correctly pull in the TLB entry and do the load ?
(Since guest code ought to be handling the "non-first-load faulted" case by looping round or otherwise arranging to retry, nothing in practice would have noticed this bug, right?)
Quoted 12 lines
Signed-off-by Richard Henderson <[email protected]>--- include/exec/cpu_ldst.h | 40 ++++-------------------- accel/tcg/cputlb.c | 69 ++++++++++++++++++++++++++++++++++++----- target/arm/sve_helper.c | 6 +--- 3 files changed, 68 insertions(+), 47 deletions(-)include/exec/cpu_ldst.h +0
-0
include/exec/cpu_ldst.h static inline CPUTLBEntry *tlb_entry(CPUArchState *env, uintptr_t mmu_idx, · line 442
Quoted 3 lines
include/exec/cpu_ldst.h +0
-0@@ -440,43 +440,15 @@ static inline CPUTLBEntry *tlb_entry(CPUArchState *env, uintptr_t mmu_idx,* This is the equivalent of the initial fast-path code used by * TCG backends for guest load and store accesses. */
The doc comment which this is the last two lines of needs updating, I think -- with the changed implementation it's no longer just the equivalent of the fast-path bit of code, and it doesn't return NULL on a TLB miss any more.
Otherwise
thanks
-- PMM
Re: [Qemu-devel] [PATCH 26/26] tcg: Use tlb_fill probe from tlb_vaddr_to_host
Quoted 8 lines · Peter Maydell
Quoted 5 lines · Richard Henderson
Most of the existing users would continue around a loop which would fault the tlb entry in via a normal load/store. But for SVE we have a true non-faulting case which requires the new probing form of
tlb_fill.
Quoted 4 lines
So am I right in thinking that this fixes a bug where we previously would mark a load as faulted if the memory happened not to be in the TLB, whereas now we will correctly pull in the TLB entry and do the load ?
Yes.
Quoted 3 lines
(Since guest code ought to be handling the "non-first-load faulted" case by looping round or otherwise arranging to retry, nothing in practice would have noticed this bug, right?)
Yes.
The only case with changed behaviour is (expected to be) SVE no-fault, where the loop you mention would have produced different incorrect results.
r~
Re: [Qemu-devel] [PATCH 26/26] tcg: Use tlb_fill probe from tlb_vaddr_to_host
Quoted 17 lines · Richard Henderson
Quoted 8 lines · Peter Maydell
Quoted 5 lines · Richard Henderson
Most of the existing users would continue around a loop which would fault the tlb entry in via a normal load/store. But for SVE we have a true non-faulting case which requires the new probing form of
tlb_fill.Quoted 4 lines
So am I right in thinking that this fixes a bug where we previously would mark a load as faulted if the memory happened not to be in the TLB, whereas now we will correctly pull in the TLB entry and do the load ?
Yes.
Quoted 8 lines
Quoted 3 lines
(Since guest code ought to be handling the "non-first-load faulted" case by looping round or otherwise arranging to retry, nothing in practice would have noticed this bug, right?)
Yes.
The only case with changed behaviour is (expected to be) SVE no-fault, where the loop you mention would have produced different incorrect results.
OK. If we're fixing a guest-visible bug it would be nice to describe that in the commit message.
thanks
-- PMM
Re: [Qemu-devel] [PATCH 26/26] tcg: Use tlb_fill probe from tlb_vaddr_to_host
Quoted 23 lines · Peter Maydell
Quoted 21 lines · Richard Henderson
Quoted 8 lines · Peter Maydell
Quoted 5 lines · Richard Henderson
Most of the existing users would continue around a loop which would fault the tlb entry in via a normal load/store. But for SVE we have a true non-faulting case which requires the new probing form of
tlb_fill.Quoted 4 lines
So am I right in thinking that this fixes a bug where we previously would mark a load as faulted if the memory happened not to be in the TLB, whereas now we will correctly pull in the TLB entry and do the load ?
Yes.
Quoted 3 lines
(Since guest code ought to be handling the "non-first-load faulted" case by looping round or otherwise arranging to retry, nothing in practice would have noticed this bug, right?)
Quoted 7 lines
Quoted 4 lines
Yes.
The only case with changed behaviour is (expected to be) SVE no-fault, where the loop you mention would have produced different incorrect results.
OK. If we're fixing a guest-visible bug it would be nice to describe that in the commit message.
The commit message now reads, in part,
But for AArch64 SVE we have an existing emulation bug wherein we would mark the first element of a no-fault vector load as faulted (within the FFR, not via exception) just because we did not have its address in the TLB. Now we can properly only mark it as faulted if there really is no valid, readable translation, while still not raising an exception. (Note that beyond the first element of the vector, the hardware may report a fault for any reason whatsoever; with at least one element loaded, forward progress is guaranteed.)
r~