Mirror map JIT memory for TCG
Subsystems (2)
v4 cover Mirror map JIT memory for TCG
Changes for v4:
* Move flush_icache_range to util/.
The fixme that I added before to softmmu/physmem.c actually happened now that we're building aarch64 xen in gitlab-ci.
* Fix ifdefs for "Remove TCG_TARGET_SUPPORT_MIRROR".
r~
Richard Henderson (43):
tcg: Do not flush icache for interpreter
util: Extract flush_icache_range to cacheflush.c
util: Enhance flush_icache_range with separate data pointer
util: Specialize flush_idcache_range for aarch64
tcg: Move tcg prologue pointer out of TCGContext
tcg: Move tcg epilogue pointer out of TCGContext
tcg: Add in_code_gen_buffer
tcg: Introduce tcg_splitwx_to_{rx,rw}
tcg: Adjust TCGLabel for const
tcg: Adjust tcg_out_call for const
tcg: Adjust tcg_out_label for const
tcg: Adjust tcg_register_jit for const
tcg: Adjust tb_target_set_jmp_target for split-wx
tcg: Make DisasContextBase.tb const
tcg: Make tb arg to synchronize_from_tb const
tcg: Use Error with alloc_code_gen_buffer
tcg: Add --accel tcg,split-wx property
accel/tcg: Support split-wx for linux with memfd accel/tcg: Support split-wx for darwin/iOS with vm_remap
tcg: Return the TB pointer from the rx region from exit_tb tcg/i386: Support split-wx code generation
tcg/aarch64: Use B not BL for tcg_out_goto_long tcg/aarch64: Support split-wx code generation
disas: Push const down through host disasassembly tcg/tci: Push const down through bytecode reading
tcg: Introduce tcg_tbrel_diff
tcg/ppc: Use tcg_tbrel_diff
tcg/ppc: Use tcg_out_mem_long to reset TCG_REG_TB tcg/ppc: Support split-wx code generation
tcg/sparc: Use tcg_tbrel_diff
tcg/sparc: Support split-wx code generation
tcg/s390: Use tcg_tbrel_diff
tcg/s390: Support split-wx code generation
tcg/riscv: Fix branch range checks
tcg/riscv: Remove branch-over-branch fallback tcg/riscv: Support split-wx code generation
accel/tcg: Add mips support to alloc_code_gen_buffer_splitwx_memfd tcg/mips: Do not assert on relocation overflow tcg/mips: Support split-wx code generation
tcg/arm: Support split-wx code generation
tcg: Remove TCG_TARGET_SUPPORT_MIRROR
tcg: Constify tcg_code_gen_epilogue
tcg: Constify TCGLabelQemuLdst.raddr
accel/tcg/tcg-runtime.h | 2 +- include/disas/dis-asm.h | 4 +- include/disas/disas.h | 2 +- include/exec/exec-all.h | 2 +- include/exec/gen-icount.h | 4 +- include/exec/log.h | 2 +- include/exec/translator.h | 2 +- include/hw/core/cpu.h | 3 +- include/qemu/cacheflush.h | 35 ++++ include/sysemu/tcg.h | 3 +- include/tcg/tcg-op.h | 2 +- include/tcg/tcg.h | 56 +++++-- tcg/aarch64/tcg-target.h | 7 +- tcg/arm/tcg-target.h | 7 +- tcg/i386/tcg-target.h | 10 +- tcg/mips/tcg-target.h | 13 +- tcg/ppc/tcg-target.h | 3 +- tcg/riscv/tcg-target.h | 7 +- tcg/s390/tcg-target.h | 12 +- tcg/sparc/tcg-target.h | 10 +- tcg/tci/tcg-target.h | 10 +- accel/tcg/cpu-exec.c | 41 +++-- accel/tcg/tcg-all.c | 26 ++- accel/tcg/tcg-runtime.c | 4 +- accel/tcg/translate-all.c | 309 +++++++++++++++++++++++++++-------- accel/tcg/translator.c | 4 +- bsd-user/main.c | 2 +- disas.c | 2 +- disas/capstone.c | 2 +- linux-user/main.c | 2 +- softmmu/physmem.c | 3 +- target/arm/cpu.c | 3 +- target/arm/translate-a64.c | 2 +- target/avr/cpu.c | 3 +- target/hppa/cpu.c | 3 +- target/i386/cpu.c | 3 +- target/microblaze/cpu.c | 3 +- target/mips/cpu.c | 3 +- target/riscv/cpu.c | 3 +- target/rx/cpu.c | 3 +- target/sh4/cpu.c | 3 +- target/sparc/cpu.c | 3 +- target/tricore/cpu.c | 2 +- tcg/tcg-op.c | 15 +- tcg/tcg.c | 91 +++++++++-- tcg/tci.c | 60 ++++--- util/cacheflush.c | 146 +++++++++++++++++ util/cacheinfo.c | 8 +- MAINTAINERS | 2 + accel/tcg/trace-events | 2 +- tcg/aarch64/tcg-target.c.inc | 75 +++++---- tcg/arm/tcg-target.c.inc | 41 ++--- tcg/i386/tcg-target.c.inc | 36 ++-- tcg/mips/tcg-target.c.inc | 97 +++++------ tcg/ppc/tcg-target.c.inc | 110 ++++++------- tcg/riscv/tcg-target.c.inc | 125 +++++--------- tcg/s390/tcg-target.c.inc | 91 +++++------ tcg/sparc/tcg-target.c.inc | 58 +++---- tcg/tcg-ldst.c.inc | 2 +- tcg/tcg-pool.c.inc | 6 +- tcg/tci/tcg-target.c.inc | 2 +- util/meson.build | 2 +- 62 files changed, 1003 insertions(+), 591 deletions(-) create mode 100644 include/qemu/cacheflush.h create mode 100644 util/cacheflush.c
Signature · 1 line
2.25.1
PATCH v4 1/43 tcg: Do not flush icache for interpreter
This is currently a no-op within tci/tcg-target.h, but is about to be moved to a more generic location.
--- tcg/tcg.c | 4 ++++ 1 file changed, 4 insertions(+)
tcg/tcg.c +4 -0
@@ -1077,7 +1077,9 @@ void tcg_prologue_init(TCGContext *s)#endif buf1 = s->code_ptr; +#ifndef CONFIG_TCG_INTERPRETER flush_icache_range ((uintptr_t )buf0, (uintptr_t )buf1); +#endif /* Deduct the prologue from the buffer. */ prologue_size =tcg_current_code_size (s);
@@ -4319,8 +4321,10 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)return -2 ; } +#ifndef CONFIG_TCG_INTERPRETER /* flush instruction cache */ flush_icache_range ((uintptr_t )s->code_buf, (uintptr_t )s->code_ptr); +#endif return tcg_current_code_size (s); }
Signature · 1 line
2.25.1
Re: [PATCH v4 01/43] tcg: Do not flush icache for interpreter
Quoted 5 lines · Richard Henderson
This is currently a no-op within
tci/tcg-target.h, but is about to be moved to a more generic location.Signed-off-by Richard Henderson <[email protected]>
PATCH v4 2/43 util: Extract flush_icache_range to cacheflush.c
In reply to Richard HendersonThis has been a tcg-specific function, but is also in use by hardware accelerators via physmem.c. This can cause link errors when tcg is disabled.
--- include/qemu/cacheflush.h | 24 +++++++++++++ tcg/aarch64/tcg-target.h | 5 --- tcg/arm/tcg-target.h | 5 --- tcg/i386/tcg-target.h | 4 --- tcg/mips/tcg-target.h | 11 ------ tcg/ppc/tcg-target.h | 1 - tcg/riscv/tcg-target.h | 5 --- tcg/s390/tcg-target.h | 4 --- tcg/sparc/tcg-target.h | 8 ----- tcg/tci/tcg-target.h | 4 --- softmmu/physmem.c | 1 + tcg/tcg.c | 1 + util/cacheflush.c | 71 +++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 2 ++ tcg/ppc/tcg-target.c.inc | 22 ------------ util/meson.build | 2 +- 16 files changed, 100 insertions(+), 70 deletions(-) create mode 100644 include/qemu/cacheflush.h create mode 100644 util/cacheflush.c
include/qemu/cacheflush.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* Flush the host cpu caches. +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef QEMU_CACHEFLUSH_H +#define QEMU_CACHEFLUSH_H + +#if defined(__i386__) || defined(__x86_64__) || defined(__s390__) + +static inline void flush_icache_range (uintptr_t start,uintptr_t stop) +{ +/* icache is coherent and does not require flushing. */ +} + +#else + +void flush_icache_range (uintptr_t start,uintptr_t stop); + +#endif + +#endif /* QEMU_CACHEFLUSH_H */
tcg/aarch64/tcg-target.h +0 -5
@@ -148,11 +148,6 @@ typedef enum {#define TCG_TARGET_DEFAULT_MO (0)#define TCG_TARGET_HAS_MEMORY_BSWAP 1 -static inline void flush_icache_range (uintptr_t start,uintptr_t stop) -{ -__builtin___clear_cache ((char *)start, (char *)stop); -} -void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t );#ifdef CONFIG_SOFTMMU
tcg/arm/tcg-target.h +0 -5
@@ -134,11 +134,6 @@ enum {#define TCG_TARGET_DEFAULT_MO (0)#define TCG_TARGET_HAS_MEMORY_BSWAP 1 -static inline void flush_icache_range (uintptr_t start,uintptr_t stop) -{ -__builtin___clear_cache ((char *) start, (char *) stop); -} -/* not defined -- call should be eliminated at compile time */ void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t );
tcg/i386/tcg-target.h +0 -4
@@ -206,10 +206,6 @@ extern bool have_avx2;#define TCG_TARGET_extract_i64_valid (ofs, len) \ (((ofs) == 8 && (len) == 8) || ((ofs) + (len)) == 32) -static inline void flush_icache_range (uintptr_t start,uintptr_t stop) -{ -} -static inline void tb_target_set_jmp_target (uintptr_t tc_ptr,uintptr_t jmp_addr,uintptr_t addr) {
tcg/mips/tcg-target.h +0 -11
@@ -198,20 +198,9 @@ extern bool use_mips32r2_instructions;#define TCG_TARGET_HAS_ext16u_i64 0/* andi rt, rs, 0xffff */ #endif -#ifdef __OpenBSD__ -#include <machine/sysarch.h> -#else -#include <sys/cachectl.h> -#endif -#define TCG_TARGET_DEFAULT_MO (0)#define TCG_TARGET_HAS_MEMORY_BSWAP 1 -static inline void flush_icache_range (uintptr_t start,uintptr_t stop) -{ -cacheflush ((void *)start, stop-start,ICACHE ); -} -void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t );#ifdef CONFIG_SOFTMMU
tcg/ppc/tcg-target.h +0 -1
@@ -175,7 +175,6 @@ extern bool have_vsx;#define TCG_TARGET_HAS_bitsel_vec have_vsx#define TCG_TARGET_HAS_cmpsel_vec 0 -void flush_icache_range (uintptr_t start,uintptr_t stop);void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t );#define TCG_TARGET_DEFAULT_MO (0)
tcg/riscv/tcg-target.h +0 -5
@@ -159,11 +159,6 @@ typedef enum {#define TCG_TARGET_HAS_mulsh_i64 1#endif -static inline void flush_icache_range (uintptr_t start,uintptr_t stop) -{ -__builtin___clear_cache ((char *)start, (char *)stop); -} -/* not defined -- call should be eliminated at compile time */ void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t );
tcg/s390/tcg-target.h +0 -4
@@ -145,10 +145,6 @@ enum { TCG_AREG0 = TCG_REG_R10, }; -static inline void flush_icache_range (uintptr_t start,uintptr_t stop) -{ -} -static inline void tb_target_set_jmp_target (uintptr_t tc_ptr,uintptr_t jmp_addr,uintptr_t addr) {
tcg/sparc/tcg-target.h +0 -8
@@ -168,14 +168,6 @@ extern bool use_vis3_instructions;#define TCG_TARGET_DEFAULT_MO (0)#define TCG_TARGET_HAS_MEMORY_BSWAP 1 -static inline void flush_icache_range (uintptr_t start,uintptr_t stop) -{ -uintptr_t p; -for (p = start &-8 ; p < ((stop +7 ) &-8 ); p +=8 ) { - __asm__ __volatile__("flush\t%0" : :"r" (p)); - } -} -void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t );#define TCG_TARGET_NEED_POOL_LABELS
tcg/tci/tcg-target.h +0 -4
@@ -191,10 +191,6 @@ void tci_disas(uint8_t opc);#define HAVE_TCG_QEMU_TB_EXEC -static inline void flush_icache_range (uintptr_t start,uintptr_t stop) -{ -} -/* We could notice __i386__ or __s390x__ and reduce the barriers depending on the host. But if you want performance, you use the normal backend. We prefer consistency across hosts on this. */
softmmu/physmem.c +1 -0
@@ -22,6 +22,7 @@#include "qapi/error.h" #include "qemu/cutils.h" +#include "qemu/cacheflush.h" #include "cpu.h" #include "exec/exec-all.h" #include "exec/target_page.h"
tcg/tcg.c +1 -0
@@ -35,6 +35,7 @@#include "qemu/host-utils.h" #include "qemu/qemu-print.h" #include "qemu/timer.h" +#include "qemu/cacheflush.h" /* Note: the long term plan is to reduce the dependencies on the QEMU CPU definitions. Currently they are used for qemu_ld/st
util/cacheflush.c new file +71 -0
71 lines not on this page · raw message
MAINTAINERS +2 -0
@@ -119,6 +119,8 @@ F: softmmu/cpus.c F: cpus-common.c F: accel/tcg/ F: accel/stubs/tcg-stub.c +F: util/cacheinfo.c +F: util/cacheflush.c F: scripts/decodetree.py F: docs/devel/decodetree.rst F: include/exec/cpu*.h
tcg/ppc/tcg-target.c.inc +0 -22
@@ -3863,25 +3863,3 @@ void tcg_register_jit(void *buf, size_t buf_size) tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame)); } #endif /* __ELF__ */ - -void flush_icache_range(uintptr_t start, uintptr_t stop) -{ - uintptr_t p, start1, stop1; - size_t dsize = qemu_dcache_linesize; - size_t isize = qemu_icache_linesize; - - start1 = start & ~(dsize - 1); - stop1 = (stop + dsize - 1) & ~(dsize - 1); - for (p = start1; p < stop1; p += dsize) { - asm volatile ("dcbst 0,%0" : : "r"(p) : "memory"); - } - asm volatile ("sync" : : : "memory"); - - start &= start & ~(isize - 1); - stop1 = (stop + isize - 1) & ~(isize - 1); - for (p = start1; p < stop1; p += isize) { - asm volatile ("icbi 0,%0" : : "r"(p) : "memory"); - } - asm volatile ("sync" : : : "memory"); - asm volatile ("isync" : : : "memory"); -}
util/meson.build +1 -1
@@ -21,7 +21,7 @@ util_ss.add(files('envlist.c', 'path.c', 'module.c')) util_ss.add(files('host-utils.c')) util_ss.add(files('bitmap.c', 'bitops.c')) util_ss.add(files('fifo8.c')) -util_ss.add(files('cacheinfo.c')) +util_ss.add(files('cacheinfo.c', 'cacheflush.c')) util_ss.add(files('error.c', 'qemu-error.c')) util_ss.add(files('qemu-print.c')) util_ss.add(files('id.c'))
Signature · 1 line
2.25.1
Re: [PATCH v4 02/43] util: Extract flush_icache_range to cacheflush.c
Quoted 15 lines · Richard Henderson
This has been a tcg-specific function, but is also in use by hardware accelerators via
physmem.c. This can cause link errors when tcg is disabled.Signed-off-by Richard Henderson <[email protected]>--- include/qemu/cacheflush.h | 24 +++++++++++++ tcg/aarch64/tcg-target.h | 5 --- tcg/arm/tcg-target.h | 5 --- tcg/i386/tcg-target.h | 4 --- tcg/mips/tcg-target.h | 11 ------ tcg/ppc/tcg-target.h | 1 - tcg/riscv/tcg-target.h | 5 --- tcg/s390/tcg-target.h | 4 --- tcg/sparc/tcg-target.h | 8 -----
Quoted 8 lines
tcg/tci/tcg-target.h | 4 --- softmmu/physmem.c | 1 + tcg/tcg.c | 1 + util/cacheflush.c | 71 +++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 2 ++ tcg/ppc/tcg-target.c.inc | 22 ------------ util/meson.build | 2 +- 16 files changed, 100 insertions(+), 70 deletions(-)
Re: [PATCH v4 02/43] util: Extract flush_icache_range to cacheflush.c
In reply to Richard HendersonQuoted 6 lines · Richard Henderson
This has been a tcg-specific function, but is also in use by hardware accelerators via
physmem.c. This can cause link errors when tcg is disabled.Signed-off-by Richard Henderson <[email protected]>
PATCH v4 3/43 util: Enhance flush_icache_range with separate data pointer
In reply to Richard HendersonWe are shortly going to have a split rw/rx jit buffer. Depending on the host, we need to flush the dcache at the rw data pointer and flush the icache at the rx code pointer.
For now, the two passed pointers are identical, so there is no effective change in behaviour.
--- include/qemu/cacheflush.h | 15 ++++++++++++-- softmmu/physmem.c | 2 +- tcg/tcg.c | 6 ++++-- util/cacheflush.c | 38 +++++++++++++++++++++--------------- util/cacheinfo.c | 8 +++++--- tcg/aarch64/tcg-target.c.inc | 2 +- tcg/mips/tcg-target.c.inc | 2 +- tcg/ppc/tcg-target.c.inc | 4 ++-- tcg/sparc/tcg-target.c.inc | 4 ++-- 9 files changed, 51 insertions(+), 30 deletions(-)
include/qemu/cacheflush.h +13 -2
@@ -8,16 +8,27 @@#ifndef QEMU_CACHEFLUSH_H #define QEMU_CACHEFLUSH_H +/** +* flush_idcache_range: +* @rx: instruction address +* @rw: data address +* @len: length to flush +* +* Flush @len bytes of the data cache at @rw and the icache at @rx +* to bring them in sync. The two addresses may be different virtual +* mappings of the same physical page(s). +*/ +#if defined(__i386__) || defined(__x86_64__) || defined(__s390__) -static inline void flush_icache_range (uintptr_t start,uintptr_t stop) +static inline void flush_idcache_range (uintptr_t rx,uintptr_t rw,size_t len) {/* icache is coherent and does not require flushing. */ }#else -void flush_icache_range (uintptr_t start,uintptr_t stop); +void flush_idcache_range (uintptr_t rx,uintptr_t rw,size_t len);#endif
softmmu/physmem.c +1 -1
@@ -2947,7 +2947,7 @@ static inline MemTxResult address_space_write_rom_internal(AddressSpace *as,invalidate_and_set_dirty (mr, addr1, l);break ;case FLUSH_CACHE : -flush_icache_range ((uintptr_t )ram_ptr, (uintptr_t )ram_ptr + l); +flush_idcache_range ((uintptr_t )ram_ptr, (uintptr_t )ram_ptr, l);break ; } }
tcg/tcg.c +4 -2
@@ -1079,7 +1079,8 @@ void tcg_prologue_init(TCGContext *s) buf1 = s->code_ptr;#ifndef CONFIG_TCG_INTERPRETER -flush_icache_range ((uintptr_t )buf0, (uintptr_t )buf1); +flush_idcache_range ((uintptr_t )buf0, (uintptr_t )buf0, +tcg_ptr_byte_diff (buf1, buf0));#endif /* Deduct the prologue from the buffer. */
@@ -4324,7 +4325,8 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)#ifndef CONFIG_TCG_INTERPRETER /* flush instruction cache */ -flush_icache_range ((uintptr_t )s->code_buf, (uintptr_t )s->code_ptr); +flush_idcache_range ((uintptr_t )s->code_buf, (uintptr_t )s->code_buf, +tcg_ptr_byte_diff (s->code_ptr, s->code_buf));#endif return tcg_current_code_size (s);
util/cacheflush.c +22 -16
@@ -21,29 +21,32 @@#include <sys/cachectl.h> #endif -void flush_icache_range (uintptr_t start,uintptr_t stop) +void flush_idcache_range (uintptr_t rx,uintptr_t rw,size_t len) { -cacheflush ((void *)start, stop - start,ICACHE ); +if (rx != rw) { +cacheflush ((void *)rw, len,DCACHE ); + } +cacheflush ((void *)rx, len,ICACHE ); }#elif defined(__powerpc__) -void flush_icache_range (uintptr_t start,uintptr_t stop) +void flush_idcache_range (uintptr_t rx,uintptr_t rw,size_t len) { -uintptr_t p, start1, stop1; +uintptr_t p, b, e;size_t dsize = qemu_dcache_linesize;size_t isize = qemu_icache_linesize; - start1 = start & ~(dsize -1 ); - stop1 = (stop + dsize -1 ) & ~(dsize -1 ); -for (p = start1; p < stop1; p += dsize) { + b = rw & ~(dsize -1 ); + e = (rw + len + dsize -1 ) & ~(dsize -1 ); +for (p = b; p < e; p += dsize) { asmvolatile ("dcbst 0,%0" : :"r" (p) :"memory" ); } asmvolatile ("sync" : : :"memory" ); - start &= start & ~(isize -1 ); - stop1 = (stop + isize -1 ) & ~(isize -1 ); -for (p = start1; p < stop1; p += isize) { + b = rx & ~(isize -1 ); + e = (rx + len + isize -1 ) & ~(isize -1 ); +for (p = b; p < e; p += isize) { asmvolatile ("icbi 0,%0" : :"r" (p) :"memory" ); } asmvolatile ("sync" : : :"memory" );
@@ -52,20 +55,23 @@ void flush_icache_range(uintptr_t start, uintptr_t stop)#elif defined(__sparc__) -void flush_icache_range (uintptr_t start,uintptr_t stop) +void flush_idcache_range (uintptr_t rx,uintptr_t rw,size_t len) { -uintptr_t p; - -for (p = start &-8 ; p < ((stop +7 ) &-8 ); p +=8 ) { +/* No additional data flush to the RW virtual address required. */ +uintptr_t p, end = (rx + len +7 ) &-8 ; +for (p = rx &-8 ; p < end; p +=8 ) { __asm__ __volatile__("flush\t%0" : :"r" (p)); } }#else -void flush_icache_range (uintptr_t start,uintptr_t stop) +void flush_idcache_range (uintptr_t rx,uintptr_t rw,size_t len) { -__builtin___clear_cache ((char *)start, (char *)stop); +if (rw != rx) { +__builtin___clear_cache ((char *)rw, (char *)rw + len); + } +__builtin___clear_cache ((char *)rx, (char *)rx + len); }#endif
util/cacheinfo.c +5 -3
@@ -166,9 +166,11 @@ static void fallback_cache_info(int *isize, int *dsize) *isize = *dsize; }else {#if defined(_ARCH_PPC) -/* For PPC, we're going to use the icache size computed for -flush_icache_range. Which means that we must use the -architecture minimum. */ +/* +* For PPC, we're going to use the cache sizes computed for +* flush_idcache_range. Which means that we must use the +* architecture minimum. +*/ *isize = *dsize =16 ;#else /* Otherwise, 64 bytes is not uncommon. */
tcg/aarch64/tcg-target.c.inc +1 -1
@@ -1363,7 +1363,7 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, } pair = (uint64_t)i2 << 32 | i1; qatomic_set((uint64_t *)jmp_addr, pair); - flush_icache_range(jmp_addr, jmp_addr + 8); + flush_idcache_range(jmp_addr, jmp_addr, 8); } static inline void tcg_out_goto_label(TCGContext *s, TCGLabel *l)
tcg/mips/tcg-target.c.inc +1 -1
@@ -2660,7 +2660,7 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, uintptr_t addr) { qatomic_set((uint32_t *)jmp_addr, deposit32(OPC_J, 0, 26, addr >> 2)); - flush_icache_range(jmp_addr, jmp_addr + 4); + flush_idcache_range(jmp_addr, jmp_addr, 4); } typedef struct {
tcg/ppc/tcg-target.c.inc +2 -2
@@ -1753,12 +1753,12 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, /* As per the enclosing if, this is ppc64. Avoid the _Static_assert within qatomic_set that would fail to build a ppc32 host. */ qatomic_set__nocheck((uint64_t *)jmp_addr, pair); - flush_icache_range(jmp_addr, jmp_addr + 8); + flush_idcache_range(jmp_addr, jmp_addr, 8); } else { intptr_t diff = addr - jmp_addr; tcg_debug_assert(in_range_b(diff)); qatomic_set((uint32_t *)jmp_addr, B | (diff & 0x3fffffc)); - flush_icache_range(jmp_addr, jmp_addr + 4); + flush_idcache_range(jmp_addr, jmp_addr, 4); } }
tcg/sparc/tcg-target.c.inc +2 -2
@@ -1836,7 +1836,7 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, if (!USE_REG_TB) { qatomic_set((uint32_t *)jmp_addr, deposit32(CALL, 0, 30, br_disp >> 2)); - flush_icache_range(jmp_addr, jmp_addr + 4); + flush_idcache_range(jmp_addr, jmp_addr, 4); return; }
@@ -1860,5 +1860,5 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, } qatomic_set((uint64_t *)jmp_addr, deposit64(i2, 32, 32, i1)); - flush_icache_range(jmp_addr, jmp_addr + 8); + flush_idcache_range(jmp_addr, jmp_addr, 8); }
Signature · 1 line
2.25.1
Re: [PATCH v4 03/43] util: Enhance flush_icache_range with separate data pointer
Quoted 10 lines · Richard Henderson
We are shortly going to have a split rw/rx jit buffer. Depending on the host, we need to flush the dcache at the rw data pointer and flush the icache at the rx code pointer.
For now, the two passed pointers are identical, so there is no effective change in behaviour.
Reviewed-by Alex Bennée <[email protected]>Signed-off-by Richard Henderson <[email protected]>
PATCH v4 4/43 util: Specialize flush_idcache_range for aarch64
In reply to Richard HendersonFor darwin, the CTR_EL0 register is not accessible, but there are system routines that we can use.
For other hosts, copy the single pointer implementation from libgcc and modify it to support the double pointer interface we require. This halves the number of cache operations required when split-rwx is enabled.
--- util/cacheflush.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+)
util/cacheflush.c +69 -0
@@ -7,12 +7,81 @@#include "qemu/osdep.h" #include "qemu/cacheflush.h" +#include "qemu/bitops.h" #if defined(__i386__) || defined(__x86_64__) || defined(__s390__)/* Caches are coherent and do not require flushing; symbol inline. */ +#elif defined(__aarch64__) + +#ifdef CONFIG_DARWIN +/* Apple does not expose CTR_EL0, so we must use system interfaces. */ +extern void sys_icache_invalidate (void *start,size_t len); +extern void sys_dcache_flush (void *start,size_t len); +void flush_idcache_range (uintptr_t rx,uintptr_t rw,size_t len) +{ +sys_dcache_flush ((void *)rw, len); +sys_icache_invalidate ((void *)rx, len); +} +#else + +/* +* TODO: unify this with cacheinfo.c. +* We want to save the whole contents of CTR_EL0, so that we +* have more than the linesize, but also IDC and DIC. +*/ +static unsigned int save_ctr_el0; +static void __attribute__((constructor))init_ctr_el0 (void ) +{ + asmvolatile ("mrs\t%0, ctr_el0" :"=r" (save_ctr_el0)); +} + +/* +* This is a copy of gcc's __aarch64_sync_cache_range, modified +* to fit this three-operand interface. +*/ +void flush_idcache_range (uintptr_t rx,uintptr_t rw,size_t len) +{ +const unsigned CTR_IDC =1u <<28 ; +const unsigned CTR_DIC =1u <<29 ; +const unsigned int ctr_el0 = save_ctr_el0; +const uintptr_t icache_lsize =4 <<extract32 (ctr_el0,0 ,4 ); +const uintptr_t dcache_lsize =4 <<extract32 (ctr_el0,16 ,4 ); +uintptr_t p; + +/* +* If CTR_EL0.IDC is enabled, Data cache clean to the Point of Unification +* is not required for instruction to data coherence. +*/ +if (!(ctr_el0 &CTR_IDC )) { +/* +* Loop over the address range, clearing one cache line at once. +* Data cache must be flushed to unification first to make sure +* the instruction cache fetches the updated data. +*/ +for (p = rw & -dcache_lsize; p < rw + len; p += dcache_lsize) { + asmvolatile ("dc\tcvau, %0" : :"r" (p) :"memory" ); + } + asmvolatile ("dsb\tish" : : :"memory" ); + } + +/* +* If CTR_EL0.DIC is enabled, Instruction cache cleaning to the Point +* of Unification is not required for instruction to data coherence. +*/ +if (!(ctr_el0 &CTR_DIC )) { +for (p = rx & -icache_lsize; p < rx + len; p += icache_lsize) { + asmvolatile ("ic\tivau, %0" : :"r" (p) :"memory" ); + } + asmvolatile ("dsb\tish" : : :"memory" ); + } + + asmvolatile ("isb" : : :"memory" ); +} +#endif /* CONFIG_DARWIN */ +#elif defined(__mips__)#ifdef __OpenBSD__
Signature · 1 line
2.25.1
Re: [PATCH v4 04/43] util: Specialize flush_idcache_range for aarch64
Quoted 11 lines · Richard Henderson
For darwin, the
CTR_EL0register is not accessible, but there are system routines that we can use.For other hosts, copy the single pointer implementation from libgcc and modify it to support the double pointer interface we require. This halves the number of cache operations required when split-rwx is enabled.
Cc Joelle van Dyne <[email protected]>Signed-off-by Richard Henderson <[email protected]>
PATCH v4 5/43 tcg: Move tcg prologue pointer out of TCGContext
In reply to Richard HendersonThis value is constant across all thread-local copies of TCGContext, so we might as well move it out of thread-local storage.
Use the correct function pointer type, and name the variable tcg_qemu_tb_exec, which means that we are able to remove the macro that does the casting.
Replace HAVE_TCG_QEMU_TB_EXEC with CONFIG_TCG_INTERPRETER, as this is somewhat clearer in intent.
--- include/tcg/tcg.h | 9 ++++----- tcg/tcg.c | 9 ++++++++- tcg/tci.c | 3 ++- 3 files changed, 14 insertions(+), 7 deletions(-)
include/tcg/tcg.h +4 -5
@@ -621,7 +621,6 @@ struct TCGContext {here, because there's too much arithmetic throughout that relies on addition and subtraction working on bytes. Rely on the GCC extension that allows arithmetic on void*. */ -void *code_gen_prologue;void *code_gen_epilogue;void *code_gen_buffer;size_t code_gen_buffer_size;
@@ -1222,11 +1221,11 @@ static inline unsigned get_mmuidx(TCGMemOpIdx oi)#define TB_EXIT_IDXMAX 1#define TB_EXIT_REQUESTED 3 -#ifdef HAVE_TCG_QEMU_TB_EXEC -uintptr_t tcg_qemu_tb_exec (CPUArchState *env,uint8_t *tb_ptr); +#ifdef CONFIG_TCG_INTERPRETER +uintptr_t tcg_qemu_tb_exec (CPUArchState *env,void *tb_ptr);#else -# define tcg_qemu_tb_exec (env, tb_ptr) \ - ((uintptr_t (*)(void *, void *))tcg_ctx->code_gen_prologue)(env, tb_ptr) +typedef uintptr_t tcg_prologue_fn (CPUArchState *env,void *tb_ptr); +extern tcg_prologue_fn *tcg_qemu_tb_exec;#endif void tcg_register_jit (void *buf,size_t buf_size);
tcg/tcg.c +8 -1
@@ -162,6 +162,10 @@ static TCGContext **tcg_ctxs;static unsigned int n_tcg_ctxs;TCGv_env cpu_env =0 ; +#ifndef CONFIG_TCG_INTERPRETER +tcg_prologue_fn *tcg_qemu_tb_exec; +#endif +struct tcg_region_tree {QemuMutex lock;GTree *tree;
@@ -1055,7 +1059,10 @@ void tcg_prologue_init(TCGContext *s) s->code_ptr = buf0; s->code_buf = buf0; s->data_gen_ptr =NULL ; - s->code_gen_prologue = buf0; + +#ifndef CONFIG_TCG_INTERPRETER + tcg_qemu_tb_exec = (tcg_prologue_fn *)buf0; +#endif /* Compute a high-water mark, at which we voluntarily flush the buffer and start over. The size here is arbitrary, significantly larger
tcg/tci.c +2 -1
@@ -475,8 +475,9 @@ static bool tci_compare64(uint64_t u0, uint64_t u1, TCGCond condition)#endif /* Interpret pseudo code in tb. */ -uintptr_t tcg_qemu_tb_exec (CPUArchState *env,uint8_t *tb_ptr) +uintptr_t tcg_qemu_tb_exec (CPUArchState *env,void *v_tb_ptr) { +uint8_t *tb_ptr = v_tb_ptr;tcg_target_ulong regs[TCG_TARGET_NB_REGS ];long tcg_temps[CPU_TEMP_BUF_NLONGS ];uintptr_t sp_value = (uintptr_t )(tcg_temps +CPU_TEMP_BUF_NLONGS );
Signature · 1 line
2.25.1
Re: [PATCH v4 05/43] tcg: Move tcg prologue pointer out of TCGContext
Quoted 10 lines · Richard Henderson
This value is constant across all thread-local copies of TCGContext, so we might as well move it out of thread-local storage.
Use the correct function pointer type, and name the variable
tcg_qemu_tb_exec, which means that we are able to remove the macro that does the casting.Replace
HAVE_TCG_QEMU_TB_EXECwithCONFIG_TCG_INTERPRETER, as this is somewhat clearer in intent.
Quoted 7 lines
Reviewed-by Alex Bennée <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- include/tcg/tcg.h | 9 ++++----- tcg/tcg.c | 9 ++++++++- tcg/tci.c | 3 ++- 3 files changed, 14 insertions(+), 7 deletions(-)
Quoted 72 lines
include/tcg/tcg.h +4
-5@@ -621,7 +621,6 @@ struct TCGContext {here, because there's too much arithmetic throughout that relies on addition and subtraction working on bytes. Rely on the GCC extension that allows arithmetic on void*. */ -void *code_gen_prologue;void *code_gen_epilogue;void *code_gen_buffer;size_t code_gen_buffer_size;@@ -1222,11 +1221,11 @@ static inline unsigned get_mmuidx(TCGMemOpIdx oi)#define TB_EXIT_IDXMAX 1#define TB_EXIT_REQUESTED 3 -#ifdef HAVE_TCG_QEMU_TB_EXEC -uintptr_t tcg_qemu_tb_exec (CPUArchState *env,uint8_t *tb_ptr); +#ifdef CONFIG_TCG_INTERPRETER +uintptr_t tcg_qemu_tb_exec (CPUArchState *env,void *tb_ptr);#else -# define tcg_qemu_tb_exec (env, tb_ptr) \ - ((uintptr_t (*)(void *, void *))tcg_ctx->code_gen_prologue)(env, tb_ptr) +typedef uintptr_t tcg_prologue_fn (CPUArchState *env,void *tb_ptr); +extern tcg_prologue_fn *tcg_qemu_tb_exec;#endif void tcg_register_jit (void *buf,size_t buf_size);tcg/tcg.c +8
-1@@ -162,6 +162,10 @@ static TCGContext **tcg_ctxs;static unsigned int n_tcg_ctxs;TCGv_env cpu_env =0 ; +#ifndef CONFIG_TCG_INTERPRETER +tcg_prologue_fn *tcg_qemu_tb_exec; +#endif +struct tcg_region_tree {QemuMutex lock;GTree *tree;@@ -1055,7 +1059,10 @@ void tcg_prologue_init(TCGContext *s) s->code_ptr = buf0; s->code_buf = buf0; s->data_gen_ptr =NULL ; - s->code_gen_prologue = buf0; + +#ifndef CONFIG_TCG_INTERPRETER + tcg_qemu_tb_exec = (tcg_prologue_fn *)buf0; +#endif /* Compute a high-water mark, at which we voluntarily flush the buffer and start over. The size here is arbitrary, significantly larger tcg/tci.c +2
-1@@ -475,8 +475,9 @@ static bool tci_compare64(uint64_t u0, uint64_t u1, TCGCond condition)#endif /* Interpret pseudo code in tb. */ -uintptr_t tcg_qemu_tb_exec (CPUArchState *env,uint8_t *tb_ptr) +uintptr_t tcg_qemu_tb_exec (CPUArchState *env,void *v_tb_ptr) { +uint8_t *tb_ptr = v_tb_ptr;tcg_target_ulong regs[TCG_TARGET_NB_REGS ];long tcg_temps[CPU_TEMP_BUF_NLONGS ];uintptr_t sp_value = (uintptr_t )(tcg_temps +CPU_TEMP_BUF_NLONGS );
Re: [PATCH v4 05/43] tcg: Move tcg prologue pointer out of TCGContext
In reply to Richard HendersonQuoted 11 lines · Richard Henderson
This value is constant across all thread-local copies of TCGContext, so we might as well move it out of thread-local storage.
Use the correct function pointer type, and name the variable
tcg_qemu_tb_exec, which means that we are able to remove the macro that does the casting.Replace
HAVE_TCG_QEMU_TB_EXECwithCONFIG_TCG_INTERPRETER, as this is somewhat clearer in intent.
Quoted 7 lines
Reviewed-by Alex Bennée <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- include/tcg/tcg.h | 9 ++++----- tcg/tcg.c | 9 ++++++++- tcg/tci.c | 3 ++- 3 files changed, 14 insertions(+), 7 deletions(-)
PATCH v4 6/43 tcg: Move tcg epilogue pointer out of TCGContext
In reply to Richard HendersonThis value is constant across all thread-local copies of TCGContext, so we might as well move it out of thread-local storage.
--- include/tcg/tcg.h | 2 +- accel/tcg/tcg-runtime.c | 2 +- tcg/tcg.c | 3 ++- tcg/aarch64/tcg-target.c.inc | 4 ++-- tcg/arm/tcg-target.c.inc | 2 +- tcg/i386/tcg-target.c.inc | 4 ++-- tcg/mips/tcg-target.c.inc | 2 +- tcg/ppc/tcg-target.c.inc | 2 +- tcg/riscv/tcg-target.c.inc | 4 ++-- tcg/s390/tcg-target.c.inc | 4 ++-- tcg/sparc/tcg-target.c.inc | 2 +- 11 files changed, 16 insertions(+), 15 deletions(-)
include/tcg/tcg.h +1 -1
@@ -621,7 +621,6 @@ struct TCGContext {here, because there's too much arithmetic throughout that relies on addition and subtraction working on bytes. Rely on the GCC extension that allows arithmetic on void*. */ -void *code_gen_epilogue;void *code_gen_buffer;size_t code_gen_buffer_size;void *code_gen_ptr;
@@ -678,6 +677,7 @@ struct TCGContext {extern TCGContext tcg_init_ctx;extern __threadTCGContext *tcg_ctx; +extern void *tcg_code_gen_epilogue;extern TCGv_env cpu_env;static inline size_t temp_idx (TCGTemp *ts)
accel/tcg/tcg-runtime.c +1 -1
@@ -154,7 +154,7 @@ void *HELPER(lookup_tb_ptr)(CPUArchState *env) tb =tb_lookup__cpu_state (cpu, &pc, &cs_base, &flags,curr_cflags ());if (tb ==NULL ) { -return tcg_ctx->code_gen_epilogue; +return tcg_code_gen_epilogue; }qemu_log_mask_and_addr (CPU_LOG_EXEC , pc, "Chain %d: %p ["
tcg/tcg.c +2 -1
@@ -161,6 +161,7 @@ static int tcg_out_ldst_finalize(TCGContext *s);static TCGContext **tcg_ctxs;static unsigned int n_tcg_ctxs;TCGv_env cpu_env =0 ; +void *tcg_code_gen_epilogue;#ifndef CONFIG_TCG_INTERPRETER tcg_prologue_fn *tcg_qemu_tb_exec;
@@ -1133,7 +1134,7 @@ void tcg_prologue_init(TCGContext *s)/* Assert that goto_ptr is implemented completely. */ if (TCG_TARGET_HAS_goto_ptr) { -tcg_debug_assert (s->code_gen_epilogue !=NULL ); +tcg_debug_assert (tcg_code_gen_epilogue !=NULL ); } }
tcg/aarch64/tcg-target.c.inc +2 -2
@@ -1873,7 +1873,7 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, case INDEX_op_exit_tb: /* Reuse the zeroing that exists for goto_ptr. */ if (a0 == 0) { - tcg_out_goto_long(s, s->code_gen_epilogue); + tcg_out_goto_long(s, tcg_code_gen_epilogue); } else { tcg_out_movi(s, TCG_TYPE_I64, TCG_REG_X0, a0); tcg_out_goto_long(s, tb_ret_addr);
@@ -2894,7 +2894,7 @@ static void tcg_target_qemu_prologue(TCGContext *s) * Return path for goto_ptr. Set return value to 0, a-la exit_tb, * and fall through to the rest of the epilogue. */ - s->code_gen_epilogue = s->code_ptr; + tcg_code_gen_epilogue = s->code_ptr; tcg_out_movi(s, TCG_TYPE_REG, TCG_REG_X0, 0); /* TB epilogue */
tcg/arm/tcg-target.c.inc +1 -1
@@ -2297,7 +2297,7 @@ static void tcg_target_qemu_prologue(TCGContext *s) * Return path for goto_ptr. Set return value to 0, a-la exit_tb, * and fall through to the rest of the epilogue. */ - s->code_gen_epilogue = s->code_ptr; + tcg_code_gen_epilogue = s->code_ptr; tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R0, 0); tcg_out_epilogue(s); }
tcg/i386/tcg-target.c.inc +2 -2
@@ -2267,7 +2267,7 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, case INDEX_op_exit_tb: /* Reuse the zeroing that exists for goto_ptr. */ if (a0 == 0) { - tcg_out_jmp(s, s->code_gen_epilogue); + tcg_out_jmp(s, tcg_code_gen_epilogue); } else { tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_EAX, a0); tcg_out_jmp(s, tb_ret_addr);
@@ -3825,7 +3825,7 @@ static void tcg_target_qemu_prologue(TCGContext *s) * Return path for goto_ptr. Set return value to 0, a-la exit_tb, * and fall through to the rest of the epilogue. */ - s->code_gen_epilogue = s->code_ptr; + tcg_code_gen_epilogue = s->code_ptr; tcg_out_movi(s, TCG_TYPE_REG, TCG_REG_EAX, 0); /* TB epilogue */
tcg/mips/tcg-target.c.inc +1 -1
@@ -2483,7 +2483,7 @@ static void tcg_target_qemu_prologue(TCGContext *s) * Return path for goto_ptr. Set return value to 0, a-la exit_tb, * and fall through to the rest of the epilogue. */ - s->code_gen_epilogue = s->code_ptr; + tcg_code_gen_epilogue = s->code_ptr; tcg_out_mov(s, TCG_TYPE_REG, TCG_REG_V0, TCG_REG_ZERO); /* TB epilogue */
tcg/ppc/tcg-target.c.inc +1 -1
@@ -2341,7 +2341,7 @@ static void tcg_target_qemu_prologue(TCGContext *s) tcg_out32(s, BCCTR | BO_ALWAYS); /* Epilogue */ - s->code_gen_epilogue = tb_ret_addr = s->code_ptr; + tcg_code_gen_epilogue = tb_ret_addr = s->code_ptr; tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_R0, TCG_REG_R1, FRAME_SIZE+LR_OFFSET); for (i = 0; i < ARRAY_SIZE(tcg_target_callee_save_regs); ++i) {
tcg/riscv/tcg-target.c.inc +2 -2
@@ -1288,7 +1288,7 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, case INDEX_op_exit_tb: /* Reuse the zeroing that exists for goto_ptr. */ if (a0 == 0) { - tcg_out_call_int(s, s->code_gen_epilogue, true); + tcg_out_call_int(s, tcg_code_gen_epilogue, true); } else { tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_A0, a0); tcg_out_call_int(s, tb_ret_addr, true);
@@ -1822,7 +1822,7 @@ static void tcg_target_qemu_prologue(TCGContext *s) tcg_out_opc_imm(s, OPC_JALR, TCG_REG_ZERO, tcg_target_call_iarg_regs[1], 0); /* Return path for goto_ptr. Set return value to 0 */ - s->code_gen_epilogue = s->code_ptr; + tcg_code_gen_epilogue = s->code_ptr; tcg_out_mov(s, TCG_TYPE_REG, TCG_REG_A0, TCG_REG_ZERO); /* TB epilogue */
tcg/s390/tcg-target.c.inc +2 -2
@@ -1756,7 +1756,7 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, /* Reuse the zeroing that exists for goto_ptr. */ a0 = args[0]; if (a0 == 0) { - tgen_gotoi(s, S390_CC_ALWAYS, s->code_gen_epilogue); + tgen_gotoi(s, S390_CC_ALWAYS, tcg_code_gen_epilogue); } else { tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R2, a0); tgen_gotoi(s, S390_CC_ALWAYS, tb_ret_addr);
@@ -2561,7 +2561,7 @@ static void tcg_target_qemu_prologue(TCGContext *s) * Return path for goto_ptr. Set return value to 0, a-la exit_tb, * and fall through to the rest of the epilogue. */ - s->code_gen_epilogue = s->code_ptr; + tcg_code_gen_epilogue = s->code_ptr; tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R2, 0); /* TB epilogue */
tcg/sparc/tcg-target.c.inc +1 -1
@@ -1038,7 +1038,7 @@ static void tcg_target_qemu_prologue(TCGContext *s) tcg_out_nop(s); /* Epilogue for goto_ptr. */ - s->code_gen_epilogue = s->code_ptr; + tcg_code_gen_epilogue = s->code_ptr; tcg_out_arithi(s, TCG_REG_G0, TCG_REG_I7, 8, RETURN); /* delay slot */ tcg_out_movi_imm13(s, TCG_REG_O0, 0);
Signature · 1 line
2.25.1
Re: [PATCH v4 06/43] tcg: Move tcg epilogue pointer out of TCGContext
Quoted 5 lines · Richard Henderson
This value is constant across all thread-local copies of TCGContext, so we might as well move it out of thread-local storage.
Signed-off-by Richard Henderson <[email protected]>
Quoted 13 lines
--- include/tcg/tcg.h | 2 +- accel/tcg/tcg-runtime.c | 2 +- tcg/tcg.c | 3 ++- tcg/aarch64/tcg-target.c.inc | 4 ++-- tcg/arm/tcg-target.c.inc | 2 +- tcg/i386/tcg-target.c.inc | 4 ++-- tcg/mips/tcg-target.c.inc | 2 +- tcg/ppc/tcg-target.c.inc | 2 +- tcg/riscv/tcg-target.c.inc | 4 ++-- tcg/s390/tcg-target.c.inc | 4 ++-- tcg/sparc/tcg-target.c.inc | 2 +- 11 files changed, 16 insertions(+), 15 deletions(-)
PATCH v4 7/43 tcg: Add in_code_gen_buffer
In reply to Richard HendersonCreate a function to determine if a pointer is within the buffer.
--- include/tcg/tcg.h | 6 ++++++ accel/tcg/translate-all.c | 26 ++++++++------------------ 2 files changed, 14 insertions(+), 18 deletions(-)
include/tcg/tcg.h +6 -0
@@ -680,6 +680,12 @@ extern __thread TCGContext *tcg_ctx;extern void *tcg_code_gen_epilogue;extern TCGv_env cpu_env; +static inline bool in_code_gen_buffer (const void *p) +{ +const TCGContext *s = &tcg_init_ctx; +return (size_t )(p - s->code_gen_buffer) <= s->code_gen_buffer_size; +} +static inline size_t temp_idx (TCGTemp *ts) {ptrdiff_t n = ts - tcg_ctx->temps;
accel/tcg/translate-all.c +8 -18
@@ -392,27 +392,18 @@ void tb_destroy(TranslationBlock *tb)bool cpu_restore_state (CPUState *cpu,uintptr_t host_pc,bool will_exit) { -TranslationBlock *tb; -bool r = false; -uintptr_t check_offset; - -/* The host_pc has to be in the region of current code buffer. If -* it is not we will not be able to resolve it here. The two cases -* where host_pc will not be correct are: +/* +* The host_pc has to be in the region of the code buffer. +* If it is not we will not be able to resolve it here. +* The two cases where host_pc will not be correct are: * * - fault during translation (instruction fetch) * - fault from helper (not using GETPC() macro) * * Either way we need return early as we can't resolve it here. -* -* We are using unsigned arithmetic so if host_pc < -* tcg_init_ctx.code_gen_buffer check_offset will wrap to way -* above the code_gen_buffer_size */ - check_offset = host_pc - (uintptr_t ) tcg_init_ctx.code_gen_buffer; - -if (check_offset < tcg_init_ctx.code_gen_buffer_size) { - tb =tcg_tb_lookup (host_pc); +if (in_code_gen_buffer ((const void *)host_pc)) { +TranslationBlock *tb =tcg_tb_lookup (host_pc);if (tb) {cpu_restore_state_from_tb (cpu, tb, host_pc, will_exit);if (tb_cflags (tb) &CF_NOCACHE ) {
@@ -421,11 +412,10 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc, bool will_exit)tcg_tb_remove (tb);tb_destroy (tb); } - r = true; +return true; } } - -return r; +return false; }static void page_init (void )
Signature · 1 line
2.25.1
Re: [PATCH v4 07/43] tcg: Add in_code_gen_buffer
Quoted 13 lines · Richard Henderson
Create a function to determine if a pointer is within the buffer.
Signed-off-by Richard Henderson <[email protected]>--- include/tcg/tcg.h | 6 ++++++ accel/tcg/translate-all.c | 26 ++++++++------------------ 2 files changed, 14 insertions(+), 18 deletions(-)include/tcg/tcg.h +0
-0
include/tcg/tcg.h extern __thread TCGContext *tcg_ctx; · line 686
Quoted 7 lines
include/tcg/tcg.h +4
-0@@ -680,6 +680,12 @@ extern __thread TCGContext *tcg_ctx;extern void *tcg_code_gen_epilogue;extern TCGv_env cpu_env; +static inline bool in_code_gen_buffer (const void *p) +{ +const TCGContext *s = &tcg_init_ctx; +return (size_t )(p - s->code_gen_buffer) <= s->code_gen_buffer_size;
If 'p == s->code_gen_buffer + s->code_gen_buffer_size', is it really "in" the buffer?
Quoted 58 lines
include/tcg/tcg.h +2
-0+} +static inline size_t temp_idx (TCGTemp *ts) {ptrdiff_t n = ts - tcg_ctx->temps;accel/tcg/translate-all.c +8
-18@@ -392,27 +392,18 @@ void tb_destroy(TranslationBlock *tb)bool cpu_restore_state (CPUState *cpu,uintptr_t host_pc,bool will_exit) { -TranslationBlock *tb; -bool r = false; -uintptr_t check_offset; - -/* The host_pc has to be in the region of current code buffer. If -* it is not we will not be able to resolve it here. The two cases -* where host_pc will not be correct are: +/* +* The host_pc has to be in the region of the code buffer. +* If it is not we will not be able to resolve it here. +* The two cases where host_pc will not be correct are: * * - fault during translation (instruction fetch) * - fault from helper (not using GETPC() macro) * * Either way we need return early as we can't resolve it here. -* -* We are using unsigned arithmetic so if host_pc < -* tcg_init_ctx.code_gen_buffer check_offset will wrap to way -* above the code_gen_buffer_size */ - check_offset = host_pc - (uintptr_t ) tcg_init_ctx.code_gen_buffer; - -if (check_offset < tcg_init_ctx.code_gen_buffer_size) { - tb =tcg_tb_lookup (host_pc); +if (in_code_gen_buffer ((const void *)host_pc)) { +TranslationBlock *tb =tcg_tb_lookup (host_pc);if (tb) {cpu_restore_state_from_tb (cpu, tb, host_pc, will_exit);if (tb_cflags (tb) &CF_NOCACHE ) {@@ -421,11 +412,10 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc, bool will_exit)tcg_tb_remove (tb);tb_destroy (tb); } - r = true; +return true; } } - -return r; +return false; }static void page_init (void )
Re: [PATCH v4 07/43] tcg: Add in_code_gen_buffer
Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 16 lines · Richard Henderson
Create a function to determine if a pointer is within the buffer.
Signed-off-by Richard Henderson <[email protected]>--- include/tcg/tcg.h | 6 ++++++ accel/tcg/translate-all.c | 26 ++++++++------------------ 2 files changed, 14 insertions(+), 18 deletions(-)include/tcg/tcg.h +0
-0@@ -680,6 +680,12 @@ extern __thread TCGContext *tcg_ctx;extern void *tcg_code_gen_epilogue;extern TCGv_env cpu_env;
Quoted 7 lines
include/tcg/tcg.h extern __thread TCGContext *tcg_ctx; · line 686
Quoted 4 lines
include/tcg/tcg.h +4
-0+static inline bool in_code_gen_buffer (const void *p) +{ +const TCGContext *s = &tcg_init_ctx; +return (size_t )(p - s->code_gen_buffer) <= s->code_gen_buffer_size;If 'p ==
s->code_gen_buffer+s->code_gen_buffer_size', is it really "in" the buffer?
Well, sort of.
Compare the fact that in C, a pointer to the end of an array is valid as a pointer even though it can't be dereferenced. This is a pointer to the end of the buffer.
Extra commentary required?
r~
Philippe Mathieu-Daudé
Reviewed-byRe: [PATCH v4 07/43] tcg: Add in_code_gen_buffer
Quoted 26 lines · Richard Henderson
Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 16 lines · Richard Henderson
Create a function to determine if a pointer is within the buffer.
Signed-off-by Richard Henderson <[email protected]>--- include/tcg/tcg.h | 6 ++++++ accel/tcg/translate-all.c | 26 ++++++++------------------ 2 files changed, 14 insertions(+), 18 deletions(-)include/tcg/tcg.h +0
-0@@ -680,6 +680,12 @@ extern __thread TCGContext *tcg_ctx;extern void *tcg_code_gen_epilogue;extern TCGv_env cpu_env;Quoted 7 lines
include/tcg/tcg.h extern __thread TCGContext *tcg_ctx; · line 686
Quoted 4 lines
include/tcg/tcg.h +4
-0+static inline bool in_code_gen_buffer (const void *p) +{ +const TCGContext *s = &tcg_init_ctx; +return (size_t )(p - s->code_gen_buffer) <= s->code_gen_buffer_size;If 'p ==
s->code_gen_buffer+s->code_gen_buffer_size', is it really "in" the buffer?
Quoted 7 lines
Well, sort of.
Compare the fact that in C, a pointer to the end of an array is valid as a pointer even though it can't be dereferenced. This is a pointer to the end of the buffer.
Extra commentary required?
Preferably, since you change from '<' to '<=', this would make it clearer, then no question asked :)
With it:
Thanks,
Phil.
PATCH v4 8/43 tcg: Introduce tcg_splitwx_to_{rx,rw}
In reply to Richard HendersonAdd two helper functions, using a global variable to hold the displacement. The displacement is currently always 0, so no change in behaviour.
Begin using the functions in tcg common code only.
--- accel/tcg/tcg-runtime.h | 2 +- include/disas/disas.h | 2 +- include/exec/exec-all.h | 2 +- include/exec/log.h | 2 +- include/tcg/tcg.h | 26 ++++++++++++++---- accel/tcg/cpu-exec.c | 2 +- accel/tcg/tcg-runtime.c | 2 +- accel/tcg/translate-all.c | 33 +++++++++++------------ disas.c | 4 ++- tcg/tcg.c | 56 ++++++++++++++++++++++++++++++++++----- tcg/tci.c | 5 ++-- accel/tcg/trace-events | 2 +- tcg/tcg-pool.c.inc | 6 ++++- 13 files changed, 104 insertions(+), 40 deletions(-)
accel/tcg/tcg-runtime.h +1 -1
@@ -24,7 +24,7 @@ DEF_HELPER_FLAGS_1(clrsb_i64, TCG_CALL_NO_RWG_SE, i64, i64) DEF_HELPER_FLAGS_1(ctpop_i32, TCG_CALL_NO_RWG_SE, i32, i32) DEF_HELPER_FLAGS_1(ctpop_i64, TCG_CALL_NO_RWG_SE, i64, i64) -DEF_HELPER_FLAGS_1(lookup_tb_ptr, TCG_CALL_NO_WG_SE, ptr, env) +DEF_HELPER_FLAGS_1(lookup_tb_ptr, TCG_CALL_NO_WG_SE, cptr, env)DEF_HELPER_FLAGS_1 (exit_atomic,TCG_CALL_NO_WG , noreturn, env)
include/disas/disas.h +1 -1
@@ -7,7 +7,7 @@#include "cpu.h" /* Disassemble this for me please... (debugging). */ -void disas (FILE *out,void *code,unsigned long size); +void disas (FILE *out,const void *code,unsigned long size);void target_disas (FILE *out,CPUState *cpu,target_ulong code,target_ulong size);
include/exec/exec-all.h +1 -1
@@ -448,7 +448,7 @@ int probe_access_flags(CPUArchState *env, target_ulong addr,* Note: the address of search data can be obtained by adding @size to @ptr. */ struct tb_tc { -void *ptr;/* pointer to the translated code */ +const void *ptr;/* pointer to the translated code */ size_t size; };
include/exec/log.h +1 -1
@@ -56,7 +56,7 @@ static inline void log_target_disas(CPUState *cpu, target_ulong start,rcu_read_unlock (); } -static inline void log_disas (void *code,unsigned long size) +static inline void log_disas (const void *code,unsigned long size) {QemuLogFile *logfile;rcu_read_lock ();
include/tcg/tcg.h +21 -5
@@ -678,6 +678,7 @@ struct TCGContext {extern TCGContext tcg_init_ctx;extern __threadTCGContext *tcg_ctx;extern void *tcg_code_gen_epilogue; +extern uintptr_t tcg_splitwx_diff;extern TCGv_env cpu_env;static inline bool in_code_gen_buffer (const void *p)
@@ -686,6 +687,21 @@ static inline bool in_code_gen_buffer(const void *p)return (size_t )(p - s->code_gen_buffer) <= s->code_gen_buffer_size; } +#ifdef CONFIG_DEBUG_TCG +const void *tcg_splitwx_to_rx (void *rw); +void *tcg_splitwx_to_rw (const void *rx); +#else +static inline const void *tcg_splitwx_to_rx (void *rw) +{ +return rw ? rw + tcg_splitwx_diff :NULL ; +} + +static inline void *tcg_splitwx_to_rw (const void *rx) +{ +return rx ? (void *)rx - tcg_splitwx_diff :NULL ; +} +#endif +static inline size_t temp_idx (TCGTemp *ts) {ptrdiff_t n = ts - tcg_ctx->temps;
@@ -1106,7 +1122,7 @@ static inline TCGLabel *arg_label(TCGArg i)* correct result. */ -static inline ptrdiff_t tcg_ptr_byte_diff (void *a,void *b) +static inline ptrdiff_t tcg_ptr_byte_diff (const void *a,const void *b) {return a - b; }
@@ -1120,9 +1136,9 @@ static inline ptrdiff_t tcg_ptr_byte_diff(void *a, void *b)* to the destination address. */ -static inline ptrdiff_t tcg_pcrel_diff (TCGContext *s,void *target) +static inline ptrdiff_t tcg_pcrel_diff (TCGContext *s,const void *target) { -return tcg_ptr_byte_diff (target, s->code_ptr); +return tcg_ptr_byte_diff (target,tcg_splitwx_to_rx (s->code_ptr)); }/**
@@ -1228,9 +1244,9 @@ static inline unsigned get_mmuidx(TCGMemOpIdx oi)#define TB_EXIT_REQUESTED 3#ifdef CONFIG_TCG_INTERPRETER -uintptr_t tcg_qemu_tb_exec (CPUArchState *env,void *tb_ptr); +uintptr_t tcg_qemu_tb_exec (CPUArchState *env,const void *tb_ptr);#else -typedef uintptr_t tcg_prologue_fn (CPUArchState *env,void *tb_ptr); +typedef uintptr_t tcg_prologue_fn (CPUArchState *env,const void *tb_ptr);extern tcg_prologue_fn *tcg_qemu_tb_exec;#endif
accel/tcg/cpu-exec.c +1 -1
@@ -150,7 +150,7 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb)uintptr_t ret;TranslationBlock *last_tb;int tb_exit; -uint8_t *tb_ptr = itb->tc.ptr; +const void *tb_ptr = itb->tc.ptr;qemu_log_mask_and_addr (CPU_LOG_EXEC , itb->pc, "Trace %d: %p ["
accel/tcg/tcg-runtime.c +1 -1
@@ -145,7 +145,7 @@ uint64_t HELPER(ctpop_i64)(uint64_t arg)return ctpop64 (arg); } -void *HELPER (lookup_tb_ptr )(CPUArchState *env) +const void *HELPER (lookup_tb_ptr )(CPUArchState *env) {CPUState *cpu =env_cpu (env);TranslationBlock *tb;
accel/tcg/translate-all.c +15 -18
@@ -269,9 +269,9 @@ static uint8_t *encode_sleb128(uint8_t *p, target_long val)/* Decode a signed leb128 sequence at *PP; increment *PP past the decoded value. Return the decoded value. */ -static target_long decode_sleb128 (uint8_t **pp) +static target_long decode_sleb128 (const uint8_t **pp) { -uint8_t *p = *pp; +const uint8_t *p = *pp;target_long val =0 ;int byte, shift =0 ;
@@ -342,7 +342,7 @@ static int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb,target_ulong data[TARGET_INSN_START_WORDS ] = { tb->pc };uintptr_t host_pc = (uintptr_t )tb->tc.ptr;CPUArchState *env = cpu->env_ptr; -uint8_t *p = tb->tc.ptr + tb->tc.size; +const uint8_t *p = tb->tc.ptr + tb->tc.size;int i, j, num_insns = tb->icount;#ifdef CONFIG_PROFILER TCGProfile *prof = &tcg_ctx->prof;
@@ -393,7 +393,7 @@ void tb_destroy(TranslationBlock *tb)bool cpu_restore_state (CPUState *cpu,uintptr_t host_pc,bool will_exit) {/* -* The host_pc has to be in the region of the code buffer. +* The host_pc has to be in the rx region of the code buffer. * If it is not we will not be able to resolve it here. * The two cases where host_pc will not be correct are: *
@@ -402,7 +402,7 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc, bool will_exit)* * Either way we need return early as we can't resolve it here. */ -if (in_code_gen_buffer ((const void *)host_pc)) { +if (in_code_gen_buffer ((const void *)(host_pc - tcg_splitwx_diff))) {TranslationBlock *tb =tcg_tb_lookup (host_pc);if (tb) {cpu_restore_state_from_tb (cpu, tb, host_pc, will_exit);
@@ -1712,7 +1712,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, } gen_code_buf = tcg_ctx->code_gen_ptr; - tb->tc.ptr = gen_code_buf; + tb->tc.ptr =tcg_splitwx_to_rx (gen_code_buf); tb->pc = pc; tb->cs_base = cs_base; tb->flags = flags;
@@ -1806,15 +1806,19 @@ TranslationBlock *tb_gen_code(CPUState *cpu,if (qemu_loglevel_mask (CPU_LOG_TB_OUT_ASM ) &&qemu_log_in_addr_range (tb->pc)) {FILE *logfile =qemu_log_lock (); -int code_size, data_size =0 ; +int code_size, data_size; +const tcg_target_ulong *rx_data_gen_ptr;size_t chunk_start;int insn =0 ;if (tcg_ctx->data_gen_ptr) { - code_size = tcg_ctx->data_gen_ptr - tb->tc.ptr; + rx_data_gen_ptr =tcg_splitwx_to_rx (tcg_ctx->data_gen_ptr); + code_size = (const void *)rx_data_gen_ptr - tb->tc.ptr; data_size = gen_code_size - code_size; }else { + rx_data_gen_ptr =0 ; code_size = gen_code_size; + data_size =0 ; }/* Dump header and the first instruction */
@@ -1849,16 +1853,9 @@ TranslationBlock *tb_gen_code(CPUState *cpu,if (data_size) {int i;qemu_log (" data: [size=%d]\n" , data_size); -for (i =0 ; i < data_size; i +=sizeof (tcg_target_ulong)) { -if (sizeof (tcg_target_ulong) ==8 ) { -qemu_log ("0x%08" PRIxPTR": .quad 0x%016" PRIx64"\n" , - (uintptr_t )tcg_ctx->data_gen_ptr + i, - *(uint64_t *)(tcg_ctx->data_gen_ptr + i)); - }else { -qemu_log ("0x%08" PRIxPTR": .long 0x%08x\n" , - (uintptr_t )tcg_ctx->data_gen_ptr + i, - *(uint32_t *)(tcg_ctx->data_gen_ptr + i)); - } +for (i =0 ; i < data_size /sizeof (tcg_target_ulong); i++) { +qemu_log ("0x%08" PRIxPTR": .quad 0x%" TCG_PRIlx"\n" , + (uintptr_t )&rx_data_gen_ptr[i], rx_data_gen_ptr[i]); } }qemu_log ("\n" );
disas.c +3 -1
@@ -299,8 +299,10 @@ char *plugin_disas(CPUState *cpu, uint64_t addr, size_t size) }/* Disassemble this for me please... (debugging). */ -void disas (FILE *out,void *code,unsigned long size) +void disas (FILE *out,const void *ccode,unsigned long size) { +/* TODO: Push constness through the disas backends. */ +void *code = (void *)ccode;uintptr_t pc;int count;CPUDebug s;
tcg/tcg.c +50 -6
118 lines not on this page · raw message
tcg/tci.c +3 -2
@@ -475,9 +475,10 @@ static bool tci_compare64(uint64_t u0, uint64_t u1, TCGCond condition)#endif /* Interpret pseudo code in tb. */ -uintptr_t tcg_qemu_tb_exec (CPUArchState *env,void *v_tb_ptr) +uintptr_t tcg_qemu_tb_exec (CPUArchState *env,const void *v_tb_ptr) { -uint8_t *tb_ptr = v_tb_ptr; +/* TODO: Propagate const through this file. */ +uint8_t *tb_ptr = (uint8_t *)v_tb_ptr;tcg_target_ulong regs[TCG_TARGET_NB_REGS ];long tcg_temps[CPU_TEMP_BUF_NLONGS ];uintptr_t sp_value = (uintptr_t )(tcg_temps +CPU_TEMP_BUF_NLONGS );
accel/tcg/trace-events +1 -1
@@ -7,4 +7,4 @@ exec_tb_nocache(void *tb, uintptr_t pc) "tb:%p pc=0x%"PRIxPTR exec_tb_exit(void *last_tb, unsigned int flags) "tb:%p flags=0x%x" # translate-all.c -translate_block(void *tb, uintptr_t pc, uint8_t *tb_code) "tb:%p, pc:0x%"PRIxPTR", tb_code:%p" +translate_block(void *tb, uintptr_t pc, const void *tb_code) "tb:%p, pc:0x%"PRIxPTR", tb_code:%p"
tcg/tcg-pool.c.inc +5 -1
@@ -140,6 +140,8 @@ static int tcg_out_pool_finalize(TCGContext *s) for (; p != NULL; p = p->next) { size_t size = sizeof(tcg_target_ulong) * p->nlong; + uintptr_t value; + if (!l || l->nlong != p->nlong || memcmp(l->data, p->data, size)) { if (unlikely(a > s->code_gen_highwater)) { return -1;
@@ -148,7 +150,9 @@ static int tcg_out_pool_finalize(TCGContext *s) a += size; l = p; } - if (!patch_reloc(p->label, p->rtype, (intptr_t)a - size, p->addend)) { + + value = (uintptr_t)tcg_splitwx_to_rx(a) - size; + if (!patch_reloc(p->label, p->rtype, value, p->addend)) { return -2; } }
Signature · 1 line
2.25.1
Re: [PATCH v4 08/43] tcg: Introduce tcg_splitwx_to_{rx,rw}
Quoted 8 lines · Richard Henderson
Add two helper functions, using a global variable to hold the displacement. The displacement is currently always 0, so no change in behaviour.
Begin using the functions in tcg common code only.
Signed-off-by Richard Henderson <[email protected]>
Quoted 15 lines
--- accel/tcg/tcg-runtime.h | 2 +- include/disas/disas.h | 2 +- include/exec/exec-all.h | 2 +- include/exec/log.h | 2 +- include/tcg/tcg.h | 26 ++++++++++++++---- accel/tcg/cpu-exec.c | 2 +- accel/tcg/tcg-runtime.c | 2 +- accel/tcg/translate-all.c | 33 +++++++++++------------ disas.c | 4 ++- tcg/tcg.c | 56 ++++++++++++++++++++++++++++++++++----- tcg/tci.c | 5 ++-- accel/tcg/trace-events | 2 +- tcg/tcg-pool.c.inc | 6 ++++- 13 files changed, 104 insertions(+), 40 deletions(-)
PATCH v4 9/43 tcg: Adjust TCGLabel for const
In reply to Richard HendersonChange TCGLabel.u.value_ptr to const, and initialize it with tcg_splitwx_to_rx. Propagate const through tcg/host/ only as far as needed to avoid errors from the value_ptr change.
--- include/tcg/tcg.h | 2 +- tcg/tcg.c | 2 +- tcg/aarch64/tcg-target.c.inc | 2 +- tcg/arm/tcg-target.c.inc | 2 +- tcg/mips/tcg-target.c.inc | 5 +++-- tcg/ppc/tcg-target.c.inc | 4 ++-- tcg/s390/tcg-target.c.inc | 2 +- 7 files changed, 10 insertions(+), 9 deletions(-)
include/tcg/tcg.h +1 -1
@@ -261,7 +261,7 @@ struct TCGLabel { unsigned refs : 16;union {uintptr_t value; -tcg_insn_unit *value_ptr; +const tcg_insn_unit *value_ptr; } u; QSIMPLEQ_HEAD(, TCGRelocation) relocs;QSIMPLEQ_ENTRY (TCGLabel) next;
tcg/tcg.c +1 -1
@@ -306,7 +306,7 @@ static void tcg_out_label(TCGContext *s, TCGLabel *l, tcg_insn_unit *ptr) {tcg_debug_assert (!l->has_value); l->has_value =1 ; - l->u.value_ptr = ptr; + l->u.value_ptr =tcg_splitwx_to_rx (ptr); }TCGLabel *gen_new_label (void )
tcg/aarch64/tcg-target.c.inc +1 -1
@@ -1306,7 +1306,7 @@ static void tcg_out_cmp(TCGContext *s, TCGType ext, TCGReg a, } } -static inline void tcg_out_goto(TCGContext *s, tcg_insn_unit *target) +static void tcg_out_goto(TCGContext *s, const tcg_insn_unit *target) { ptrdiff_t offset = target - s->code_ptr; tcg_debug_assert(offset == sextract64(offset, 0, 26));
tcg/arm/tcg-target.c.inc +1 -1
@@ -1019,7 +1019,7 @@ static inline void tcg_out_st8(TCGContext *s, int cond, * with the code buffer limited to 16MB we wouldn't need the long case. * But we also use it for the tail-call to the qemu_ld/st helpers, which does. */ -static void tcg_out_goto(TCGContext *s, int cond, tcg_insn_unit *addr) +static void tcg_out_goto(TCGContext *s, int cond, const tcg_insn_unit *addr) { intptr_t addri = (intptr_t)addr; ptrdiff_t disp = tcg_pcrel_diff(s, addr);
tcg/mips/tcg-target.c.inc +3 -2
@@ -144,7 +144,8 @@ static tcg_insn_unit *bswap32_addr; static tcg_insn_unit *bswap32u_addr; static tcg_insn_unit *bswap64_addr; -static inline uint32_t reloc_pc16_val(tcg_insn_unit *pc, tcg_insn_unit *target) +static inline uint32_t reloc_pc16_val(tcg_insn_unit *pc, + const tcg_insn_unit *target) { /* Let the compiler perform the right-shift as part of the arithmetic. */ ptrdiff_t disp = target - (pc + 1);
@@ -152,7 +153,7 @@ static inline uint32_t reloc_pc16_val(tcg_insn_unit *pc, tcg_insn_unit *target) return disp & 0xffff; } -static inline void reloc_pc16(tcg_insn_unit *pc, tcg_insn_unit *target) +static inline void reloc_pc16(tcg_insn_unit *pc, const tcg_insn_unit *target) { *pc = deposit32(*pc, 0, 16, reloc_pc16_val(pc, target)); }
tcg/ppc/tcg-target.c.inc +2 -2
@@ -184,7 +184,7 @@ static inline bool in_range_b(tcg_target_long target) return target == sextract64(target, 0, 26); } -static uint32_t reloc_pc24_val(tcg_insn_unit *pc, tcg_insn_unit *target) +static uint32_t reloc_pc24_val(tcg_insn_unit *pc, const tcg_insn_unit *target) { ptrdiff_t disp = tcg_ptr_byte_diff(target, pc); tcg_debug_assert(in_range_b(disp));
@@ -201,7 +201,7 @@ static bool reloc_pc24(tcg_insn_unit *pc, tcg_insn_unit *target) return false; } -static uint16_t reloc_pc14_val(tcg_insn_unit *pc, tcg_insn_unit *target) +static uint16_t reloc_pc14_val(tcg_insn_unit *pc, const tcg_insn_unit *target) { ptrdiff_t disp = tcg_ptr_byte_diff(target, pc); tcg_debug_assert(disp == (int16_t) disp);
tcg/s390/tcg-target.c.inc +1 -1
@@ -1302,7 +1302,7 @@ static void tgen_extract(TCGContext *s, TCGReg dest, TCGReg src, tcg_out_risbg(s, dest, src, 64 - len, 63, 64 - ofs, 1); } -static void tgen_gotoi(TCGContext *s, int cc, tcg_insn_unit *dest) +static void tgen_gotoi(TCGContext *s, int cc, const tcg_insn_unit *dest) { ptrdiff_t off = dest - s->code_ptr; if (off == (int16_t)off) {
Signature · 1 line
2.25.1
Re: [PATCH v4 09/43] tcg: Adjust TCGLabel for const
Quoted 6 lines · Richard Henderson
Change TCGLabel.u.value_ptr to const, and initialize it with
tcg_splitwx_to_rx. Propagate const through tcg/host/ only as far as needed to avoid errors from thevalue_ptrchange.Signed-off-by Richard Henderson <[email protected]>
Quoted 9 lines
--- include/tcg/tcg.h | 2 +- tcg/tcg.c | 2 +- tcg/aarch64/tcg-target.c.inc | 2 +- tcg/arm/tcg-target.c.inc | 2 +- tcg/mips/tcg-target.c.inc | 5 +++-- tcg/ppc/tcg-target.c.inc | 4 ++-- tcg/s390/tcg-target.c.inc | 2 +- 7 files changed, 10 insertions(+), 9 deletions(-)
PATCH v4 10/43 tcg: Adjust tcg_out_call for const
In reply to Richard HendersonWe must change all targets at once, since all must match the declaration in tcg.c.
--- tcg/tcg.c | 2 +- tcg/aarch64/tcg-target.c.inc | 2 +- tcg/arm/tcg-target.c.inc | 2 +- tcg/i386/tcg-target.c.inc | 4 ++-- tcg/mips/tcg-target.c.inc | 6 +++--- tcg/ppc/tcg-target.c.inc | 8 ++++---- tcg/riscv/tcg-target.c.inc | 6 +++--- tcg/s390/tcg-target.c.inc | 2 +- tcg/sparc/tcg-target.c.inc | 4 ++-- tcg/tci/tcg-target.c.inc | 2 +- 10 files changed, 19 insertions(+), 19 deletions(-)
tcg/tcg.c +1 -1
@@ -149,7 +149,7 @@ static void tcg_out_st(TCGContext *s, TCGType type, TCGReg arg, TCGReg arg1, intptr_t arg2);static bool tcg_out_sti (TCGContext *s,TCGType type,TCGArg val,TCGReg base,intptr_t ofs); -static void tcg_out_call (TCGContext *s,tcg_insn_unit *target); +static void tcg_out_call (TCGContext *s,const tcg_insn_unit *target);static int tcg_target_const_match (tcg_target_long val,TCGType type,const TCGArgConstraint *arg_ct);#ifdef TCG_TARGET_NEED_LDST_LABELS
tcg/aarch64/tcg-target.c.inc +1 -1
@@ -1329,7 +1329,7 @@ static inline void tcg_out_callr(TCGContext *s, TCGReg reg) tcg_out_insn(s, 3207, BLR, reg); } -static inline void tcg_out_call(TCGContext *s, tcg_insn_unit *target) +static inline void tcg_out_call(TCGContext *s, const tcg_insn_unit *target) { ptrdiff_t offset = target - s->code_ptr; if (offset == sextract64(offset, 0, 26)) {
tcg/arm/tcg-target.c.inc +1 -1
@@ -1033,7 +1033,7 @@ static void tcg_out_goto(TCGContext *s, int cond, const tcg_insn_unit *addr) /* The call case is mostly used for helpers - so it's not unreasonable * for them to be beyond branch range */ -static void tcg_out_call(TCGContext *s, tcg_insn_unit *addr) +static void tcg_out_call(TCGContext *s, const tcg_insn_unit *addr) { intptr_t addri = (intptr_t)addr; ptrdiff_t disp = tcg_pcrel_diff(s, addr);
tcg/i386/tcg-target.c.inc +2 -2
@@ -1591,7 +1591,7 @@ static void tcg_out_clz(TCGContext *s, int rexw, TCGReg dest, TCGReg arg1, } } -static void tcg_out_branch(TCGContext *s, int call, tcg_insn_unit *dest) +static void tcg_out_branch(TCGContext *s, int call, const tcg_insn_unit *dest) { intptr_t disp = tcg_pcrel_diff(s, dest) - 5;
@@ -1610,7 +1610,7 @@ static void tcg_out_branch(TCGContext *s, int call, tcg_insn_unit *dest) } } -static inline void tcg_out_call(TCGContext *s, tcg_insn_unit *dest) +static inline void tcg_out_call(TCGContext *s, const tcg_insn_unit *dest) { tcg_out_branch(s, 1, dest); }
tcg/mips/tcg-target.c.inc +3 -3
@@ -517,7 +517,7 @@ static void tcg_out_opc_sa64(TCGContext *s, MIPSInsn opc1, MIPSInsn opc2, * Type jump. * Returns true if the branch was in range and the insn was emitted. */ -static bool tcg_out_opc_jmp(TCGContext *s, MIPSInsn opc, void *target) +static bool tcg_out_opc_jmp(TCGContext *s, MIPSInsn opc, const void *target) { uintptr_t dest = (uintptr_t)target; uintptr_t from = (uintptr_t)s->code_ptr + 4;
@@ -1080,7 +1080,7 @@ static void tcg_out_movcond(TCGContext *s, TCGCond cond, TCGReg ret, } } -static void tcg_out_call_int(TCGContext *s, tcg_insn_unit *arg, bool tail) +static void tcg_out_call_int(TCGContext *s, const tcg_insn_unit *arg, bool tail) { /* Note that the ABI requires the called function's address to be loaded into T9, even if a direct branch is in range. */
@@ -1098,7 +1098,7 @@ static void tcg_out_call_int(TCGContext *s, tcg_insn_unit *arg, bool tail) } } -static void tcg_out_call(TCGContext *s, tcg_insn_unit *arg) +static void tcg_out_call(TCGContext *s, const tcg_insn_unit *arg) { tcg_out_call_int(s, arg, false); tcg_out_nop(s);
tcg/ppc/tcg-target.c.inc +4 -4
@@ -1106,7 +1106,7 @@ static void tcg_out_xori32(TCGContext *s, TCGReg dst, TCGReg src, uint32_t c) tcg_out_zori32(s, dst, src, c, XORI, XORIS); } -static void tcg_out_b(TCGContext *s, int mask, tcg_insn_unit *target) +static void tcg_out_b(TCGContext *s, int mask, const tcg_insn_unit *target) { ptrdiff_t disp = tcg_pcrel_diff(s, target); if (in_range_b(disp)) {
@@ -1762,13 +1762,13 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, } } -static void tcg_out_call(TCGContext *s, tcg_insn_unit *target) +static void tcg_out_call(TCGContext *s, const tcg_insn_unit *target) { #ifdef _CALL_AIX /* Look through the descriptor. If the branch is in range, and we don't have to spend too much effort on building the toc. */ - void *tgt = ((void **)target)[0]; - uintptr_t toc = ((uintptr_t *)target)[1]; + const void *tgt = ((const void * const *)target)[0]; + uintptr_t toc = ((const uintptr_t *)target)[1]; intptr_t diff = tcg_pcrel_diff(s, tgt); if (in_range_b(diff) && toc == (uint32_t)toc) {
tcg/riscv/tcg-target.c.inc +3 -3
@@ -449,7 +449,7 @@ static bool reloc_jimm20(tcg_insn_unit *code_ptr, tcg_insn_unit *target) return false; } -static bool reloc_call(tcg_insn_unit *code_ptr, tcg_insn_unit *target) +static bool reloc_call(tcg_insn_unit *code_ptr, const tcg_insn_unit *target) { intptr_t offset = (intptr_t)target - (intptr_t)code_ptr; int32_t lo = sextreg(offset, 0, 12);
@@ -861,7 +861,7 @@ static inline void tcg_out_goto(TCGContext *s, tcg_insn_unit *target) tcg_out_opc_jump(s, OPC_JAL, TCG_REG_ZERO, offset); } -static void tcg_out_call_int(TCGContext *s, tcg_insn_unit *arg, bool tail) +static void tcg_out_call_int(TCGContext *s, const tcg_insn_unit *arg, bool tail) { TCGReg link = tail ? TCG_REG_ZERO : TCG_REG_RA; ptrdiff_t offset = tcg_pcrel_diff(s, arg);
@@ -888,7 +888,7 @@ static void tcg_out_call_int(TCGContext *s, tcg_insn_unit *arg, bool tail) } } -static void tcg_out_call(TCGContext *s, tcg_insn_unit *arg) +static void tcg_out_call(TCGContext *s, const tcg_insn_unit *arg) { tcg_out_call_int(s, arg, false); }
tcg/s390/tcg-target.c.inc +1 -1
@@ -1415,7 +1415,7 @@ static void tgen_brcond(TCGContext *s, TCGType type, TCGCond c, tgen_branch(s, cc, l); } -static void tcg_out_call(TCGContext *s, tcg_insn_unit *dest) +static void tcg_out_call(TCGContext *s, const tcg_insn_unit *dest) { ptrdiff_t off = dest - s->code_ptr; if (off == (int32_t)off) {
tcg/sparc/tcg-target.c.inc +2 -2
@@ -840,7 +840,7 @@ static void tcg_out_addsub2_i64(TCGContext *s, TCGReg rl, TCGReg rh, tcg_out_mov(s, TCG_TYPE_I64, rl, tmp); } -static void tcg_out_call_nodelay(TCGContext *s, tcg_insn_unit *dest, +static void tcg_out_call_nodelay(TCGContext *s, const tcg_insn_unit *dest, bool in_prologue) { ptrdiff_t disp = tcg_pcrel_diff(s, dest);
@@ -855,7 +855,7 @@ static void tcg_out_call_nodelay(TCGContext *s, tcg_insn_unit *dest, } } -static void tcg_out_call(TCGContext *s, tcg_insn_unit *dest) +static void tcg_out_call(TCGContext *s, const tcg_insn_unit *dest) { tcg_out_call_nodelay(s, dest, false); tcg_out_nop(s);
tcg/tci/tcg-target.c.inc +1 -1
@@ -545,7 +545,7 @@ static void tcg_out_movi(TCGContext *s, TCGType type, old_code_ptr[1] = s->code_ptr - old_code_ptr; } -static inline void tcg_out_call(TCGContext *s, tcg_insn_unit *arg) +static inline void tcg_out_call(TCGContext *s, const tcg_insn_unit *arg) { uint8_t *old_code_ptr = s->code_ptr; tcg_out_op_t(s, INDEX_op_call);
Signature · 1 line
2.25.1
Re: [PATCH v4 10/43] tcg: Adjust tcg_out_call for const
Quoted 4 lines · Richard Henderson
We must change all targets at once, since all must match the declaration in
tcg.c.Signed-off-by Richard Henderson <[email protected]>
Quoted 12 lines
--- tcg/tcg.c | 2 +- tcg/aarch64/tcg-target.c.inc | 2 +- tcg/arm/tcg-target.c.inc | 2 +- tcg/i386/tcg-target.c.inc | 4 ++-- tcg/mips/tcg-target.c.inc | 6 +++--- tcg/ppc/tcg-target.c.inc | 8 ++++---- tcg/riscv/tcg-target.c.inc | 6 +++--- tcg/s390/tcg-target.c.inc | 2 +- tcg/sparc/tcg-target.c.inc | 4 ++-- tcg/tci/tcg-target.c.inc | 2 +- 10 files changed, 19 insertions(+), 19 deletions(-)
Re: [PATCH v4 10/43] tcg: Adjust tcg_out_call for const
In reply to Richard HendersonQuoted 5 lines · Richard Henderson
We must change all targets at once, since all must match the declaration in
tcg.c.Signed-off-by Richard Henderson <[email protected]>
Quoted 12 lines
--- tcg/tcg.c | 2 +- tcg/aarch64/tcg-target.c.inc | 2 +- tcg/arm/tcg-target.c.inc | 2 +- tcg/i386/tcg-target.c.inc | 4 ++-- tcg/mips/tcg-target.c.inc | 6 +++--- tcg/ppc/tcg-target.c.inc | 8 ++++---- tcg/riscv/tcg-target.c.inc | 6 +++--- tcg/s390/tcg-target.c.inc | 2 +- tcg/sparc/tcg-target.c.inc | 4 ++-- tcg/tci/tcg-target.c.inc | 2 +- 10 files changed, 19 insertions(+), 19 deletions(-)
PATCH v4 11/43 tcg: Adjust tcg_out_label for const
In reply to Richard HendersonSimplify the arguments to always use s->code_ptr instead of take it as an argument. That makes it easy to ensure that the value_ptr is always the rx version.
--- tcg/tcg.c | 6 +++--- tcg/i386/tcg-target.c.inc | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-)
tcg/tcg.c +3 -3
@@ -302,11 +302,11 @@ static void tcg_out_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,QSIMPLEQ_INSERT_TAIL (&l->relocs, r, next); } -static void tcg_out_label (TCGContext *s,TCGLabel *l,tcg_insn_unit *ptr) +static void tcg_out_label (TCGContext *s,TCGLabel *l) {tcg_debug_assert (!l->has_value); l->has_value =1 ; - l->u.value_ptr =tcg_splitwx_to_rx (ptr); + l->u.value_ptr =tcg_splitwx_to_rx (s->code_ptr); }TCGLabel *gen_new_label (void )
@@ -4325,7 +4325,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)break ;case INDEX_op_set_label:tcg_reg_alloc_bb_end (s, s->reserved_regs); -tcg_out_label (s,arg_label (op->args[0 ]), s->code_ptr); +tcg_out_label (s,arg_label (op->args[0 ]));break ;case INDEX_op_call:tcg_reg_alloc_call (s, op);
tcg/i386/tcg-target.c.inc +5 -5
@@ -1452,7 +1452,7 @@ static void tcg_out_brcond2(TCGContext *s, const TCGArg *args, default: tcg_abort(); } - tcg_out_label(s, label_next, s->code_ptr); + tcg_out_label(s, label_next); } #endif
@@ -1494,10 +1494,10 @@ static void tcg_out_setcond2(TCGContext *s, const TCGArg *args, tcg_out_movi(s, TCG_TYPE_I32, args[0], 0); tcg_out_jxx(s, JCC_JMP, label_over, 1); - tcg_out_label(s, label_true, s->code_ptr); + tcg_out_label(s, label_true); tcg_out_movi(s, TCG_TYPE_I32, args[0], 1); - tcg_out_label(s, label_over, s->code_ptr); + tcg_out_label(s, label_over); } else { /* When the destination does not overlap one of the arguments, clear the destination first, jump if cond false, and emit an
@@ -1511,7 +1511,7 @@ static void tcg_out_setcond2(TCGContext *s, const TCGArg *args, tcg_out_brcond2(s, new_args, const_args+1, 1); tgen_arithi(s, ARITH_ADD, args[0], 1, 0); - tcg_out_label(s, label_over, s->code_ptr); + tcg_out_label(s, label_over); } } #endif
@@ -1525,7 +1525,7 @@ static void tcg_out_cmov(TCGContext *s, TCGCond cond, int rexw, TCGLabel *over = gen_new_label(); tcg_out_jxx(s, tcg_cond_to_jcc[tcg_invert_cond(cond)], over, 1); tcg_out_mov(s, TCG_TYPE_I32, dest, v1); - tcg_out_label(s, over, s->code_ptr); + tcg_out_label(s, over); } }
Signature · 1 line
2.25.1
Re: [PATCH v4 11/43] tcg: Adjust tcg_out_label for const
Quoted 9 lines · Richard Henderson
Simplify the arguments to always use
s->code_ptrinstead of take it as an argument. That makes it easy to ensure that thevalue_ptris always the rx version.Signed-off-by Richard Henderson <[email protected]>--- tcg/tcg.c | 6 +++--- tcg/i386/tcg-target.c.inc | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-)
Re: [PATCH v4 11/43] tcg: Adjust tcg_out_label for const
In reply to Richard HendersonQuoted 10 lines · Richard Henderson
Simplify the arguments to always use
s->code_ptrinstead of take it as an argument. That makes it easy to ensure that thevalue_ptris always the rx version.Signed-off-by Richard Henderson <[email protected]>--- tcg/tcg.c | 6 +++--- tcg/i386/tcg-target.c.inc | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-)
PATCH v4 12/43 tcg: Adjust tcg_register_jit for const
In reply to Richard HendersonWe must change all targets at once, since all must match the declaration in tcg.c.
--- include/tcg/tcg.h | 2 +- tcg/tcg.c | 10 +++++----- tcg/aarch64/tcg-target.c.inc | 2 +- tcg/arm/tcg-target.c.inc | 2 +- tcg/i386/tcg-target.c.inc | 2 +- tcg/mips/tcg-target.c.inc | 2 +- tcg/ppc/tcg-target.c.inc | 2 +- tcg/riscv/tcg-target.c.inc | 2 +- tcg/s390/tcg-target.c.inc | 2 +- tcg/sparc/tcg-target.c.inc | 2 +- 10 files changed, 14 insertions(+), 14 deletions(-)
include/tcg/tcg.h +1 -1
@@ -1250,7 +1250,7 @@ typedef uintptr_t tcg_prologue_fn(CPUArchState *env, const void *tb_ptr);extern tcg_prologue_fn *tcg_qemu_tb_exec;#endif -void tcg_register_jit (void *buf,size_t buf_size); +void tcg_register_jit (const void *buf,size_t buf_size);#if TCG_TARGET_MAYBE_vec/* Return zero if the tuple (opc, type, vece) is unsupportable;
tcg/tcg.c +5 -5
@@ -97,7 +97,7 @@ typedef struct QEMU_PACKED {DebugFrameFDEHeader fde; } DebugFrameHeader; -static void tcg_register_jit_int (void *buf,size_t size, +static void tcg_register_jit_int (const void *buf,size_t size,const void *debug_frame,size_t debug_frame_size) __attribute__((unused));
@@ -1137,7 +1137,7 @@ void tcg_prologue_init(TCGContext *s) total_size -= prologue_size; s->code_gen_buffer_size = total_size; -tcg_register_jit (s->code_gen_buffer, total_size); +tcg_register_jit (tcg_splitwx_to_rx (s->code_gen_buffer), total_size);#ifdef DEBUG_DISAS if (qemu_loglevel_mask (CPU_LOG_TB_OUT_ASM )) {
@@ -4507,7 +4507,7 @@ static int find_string(const char *strtab, const char *str) } } -static void tcg_register_jit_int (void *buf_ptr,size_t buf_size, +static void tcg_register_jit_int (const void *buf_ptr,size_t buf_size,const void *debug_frame,size_t debug_frame_size) {
@@ -4709,13 +4709,13 @@ static void tcg_register_jit_int(void *buf_ptr, size_t buf_size,/* No support for the feature. Provide the entry point expected by exec.c, and implement the internal function we declared earlier. */ -static void tcg_register_jit_int (void *buf,size_t size, +static void tcg_register_jit_int (const void *buf,size_t size,const void *debug_frame,size_t debug_frame_size) { } -void tcg_register_jit (void *buf,size_t buf_size) +void tcg_register_jit (const void *buf,size_t buf_size) { }#endif /* ELF_HOST_MACHINE */
tcg/aarch64/tcg-target.c.inc +1 -1
@@ -2964,7 +2964,7 @@ static const DebugFrame debug_frame = { } }; -void tcg_register_jit(void *buf, size_t buf_size) +void tcg_register_jit(const void *buf, size_t buf_size) { tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame)); }
tcg/arm/tcg-target.c.inc +1 -1
@@ -2353,7 +2353,7 @@ static const DebugFrame debug_frame = { } }; -void tcg_register_jit(void *buf, size_t buf_size) +void tcg_register_jit(const void *buf, size_t buf_size) { tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame)); }
tcg/i386/tcg-target.c.inc +1 -1
@@ -3998,7 +3998,7 @@ static const DebugFrame debug_frame = { #endif #if defined(ELF_HOST_MACHINE) -void tcg_register_jit(void *buf, size_t buf_size) +void tcg_register_jit(const void *buf, size_t buf_size) { tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame)); }
tcg/mips/tcg-target.c.inc +1 -1
@@ -2703,7 +2703,7 @@ static const DebugFrame debug_frame = { } }; -void tcg_register_jit(void *buf, size_t buf_size) +void tcg_register_jit(const void *buf, size_t buf_size) { tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame)); }
tcg/ppc/tcg-target.c.inc +1 -1
@@ -3847,7 +3847,7 @@ static DebugFrame debug_frame = { } }; -void tcg_register_jit(void *buf, size_t buf_size) +void tcg_register_jit(const void *buf, size_t buf_size) { uint8_t *p = &debug_frame.fde_reg_ofs[3]; int i;
tcg/riscv/tcg-target.c.inc +1 -1
@@ -1907,7 +1907,7 @@ static const DebugFrame debug_frame = { } }; -void tcg_register_jit(void *buf, size_t buf_size) +void tcg_register_jit(const void *buf, size_t buf_size) { tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame)); }
tcg/s390/tcg-target.c.inc +1 -1
@@ -2620,7 +2620,7 @@ static const DebugFrame debug_frame = { } }; -void tcg_register_jit(void *buf, size_t buf_size) +void tcg_register_jit(const void *buf, size_t buf_size) { tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame)); }
tcg/sparc/tcg-target.c.inc +1 -1
@@ -1816,7 +1816,7 @@ static const DebugFrame debug_frame = { .fde_ret_save = { 9, 15, 31 }, /* DW_CFA_register o7, i7 */ }; -void tcg_register_jit(void *buf, size_t buf_size) +void tcg_register_jit(const void *buf, size_t buf_size) { tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame)); }
Signature · 1 line
2.25.1
Re: [PATCH v4 12/43] tcg: Adjust tcg_register_jit for const
Quoted 5 lines · Richard Henderson
We must change all targets at once, since all must match the declaration in
tcg.c.Signed-off-by Richard Henderson <[email protected]>
Quoted 12 lines
--- include/tcg/tcg.h | 2 +- tcg/tcg.c | 10 +++++----- tcg/aarch64/tcg-target.c.inc | 2 +- tcg/arm/tcg-target.c.inc | 2 +- tcg/i386/tcg-target.c.inc | 2 +- tcg/mips/tcg-target.c.inc | 2 +- tcg/ppc/tcg-target.c.inc | 2 +- tcg/riscv/tcg-target.c.inc | 2 +- tcg/s390/tcg-target.c.inc | 2 +- tcg/sparc/tcg-target.c.inc | 2 +- 10 files changed, 14 insertions(+), 14 deletions(-)
PATCH v4 13/43 tcg: Adjust tb_target_set_jmp_target for split-wx
In reply to Richard HendersonPass both rx and rw addresses to tb_target_set_jmp_target.
--- tcg/aarch64/tcg-target.h | 2 +- tcg/arm/tcg-target.h | 2 +- tcg/i386/tcg-target.h | 6 +++--- tcg/mips/tcg-target.h | 2 +- tcg/ppc/tcg-target.h | 2 +- tcg/riscv/tcg-target.h | 2 +- tcg/s390/tcg-target.h | 8 ++++---- tcg/sparc/tcg-target.h | 2 +- tcg/tci/tcg-target.h | 6 +++--- accel/tcg/cpu-exec.c | 4 +++- tcg/aarch64/tcg-target.c.inc | 12 ++++++------ tcg/mips/tcg-target.c.inc | 8 ++++---- tcg/ppc/tcg-target.c.inc | 16 ++++++++-------- tcg/sparc/tcg-target.c.inc | 14 +++++++------- 14 files changed, 44 insertions(+), 42 deletions(-)
tcg/aarch64/tcg-target.h +1 -1
@@ -148,7 +148,7 @@ typedef enum {#define TCG_TARGET_DEFAULT_MO (0)#define TCG_TARGET_HAS_MEMORY_BSWAP 1 -void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t ); +void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t ,uintptr_t );#ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_LABELS
tcg/arm/tcg-target.h +1 -1
@@ -135,7 +135,7 @@ enum {#define TCG_TARGET_HAS_MEMORY_BSWAP 1/* not defined -- call should be eliminated at compile time */ -void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t ); +void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t ,uintptr_t );#ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_LABELS
tcg/i386/tcg-target.h +3 -3
@@ -206,11 +206,11 @@ extern bool have_avx2;#define TCG_TARGET_extract_i64_valid (ofs, len) \ (((ofs) == 8 && (len) == 8) || ((ofs) + (len)) == 32) -static inline void tb_target_set_jmp_target (uintptr_t tc_ptr, -uintptr_t jmp_addr,uintptr_t addr) +static inline void tb_target_set_jmp_target (uintptr_t tc_ptr,uintptr_t jmp_rx, +uintptr_t jmp_rw,uintptr_t addr) {/* patch the branch destination */ -qatomic_set ((int32_t *)jmp_addr, addr - (jmp_addr +4 )); +qatomic_set ((int32_t *)jmp_rw, addr - (jmp_rx +4 ));/* no need to flush icache explicitly */ }
tcg/mips/tcg-target.h +1 -1
@@ -201,7 +201,7 @@ extern bool use_mips32r2_instructions;#define TCG_TARGET_DEFAULT_MO (0)#define TCG_TARGET_HAS_MEMORY_BSWAP 1 -void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t ); +void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t ,uintptr_t );#ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_LABELS
tcg/ppc/tcg-target.h +1 -1
@@ -175,7 +175,7 @@ extern bool have_vsx;#define TCG_TARGET_HAS_bitsel_vec have_vsx#define TCG_TARGET_HAS_cmpsel_vec 0 -void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t ); +void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t ,uintptr_t );#define TCG_TARGET_DEFAULT_MO (0)#define TCG_TARGET_HAS_MEMORY_BSWAP 1
tcg/riscv/tcg-target.h +1 -1
@@ -160,7 +160,7 @@ typedef enum {#endif /* not defined -- call should be eliminated at compile time */ -void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t ); +void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t ,uintptr_t );#define TCG_TARGET_DEFAULT_MO (0)
tcg/s390/tcg-target.h +4 -4
@@ -145,12 +145,12 @@ enum { TCG_AREG0 = TCG_REG_R10, }; -static inline void tb_target_set_jmp_target (uintptr_t tc_ptr, -uintptr_t jmp_addr,uintptr_t addr) +static inline void tb_target_set_jmp_target (uintptr_t tc_ptr,uintptr_t jmp_rx, +uintptr_t jmp_rw,uintptr_t addr) {/* patch the branch destination */ -intptr_t disp = addr - (jmp_addr -2 ); -qatomic_set ((int32_t *)jmp_addr, disp /2 ); +intptr_t disp = addr - (jmp_rx -2 ); +qatomic_set ((int32_t *)jmp_rw, disp /2 );/* no need to flush icache explicitly */ }
tcg/sparc/tcg-target.h +1 -1
@@ -168,7 +168,7 @@ extern bool use_vis3_instructions;#define TCG_TARGET_DEFAULT_MO (0)#define TCG_TARGET_HAS_MEMORY_BSWAP 1 -void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t ); +void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t ,uintptr_t );#define TCG_TARGET_NEED_POOL_LABELS
tcg/tci/tcg-target.h +3 -3
@@ -198,11 +198,11 @@ void tci_disas(uint8_t opc);#define TCG_TARGET_HAS_MEMORY_BSWAP 1 -static inline void tb_target_set_jmp_target (uintptr_t tc_ptr, -uintptr_t jmp_addr,uintptr_t addr) +static inline void tb_target_set_jmp_target (uintptr_t tc_ptr,uintptr_t jmp_rx, +uintptr_t jmp_rw,uintptr_t addr) {/* patch the branch destination */ -qatomic_set ((int32_t *)jmp_addr, addr - (jmp_addr +4 )); +qatomic_set ((int32_t *)jmp_rw, addr - (jmp_rx +4 ));/* no need to flush icache explicitly */ }
accel/tcg/cpu-exec.c +3 -1
@@ -354,7 +354,9 @@ void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr)if (TCG_TARGET_HAS_direct_jump) {uintptr_t offset = tb->jmp_target_arg[n];uintptr_t tc_ptr = (uintptr_t )tb->tc.ptr; -tb_target_set_jmp_target (tc_ptr, tc_ptr + offset, addr); +uintptr_t jmp_rx = tc_ptr + offset; +uintptr_t jmp_rw = jmp_rx - tcg_splitwx_diff; +tb_target_set_jmp_target (tc_ptr, jmp_rx, jmp_rw, addr); }else { tb->jmp_target_arg[n] = addr; }
tcg/aarch64/tcg-target.c.inc +6 -6
@@ -1340,21 +1340,21 @@ static inline void tcg_out_call(TCGContext *s, const tcg_insn_unit *target) } } -void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, - uintptr_t addr) +void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx, + uintptr_t jmp_rw, uintptr_t addr) { tcg_insn_unit i1, i2; TCGType rt = TCG_TYPE_I64; TCGReg rd = TCG_REG_TMP; uint64_t pair; - ptrdiff_t offset = addr - jmp_addr; + ptrdiff_t offset = addr - jmp_rx; if (offset == sextract64(offset, 0, 26)) { i1 = I3206_B | ((offset >> 2) & 0x3ffffff); i2 = NOP; } else { - offset = (addr >> 12) - (jmp_addr >> 12); + offset = (addr >> 12) - (jmp_rx >> 12); /* patch ADRP */ i1 = I3406_ADRP | (offset & 3) << 29 | (offset & 0x1ffffc) << (5 - 2) | rd;
@@ -1362,8 +1362,8 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, i2 = I3401_ADDI | rt << 31 | (addr & 0xfff) << 10 | rd << 5 | rd; } pair = (uint64_t)i2 << 32 | i1; - qatomic_set((uint64_t *)jmp_addr, pair); - flush_idcache_range(jmp_addr, jmp_addr, 8); + qatomic_set((uint64_t *)jmp_rw, pair); + flush_idcache_range(jmp_rx, jmp_rw, 8); } static inline void tcg_out_goto_label(TCGContext *s, TCGLabel *l)
tcg/mips/tcg-target.c.inc +4 -4
@@ -2657,11 +2657,11 @@ static void tcg_target_init(TCGContext *s) tcg_regset_set_reg(s->reserved_regs, TCG_REG_GP); /* global pointer */ } -void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, - uintptr_t addr) +void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx, + uintptr_t jmp_rw, uintptr_t addr) { - qatomic_set((uint32_t *)jmp_addr, deposit32(OPC_J, 0, 26, addr >> 2)); - flush_idcache_range(jmp_addr, jmp_addr, 4); + qatomic_set((uint32_t *)jmp_rw, deposit32(OPC_J, 0, 26, addr >> 2)); + flush_idcache_range(jmp_rx, jmp_rw, 4); } typedef struct {
tcg/ppc/tcg-target.c.inc +8 -8
@@ -1722,13 +1722,13 @@ static void tcg_out_mb(TCGContext *s, TCGArg a0) tcg_out32(s, insn); } -void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, - uintptr_t addr) +void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx, + uintptr_t jmp_rw, uintptr_t addr) { if (TCG_TARGET_REG_BITS == 64) { tcg_insn_unit i1, i2; intptr_t tb_diff = addr - tc_ptr; - intptr_t br_diff = addr - (jmp_addr + 4); + intptr_t br_diff = addr - (jmp_rx + 4); uint64_t pair; /* This does not exercise the range of the branch, but we do
@@ -1752,13 +1752,13 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, /* As per the enclosing if, this is ppc64. Avoid the _Static_assert within qatomic_set that would fail to build a ppc32 host. */ - qatomic_set__nocheck((uint64_t *)jmp_addr, pair); - flush_idcache_range(jmp_addr, jmp_addr, 8); + qatomic_set__nocheck((uint64_t *)jmp_rw, pair); + flush_idcache_range(jmp_rx, jmp_rw, 8); } else { - intptr_t diff = addr - jmp_addr; + intptr_t diff = addr - jmp_rx; tcg_debug_assert(in_range_b(diff)); - qatomic_set((uint32_t *)jmp_addr, B | (diff & 0x3fffffc)); - flush_idcache_range(jmp_addr, jmp_addr, 4); + qatomic_set((uint32_t *)jmp_rw, B | (diff & 0x3fffffc)); + flush_idcache_range(jmp_rx, jmp_rw, 4); } }
tcg/sparc/tcg-target.c.inc +7 -7
@@ -1821,11 +1821,11 @@ void tcg_register_jit(const void *buf, size_t buf_size) tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame)); } -void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, - uintptr_t addr) +void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx, + uintptr_t jmp_rw, uintptr_t addr) { intptr_t tb_disp = addr - tc_ptr; - intptr_t br_disp = addr - jmp_addr; + intptr_t br_disp = addr - jmp_rx; tcg_insn_unit i1, i2; /* We can reach the entire address space for ILP32.
@@ -1834,9 +1834,9 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, tcg_debug_assert(br_disp == (int32_t)br_disp); if (!USE_REG_TB) { - qatomic_set((uint32_t *)jmp_addr, + qatomic_set((uint32_t *)jmp_rw, deposit32(CALL, 0, 30, br_disp >> 2)); - flush_idcache_range(jmp_addr, jmp_addr, 4); + flush_idcache_range(jmp_rx, jmp_rw, 4); return; }
@@ -1859,6 +1859,6 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, | INSN_IMM13((tb_disp & 0x3ff) | -0x400)); } - qatomic_set((uint64_t *)jmp_addr, deposit64(i2, 32, 32, i1)); - flush_idcache_range(jmp_addr, jmp_addr, 8); + qatomic_set((uint64_t *)jmp_rw, deposit64(i2, 32, 32, i1)); + flush_idcache_range(jmp_rx, jmp_rw, 8); }
Signature · 1 line
2.25.1
Re: [PATCH v4 13/43] tcg: Adjust tb_target_set_jmp_target for split-wx
Quoted 4 lines · Richard Henderson
Pass both rx and rw addresses to
tb_target_set_jmp_target.Signed-off-by Richard Henderson <[email protected]>
Quoted 16 lines
--- tcg/aarch64/tcg-target.h | 2 +- tcg/arm/tcg-target.h | 2 +- tcg/i386/tcg-target.h | 6 +++--- tcg/mips/tcg-target.h | 2 +- tcg/ppc/tcg-target.h | 2 +- tcg/riscv/tcg-target.h | 2 +- tcg/s390/tcg-target.h | 8 ++++---- tcg/sparc/tcg-target.h | 2 +- tcg/tci/tcg-target.h | 6 +++--- accel/tcg/cpu-exec.c | 4 +++- tcg/aarch64/tcg-target.c.inc | 12 ++++++------ tcg/mips/tcg-target.c.inc | 8 ++++---- tcg/ppc/tcg-target.c.inc | 16 ++++++++-------- tcg/sparc/tcg-target.c.inc | 14 +++++++------- 14 files changed, 44 insertions(+), 42 deletions(-)
PATCH v4 14/43 tcg: Make DisasContextBase.tb const
In reply to Richard HendersonThere is nothing within the translators that ought to be changing the TranslationBlock data, so make it const.
This does not actually use the read-only copy of the data structure that exists within the rx region.
--- include/exec/gen-icount.h | 4 ++-- include/exec/translator.h | 2 +- include/tcg/tcg-op.h | 2 +- accel/tcg/translator.c | 4 ++-- target/arm/translate-a64.c | 2 +- tcg/tcg-op.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-)
include/exec/gen-icount.h +2 -2
@@ -32,7 +32,7 @@ static inline void gen_io_end(void)tcg_temp_free_i32 (tmp); } -static inline void gen_tb_start (TranslationBlock *tb) +static inline void gen_tb_start (const TranslationBlock *tb) {TCGv_i32 count, imm;
@@ -71,7 +71,7 @@ static inline void gen_tb_start(TranslationBlock *tb)tcg_temp_free_i32 (count); } -static inline void gen_tb_end (TranslationBlock *tb,int num_insns) +static inline void gen_tb_end (const TranslationBlock *tb,int num_insns) {if (tb_cflags (tb) &CF_USE_ICOUNT ) {/* Update the num_insn immediate parameter now that we know
include/exec/translator.h +1 -1
@@ -67,7 +67,7 @@ typedef enum DisasJumpType {* Architecture-agnostic disassembly context. */ typedef struct DisasContextBase { - TranslationBlock *tb; + const TranslationBlock *tb; target_ulong pc_first; target_ulong pc_next; DisasJumpType is_jmp;
include/tcg/tcg-op.h +1 -1
@@ -805,7 +805,7 @@ static inline void tcg_gen_insn_start(target_ulong pc, target_ulong a1,* be NULL and @idx should be 0. Otherwise, @tb should be valid and * @idx should be one of the TB_EXIT_ values. */ -void tcg_gen_exit_tb (TranslationBlock *tb,unsigned idx); +void tcg_gen_exit_tb (const TranslationBlock *tb,unsigned idx);/** * tcg_gen_goto_tb() - output goto_tb TCG operation
accel/tcg/translator.c +2 -2
@@ -133,8 +133,8 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, }/* The disas_log hook may use these values rather than recompute. */ - db->tb->size = db->pc_next - db->pc_first; - db->tb->icount = db->num_insns; + tb->size = db->pc_next - db->pc_first; + tb->icount = db->num_insns;#ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)
target/arm/translate-a64.c +1 -1
@@ -410,7 +410,7 @@ static inline bool use_goto_tb(DisasContext *s, int n, uint64_t dest)static inline void gen_goto_tb (DisasContext *s,int n,uint64_t dest) { -TranslationBlock *tb; +const TranslationBlock *tb; tb = s->base.tb;if (use_goto_tb (s, n, dest)) {
tcg/tcg-op.c +1 -1
@@ -2664,7 +2664,7 @@ void tcg_gen_extr32_i64(TCGv_i64 lo, TCGv_i64 hi, TCGv_i64 arg)/* QEMU specific operations. */ -void tcg_gen_exit_tb (TranslationBlock *tb,unsigned idx) +void tcg_gen_exit_tb (const TranslationBlock *tb,unsigned idx) {uintptr_t val = (uintptr_t )tb + idx;
Signature · 1 line
2.25.1
Re: [PATCH v4 14/43] tcg: Make DisasContextBase.tb const
Quoted 7 lines · Richard Henderson
There is nothing within the translators that ought to be changing the TranslationBlock data, so make it const.
This does not actually use the read-only copy of the data structure that exists within the rx region.
Signed-off-by Richard Henderson <[email protected]>
Quoted 8 lines
--- include/exec/gen-icount.h | 4 ++-- include/exec/translator.h | 2 +- include/tcg/tcg-op.h | 2 +- accel/tcg/translator.c | 4 ++-- target/arm/translate-a64.c | 2 +- tcg/tcg-op.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-)
Re: [PATCH v4 14/43] tcg: Make DisasContextBase.tb const
In reply to Richard HendersonQuoted 8 lines · Richard Henderson
There is nothing within the translators that ought to be changing the TranslationBlock data, so make it const.
This does not actually use the read-only copy of the data structure that exists within the rx region.
Signed-off-by Richard Henderson <[email protected]>
Quoted 8 lines
--- include/exec/gen-icount.h | 4 ++-- include/exec/translator.h | 2 +- include/tcg/tcg-op.h | 2 +- accel/tcg/translator.c | 4 ++-- target/arm/translate-a64.c | 2 +- tcg/tcg-op.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-)
PATCH v4 15/43 tcg: Make tb arg to synchronize_from_tb const
In reply to Richard HendersonThere is nothing within the translators that ought to be changing the TranslationBlock data, so make it const.
This does not actually use the read-only copy of the data structure that exists within the rx region.
--- include/hw/core/cpu.h | 3 ++- target/arm/cpu.c | 3 ++- target/avr/cpu.c | 3 ++- target/hppa/cpu.c | 3 ++- target/i386/cpu.c | 3 ++- target/microblaze/cpu.c | 3 ++- target/mips/cpu.c | 3 ++- target/riscv/cpu.c | 3 ++- target/rx/cpu.c | 3 ++- target/sh4/cpu.c | 3 ++- target/sparc/cpu.c | 3 ++- target/tricore/cpu.c | 2 +- 12 files changed, 23 insertions(+), 12 deletions(-)
include/hw/core/cpu.h +2 -1
@@ -189,7 +189,8 @@ struct CPUClass {void (*get_memory_mapping)(CPUState *cpu,MemoryMappingList *list,Error **errp);void (*set_pc)(CPUState *cpu,vaddr value); -void (*synchronize_from_tb)(CPUState *cpu,struct TranslationBlock *tb); +void (*synchronize_from_tb)(CPUState *cpu, +const struct TranslationBlock *tb);bool (*tlb_fill)(CPUState *cpu,vaddr address,int size,MMUAccessType access_type,int mmu_idx,bool probe,uintptr_t retaddr);
target/arm/cpu.c +2 -1
@@ -54,7 +54,8 @@ static void arm_cpu_set_pc(CPUState *cs, vaddr value) } } -static void arm_cpu_synchronize_from_tb (CPUState *cs,TranslationBlock *tb) +static void arm_cpu_synchronize_from_tb (CPUState *cs, +const TranslationBlock *tb) {ARMCPU *cpu =ARM_CPU (cs);CPUARMState *env = &cpu->env;
target/avr/cpu.c +2 -1
@@ -41,7 +41,8 @@ static bool avr_cpu_has_work(CPUState *cs) &&cpu_interrupts_enabled (env); } -static void avr_cpu_synchronize_from_tb (CPUState *cs,TranslationBlock *tb) +static void avr_cpu_synchronize_from_tb (CPUState *cs, +const TranslationBlock *tb) {AVRCPU *cpu =AVR_CPU (cs);CPUAVRState *env = &cpu->env;
target/hppa/cpu.c +2 -1
@@ -35,7 +35,8 @@ static void hppa_cpu_set_pc(CPUState *cs, vaddr value) cpu->env.iaoq_b = value +4 ; } -static void hppa_cpu_synchronize_from_tb (CPUState *cs,TranslationBlock *tb) +static void hppa_cpu_synchronize_from_tb (CPUState *cs, +const TranslationBlock *tb) {HPPACPU *cpu =HPPA_CPU (cs);
target/i386/cpu.c +2 -1
@@ -7047,7 +7047,8 @@ static void x86_cpu_set_pc(CPUState *cs, vaddr value) cpu->env.eip = value; } -static void x86_cpu_synchronize_from_tb (CPUState *cs,TranslationBlock *tb) +static void x86_cpu_synchronize_from_tb (CPUState *cs, +const TranslationBlock *tb) {X86CPU *cpu =X86_CPU (cs);
target/microblaze/cpu.c +2 -1
@@ -83,7 +83,8 @@ static void mb_cpu_set_pc(CPUState *cs, vaddr value) cpu->env.iflags =0 ; } -static void mb_cpu_synchronize_from_tb (CPUState *cs,TranslationBlock *tb) +static void mb_cpu_synchronize_from_tb (CPUState *cs, +const TranslationBlock *tb) {MicroBlazeCPU *cpu =MICROBLAZE_CPU (cs);
target/mips/cpu.c +2 -1
@@ -44,7 +44,8 @@ static void mips_cpu_set_pc(CPUState *cs, vaddr value) } } -static void mips_cpu_synchronize_from_tb (CPUState *cs,TranslationBlock *tb) +static void mips_cpu_synchronize_from_tb (CPUState *cs, +const TranslationBlock *tb) {MIPSCPU *cpu =MIPS_CPU (cs);CPUMIPSState *env = &cpu->env;
target/riscv/cpu.c +2 -1
@@ -285,7 +285,8 @@ static void riscv_cpu_set_pc(CPUState *cs, vaddr value) env->pc = value; } -static void riscv_cpu_synchronize_from_tb (CPUState *cs,TranslationBlock *tb) +static void riscv_cpu_synchronize_from_tb (CPUState *cs, +const TranslationBlock *tb) {RISCVCPU *cpu =RISCV_CPU (cs);CPURISCVState *env = &cpu->env;
target/rx/cpu.c +2 -1
@@ -33,7 +33,8 @@ static void rx_cpu_set_pc(CPUState *cs, vaddr value) cpu->env.pc = value; } -static void rx_cpu_synchronize_from_tb (CPUState *cs,TranslationBlock *tb) +static void rx_cpu_synchronize_from_tb (CPUState *cs, +const TranslationBlock *tb) {RXCPU *cpu =RX_CPU (cs);
target/sh4/cpu.c +2 -1
@@ -34,7 +34,8 @@ static void superh_cpu_set_pc(CPUState *cs, vaddr value) cpu->env.pc = value; } -static void superh_cpu_synchronize_from_tb (CPUState *cs,TranslationBlock *tb) +static void superh_cpu_synchronize_from_tb (CPUState *cs, +const TranslationBlock *tb) {SuperHCPU *cpu =SUPERH_CPU (cs);
target/sparc/cpu.c +2 -1
@@ -691,7 +691,8 @@ static void sparc_cpu_set_pc(CPUState *cs, vaddr value) cpu->env.npc = value +4 ; } -static void sparc_cpu_synchronize_from_tb (CPUState *cs,TranslationBlock *tb) +static void sparc_cpu_synchronize_from_tb (CPUState *cs, +const TranslationBlock *tb) {SPARCCPU *cpu =SPARC_CPU (cs);
target/tricore/cpu.c +1 -1
@@ -42,7 +42,7 @@ static void tricore_cpu_set_pc(CPUState *cs, vaddr value) }static void tricore_cpu_synchronize_from_tb (CPUState *cs, -TranslationBlock *tb) +const TranslationBlock *tb) {TriCoreCPU *cpu =TRICORE_CPU (cs);CPUTriCoreState *env = &cpu->env;
Signature · 1 line
2.25.1
Re: [PATCH v4 15/43] tcg: Make tb arg to synchronize_from_tb const
Quoted 7 lines · Richard Henderson
There is nothing within the translators that ought to be changing the TranslationBlock data, so make it const.
This does not actually use the read-only copy of the data structure that exists within the rx region.
Signed-off-by Richard Henderson <[email protected]>
Quoted 14 lines
--- include/hw/core/cpu.h | 3 ++- target/arm/cpu.c | 3 ++- target/avr/cpu.c | 3 ++- target/hppa/cpu.c | 3 ++- target/i386/cpu.c | 3 ++- target/microblaze/cpu.c | 3 ++- target/mips/cpu.c | 3 ++- target/riscv/cpu.c | 3 ++- target/rx/cpu.c | 3 ++- target/sh4/cpu.c | 3 ++- target/sparc/cpu.c | 3 ++- target/tricore/cpu.c | 2 +- 12 files changed, 23 insertions(+), 12 deletions(-)
Re: [PATCH v4 15/43] tcg: Make tb arg to synchronize_from_tb const
In reply to Richard HendersonQuoted 8 lines · Richard Henderson
There is nothing within the translators that ought to be changing the TranslationBlock data, so make it const.
This does not actually use the read-only copy of the data structure that exists within the rx region.
Signed-off-by Richard Henderson <[email protected]>
Quoted 14 lines
--- include/hw/core/cpu.h | 3 ++- target/arm/cpu.c | 3 ++- target/avr/cpu.c | 3 ++- target/hppa/cpu.c | 3 ++- target/i386/cpu.c | 3 ++- target/microblaze/cpu.c | 3 ++- target/mips/cpu.c | 3 ++- target/riscv/cpu.c | 3 ++- target/rx/cpu.c | 3 ++- target/sh4/cpu.c | 3 ++- target/sparc/cpu.c | 3 ++- target/tricore/cpu.c | 2 +- 12 files changed, 23 insertions(+), 12 deletions(-)
PATCH v4 16/43 tcg: Use Error with alloc_code_gen_buffer
In reply to Richard HendersonReport better error messages than just "could not allocate". Let alloc_code_gen_buffer set ctx->code_gen_buffer_size and ctx->code_gen_buffer, and simply return bool.
--- accel/tcg/translate-all.c | 60 ++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 26 deletions(-)
accel/tcg/translate-all.c +34 -26
@@ -59,6 +59,7 @@#include "sysemu/cpus.h" #include "sysemu/cpu-timers.h" #include "sysemu/tcg.h" +#include "qapi/error.h" /* #define DEBUG_TB_INVALIDATE */ /* #define DEBUG_TB_FLUSH */
@@ -963,7 +964,7 @@ static void page_lock_pair(PageDesc **ret_p1, tb_page_addr_t phys1, (DEFAULT_CODE_GEN_BUFFER_SIZE_1 <MAX_CODE_GEN_BUFFER_SIZE \ ? DEFAULT_CODE_GEN_BUFFER_SIZE_1 : MAX_CODE_GEN_BUFFER_SIZE) -static inline size_t size_code_gen_buffer (size_t tb_size) +static size_t size_code_gen_buffer (size_t tb_size) {/* Size the buffer. */ if (tb_size ==0 ) {
@@ -1014,7 +1015,7 @@ static inline void *split_cross_256mb(void *buf1, size_t size1) static uint8_t static_code_gen_buffer[DEFAULT_CODE_GEN_BUFFER_SIZE] __attribute__((aligned(CODE_GEN_ALIGN))); -static inline void *alloc_code_gen_buffer (void ) +static bool alloc_code_gen_buffer (size_t tb_size,Error **errp) {void *buf = static_code_gen_buffer;void *end = static_code_gen_buffer +sizeof (static_code_gen_buffer);
@@ -1027,9 +1028,8 @@ static inline void *alloc_code_gen_buffer(void) size = end - buf;/* Honor a command-line option limiting the size of the buffer. */ -if (size > tcg_ctx->code_gen_buffer_size) { - size =QEMU_ALIGN_DOWN (tcg_ctx->code_gen_buffer_size, - qemu_real_host_page_size); +if (size > tb_size) { + size =QEMU_ALIGN_DOWN (tb_size, qemu_real_host_page_size); } tcg_ctx->code_gen_buffer_size = size;
@@ -1041,31 +1041,43 @@ static inline void *alloc_code_gen_buffer(void)#endif if (qemu_mprotect_rwx (buf, size)) { -abort (); +error_setg_errno (errp, errno,"mprotect of jit buffer" ); +return false; }qemu_madvise (buf, size,QEMU_MADV_HUGEPAGE ); -return buf; + tcg_ctx->code_gen_buffer = buf; +return true; }#elif defined(_WIN32) -static inline void *alloc_code_gen_buffer (void ) +static bool alloc_code_gen_buffer (size_t size,Error **errp) { -size_t size = tcg_ctx->code_gen_buffer_size; -return VirtualAlloc (NULL , size,MEM_RESERVE |MEM_COMMIT , -PAGE_EXECUTE_READWRITE ); +void *buf =VirtualAlloc (NULL , size,MEM_RESERVE |MEM_COMMIT , +PAGE_EXECUTE_READWRITE ); +if (buf ==NULL ) { +error_setg_win32 (errp,GetLastError (), +"allocate %zu bytes for jit buffer" , size); +return false; + } + + tcg_ctx->code_gen_buffer = buf; + tcg_ctx->code_gen_buffer_size = size; +return true; }#else -static inline void *alloc_code_gen_buffer (void ) +static bool alloc_code_gen_buffer (size_t size,Error **errp) {int prot =PROT_WRITE |PROT_READ |PROT_EXEC ;int flags =MAP_PRIVATE |MAP_ANONYMOUS ; -size_t size = tcg_ctx->code_gen_buffer_size;void *buf; buf =mmap (NULL , size, prot, flags,-1 ,0 );if (buf ==MAP_FAILED ) { -return NULL ; +error_setg_errno (errp, errno, +"allocate %zu bytes for jit buffer" , size); +return false; } + tcg_ctx->code_gen_buffer_size = size;#ifdef __mips__if (cross_256mb (buf, size)) {
@@ -1104,20 +1116,11 @@ static inline void *alloc_code_gen_buffer(void)/* Request large pages for the buffer. */ qemu_madvise (buf, size,QEMU_MADV_HUGEPAGE ); - return buf; + tcg_ctx->code_gen_buffer = buf; + return true; }#endif /* USE_STATIC_CODE_GEN_BUFFER, WIN32, POSIX */ -static inline void code_gen_alloc (size_t tb_size) -{ - tcg_ctx->code_gen_buffer_size =size_code_gen_buffer (tb_size); - tcg_ctx->code_gen_buffer =alloc_code_gen_buffer (); -if (tcg_ctx->code_gen_buffer ==NULL ) { -fprintf (stderr,"Could not allocate dynamic translator buffer\n" ); -exit (1 ); - } -} -static bool tb_cmp (const void *ap,const void *bp) {const TranslationBlock *a = ap;
@@ -1144,11 +1147,16 @@ static void tb_htable_init(void)size. */ void tcg_exec_init (unsigned long tb_size) { +bool ok; + tcg_allowed = true;cpu_gen_init ();page_init ();tb_htable_init (); -code_gen_alloc (tb_size); + + ok =alloc_code_gen_buffer (size_code_gen_buffer (tb_size), &error_fatal); +assert (ok); +#if defined(CONFIG_SOFTMMU )/* There's no guest base to take into account, so go ahead and initialize the prologue now. */
Signature · 1 line
2.25.1
Re: [PATCH v4 16/43] tcg: Use Error with alloc_code_gen_buffer
Quoted 9 lines · Richard Henderson
Report better error messages than just "could not allocate". Let
alloc_code_gen_buffersetctx->code_gen_buffer_sizeandctx->code_gen_buffer, and simply return bool.Signed-off-by Richard Henderson <[email protected]>--- accel/tcg/translate-all.c | 60 ++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 26 deletions(-)
PATCH v4 17/43 tcg: Add --accel tcg,split-wx property
In reply to Richard HendersonPlumb the value through to alloc_code_gen_buffer. This is not supported by any os or tcg backend, so for now enabling it will result in an error.
--- include/sysemu/tcg.h | 3 ++- tcg/aarch64/tcg-target.h | 1 + tcg/arm/tcg-target.h | 1 + tcg/i386/tcg-target.h | 1 + tcg/mips/tcg-target.h | 1 + tcg/ppc/tcg-target.h | 1 + tcg/riscv/tcg-target.h | 1 + tcg/s390/tcg-target.h | 1 + tcg/sparc/tcg-target.h | 1 + tcg/tci/tcg-target.h | 1 + accel/tcg/tcg-all.c | 26 +++++++++++++++++++++++++- accel/tcg/translate-all.c | 35 +++++++++++++++++++++++++++-------- bsd-user/main.c | 2 +- linux-user/main.c | 2 +- 14 files changed, 65 insertions(+), 12 deletions(-)
include/sysemu/tcg.h +2 -1
@@ -8,7 +8,8 @@#ifndef SYSEMU_TCG_H #define SYSEMU_TCG_H -void tcg_exec_init (unsigned long tb_size); +void tcg_exec_init (unsigned long tb_size,int splitwx); +#ifdef CONFIG_TCG extern bool tcg_allowed;#define tcg_enabled () (tcg_allowed)
tcg/aarch64/tcg-target.h +1 -0
@@ -154,5 +154,6 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);#define TCG_TARGET_NEED_LDST_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS +#define TCG_TARGET_SUPPORT_MIRROR 0#endif /* AARCH64_TCG_TARGET_H */
tcg/arm/tcg-target.h +1 -0
@@ -141,5 +141,6 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);#define TCG_TARGET_NEED_LDST_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS +#define TCG_TARGET_SUPPORT_MIRROR 0#endif
tcg/i386/tcg-target.h +1 -0
@@ -231,5 +231,6 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx,#define TCG_TARGET_NEED_LDST_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS +#define TCG_TARGET_SUPPORT_MIRROR 0#endif
tcg/mips/tcg-target.h +1 -0
@@ -200,6 +200,7 @@ extern bool use_mips32r2_instructions;#define TCG_TARGET_DEFAULT_MO (0)#define TCG_TARGET_HAS_MEMORY_BSWAP 1 +#define TCG_TARGET_SUPPORT_MIRROR 0void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t ,uintptr_t );
tcg/ppc/tcg-target.h +1 -0
@@ -184,5 +184,6 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);#define TCG_TARGET_NEED_LDST_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS +#define TCG_TARGET_SUPPORT_MIRROR 0#endif
tcg/riscv/tcg-target.h +1 -0
@@ -170,5 +170,6 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);#define TCG_TARGET_NEED_POOL_LABELS #define TCG_TARGET_HAS_MEMORY_BSWAP 0 +#define TCG_TARGET_SUPPORT_MIRROR 0#endif
tcg/s390/tcg-target.h +1 -0
@@ -158,5 +158,6 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx,#define TCG_TARGET_NEED_LDST_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS +#define TCG_TARGET_SUPPORT_MIRROR 0#endif
tcg/sparc/tcg-target.h +1 -0
@@ -171,5 +171,6 @@ extern bool use_vis3_instructions;void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t ,uintptr_t );#define TCG_TARGET_NEED_POOL_LABELS +#define TCG_TARGET_SUPPORT_MIRROR 0#endif
tcg/tci/tcg-target.h +1 -0
@@ -197,6 +197,7 @@ void tci_disas(uint8_t opc);#define TCG_TARGET_DEFAULT_MO (0)#define TCG_TARGET_HAS_MEMORY_BSWAP 1 +#define TCG_TARGET_SUPPORT_MIRROR 0static inline void tb_target_set_jmp_target (uintptr_t tc_ptr,uintptr_t jmp_rx,uintptr_t jmp_rw,uintptr_t addr)
accel/tcg/tcg-all.c +25 -1
@@ -38,6 +38,7 @@ struct TCGState {AccelState parent_obj;bool mttcg_enabled; +int splitwx_enabled;unsigned long tb_size; };typedef struct TCGState TCGState ;
@@ -94,6 +95,13 @@ static void tcg_accel_instance_init(Object *obj)TCGState *s =TCG_STATE (obj); s->mttcg_enabled =default_mttcg_enabled (); + +/* If debugging enabled, default "auto on", otherwise off. */ +#ifdef CONFIG_DEBUG_TCG + s->splitwx_enabled =-1 ; +#else + s->splitwx_enabled =0 ; +#endif }bool mttcg_enabled;
@@ -102,7 +110,7 @@ static int tcg_init(MachineState *ms) {TCGState *s =TCG_STATE (current_accel ()); -tcg_exec_init (s->tb_size *1024 *1024 ); +tcg_exec_init (s->tb_size *1024 *1024 , s->splitwx_enabled); mttcg_enabled = s->mttcg_enabled;/*
@@ -179,6 +187,18 @@ static void tcg_set_tb_size(Object *obj, Visitor *v, s->tb_size = value; } +static bool tcg_get_splitwx (Object *obj,Error **errp) +{ +TCGState *s =TCG_STATE (obj); +return s->splitwx_enabled; +} + +static void tcg_set_splitwx (Object *obj,bool value,Error **errp) +{ +TCGState *s =TCG_STATE (obj); + s->splitwx_enabled = value; +} +static void tcg_accel_class_init (ObjectClass *oc,void *data) {AccelClass *ac =ACCEL_CLASS (oc);
@@ -196,6 +216,10 @@ static void tcg_accel_class_init(ObjectClass *oc, void *data)object_class_property_set_description (oc,"tb-size" ,"TCG translation block cache size" ); +object_class_property_add_bool (oc,"split-wx" , + tcg_get_splitwx, tcg_set_splitwx); +object_class_property_set_description (oc,"split-wx" , +"Map jit pages into separate RW and RX regions" ); }static const TypeInfo tcg_accel_type = {
accel/tcg/translate-all.c +27 -8
@@ -1015,13 +1015,19 @@ static inline void *split_cross_256mb(void *buf1, size_t size1) static uint8_t static_code_gen_buffer[DEFAULT_CODE_GEN_BUFFER_SIZE] __attribute__((aligned(CODE_GEN_ALIGN))); -static bool alloc_code_gen_buffer (size_t tb_size,Error **errp) +static bool alloc_code_gen_buffer (size_t tb_size,int splitwx,Error **errp) { -void *buf = static_code_gen_buffer; -void *end = static_code_gen_buffer +sizeof (static_code_gen_buffer); +void *buf, *end;size_t size; +if (splitwx >0 ) { +error_setg (errp,"jit split-wx not supported" ); +return false; + } +/* page-align the beginning and end of the buffer */ + buf = static_code_gen_buffer; + end = static_code_gen_buffer +sizeof (static_code_gen_buffer); buf =QEMU_ALIGN_PTR_UP (buf, qemu_real_host_page_size); end =QEMU_ALIGN_PTR_DOWN (end, qemu_real_host_page_size);
@@ -1050,9 +1056,16 @@ static bool alloc_code_gen_buffer(size_t tb_size, Error **errp)return true; }#elif defined(_WIN32) -static bool alloc_code_gen_buffer (size_t size,Error **errp) +static bool alloc_code_gen_buffer (size_t size,int splitwx,Error **errp) { -void *buf =VirtualAlloc (NULL , size,MEM_RESERVE |MEM_COMMIT , +void *buf; + +if (splitwx >0 ) { +error_setg (errp,"jit split-wx not supported" ); +return false; + } + + buf =VirtualAlloc (NULL , size,MEM_RESERVE |MEM_COMMIT ,PAGE_EXECUTE_READWRITE );if (buf ==NULL ) { error_setg_win32(errp, GetLastError(),
@@ -1065,12 +1078,17 @@ static bool alloc_code_gen_buffer(size_t size, Error **errp)return true; }#else -static bool alloc_code_gen_buffer (size_t size,Error **errp) +static bool alloc_code_gen_buffer (size_t size,int splitwx,Error **errp) {int prot =PROT_WRITE |PROT_READ |PROT_EXEC ;int flags =MAP_PRIVATE |MAP_ANONYMOUS ;void *buf; +if (splitwx >0 ) { +error_setg (errp,"jit split-wx not supported" ); +return false; + } + buf =mmap (NULL , size, prot, flags,-1 ,0 );if (buf ==MAP_FAILED ) { error_setg_errno(errp, errno,
@@ -1145,7 +1163,7 @@ static void tb_htable_init(void)/* Must be called before using the QEMU cpus. 'tb_size' is the size (in bytes) allocated to the translation buffer. Zero means default size. */ -void tcg_exec_init (unsigned long tb_size) +void tcg_exec_init (unsigned long tb_size,int splitwx) {bool ok;
@@ -1154,7 +1172,8 @@ void tcg_exec_init(unsigned long tb_size)page_init ();tb_htable_init (); - ok =alloc_code_gen_buffer (size_code_gen_buffer (tb_size), &error_fatal); + ok =alloc_code_gen_buffer (size_code_gen_buffer (tb_size), + splitwx, &error_fatal);assert (ok);#if defined(CONFIG_SOFTMMU )
bsd-user/main.c +1 -1
@@ -908,7 +908,7 @@ int main(int argc, char **argv) }/* init tcg before creating CPUs and to get qemu_host_page_size */ -tcg_exec_init (0 ); +tcg_exec_init (0 , false); cpu_type =parse_cpu_option (cpu_model); cpu =cpu_create (cpu_type);
linux-user/main.c +1 -1
@@ -703,7 +703,7 @@ int main(int argc, char **argv, char **envp) cpu_type =parse_cpu_option (cpu_model);/* init tcg before creating CPUs and to get qemu_host_page_size */ -tcg_exec_init (0 ); +tcg_exec_init (0 , false); cpu =cpu_create (cpu_type); env = cpu->env_ptr;
Signature · 1 line
2.25.1
Re: [PATCH v4 17/43] tcg: Add --accel tcg,split-wx property
Should qemu-options.hx be updated?
-j
Quoted 316 lines · Richard Henderson
Plumb the value through to
alloc_code_gen_buffer. This is not supported by any os or tcg backend, so for now enabling it will result in an error.Signed-off-by Richard Henderson <[email protected]>--- include/sysemu/tcg.h | 3 ++- tcg/aarch64/tcg-target.h | 1 + tcg/arm/tcg-target.h | 1 + tcg/i386/tcg-target.h | 1 + tcg/mips/tcg-target.h | 1 + tcg/ppc/tcg-target.h | 1 + tcg/riscv/tcg-target.h | 1 + tcg/s390/tcg-target.h | 1 + tcg/sparc/tcg-target.h | 1 + tcg/tci/tcg-target.h | 1 + accel/tcg/tcg-all.c | 26 +++++++++++++++++++++++++- accel/tcg/translate-all.c | 35 +++++++++++++++++++++++++++-------- bsd-user/main.c | 2 +- linux-user/main.c | 2 +- 14 files changed, 65 insertions(+), 12 deletions(-)include/sysemu/tcg.h +2
-1@@ -8,7 +8,8 @@#ifndef SYSEMU_TCG_H #define SYSEMU_TCG_H -void tcg_exec_init (unsigned long tb_size); +void tcg_exec_init (unsigned long tb_size,int splitwx); +#ifdef CONFIG_TCG extern bool tcg_allowed;#define tcg_enabled () (tcg_allowed)tcg/aarch64/tcg-target.h +1
-0@@ -154,5 +154,6 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);#define TCG_TARGET_NEED_LDST_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS +#define TCG_TARGET_SUPPORT_MIRROR 0#endif /* AARCH64_TCG_TARGET_H */ tcg/arm/tcg-target.h +1
-0@@ -141,5 +141,6 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);#define TCG_TARGET_NEED_LDST_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS +#define TCG_TARGET_SUPPORT_MIRROR 0#endif tcg/i386/tcg-target.h +1
-0@@ -231,5 +231,6 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx,#define TCG_TARGET_NEED_LDST_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS +#define TCG_TARGET_SUPPORT_MIRROR 0#endif tcg/mips/tcg-target.h +1
-0@@ -200,6 +200,7 @@ extern bool use_mips32r2_instructions;#define TCG_TARGET_DEFAULT_MO (0)#define TCG_TARGET_HAS_MEMORY_BSWAP 1 +#define TCG_TARGET_SUPPORT_MIRROR 0void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t ,uintptr_t );tcg/ppc/tcg-target.h +1
-0@@ -184,5 +184,6 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);#define TCG_TARGET_NEED_LDST_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS +#define TCG_TARGET_SUPPORT_MIRROR 0#endif tcg/riscv/tcg-target.h +1
-0@@ -170,5 +170,6 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);#define TCG_TARGET_NEED_POOL_LABELS #define TCG_TARGET_HAS_MEMORY_BSWAP 0 +#define TCG_TARGET_SUPPORT_MIRROR 0#endif tcg/s390/tcg-target.h +1
-0@@ -158,5 +158,6 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx,#define TCG_TARGET_NEED_LDST_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS +#define TCG_TARGET_SUPPORT_MIRROR 0#endif tcg/sparc/tcg-target.h +1
-0@@ -171,5 +171,6 @@ extern bool use_vis3_instructions;void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t ,uintptr_t );#define TCG_TARGET_NEED_POOL_LABELS +#define TCG_TARGET_SUPPORT_MIRROR 0#endif tcg/tci/tcg-target.h +1
-0@@ -197,6 +197,7 @@ void tci_disas(uint8_t opc);#define TCG_TARGET_DEFAULT_MO (0)#define TCG_TARGET_HAS_MEMORY_BSWAP 1 +#define TCG_TARGET_SUPPORT_MIRROR 0static inline void tb_target_set_jmp_target (uintptr_t tc_ptr,uintptr_t jmp_rx,uintptr_t jmp_rw,uintptr_t addr)accel/tcg/tcg-all.c +25
-1@@ -38,6 +38,7 @@ struct TCGState {AccelState parent_obj;bool mttcg_enabled; +int splitwx_enabled;unsigned long tb_size; };typedef struct TCGState TCGState ;@@ -94,6 +95,13 @@ static void tcg_accel_instance_init(Object *obj)TCGState *s =TCG_STATE (obj); s->mttcg_enabled =default_mttcg_enabled (); + +/* If debugging enabled, default "auto on", otherwise off. */ +#ifdef CONFIG_DEBUG_TCG + s->splitwx_enabled =-1 ; +#else + s->splitwx_enabled =0 ; +#endif }bool mttcg_enabled;@@ -102,7 +110,7 @@ static int tcg_init(MachineState *ms) {TCGState *s =TCG_STATE (current_accel ()); -tcg_exec_init (s->tb_size *1024 *1024 ); +tcg_exec_init (s->tb_size *1024 *1024 , s->splitwx_enabled); mttcg_enabled = s->mttcg_enabled;/* @@ -179,6 +187,18 @@ static void tcg_set_tb_size(Object *obj, Visitor *v, s->tb_size = value; } +static bool tcg_get_splitwx (Object *obj,Error **errp) +{ +TCGState *s =TCG_STATE (obj); +return s->splitwx_enabled; +} + +static void tcg_set_splitwx (Object *obj,bool value,Error **errp) +{ +TCGState *s =TCG_STATE (obj); + s->splitwx_enabled = value; +} +static void tcg_accel_class_init (ObjectClass *oc,void *data) {AccelClass *ac =ACCEL_CLASS (oc);@@ -196,6 +216,10 @@ static void tcg_accel_class_init(ObjectClass *oc, void *data)object_class_property_set_description (oc,"tb-size" ,"TCG translation block cache size" ); +object_class_property_add_bool (oc,"split-wx" , + tcg_get_splitwx, tcg_set_splitwx); +object_class_property_set_description (oc,"split-wx" , +"Map jit pages into separate RW and RX regions" ); }static const TypeInfo tcg_accel_type = {accel/tcg/translate-all.c +27
-8@@ -1015,13 +1015,19 @@ static inline void *split_cross_256mb(void *buf1, size_t size1) static uint8_t static_code_gen_buffer[DEFAULT_CODE_GEN_BUFFER_SIZE] __attribute__((aligned(CODE_GEN_ALIGN))); -static bool alloc_code_gen_buffer (size_t tb_size,Error **errp) +static bool alloc_code_gen_buffer (size_t tb_size,int splitwx,Error **errp) { -void *buf = static_code_gen_buffer; -void *end = static_code_gen_buffer +sizeof (static_code_gen_buffer); +void *buf, *end;size_t size; +if (splitwx >0 ) { +error_setg (errp,"jit split-wx not supported" ); +return false; + } +/* page-align the beginning and end of the buffer */ + buf = static_code_gen_buffer; + end = static_code_gen_buffer +sizeof (static_code_gen_buffer); buf =QEMU_ALIGN_PTR_UP (buf, qemu_real_host_page_size); end =QEMU_ALIGN_PTR_DOWN (end, qemu_real_host_page_size);@@ -1050,9 +1056,16 @@ static bool alloc_code_gen_buffer(size_t tb_size, Error **errp)return true; }#elif defined(_WIN32) -static bool alloc_code_gen_buffer (size_t size,Error **errp) +static bool alloc_code_gen_buffer (size_t size,int splitwx,Error **errp) { -void *buf =VirtualAlloc (NULL , size,MEM_RESERVE |MEM_COMMIT , +void *buf; + +if (splitwx >0 ) { +error_setg (errp,"jit split-wx not supported" ); +return false; + } + + buf =VirtualAlloc (NULL , size,MEM_RESERVE |MEM_COMMIT ,PAGE_EXECUTE_READWRITE );if (buf ==NULL ) { error_setg_win32(errp, GetLastError(),@@ -1065,12 +1078,17 @@ static bool alloc_code_gen_buffer(size_t size, Error **errp)return true; }#else -static bool alloc_code_gen_buffer (size_t size,Error **errp) +static bool alloc_code_gen_buffer (size_t size,int splitwx,Error **errp) {int prot =PROT_WRITE |PROT_READ |PROT_EXEC ;int flags =MAP_PRIVATE |MAP_ANONYMOUS ;void *buf; +if (splitwx >0 ) { +error_setg (errp,"jit split-wx not supported" ); +return false; + } + buf =mmap (NULL , size, prot, flags,-1 ,0 );if (buf ==MAP_FAILED ) { error_setg_errno(errp, errno,@@ -1145,7 +1163,7 @@ static void tb_htable_init(void)/* Must be called before using the QEMU cpus. 'tb_size' is the size (in bytes) allocated to the translation buffer. Zero means default size. */ -void tcg_exec_init (unsigned long tb_size) +void tcg_exec_init (unsigned long tb_size,int splitwx) {bool ok;@@ -1154,7 +1172,8 @@ void tcg_exec_init(unsigned long tb_size)page_init ();tb_htable_init (); - ok =alloc_code_gen_buffer (size_code_gen_buffer (tb_size), &error_fatal); + ok =alloc_code_gen_buffer (size_code_gen_buffer (tb_size), + splitwx, &error_fatal);assert (ok);#if defined(CONFIG_SOFTMMU )bsd-user/main.c +1
-1@@ -908,7 +908,7 @@ int main(int argc, char **argv) }/* init tcg before creating CPUs and to get qemu_host_page_size */ -tcg_exec_init (0 ); +tcg_exec_init (0 , false); cpu_type =parse_cpu_option (cpu_model); cpu =cpu_create (cpu_type);linux-user/main.c +1
-2@@ -703,7 +703,7 @@ int main(int argc, char **argv, char **envp) cpu_type =parse_cpu_option (cpu_model);/* init tcg before creating CPUs and to get qemu_host_page_size */ -tcg_exec_init (0 ); +tcg_exec_init (0 , false); cpu =cpu_create (cpu_type); env = cpu->env_ptr; --2.25.1
Re: [PATCH v4 17/43] tcg: Add --accel tcg,split-wx property
Quoted 1 line · Joelle van Dyne
Should qemu-options.hx be updated?
Yep, good catch.
r~
PATCH v4 18/43 accel/tcg: Support split-wx for linux with memfd
In reply to Richard HendersonWe cannot use a real temp file, because we would need to find a filesystem that does not have noexec enabled. However, a memfd is not associated with any filesystem.
--- accel/tcg/translate-all.c | 84 +++++++++++++++++++++++++++++++++++---- 1 file changed, 76 insertions(+), 8 deletions(-)
accel/tcg/translate-all.c +76 -8
@@ -1078,17 +1078,11 @@ static bool alloc_code_gen_buffer(size_t size, int splitwx, Error **errp)return true; }#else -static bool alloc_code_gen_buffer (size_t size,int splitwx,Error **errp) +static bool alloc_code_gen_buffer_anon (size_t size,int prot, +int flags,Error **errp) { -int prot =PROT_WRITE |PROT_READ |PROT_EXEC ; -int flags =MAP_PRIVATE |MAP_ANONYMOUS ;void *buf; -if (splitwx >0 ) { -error_setg (errp,"jit split-wx not supported" ); -return false; - } - buf =mmap (NULL , size, prot, flags,-1 ,0 );if (buf ==MAP_FAILED ) { error_setg_errno(errp, errno,
@@ -1137,6 +1131,80 @@ static bool alloc_code_gen_buffer(size_t size, int splitwx, Error **errp) tcg_ctx->code_gen_buffer = buf;return true; } + +#ifdef CONFIG_POSIX +#include "qemu/memfd.h" + +static bool alloc_code_gen_buffer_splitwx_memfd (size_t size,Error **errp) +{ +void *buf_rw, *buf_rx; +int fd =-1 ; + + buf_rw =qemu_memfd_alloc ("tcg-jit" , size,0 , &fd, errp); +if (buf_rw ==NULL ) { +return false; + } + + buf_rx =mmap (NULL , size,PROT_READ |PROT_EXEC ,MAP_SHARED , fd,0 ); +if (buf_rx ==MAP_FAILED ) { +error_setg_errno (errp, errno, +"failed to map shared memory for execute" ); +munmap (buf_rw, size); +close (fd); +return false; + } +close (fd); + + tcg_ctx->code_gen_buffer = buf_rw; + tcg_ctx->code_gen_buffer_size = size; + tcg_splitwx_diff = buf_rx - buf_rw; + +/* Request large pages for the buffer and the splitwx. */ +qemu_madvise (buf_rw, size,QEMU_MADV_HUGEPAGE ); +qemu_madvise (buf_rx, size,QEMU_MADV_HUGEPAGE ); +return true; +} +#endif /* CONFIG_POSIX */ + +static bool alloc_code_gen_buffer_splitwx (size_t size,Error **errp) +{ +if (TCG_TARGET_SUPPORT_MIRROR ) { +#ifdef CONFIG_POSIX +return alloc_code_gen_buffer_splitwx_memfd (size, errp); +#endif + } +error_setg (errp,"jit split-wx not supported" ); +return false; +} + +static bool alloc_code_gen_buffer (size_t size,int splitwx,Error **errp) +{ +ERRP_GUARD (); +int prot, flags; + +if (splitwx) { +if (alloc_code_gen_buffer_splitwx (size, errp)) { +return true; + } +/* +* If splitwx force-on (1), fail; +* if splitwx default-on (-1), fall through to splitwx off. +*/ +if (splitwx >0 ) { +return false; + } +error_free_or_abort (errp); + } + + prot =PROT_READ |PROT_WRITE |PROT_EXEC ; + flags =MAP_PRIVATE |MAP_ANONYMOUS ; +#ifdef CONFIG_TCG_INTERPRETER +/* The tcg interpreter does not need execute permission. */ + prot =PROT_READ |PROT_WRITE ; +#endif + +return alloc_code_gen_buffer_anon (size, prot, flags, errp); +}#endif /* USE_STATIC_CODE_GEN_BUFFER, WIN32, POSIX */ static bool tb_cmp (const void *ap,const void *bp)
Signature · 1 line
2.25.1
Re: [PATCH v4 18/43] accel/tcg: Support split-wx for linux with memfd
Quoted 9 lines · Richard Henderson
We cannot use a real temp file, because we would need to find a filesystem that does not have noexec enabled. However, a memfd is not associated with any filesystem.
Signed-off-by Richard Henderson <[email protected]>--- accel/tcg/translate-all.c | 84 +++++++++++++++++++++++++++++++++++---- 1 file changed, 76 insertions(+), 8 deletions(-)
PATCH v4 19/43 accel/tcg: Support split-wx for darwin/iOS with vm_remap
In reply to Richard HendersonCribbed from code posted by Joelle van Dyne <[email protected]>, and rearranged to a cleaner structure.
--- accel/tcg/translate-all.c | 65 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+)
accel/tcg/translate-all.c +65 -0
@@ -1166,9 +1166,71 @@ static bool alloc_code_gen_buffer_splitwx_memfd(size_t size, Error **errp) }#endif /* CONFIG_POSIX */ +#ifdef CONFIG_DARWIN +#include <mach/mach.h> + +extern kern_return_t mach_vm_remap (vm_map_t target_task, +mach_vm_address_t *target_address, +mach_vm_size_t size, +mach_vm_offset_t mask, +int flags, +vm_map_t src_task, +mach_vm_address_t src_address, +boolean_t copy, +vm_prot_t *cur_protection, +vm_prot_t *max_protection, +vm_inherit_t inheritance); + +static bool alloc_code_gen_buffer_splitwx_vmremap (size_t size,Error **errp) +{ +kern_return_t ret; +mach_vm_address_t buf_rw, buf_rx; +vm_prot_t cur_prot, max_prot; + +/* Map the read-write portion via normal anon memory. */ +if (!alloc_code_gen_buffer_anon (size,PROT_READ |PROT_WRITE , +MAP_PRIVATE |MAP_ANONYMOUS , errp)) { +return false; + } + + buf_rw = (mach_vm_address_t )tcg_ctx->code_gen_buffer; + buf_rx =0 ; + ret =mach_vm_remap (mach_task_self (), + &buf_rx, + size, +0 , +VM_FLAGS_ANYWHERE , +mach_task_self (), + buf_rw, + false, + &cur_prot, + &max_prot, +VM_INHERIT_NONE ); +if (ret !=KERN_SUCCESS ) { +/* TODO: Convert "ret" to a human readable error message. */ +error_setg (errp,"vm_remap for jit splitwx failed" ); +munmap ((void *)buf_rw, size); +return false; + } + +if (mprotect ((void *)buf_rx, size,PROT_READ |PROT_EXEC ) !=0 ) { +error_setg_errno (errp, errno,"mprotect for jit splitwx" ); +munmap ((void *)buf_rx, size); +munmap ((void *)buf_rw, size); +return false; + } + + tcg_splitwx_diff = buf_rx - buf_rw; +return true; +} +#endif /* CONFIG_DARWIN */ +static bool alloc_code_gen_buffer_splitwx (size_t size,Error **errp) {if (TCG_TARGET_SUPPORT_MIRROR ) { +#ifdef CONFIG_DARWIN +return alloc_code_gen_buffer_splitwx_vmremap (size, errp); +#endif #ifdef CONFIG_POSIX return alloc_code_gen_buffer_splitwx_memfd (size, errp);#endif
@@ -1201,6 +1263,9 @@ static bool alloc_code_gen_buffer(size_t size, int splitwx, Error **errp)#ifdef CONFIG_TCG_INTERPRETER /* The tcg interpreter does not need execute permission. */ prot =PROT_READ |PROT_WRITE ; +#elif defined(CONFIG_DARWIN ) +/* Applicable to both iOS and macOS (Apple Silicon). */ + flags |=MAP_JIT ;#endif return alloc_code_gen_buffer_anon (size, prot, flags, errp);
Signature · 1 line
2.25.1
Re: [PATCH v4 19/43] accel/tcg: Support split-wx for darwin/iOS with vm_remap
Guarding MAP_JIT with
if (!splitwx) {
flags |= MAP_JIT;
}is better because MAP_JIT tells the kernel that we want a RWX mapping which is not the case. On iOS, special entitlements are needed for MAP_JIT.
-j
Quoted 99 lines · Richard Henderson
Cribbed from code posted by Joelle van Dyne <[email protected]>, and rearranged to a cleaner structure.
Reviewed-by Joelle van Dyne <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- accel/tcg/translate-all.c | 65 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+)accel/tcg/translate-all.c +65
-1@@ -1166,9 +1166,71 @@ static bool alloc_code_gen_buffer_splitwx_memfd(size_t size, Error **errp) }#endif /* CONFIG_POSIX */ +#ifdef CONFIG_DARWIN +#include <mach/mach.h> + +extern kern_return_t mach_vm_remap (vm_map_t target_task, +mach_vm_address_t *target_address, +mach_vm_size_t size, +mach_vm_offset_t mask, +int flags, +vm_map_t src_task, +mach_vm_address_t src_address, +boolean_t copy, +vm_prot_t *cur_protection, +vm_prot_t *max_protection, +vm_inherit_t inheritance); + +static bool alloc_code_gen_buffer_splitwx_vmremap (size_t size,Error **errp) +{ +kern_return_t ret; +mach_vm_address_t buf_rw, buf_rx; +vm_prot_t cur_prot, max_prot; + +/* Map the read-write portion via normal anon memory. */ +if (!alloc_code_gen_buffer_anon (size,PROT_READ |PROT_WRITE , +MAP_PRIVATE |MAP_ANONYMOUS , errp)) { +return false; + } + + buf_rw = (mach_vm_address_t )tcg_ctx->code_gen_buffer; + buf_rx =0 ; + ret =mach_vm_remap (mach_task_self (), + &buf_rx, + size, +0 , +VM_FLAGS_ANYWHERE , +mach_task_self (), + buf_rw, + false, + &cur_prot, + &max_prot, +VM_INHERIT_NONE ); +if (ret !=KERN_SUCCESS ) { +/* TODO: Convert "ret" to a human readable error message. */ +error_setg (errp,"vm_remap for jit splitwx failed" ); +munmap ((void *)buf_rw, size); +return false; + } + +if (mprotect ((void *)buf_rx, size,PROT_READ |PROT_EXEC ) !=0 ) { +error_setg_errno (errp, errno,"mprotect for jit splitwx" ); +munmap ((void *)buf_rx, size); +munmap ((void *)buf_rw, size); +return false; + } + + tcg_splitwx_diff = buf_rx - buf_rw; +return true; +} +#endif /* CONFIG_DARWIN */ +static bool alloc_code_gen_buffer_splitwx (size_t size,Error **errp) {if (TCG_TARGET_SUPPORT_MIRROR ) { +#ifdef CONFIG_DARWIN +return alloc_code_gen_buffer_splitwx_vmremap (size, errp); +#endif #ifdef CONFIG_POSIX return alloc_code_gen_buffer_splitwx_memfd (size, errp);#endif @@ -1201,6 +1263,9 @@ static bool alloc_code_gen_buffer(size_t size, int splitwx, Error **errp)#ifdef CONFIG_TCG_INTERPRETER /* The tcg interpreter does not need execute permission. */ prot =PROT_READ |PROT_WRITE ; +#elif defined(CONFIG_DARWIN ) +/* Applicable to both iOS and macOS (Apple Silicon). */ + flags |=MAP_JIT ;#endif return alloc_code_gen_buffer_anon (size, prot, flags, errp); --2.25.1
Re: [PATCH v4 19/43] accel/tcg: Support split-wx for darwin/iOS with vm_remap
Quoted 9 lines · Joelle van Dyne
Guarding
MAP_JITwithif (!splitwx) { flags |= MAP_JIT; }is better because
MAP_JITtells the kernel that we want a RWX mapping which is not the case. On iOS, special entitlements are needed forMAP_JIT.
Thanks, fixed.
r~
PATCH v4 20/43 tcg: Return the TB pointer from the rx region from exit_tb
In reply to Richard HendersonThis produces a small pc-relative displacement within the generated code to the TB structure that preceeds it.
--- accel/tcg/cpu-exec.c | 35 ++++++++++++++++++++++------------- tcg/tcg-op.c | 13 ++++++++++++- 2 files changed, 34 insertions(+), 14 deletions(-)
accel/tcg/cpu-exec.c +22 -13
@@ -144,12 +144,13 @@ static void init_delay_params(SyncClocks *sc, const CPUState *cpu)#endif /* CONFIG USER ONLY */ /* Execute a TB, and fix up the CPU state afterwards if necessary */ -static inline tcg_target_ulong cpu_tb_exec (CPUState *cpu,TranslationBlock *itb) +static inline TranslationBlock *cpu_tb_exec (CPUState *cpu, +TranslationBlock *itb, +int *tb_exit) {CPUArchState *env = cpu->env_ptr;uintptr_t ret;TranslationBlock *last_tb; -int tb_exit;const void *tb_ptr = itb->tc.ptr; qemu_log_mask_and_addr(CPU_LOG_EXEC, itb->pc,
@@ -177,11 +178,20 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb) ret =tcg_qemu_tb_exec (env, tb_ptr); cpu->can_do_io =1 ; - last_tb = (TranslationBlock *)(ret & ~TB_EXIT_MASK ); - tb_exit = ret &TB_EXIT_MASK ; -trace_exec_tb_exit (last_tb, tb_exit); +/* +* TODO: Delay swapping back to the read-write region of the TB +* until we actually need to modify the TB. The read-only copy, +* coming from the rx region, shares the same host TLB entry as +* the code that executed the exit_tb opcode that arrived here. +* If we insist on touching both the RX and the RW pages, we +* double the host TLB pressure. +*/ + last_tb =tcg_splitwx_to_rw ((void *)(ret & ~TB_EXIT_MASK )); + *tb_exit = ret &TB_EXIT_MASK ; -if (tb_exit >TB_EXIT_IDX1 ) { +trace_exec_tb_exit (last_tb, *tb_exit); + +if (*tb_exit >TB_EXIT_IDX1 ) {/* We didn't start executing this TB (eg because the instruction * counter hit zero); we must restore the guest PC to the address * of the start of the TB.
@@ -199,7 +209,7 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb) cc->set_pc (cpu, last_tb->pc); } } -return ret; +return last_tb; }#ifndef CONFIG_USER_ONLY
@@ -210,6 +220,7 @@ static void cpu_exec_nocache(CPUState *cpu, int max_cycles, {TranslationBlock *tb;uint32_t cflags =curr_cflags () |CF_NOCACHE ; +int tb_exit;if (ignore_icount) { cflags &= ~CF_USE_ICOUNT ;
@@ -227,7 +238,7 @@ static void cpu_exec_nocache(CPUState *cpu, int max_cycles,/* execute the generated code */ trace_exec_tb_nocache (tb, tb->pc); -cpu_tb_exec (cpu, tb); +cpu_tb_exec (cpu, tb, &tb_exit);mmap_lock ();tb_phys_invalidate (tb,-1 );
@@ -244,6 +255,7 @@ void cpu_exec_step_atomic(CPUState *cpu)uint32_t flags;uint32_t cflags =1 ;uint32_t cf_mask = cflags &CF_HASH_MASK ; +int tb_exit;if (sigsetjmp (cpu->jmp_env,0 ) ==0 ) {start_exclusive ();
@@ -260,7 +272,7 @@ void cpu_exec_step_atomic(CPUState *cpu) cc->cpu_exec_enter (cpu);/* execute the generated code */ trace_exec_tb (tb, pc); -cpu_tb_exec (cpu, tb); +cpu_tb_exec (cpu, tb, &tb_exit); cc->cpu_exec_exit (cpu); }else {/*
@@ -653,13 +665,10 @@ static inline bool cpu_handle_interrupt(CPUState *cpu,static inline void cpu_loop_exec_tb (CPUState *cpu,TranslationBlock *tb,TranslationBlock **last_tb,int *tb_exit) { -uintptr_t ret;int32_t insns_left;trace_exec_tb (tb, tb->pc); - ret =cpu_tb_exec (cpu, tb); - tb = (TranslationBlock *)(ret & ~TB_EXIT_MASK ); - *tb_exit = ret &TB_EXIT_MASK ; + tb =cpu_tb_exec (cpu, tb, tb_exit);if (*tb_exit !=TB_EXIT_REQUESTED ) { *last_tb = tb;return ;
tcg/tcg-op.c +12 -1
@@ -2666,7 +2666,18 @@ void tcg_gen_extr32_i64(TCGv_i64 lo, TCGv_i64 hi, TCGv_i64 arg)void tcg_gen_exit_tb (const TranslationBlock *tb,unsigned idx) { -uintptr_t val = (uintptr_t )tb + idx; +/* +* Let the jit code return the read-only version of the +* TranslationBlock, so that we minimize the pc-relative +* distance of the address of the exit_tb code to TB. +* This will improve utilization of pc-relative address loads. +* +* TODO: Move this to translator_loop, so that all const +* TranslationBlock pointers refer to read-only memory. +* This requires coordination with targets that do not use +* the translator_loop. +*/ +uintptr_t val = (uintptr_t )tcg_splitwx_to_rx ((void *)tb) + idx;if (tb ==NULL ) {tcg_debug_assert (idx ==0 );
Signature · 1 line
2.25.1
Re: [PATCH v4 20/43] tcg: Return the TB pointer from the rx region from exit_tb
Quoted 9 lines · Richard Henderson
This produces a small pc-relative displacement within the generated code to the TB structure that preceeds it.
Signed-off-by Richard Henderson <[email protected]>--- accel/tcg/cpu-exec.c | 35 ++++++++++++++++++++++------------- tcg/tcg-op.c | 13 ++++++++++++- 2 files changed, 34 insertions(+), 14 deletions(-)
PATCH v4 21/43 tcg/i386: Support split-wx code generation
In reply to Richard Henderson--- tcg/i386/tcg-target.h | 2 +- tcg/i386/tcg-target.c.inc | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-)
tcg/i386/tcg-target.h +1 -1
@@ -231,6 +231,6 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx,#define TCG_TARGET_NEED_LDST_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS -#define TCG_TARGET_SUPPORT_MIRROR 0 +#define TCG_TARGET_SUPPORT_MIRROR 1#endif
tcg/i386/tcg-target.c.inc +11 -9
@@ -165,7 +165,7 @@ static bool have_lzcnt; # define have_lzcnt 0 #endif -static tcg_insn_unit *tb_ret_addr; +static const tcg_insn_unit *tb_ret_addr; static bool patch_reloc(tcg_insn_unit *code_ptr, int type, intptr_t value, intptr_t addend)
@@ -173,7 +173,7 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type, value += addend; switch(type) { case R_386_PC32: - value -= (uintptr_t)code_ptr; + value -= (uintptr_t)tcg_splitwx_to_rx(code_ptr); if (value != (int32_t)value) { return false; }
@@ -182,7 +182,7 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type, tcg_patch32(code_ptr, value); break; case R_386_PC8: - value -= (uintptr_t)code_ptr; + value -= (uintptr_t)tcg_splitwx_to_rx(code_ptr); if (value != (int8_t)value) { return false; }
@@ -1006,7 +1006,7 @@ static void tcg_out_movi(TCGContext *s, TCGType type, } /* Try a 7 byte pc-relative lea before the 10 byte movq. */ - diff = arg - ((uintptr_t)s->code_ptr + 7); + diff = tcg_pcrel_diff(s, (const void *)arg) - 7; if (diff == (int32_t)diff) { tcg_out_opc(s, OPC_LEA | P_REXW, ret, 0, 0); tcg_out8(s, (LOWREGMASK(ret) << 3) | 5);
@@ -1615,7 +1615,7 @@ static inline void tcg_out_call(TCGContext *s, const tcg_insn_unit *dest) tcg_out_branch(s, 1, dest); } -static void tcg_out_jmp(TCGContext *s, tcg_insn_unit *dest) +static void tcg_out_jmp(TCGContext *s, const tcg_insn_unit *dest) { tcg_out_branch(s, 0, dest); }
@@ -1786,7 +1786,8 @@ static void add_qemu_ldst_label(TCGContext *s, bool is_ld, bool is_64, label->datahi_reg = datahi; label->addrlo_reg = addrlo; label->addrhi_reg = addrhi; - label->raddr = raddr; + /* TODO: Cast goes away when all hosts converted */ + label->raddr = (void *)tcg_splitwx_to_rx(raddr); label->label_ptr[0] = label_ptr[0]; if (TARGET_LONG_BITS > TCG_TARGET_REG_BITS) { label->label_ptr[1] = label_ptr[1];
@@ -2280,7 +2281,7 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, /* jump displacement must be aligned for atomic patching; * see if we need to add extra nops before jump */ - gap = tcg_pcrel_diff(s, QEMU_ALIGN_PTR_UP(s->code_ptr + 1, 4)); + gap = QEMU_ALIGN_PTR_UP(s->code_ptr + 1, 4) - s->code_ptr; if (gap != 1) { tcg_out_nopn(s, gap - 1); }
@@ -3825,11 +3826,12 @@ static void tcg_target_qemu_prologue(TCGContext *s) * Return path for goto_ptr. Set return value to 0, a-la exit_tb, * and fall through to the rest of the epilogue. */ - tcg_code_gen_epilogue = s->code_ptr; + /* TODO: Cast goes away when all hosts converted */ + tcg_code_gen_epilogue = (void *)tcg_splitwx_to_rx(s->code_ptr); tcg_out_movi(s, TCG_TYPE_REG, TCG_REG_EAX, 0); /* TB epilogue */ - tb_ret_addr = s->code_ptr; + tb_ret_addr = tcg_splitwx_to_rx(s->code_ptr); tcg_out_addi(s, TCG_REG_CALL_STACK, stack_addend);
Signature · 1 line
2.25.1
Re: [PATCH v4 21/43] tcg/i386: Support split-wx code generation
Quoted 6 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- tcg/i386/tcg-target.h | 2 +- tcg/i386/tcg-target.c.inc | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-)
PATCH v4 22/43 tcg/aarch64: Use B not BL for tcg_out_goto_long
In reply to Richard HendersonA typo generated a branch-and-link insn instead of plain branch.
--- tcg/aarch64/tcg-target.c.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tcg/aarch64/tcg-target.c.inc +1 -1
@@ -1317,7 +1317,7 @@ static inline void tcg_out_goto_long(TCGContext *s, tcg_insn_unit *target) { ptrdiff_t offset = target - s->code_ptr; if (offset == sextract64(offset, 0, 26)) { - tcg_out_insn(s, 3206, BL, offset); + tcg_out_insn(s, 3206, B, offset); } else { tcg_out_movi(s, TCG_TYPE_I64, TCG_REG_TMP, (intptr_t)target); tcg_out_insn(s, 3207, BR, TCG_REG_TMP);
Signature · 1 line
2.25.1
Re: [PATCH v4 22/43] tcg/aarch64: Use B not BL for tcg_out_goto_long
Quoted 7 lines · Richard Henderson
A typo generated a branch-and-link insn instead of plain branch.
Signed-off-by Richard Henderson <[email protected]>--- tcg/aarch64/tcg-target.c.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH v4 23/43 tcg/aarch64: Support split-wx code generation
In reply to Richard Henderson--- tcg/aarch64/tcg-target.h | 2 +- tcg/aarch64/tcg-target.c.inc | 57 ++++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 26 deletions(-)
tcg/aarch64/tcg-target.h +1 -1
@@ -154,6 +154,6 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);#define TCG_TARGET_NEED_LDST_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS -#define TCG_TARGET_SUPPORT_MIRROR 0 +#define TCG_TARGET_SUPPORT_MIRROR 1#endif /* AARCH64_TCG_TARGET_H */
tcg/aarch64/tcg-target.c.inc +32 -25
158 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v4 23/43] tcg/aarch64: Support split-wx code generation
Quoted 6 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- tcg/aarch64/tcg-target.h | 2 +- tcg/aarch64/tcg-target.c.inc | 57 ++++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 26 deletions(-)
PATCH v4 24/43 disas: Push const down through host disasassembly
In reply to Richard Henderson--- include/disas/dis-asm.h | 4 ++-- disas.c | 4 +--- disas/capstone.c | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-)
include/disas/dis-asm.h +2 -2
@@ -358,7 +358,7 @@ typedef struct disassemble_info { (bfd_vma addr, struct disassemble_info * info);/* These are for buffer_read_memory. */ -bfd_byte *buffer; +const bfd_byte *buffer;bfd_vma buffer_vma;int buffer_length;
@@ -462,7 +462,7 @@ int print_insn_rx(bfd_vma, disassemble_info *);#ifdef CONFIG_CAPSTONE bool cap_disas_target (disassemble_info *info,uint64_t pc,size_t size); -bool cap_disas_host (disassemble_info *info,void *code,size_t size); +bool cap_disas_host (disassemble_info *info,const void *code,size_t size);bool cap_disas_monitor (disassemble_info *info,uint64_t pc,int count);bool cap_disas_plugin (disassemble_info *info,uint64_t pc,size_t size);#else
disas.c +1 -3
@@ -299,10 +299,8 @@ char *plugin_disas(CPUState *cpu, uint64_t addr, size_t size) }/* Disassemble this for me please... (debugging). */ -void disas (FILE *out,const void *ccode,unsigned long size) +void disas (FILE *out,const void *code,unsigned long size) { -/* TODO: Push constness through the disas backends. */ -void *code = (void *)ccode;uintptr_t pc;int count;CPUDebug s;
disas/capstone.c +1 -1
@@ -229,7 +229,7 @@ bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size) }/* Disassemble SIZE bytes at CODE for the host. */ -bool cap_disas_host (disassemble_info *info,void *code,size_t size) +bool cap_disas_host (disassemble_info *info,const void *code,size_t size) {csh handle;const uint8_t *cbuf;
Signature · 1 line
2.25.1
Re: [PATCH v4 24/43] disas: Push const down through host disasassembly
Typo "disassembly" in subject?
Quoted 6 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- include/disas/dis-asm.h | 4 ++-- disas.c | 4 +--- disas/capstone.c | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-)
Re: [PATCH v4 24/43] disas: Push const down through host disasassembly
In reply to Richard HendersonQuoted 7 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- include/disas/dis-asm.h | 4 ++-- disas.c | 4 +--- disas/capstone.c | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-)
PATCH v4 25/43 tcg/tci: Push const down through bytecode reading
In reply to Richard Henderson--- tcg/tci.c | 60 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 26 deletions(-)
tcg/tci.c +34 -26
@@ -163,34 +163,34 @@ static uint64_t tci_uint64(uint32_t high, uint32_t low)#endif /* Read constant (native size) from bytecode. */ -static tcg_target_ulong tci_read_i (uint8_t **tb_ptr) +static tcg_target_ulong tci_read_i (const uint8_t **tb_ptr) { -tcg_target_ulong value = *(tcg_target_ulong *)(*tb_ptr); +tcg_target_ulong value = *(const tcg_target_ulong *)(*tb_ptr); *tb_ptr +=sizeof (value);return value; }/* Read unsigned constant (32 bit) from bytecode. */ -static uint32_t tci_read_i32 (uint8_t **tb_ptr) +static uint32_t tci_read_i32 (const uint8_t **tb_ptr) { -uint32_t value = *(uint32_t *)(*tb_ptr); +uint32_t value = *(const uint32_t *)(*tb_ptr); *tb_ptr +=sizeof (value);return value; }/* Read signed constant (32 bit) from bytecode. */ -static int32_t tci_read_s32 (uint8_t **tb_ptr) +static int32_t tci_read_s32 (const uint8_t **tb_ptr) { -int32_t value = *(int32_t *)(*tb_ptr); +int32_t value = *(const int32_t *)(*tb_ptr); *tb_ptr +=sizeof (value);return value; }#if TCG_TARGET_REG_BITS ==64 /* Read constant (64 bit) from bytecode. */ -static uint64_t tci_read_i64 (uint8_t **tb_ptr) +static uint64_t tci_read_i64 (const uint8_t **tb_ptr) { -uint64_t value = *(uint64_t *)(*tb_ptr); +uint64_t value = *(const uint64_t *)(*tb_ptr); *tb_ptr +=sizeof (value);return value; }
@@ -198,7 +198,7 @@ static uint64_t tci_read_i64(uint8_t **tb_ptr)/* Read indexed register (native size) from bytecode. */ static tcg_target_ulong -tci_read_r (const tcg_target_ulong *regs,uint8_t **tb_ptr) +tci_read_r (const tcg_target_ulong *regs,const uint8_t **tb_ptr) {tcg_target_ulong value =tci_read_reg (regs, **tb_ptr); *tb_ptr +=1 ;
@@ -206,7 +206,7 @@ tci_read_r(const tcg_target_ulong *regs, uint8_t **tb_ptr) }/* Read indexed register (8 bit) from bytecode. */ -static uint8_t tci_read_r8 (const tcg_target_ulong *regs,uint8_t **tb_ptr) +static uint8_t tci_read_r8 (const tcg_target_ulong *regs,const uint8_t **tb_ptr) {uint8_t value =tci_read_reg8 (regs, **tb_ptr); *tb_ptr +=1 ;
@@ -215,7 +215,7 @@ static uint8_t tci_read_r8(const tcg_target_ulong *regs, uint8_t **tb_ptr)#if TCG_TARGET_HAS_ext8s_i32 || TCG_TARGET_HAS_ext8s_i64/* Read indexed register (8 bit signed) from bytecode. */ -static int8_t tci_read_r8s (const tcg_target_ulong *regs,uint8_t **tb_ptr) +static int8_t tci_read_r8s (const tcg_target_ulong *regs,const uint8_t **tb_ptr) {int8_t value =tci_read_reg8s (regs, **tb_ptr); *tb_ptr +=1 ;
@@ -224,7 +224,8 @@ static int8_t tci_read_r8s(const tcg_target_ulong *regs, uint8_t **tb_ptr)#endif /* Read indexed register (16 bit) from bytecode. */ -static uint16_t tci_read_r16 (const tcg_target_ulong *regs,uint8_t **tb_ptr) +static uint16_t tci_read_r16 (const tcg_target_ulong *regs, +const uint8_t **tb_ptr) {uint16_t value =tci_read_reg16 (regs, **tb_ptr); *tb_ptr +=1 ;
@@ -233,7 +234,8 @@ static uint16_t tci_read_r16(const tcg_target_ulong *regs, uint8_t **tb_ptr)#if TCG_TARGET_HAS_ext16s_i32 || TCG_TARGET_HAS_ext16s_i64/* Read indexed register (16 bit signed) from bytecode. */ -static int16_t tci_read_r16s (const tcg_target_ulong *regs,uint8_t **tb_ptr) +static int16_t tci_read_r16s (const tcg_target_ulong *regs, +const uint8_t **tb_ptr) {int16_t value =tci_read_reg16s (regs, **tb_ptr); *tb_ptr +=1 ;
@@ -242,7 +244,8 @@ static int16_t tci_read_r16s(const tcg_target_ulong *regs, uint8_t **tb_ptr)#endif /* Read indexed register (32 bit) from bytecode. */ -static uint32_t tci_read_r32 (const tcg_target_ulong *regs,uint8_t **tb_ptr) +static uint32_t tci_read_r32 (const tcg_target_ulong *regs, +const uint8_t **tb_ptr) {uint32_t value =tci_read_reg32 (regs, **tb_ptr); *tb_ptr +=1 ;
@@ -251,14 +254,16 @@ static uint32_t tci_read_r32(const tcg_target_ulong *regs, uint8_t **tb_ptr)#if TCG_TARGET_REG_BITS ==32 /* Read two indexed registers (2 * 32 bit) from bytecode. */ -static uint64_t tci_read_r64 (const tcg_target_ulong *regs,uint8_t **tb_ptr) +static uint64_t tci_read_r64 (const tcg_target_ulong *regs, +const uint8_t **tb_ptr) {uint32_t low =tci_read_r32 (regs, tb_ptr);return tci_uint64 (tci_read_r32 (regs, tb_ptr), low); }#elif TCG_TARGET_REG_BITS ==64 /* Read indexed register (32 bit signed) from bytecode. */ -static int32_t tci_read_r32s (const tcg_target_ulong *regs,uint8_t **tb_ptr) +static int32_t tci_read_r32s (const tcg_target_ulong *regs, +const uint8_t **tb_ptr) {int32_t value =tci_read_reg32s (regs, **tb_ptr); *tb_ptr +=1 ;
@@ -266,7 +271,8 @@ static int32_t tci_read_r32s(const tcg_target_ulong *regs, uint8_t **tb_ptr) }/* Read indexed register (64 bit) from bytecode. */ -static uint64_t tci_read_r64 (const tcg_target_ulong *regs,uint8_t **tb_ptr) +static uint64_t tci_read_r64 (const tcg_target_ulong *regs, +const uint8_t **tb_ptr) {uint64_t value =tci_read_reg64 (regs, **tb_ptr); *tb_ptr +=1 ;
@@ -276,7 +282,7 @@ static uint64_t tci_read_r64(const tcg_target_ulong *regs, uint8_t **tb_ptr)/* Read indexed register(s) with target address from bytecode. */ static target_ulong -tci_read_ulong (const tcg_target_ulong *regs,uint8_t **tb_ptr) +tci_read_ulong (const tcg_target_ulong *regs,const uint8_t **tb_ptr) {target_ulong taddr =tci_read_r (regs, tb_ptr);#if TARGET_LONG_BITS >TCG_TARGET_REG_BITS
@@ -287,7 +293,7 @@ tci_read_ulong(const tcg_target_ulong *regs, uint8_t **tb_ptr)/* Read indexed register or constant (native size) from bytecode. */ static tcg_target_ulong -tci_read_ri (const tcg_target_ulong *regs,uint8_t **tb_ptr) +tci_read_ri (const tcg_target_ulong *regs,const uint8_t **tb_ptr) {tcg_target_ulong value;TCGReg r = **tb_ptr;
@@ -301,7 +307,8 @@ tci_read_ri(const tcg_target_ulong *regs, uint8_t **tb_ptr) }/* Read indexed register or constant (32 bit) from bytecode. */ -static uint32_t tci_read_ri32 (const tcg_target_ulong *regs,uint8_t **tb_ptr) +static uint32_t tci_read_ri32 (const tcg_target_ulong *regs, +const uint8_t **tb_ptr) {uint32_t value;TCGReg r = **tb_ptr;
@@ -316,14 +323,16 @@ static uint32_t tci_read_ri32(const tcg_target_ulong *regs, uint8_t **tb_ptr)#if TCG_TARGET_REG_BITS ==32 /* Read two indexed registers or constants (2 * 32 bit) from bytecode. */ -static uint64_t tci_read_ri64 (const tcg_target_ulong *regs,uint8_t **tb_ptr) +static uint64_t tci_read_ri64 (const tcg_target_ulong *regs, +const uint8_t **tb_ptr) {uint32_t low =tci_read_ri32 (regs, tb_ptr);return tci_uint64 (tci_read_ri32 (regs, tb_ptr), low); }#elif TCG_TARGET_REG_BITS ==64 /* Read indexed register or constant (64 bit) from bytecode. */ -static uint64_t tci_read_ri64 (const tcg_target_ulong *regs,uint8_t **tb_ptr) +static uint64_t tci_read_ri64 (const tcg_target_ulong *regs, +const uint8_t **tb_ptr) {uint64_t value;TCGReg r = **tb_ptr;
@@ -337,7 +346,7 @@ static uint64_t tci_read_ri64(const tcg_target_ulong *regs, uint8_t **tb_ptr) }#endif -static tcg_target_ulong tci_read_label (uint8_t **tb_ptr) +static tcg_target_ulong tci_read_label (const uint8_t **tb_ptr) {tcg_target_ulong label =tci_read_i (tb_ptr);tci_assert (label !=0 );
@@ -477,8 +486,7 @@ static bool tci_compare64(uint64_t u0, uint64_t u1, TCGCond condition)/* Interpret pseudo code in tb. */ uintptr_t tcg_qemu_tb_exec (CPUArchState *env,const void *v_tb_ptr) { -/* TODO: Propagate const through this file. */ -uint8_t *tb_ptr = (uint8_t *)v_tb_ptr; +const uint8_t *tb_ptr = v_tb_ptr;tcg_target_ulong regs[TCG_TARGET_NB_REGS ];long tcg_temps[CPU_TEMP_BUF_NLONGS ];uintptr_t sp_value = (uintptr_t )(tcg_temps +CPU_TEMP_BUF_NLONGS );
@@ -492,7 +500,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, const void *v_tb_ptr)TCGOpcode opc = tb_ptr[0 ];#if defined(CONFIG_DEBUG_TCG ) && !defined(NDEBUG )uint8_t op_size = tb_ptr[1 ]; -uint8_t *old_code_ptr = tb_ptr; +const uint8_t *old_code_ptr = tb_ptr;#endif tcg_target_ulong t0;tcg_target_ulong t1;
Signature · 1 line
2.25.1
Re: [PATCH v4 25/43] tcg/tci: Push const down through bytecode reading
Quoted 5 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- tcg/tci.c | 60 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 26 deletions(-)
PATCH v4 26/43 tcg: Introduce tcg_tbrel_diff
In reply to Richard Henderson--- include/tcg/tcg.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
include/tcg/tcg.h +13 -0
@@ -1141,6 +1141,19 @@ static inline ptrdiff_t tcg_pcrel_diff(TCGContext *s, const void *target)return tcg_ptr_byte_diff (target,tcg_splitwx_to_rx (s->code_ptr)); } +/** +* tcg_tbrel_diff +* @s: the tcg context +* @target: address of the target +* +* Produce a difference, from the beginning of the current TB code +* to the destination address. +*/ +static inline ptrdiff_t tcg_tbrel_diff (TCGContext *s,const void *target) +{ +return tcg_ptr_byte_diff (target,tcg_splitwx_to_rx (s->code_buf)); +} +/** * tcg_current_code_size * @s: the tcg context
Signature · 1 line
2.25.1
Re: [PATCH v4 26/43] tcg: Introduce tcg_tbrel_diff
Quoted 5 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- include/tcg/tcg.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
PATCH v4 27/43 tcg/ppc: Use tcg_tbrel_diff
In reply to Richard HendersonUse tcg_tbrel_diff when we need a displacement to a label, and with a NULL argument when we need the normalizing addend.
--- tcg/ppc/tcg-target.c.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tcg/ppc/tcg-target.c.inc +3 -3
@@ -837,7 +837,7 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, } /* Load addresses within the TB with one insn. */ - tb_diff = arg - (intptr_t)s->code_gen_ptr; + tb_diff = tcg_tbrel_diff(s, (void *)arg); if (!in_prologue && USE_REG_TB && tb_diff == (int16_t)tb_diff) { tcg_out32(s, ADDI | TAI(ret, TCG_REG_TB, tb_diff)); return;
@@ -890,7 +890,7 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, /* Use the constant pool, if possible. */ if (!in_prologue && USE_REG_TB) { new_pool_label(s, arg, R_PPC_ADDR16, s->code_ptr, - -(intptr_t)s->code_gen_ptr); + tcg_tbrel_diff(s, NULL)); tcg_out32(s, LD | TAI(ret, TCG_REG_TB, 0)); return; }
@@ -940,7 +940,7 @@ static void tcg_out_dupi_vec(TCGContext *s, TCGType type, TCGReg ret, */ if (USE_REG_TB) { rel = R_PPC_ADDR16; - add = -(intptr_t)s->code_gen_ptr; + add = tcg_tbrel_diff(s, NULL); } else { rel = R_PPC_ADDR32; add = 0;
Signature · 1 line
2.25.1
PATCH v4 28/43 tcg/ppc: Use tcg_out_mem_long to reset TCG_REG_TB
In reply to Richard HendersonThe maximum TB code gen size is UINT16_MAX, which the current code does not support. Use our utility function to optimally add an arbitrary constant.
--- tcg/ppc/tcg-target.c.inc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
tcg/ppc/tcg-target.c.inc +2 -3
@@ -2392,9 +2392,8 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, set_jmp_reset_offset(s, args[0]); if (USE_REG_TB) { /* For the unlinked case, need to reset TCG_REG_TB. */ - c = -tcg_current_code_size(s); - assert(c == (int16_t)c); - tcg_out32(s, ADDI | TAI(TCG_REG_TB, TCG_REG_TB, c)); + tcg_out_mem_long(s, ADDI, ADD, TCG_REG_TB, TCG_REG_TB, + -tcg_current_code_size(s)); } break; case INDEX_op_goto_ptr:
Signature · 1 line
2.25.1
PATCH v4 29/43 tcg/ppc: Support split-wx code generation
In reply to Richard Henderson--- tcg/ppc/tcg-target.h | 2 +- tcg/ppc/tcg-target.c.inc | 53 +++++++++++++++++++++++----------------- 2 files changed, 31 insertions(+), 24 deletions(-)
tcg/ppc/tcg-target.h +1 -1
@@ -184,6 +184,6 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);#define TCG_TARGET_NEED_LDST_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS -#define TCG_TARGET_SUPPORT_MIRROR 0 +#define TCG_TARGET_SUPPORT_MIRROR 1#endif
tcg/ppc/tcg-target.c.inc +30 -23
144 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v4 30/43 tcg/sparc: Use tcg_tbrel_diff
In reply to Richard Henderson--- tcg/sparc/tcg-target.c.inc | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
tcg/sparc/tcg-target.c.inc +7 -8
@@ -440,7 +440,7 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, /* A 13-bit constant relative to the TB. */ if (!in_prologue && USE_REG_TB) { - test = arg - (uintptr_t)s->code_gen_ptr; + test = tcg_tbrel_diff(s, (void *)arg); if (check_fit_ptr(test, 13)) { tcg_out_arithi(s, ret, TCG_REG_TB, test, ARITH_ADD); return;
@@ -537,15 +537,15 @@ static inline bool tcg_out_sti(TCGContext *s, TCGType type, TCGArg val, return false; } -static void tcg_out_ld_ptr(TCGContext *s, TCGReg ret, uintptr_t arg) +static void tcg_out_ld_ptr(TCGContext *s, TCGReg ret, const void *arg) { - intptr_t diff = arg - (uintptr_t)s->code_gen_ptr; + intptr_t diff = tcg_tbrel_diff(s, arg); if (USE_REG_TB && check_fit_ptr(diff, 13)) { tcg_out_ld(s, TCG_TYPE_PTR, ret, TCG_REG_TB, diff); return; } - tcg_out_movi(s, TCG_TYPE_PTR, ret, arg & ~0x3ff); - tcg_out_ld(s, TCG_TYPE_PTR, ret, ret, arg & 0x3ff); + tcg_out_movi(s, TCG_TYPE_PTR, ret, (uintptr_t)arg & ~0x3ff); + tcg_out_ld(s, TCG_TYPE_PTR, ret, ret, (uintptr_t)arg & 0x3ff); } static inline void tcg_out_sety(TCGContext *s, TCGReg rs)
@@ -1313,7 +1313,7 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, tcg_out_movi_imm13(s, TCG_REG_O0, a0); break; } else if (USE_REG_TB) { - intptr_t tb_diff = a0 - (uintptr_t)s->code_gen_ptr; + intptr_t tb_diff = tcg_tbrel_diff(s, (void *)a0); if (check_fit_ptr(tb_diff, 13)) { tcg_out_arithi(s, TCG_REG_G0, TCG_REG_I7, 8, RETURN); /* Note that TCG_REG_TB has been unwound to O1. */
@@ -1345,8 +1345,7 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, } } else { /* indirect jump method */ - tcg_out_ld_ptr(s, TCG_REG_TB, - (uintptr_t)(s->tb_jmp_target_addr + a0)); + tcg_out_ld_ptr(s, TCG_REG_TB, s->tb_jmp_target_addr + a0); tcg_out_arithi(s, TCG_REG_G0, TCG_REG_TB, 0, JMPL); tcg_out_nop(s); }
Signature · 1 line
2.25.1
PATCH v4 31/43 tcg/sparc: Support split-wx code generation
In reply to Richard Henderson--- tcg/sparc/tcg-target.h | 2 +- tcg/sparc/tcg-target.c.inc | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-)
tcg/sparc/tcg-target.h +1 -1
@@ -171,6 +171,6 @@ extern bool use_vis3_instructions;void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t ,uintptr_t );#define TCG_TARGET_NEED_POOL_LABELS -#define TCG_TARGET_SUPPORT_MIRROR 0 +#define TCG_TARGET_SUPPORT_MIRROR 1#endif
tcg/sparc/tcg-target.c.inc +13 -11
@@ -291,14 +291,15 @@ static inline int check_fit_i32(int32_t val, unsigned int bits) # define check_fit_ptr check_fit_i32 #endif -static bool patch_reloc(tcg_insn_unit *code_ptr, int type, +static bool patch_reloc(tcg_insn_unit *src_rw, int type, intptr_t value, intptr_t addend) { - uint32_t insn = *code_ptr; + const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw); + uint32_t insn = *src_rw; intptr_t pcrel; value += addend; - pcrel = tcg_ptr_byte_diff((tcg_insn_unit *)value, code_ptr); + pcrel = tcg_ptr_byte_diff((tcg_insn_unit *)value, src_rx); switch (type) { case R_SPARC_WDISP16:
@@ -315,7 +316,7 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type, g_assert_not_reached(); } - *code_ptr = insn; + *src_rw = insn; return true; }
@@ -868,8 +869,8 @@ static void tcg_out_mb(TCGContext *s, TCGArg a0) } #ifdef CONFIG_SOFTMMU -static tcg_insn_unit *qemu_ld_trampoline[16]; -static tcg_insn_unit *qemu_st_trampoline[16]; +static const tcg_insn_unit *qemu_ld_trampoline[16]; +static const tcg_insn_unit *qemu_st_trampoline[16]; static void emit_extend(TCGContext *s, TCGReg r, int op) {
@@ -930,7 +931,7 @@ static void build_trampolines(TCGContext *s) while ((uintptr_t)s->code_ptr & 15) { tcg_out_nop(s); } - qemu_ld_trampoline[i] = s->code_ptr; + qemu_ld_trampoline[i] = tcg_splitwx_to_rx(s->code_ptr); if (SPARC64 || TARGET_LONG_BITS == 32) { ra = TCG_REG_O3;
@@ -958,7 +959,7 @@ static void build_trampolines(TCGContext *s) while ((uintptr_t)s->code_ptr & 15) { tcg_out_nop(s); } - qemu_st_trampoline[i] = s->code_ptr; + qemu_st_trampoline[i] = tcg_splitwx_to_rx(s->code_ptr); if (SPARC64) { emit_extend(s, TCG_REG_O2, i);
@@ -1038,7 +1039,8 @@ static void tcg_target_qemu_prologue(TCGContext *s) tcg_out_nop(s); /* Epilogue for goto_ptr. */ - tcg_code_gen_epilogue = s->code_ptr; + /* TODO: Cast goes away when all hosts converted */ + tcg_code_gen_epilogue = (void *)tcg_splitwx_to_rx(s->code_ptr); tcg_out_arithi(s, TCG_REG_G0, TCG_REG_I7, 8, RETURN); /* delay slot */ tcg_out_movi_imm13(s, TCG_REG_O0, 0);
@@ -1163,7 +1165,7 @@ static void tcg_out_qemu_ld(TCGContext *s, TCGReg data, TCGReg addr, #ifdef CONFIG_SOFTMMU unsigned memi = get_mmuidx(oi); TCGReg addrz, param; - tcg_insn_unit *func; + const tcg_insn_unit *func; tcg_insn_unit *label_ptr; addrz = tcg_out_tlb_load(s, addr, memi, memop,
@@ -1245,7 +1247,7 @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg data, TCGReg addr, #ifdef CONFIG_SOFTMMU unsigned memi = get_mmuidx(oi); TCGReg addrz, param; - tcg_insn_unit *func; + const tcg_insn_unit *func; tcg_insn_unit *label_ptr; addrz = tcg_out_tlb_load(s, addr, memi, memop,
Signature · 1 line
2.25.1
PATCH v4 32/43 tcg/s390: Use tcg_tbrel_diff
In reply to Richard HendersonUse tcg_tbrel_diff when we need a displacement to a label, and with a NULL argument when we need the normalizing addend.
--- tcg/s390/tcg-target.c.inc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
tcg/s390/tcg-target.c.inc +8 -8
@@ -630,7 +630,7 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, return; } } else if (USE_REG_TB && !in_prologue) { - ptrdiff_t off = sval - (uintptr_t)s->code_gen_ptr; + ptrdiff_t off = tcg_tbrel_diff(s, (void *)sval); if (off == sextract64(off, 0, 20)) { /* This is certain to be an address within TB, and therefore OFF will be negative; don't try RX_LA. */
@@ -655,7 +655,7 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, } else if (USE_REG_TB && !in_prologue) { tcg_out_insn(s, RXY, LG, ret, TCG_REG_TB, TCG_REG_NONE, 0); new_pool_label(s, sval, R_390_20, s->code_ptr - 2, - -(intptr_t)s->code_gen_ptr); + tcg_tbrel_diff(s, NULL)); } else { TCGReg base = ret ? ret : TCG_TMP0; tcg_out_insn(s, RIL, LARL, base, 0);
@@ -746,7 +746,7 @@ static void tcg_out_ld_abs(TCGContext *s, TCGType type, TCGReg dest, void *abs) } } if (USE_REG_TB) { - ptrdiff_t disp = abs - (void *)s->code_gen_ptr; + ptrdiff_t disp = tcg_tbrel_diff(s, abs); if (disp == sextract64(disp, 0, 20)) { tcg_out_ld(s, type, dest, TCG_REG_TB, disp); return;
@@ -956,7 +956,7 @@ static void tgen_andi(TCGContext *s, TCGType type, TCGReg dest, uint64_t val) if (!maybe_out_small_movi(s, type, TCG_TMP0, val)) { tcg_out_insn(s, RXY, NG, dest, TCG_REG_TB, TCG_REG_NONE, 0); new_pool_label(s, val & valid, R_390_20, s->code_ptr - 2, - -(intptr_t)s->code_gen_ptr); + tcg_tbrel_diff(s, NULL)); return; } } else {
@@ -1015,7 +1015,7 @@ static void tgen_ori(TCGContext *s, TCGType type, TCGReg dest, uint64_t val) } else if (USE_REG_TB) { tcg_out_insn(s, RXY, OG, dest, TCG_REG_TB, TCG_REG_NONE, 0); new_pool_label(s, val, R_390_20, s->code_ptr - 2, - -(intptr_t)s->code_gen_ptr); + tcg_tbrel_diff(s, NULL)); } else { /* Perform the OR via sequential modifications to the high and low parts. Do this via recursion to handle 16-bit vs 32-bit
@@ -1050,7 +1050,7 @@ static void tgen_xori(TCGContext *s, TCGType type, TCGReg dest, uint64_t val) } else if (USE_REG_TB) { tcg_out_insn(s, RXY, XG, dest, TCG_REG_TB, TCG_REG_NONE, 0); new_pool_label(s, val, R_390_20, s->code_ptr - 2, - -(intptr_t)s->code_gen_ptr); + tcg_tbrel_diff(s, NULL)); } else { /* Perform the xor by parts. */ tcg_debug_assert(s390_facilities & FACILITY_EXT_IMM);
@@ -1108,12 +1108,12 @@ static int tgen_cmp(TCGContext *s, TCGType type, TCGCond c, TCGReg r1, op = (is_unsigned ? RXY_CLY : RXY_CY); tcg_out_insn_RXY(s, op, r1, TCG_REG_TB, TCG_REG_NONE, 0); new_pool_label(s, (uint32_t)c2, R_390_20, s->code_ptr - 2, - 4 - (intptr_t)s->code_gen_ptr); + 4 - tcg_tbrel_diff(s, NULL)); } else { op = (is_unsigned ? RXY_CLG : RXY_CG); tcg_out_insn_RXY(s, op, r1, TCG_REG_TB, TCG_REG_NONE, 0); new_pool_label(s, c2, R_390_20, s->code_ptr - 2, - -(intptr_t)s->code_gen_ptr); + tcg_tbrel_diff(s, NULL)); } goto exit; } else {
Signature · 1 line
2.25.1
PATCH v4 33/43 tcg/s390: Support split-wx code generation
In reply to Richard Henderson--- tcg/s390/tcg-target.h | 2 +- tcg/s390/tcg-target.c.inc | 69 +++++++++++++++++---------------------- 2 files changed, 31 insertions(+), 40 deletions(-)
tcg/s390/tcg-target.h +1 -1
@@ -158,6 +158,6 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx,#define TCG_TARGET_NEED_LDST_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS -#define TCG_TARGET_SUPPORT_MIRROR 0 +#define TCG_TARGET_SUPPORT_MIRROR 1#endif
tcg/s390/tcg-target.c.inc +30 -39
175 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v4 34/43 tcg/riscv: Fix branch range checks
In reply to Richard HendersonThe offset even checks were folded into the range check incorrectly. By offsetting by 1, and not decrementing the width, we silently allowed out of range branches.
Assert that the offset is always even instead. Move tcg_out_goto down into the CONFIG_SOFTMMU block so that it is not unused.
--- tcg/riscv/tcg-target.c.inc | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
tcg/riscv/tcg-target.c.inc +15 -13
@@ -429,7 +429,8 @@ static bool reloc_sbimm12(tcg_insn_unit *code_ptr, tcg_insn_unit *target) { intptr_t offset = (intptr_t)target - (intptr_t)code_ptr; - if (offset == sextreg(offset, 1, 12) << 1) { + tcg_debug_assert((offset & 1) == 0); + if (offset == sextreg(offset, 0, 12)) { code_ptr[0] |= encode_sbimm12(offset); return true; }
@@ -441,7 +442,8 @@ static bool reloc_jimm20(tcg_insn_unit *code_ptr, tcg_insn_unit *target) { intptr_t offset = (intptr_t)target - (intptr_t)code_ptr; - if (offset == sextreg(offset, 1, 20) << 1) { + tcg_debug_assert((offset & 1) == 0); + if (offset == sextreg(offset, 0, 20)) { code_ptr[0] |= encode_ujimm20(offset); return true; }
@@ -854,28 +856,21 @@ static void tcg_out_setcond2(TCGContext *s, TCGCond cond, TCGReg ret, g_assert_not_reached(); } -static inline void tcg_out_goto(TCGContext *s, tcg_insn_unit *target) -{ - ptrdiff_t offset = tcg_pcrel_diff(s, target); - tcg_debug_assert(offset == sextreg(offset, 1, 20) << 1); - tcg_out_opc_jump(s, OPC_JAL, TCG_REG_ZERO, offset); -} - static void tcg_out_call_int(TCGContext *s, const tcg_insn_unit *arg, bool tail) { TCGReg link = tail ? TCG_REG_ZERO : TCG_REG_RA; ptrdiff_t offset = tcg_pcrel_diff(s, arg); int ret; - if (offset == sextreg(offset, 1, 20) << 1) { + tcg_debug_assert((offset & 1) == 0); + if (offset == sextreg(offset, 0, 20)) { /* short jump: -2097150 to 2097152 */ tcg_out_opc_jump(s, OPC_JAL, link, offset); - } else if (TCG_TARGET_REG_BITS == 32 || - offset == sextreg(offset, 1, 31) << 1) { + } else if (TCG_TARGET_REG_BITS == 32 || offset == (int32_t)offset) { /* long jump: -2147483646 to 2147483648 */ tcg_out_opc_upper(s, OPC_AUIPC, TCG_REG_TMP0, 0); tcg_out_opc_imm(s, OPC_JALR, link, TCG_REG_TMP0, 0); - ret = reloc_call(s->code_ptr - 2, arg);\ + ret = reloc_call(s->code_ptr - 2, arg); tcg_debug_assert(ret == true); } else if (TCG_TARGET_REG_BITS == 64) { /* far jump: 64-bit */
@@ -962,6 +957,13 @@ QEMU_BUILD_BUG_ON(TCG_TARGET_REG_BITS < TARGET_LONG_BITS); QEMU_BUILD_BUG_ON(TLB_MASK_TABLE_OFS(0) > 0); QEMU_BUILD_BUG_ON(TLB_MASK_TABLE_OFS(0) < -(1 << 11)); +static void tcg_out_goto(TCGContext *s, tcg_insn_unit *target) +{ + tcg_out_opc_jump(s, OPC_JAL, TCG_REG_ZERO, 0); + bool ok = reloc_jimm20(s->code_ptr - 1, target); + tcg_debug_assert(ok); +} + static void tcg_out_tlb_load(TCGContext *s, TCGReg addrl, TCGReg addrh, TCGMemOpIdx oi, tcg_insn_unit **label_ptr, bool is_load)
Signature · 1 line
2.25.1
Re: [PATCH v4 34/43] tcg/riscv: Fix branch range checks
Quoted 9 lines · Richard Henderson
The offset even checks were folded into the range check incorrectly. By offsetting by 1, and not decrementing the width, we silently allowed out of range branches.
Assert that the offset is always even instead. Move
tcg_out_gotodown into theCONFIG_SOFTMMUblock so that it is not unused.Signed-off-by Richard Henderson <[email protected]>
Alistair
Quoted 79 lines
--- tcg/riscv/tcg-target.c.inc | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)tcg/riscv/tcg-target.c.inc +15
-14@@ -429,7 +429,8 @@ static bool reloc_sbimm12(tcg_insn_unit *code_ptr, tcg_insn_unit *target) { intptr_t offset = (intptr_t)target - (intptr_t)code_ptr; - if (offset == sextreg(offset, 1, 12) << 1) { + tcg_debug_assert((offset & 1) == 0); + if (offset == sextreg(offset, 0, 12)) { code_ptr[0] |= encode_sbimm12(offset); return true; }@@ -441,7 +442,8 @@ static bool reloc_jimm20(tcg_insn_unit *code_ptr, tcg_insn_unit *target) { intptr_t offset = (intptr_t)target - (intptr_t)code_ptr; - if (offset == sextreg(offset, 1, 20) << 1) { + tcg_debug_assert((offset & 1) == 0); + if (offset == sextreg(offset, 0, 20)) { code_ptr[0] |= encode_ujimm20(offset); return true; }@@ -854,28 +856,21 @@ static void tcg_out_setcond2(TCGContext *s, TCGCond cond, TCGReg ret, g_assert_not_reached(); } -static inline void tcg_out_goto(TCGContext *s, tcg_insn_unit *target) -{ - ptrdiff_t offset = tcg_pcrel_diff(s, target); - tcg_debug_assert(offset == sextreg(offset, 1, 20) << 1); - tcg_out_opc_jump(s, OPC_JAL, TCG_REG_ZERO, offset); -} - static void tcg_out_call_int(TCGContext *s, const tcg_insn_unit *arg, bool tail) { TCGReg link = tail ? TCG_REG_ZERO : TCG_REG_RA; ptrdiff_t offset = tcg_pcrel_diff(s, arg); int ret; - if (offset == sextreg(offset, 1, 20) << 1) { + tcg_debug_assert((offset & 1) == 0); + if (offset == sextreg(offset, 0, 20)) { /* short jump: -2097150 to 2097152 */ tcg_out_opc_jump(s, OPC_JAL, link, offset); - } else if (TCG_TARGET_REG_BITS == 32 || - offset == sextreg(offset, 1, 31) << 1) { + } else if (TCG_TARGET_REG_BITS == 32 || offset == (int32_t)offset) { /* long jump: -2147483646 to 2147483648 */ tcg_out_opc_upper(s, OPC_AUIPC, TCG_REG_TMP0, 0); tcg_out_opc_imm(s, OPC_JALR, link, TCG_REG_TMP0, 0); - ret = reloc_call(s->code_ptr - 2, arg);\ + ret = reloc_call(s->code_ptr - 2, arg); tcg_debug_assert(ret == true); } else if (TCG_TARGET_REG_BITS == 64) { /* far jump: 64-bit */@@ -962,6 +957,13 @@ QEMU_BUILD_BUG_ON(TCG_TARGET_REG_BITS < TARGET_LONG_BITS); QEMU_BUILD_BUG_ON(TLB_MASK_TABLE_OFS(0) > 0); QEMU_BUILD_BUG_ON(TLB_MASK_TABLE_OFS(0) < -(1 << 11)); +static void tcg_out_goto(TCGContext *s, tcg_insn_unit *target) +{ + tcg_out_opc_jump(s, OPC_JAL, TCG_REG_ZERO, 0); + bool ok = reloc_jimm20(s->code_ptr - 1, target); + tcg_debug_assert(ok); +} + static void tcg_out_tlb_load(TCGContext *s, TCGReg addrl, TCGReg addrh, TCGMemOpIdx oi, tcg_insn_unit **label_ptr, bool is_load) --2.25.1
PATCH v4 35/43 tcg/riscv: Remove branch-over-branch fallback
In reply to Richard HendersonSince 7ecd02a06f8, we are prepared to re-start code generation with a smaller TB if a relocation is out of range. We no longer need to leave a nop in the stream Just In Case.
--- tcg/riscv/tcg-target.c.inc | 56 ++++---------------------------------- 1 file changed, 6 insertions(+), 50 deletions(-)
tcg/riscv/tcg-target.c.inc +6 -50
@@ -469,43 +469,16 @@ static bool reloc_call(tcg_insn_unit *code_ptr, const tcg_insn_unit *target) static bool patch_reloc(tcg_insn_unit *code_ptr, int type, intptr_t value, intptr_t addend) { - uint32_t insn = *code_ptr; - intptr_t diff; - bool short_jmp; - tcg_debug_assert(addend == 0); - switch (type) { case R_RISCV_BRANCH: - diff = value - (uintptr_t)code_ptr; - short_jmp = diff == sextreg(diff, 0, 12); - if (short_jmp) { - return reloc_sbimm12(code_ptr, (tcg_insn_unit *)value); - } else { - /* Invert the condition */ - insn = insn ^ (1 << 12); - /* Clear the offset */ - insn &= 0x01fff07f; - /* Set the offset to the PC + 8 */ - insn |= encode_sbimm12(8); - - /* Move forward */ - code_ptr[0] = insn; - - /* Overwrite the NOP with jal x0,value */ - diff = value - (uintptr_t)(code_ptr + 1); - insn = encode_uj(OPC_JAL, TCG_REG_ZERO, diff); - code_ptr[1] = insn; - - return true; - } - break; + return reloc_sbimm12(code_ptr, (tcg_insn_unit *)value); case R_RISCV_JAL: return reloc_jimm20(code_ptr, (tcg_insn_unit *)value); case R_RISCV_CALL: return reloc_call(code_ptr, (tcg_insn_unit *)value); default: - tcg_abort(); + g_assert_not_reached(); } }
@@ -779,21 +752,8 @@ static void tcg_out_brcond(TCGContext *s, TCGCond cond, TCGReg arg1, arg2 = t; } - if (l->has_value) { - intptr_t diff = tcg_pcrel_diff(s, l->u.value_ptr); - if (diff == sextreg(diff, 0, 12)) { - tcg_out_opc_branch(s, op, arg1, arg2, diff); - } else { - /* Invert the conditional branch. */ - tcg_out_opc_branch(s, op ^ (1 << 12), arg1, arg2, 8); - tcg_out_opc_jump(s, OPC_JAL, TCG_REG_ZERO, diff - 4); - } - } else { - tcg_out_reloc(s, s->code_ptr, R_RISCV_BRANCH, l, 0); - tcg_out_opc_branch(s, op, arg1, arg2, 0); - /* NOP to allow patching later */ - tcg_out_opc_imm(s, OPC_ADDI, TCG_REG_ZERO, TCG_REG_ZERO, 0); - } + tcg_out_reloc(s, s->code_ptr, R_RISCV_BRANCH, l, 0); + tcg_out_opc_branch(s, op, arg1, arg2, 0); } static void tcg_out_setcond(TCGContext *s, TCGCond cond, TCGReg ret,
@@ -1009,8 +969,6 @@ static void tcg_out_tlb_load(TCGContext *s, TCGReg addrl, /* Compare masked address with the TLB entry. */ label_ptr[0] = s->code_ptr; tcg_out_opc_branch(s, OPC_BNE, TCG_REG_TMP0, TCG_REG_TMP1, 0); - /* NOP to allow patching later */ - tcg_out_opc_imm(s, OPC_ADDI, TCG_REG_ZERO, TCG_REG_ZERO, 0); /* TLB Hit - translate address using addend. */ if (TCG_TARGET_REG_BITS > TARGET_LONG_BITS) {
@@ -1054,8 +1012,7 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l) } /* resolve label address */ - if (!patch_reloc(l->label_ptr[0], R_RISCV_BRANCH, - (intptr_t) s->code_ptr, 0)) { + if (!reloc_sbimm12(l->label_ptr[0], s->code_ptr)) { return false; }
@@ -1089,8 +1046,7 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l) } /* resolve label address */ - if (!patch_reloc(l->label_ptr[0], R_RISCV_BRANCH, - (intptr_t) s->code_ptr, 0)) { + if (!reloc_sbimm12(l->label_ptr[0], s->code_ptr)) { return false; }
Signature · 1 line
2.25.1
Re: [PATCH v4 35/43] tcg/riscv: Remove branch-over-branch fallback
Quoted 6 lines · Richard Henderson
Since
7ecd02a06f8, we are prepared to re-start code generation with a smaller TB if a relocation is out of range. We no longer need to leave a nop in the stream Just In Case.Signed-off-by Richard Henderson <[email protected]>
Alistair
Quoted 111 lines
--- tcg/riscv/tcg-target.c.inc | 56 ++++---------------------------------- 1 file changed, 6 insertions(+), 50 deletions(-)tcg/riscv/tcg-target.c.inc +6
-51@@ -469,43 +469,16 @@ static bool reloc_call(tcg_insn_unit *code_ptr, const tcg_insn_unit *target) static bool patch_reloc(tcg_insn_unit *code_ptr, int type, intptr_t value, intptr_t addend) { - uint32_t insn = *code_ptr; - intptr_t diff; - bool short_jmp; - tcg_debug_assert(addend == 0); - switch (type) { case R_RISCV_BRANCH: - diff = value - (uintptr_t)code_ptr; - short_jmp = diff == sextreg(diff, 0, 12); - if (short_jmp) { - return reloc_sbimm12(code_ptr, (tcg_insn_unit *)value); - } else { - /* Invert the condition */ - insn = insn ^ (1 << 12); - /* Clear the offset */ - insn &= 0x01fff07f; - /* Set the offset to the PC + 8 */ - insn |= encode_sbimm12(8); - - /* Move forward */ - code_ptr[0] = insn; - - /* Overwrite the NOP with jal x0,value */ - diff = value - (uintptr_t)(code_ptr + 1); - insn = encode_uj(OPC_JAL, TCG_REG_ZERO, diff); - code_ptr[1] = insn; - - return true; - } - break; + return reloc_sbimm12(code_ptr, (tcg_insn_unit *)value); case R_RISCV_JAL: return reloc_jimm20(code_ptr, (tcg_insn_unit *)value); case R_RISCV_CALL: return reloc_call(code_ptr, (tcg_insn_unit *)value); default: - tcg_abort(); + g_assert_not_reached(); } }@@ -779,21 +752,8 @@ static void tcg_out_brcond(TCGContext *s, TCGCond cond, TCGReg arg1, arg2 = t; } - if (l->has_value) { - intptr_t diff = tcg_pcrel_diff(s, l->u.value_ptr); - if (diff == sextreg(diff, 0, 12)) { - tcg_out_opc_branch(s, op, arg1, arg2, diff); - } else { - /* Invert the conditional branch. */ - tcg_out_opc_branch(s, op ^ (1 << 12), arg1, arg2, 8); - tcg_out_opc_jump(s, OPC_JAL, TCG_REG_ZERO, diff - 4); - } - } else { - tcg_out_reloc(s, s->code_ptr, R_RISCV_BRANCH, l, 0); - tcg_out_opc_branch(s, op, arg1, arg2, 0); - /* NOP to allow patching later */ - tcg_out_opc_imm(s, OPC_ADDI, TCG_REG_ZERO, TCG_REG_ZERO, 0); - } + tcg_out_reloc(s, s->code_ptr, R_RISCV_BRANCH, l, 0); + tcg_out_opc_branch(s, op, arg1, arg2, 0); } static void tcg_out_setcond(TCGContext *s, TCGCond cond, TCGReg ret,@@ -1009,8 +969,6 @@ static void tcg_out_tlb_load(TCGContext *s, TCGReg addrl, /* Compare masked address with the TLB entry. */ label_ptr[0] = s->code_ptr; tcg_out_opc_branch(s, OPC_BNE, TCG_REG_TMP0, TCG_REG_TMP1, 0); - /* NOP to allow patching later */ - tcg_out_opc_imm(s, OPC_ADDI, TCG_REG_ZERO, TCG_REG_ZERO, 0); /* TLB Hit - translate address using addend. */ if (TCG_TARGET_REG_BITS > TARGET_LONG_BITS) {@@ -1054,8 +1012,7 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l) } /* resolve label address */ - if (!patch_reloc(l->label_ptr[0], R_RISCV_BRANCH, - (intptr_t) s->code_ptr, 0)) { + if (!reloc_sbimm12(l->label_ptr[0], s->code_ptr)) { return false; }@@ -1089,8 +1046,7 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l) } /* resolve label address */ - if (!patch_reloc(l->label_ptr[0], R_RISCV_BRANCH, - (intptr_t) s->code_ptr, 0)) { + if (!reloc_sbimm12(l->label_ptr[0], s->code_ptr)) { return false; } --2.25.1
PATCH v4 36/43 tcg/riscv: Support split-wx code generation
In reply to Richard Henderson--- tcg/riscv/tcg-target.h | 2 +- tcg/riscv/tcg-target.c.inc | 41 +++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 19 deletions(-)
tcg/riscv/tcg-target.h +1 -1
@@ -170,6 +170,6 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);#define TCG_TARGET_NEED_POOL_LABELS #define TCG_TARGET_HAS_MEMORY_BSWAP 0 -#define TCG_TARGET_SUPPORT_MIRROR 0 +#define TCG_TARGET_SUPPORT_MIRROR 1#endif
tcg/riscv/tcg-target.c.inc +23 -18
117 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v4 36/43] tcg/riscv: Support split-wx code generation
Quoted 2 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>
Alistair
Quoted 150 lines
--- tcg/riscv/tcg-target.h | 2 +- tcg/riscv/tcg-target.c.inc | 41 +++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 19 deletions(-)tcg/riscv/tcg-target.h +1
-1@@ -170,6 +170,6 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);#define TCG_TARGET_NEED_POOL_LABELS #define TCG_TARGET_HAS_MEMORY_BSWAP 0 -#define TCG_TARGET_SUPPORT_MIRROR 0 +#define TCG_TARGET_SUPPORT_MIRROR 1#endif tcg/riscv/tcg-target.c.inc +23
-19@@ -425,41 +425,44 @@ static void tcg_out_nop_fill(tcg_insn_unit *p, int count) * Relocations */ -static bool reloc_sbimm12(tcg_insn_unit *code_ptr, tcg_insn_unit *target) +static bool reloc_sbimm12(tcg_insn_unit *src_rw, const tcg_insn_unit *target) { - intptr_t offset = (intptr_t)target - (intptr_t)code_ptr; + const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw); + intptr_t offset = (intptr_t)target - (intptr_t)src_rx; tcg_debug_assert((offset & 1) == 0); if (offset == sextreg(offset, 0, 12)) { - code_ptr[0] |= encode_sbimm12(offset); + *src_rw |= encode_sbimm12(offset); return true; } return false; } -static bool reloc_jimm20(tcg_insn_unit *code_ptr, tcg_insn_unit *target) +static bool reloc_jimm20(tcg_insn_unit *src_rw, const tcg_insn_unit *target) { - intptr_t offset = (intptr_t)target - (intptr_t)code_ptr; + const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw); + intptr_t offset = (intptr_t)target - (intptr_t)src_rx; tcg_debug_assert((offset & 1) == 0); if (offset == sextreg(offset, 0, 20)) { - code_ptr[0] |= encode_ujimm20(offset); + *src_rw |= encode_ujimm20(offset); return true; } return false; } -static bool reloc_call(tcg_insn_unit *code_ptr, const tcg_insn_unit *target) +static bool reloc_call(tcg_insn_unit *src_rw, const tcg_insn_unit *target) { - intptr_t offset = (intptr_t)target - (intptr_t)code_ptr; + const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw); + intptr_t offset = (intptr_t)target - (intptr_t)src_rx; int32_t lo = sextreg(offset, 0, 12); int32_t hi = offset - lo; if (offset == hi + lo) { - code_ptr[0] |= encode_uimm20(hi); - code_ptr[1] |= encode_imm12(lo); + src_rw[0] |= encode_uimm20(hi); + src_rw[1] |= encode_imm12(lo); return true; }@@ -532,7 +535,7 @@ static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg rd, if (tmp == (int32_t)tmp) { tcg_out_opc_upper(s, OPC_AUIPC, rd, 0); tcg_out_opc_imm(s, OPC_ADDI, rd, rd, 0); - ret = reloc_call(s->code_ptr - 2, (tcg_insn_unit *)val); + ret = reloc_call(s->code_ptr - 2, (const tcg_insn_unit *)val); tcg_debug_assert(ret == true); return; }@@ -917,7 +920,7 @@ QEMU_BUILD_BUG_ON(TCG_TARGET_REG_BITS < TARGET_LONG_BITS); QEMU_BUILD_BUG_ON(TLB_MASK_TABLE_OFS(0) > 0); QEMU_BUILD_BUG_ON(TLB_MASK_TABLE_OFS(0) < -(1 << 11)); -static void tcg_out_goto(TCGContext *s, tcg_insn_unit *target) +static void tcg_out_goto(TCGContext *s, const tcg_insn_unit *target) { tcg_out_opc_jump(s, OPC_JAL, TCG_REG_ZERO, 0); bool ok = reloc_jimm20(s->code_ptr - 1, target);@@ -993,7 +996,8 @@ static void add_qemu_ldst_label(TCGContext *s, int is_ld, TCGMemOpIdx oi, label->datahi_reg = datahi; label->addrlo_reg = addrlo; label->addrhi_reg = addrhi; - label->raddr = raddr; + /* TODO: Cast goes away when all hosts converted */ + label->raddr = (void *)tcg_splitwx_to_rx(raddr); label->label_ptr[0] = label_ptr[0]; }@@ -1012,7 +1016,7 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l) } /* resolve label address */ - if (!reloc_sbimm12(l->label_ptr[0], s->code_ptr)) { + if (!reloc_sbimm12(l->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) { return false; }@@ -1046,7 +1050,7 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l) } /* resolve label address */ - if (!reloc_sbimm12(l->label_ptr[0], s->code_ptr)) { + if (!reloc_sbimm12(l->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) { return false; }@@ -1232,7 +1236,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64) #endif } -static tcg_insn_unit *tb_ret_addr; +static const tcg_insn_unit *tb_ret_addr; static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, const int *const_args)@@ -1780,11 +1784,12 @@ static void tcg_target_qemu_prologue(TCGContext *s) tcg_out_opc_imm(s, OPC_JALR, TCG_REG_ZERO, tcg_target_call_iarg_regs[1], 0); /* Return path for goto_ptr. Set return value to 0 */ - tcg_code_gen_epilogue = s->code_ptr; + /* TODO: Cast goes away when all hosts converted */ + tcg_code_gen_epilogue = (void *)tcg_splitwx_to_rx(s->code_ptr); tcg_out_mov(s, TCG_TYPE_REG, TCG_REG_A0, TCG_REG_ZERO); /* TB epilogue */ - tb_ret_addr = s->code_ptr; + tb_ret_addr = tcg_splitwx_to_rx(s->code_ptr); for (i = 0; i < ARRAY_SIZE(tcg_target_callee_save_regs); i++) { tcg_out_ld(s, TCG_TYPE_REG, tcg_target_callee_save_regs[i], TCG_REG_SP, SAVE_OFS + i * REG_SIZE); --2.25.1
PATCH v4 37/43 accel/tcg: Add mips support to alloc_code_gen_buffer_splitwx_memfd
In reply to Richard HendersonRe-use the 256MiB region handling from alloc_code_gen_buffer_anon, and replace that with the shared file mapping.
--- accel/tcg/translate-all.c | 46 ++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 8 deletions(-)
accel/tcg/translate-all.c +38 -8
@@ -1137,24 +1137,40 @@ static bool alloc_code_gen_buffer_anon(size_t size, int prot,static bool alloc_code_gen_buffer_splitwx_memfd (size_t size,Error **errp) { -void *buf_rw, *buf_rx; +void *buf_rw =NULL , *buf_rx =MAP_FAILED ;int fd =-1 ; +#ifdef __mips__ +/* Find space for the RX mapping, vs the 256MiB regions. */ +if (!alloc_code_gen_buffer_anon (size,PROT_NONE , +MAP_PRIVATE |MAP_ANONYMOUS | +MAP_NORESERVE , errp)) { +return false; + } +/* The size of the mapping may have been adjusted. */ + size = tcg_ctx->code_gen_buffer_size; + buf_rx = tcg_ctx->code_gen_buffer; +#endif + buf_rw =qemu_memfd_alloc ("tcg-jit" , size,0 , &fd, errp);if (buf_rw ==NULL ) { -return false; + goto fail; } +#ifdef __mips__ +void *tmp =mmap (buf_rx, size,PROT_READ |PROT_EXEC , +MAP_SHARED |MAP_FIXED , fd,0 ); +if (tmp != buf_rx) { + goto fail_rx; + } +#else buf_rx =mmap (NULL , size,PROT_READ |PROT_EXEC ,MAP_SHARED , fd,0 );if (buf_rx ==MAP_FAILED ) { -error_setg_errno (errp, errno, -"failed to map shared memory for execute" ); -munmap (buf_rw, size); -close (fd); -return false; + goto fail_rx; } -close (fd); +#endif +close (fd); tcg_ctx->code_gen_buffer = buf_rw; tcg_ctx->code_gen_buffer_size = size; tcg_splitwx_diff = buf_rx - buf_rw;
@@ -1163,6 +1179,20 @@ static bool alloc_code_gen_buffer_splitwx_memfd(size_t size, Error **errp)qemu_madvise (buf_rw, size,QEMU_MADV_HUGEPAGE );qemu_madvise (buf_rx, size,QEMU_MADV_HUGEPAGE );return true; + + fail_rx: +error_setg_errno (errp, errno,"failed to map shared memory for execute" ); + fail: +if (buf_rx !=MAP_FAILED ) { +munmap (buf_rx, size); + } +if (buf_rw) { +munmap (buf_rw, size); + } +if (fd >=0 ) { +close (fd); + } + return false; }#endif /* CONFIG_POSIX */
Signature · 1 line
2.25.1
PATCH v4 38/43 tcg/mips: Do not assert on relocation overflow
In reply to Richard HendersonThis target was not updated with 7ecd02a06f8, and so did not allow re-compilation with relocation overflow.
Remove reloc_26 and reloc_26_val as unused.
--- tcg/mips/tcg-target.c.inc | 53 ++++++++++++++------------------------- 1 file changed, 19 insertions(+), 34 deletions(-)
tcg/mips/tcg-target.c.inc +19 -34
@@ -144,29 +144,15 @@ static tcg_insn_unit *bswap32_addr; static tcg_insn_unit *bswap32u_addr; static tcg_insn_unit *bswap64_addr; -static inline uint32_t reloc_pc16_val(tcg_insn_unit *pc, - const tcg_insn_unit *target) +static bool reloc_pc16(tcg_insn_unit *pc, const tcg_insn_unit *target) { /* Let the compiler perform the right-shift as part of the arithmetic. */ ptrdiff_t disp = target - (pc + 1); - tcg_debug_assert(disp == (int16_t)disp); - return disp & 0xffff; -} - -static inline void reloc_pc16(tcg_insn_unit *pc, const tcg_insn_unit *target) -{ - *pc = deposit32(*pc, 0, 16, reloc_pc16_val(pc, target)); -} - -static inline uint32_t reloc_26_val(tcg_insn_unit *pc, tcg_insn_unit *target) -{ - tcg_debug_assert((((uintptr_t)pc ^ (uintptr_t)target) & 0xf0000000) == 0); - return ((uintptr_t)target >> 2) & 0x3ffffff; -} - -static inline void reloc_26(tcg_insn_unit *pc, tcg_insn_unit *target) -{ - *pc = deposit32(*pc, 0, 26, reloc_26_val(pc, target)); + if (disp == (int16_t)disp) { + *pc = deposit32(*pc, 0, 16, disp); + return true; + } + return false; } static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
@@ -174,8 +160,7 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type, { tcg_debug_assert(type == R_MIPS_PC16); tcg_debug_assert(addend == 0); - reloc_pc16(code_ptr, (tcg_insn_unit *)value); - return true; + return reloc_pc16(code_ptr, (const tcg_insn_unit *)value); } #define TCG_CT_CONST_ZERO 0x100
@@ -925,11 +910,7 @@ static void tcg_out_brcond(TCGContext *s, TCGCond cond, TCGReg arg1, } tcg_out_opc_br(s, b_opc, arg1, arg2); - if (l->has_value) { - reloc_pc16(s->code_ptr - 1, l->u.value_ptr); - } else { - tcg_out_reloc(s, s->code_ptr - 1, R_MIPS_PC16, l, 0); - } + tcg_out_reloc(s, s->code_ptr - 1, R_MIPS_PC16, l, 0); tcg_out_nop(s); }
@@ -1316,9 +1297,10 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l) int i; /* resolve label address */ - reloc_pc16(l->label_ptr[0], s->code_ptr); - if (TCG_TARGET_REG_BITS < TARGET_LONG_BITS) { - reloc_pc16(l->label_ptr[1], s->code_ptr); + if (!reloc_pc16(l->label_ptr[0], s->code_ptr) + || (TCG_TARGET_REG_BITS < TARGET_LONG_BITS + && !reloc_pc16(l->label_ptr[1], s->code_ptr))) { + return false; } i = 1;
@@ -1346,7 +1328,9 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l) } tcg_out_opc_br(s, OPC_BEQ, TCG_REG_ZERO, TCG_REG_ZERO); - reloc_pc16(s->code_ptr - 1, l->raddr); + if (!reloc_pc16(s->code_ptr - 1, l->raddr)) { + return false; + } /* delay slot */ if (TCG_TARGET_REG_BITS == 64 && l->type == TCG_TYPE_I32) {
@@ -1366,9 +1350,10 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l) int i; /* resolve label address */ - reloc_pc16(l->label_ptr[0], s->code_ptr); - if (TCG_TARGET_REG_BITS < TARGET_LONG_BITS) { - reloc_pc16(l->label_ptr[1], s->code_ptr); + if (!reloc_pc16(l->label_ptr[0], s->code_ptr) + || (TCG_TARGET_REG_BITS < TARGET_LONG_BITS + && !reloc_pc16(l->label_ptr[1], s->code_ptr))) { + return false; } i = 1;
Signature · 1 line
2.25.1
PATCH v4 39/43 tcg/mips: Support split-wx code generation
In reply to Richard Henderson--- tcg/mips/tcg-target.h | 2 +- tcg/mips/tcg-target.c.inc | 43 ++++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 20 deletions(-)
tcg/mips/tcg-target.h +1 -1
@@ -200,7 +200,7 @@ extern bool use_mips32r2_instructions;#define TCG_TARGET_DEFAULT_MO (0)#define TCG_TARGET_HAS_MEMORY_BSWAP 1 -#define TCG_TARGET_SUPPORT_MIRROR 0 +#define TCG_TARGET_SUPPORT_MIRROR 1void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t ,uintptr_t );
tcg/mips/tcg-target.c.inc +24 -19
124 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v4 40/43 tcg/arm: Support split-wx code generation
In reply to Richard Henderson--- tcg/arm/tcg-target.h | 2 +- tcg/arm/tcg-target.c.inc | 37 +++++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 17 deletions(-)
tcg/arm/tcg-target.h +1 -1
@@ -141,6 +141,6 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);#define TCG_TARGET_NEED_LDST_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS -#define TCG_TARGET_SUPPORT_MIRROR 0 +#define TCG_TARGET_SUPPORT_MIRROR 1#endif
tcg/arm/tcg-target.c.inc +21 -16
@@ -187,29 +187,32 @@ static const uint8_t tcg_cond_to_arm_cond[] = { [TCG_COND_GTU] = COND_HI, }; -static inline bool reloc_pc24(tcg_insn_unit *code_ptr, tcg_insn_unit *target) +static bool reloc_pc24(tcg_insn_unit *src_rw, const tcg_insn_unit *target) { - ptrdiff_t offset = (tcg_ptr_byte_diff(target, code_ptr) - 8) >> 2; + const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw); + ptrdiff_t offset = (tcg_ptr_byte_diff(target, src_rx) - 8) >> 2; + if (offset == sextract32(offset, 0, 24)) { - *code_ptr = (*code_ptr & ~0xffffff) | (offset & 0xffffff); + *src_rw = deposit32(*src_rw, 0, 24, offset); return true; } return false; } -static inline bool reloc_pc13(tcg_insn_unit *code_ptr, tcg_insn_unit *target) +static bool reloc_pc13(tcg_insn_unit *src_rw, const tcg_insn_unit *target) { - ptrdiff_t offset = tcg_ptr_byte_diff(target, code_ptr) - 8; + const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw); + ptrdiff_t offset = tcg_ptr_byte_diff(target, src_rx) - 8; if (offset >= -0xfff && offset <= 0xfff) { - tcg_insn_unit insn = *code_ptr; + tcg_insn_unit insn = *src_rw; bool u = (offset >= 0); if (!u) { offset = -offset; } insn = deposit32(insn, 23, 1, u); insn = deposit32(insn, 0, 12, offset); - *code_ptr = insn; + *src_rw = insn; return true; } return false;
@@ -221,9 +224,9 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type, tcg_debug_assert(addend == 0); if (type == R_ARM_PC24) { - return reloc_pc24(code_ptr, (tcg_insn_unit *)value); + return reloc_pc24(code_ptr, (const tcg_insn_unit *)value); } else if (type == R_ARM_PC13) { - return reloc_pc13(code_ptr, (tcg_insn_unit *)value); + return reloc_pc13(code_ptr, (const tcg_insn_unit *)value); } else { g_assert_not_reached(); }
@@ -617,7 +620,7 @@ static void tcg_out_movi32(TCGContext *s, int cond, int rd, uint32_t arg) /* Check for a pc-relative address. This will usually be the TB, or within the TB, which is immediately before the code block. */ - diff = arg - ((intptr_t)s->code_ptr + 8); + diff = tcg_pcrel_diff(s, (void *)arg) - 8; if (diff >= 0) { rot = encode_imm(diff); if (rot >= 0) {
@@ -1337,7 +1340,8 @@ static void add_qemu_ldst_label(TCGContext *s, bool is_ld, TCGMemOpIdx oi, label->datahi_reg = datahi; label->addrlo_reg = addrlo; label->addrhi_reg = addrhi; - label->raddr = raddr; + /* TODO: Cast goes away when all hosts converted */ + label->raddr = (void *)tcg_splitwx_to_rx(raddr); label->label_ptr[0] = label_ptr; }
@@ -1348,7 +1352,7 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *lb) MemOp opc = get_memop(oi); void *func; - if (!reloc_pc24(lb->label_ptr[0], s->code_ptr)) { + if (!reloc_pc24(lb->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) { return false; }
@@ -1411,7 +1415,7 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb) TCGMemOpIdx oi = lb->oi; MemOp opc = get_memop(oi); - if (!reloc_pc24(lb->label_ptr[0], s->code_ptr)) { + if (!reloc_pc24(lb->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) { return false; }
@@ -1762,8 +1766,8 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, TCGReg base = TCG_REG_PC; tcg_debug_assert(s->tb_jmp_insn_offset == 0); - ptr = (intptr_t)(s->tb_jmp_target_addr + args[0]); - dif = ptr - ((intptr_t)s->code_ptr + 8); + ptr = (intptr_t)tcg_splitwx_to_rx(s->tb_jmp_target_addr + args[0]); + dif = tcg_pcrel_diff(s, (void *)ptr) - 8; dil = sextract32(dif, 0, 12); if (dif != dil) { /* The TB is close, but outside the 12 bits addressable by
@@ -2297,7 +2301,8 @@ static void tcg_target_qemu_prologue(TCGContext *s) * Return path for goto_ptr. Set return value to 0, a-la exit_tb, * and fall through to the rest of the epilogue. */ - tcg_code_gen_epilogue = s->code_ptr; + /* TODO: Cast goes away when all hosts converted */ + tcg_code_gen_epilogue = (void *)tcg_splitwx_to_rx(s->code_ptr); tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R0, 0); tcg_out_epilogue(s); }
Signature · 1 line
2.25.1
PATCH v4 41/43 tcg: Remove TCG_TARGET_SUPPORT_MIRROR
In reply to Richard HendersonNow that all native tcg hosts support splitwx, remove the define. Replace the one use with a test for CONFIG_TCG_INTERPRETER.
--- tcg/aarch64/tcg-target.h | 1 - tcg/arm/tcg-target.h | 1 - tcg/i386/tcg-target.h | 1 - tcg/mips/tcg-target.h | 1 - tcg/ppc/tcg-target.h | 1 - tcg/riscv/tcg-target.h | 1 - tcg/s390/tcg-target.h | 1 - tcg/sparc/tcg-target.h | 1 - tcg/tci/tcg-target.h | 1 - accel/tcg/translate-all.c | 16 +++++++++------- 10 files changed, 9 insertions(+), 16 deletions(-)
tcg/aarch64/tcg-target.h +0 -1
@@ -154,6 +154,5 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);#define TCG_TARGET_NEED_LDST_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS -#define TCG_TARGET_SUPPORT_MIRROR 1#endif /* AARCH64_TCG_TARGET_H */
tcg/arm/tcg-target.h +0 -1
@@ -141,6 +141,5 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);#define TCG_TARGET_NEED_LDST_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS -#define TCG_TARGET_SUPPORT_MIRROR 1#endif
tcg/i386/tcg-target.h +0 -1
@@ -231,6 +231,5 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx,#define TCG_TARGET_NEED_LDST_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS -#define TCG_TARGET_SUPPORT_MIRROR 1#endif
tcg/mips/tcg-target.h +0 -1
@@ -200,7 +200,6 @@ extern bool use_mips32r2_instructions;#define TCG_TARGET_DEFAULT_MO (0)#define TCG_TARGET_HAS_MEMORY_BSWAP 1 -#define TCG_TARGET_SUPPORT_MIRROR 1void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t ,uintptr_t );
tcg/ppc/tcg-target.h +0 -1
@@ -184,6 +184,5 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);#define TCG_TARGET_NEED_LDST_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS -#define TCG_TARGET_SUPPORT_MIRROR 1#endif
tcg/riscv/tcg-target.h +0 -1
@@ -170,6 +170,5 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);#define TCG_TARGET_NEED_POOL_LABELS #define TCG_TARGET_HAS_MEMORY_BSWAP 0 -#define TCG_TARGET_SUPPORT_MIRROR 1#endif
tcg/s390/tcg-target.h +0 -1
@@ -158,6 +158,5 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx,#define TCG_TARGET_NEED_LDST_LABELS #endif #define TCG_TARGET_NEED_POOL_LABELS -#define TCG_TARGET_SUPPORT_MIRROR 1#endif
tcg/sparc/tcg-target.h +0 -1
@@ -171,6 +171,5 @@ extern bool use_vis3_instructions;void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t ,uintptr_t );#define TCG_TARGET_NEED_POOL_LABELS -#define TCG_TARGET_SUPPORT_MIRROR 1#endif
tcg/tci/tcg-target.h +0 -1
@@ -197,7 +197,6 @@ void tci_disas(uint8_t opc);#define TCG_TARGET_DEFAULT_MO (0)#define TCG_TARGET_HAS_MEMORY_BSWAP 1 -#define TCG_TARGET_SUPPORT_MIRROR 0static inline void tb_target_set_jmp_target (uintptr_t tc_ptr,uintptr_t jmp_rx,uintptr_t jmp_rw,uintptr_t addr)
accel/tcg/translate-all.c +9 -7
@@ -1132,6 +1132,7 @@ static bool alloc_code_gen_buffer_anon(size_t size, int prot,return true; } +#ifndef CONFIG_TCG_INTERPRETER #ifdef CONFIG_POSIX #include "qemu/memfd.h"
@@ -1254,17 +1255,18 @@ static bool alloc_code_gen_buffer_splitwx_vmremap(size_t size, Error **errp)return true; }#endif /* CONFIG_DARWIN */ +#endif /* CONFIG_TCG_INTERPRETER */ static bool alloc_code_gen_buffer_splitwx (size_t size,Error **errp) { -if (TCG_TARGET_SUPPORT_MIRROR ) { -#ifdef CONFIG_DARWIN -return alloc_code_gen_buffer_splitwx_vmremap (size, errp); +#ifndef CONFIG_TCG_INTERPRETER +# ifdef CONFIG_DARWIN +return alloc_code_gen_buffer_splitwx_vmremap (size, errp); +# endif +# ifdef CONFIG_POSIX +return alloc_code_gen_buffer_splitwx_memfd (size, errp); +# endif #endif -#ifdef CONFIG_POSIX -return alloc_code_gen_buffer_splitwx_memfd (size, errp); -#endif - }error_setg (errp,"jit split-wx not supported" );return false; }
Signature · 1 line
2.25.1
Re: [PATCH v4 41/43] tcg: Remove TCG_TARGET_SUPPORT_MIRROR
Quoted 5 lines · Richard Henderson
Now that all native tcg hosts support splitwx, remove the define. Replace the one use with a test for
CONFIG_TCG_INTERPRETER.Signed-off-by Richard Henderson <[email protected]>
Quoted 12 lines
--- tcg/aarch64/tcg-target.h | 1 - tcg/arm/tcg-target.h | 1 - tcg/i386/tcg-target.h | 1 - tcg/mips/tcg-target.h | 1 - tcg/ppc/tcg-target.h | 1 - tcg/riscv/tcg-target.h | 1 - tcg/s390/tcg-target.h | 1 - tcg/sparc/tcg-target.h | 1 - tcg/tci/tcg-target.h | 1 - accel/tcg/translate-all.c | 16 +++++++++------- 10 files changed, 9 insertions(+), 16 deletions(-)
PATCH v4 42/43 tcg: Constify tcg_code_gen_epilogue
In reply to Richard HendersonNow that all native tcg hosts support splitwx,
make this pointer const.
--- include/tcg/tcg.h | 2 +- tcg/tcg.c | 2 +- tcg/aarch64/tcg-target.c.inc | 3 +-- tcg/arm/tcg-target.c.inc | 3 +-- tcg/i386/tcg-target.c.inc | 3 +-- tcg/mips/tcg-target.c.inc | 3 +-- tcg/ppc/tcg-target.c.inc | 3 +-- tcg/riscv/tcg-target.c.inc | 3 +-- tcg/s390/tcg-target.c.inc | 3 +-- tcg/sparc/tcg-target.c.inc | 3 +-- 10 files changed, 10 insertions(+), 18 deletions(-)
include/tcg/tcg.h +1 -1
@@ -677,7 +677,7 @@ struct TCGContext {extern TCGContext tcg_init_ctx;extern __threadTCGContext *tcg_ctx; -extern void *tcg_code_gen_epilogue; +extern const void *tcg_code_gen_epilogue;extern uintptr_t tcg_splitwx_diff;extern TCGv_env cpu_env;
tcg/tcg.c +1 -1
@@ -161,7 +161,7 @@ static int tcg_out_ldst_finalize(TCGContext *s);static TCGContext **tcg_ctxs;static unsigned int n_tcg_ctxs;TCGv_env cpu_env =0 ; -void *tcg_code_gen_epilogue; +const void *tcg_code_gen_epilogue;uintptr_t tcg_splitwx_diff;#ifndef CONFIG_TCG_INTERPRETER
tcg/aarch64/tcg-target.c.inc +1 -2
@@ -2900,8 +2900,7 @@ static void tcg_target_qemu_prologue(TCGContext *s) * Return path for goto_ptr. Set return value to 0, a-la exit_tb, * and fall through to the rest of the epilogue. */ - /* TODO: Cast goes away when all hosts converted */ - tcg_code_gen_epilogue = (void *)tcg_splitwx_to_rx(s->code_ptr); + tcg_code_gen_epilogue = tcg_splitwx_to_rx(s->code_ptr); tcg_out_movi(s, TCG_TYPE_REG, TCG_REG_X0, 0); /* TB epilogue */
tcg/arm/tcg-target.c.inc +1 -2
@@ -2301,8 +2301,7 @@ static void tcg_target_qemu_prologue(TCGContext *s) * Return path for goto_ptr. Set return value to 0, a-la exit_tb, * and fall through to the rest of the epilogue. */ - /* TODO: Cast goes away when all hosts converted */ - tcg_code_gen_epilogue = (void *)tcg_splitwx_to_rx(s->code_ptr); + tcg_code_gen_epilogue = tcg_splitwx_to_rx(s->code_ptr); tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R0, 0); tcg_out_epilogue(s); }
tcg/i386/tcg-target.c.inc +1 -2
@@ -3826,8 +3826,7 @@ static void tcg_target_qemu_prologue(TCGContext *s) * Return path for goto_ptr. Set return value to 0, a-la exit_tb, * and fall through to the rest of the epilogue. */ - /* TODO: Cast goes away when all hosts converted */ - tcg_code_gen_epilogue = (void *)tcg_splitwx_to_rx(s->code_ptr); + tcg_code_gen_epilogue = tcg_splitwx_to_rx(s->code_ptr); tcg_out_movi(s, TCG_TYPE_REG, TCG_REG_EAX, 0); /* TB epilogue */
tcg/mips/tcg-target.c.inc +1 -2
@@ -2473,8 +2473,7 @@ static void tcg_target_qemu_prologue(TCGContext *s) * Return path for goto_ptr. Set return value to 0, a-la exit_tb, * and fall through to the rest of the epilogue. */ - /* TODO: Cast goes away when all hosts converted */ - tcg_code_gen_epilogue = (void *)tcg_splitwx_to_rx(s->code_ptr); + tcg_code_gen_epilogue = tcg_splitwx_to_rx(s->code_ptr); tcg_out_mov(s, TCG_TYPE_REG, TCG_REG_V0, TCG_REG_ZERO); /* TB epilogue */
tcg/ppc/tcg-target.c.inc +1 -2
@@ -2346,8 +2346,7 @@ static void tcg_target_qemu_prologue(TCGContext *s) tcg_out32(s, BCCTR | BO_ALWAYS); /* Epilogue */ - /* TODO: Cast goes away when all hosts converted */ - tcg_code_gen_epilogue = (void *)tcg_splitwx_to_rx(s->code_ptr); + tcg_code_gen_epilogue = tcg_splitwx_to_rx(s->code_ptr); tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_R0, TCG_REG_R1, FRAME_SIZE+LR_OFFSET); for (i = 0; i < ARRAY_SIZE(tcg_target_callee_save_regs); ++i) {
tcg/riscv/tcg-target.c.inc +1 -2
@@ -1784,8 +1784,7 @@ static void tcg_target_qemu_prologue(TCGContext *s) tcg_out_opc_imm(s, OPC_JALR, TCG_REG_ZERO, tcg_target_call_iarg_regs[1], 0); /* Return path for goto_ptr. Set return value to 0 */ - /* TODO: Cast goes away when all hosts converted */ - tcg_code_gen_epilogue = (void *)tcg_splitwx_to_rx(s->code_ptr); + tcg_code_gen_epilogue = tcg_splitwx_to_rx(s->code_ptr); tcg_out_mov(s, TCG_TYPE_REG, TCG_REG_A0, TCG_REG_ZERO); /* TB epilogue */
tcg/s390/tcg-target.c.inc +1 -2
@@ -2551,8 +2551,7 @@ static void tcg_target_qemu_prologue(TCGContext *s) * Return path for goto_ptr. Set return value to 0, a-la exit_tb, * and fall through to the rest of the epilogue. */ - /* TODO: Cast goes away when all hosts converted */ - tcg_code_gen_epilogue = (void *)tcg_splitwx_to_rx(s->code_ptr); + tcg_code_gen_epilogue = tcg_splitwx_to_rx(s->code_ptr); tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R2, 0); /* TB epilogue */
tcg/sparc/tcg-target.c.inc +1 -2
@@ -1039,8 +1039,7 @@ static void tcg_target_qemu_prologue(TCGContext *s) tcg_out_nop(s); /* Epilogue for goto_ptr. */ - /* TODO: Cast goes away when all hosts converted */ - tcg_code_gen_epilogue = (void *)tcg_splitwx_to_rx(s->code_ptr); + tcg_code_gen_epilogue = tcg_splitwx_to_rx(s->code_ptr); tcg_out_arithi(s, TCG_REG_G0, TCG_REG_I7, 8, RETURN); /* delay slot */ tcg_out_movi_imm13(s, TCG_REG_O0, 0);
Signature · 1 line
2.25.1
Re: [PATCH v4 42/43] tcg: Constify tcg_code_gen_epilogue
Quoted 5 lines · Richard Henderson
Now that all native tcg hosts support splitwx,
make this pointer const.Signed-off-by Richard Henderson <[email protected]>
Quoted 12 lines
--- include/tcg/tcg.h | 2 +- tcg/tcg.c | 2 +- tcg/aarch64/tcg-target.c.inc | 3 +-- tcg/arm/tcg-target.c.inc | 3 +-- tcg/i386/tcg-target.c.inc | 3 +-- tcg/mips/tcg-target.c.inc | 3 +-- tcg/ppc/tcg-target.c.inc | 3 +-- tcg/riscv/tcg-target.c.inc | 3 +-- tcg/s390/tcg-target.c.inc | 3 +-- tcg/sparc/tcg-target.c.inc | 3 +-- 10 files changed, 10 insertions(+), 18 deletions(-)
PATCH v4 43/43 tcg: Constify TCGLabelQemuLdst.raddr
In reply to Richard HendersonNow that all native tcg hosts support splitwx,
make this pointer const.
--- tcg/aarch64/tcg-target.c.inc | 3 +-- tcg/arm/tcg-target.c.inc | 3 +-- tcg/i386/tcg-target.c.inc | 3 +-- tcg/mips/tcg-target.c.inc | 3 +-- tcg/ppc/tcg-target.c.inc | 3 +-- tcg/riscv/tcg-target.c.inc | 3 +-- tcg/s390/tcg-target.c.inc | 3 +-- tcg/tcg-ldst.c.inc | 2 +- 8 files changed, 8 insertions(+), 15 deletions(-)
tcg/aarch64/tcg-target.c.inc +1 -2
@@ -1636,8 +1636,7 @@ static void add_qemu_ldst_label(TCGContext *s, bool is_ld, TCGMemOpIdx oi, label->type = ext; label->datalo_reg = data_reg; label->addrlo_reg = addr_reg; - /* TODO: Cast goes away when all hosts converted */ - label->raddr = (void *)tcg_splitwx_to_rx(raddr); + label->raddr = tcg_splitwx_to_rx(raddr); label->label_ptr[0] = label_ptr; }
tcg/arm/tcg-target.c.inc +1 -2
@@ -1340,8 +1340,7 @@ static void add_qemu_ldst_label(TCGContext *s, bool is_ld, TCGMemOpIdx oi, label->datahi_reg = datahi; label->addrlo_reg = addrlo; label->addrhi_reg = addrhi; - /* TODO: Cast goes away when all hosts converted */ - label->raddr = (void *)tcg_splitwx_to_rx(raddr); + label->raddr = tcg_splitwx_to_rx(raddr); label->label_ptr[0] = label_ptr; }
tcg/i386/tcg-target.c.inc +1 -2
@@ -1786,8 +1786,7 @@ static void add_qemu_ldst_label(TCGContext *s, bool is_ld, bool is_64, label->datahi_reg = datahi; label->addrlo_reg = addrlo; label->addrhi_reg = addrhi; - /* TODO: Cast goes away when all hosts converted */ - label->raddr = (void *)tcg_splitwx_to_rx(raddr); + label->raddr = tcg_splitwx_to_rx(raddr); label->label_ptr[0] = label_ptr[0]; if (TARGET_LONG_BITS > TCG_TARGET_REG_BITS) { label->label_ptr[1] = label_ptr[1];
tcg/mips/tcg-target.c.inc +1 -2
@@ -1283,8 +1283,7 @@ static void add_qemu_ldst_label(TCGContext *s, int is_ld, TCGMemOpIdx oi, label->datahi_reg = datahi; label->addrlo_reg = addrlo; label->addrhi_reg = addrhi; - /* TODO: Cast goes away when all hosts converted */ - label->raddr = (void *)tcg_splitwx_to_rx(raddr); + label->raddr = tcg_splitwx_to_rx(raddr); label->label_ptr[0] = label_ptr[0]; if (TCG_TARGET_REG_BITS < TARGET_LONG_BITS) { label->label_ptr[1] = label_ptr[1];
tcg/ppc/tcg-target.c.inc +1 -2
@@ -2001,8 +2001,7 @@ static void add_qemu_ldst_label(TCGContext *s, bool is_ld, TCGMemOpIdx oi, label->datahi_reg = datahi_reg; label->addrlo_reg = addrlo_reg; label->addrhi_reg = addrhi_reg; - /* TODO: Cast goes away when all hosts converted */ - label->raddr = (void *)tcg_splitwx_to_rx(raddr); + label->raddr = tcg_splitwx_to_rx(raddr); label->label_ptr[0] = lptr; }
tcg/riscv/tcg-target.c.inc +1 -2
@@ -996,8 +996,7 @@ static void add_qemu_ldst_label(TCGContext *s, int is_ld, TCGMemOpIdx oi, label->datahi_reg = datahi; label->addrlo_reg = addrlo; label->addrhi_reg = addrhi; - /* TODO: Cast goes away when all hosts converted */ - label->raddr = (void *)tcg_splitwx_to_rx(raddr); + label->raddr = tcg_splitwx_to_rx(raddr); label->label_ptr[0] = label_ptr[0]; }
tcg/s390/tcg-target.c.inc +1 -2
@@ -1587,8 +1587,7 @@ static void add_qemu_ldst_label(TCGContext *s, bool is_ld, TCGMemOpIdx oi, label->oi = oi; label->datalo_reg = data; label->addrlo_reg = addr; - /* TODO: Cast goes away when all hosts converted */ - label->raddr = (void *)tcg_splitwx_to_rx(raddr); + label->raddr = tcg_splitwx_to_rx(raddr); label->label_ptr[0] = label_ptr; }
tcg/tcg-ldst.c.inc +1 -1
@@ -28,7 +28,7 @@ typedef struct TCGLabelQemuLdst { TCGReg addrhi_reg; /* reg index for high word of guest virtual addr */ TCGReg datalo_reg; /* reg index for low word to be loaded or stored */ TCGReg datahi_reg; /* reg index for high word to be loaded or stored */ - tcg_insn_unit *raddr; /* gen code addr of the next IR of qemu_ld/st IR */ + const tcg_insn_unit *raddr; /* addr of the next IR of qemu_ld/st IR */ tcg_insn_unit *label_ptr[2]; /* label pointers to be updated */ QSIMPLEQ_ENTRY(TCGLabelQemuLdst) next; } TCGLabelQemuLdst;
Signature · 1 line
2.25.1
Re: [PATCH v4 43/43] tcg: Constify TCGLabelQemuLdst.raddr
Quoted 5 lines · Richard Henderson
Now that all native tcg hosts support splitwx,
make this pointer const.Signed-off-by Richard Henderson <[email protected]>
Quoted 10 lines
--- tcg/aarch64/tcg-target.c.inc | 3 +-- tcg/arm/tcg-target.c.inc | 3 +-- tcg/i386/tcg-target.c.inc | 3 +-- tcg/mips/tcg-target.c.inc | 3 +-- tcg/ppc/tcg-target.c.inc | 3 +-- tcg/riscv/tcg-target.c.inc | 3 +-- tcg/s390/tcg-target.c.inc | 3 +-- tcg/tcg-ldst.c.inc | 2 +- 8 files changed, 8 insertions(+), 15 deletions(-)
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [PATCH v4 00/43] Mirror map JIT memory for TCG
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
37f04b7..aa14de0 master -> master - [tag update] patchew/[email protected] -> patchew/[email protected] * [new tag] patchew/[email protected] -> patchew/[email protected] * [new tag] patchew/[email protected] -> patchew/[email protected] * [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
5861ba1 tcg: Constify TCGLabelQemuLdst.raddr
8b66138 tcg: Constify tcg_code_gen_epilogue
b60ae50 tcg: Remove TCG_TARGET_SUPPORT_MIRROR
ceb2ae8 tcg/arm: Support split-wx code generation
ddb32ce tcg/mips: Support split-wx code generation
d286278 tcg/mips: Do not assert on relocation overflow
c6603c2 accel/tcg: Add mips support to alloc_code_gen_buffer_splitwx_memfd f472d2a tcg/riscv: Support split-wx code generation
c7b4c9e tcg/riscv: Remove branch-over-branch fallback
5a73605 tcg/riscv: Fix branch range checks
b07237d tcg/s390: Support split-wx code generation
1b609a5 tcg/s390: Use tcg_tbrel_diff
ab6c76a tcg/sparc: Support split-wx code generation
eeb9f35 tcg/sparc: Use tcg_tbrel_diff
5d2fb73 tcg/ppc: Support split-wx code generation
54626b4 tcg/ppc: Use tcg_out_mem_long to reset TCG_REG_TB a810384 tcg/ppc: Use tcg_tbrel_diff
4327613 tcg: Introduce tcg_tbrel_diff
b5817c5 tcg/tci: Push const down through bytecode reading 3a0b856 disas: Push const down through host disasassembly 875346c tcg/aarch64: Support split-wx code generation
d8fca0b tcg/aarch64: Use B not BL for tcg_out_goto_long 5c1da59 tcg/i386: Support split-wx code generation
cf974dc tcg: Return the TB pointer from the rx region from exit_tb 4e63180 accel/tcg: Support split-wx for darwin/iOS with vm_remap 2acd41d accel/tcg: Support split-wx for linux with memfd 43dc2fc tcg: Add --accel tcg,split-wx property
a93d787 tcg: Use Error with alloc_code_gen_buffer
14f4dae tcg: Make tb arg to synchronize_from_tb const
6d2cbe3 tcg: Make DisasContextBase.tb const
1ff4e38 tcg: Adjust tb_target_set_jmp_target for split-wx 9163383 tcg: Adjust tcg_register_jit for const
ef98b3c tcg: Adjust tcg_out_label for const
ff58797 tcg: Adjust tcg_out_call for const
204f5dd tcg: Adjust TCGLabel for const
3a0629b tcg: Introduce tcg_splitwx_to_{rx,rw}
e69b13a tcg: Add in_code_gen_buffer
0c55fbc tcg: Move tcg epilogue pointer out of TCGContext 5b1eb71 tcg: Move tcg prologue pointer out of TCGContext 22fc3b0 util: Specialize flush_idcache_range for aarch64 4a47d91 util: Enhance flush_icache_range with separate data pointer 722b23b util: Extract flush_icache_range to cacheflush.c 2a3aaed tcg: Do not flush icache for interpreter
=== OUTPUT BEGIN ===
1/43 Checking commit 2a3aaedef170 (tcg: Do not flush icache for interpreter) 2/43 Checking commit 722b23b5bb81 (util: Extract flush_icache_range to cacheflush.c)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #28:
new file mode 100644
WARNING: architecture specific defines should be avoided #43: FILE: include/qemu/cacheflush.h:11:
+#if defined(__i386__) || defined(__x86_64__) || defined(__s390__)
WARNING: architecture specific defines should be avoided #277: FILE: util/cacheflush.c:12:
+#if defined(__i386__) || defined(__x86_64__) || defined(__s390__)
WARNING: architecture specific defines should be avoided #283: FILE: util/cacheflush.c:18:
+#ifdef __OpenBSD__
total: 0 errors, 4 warnings, 232 lines checked
Patch 2/43 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
3/43 Checking commit 4a47d9160cc1 (util: Enhance flush_icache_range with separate data pointer) 4/43 Checking commit 22fc3b028090 (util: Specialize flush_idcache_range for aarch64)
ERROR: externs should be avoided in .c files
#38: FILE: util/cacheflush.c:21:
+extern void sys_icache_invalidate(void *start, size_t len);
ERROR: externs should be avoided in .c files #39: FILE: util/cacheflush.c:22:
+extern void sys_dcache_flush(void *start, size_t len);
total: 2 errors, 0 warnings, 81 lines checked
Patch 4/43 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
5/43 Checking commit 5b1eb71d0d3a (tcg: Move tcg prologue pointer out of TCGContext) 6/43 Checking commit 0c55fbc2c214 (tcg: Move tcg epilogue pointer out of TCGContext) 7/43 Checking commit e69b13a6c541 (tcg: Add in_code_gen_buffer)
8/43 Checking commit 3a0629b80930 (tcg: Introduce tcg_splitwx_to_{rx,rw})
9/43 Checking commit 204f5dd20af1 (tcg: Adjust TCGLabel for const)
10/43 Checking commit ff58797d1164 (tcg: Adjust tcg_out_call for const)
11/43 Checking commit ef98b3c104ed (tcg: Adjust tcg_out_label for const)
12/43 Checking commit 91633839ff16 (tcg: Adjust tcg_register_jit for const) 13/43 Checking commit 1ff4e38e1db3 (tcg: Adjust tb_target_set_jmp_target for split-wx) 14/43 Checking commit 6d2cbe338b4c (tcg: Make DisasContextBase.tb const)
15/43 Checking commit 14f4daed4c08 (tcg: Make tb arg to synchronize_from_tb const) 16/43 Checking commit a93d787bb9c9 (tcg: Use Error with alloc_code_gen_buffer) 17/43 Checking commit 43dc2fccc410 (tcg: Add --accel tcg,split-wx property) 18/43 Checking commit 2acd41d2d9f5 (accel/tcg: Support split-wx for linux with memfd) 19/43 Checking commit 4e63180ada66 (accel/tcg: Support split-wx for darwin/iOS with vm_remap)
ERROR: externs should be avoided in .c files
#25: FILE: accel/tcg/translate-all.c:1172:
+extern kern_return_t mach_vm_remap(vm_map_t target_task,
total: 1 errors, 0 warnings, 80 lines checked
Patch 19/43 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
20/43 Checking commit cf974dcd5791 (tcg: Return the TB pointer from the rx region from exit_tb) 21/43 Checking commit 5c1da59df861 (tcg/i386: Support split-wx code generation)
22/43 Checking commit d8fca0b8d088 (tcg/aarch64: Use B not BL for tcg_out_goto_long) 23/43 Checking commit 875346c2f10b (tcg/aarch64: Support split-wx code generation) 24/43 Checking commit 3a0b856585ee (disas: Push const down through host disasassembly) 25/43 Checking commit b5817c5ffe00 (tcg/tci: Push const down through bytecode reading) 26/43 Checking commit 43276137bef1 (tcg: Introduce tcg_tbrel_diff)
27/43 Checking commit a81038425cc1 (tcg/ppc: Use tcg_tbrel_diff)
28/43 Checking commit 54626b45773b (tcg/ppc: Use tcg_out_mem_long to reset TCG_REG_TB) 29/43 Checking commit 5d2fb73b63eb (tcg/ppc: Support split-wx code generation)
30/43 Checking commit eeb9f35b5237 (tcg/sparc: Use tcg_tbrel_diff)
31/43 Checking commit ab6c76aedab4 (tcg/sparc: Support split-wx code generation)
32/43 Checking commit 1b609a5e826c (tcg/s390: Use tcg_tbrel_diff)
33/43 Checking commit b07237ddf5df (tcg/s390: Support split-wx code generation)
34/43 Checking commit 5a73605068a9 (tcg/riscv: Fix branch range checks)
35/43 Checking commit c7b4c9ef06e0 (tcg/riscv: Remove branch-over-branch fallback) 36/43 Checking commit f472d2a9a4ed (tcg/riscv: Support split-wx code generation)
37/43 Checking commit c6603c22b80e (accel/tcg: Add mips support to alloc_code_gen_buffer_splitwx_memfd)
WARNING: architecture specific defines should be avoided
#25: FILE: accel/tcg/translate-all.c:1143:
+#ifdef __mips__
WARNING: architecture specific defines should be avoided #43: FILE: accel/tcg/translate-all.c:1160:
+#ifdef __mips__
total: 0 errors, 2 warnings, 68 lines checked
Patch 37/43 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
38/43 Checking commit d2862788fc63 (tcg/mips: Do not assert on relocation overflow) 39/43 Checking commit ddb32ce98dcc (tcg/mips: Support split-wx code generation) 40/43 Checking commit ceb2ae8c947b (tcg/arm: Support split-wx code generation) 41/43 Checking commit b60ae504f046 (tcg: Remove TCG_TARGET_SUPPORT_MIRROR) 42/43 Checking commit 8b66138f4c23 (tcg: Constify tcg_code_gen_epilogue) 43/43 Checking commit 5861ba146e9c (tcg: Constify TCGLabelQemuLdst.raddr) === OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]