Replace remaining target_ulong in system-mode accel
cover Replace remaining target_ulong in system-mode accel
This patchset replaces the remaining uses of target_ulong in the accel/ directory. Specifically, the address type of a few kvm/hvf functions is widened to vaddr, and the address type of the cpu_[st|ld]*() functions is changed to abi_ptr (which is re-typedef'd to vaddr in system mode).
As a starting point, my goal is to be able to build cputlb.c once for system mode, and this is a step in that direction by reducing the target-dependence of accel/.
* Changes in v2:
- Removed explicit target_ulong casts from 3rd and 4th patches.
Anton Johansson (9):
accel/kvm: Widen pc/saved_insn for kvm_sw_breakpoint accel/hvf: Widen pc/saved_insn for hvf_sw_breakpoint
target: Use vaddr for kvm_arch_[insert|remove]_hw_breakpoint
target: Use vaddr for hvf_arch_[insert|remove]_hw_breakpoint Replace target_ulong with abi_ptr in cpu_[st|ld]*() include/exec: typedef abi_ptr to vaddr in softmmu include/exec: Widen tlb_hit/tlb_hit_page() accel/tcg: Widen address arg. in tlb_compare_set() accel/tcg: Update run_on_cpu_data static assert
accel/tcg/atomic_template.h | 16 ++++++++-------- include/exec/cpu-all.h | 4 ++-- include/exec/cpu_ldst.h | 28 ++++++++++++++-------------- include/sysemu/hvf.h | 12 +++++------- include/sysemu/kvm.h | 12 +++++------- accel/hvf/hvf-accel-ops.c | 4 ++-- accel/hvf/hvf-all.c | 2 +- accel/kvm/kvm-all.c | 3 +-- accel/tcg/cputlb.c | 17 +++++++++-------- target/arm/hvf/hvf.c | 4 ++-- target/arm/kvm64.c | 6 ++---- target/i386/hvf/hvf.c | 4 ++-- target/i386/kvm/kvm.c | 8 +++----- target/ppc/kvm.c | 13 ++++++------- target/riscv/vector_helper.c | 2 +- target/rx/op_helper.c | 6 +++--- target/s390x/kvm/kvm.c | 6 ++---- 17 files changed, 68 insertions(+), 79 deletions(-)
--
2.41.0
PATCH v2 1/9 accel/kvm: Widen pc/saved_insn for kvm_sw_breakpoint
Widens the pc and saved_insn fields of kvm_sw_breakpoint from target_ulong to vaddr. The pc argument of kvm_find_sw_breakpoint is also widened to match.
--- include/sysemu/kvm.h | 6 +++--- accel/kvm/kvm-all.c | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-)
include/sysemu/kvm.h +3 -3
@@ -411,14 +411,14 @@ struct kvm_guest_debug;struct kvm_debug_exit_arch ;struct kvm_sw_breakpoint { -target_ulong pc; -target_ulong saved_insn; +vaddr pc; +vaddr saved_insn;int use_count;QTAILQ_ENTRY (kvm_sw_breakpoint) entry; };struct kvm_sw_breakpoint *kvm_find_sw_breakpoint (CPUState *cpu, -target_ulong pc); +vaddr pc);int kvm_sw_breakpoints_active (CPUState *cpu);
accel/kvm/kvm-all.c +1 -2
@@ -3306,8 +3306,7 @@ bool kvm_arm_supports_user_irq(void) }#ifdef KVM_CAP_SET_GUEST_DEBUG -struct kvm_sw_breakpoint *kvm_find_sw_breakpoint (CPUState *cpu, -target_ulong pc) +struct kvm_sw_breakpoint *kvm_find_sw_breakpoint (CPUState *cpu,vaddr pc) {struct kvm_sw_breakpoint *bp;
Signature · 1 line
2.41.0
PATCH v2 2/9 accel/hvf: Widen pc/saved_insn for hvf_sw_breakpoint
In reply to Anton Johansson viaWidens the pc and saved_insn fields of hvf_sw_breakpoint from target_ulong to vaddr. Other hvf_* functions accessing hvf_sw_breakpoint are also widened to match.
--- include/sysemu/hvf.h | 6 +++--- accel/hvf/hvf-accel-ops.c | 4 ++-- accel/hvf/hvf-all.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-)
include/sysemu/hvf.h +3 -3
@@ -39,14 +39,14 @@ DECLARE_INSTANCE_CHECKER(HVFState, HVF_STATE,#ifdef NEED_CPU_H struct hvf_sw_breakpoint { -target_ulong pc; -target_ulong saved_insn; +vaddr pc; +vaddr saved_insn;int use_count;QTAILQ_ENTRY (hvf_sw_breakpoint) entry; };struct hvf_sw_breakpoint *hvf_find_sw_breakpoint (CPUState *cpu, -target_ulong pc); +vaddr pc);int hvf_sw_breakpoints_active (CPUState *cpu);int hvf_arch_insert_sw_breakpoint (CPUState *cpu,struct hvf_sw_breakpoint *bp);
accel/hvf/hvf-accel-ops.c +2 -2
@@ -474,7 +474,7 @@ static void hvf_start_vcpu_thread(CPUState *cpu) cpu, QEMU_THREAD_JOINABLE); } -static int hvf_insert_breakpoint (CPUState *cpu,int type,hwaddr addr,hwaddr len) +static int hvf_insert_breakpoint (CPUState *cpu,int type,vaddr addr,vaddr len) {struct hvf_sw_breakpoint *bp;int err;
@@ -512,7 +512,7 @@ static int hvf_insert_breakpoint(CPUState *cpu, int type, hwaddr addr, hwaddr lereturn 0 ; } -static int hvf_remove_breakpoint (CPUState *cpu,int type,hwaddr addr,hwaddr len) +static int hvf_remove_breakpoint (CPUState *cpu,int type,vaddr addr,vaddr len) {struct hvf_sw_breakpoint *bp;int err;
accel/hvf/hvf-all.c +1 -1
@@ -51,7 +51,7 @@ void assert_hvf_ok(hv_return_t ret)abort (); } -struct hvf_sw_breakpoint *hvf_find_sw_breakpoint (CPUState *cpu,target_ulong pc) +struct hvf_sw_breakpoint *hvf_find_sw_breakpoint (CPUState *cpu,vaddr pc) {struct hvf_sw_breakpoint *bp;
Signature · 1 line
2.41.0
PATCH v2 3/9 target: Use vaddr for kvm_arch_[insert|remove]_hw_breakpoint
In reply to Anton Johansson viaChanges the signature of the target-defined functions for inserting/removing kvm hw breakpoints. The address and length arguments are now of vaddr type, which both matches the type used internally in accel/kvm/kvm-all.c and makes the api target-agnostic.
--- include/sysemu/kvm.h | 6 ++---- target/arm/kvm64.c | 6 ++---- target/i386/kvm/kvm.c | 8 +++----- target/ppc/kvm.c | 13 ++++++------- target/s390x/kvm/kvm.c | 6 ++---- 5 files changed, 15 insertions(+), 24 deletions(-)
include/sysemu/kvm.h +2 -4
@@ -426,10 +426,8 @@ int kvm_arch_insert_sw_breakpoint(CPUState *cpu, struct kvm_sw_breakpoint *bp);int kvm_arch_remove_sw_breakpoint (CPUState *cpu,struct kvm_sw_breakpoint *bp); -int kvm_arch_insert_hw_breakpoint (target_ulong addr, -target_ulong len,int type); -int kvm_arch_remove_hw_breakpoint (target_ulong addr, -target_ulong len,int type); +int kvm_arch_insert_hw_breakpoint (vaddr addr,vaddr len,int type); +int kvm_arch_remove_hw_breakpoint (vaddr addr,vaddr len,int type);void kvm_arch_remove_all_hw_breakpoints (void );void kvm_arch_update_guest_debug (CPUState *cpu,struct kvm_guest_debug *dbg);
target/arm/kvm64.c +2 -4
@@ -49,8 +49,7 @@ void kvm_arm_init_debug(KVMState *s)return ; } -int kvm_arch_insert_hw_breakpoint (target_ulong addr, -target_ulong len,int type) +int kvm_arch_insert_hw_breakpoint (vaddr addr,vaddr len,int type) {switch (type) {case GDB_BREAKPOINT_HW :
@@ -65,8 +64,7 @@ int kvm_arch_insert_hw_breakpoint(target_ulong addr, } } -int kvm_arch_remove_hw_breakpoint (target_ulong addr, -target_ulong len,int type) +int kvm_arch_remove_hw_breakpoint (vaddr addr,vaddr len,int type) {switch (type) {case GDB_BREAKPOINT_HW :
target/i386/kvm/kvm.c +3 -5
@@ -4995,7 +4995,7 @@ MemTxAttrs kvm_arch_post_run(CPUState *cpu, struct kvm_run *run)kvm_rate_limit_on_bus_lock (); } -#ifdef CONFIG_XEN_EMU +#ifdef CONFIG_XEN_EMU /* * If the callback is asserted as a GSI (or PCI INTx) then check if * vcpu_info->evtchn_upcall_pending has been cleared, and deassert
@@ -5156,8 +5156,7 @@ static int find_hw_breakpoint(target_ulong addr, int len, int type)return -1 ; } -int kvm_arch_insert_hw_breakpoint (target_ulong addr, -target_ulong len,int type) +int kvm_arch_insert_hw_breakpoint (vaddr addr,vaddr len,int type) {switch (type) {case GDB_BREAKPOINT_HW :
@@ -5197,8 +5196,7 @@ int kvm_arch_insert_hw_breakpoint(target_ulong addr,return 0 ; } -int kvm_arch_remove_hw_breakpoint (target_ulong addr, -target_ulong len,int type) +int kvm_arch_remove_hw_breakpoint (vaddr addr,vaddr len,int type) {int n;
target/ppc/kvm.c +6 -7
@@ -1444,15 +1444,15 @@ static int find_hw_watchpoint(target_ulong addr, int *flag)return -1 ; } -int kvm_arch_insert_hw_breakpoint (target_ulong addr, -target_ulong len,int type) +int kvm_arch_insert_hw_breakpoint (vaddr addr,vaddr len,int type) { -if ((nb_hw_breakpoint + nb_hw_watchpoint) >=ARRAY_SIZE (hw_debug_points)) { +const unsigned breakpoint_index = nb_hw_breakpoint + nb_hw_watchpoint; +if (breakpoint_index >=ARRAY_SIZE (hw_debug_points)) {return -ENOBUFS ; } - hw_debug_points[nb_hw_breakpoint + nb_hw_watchpoint].addr = addr; - hw_debug_points[nb_hw_breakpoint + nb_hw_watchpoint].type = type; + hw_debug_points[breakpoint_index].addr = addr; + hw_debug_points[breakpoint_index].type = type;switch (type) {case GDB_BREAKPOINT_HW :
@@ -1488,8 +1488,7 @@ int kvm_arch_insert_hw_breakpoint(target_ulong addr,return 0 ; } -int kvm_arch_remove_hw_breakpoint (target_ulong addr, -target_ulong len,int type) +int kvm_arch_remove_hw_breakpoint (vaddr addr,vaddr len,int type) {int n;
target/s390x/kvm/kvm.c +2 -4
@@ -995,8 +995,7 @@ static int insert_hw_breakpoint(target_ulong addr, int len, int type)return 0 ; } -int kvm_arch_insert_hw_breakpoint (target_ulong addr, -target_ulong len,int type) +int kvm_arch_insert_hw_breakpoint (vaddr addr,vaddr len,int type) {switch (type) {case GDB_BREAKPOINT_HW :
@@ -1014,8 +1013,7 @@ int kvm_arch_insert_hw_breakpoint(target_ulong addr,return insert_hw_breakpoint (addr, len, type); } -int kvm_arch_remove_hw_breakpoint (target_ulong addr, -target_ulong len,int type) +int kvm_arch_remove_hw_breakpoint (vaddr addr,vaddr len,int type) {int size;struct kvm_hw_breakpoint *bp =find_hw_breakpoint (addr, len, type);
Signature · 1 line
2.41.0
Re: [PATCH v2 3/9] target: Use vaddr for kvm_arch_[insert|remove]_hw_breakpoint
Quoted 5 lines · Anton Johansson
Changes the signature of the target-defined functions for inserting/removing kvm hw breakpoints. The address and length arguments are now of vaddr type, which both matches the type used internally in
accel/kvm/kvm-all.cand makes the api target-agnostic.
Quoted 8 lines
Signed-off-by Anton Johansson<[email protected]>--- include/sysemu/kvm.h | 6 ++---- target/arm/kvm64.c | 6 ++---- target/i386/kvm/kvm.c | 8 +++----- target/ppc/kvm.c | 13 ++++++------- target/s390x/kvm/kvm.c | 6 ++---- 5 files changed, 15 insertions(+), 24 deletions(-)
r~
PATCH v2 4/9 target: Use vaddr for hvf_arch_[insert|remove]_hw_breakpoint
In reply to Anton Johansson viaChanges the signature of the target-defined functions for inserting/removing hvf hw breakpoints. The address and length arguments are now of vaddr type, which both matches the type used internally in accel/hvf/hvf-all.c and makes the api target-agnostic.
--- include/sysemu/hvf.h | 6 ++---- target/arm/hvf/hvf.c | 4 ++-- target/i386/hvf/hvf.c | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-)
include/sysemu/hvf.h +2 -4
@@ -51,10 +51,8 @@ int hvf_sw_breakpoints_active(CPUState *cpu);int hvf_arch_insert_sw_breakpoint (CPUState *cpu,struct hvf_sw_breakpoint *bp);int hvf_arch_remove_sw_breakpoint (CPUState *cpu,struct hvf_sw_breakpoint *bp); -int hvf_arch_insert_hw_breakpoint (target_ulong addr,target_ulong len, -int type); -int hvf_arch_remove_hw_breakpoint (target_ulong addr,target_ulong len, -int type); +int hvf_arch_insert_hw_breakpoint (vaddr addr,vaddr len,int type); +int hvf_arch_remove_hw_breakpoint (vaddr addr,vaddr len,int type);void hvf_arch_remove_all_hw_breakpoints (void );/*
target/arm/hvf/hvf.c +2 -2
@@ -2063,7 +2063,7 @@ int hvf_arch_remove_sw_breakpoint(CPUState *cpu, struct hvf_sw_breakpoint *bp)return 0 ; } -int hvf_arch_insert_hw_breakpoint (target_ulong addr,target_ulong len,int type) +int hvf_arch_insert_hw_breakpoint (vaddr addr,vaddr len,int type) {switch (type) {case GDB_BREAKPOINT_HW :
@@ -2077,7 +2077,7 @@ int hvf_arch_insert_hw_breakpoint(target_ulong addr, target_ulong len, int type) } } -int hvf_arch_remove_hw_breakpoint (target_ulong addr,target_ulong len,int type) +int hvf_arch_remove_hw_breakpoint (vaddr addr,vaddr len,int type) {switch (type) {case GDB_BREAKPOINT_HW :
target/i386/hvf/hvf.c +2 -2
@@ -690,12 +690,12 @@ int hvf_arch_remove_sw_breakpoint(CPUState *cpu, struct hvf_sw_breakpoint *bp)return -ENOSYS ; } -int hvf_arch_insert_hw_breakpoint (target_ulong addr,target_ulong len,int type) +int hvf_arch_insert_hw_breakpoint (vaddr addr,vaddr len,int type) {return -ENOSYS ; } -int hvf_arch_remove_hw_breakpoint (target_ulong addr,target_ulong len,int type) +int hvf_arch_remove_hw_breakpoint (vaddr addr,vaddr len,int type) {return -ENOSYS ; }
Signature · 1 line
2.41.0
Re: [PATCH v2 4/9] target: Use vaddr for hvf_arch_[insert|remove]_hw_breakpoint
Quoted 11 lines · Anton Johansson
Changes the signature of the target-defined functions for inserting/removing hvf hw breakpoints. The address and length arguments are now of vaddr type, which both matches the type used internally in
accel/hvf/hvf-all.cand makes the api target-agnostic.Signed-off-by Anton Johansson<[email protected]>--- include/sysemu/hvf.h | 6 ++---- target/arm/hvf/hvf.c | 4 ++-- target/i386/hvf/hvf.c | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-)
r~
PATCH v2 5/9 Replace target_ulong with abi_ptr in cpu_[st|ld]*()
In reply to Anton Johansson viaChanges the address type of the guest memory read/write functions from target_ulong to abi_ptr. (abi_ptr is currently typedef'd to target_ulong but that will change in a following commit.) This will reduce the coupling between accel/ and target/.
Note: Function pointers that point to cpu_[st|ld]*() in target/riscv and target/rx are also updated in this commit.
--- accel/tcg/atomic_template.h | 16 ++++++++-------- include/exec/cpu_ldst.h | 24 ++++++++++++------------ accel/tcg/cputlb.c | 10 +++++----- target/riscv/vector_helper.c | 2 +- target/rx/op_helper.c | 6 +++--- 5 files changed, 29 insertions(+), 29 deletions(-)
accel/tcg/atomic_template.h +8 -8
@@ -69,7 +69,7 @@# define END _le#endif -ABI_TYPE ATOMIC_NAME (cmpxchg )(CPUArchState *env,target_ulong addr, +ABI_TYPE ATOMIC_NAME (cmpxchg )(CPUArchState *env,abi_ptr addr,ABI_TYPE cmpv,ABI_TYPE newv,MemOpIdx oi,uintptr_t retaddr) {
@@ -87,7 +87,7 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, target_ulong addr, }#if DATA_SIZE <16 -ABI_TYPE ATOMIC_NAME (xchg )(CPUArchState *env,target_ulong addr,ABI_TYPE val, +ABI_TYPE ATOMIC_NAME (xchg )(CPUArchState *env,abi_ptr addr,ABI_TYPE val,MemOpIdx oi,uintptr_t retaddr) {DATA_TYPE *haddr =atomic_mmu_lookup (env, addr, oi,DATA_SIZE , retaddr);
@@ -100,7 +100,7 @@ ABI_TYPE ATOMIC_NAME(xchg)(CPUArchState *env, target_ulong addr, ABI_TYPE val, }#define GEN_ATOMIC_HELPER (X ) \ -ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr, \ +ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, abi_ptr addr, \ ABI_TYPE val, MemOpIdx oi, uintptr_t retaddr) \ { \ DATA_TYPE *haddr, ret; \
@@ -131,7 +131,7 @@ GEN_ATOMIC_HELPER(xor_fetch)* of CF_PARALLEL's value, we'll trace just a read and a write. */ #define GEN_ATOMIC_HELPER_FN (X ,FN ,XDATA_TYPE ,RET ) \ -ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr, \ +ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, abi_ptr addr, \ ABI_TYPE xval, MemOpIdx oi, uintptr_t retaddr) \ { \ XDATA_TYPE *haddr, cmp, old, new, val = xval; \
@@ -172,7 +172,7 @@ GEN_ATOMIC_HELPER_FN(umax_fetch, MAX, DATA_TYPE, new)# define END _be#endif -ABI_TYPE ATOMIC_NAME (cmpxchg )(CPUArchState *env,target_ulong addr, +ABI_TYPE ATOMIC_NAME (cmpxchg )(CPUArchState *env,abi_ptr addr,ABI_TYPE cmpv,ABI_TYPE newv,MemOpIdx oi,uintptr_t retaddr) {
@@ -190,7 +190,7 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, target_ulong addr, }#if DATA_SIZE <16 -ABI_TYPE ATOMIC_NAME (xchg )(CPUArchState *env,target_ulong addr,ABI_TYPE val, +ABI_TYPE ATOMIC_NAME (xchg )(CPUArchState *env,abi_ptr addr,ABI_TYPE val,MemOpIdx oi,uintptr_t retaddr) {DATA_TYPE *haddr =atomic_mmu_lookup (env, addr, oi,DATA_SIZE , retaddr);
@@ -203,7 +203,7 @@ ABI_TYPE ATOMIC_NAME(xchg)(CPUArchState *env, target_ulong addr, ABI_TYPE val, }#define GEN_ATOMIC_HELPER (X ) \ -ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr, \ +ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, abi_ptr addr, \ ABI_TYPE val, MemOpIdx oi, uintptr_t retaddr) \ { \ DATA_TYPE *haddr, ret; \
@@ -231,7 +231,7 @@ GEN_ATOMIC_HELPER(xor_fetch)* of CF_PARALLEL's value, we'll trace just a read and a write. */ #define GEN_ATOMIC_HELPER_FN (X ,FN ,XDATA_TYPE ,RET ) \ -ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr, \ +ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, abi_ptr addr, \ ABI_TYPE xval, MemOpIdx oi, uintptr_t retaddr) \ { \ XDATA_TYPE *haddr, ldo, ldn, old, new, val = xval; \
include/exec/cpu_ldst.h +12 -12
@@ -223,31 +223,31 @@ void cpu_stq_mmu(CPUArchState *env, abi_ptr ptr, uint64_t val,void cpu_st16_mmu (CPUArchState *env,abi_ptr addr,Int128 val,MemOpIdx oi,uintptr_t ra); -uint32_t cpu_atomic_cmpxchgb_mmu (CPUArchState *env,target_ulong addr, +uint32_t cpu_atomic_cmpxchgb_mmu (CPUArchState *env,abi_ptr addr,uint32_t cmpv,uint32_t newv,MemOpIdx oi,uintptr_t retaddr); -uint32_t cpu_atomic_cmpxchgw_le_mmu (CPUArchState *env,target_ulong addr, +uint32_t cpu_atomic_cmpxchgw_le_mmu (CPUArchState *env,abi_ptr addr,uint32_t cmpv,uint32_t newv,MemOpIdx oi,uintptr_t retaddr); -uint32_t cpu_atomic_cmpxchgl_le_mmu (CPUArchState *env,target_ulong addr, +uint32_t cpu_atomic_cmpxchgl_le_mmu (CPUArchState *env,abi_ptr addr,uint32_t cmpv,uint32_t newv,MemOpIdx oi,uintptr_t retaddr); -uint64_t cpu_atomic_cmpxchgq_le_mmu (CPUArchState *env,target_ulong addr, +uint64_t cpu_atomic_cmpxchgq_le_mmu (CPUArchState *env,abi_ptr addr,uint64_t cmpv,uint64_t newv,MemOpIdx oi,uintptr_t retaddr); -uint32_t cpu_atomic_cmpxchgw_be_mmu (CPUArchState *env,target_ulong addr, +uint32_t cpu_atomic_cmpxchgw_be_mmu (CPUArchState *env,abi_ptr addr,uint32_t cmpv,uint32_t newv,MemOpIdx oi,uintptr_t retaddr); -uint32_t cpu_atomic_cmpxchgl_be_mmu (CPUArchState *env,target_ulong addr, +uint32_t cpu_atomic_cmpxchgl_be_mmu (CPUArchState *env,abi_ptr addr,uint32_t cmpv,uint32_t newv,MemOpIdx oi,uintptr_t retaddr); -uint64_t cpu_atomic_cmpxchgq_be_mmu (CPUArchState *env,target_ulong addr, +uint64_t cpu_atomic_cmpxchgq_be_mmu (CPUArchState *env,abi_ptr addr,uint64_t cmpv,uint64_t newv,MemOpIdx oi,uintptr_t retaddr); -#define GEN_ATOMIC_HELPER (NAME ,TYPE ,SUFFIX ) \ -TYPE cpu_atomic_ ## NAME ## SUFFIX ## _mmu \ - (CPUArchState *env, target_ulong addr, TYPE val, \ +#define GEN_ATOMIC_HELPER (NAME ,TYPE ,SUFFIX ) \ +TYPE cpu_atomic_ ## NAME ## SUFFIX ## _mmu \ + (CPUArchState *env, abi_ptr addr, TYPE val, \ MemOpIdx oi, uintptr_t retaddr);#ifdef CONFIG_ATOMIC64
@@ -293,10 +293,10 @@ GEN_ATOMIC_HELPER_ALL(xchg)#undef GEN_ATOMIC_HELPER_ALL#undef GEN_ATOMIC_HELPER -Int128 cpu_atomic_cmpxchgo_le_mmu (CPUArchState *env,target_ulong addr, +Int128 cpu_atomic_cmpxchgo_le_mmu (CPUArchState *env,abi_ptr addr,Int128 cmpv,Int128 newv,MemOpIdx oi,uintptr_t retaddr); -Int128 cpu_atomic_cmpxchgo_be_mmu (CPUArchState *env,target_ulong addr, +Int128 cpu_atomic_cmpxchgo_be_mmu (CPUArchState *env,abi_ptr addr,Int128 cmpv,Int128 newv,MemOpIdx oi,uintptr_t retaddr);
accel/tcg/cputlb.c +5 -5
@@ -3038,14 +3038,14 @@ static void plugin_store_cb(CPUArchState *env, abi_ptr addr, MemOpIdx oi)qemu_plugin_vcpu_mem_cb (env_cpu (env), addr, oi,QEMU_PLUGIN_MEM_W ); } -void cpu_stb_mmu (CPUArchState *env,target_ulong addr,uint8_t val, +void cpu_stb_mmu (CPUArchState *env,abi_ptr addr,uint8_t val,MemOpIdx oi,uintptr_t retaddr) {helper_stb_mmu (env, addr, val, oi, retaddr);plugin_store_cb (env, addr, oi); } -void cpu_stw_mmu (CPUArchState *env,target_ulong addr,uint16_t val, +void cpu_stw_mmu (CPUArchState *env,abi_ptr addr,uint16_t val,MemOpIdx oi,uintptr_t retaddr) {tcg_debug_assert ((get_memop (oi) &MO_SIZE ) ==MO_16 );
@@ -3053,7 +3053,7 @@ void cpu_stw_mmu(CPUArchState *env, target_ulong addr, uint16_t val,plugin_store_cb (env, addr, oi); } -void cpu_stl_mmu (CPUArchState *env,target_ulong addr,uint32_t val, +void cpu_stl_mmu (CPUArchState *env,abi_ptr addr,uint32_t val,MemOpIdx oi,uintptr_t retaddr) {tcg_debug_assert ((get_memop (oi) &MO_SIZE ) ==MO_32 );
@@ -3061,7 +3061,7 @@ void cpu_stl_mmu(CPUArchState *env, target_ulong addr, uint32_t val,plugin_store_cb (env, addr, oi); } -void cpu_stq_mmu (CPUArchState *env,target_ulong addr,uint64_t val, +void cpu_stq_mmu (CPUArchState *env,abi_ptr addr,uint64_t val,MemOpIdx oi,uintptr_t retaddr) {tcg_debug_assert ((get_memop (oi) &MO_SIZE ) ==MO_64 );
@@ -3069,7 +3069,7 @@ void cpu_stq_mmu(CPUArchState *env, target_ulong addr, uint64_t val,plugin_store_cb (env, addr, oi); } -void cpu_st16_mmu (CPUArchState *env,target_ulong addr,Int128 val, +void cpu_st16_mmu (CPUArchState *env,abi_ptr addr,Int128 val,MemOpIdx oi,uintptr_t retaddr) {tcg_debug_assert ((get_memop (oi) &MO_SIZE ) ==MO_128 );
target/riscv/vector_helper.c +1 -1
@@ -235,7 +235,7 @@ static inline int vext_elem_mask(void *v0, int index) }/* elements operations for load and store */ -typedef void vext_ldst_elem_fn (CPURISCVState *env,target_ulong addr, +typedef void vext_ldst_elem_fn (CPURISCVState *env,abi_ptr addr,uint32_t idx,void *vd,uintptr_t retaddr);#define GEN_VEXT_LD_ELEM (NAME ,ETYPE ,H ,LDSUF ) \
target/rx/op_helper.c +3 -3
@@ -216,19 +216,19 @@ void helper_scmpu(CPURXState *env) }static uint32_t (*const cpu_ldufn[])(CPUArchState *env, -target_ulong ptr, +abi_ptr ptr,uintptr_t retaddr) = { cpu_ldub_data_ra, cpu_lduw_data_ra, cpu_ldl_data_ra, };static uint32_t (*const cpu_ldfn[])(CPUArchState *env, -target_ulong ptr, +abi_ptr ptr,uintptr_t retaddr) = { cpu_ldub_data_ra, cpu_lduw_data_ra, cpu_ldl_data_ra, };static void (*const cpu_stfn[])(CPUArchState *env, -target_ulong ptr, +abi_ptr ptr,uint32_t val,uintptr_t retaddr) = { cpu_stb_data_ra, cpu_stw_data_ra, cpu_stl_data_ra,
Signature · 1 line
2.41.0
PATCH v2 6/9 include/exec: typedef abi_ptr to vaddr in softmmu
In reply to Anton Johansson viaIn system mode, abi_ptr is primarily used for representing addresses when accessing guest memory with cpu_[st|ld]*(). Widening it from target_ulong to vaddr reduces the target dependence of these functions and is step towards building accel/ once for system mode.
--- include/exec/cpu_ldst.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/exec/cpu_ldst.h +2 -2
@@ -121,8 +121,8 @@ static inline bool guest_range_valid_untagged(abi_ulong start, abi_ulong len)h2g_nocheck (x); \ })#else -typedef target_ulong abi_ptr ; -#define TARGET_ABI_FMT_ptr TARGET_FMT_lx +typedef vaddr abi_ptr ; +#define TARGET_ABI_FMT_ptr "%016" VADDR_PRIx#endif uint32_t cpu_ldub_data (CPUArchState *env,abi_ptr ptr);
Signature · 1 line
2.41.0
PATCH v2 7/9 include/exec: Widen tlb_hit/tlb_hit_page()
In reply to Anton Johansson viatlb_addr is changed from target_ulong to uint64_t to match the type of a CPUTLBEntry value, and the addressed is changed to vaddr.
--- include/exec/cpu-all.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/exec/cpu-all.h +2 -2
@@ -397,7 +397,7 @@ QEMU_BUILD_BUG_ON(TLB_FLAGS_MASK & TLB_SLOW_FLAGS_MASK);* @addr: virtual address to test (must be page aligned) * @tlb_addr: TLB entry address (a CPUTLBEntry addr_read/write/code value) */ -static inline bool tlb_hit_page (target_ulong tlb_addr,target_ulong addr) +static inline bool tlb_hit_page (uint64_t tlb_addr,vaddr addr) {return addr == (tlb_addr & (TARGET_PAGE_MASK |TLB_INVALID_MASK )); }
@@ -408,7 +408,7 @@ static inline bool tlb_hit_page(target_ulong tlb_addr, target_ulong addr)* @addr: virtual address to test (need not be page aligned) * @tlb_addr: TLB entry address (a CPUTLBEntry addr_read/write/code value) */ -static inline bool tlb_hit (target_ulong tlb_addr,target_ulong addr) +static inline bool tlb_hit (uint64_t tlb_addr,vaddr addr) {return tlb_hit_page (tlb_addr, addr &TARGET_PAGE_MASK ); }
Signature · 1 line
2.41.0
PATCH v2 8/9 accel/tcg: Widen address arg. in tlb_compare_set()
In reply to Anton Johansson via--- accel/tcg/cputlb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
accel/tcg/cputlb.c +1 -1
@@ -1108,7 +1108,7 @@ static void tlb_add_large_page(CPUArchState *env, int mmu_idx, }static inline void tlb_set_compare (CPUTLBEntryFull *full,CPUTLBEntry *ent, -target_ulong address,int flags, +vaddr address,int flags,MMUAccessType access_type,bool enable) {if (enable) {
Signature · 1 line
2.41.0
PATCH v2 9/9 accel/tcg: Update run_on_cpu_data static assert
In reply to Anton Johansson viaAs we are now using vaddr for representing guest addresses, update the static assert to check that vaddr fits in the run_on_cpu_data union.
--- accel/tcg/cputlb.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
accel/tcg/cputlb.c +3 -2
@@ -74,8 +74,9 @@ }while (0 )/* run_on_cpu_data.target_ptr should always be big enough for a -* target_ulong even on 32 bit builds */ -QEMU_BUILD_BUG_ON (sizeof (target_ulong) >sizeof (run_on_cpu_data)); +* vaddr even on 32 bit builds +*/ +QEMU_BUILD_BUG_ON (sizeof (vaddr) >sizeof (run_on_cpu_data));/* We currently can't handle more than 16 bits in the MMUIDX bitmask. */
Signature · 1 line
2.41.0
Richard Henderson
AppliedQuoted 6 lines · Anton Johansson
This patchset replaces the remaining uses of
target_ulongin the accel/ directory. Specifically, the address type of a few kvm/hvf functions is widened to vaddr, and the address type of the cpu_[st|ld]*() functions is changed toabi_ptr(which is re-typedef'd to vaddr in system mode).
Quoted 6 lines
As a starting point, my goal is to be able to build
cputlb.conce for system mode, and this is a step in that direction by reducing the target-dependence of accel/.* Changes in v2:
- Removed explicittarget_ulongcasts from 3rd and 4th patches.
Queued to for 8.2.
r~
Hi,
Maybe its too late for the 8.1 window, but I noticed that this patchset fixes a segfault in qemu-system-ppc (and other 32 bits archs ?) introduced by commit fb2c53c.
Therefore maybe it would be relevant to get merge it before 8.2.
I put the details below, please tell me if you prefer I file a bug.
If the guest accesses memory accross the 32-bits boundary (eg: fetching a dword at 0xffffffff), do_ld4_mmu will make two calls to do_ld_beN (one for 0xffffffff, the other for 0x100000000).
In the second call, mmu_lookup1 will call tlb_hit(tlb_addr, addr) to see check if the address is already in the TLB. If the first page is loaded, this will result in a call to tlb_hit(0, 0x100000000) which returns 0, telling it wrongly that the address belongs in page 0. data->haddr will then be set to an out-of-bounds address.
The Patch 7/9 "include/exec: Widen tlb_hit/tlb_hit_page()" fixes that.
Example crash:
# asm dump # 0x04: 3820ffff li r1, -1 # 0x08: 81210000 lwz r9, 0(r1) $ ./build/qemu-system-ppc -device loader,addr=4,data=0x3820ffff81210000,data-len=8,data-be=true -device loader,addr=0x4,cpu-num=0
Thread 3 "qemu-system-ppc" received signal SIGSEGV, Segmentation fault.
#0 0x0000555555cbf8c7 in do_ld_bytes_beN (p=0x7ffff6c4a2a0, ret_be=0x25) at ../accel/tcg/cputlb.c:2141 #1 0x0000555555cbfe41 in do_ld_beN (env=0x55555684faa0, p=0x7ffff6c4a2a0, ret_be=0x25, mmu_idx=0x3, type=MMU_DATA_LOAD, mop=MO_BEUL, ra=0x7fff7000014d) at ../accel/tcg/cputlb.c:2302 #2 0x0000555555cc088b in do_ld4_mmu (env=0x55555684faa0, addr=0xffffffff, oi=0x123, ra=0x7fff7000014d, access_type=MMU_DATA_LOAD) at ../accel/tcg/cputlb.c:2505 #3 0x0000555555cc092b in helper_ldul_mmu (env=0x55555684faa0, addr=0xffffffff, oi=0x123, retaddr=0x7fff7000014d) at ../accel/tcg/cputlb.c:2516 #4 0x00007fff70000190 in code_gen_buffer () #5 0x0000555555cab186 in cpu_tb_exec (cpu=0x55555684d2d0, itb=0x7fffb0000040, tb_exit=0x7ffff6c4a8b0) at ../accel/tcg/cpu-exec.c:457 #6 0x0000555555cabeaf in cpu_loop_exec_tb (cpu=0x55555684d2d0, tb=0x7fffb0000040, pc=0x4, last_tb=0x7ffff6c4a8c0, tb_exit=0x7ffff6c4a8b0) at ../accel/tcg/cpu-exec.c:919 #7 0x0000555555cac219 in cpu_exec_loop (cpu=0x55555684d2d0, sc=0x7ffff6c4a940) at ../accel/tcg/cpu-exec.c:1040 #8 0x0000555555cac2d7 in cpu_exec_setjmp (cpu=0x55555684d2d0, sc=0x7ffff6c4a940) at ../accel/tcg/cpu-exec.c:1057 #9 0x0000555555cac35e in cpu_exec (cpu=0x55555684d2d0) at ../accel/tcg/cpu-exec.c:1083
#10 0x0000555555ccb9a0 in tcg_cpus_exec (cpu=0x55555684d2d0) at ../accel/tcg/tcg-accel-ops.c:75 #11 0x0000555555cccef5 in rr_cpu_thread_fn (arg=0x55555684d2d0) at ../accel/tcg/tcg-accel-ops-rr.c:261 #12 0x0000555555e8d661 in qemu_thread_start (args=0x5555568b6310) at ../util/qemu-thread-posix.c:541 #13 0x00007ffff7a8c9eb in start_thread (arg=<optimized out>) at pthread_create.c:444 #14 0x00007ffff7b10dfc in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
Regards,
Timothée.
Quoted 6 lines · 22.08.2023 22:02, [email protected] wrote:
Hi,
Maybe its too late for the 8.1 window, but I noticed that this patchset fixes a segfault in qemu-system-ppc (and other 32 bits archs ?) introduced by commit fb2c53c.
Therefore maybe it would be relevant to get merge it before 8.2.
It's definitely too later for 8.1.0 (which has been tagged earlier today, and it has been too later at -rc4 already). But it's not too late for 8.1.1 stable series, so a fix can be applied to stable-8.1 (Cc'ing qemu-stable@).
It seems I can reproduce the crash.
Thanks,
/mjt
Michael Tokarev
Reviewed-by Richard HendersonQuoted 8 lines · Michael Tokarev
Quoted 6 lines · 22.08.2023 22:02, [email protected] wrote:
Hi,
Maybe its too late for the 8.1 window, but I noticed that this patchset fixes a segfault in qemu-system-ppc (and other 32 bits archs ?) introduced by commit fb2c53c.
Therefore maybe it would be relevant to get merge it before 8.2.
Quoted 6 lines
It's definitely too later for 8.1.0 (which has been tagged earlier today, and it has been too later at -rc4 already). But it's not too late for 8.1.1 stable series, so a fix can be applied to stable-8.1 (Cc'ing qemu-stable@).
It seems I can reproduce the crash.
The sigsegv (reported testcase) seems to be fixed by commit 7/9:
Author: Anton Johansson via <[email protected]> Date: Mon Aug 7 17:57:04 2023 +0200
include/exec: Widen tlb_hit/tlb_hit_page()
tlb_addr is changed from target_ulong to uint64_t to match the type of a CPUTLBEntry value, and the addressed is changed to vaddr.
/mjt
Quoted 13 lines · Anton Johansson via
This patchset replaces the remaining uses of
target_ulongin the accel/ directory. Specifically, the address type of a few kvm/hvf functions is widened to vaddr, and the address type of the cpu_[st|ld]*() functions is changed toabi_ptr(which is re-typedef'd to vaddr in system mode).As a starting point, my goal is to be able to build
cputlb.conce for system mode, and this is a step in that direction by reducing the target-dependence of accel/.* Changes in v2:
- Removed explicittarget_ulongcasts from 3rd and 4th patches.
Quoted 10 lines
Anton Johansson (9):
accel/kvm: Widen pc/saved_insn forkvm_sw_breakpointaccel/hvf: Widen pc/saved_insn forhvf_sw_breakpoint
target: Use vaddr for kvm_arch_[insert|remove]_hw_breakpoint
target: Use vaddr for hvf_arch_[insert|remove]_hw_breakpoint Replacetarget_ulongwithabi_ptrin cpu_[st|ld]*()include/exec: typedefabi_ptrto vaddr in softmmuinclude/exec: Widen tlb_hit/tlb_hit_page() accel/tcg: Widen address arg. intlb_compare_set()accel/tcg: Updaterun_on_cpu_datastatic assert
Pinging a relatively old patchset, - which fixes from here needs to go to stable-8.1?
The context: https://lore.kernel.org/qemu-devel/[email protected]/
And according to this email:
https://lore.kernel.org/qemu-devel/[email protected]/
at least "include/exec: Widen tlb_hit/tlb_hit_page()" should go to 8.1, something else?
Thanks,
/mjt
Quoted 31 lines · Michael Tokarev
Quoted 13 lines · Anton Johansson via
This patchset replaces the remaining uses of
target_ulongin the accel/ directory. Specifically, the address type of a few kvm/hvf functions is widened to vaddr, and the address type of the cpu_[st|ld]*() functions is changed toabi_ptr(which is re-typedef'd to vaddr in system mode).As a starting point, my goal is to be able to build
cputlb.conce for system mode, and this is a step in that direction by reducing the target-dependence of accel/.* Changes in v2:
- Removed explicittarget_ulongcasts from 3rd and 4th patches.Quoted 10 lines
Anton Johansson (9):
accel/kvm: Widen pc/saved_insn forkvm_sw_breakpointaccel/hvf: Widen pc/saved_insn forhvf_sw_breakpoint
target: Use vaddr for kvm_arch_[insert|remove]_hw_breakpoint
target: Use vaddr for hvf_arch_[insert|remove]_hw_breakpoint Replacetarget_ulongwithabi_ptrin cpu_[st|ld]*()include/exec: typedefabi_ptrto vaddr in softmmuinclude/exec: Widen tlb_hit/tlb_hit_page() accel/tcg: Widen address arg. intlb_compare_set()accel/tcg: Updaterun_on_cpu_datastatic assertPinging a relatively old patchset, - which fixes from here needs to go to stable-8.1?
The context: https://lore.kernel.org/qemu-devel/[email protected]/
And according to this email:
Quoted 8 lines
https://lore.kernel.org/qemu-devel/[email protected]/
at least "
include/exec: Widen tlb_hit/tlb_hit_page()" should go to 8.1, something else?Thanks,
/mjt
If the patch above is the only one needed to fix the segfault (haven't tested myself), pulling it in isolation is fine as it doesn't depend on any of the other patches.
The rest of the patches can be delayed without issue.
Signature · 2 lines
Anton Johansson rev.ng Labs Srl.
[Trimming Cc list]
22.09.2023 13:45, Anton Johansson:
Quoted 15 lines · Michael Tokarev
Quoted 14 lines
Quoted 11 lines
Anton Johansson (9):
accel/kvm: Widen pc/saved_insn forkvm_sw_breakpointaccel/hvf: Widen pc/saved_insn forhvf_sw_breakpoint
target: Use vaddr for kvm_arch_[insert|remove]_hw_breakpoint
target: Use vaddr for hvf_arch_[insert|remove]_hw_breakpoint Replacetarget_ulongwithabi_ptrin cpu_[st|ld]*()include/exec: typedefabi_ptrto vaddr in softmmuinclude/exec: Widen tlb_hit/tlb_hit_page() accel/tcg: Widen address arg. intlb_compare_set()accel/tcg: Updaterun_on_cpu_datastatic assertPinging a relatively old patchset, - which fixes from here needs to go to stable-8.1?
...
Quoted 1 line
The rest of the patches can be delayed without issue.
Now I'm confused. What do you mean "delayed"?
Should the rest be picked up for 8.1.2 or 8.1.3 or maybe 8.1.4?
The whole series has been accepted/applied to master, I asked which changes should be picked up for stable-8.1, - there's no delay involved, it is either picked up or not, either needed in stable or not.
Yes, "Widen tlb_hit/tlb_hit_page()" fixes a known bug and I picked up that one, - unfortunately it missed 8.1.1 release. The question is about the other changes in this patch set, - do they fix other similar, not yet discovered, bugs in other places, or not fixing anything? Or should we delay picking them up until a bug is reported? :)
Thank you for the changes and the reply!
/mjt
Quoted 34 lines · Michael Tokarev
[Trimming Cc list]
22.09.2023 13:45, Anton Johansson:
Quoted 15 lines · Michael Tokarev
Quoted 14 lines
Quoted 11 lines
Anton Johansson (9):
accel/kvm: Widen pc/saved_insn forkvm_sw_breakpointaccel/hvf: Widen pc/saved_insn forhvf_sw_breakpoint
target: Use vaddr for kvm_arch_[insert|remove]_hw_breakpoint
target: Use vaddr for hvf_arch_[insert|remove]_hw_breakpoint Replacetarget_ulongwithabi_ptrin cpu_[st|ld]*()include/exec: typedefabi_ptrto vaddr in softmmuinclude/exec: Widen tlb_hit/tlb_hit_page() accel/tcg: Widen address arg. intlb_compare_set()accel/tcg: Updaterun_on_cpu_datastatic assertPinging a relatively old patchset, - which fixes from here needs to go to stable-8.1?
...
Quoted 1 line
The rest of the patches can be delayed without issue.
Now I'm confused. What do you mean "delayed"?
Should the rest be picked up for 8.1.2 or 8.1.3 or maybe 8.1.4?The whole series has been accepted/applied to master, I asked which changes should be picked up for stable-8.1, - there's no delay involved, it is either picked up or not, either needed in stable or not.
Yes, "Widen tlb_hit/tlb_hit_page()" fixes a known bug and I picked up that one, - unfortunately it missed 8.1.1 release. The question is about the other changes in this patch set, - do they fix other similar, not yet discovered, bugs in other places, or not fixing anything? Or should we delay picking them up until a bug is reported? :)
Quoted 3 lines
Thank you for the changes and the reply!
/mjt
Oh I see what you mean now, thanks for the clarification!:) I'm not that used to think in terms of what patches end up in stable.
The other patches in this series are refactors to reduce target-dependence in accel/, and they do not fix any bugs directly. Eventually we'll need to pick them up for compiling cputlb.c once for system mode etc., or other patches that depend on the refactor, but they are not critical to get in due to fixing some bug, that's what I meant by "can be delayed without issue".
How do you usually deal with these types of refactor heavy changes? Picking asap vs delaying until absolutely needed?
Thanks again for the explanation, I hope this was of some help.
//Anton