Skip to contentSkip to conversation

Start replacing target_ulong with vaddr

PATCH Superseded Anton Johansson via 4 participants 29 messages Apr 20, 2023 – Apr 24, 2023

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Start replacing target_ulong with vaddr

This is a first patchset in removing target_ulong from non-target/ directories. As use of target_ulong is spread accross the codebase we are attempting to target as few maintainers as possible with each patchset in order to ease reviewing.

The following instances of target_ulong remain in accel/ and tcg/
- atomic helpers (atomic_common.c.inc), cpu_atomic_*() (atomic_template.h,) and cpu_[st|ld]*() (cputlb.c/ldst_common.c.inc) are only used in target/ and can be pulled out into a separate target-specific file;

- Calls to cpu_get_tb_cpu_state() cast pc and cs_base to target_ulong in order to avoid having to touch the target/ directory in this patchset;

- walk_memory_regions() is used in user-exec.c and linux-user/elfload.c;

- helper_ret_*_mmu() is used in tcg/*/tcg-target.c.inc and tcg/tci.c;

- Functions in translate-all.c dealing with TCGContext.gen_insn_data will be switched off target_ulong once gen_insn_data and TARGET_INSN_START_WORDS have been dealt with;

- kvm_find_sw_breakpoint() in kvm-all.c used in target/;

- The last address when looking up page flags for an interval [start,last] in pageflags_find()/pageflags_next() is still target_long. I'm not sure why this is required. This only seems relevant on 32-bit guests since the addresses passed to the interval tree are uint64_t's, are we relying on a sign extension here for some reason?

- CPUTLBEntry and functions that read from it will be left for a later date;

Smaller patchsets implementing above changes will follow.

Finally, the grand goal is to allow for heterogeneous QEMU binaries consisting of multiple frontends.

RFC: https://lists.nongnu.org/archive/html/qemu-devel/2022-12/msg04518.html

Anton Johansson (8):
accel: Replace target_ulong with vaddr in TB/TLB
accel: Replace target_ulong with vaddr in probe_*() accel/tcg: Replace target_ulong with vaddr in *_mmu_lookup() accel/tcg: Replace target_ulong with vaddr in helper_unaligned_*() accel/tcg: Replace target_ulong with vaddr in translator_*() accel/tcg: Replace target_ulong with vaddr in page_*()
cpu: Replace target_ulong with vaddr in tb_invalidate_phys_addr()
tcg: Replace target_ulong with vaddr in tcg_gen_code()

 accel/stubs/tcg-stub.c       |   6 +-
 accel/tcg/cpu-exec.c         |  49 ++++-----
 accel/tcg/cputlb.c           | 195 +++++++++++++++++------------------
 accel/tcg/internal.h         |   6 +-
 accel/tcg/tb-hash.h          |  12 +--
 accel/tcg/tb-jmp-cache.h     |   2 +-
 accel/tcg/tb-maint.c         |   2 +-
 accel/tcg/translate-all.c    |  15 +--
 accel/tcg/translator.c       |  10 +-
 accel/tcg/user-exec.c        |  59 ++++++-----
 cpu.c                        |   2 +-
 include/exec/cpu-all.h       |  10 +-
 include/exec/cpu-defs.h      |   4 +-
 include/exec/cpu_ldst.h      |   6 +-
 include/exec/exec-all.h      |  98 +++++++++---------
 include/exec/translate-all.h |   2 +-
 include/exec/translator.h    |   6 +-
 include/qemu/plugin-memory.h |   2 +-
 include/tcg/tcg-ldst.h       |   4 +-
 include/tcg/tcg.h            |   2 +-
 tcg/tcg.c                    |   2 +-
 21 files changed, 247 insertions(+), 247 deletions(-)

--
2.39.1

#1 lore raw

PATCH 1/8 accel: Replace `target_ulong` with `vaddr` in TB/TLB

Changes pc and cs_base in TranslationBlock from target_ulong to vaddr. Auxilliary structs and tb_*()/tlb_*() functions that depend on this change are also updated to take a vaddr for guest virtual addresses.

---
 accel/stubs/tcg-stub.c       |   2 +-
 accel/tcg/cpu-exec.c         |  49 +++++-----
 accel/tcg/cputlb.c           | 179 +++++++++++++++++------------------
 accel/tcg/internal.h         |   6 +-
 accel/tcg/tb-hash.h          |  12 +--
 accel/tcg/tb-jmp-cache.h     |   2 +-
 accel/tcg/tb-maint.c         |   2 +-
 accel/tcg/translate-all.c    |  15 +--
 include/exec/cpu-defs.h      |   4 +-
 include/exec/cpu_ldst.h      |   6 +-
 include/exec/exec-all.h      |  82 ++++++++--------
 include/qemu/plugin-memory.h |   2 +-
 12 files changed, 181 insertions(+), 180 deletions(-)
accel/stubs/tcg-stub.c +1 -1
index 813695b402..0998e601ad 100644
@@ -18,7 +18,7 @@ void tb_flush(CPUState *cpu)
 {
 }
 
-void tlb_set_dirty(CPUState *cpu, target_ulong vaddr)
+void tlb_set_dirty(CPUState *cpu, vaddr vaddr)
 {
 }
 
accel/tcg/cpu-exec.c +26 -23

136 lines not on this page · raw message

accel/tcg/cputlb.c +88 -91

520 lines not on this page · raw message

accel/tcg/internal.h +3 -3
index 96f198b28b..89906dbdba 100644
@@ -42,8 +42,8 @@ void tb_invalidate_phys_range_fast(ram_addr_t ram_addr,
 G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);
 #endif /* CONFIG_SOFTMMU */
 
-TranslationBlock *tb_gen_code(CPUState *cpu, target_ulong pc,
-                              target_ulong cs_base, uint32_t flags,
+TranslationBlock *tb_gen_code(CPUState *cpu, vaddr pc,
+                              vaddr cs_base, uint32_t flags,
                               int cflags);
 void page_init(void);
 void tb_htable_init(void);
@@ -55,7 +55,7 @@ void cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb,
                                uintptr_t host_pc);
 
 /* Return the current PC from CPU, which may be cached in TB. */
-static inline target_ulong log_pc(CPUState *cpu, const TranslationBlock *tb)
+static inline vaddr log_pc(CPUState *cpu, const TranslationBlock *tb)
 {
     if (tb_cflags(tb) & CF_PCREL) {
         return cpu->cc->get_pc(cpu);
accel/tcg/tb-hash.h +6 -6
index 83dc610e4c..f560d3b0bb 100644
@@ -35,16 +35,16 @@
 #define TB_JMP_ADDR_MASK (TB_JMP_PAGE_SIZE - 1)
 #define TB_JMP_PAGE_MASK (TB_JMP_CACHE_SIZE - TB_JMP_PAGE_SIZE)
 
-static inline unsigned int tb_jmp_cache_hash_page(target_ulong pc)
+static inline unsigned int tb_jmp_cache_hash_page(vaddr pc)
 {
-    target_ulong tmp;
+    vaddr tmp;
     tmp = pc ^ (pc >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS));
     return (tmp >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS)) & TB_JMP_PAGE_MASK;
 }
 
-static inline unsigned int tb_jmp_cache_hash_func(target_ulong pc)
+static inline unsigned int tb_jmp_cache_hash_func(vaddr pc)
 {
-    target_ulong tmp;
+    vaddr tmp;
     tmp = pc ^ (pc >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS));
     return (((tmp >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS)) & TB_JMP_PAGE_MASK)
            | (tmp & TB_JMP_ADDR_MASK));
@@ -53,7 +53,7 @@ static inline unsigned int tb_jmp_cache_hash_func(target_ulong pc)
 #else
 
 /* In user-mode we can get better hashing because we do not have a TLB */
-static inline unsigned int tb_jmp_cache_hash_func(target_ulong pc)
+static inline unsigned int tb_jmp_cache_hash_func(vaddr pc)
 {
     return (pc ^ (pc >> TB_JMP_CACHE_BITS)) & (TB_JMP_CACHE_SIZE - 1);
 }
@@ -61,7 +61,7 @@ static inline unsigned int tb_jmp_cache_hash_func(target_ulong pc)
 #endif /* CONFIG_SOFTMMU */
 
 static inline
-uint32_t tb_hash_func(tb_page_addr_t phys_pc, target_ulong pc, uint32_t flags,
+uint32_t tb_hash_func(tb_page_addr_t phys_pc, vaddr pc, uint32_t flags,
                       uint32_t cf_mask, uint32_t trace_vcpu_dstate)
 {
     return qemu_xxhash7(phys_pc, pc, flags, cf_mask, trace_vcpu_dstate);
accel/tcg/tb-jmp-cache.h +1 -1
index bee87eb840..bb424c8a05 100644
@@ -21,7 +21,7 @@ struct CPUJumpCache {
     struct rcu_head rcu;
     struct {
         TranslationBlock *tb;
-        target_ulong pc;
+        vaddr pc;
     } array[TB_JMP_CACHE_SIZE];
 };
 
accel/tcg/tb-maint.c +1 -1
index cb1f806f00..a3596085b2 100644
@@ -99,7 +99,7 @@ static void tb_remove_all(void)
 /* Call with mmap_lock held. */
 static void tb_record(TranslationBlock *tb, PageDesc *p1, PageDesc *p2)
 {
-    target_ulong addr;
+    vaddr addr;
     int flags;
 
     assert_memory_lock();
accel/tcg/translate-all.c +8 -7
index 5b13281119..d4e567ed89 100644
@@ -271,7 +271,7 @@ void page_init(void)
  * Return the size of the generated code, or negative on error.
  */
 static int setjmp_gen_code(CPUArchState *env, TranslationBlock *tb,
-                           target_ulong pc, void *host_pc,
+                           vaddr pc, void *host_pc,
                            int *max_insns, int64_t *ti)
 {
     int ret = sigsetjmp(tcg_ctx->jmp_trans, 0);
@@ -299,7 +299,7 @@ static int setjmp_gen_code(CPUArchState *env, TranslationBlock *tb,
 
 /* Called with mmap_lock held for user mode emulation.  */
 TranslationBlock *tb_gen_code(CPUState *cpu,
-                              target_ulong pc, target_ulong cs_base,
+                              vaddr pc, vaddr cs_base,
                               uint32_t flags, int cflags)
 {
     CPUArchState *env = cpu->env_ptr;
@@ -565,11 +565,12 @@ void tb_check_watchpoint(CPUState *cpu, uintptr_t retaddr)
         /* The exception probably happened in a helper.  The CPU state should
            have been saved before calling it. Fetch the PC from there.  */
         CPUArchState *env = cpu->env_ptr;
-        target_ulong pc, cs_base;
+        vaddr pc = 0, cs_base = 0;
         tb_page_addr_t addr;
         uint32_t flags;
 
-        cpu_get_tb_cpu_state(env, &pc, &cs_base, &flags);
+        cpu_get_tb_cpu_state(env, (target_ulong *) &pc,
+                             (target_ulong *) &cs_base, &flags);
         addr = get_page_addr_code(env, pc);
         if (addr != -1) {
             tb_invalidate_phys_range(addr, addr);
@@ -619,10 +620,10 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)
     cpu->cflags_next_tb = curr_cflags(cpu) | CF_MEMI_ONLY | CF_LAST_IO | n;
 
     if (qemu_loglevel_mask(CPU_LOG_EXEC)) {
-        target_ulong pc = log_pc(cpu, tb);
+        vaddr pc = log_pc(cpu, tb);
         if (qemu_log_in_addr_range(pc)) {
-            qemu_log("cpu_io_recompile: rewound execution of TB to "
-                     TARGET_FMT_lx "\n", pc);
+            qemu_log("cpu_io_recompile: rewound execution of TB to %"
+                     VADDR_PRIx "\n", pc);
         }
     }
 
include/exec/cpu-defs.h +2 -2
index e1c498ef4b..d725f55d73 100644
@@ -177,8 +177,8 @@ typedef struct CPUTLBDesc {
      * we must flush the entire tlb.  The region is matched if
      * (addr & large_page_mask) == large_page_addr.
      */
-    target_ulong large_page_addr;
-    target_ulong large_page_mask;
+    vaddr large_page_addr;
+    vaddr large_page_mask;
     /* host time (in ns) at the beginning of the time window */
     int64_t window_begin_ns;
     /* maximum number of entries observed in the window */
include/exec/cpu_ldst.h +3 -3
index 09b55cc0ee..41e0ca05c5 100644
@@ -360,7 +360,7 @@ static inline void clear_helper_retaddr(void)
 /* Needed for TCG_OVERSIZED_GUEST */
 #include "tcg/tcg.h"
 
-static inline target_ulong tlb_addr_write(const CPUTLBEntry *entry)
+static inline vaddr tlb_addr_write(const CPUTLBEntry *entry)
 {
 #if TCG_OVERSIZED_GUEST
     return entry->addr_write;
@@ -371,7 +371,7 @@ static inline target_ulong tlb_addr_write(const CPUTLBEntry *entry)
 
 /* Find the TLB index corresponding to the mmu_idx + address pair.  */
 static inline uintptr_t tlb_index(CPUArchState *env, uintptr_t mmu_idx,
-                                  target_ulong addr)
+                                  vaddr addr)
 {
     uintptr_t size_mask = env_tlb(env)->f[mmu_idx].mask >> CPU_TLB_ENTRY_BITS;
 
@@ -380,7 +380,7 @@ static inline uintptr_t tlb_index(CPUArchState *env, uintptr_t mmu_idx,
 
 /* Find the TLB entry corresponding to the mmu_idx + address pair.  */
 static inline CPUTLBEntry *tlb_entry(CPUArchState *env, uintptr_t mmu_idx,
-                                     target_ulong addr)
+                                     vaddr addr)
 {
     return &env_tlb(env)->f[mmu_idx].table[tlb_index(env, mmu_idx, addr)];
 }
include/exec/exec-all.h +41 -41

250 lines not on this page · raw message

include/qemu/plugin-memory.h +1 -1
index 6fd539022a..43165f2452 100644
@@ -37,7 +37,7 @@ struct qemu_plugin_hwaddr {
  * It would only fail if not called from an instrumented memory access
  * which would be an abuse of the API.
  */
-bool tlb_plugin_lookup(CPUState *cpu, target_ulong addr, int mmu_idx,
+bool tlb_plugin_lookup(CPUState *cpu, vaddr addr, int mmu_idx,
                        bool is_store, struct qemu_plugin_hwaddr *data);
 
 #endif /* PLUGIN_MEMORY_H */
Signature · 1 line
2.39.1
#2 lore raw

Re: [PATCH 1/8] accel: Replace `target_ulong` with `vaddr` in TB/TLB

Quoted 5 lines · Anton Johansson

Changes pc and cs_base in TranslationBlock from target_ulong to vaddr. Auxilliary structs and tb_*()/tlb_*() functions that depend on this change are also updated to take a vaddr for guest virtual addresses.

Quoted 14 lines
---
  accel/stubs/tcg-stub.c       |   2 +-
  accel/tcg/cpu-exec.c         |  49 +++++-----
  accel/tcg/cputlb.c           | 179 +++++++++++++++++------------------
  accel/tcg/internal.h         |   6 +-
  accel/tcg/tb-hash.h          |  12 +--
  accel/tcg/tb-jmp-cache.h     |   2 +-
  accel/tcg/tb-maint.c         |   2 +-
  accel/tcg/translate-all.c    |  15 +--
  include/exec/cpu-defs.h      |   4 +-
  include/exec/cpu_ldst.h      |   6 +-
  include/exec/exec-all.h      |  82 ++++++++--------
  include/qemu/plugin-memory.h |   2 +-
  12 files changed, 181 insertions(+), 180 deletions(-)

This is too large and must be split. In addition, there are places where you must take more care with the replacement.

accel/tcg/cpu-exec.c const void *HELPER(lookup_tb_ptr)(CPUArchState *env) · line 419

Quoted 11 lines
accel/tcg/cpu-exec.c +3 -2
@@ -412,10 +412,11 @@ const void *HELPER(lookup_tb_ptr)(CPUArchState *env)
  {
      CPUState *cpu = env_cpu(env);
      TranslationBlock *tb;
-    target_ulong cs_base, pc;
+    vaddr cs_base = 0, pc = 0;
      uint32_t flags, cflags;
 
-    cpu_get_tb_cpu_state(env, &pc, &cs_base, &flags);
+    cpu_get_tb_cpu_state(env, (target_ulong *) &pc,
+                         (target_ulong *) &cs_base, &flags);

This simply will not work on big-endian hosts.

accel/tcg/cpu-exec.c void cpu_exec_step_atomic(CPUState *cpu) · line 548

Quoted 7 lines
accel/tcg/cpu-exec.c +2 -1
@@ -543,7 +544,8 @@ void cpu_exec_step_atomic(CPUState *cpu)
          g_assert(!cpu->running);
          cpu->running = true;
 
-        cpu_get_tb_cpu_state(env, &pc, &cs_base, &flags);
+        cpu_get_tb_cpu_state(env, (target_ulong *) &pc,
+                             (target_ulong *) &cs_base, &flags);

Likewise.

accel/tcg/cpu-exec.c cpu_exec_loop(CPUState *cpu, SyncClocks *sc) · line 955

Quoted 11 lines
accel/tcg/cpu-exec.c +3 -2
@@ -946,10 +948,11 @@ cpu_exec_loop(CPUState *cpu, SyncClocks *sc)
 
          while (!cpu_handle_interrupt(cpu, &last_tb)) {
              TranslationBlock *tb;
-            target_ulong cs_base, pc;
+            vaddr cs_base = 0, pc = 0;
              uint32_t flags, cflags;
 
-            cpu_get_tb_cpu_state(cpu->env_ptr, &pc, &cs_base, &flags);
+            cpu_get_tb_cpu_state(cpu->env_ptr, (target_ulong *) &pc,
+                                 (target_ulong *) &cs_base, &flags);

Likewise. And one more in translate-all.c.

accel/tcg/cputlb.c static void tlb_flush_page_by_mmuidx_async_0(CPUState *cpu, · line 560

Quoted 7 lines
accel/tcg/cputlb.c +1 -2
@@ -560,15 +557,15 @@ static void tlb_flush_page_by_mmuidx_async_0(CPUState *cpu,
  static void tlb_flush_page_by_mmuidx_async_1(CPUState *cpu,
                                               run_on_cpu_data data)
  {
-    target_ulong addr_and_idxmap = (target_ulong) data.target_ptr;
-    target_ulong addr = addr_and_idxmap & TARGET_PAGE_MASK;
+    vaddr addr_and_idxmap = (vaddr) data.target_ptr;

run_on_cpu_data.target_ptr is already vaddr, no need for cast.

r~

#3 lore raw

Re: [PATCH 1/8] accel: Replace `target_ulong` with `vaddr` in TB/TLB

Quoted 21 lines · Richard Henderson
Quoted 14 lines · Anton Johansson

Changes pc and cs_base in TranslationBlock from target_ulong to vaddr. Auxilliary structs and tb_*()/tlb_*() functions that depend on this change are also updated to take a vaddr for guest virtual addresses.

---
  accel/stubs/tcg-stub.c       |   2 +-
  accel/tcg/cpu-exec.c         |  49 +++++----- accel/tcg/cputlb.c           | 179 +++++++++++++++++------------------ accel/tcg/internal.h         |   6 +-
  accel/tcg/tb-hash.h          |  12 +-- accel/tcg/tb-jmp-cache.h     |   2 +-
  accel/tcg/tb-maint.c         |   2 +- accel/tcg/translate-all.c    |  15 +--

Quoted 5 lines
  include/exec/cpu-defs.h      |   4 +-
  include/exec/cpu_ldst.h      |   6 +-
  include/exec/exec-all.h      |  82 ++++++++--------
  include/qemu/plugin-memory.h |   2 +-
  12 files changed, 181 insertions(+), 180 deletions(-)
Quoted 1 line

This is too large and must be split.  In addition, there are places where you must take more care with the replacement.

Agreed this patch is very large. I struggled a bit in chopping it up without breaking bisection, but I'll give it another go!

Quoted 14 lines

accel/tcg/cpu-exec.c const void *HELPER(lookup_tb_ptr)(CPUArchState · line 420

Quoted 12 lines
accel/tcg/cpu-exec.c +3 -1
@@ -412,10 +412,11 @@ const void *HELPER(lookup_tb_ptr)(CPUArchState 
 *env)
   {
       CPUState *cpu = env_cpu(env);
       TranslationBlock *tb;
-    target_ulong cs_base, pc;
+    vaddr cs_base = 0, pc = 0;
       uint32_t flags, cflags;
   -    cpu_get_tb_cpu_state(env, &pc, &cs_base, &flags);
+    cpu_get_tb_cpu_state(env, (target_ulong *) &pc,
+                         (target_ulong *) &cs_base, &flags);

This simply will not work on big-endian hosts.

Ah of course! I'll pull in the changes updating the arguments of cpu_get_tb_cpu_state() to avoid the pointer casts.

Quoted 12 lines

accel/tcg/cputlb.c static void · line 561

Quoted 10 lines
accel/tcg/cputlb.c +1 -2
@@ -560,15 +557,15 @@ static void 
 tlb_flush_page_by_mmuidx_async_0(CPUState *cpu,
   static void tlb_flush_page_by_mmuidx_async_1(CPUState *cpu,
                                                run_on_cpu_data data)
   {
-    target_ulong addr_and_idxmap = (target_ulong) data.target_ptr;
-    target_ulong addr = addr_and_idxmap & TARGET_PAGE_MASK;
+    vaddr addr_and_idxmap = (vaddr) data.target_ptr;

run_on_cpu_data.target_ptr is already vaddr, no need for cast.

Right, will fix! Thanks

Signature · 2 lines
Anton Johansson,
rev.ng Labs Srl.
#4 lore raw

PATCH 2/8 accel: Replace target_ulong with vaddr in probe_*()

In reply to Anton Johansson via

Functions for probing memory accesses (and functions that call these) are updated to take a vaddr for guest virtual addresses over target_ulong.

---
 accel/stubs/tcg-stub.c  |  4 ++--
 accel/tcg/cputlb.c      | 12 ++++++------
 accel/tcg/user-exec.c   |  8 ++++----
 include/exec/exec-all.h | 14 +++++++-------
 4 files changed, 19 insertions(+), 19 deletions(-)
accel/stubs/tcg-stub.c +2 -2
index 0998e601ad..a9e7a2d5b4 100644
@@ -26,14 +26,14 @@ void tcg_flush_jmp_cache(CPUState *cpu)
 {
 }
 
-int probe_access_flags(CPUArchState *env, target_ulong addr, int size,
+int probe_access_flags(CPUArchState *env, vaddr addr, int size,
                        MMUAccessType access_type, int mmu_idx,
                        bool nonfault, void **phost, uintptr_t retaddr)
 {
      g_assert_not_reached();
 }
 
-void *probe_access(CPUArchState *env, target_ulong addr, int size,
+void *probe_access(CPUArchState *env, vaddr addr, int size,
                    MMUAccessType access_type, int mmu_idx, uintptr_t retaddr)
 {
      /* Handled by hardware accelerator. */
accel/tcg/cputlb.c +6 -6
index 7400b860aa..f35da2fc3b 100644
@@ -1516,7 +1516,7 @@ static void notdirty_write(CPUState *cpu, vaddr mem_vaddr, unsigned size,
     }
 }
 
-static int probe_access_internal(CPUArchState *env, target_ulong addr,
+static int probe_access_internal(CPUArchState *env, vaddr addr,
                                  int fault_size, MMUAccessType access_type,
                                  int mmu_idx, bool nonfault,
                                  void **phost, CPUTLBEntryFull **pfull,
@@ -1524,7 +1524,7 @@ static int probe_access_internal(CPUArchState *env, target_ulong addr,
 {
     uintptr_t index = tlb_index(env, mmu_idx, addr);
     CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr);
-    target_ulong tlb_addr, page_addr;
+    vaddr tlb_addr, page_addr;
     size_t elt_ofs;
     int flags;
 
@@ -1585,7 +1585,7 @@ static int probe_access_internal(CPUArchState *env, target_ulong addr,
     return flags;
 }
 
-int probe_access_full(CPUArchState *env, target_ulong addr, int size,
+int probe_access_full(CPUArchState *env, vaddr addr, int size,
                       MMUAccessType access_type, int mmu_idx,
                       bool nonfault, void **phost, CPUTLBEntryFull **pfull,
                       uintptr_t retaddr)
@@ -1602,7 +1602,7 @@ int probe_access_full(CPUArchState *env, target_ulong addr, int size,
     return flags;
 }
 
-int probe_access_flags(CPUArchState *env, target_ulong addr, int size,
+int probe_access_flags(CPUArchState *env, vaddr addr, int size,
                        MMUAccessType access_type, int mmu_idx,
                        bool nonfault, void **phost, uintptr_t retaddr)
 {
@@ -1623,7 +1623,7 @@ int probe_access_flags(CPUArchState *env, target_ulong addr, int size,
     return flags;
 }
 
-void *probe_access(CPUArchState *env, target_ulong addr, int size,
+void *probe_access(CPUArchState *env, vaddr addr, int size,
                    MMUAccessType access_type, int mmu_idx, uintptr_t retaddr)
 {
     CPUTLBEntryFull *full;
@@ -1682,7 +1682,7 @@ void *tlb_vaddr_to_host(CPUArchState *env, abi_ptr addr,
  * NOTE: This function will trigger an exception if the page is
  * not executable.
  */
-tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong addr,
+tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, vaddr addr,
                                         void **hostp)
 {
     CPUTLBEntryFull *full;
accel/tcg/user-exec.c +4 -4
index a7e0c3e2f4..9d49fe95e4 100644
@@ -721,7 +721,7 @@ int page_unprotect(target_ulong address, uintptr_t pc)
     return current_tb_invalidated ? 2 : 1;
 }
 
-static int probe_access_internal(CPUArchState *env, target_ulong addr,
+static int probe_access_internal(CPUArchState *env, vaddr addr,
                                  int fault_size, MMUAccessType access_type,
                                  bool nonfault, uintptr_t ra)
 {
@@ -759,7 +759,7 @@ static int probe_access_internal(CPUArchState *env, target_ulong addr,
     cpu_loop_exit_sigsegv(env_cpu(env), addr, access_type, maperr, ra);
 }
 
-int probe_access_flags(CPUArchState *env, target_ulong addr, int size,
+int probe_access_flags(CPUArchState *env, vaddr addr, int size,
                        MMUAccessType access_type, int mmu_idx,
                        bool nonfault, void **phost, uintptr_t ra)
 {
@@ -771,7 +771,7 @@ int probe_access_flags(CPUArchState *env, target_ulong addr, int size,
     return flags;
 }
 
-void *probe_access(CPUArchState *env, target_ulong addr, int size,
+void *probe_access(CPUArchState *env, vaddr addr, int size,
                    MMUAccessType access_type, int mmu_idx, uintptr_t ra)
 {
     int flags;
@@ -783,7 +783,7 @@ void *probe_access(CPUArchState *env, target_ulong addr, int size,
     return size ? g2h(env_cpu(env), addr) : NULL;
 }
 
-tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong addr,
+tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, vaddr addr,
                                         void **hostp)
 {
     int flags;
include/exec/exec-all.h +7 -7
index 47c5154718..c6cb3fcb8a 100644
@@ -428,16 +428,16 @@ static inline void tlb_flush_range_by_mmuidx_all_cpus_synced(CPUState *cpu,
  * Finally, return the host address for a page that is backed by RAM,
  * or NULL if the page requires I/O.
  */
-void *probe_access(CPUArchState *env, target_ulong addr, int size,
+void *probe_access(CPUArchState *env, vaddr addr, int size,
                    MMUAccessType access_type, int mmu_idx, uintptr_t retaddr);
 
-static inline void *probe_write(CPUArchState *env, target_ulong addr, int size,
+static inline void *probe_write(CPUArchState *env, vaddr addr, int size,
                                 int mmu_idx, uintptr_t retaddr)
 {
     return probe_access(env, addr, size, MMU_DATA_STORE, mmu_idx, retaddr);
 }
 
-static inline void *probe_read(CPUArchState *env, target_ulong addr, int size,
+static inline void *probe_read(CPUArchState *env, vaddr addr, int size,
                                int mmu_idx, uintptr_t retaddr)
 {
     return probe_access(env, addr, size, MMU_DATA_LOAD, mmu_idx, retaddr);
@@ -462,7 +462,7 @@ static inline void *probe_read(CPUArchState *env, target_ulong addr, int size,
  * Do handle clean pages, so exclude TLB_NOTDIRY from the returned flags.
  * For simplicity, all "mmio-like" flags are folded to TLB_MMIO.
  */
-int probe_access_flags(CPUArchState *env, target_ulong addr, int size,
+int probe_access_flags(CPUArchState *env, vaddr addr, int size,
                        MMUAccessType access_type, int mmu_idx,
                        bool nonfault, void **phost, uintptr_t retaddr);
 
@@ -475,7 +475,7 @@ int probe_access_flags(CPUArchState *env, target_ulong addr, int size,
  * and must be consumed or copied immediately, before any further
  * access or changes to TLB @mmu_idx.
  */
-int probe_access_full(CPUArchState *env, target_ulong addr, int size,
+int probe_access_full(CPUArchState *env, vaddr addr, int size,
                       MMUAccessType access_type, int mmu_idx,
                       bool nonfault, void **phost,
                       CPUTLBEntryFull **pfull, uintptr_t retaddr);
@@ -728,7 +728,7 @@ struct MemoryRegionSection *iotlb_to_section(CPUState *cpu,
  *
  * Note: this function can trigger an exception.
  */
-tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong addr,
+tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, vaddr addr,
                                         void **hostp);
 
 /**
@@ -743,7 +743,7 @@ tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong addr,
  * Note: this function can trigger an exception.
  */
 static inline tb_page_addr_t get_page_addr_code(CPUArchState *env,
-                                                target_ulong addr)
+                                                vaddr addr)
 {
     return get_page_addr_code_hostp(env, addr, NULL);
 }
Signature · 1 line
2.39.1
Reviewed-by on v1 2/8
#5 lore raw

Re: [PATCH 2/8] accel: Replace target_ulong with vaddr in probe_*()

Quoted 11 lines · Anton Johansson

Functions for probing memory accesses (and functions that call these) are updated to take a vaddr for guest virtual addresses over target_ulong.

---
  accel/stubs/tcg-stub.c  |  4 ++--
  accel/tcg/cputlb.c      | 12 ++++++------
  accel/tcg/user-exec.c   |  8 ++++----
  include/exec/exec-all.h | 14 +++++++-------
  4 files changed, 19 insertions(+), 19 deletions(-)

r~

#6 lore raw

PATCH 3/8 accel/tcg: Replace target_ulong with vaddr in *_mmu_lookup()

In reply to Anton Johansson via

Update atomic_mmu_lookup() and cpu_mmu_lookup() to take the guest virtual address as a vaddr instead of a target_ulong.

---
 accel/tcg/cputlb.c    | 4 ++--
 accel/tcg/user-exec.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
accel/tcg/cputlb.c +2 -2
index f35da2fc3b..bf4858c116 100644
@@ -1753,7 +1753,7 @@ bool tlb_plugin_lookup(CPUState *cpu, vaddr addr, int mmu_idx,
  *
  * @prot may be PAGE_READ, PAGE_WRITE, or PAGE_READ|PAGE_WRITE.
  */
-static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,
+static void *atomic_mmu_lookup(CPUArchState *env, vaddr addr,
                                MemOpIdx oi, int size, int prot,
                                uintptr_t retaddr)
 {
@@ -1762,7 +1762,7 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,
     int a_bits = get_alignment_bits(mop);
     uintptr_t index;
     CPUTLBEntry *tlbe;
-    target_ulong tlb_addr;
+    vaddr tlb_addr;
     void *hostaddr;
     CPUTLBEntryFull *full;
 
accel/tcg/user-exec.c +2 -2
index 9d49fe95e4..7ec49933fb 100644
@@ -914,7 +914,7 @@ void helper_unaligned_st(CPUArchState *env, target_ulong addr)
     cpu_loop_exit_sigbus(env_cpu(env), addr, MMU_DATA_STORE, GETPC());
 }
 
-static void *cpu_mmu_lookup(CPUArchState *env, target_ulong addr,
+static void *cpu_mmu_lookup(CPUArchState *env, vaddr addr,
                             MemOpIdx oi, uintptr_t ra, MMUAccessType type)
 {
     MemOp mop = get_memop(oi);
@@ -1226,7 +1226,7 @@ uint64_t cpu_ldq_code(CPUArchState *env, abi_ptr ptr)
  *
  * @prot may be PAGE_READ, PAGE_WRITE, or PAGE_READ|PAGE_WRITE.
  */
-static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,
+static void *atomic_mmu_lookup(CPUArchState *env, vaddr addr,
                                MemOpIdx oi, int size, int prot,
                                uintptr_t retaddr)
 {
Signature · 1 line
2.39.1
Reviewed-by on v1 3/8
#7 lore raw

Re: [PATCH 3/8] accel/tcg: Replace target_ulong with vaddr in *_mmu_lookup()

Quoted 8 lines · Anton Johansson

Update atomic_mmu_lookup() and cpu_mmu_lookup() to take the guest virtual address as a vaddr instead of a target_ulong.

---
  accel/tcg/cputlb.c    | 4 ++--
  accel/tcg/user-exec.c | 4 ++--
  2 files changed, 4 insertions(+), 4 deletions(-)

r~

#8 lore raw

PATCH 4/8 accel/tcg: Replace target_ulong with vaddr in helper_unaligned_*()

In reply to Anton Johansson via

Updates helper_unaligned_[ld|st] to take the store/load address as a vaddr instead of a target_ulong.

---
 accel/tcg/user-exec.c  | 4 ++--
 include/tcg/tcg-ldst.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
accel/tcg/user-exec.c +2 -2
index 7ec49933fb..d0673de771 100644
@@ -904,12 +904,12 @@ static void validate_memop(MemOpIdx oi, MemOp expected)
 #endif
 }
 
-void helper_unaligned_ld(CPUArchState *env, target_ulong addr)
+void helper_unaligned_ld(CPUArchState *env, vaddr addr)
 {
     cpu_loop_exit_sigbus(env_cpu(env), addr, MMU_DATA_LOAD, GETPC());
 }
 
-void helper_unaligned_st(CPUArchState *env, target_ulong addr)
+void helper_unaligned_st(CPUArchState *env, vaddr addr)
 {
     cpu_loop_exit_sigbus(env_cpu(env), addr, MMU_DATA_STORE, GETPC());
 }
include/tcg/tcg-ldst.h +2 -2
index 2ba22bd5fe..cad7782e2e 100644
@@ -72,8 +72,8 @@ void helper_be_stq_mmu(CPUArchState *env, target_ulong addr, uint64_t val,
 
 #else
 
-G_NORETURN void helper_unaligned_ld(CPUArchState *env, target_ulong addr);
-G_NORETURN void helper_unaligned_st(CPUArchState *env, target_ulong addr);
+G_NORETURN void helper_unaligned_ld(CPUArchState *env, vaddr addr);
+G_NORETURN void helper_unaligned_st(CPUArchState *env, vaddr addr);
 
 #endif /* CONFIG_SOFTMMU */
 #endif /* TCG_LDST_H */
Signature · 1 line
2.39.1
#9 lore raw

Re: [PATCH 4/8] accel/tcg: Replace target_ulong with vaddr in helper_unaligned_*()

Quoted 8 lines · Anton Johansson

Updates helper_unaligned_[ld|st] to take the store/load address as a vaddr instead of a target_ulong.

---
  accel/tcg/user-exec.c  | 4 ++--
  include/tcg/tcg-ldst.h | 4 ++--
  2 files changed, 4 insertions(+), 4 deletions(-)

I've got patches posted to remove these functions.

r~

#10 lore raw

Re: [PATCH 4/8] accel/tcg: Replace target_ulong with vaddr in helper_unaligned_*()

Quoted 11 lines · Richard Henderson
Quoted 8 lines · Anton Johansson

Updates helper_unaligned_[ld|st] to take the store/load address as a vaddr instead of a target_ulong.

---
  accel/tcg/user-exec.c  | 4 ++--
  include/tcg/tcg-ldst.h | 4 ++--

  2 files changed, 4 insertions(+), 4 deletions(-)

I've got patches posted to remove these functions.

Nice, I'll remove this patch then!

Signature · 2 lines
Anton Johansson,
rev.ng Labs Srl.
#11 lore raw

PATCH 5/8 accel/tcg: Replace target_ulong with vaddr in translator_*()

In reply to Anton Johansson via

Use vaddr for guest virtual address in translator_use_goto_tb() and translator_loop().

---
 accel/tcg/translator.c    | 10 +++++-----
 include/exec/translator.h |  6 +++---
 2 files changed, 8 insertions(+), 8 deletions(-)
accel/tcg/translator.c +5 -5
index 7bda43ff61..58737eff97 100644
@@ -18,7 +18,7 @@
 #include "exec/plugin-gen.h"
 #include "exec/replay-core.h"
 
-bool translator_use_goto_tb(DisasContextBase *db, target_ulong dest)
+bool translator_use_goto_tb(DisasContextBase *db, vaddr dest)
 {
     /* Suppress goto_tb if requested. */
     if (tb_cflags(db->tb) & CF_NO_GOTO_TB) {
@@ -30,8 +30,8 @@ bool translator_use_goto_tb(DisasContextBase *db, target_ulong dest)
 }
 
 void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
-                     target_ulong pc, void *host_pc,
-                     const TranslatorOps *ops, DisasContextBase *db)
+                     vaddr pc, void *host_pc, const TranslatorOps *ops,
+                     DisasContextBase *db)
 {
     uint32_t cflags = tb_cflags(tb);
     bool plugin_enabled;
@@ -137,10 +137,10 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
 }
 
 static void *translator_access(CPUArchState *env, DisasContextBase *db,
-                               target_ulong pc, size_t len)
+                               vaddr pc, size_t len)
 {
     void *host;
-    target_ulong base, end;
+    vaddr base, end;
     TranslationBlock *tb;
 
     tb = db->tb;
include/exec/translator.h +3 -3
index 797fef7515..fa3c2ba529 100644
@@ -147,8 +147,8 @@ typedef struct TranslatorOps {
  * - When too many instructions have been translated.
  */
 void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
-                     target_ulong pc, void *host_pc,
-                     const TranslatorOps *ops, DisasContextBase *db);
+                     vaddr pc, void *host_pc, const TranslatorOps *ops,
+                     DisasContextBase *db);
 
 /**
  * translator_use_goto_tb
@@ -158,7 +158,7 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
  * Return true if goto_tb is allowed between the current TB
  * and the destination PC.
  */
-bool translator_use_goto_tb(DisasContextBase *db, target_ulong dest);
+bool translator_use_goto_tb(DisasContextBase *db, vaddr dest);
 
 /*
  * Translator Load Functions
Signature · 1 line
2.39.1
Reviewed-by on v1 5/8
#12 lore raw

Re: [PATCH 5/8] accel/tcg: Replace target_ulong with vaddr in translator_*()

Quoted 8 lines · Anton Johansson

Use vaddr for guest virtual address in translator_use_goto_tb() and translator_loop().

---
  accel/tcg/translator.c    | 10 +++++-----
  include/exec/translator.h |  6 +++---
  2 files changed, 8 insertions(+), 8 deletions(-)

r~

#13 lore raw

PATCH 6/8 accel/tcg: Replace target_ulong with vaddr in page_*()

In reply to Anton Johansson via

Use vaddr for guest virtual addresses for functions dealing with page flags.

---
 accel/tcg/user-exec.c        | 43 ++++++++++++++++++------------------
 include/exec/cpu-all.h       | 10 ++++-----
 include/exec/translate-all.h |  2 +-
 3 files changed, 27 insertions(+), 28 deletions(-)
accel/tcg/user-exec.c +21 -22
index d0673de771..d3626c16d7 100644
@@ -144,7 +144,7 @@ typedef struct PageFlagsNode {
 
 static IntervalTreeRoot pageflags_root;
 
-static PageFlagsNode *pageflags_find(target_ulong start, target_long last)
+static PageFlagsNode *pageflags_find(vaddr start, target_long last)
 {
     IntervalTreeNode *n;
 
@@ -152,7 +152,7 @@ static PageFlagsNode *pageflags_find(target_ulong start, target_long last)
     return n ? container_of(n, PageFlagsNode, itree) : NULL;
 }
 
-static PageFlagsNode *pageflags_next(PageFlagsNode *p, target_ulong start,
+static PageFlagsNode *pageflags_next(PageFlagsNode *p, vaddr start,
                                      target_long last)
 {
     IntervalTreeNode *n;
@@ -205,7 +205,7 @@ void page_dump(FILE *f)
     walk_memory_regions(f, dump_region);
 }
 
-int page_get_flags(target_ulong address)
+int page_get_flags(vaddr address)
 {
     PageFlagsNode *p = pageflags_find(address, address);
 
@@ -228,7 +228,7 @@ int page_get_flags(target_ulong address)
 }
 
 /* A subroutine of page_set_flags: insert a new node for [start,last]. */
-static void pageflags_create(target_ulong start, target_ulong last, int flags)
+static void pageflags_create(vaddr start, vaddr last, int flags)
 {
     PageFlagsNode *p = g_new(PageFlagsNode, 1);
 
@@ -239,13 +239,13 @@ static void pageflags_create(target_ulong start, target_ulong last, int flags)
 }
 
 /* A subroutine of page_set_flags: remove everything in [start,last]. */
-static bool pageflags_unset(target_ulong start, target_ulong last)
+static bool pageflags_unset(vaddr start, vaddr last)
 {
     bool inval_tb = false;
 
     while (true) {
         PageFlagsNode *p = pageflags_find(start, last);
-        target_ulong p_last;
+        vaddr p_last;
 
         if (!p) {
             break;
@@ -284,8 +284,7 @@ static bool pageflags_unset(target_ulong start, target_ulong last)
  * A subroutine of page_set_flags: nothing overlaps [start,last],
  * but check adjacent mappings and maybe merge into a single range.
  */
-static void pageflags_create_merge(target_ulong start, target_ulong last,
-                                   int flags)
+static void pageflags_create_merge(vaddr start, vaddr last, int flags)
 {
     PageFlagsNode *next = NULL, *prev = NULL;
 
@@ -336,11 +335,11 @@ static void pageflags_create_merge(target_ulong start, target_ulong last,
 #define PAGE_STICKY  (PAGE_ANON | PAGE_PASSTHROUGH | PAGE_TARGET_STICKY)
 
 /* A subroutine of page_set_flags: add flags to [start,last]. */
-static bool pageflags_set_clear(target_ulong start, target_ulong last,
+static bool pageflags_set_clear(vaddr start, vaddr last,
                                 int set_flags, int clear_flags)
 {
     PageFlagsNode *p;
-    target_ulong p_start, p_last;
+    vaddr p_start, p_last;
     int p_flags, merge_flags;
     bool inval_tb = false;
 
@@ -480,7 +479,7 @@ static bool pageflags_set_clear(target_ulong start, target_ulong last,
  * The flag PAGE_WRITE_ORG is positioned automatically depending
  * on PAGE_WRITE.  The mmap_lock should already be held.
  */
-void page_set_flags(target_ulong start, target_ulong last, int flags)
+void page_set_flags(vaddr start, vaddr last, int flags)
 {
     bool reset = false;
     bool inval_tb = false;
@@ -520,9 +519,9 @@ void page_set_flags(target_ulong start, target_ulong last, int flags)
     }
 }
 
-int page_check_range(target_ulong start, target_ulong len, int flags)
+int page_check_range(vaddr start, vaddr len, int flags)
 {
-    target_ulong last;
+    vaddr last;
     int locked;  /* tri-state: =0: unlocked, +1: global, -1: local */
     int ret;
 
@@ -601,7 +600,7 @@ int page_check_range(target_ulong start, target_ulong len, int flags)
 void page_protect(tb_page_addr_t address)
 {
     PageFlagsNode *p;
-    target_ulong start, last;
+    vaddr start, last;
     int prot;
 
     assert_memory_lock();
@@ -642,7 +641,7 @@ void page_protect(tb_page_addr_t address)
  * immediately exited. (We can only return 2 if the 'pc' argument is
  * non-zero.)
  */
-int page_unprotect(target_ulong address, uintptr_t pc)
+int page_unprotect(vaddr address, uintptr_t pc)
 {
     PageFlagsNode *p;
     bool current_tb_invalidated;
@@ -676,7 +675,7 @@ int page_unprotect(target_ulong address, uintptr_t pc)
         }
 #endif
     } else {
-        target_ulong start, len, i;
+        vaddr start, len, i;
         int prot;
 
         if (qemu_host_page_size <= TARGET_PAGE_SIZE) {
@@ -691,7 +690,7 @@ int page_unprotect(target_ulong address, uintptr_t pc)
             prot = 0;
 
             for (i = 0; i < len; i += TARGET_PAGE_SIZE) {
-                target_ulong addr = start + i;
+                vaddr addr = start + i;
 
                 p = pageflags_find(addr, addr);
                 if (p) {
@@ -814,7 +813,7 @@ typedef struct TargetPageDataNode {
 
 static IntervalTreeRoot targetdata_root;
 
-void page_reset_target_data(target_ulong start, target_ulong last)
+void page_reset_target_data(vaddr start, vaddr last)
 {
     IntervalTreeNode *n, *next;
 
@@ -828,7 +827,7 @@ void page_reset_target_data(target_ulong start, target_ulong last)
          n != NULL;
          n = next,
          next = next ? interval_tree_iter_next(n, start, last) : NULL) {
-        target_ulong n_start, n_last, p_ofs, p_len;
+        vaddr n_start, n_last, p_ofs, p_len;
         TargetPageDataNode *t = container_of(n, TargetPageDataNode, itree);
 
         if (n->start >= start && n->last <= last) {
@@ -851,11 +850,11 @@ void page_reset_target_data(target_ulong start, target_ulong last)
     }
 }
 
-void *page_get_target_data(target_ulong address)
+void *page_get_target_data(vaddr address)
 {
     IntervalTreeNode *n;
     TargetPageDataNode *t;
-    target_ulong page, region;
+    vaddr page, region;
 
     page = address & TARGET_PAGE_MASK;
     region = address & TBD_MASK;
@@ -884,7 +883,7 @@ void *page_get_target_data(target_ulong address)
     return t->data[(page - region) >> TARGET_PAGE_BITS];
 }
 #else
-void page_reset_target_data(target_ulong start, target_ulong last) { }
+void page_reset_target_data(vaddr start, vaddr last) { }
 #endif /* TARGET_PAGE_DATA_SIZE */
 
 /* The softmmu versions of these helpers are in cputlb.c.  */
include/exec/cpu-all.h +5 -5
index 090922e4a8..1dbb2b7c66 100644
@@ -284,10 +284,10 @@ typedef int (*walk_memory_regions_fn)(void *, target_ulong,
                                       target_ulong, unsigned long);
 int walk_memory_regions(void *, walk_memory_regions_fn);
 
-int page_get_flags(target_ulong address);
-void page_set_flags(target_ulong start, target_ulong last, int flags);
-void page_reset_target_data(target_ulong start, target_ulong last);
-int page_check_range(target_ulong start, target_ulong len, int flags);
+int page_get_flags(vaddr address);
+void page_set_flags(vaddr start, vaddr last, int flags);
+void page_reset_target_data(vaddr start, vaddr last);
+int page_check_range(vaddr start, vaddr len, int flags);
 
 /**
  * page_get_target_data(address)
@@ -300,7 +300,7 @@ int page_check_range(target_ulong start, target_ulong len, int flags);
  * The memory will be freed when the guest page is deallocated,
  * e.g. with the munmap system call.
  */
-void *page_get_target_data(target_ulong address)
+void *page_get_target_data(vaddr address)
     __attribute__((returns_nonnull));
 #endif
 
include/exec/translate-all.h +1 -1
index 88602ae8d8..0b9d2e3b32 100644
@@ -28,7 +28,7 @@ void tb_check_watchpoint(CPUState *cpu, uintptr_t retaddr);
 
 #ifdef CONFIG_USER_ONLY
 void page_protect(tb_page_addr_t page_addr);
-int page_unprotect(target_ulong address, uintptr_t pc);
+int page_unprotect(vaddr address, uintptr_t pc);
 #endif
 
 #endif /* TRANSLATE_ALL_H */
Signature · 1 line
2.39.1
#14 lore raw

Re: [PATCH 6/8] accel/tcg: Replace target_ulong with vaddr in page_*()

accel/tcg/user-exec.c typedef struct PageFlagsNode { · line 147

Quoted 2 lines · Anton Johansson
accel/tcg/user-exec.c +1 -1
-static PageFlagsNode *pageflags_find(target_ulong start, target_long last)
+static PageFlagsNode *pageflags_find(vaddr start, target_long last)

Both arguments are target addresses.

r~

#15 lore raw

Re: [PATCH 6/8] accel/tcg: Replace target_ulong with vaddr in page_*()

Quoted 6 lines · Richard Henderson
Quoted 3 lines · Anton Johansson

-static PageFlagsNode *pageflags_find(target_ulong start, target_long last)
+static PageFlagsNode *pageflags_find(vaddr start, target_long last)

Both arguments are target addresses.

See comment in cover letter. In short, I'm unsure why the signedness matters here as even changing last from target_long to target_ulong breaks tests.

Signature · 2 lines
Anton Johansson,
rev.ng Labs Srl.
#16 lore raw

Re: [PATCH 6/8] accel/tcg: Replace target_ulong with vaddr in page_*()

Quoted 10 lines · Anton Johansson
Quoted 5 lines · Richard Henderson

accel/tcg/user-exec.c typedef struct PageFlagsNode { · line 147

Quoted 2 lines · Anton Johansson
accel/tcg/user-exec.c +1 -1
-static PageFlagsNode *pageflags_find(target_ulong start, target_long last)
+static PageFlagsNode *pageflags_find(vaddr start, target_long last)

Both arguments are target addresses.

See comment in cover letter. In short, I'm unsure why the signedness matters here as even changing last from target_long to target_ulong breaks tests.

Really? Odd. It's clearly a typo for last to be signed. I'll have a look.

r~

#17 lore raw

PATCH 7/8 cpu: Replace target_ulong with vaddr in tb_invalidate_phys_addr()

In reply to Anton Johansson via
---
 cpu.c                   | 2 +-
 include/exec/exec-all.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
cpu.c +1 -1
index 849bac062c..c245727ca6 100644
@@ -293,7 +293,7 @@ void list_cpus(const char *optarg)
 }
 
 #if defined(CONFIG_USER_ONLY)
-void tb_invalidate_phys_addr(target_ulong addr)
+void tb_invalidate_phys_addr(vaddr addr)
 {
     mmap_lock();
     tb_invalidate_phys_page(addr);
include/exec/exec-all.h +1 -1
index c6cb3fcb8a..a00c298e4b 100644
@@ -673,7 +673,7 @@ uint32_t curr_cflags(CPUState *cpu);
 
 /* TranslationBlock invalidate API */
 #if defined(CONFIG_USER_ONLY)
-void tb_invalidate_phys_addr(target_ulong addr);
+void tb_invalidate_phys_addr(vaddr addr);
 #else
 void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr, MemTxAttrs attrs);
 #endif
Signature · 1 line
2.39.1
#18 lore raw

Re: [PATCH 7/8] cpu: Replace target_ulong with vaddr in tb_invalidate_phys_addr()

cpu.c void list_cpus(const char *optarg) · line 296

Quoted 2 lines · Anton Johansson
cpu.c +1 -1
-void tb_invalidate_phys_addr(target_ulong addr)
+void tb_invalidate_phys_addr(vaddr addr)

Hmm. This isn't a virtual address, so 'vaddr' isn't right. I'm sure we have something more appropriate.

r~

#19 lore raw

Re: [PATCH 7/8] cpu: Replace target_ulong with vaddr in tb_invalidate_phys_addr()

Quoted 6 lines · Richard Henderson

cpu.c void list_cpus(const char *optarg) · line 296

Quoted 2 lines · Anton Johansson
cpu.c +1 -1
-void tb_invalidate_phys_addr(target_ulong addr)
+void tb_invalidate_phys_addr(vaddr addr)

Hmm.  This isn't a virtual address, so 'vaddr' isn't right. I'm sure we have something more appropriate.

tb_page_addr_t?

#20 lore raw

Re: [PATCH 7/8] cpu: Replace target_ulong with vaddr in tb_invalidate_phys_addr()

Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Richard Henderson

cpu.c void list_cpus(const char *optarg) · line 296

Quoted 2 lines · Anton Johansson
cpu.c +1 -1
-void tb_invalidate_phys_addr(target_ulong addr)
+void tb_invalidate_phys_addr(vaddr addr)

Hmm.  This isn't a virtual address, so 'vaddr' isn't right. I'm sure we have something more appropriate.

tb_page_addr_t?

No, it isn't a ram_addr_t either (see exec-all.h). Perhaps just uint64_t.

r~

#21 lore raw

Re: [PATCH 7/8] cpu: Replace target_ulong with vaddr in tb_invalidate_phys_addr()

Quoted 8 lines · Richard Henderson
Quoted 7 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Richard Henderson

cpu.c void list_cpus(const char *optarg) · line 296

Quoted 2 lines · Anton Johansson
cpu.c +1 -1
-void tb_invalidate_phys_addr(target_ulong addr)
+void tb_invalidate_phys_addr(vaddr addr)

Hmm.  This isn't a virtual address, so 'vaddr' isn't right. I'm sure we have something more appropriate.

Quoted 4 lines
Quoted 1 line

tb_page_addr_t?

No, it isn't a ram_addr_t either (see exec-all.h). Perhaps just uint64_t.

Surely hwaddr?

Quoted 3 lines

r~

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#22 lore raw

Re: [PATCH 7/8] cpu: Replace target_ulong with vaddr in tb_invalidate_phys_addr()

Quoted 11 lines · Alex Bennée
Quoted 8 lines · Richard Henderson
Quoted 7 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Richard Henderson

cpu.c void list_cpus(const char *optarg) · line 296

Quoted 2 lines · Anton Johansson
cpu.c +1 -1
-void tb_invalidate_phys_addr(target_ulong addr)
+void tb_invalidate_phys_addr(vaddr addr)

Hmm.  This isn't a virtual address, so 'vaddr' isn't right. I'm sure we have something more appropriate.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

tb_page_addr_t?

No, it isn't a ram_addr_t either (see exec-all.h). Perhaps just uint64_t.

Surely hwaddr?

Duh. Thanks,

r~

#23 lore raw

Re: [PATCH 7/8] cpu: Replace target_ulong with vaddr in tb_invalidate_phys_addr()

Quoted 12 lines · Richard Henderson
Quoted 11 lines · Alex Bennée
Quoted 8 lines · Richard Henderson
Quoted 7 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Richard Henderson

cpu.c void list_cpus(const char *optarg) · line 296

Quoted 2 lines · Anton Johansson
cpu.c +1 -1
-void tb_invalidate_phys_addr(target_ulong addr)
+void tb_invalidate_phys_addr(vaddr addr)

Hmm.  This isn't a virtual address, so 'vaddr' isn't right. I'm sure we have something more appropriate.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

tb_page_addr_t?

No, it isn't a ram_addr_t either (see exec-all.h). Perhaps just uint64_t.

Surely hwaddr?

Duh.  Thanks,

Thanks guys, and hwaddr it shall be!

Signature · 2 lines
Anton Johansson,
rev.ng Labs Srl.
#24 lore raw

Re: [PATCH 7/8] cpu: Replace target_ulong with vaddr in tb_invalidate_phys_addr()

Quoted 14 lines · Anton Johansson
Quoted 12 lines · Richard Henderson
Quoted 11 lines · Alex Bennée
Quoted 8 lines · Richard Henderson
Quoted 7 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Richard Henderson

Review

Quoted 2 lines · Anton Johansson
(quoted diff) +1 -1
-void tb_invalidate_phys_addr(target_ulong addr)
+void tb_invalidate_phys_addr(vaddr addr)

Hmm.  This isn't a virtual address, so 'vaddr' isn't right. I'm sure we have something more appropriate.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

tb_page_addr_t?

No, it isn't a ram_addr_t either (see exec-all.h). Perhaps just uint64_t.

Surely hwaddr?

But hwaddr is only defined on system emulation...

Quoted 5 lines
Quoted 2 lines

Duh.  Thanks,

Thanks guys, and hwaddr it shall be!

#25 lore raw

PATCH 8/8 tcg: Replace target_ulong with vaddr in tcg_gen_code()

In reply to Anton Johansson via
---
 include/tcg/tcg.h | 2 +-
 tcg/tcg.c         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/tcg/tcg.h +1 -1
index 5cfaa53938..b8dbc66610 100644
@@ -852,7 +852,7 @@ void tcg_register_thread(void);
 void tcg_prologue_init(TCGContext *s);
 void tcg_func_start(TCGContext *s);
 
-int tcg_gen_code(TCGContext *s, TranslationBlock *tb, target_ulong pc_start);
+int tcg_gen_code(TCGContext *s, TranslationBlock *tb, vaddr pc_start);
 
 void tb_target_set_jmp_target(const TranslationBlock *, int,
                               uintptr_t, uintptr_t);
tcg/tcg.c +1 -1
index bb52bc060b..3823c3156a 100644
@@ -4922,7 +4922,7 @@ int64_t tcg_cpu_exec_time(void)
 #endif
 
 
-int tcg_gen_code(TCGContext *s, TranslationBlock *tb, target_ulong pc_start)
+int tcg_gen_code(TCGContext *s, TranslationBlock *tb, vaddr pc_start)
 {
 #ifdef CONFIG_PROFILER
     TCGProfile *prof = &s->prof;
Signature · 1 line
2.39.1
#27 lore raw
In reply to Anton Johansson via
Quoted 34 lines · Anton Johansson

This is a first patchset in removing target_ulong from non-target/ directories. As use of target_ulong is spread accross the codebase we are attempting to target as few maintainers as possible with each patchset in order to ease reviewing.

The following instances of target_ulong remain in accel/ and tcg/
- atomic helpers (atomic_common.c.inc), cpu_atomic_*() (atomic_template.h,) and cpu_[st|ld]*() (cputlb.c/ldst_common.c.inc) are only used in target/ and can be pulled out into a separate target-specific file;

- Calls to cpu_get_tb_cpu_state() cast pc and cs_base to target_ulong in order to avoid having to touch the target/ directory in this patchset;

- walk_memory_regions() is used in user-exec.c and linux-user/elfload.c;

- helper_ret_*_mmu() is used in tcg/*/tcg-target.c.inc and tcg/tci.c;

- Functions in translate-all.c dealing with TCGContext.gen_insn_data will be switched off target_ulong once gen_insn_data and TARGET_INSN_START_WORDS have been dealt with;

- kvm_find_sw_breakpoint() in kvm-all.c used in target/;

- The last address when looking up page flags for an interval [start,last] in pageflags_find()/pageflags_next() is still target_long. I'm not sure why this is required. This only seems relevant on 32-bit guests since the addresses passed to the interval tree are uint64_t's, are we relying on a sign extension here for some reason?

Quoted 4 lines

- CPUTLBEntry and functions that read from it will be left for a later date;

Smaller patchsets implementing above changes will follow.

You may wish to browse my work in progress

https://gitlab.com/rth7680/qemu/-/commits/tcg-once/

to avoid duplication, as I have done some of these. This tree is on top of my atomicity patch set; I'm working on upstreaming that now.

r~

#28 lore raw
Quoted 5 lines · Richard Henderson

You may wish to browse my work in progress

  https://gitlab.com/rth7680/qemu/-/commits/tcg-once/

to avoid duplication, as I have done some of these.  This tree is on top of my atomicity patch set; I'm working on upstreaming that now.

I had a suspicion that would be the case, I'll take a look. Thanks!

Signature · 2 lines
Anton Johansson,
rev.ng Labs Srl.