tcg patch queue
Subsystems (3)
The following changes since commit e750a7ace492f0b450653d4ad368a77d6f660fb8:
Merge tag 'pull-9p-20221024' of https://github.com/cschoenebeck/qemu into staging (2022-10-24 14:27:12 -0400)
are available in the Git repository at:
https://gitlab.com/rth7680/qemu.git tags/pull-tcg-20221026
for you to fetch changes up to 04f105758b0089f73ee47260671580cde35f96cc:
accel/tcg: Remove restore_state_to_opc function (2022-10-26 11:11:28 +1000)
----------------------------------------------------------------
Revert incorrect cflags initialization. Add direct jumps for tcg/loongarch64. Speed up breakpoint check.
Improve assertions for atomic.h. Move restore_state_to_opc to TCGCPUOps. Cleanups to TranslationBlock maintenance.
----------------------------------------------------------------
Leandro Lupori (1):
accel/tcg: Add a quicker check for breakpoints
Peter Maydell (1):
Revert "accel/tcg: Init TCG cflags in vCPU thread handler"
Qi Hu (2):
tcg/loongarch64: Add direct jump support tcg/aarch64: Remove unused code in tcg_out_op
Richard Henderson (43):
include/qemu/osdep: Add qemu_build_assert include/qemu/atomic: Use qemu_build_assert include/qemu/thread: Use qatomic_* functions
accel/tcg: Make page_alloc_target_data allocation constant accel/tcg: Remove disabled debug in translate-all.c accel/tcg: Split out PageDesc to internal.h
accel/tcg: Split out tb-maint.c
accel/tcg: Move assert_no_pages_locked to internal.h accel/tcg: Drop cpu_get_tb_cpu_state from TARGET_HAS_PRECISE_SMC accel/tcg: Remove duplicate store to tb->page_addr[] accel/tcg: Introduce tb_{set_}page_addr{0,1}
accel/tcg: Rename tb_invalidate_phys_page
accel/tcg: Rename tb_invalidate_phys_page_range and drop end parameter accel/tcg: Unify declarations of tb_invalidate_phys_range accel/tcg: Use tb_invalidate_phys_page in page_set_flags accel/tcg: Call tb_invalidate_phys_page for PAGE_RESET accel/tcg: Use page_reset_target_data in page_set_flags accel/tcg: Use tb_invalidate_phys_range in page_set_flags accel/tcg: Move TARGET_PAGE_DATA_SIZE impl to user-exec.c accel/tcg: Simplify page_get/alloc_target_data
accel/tcg: Add restore_state_to_opc to TCGCPUOps target/alpha: Convert to tcg_ops restore_state_to_opc target/arm: Convert to tcg_ops restore_state_to_opc target/avr: Convert to tcg_ops restore_state_to_opc target/cris: Convert to tcg_ops restore_state_to_opc target/hexagon: Convert to tcg_ops restore_state_to_opc target/hppa: Convert to tcg_ops restore_state_to_opc target/i386: Convert to tcg_ops restore_state_to_opc target/loongarch: Convert to tcg_ops restore_state_to_opc target/m68k: Convert to tcg_ops restore_state_to_opc target/microblaze: Convert to tcg_ops restore_state_to_opc target/mips: Convert to tcg_ops restore_state_to_opc target/nios2: Convert to tcg_ops restore_state_to_opc target/openrisc: Convert to tcg_ops restore_state_to_opc target/ppc: Convert to tcg_ops restore_state_to_opc target/riscv: Convert to tcg_ops restore_state_to_opc target/rx: Convert to tcg_ops restore_state_to_opc target/s390x: Convert to tcg_ops restore_state_to_opc target/sh4: Convert to tcg_ops restore_state_to_opc target/sparc: Convert to tcg_ops restore_state_to_opc target/tricore: Convert to tcg_ops restore_state_to_opc target/xtensa: Convert to tcg_ops restore_state_to_opc accel/tcg: Remove restore_state_to_opc function
accel/tcg/internal.h | 91 ++++ include/exec/cpu-all.h | 22 +- include/exec/exec-all.h | 35 +- include/exec/ram_addr.h | 2 - include/exec/translate-all.h | 2 +- include/hw/core/tcg-cpu-ops.h | 11 + include/qemu/atomic.h | 16 +- include/qemu/osdep.h | 8 + include/qemu/thread.h | 8 +- target/arm/cpu.h | 8 + target/arm/internals.h | 4 - target/mips/tcg/tcg-internal.h | 3 + target/s390x/s390x-internal.h | 4 +- target/sparc/cpu.h | 3 + tcg/loongarch64/tcg-target.h | 9 +- accel/tcg/cpu-exec.c | 24 +- accel/tcg/tb-maint.c | 704 ++++++++++++++++++++++++++ accel/tcg/tcg-accel-ops-mttcg.c | 5 +- accel/tcg/tcg-accel-ops-rr.c | 7 +- accel/tcg/translate-all.c | 1017 ++------------------------------------ accel/tcg/translator.c | 9 +- accel/tcg/user-exec.c | 42 ++ bsd-user/mmap.c | 2 - cpu.c | 4 +- linux-user/mmap.c | 4 - target/alpha/cpu.c | 9 + target/alpha/translate.c | 6 - target/arm/cpu.c | 26 + target/arm/mte_helper.c | 5 - target/arm/translate.c | 22 - target/avr/cpu.c | 11 + target/avr/translate.c | 6 - target/cris/cpu.c | 11 + target/cris/translate.c | 6 - target/hexagon/cpu.c | 9 +- target/hppa/cpu.c | 19 + target/hppa/translate.c | 13 - target/i386/tcg/tcg-cpu.c | 19 + target/i386/tcg/translate.c | 15 - target/loongarch/cpu.c | 11 + target/loongarch/translate.c | 6 - target/m68k/cpu.c | 14 + target/m68k/translate.c | 10 - target/microblaze/cpu.c | 11 + target/microblaze/translate.c | 7 - target/mips/cpu.c | 1 + target/mips/tcg/translate.c | 8 +- target/nios2/cpu.c | 11 + target/nios2/translate.c | 6 - target/openrisc/cpu.c | 13 + target/openrisc/translate.c | 10 - target/ppc/cpu_init.c | 10 + target/ppc/translate.c | 6 - target/riscv/cpu.c | 9 +- target/rx/cpu.c | 10 + target/rx/translate.c | 6 - target/s390x/cpu.c | 1 + target/s390x/tcg/translate.c | 7 +- target/sh4/cpu.c | 16 + target/sh4/translate.c | 10 - target/sparc/cpu.c | 1 + target/sparc/translate.c | 7 +- target/tricore/cpu.c | 11 + target/tricore/translate.c | 6 - target/xtensa/cpu.c | 10 + target/xtensa/translate.c | 6 - tcg/aarch64/tcg-target.c.inc | 31 +- tcg/loongarch64/tcg-target.c.inc | 48 +- accel/tcg/meson.build | 1 + 69 files changed, 1304 insertions(+), 1221 deletions(-) create mode 100644 accel/tcg/tb-maint.c
[PULL 22/47] accel/tcg: Use tb_invalidate_phys_range in page_set_flags
Flush translation blocks in bulk, rather than page-by-page.
--- accel/tcg/translate-all.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
accel/tcg/translate-all.c +6 -2
@@ -1352,7 +1352,7 @@ int page_get_flags(target_ulong address)void page_set_flags (target_ulong start,target_ulong end,int flags) {target_ulong addr, len; -bool reset; +bool reset, inval_tb = false;/* This function should never be called with addresses outside the guest address space. If this assert fires, it probably indicates
@@ -1388,11 +1388,15 @@ void page_set_flags(target_ulong start, target_ulong end, int flags) && (reset || !(flags & PAGE_EXEC) || (flags & ~p->flags & PAGE_WRITE))) { -tb_invalidate_phys_page (addr); + inval_tb = true; }/* Using mprotect on a page does not change sticky bits. */ p->flags = (reset ?0 : p->flags &PAGE_STICKY ) | flags; } + +if (inval_tb) { +tb_invalidate_phys_range (start, end); + } }void page_reset_target_data (target_ulong start,target_ulong end)
Signature · 1 line
2.34.1
[PULL 15/47] accel/tcg: Introduce tb_{set_}page_addr{0,1}
In reply to Richard HendersonThis data structure will be replaced for user-only: add accessors.
--- include/exec/exec-all.h | 22 ++++++++++++++++++++++ accel/tcg/cpu-exec.c | 9 +++++---- accel/tcg/tb-maint.c | 29 +++++++++++++++-------------- accel/tcg/translate-all.c | 16 ++++++++-------- accel/tcg/translator.c | 9 +++++---- 5 files changed, 55 insertions(+), 30 deletions(-)
include/exec/exec-all.h +22 -0
@@ -610,6 +610,28 @@ static inline uint32_t tb_cflags(const TranslationBlock *tb)return qatomic_read (&tb->cflags); } +static inline tb_page_addr_t tb_page_addr0 (const TranslationBlock *tb) +{ +return tb->page_addr[0 ]; +} + +static inline tb_page_addr_t tb_page_addr1 (const TranslationBlock *tb) +{ +return tb->page_addr[1 ]; +} + +static inline void tb_set_page_addr0 (TranslationBlock *tb, +tb_page_addr_t addr) +{ + tb->page_addr[0 ] = addr; +} + +static inline void tb_set_page_addr1 (TranslationBlock *tb, +tb_page_addr_t addr) +{ + tb->page_addr[1 ] = addr; +} +/* current cflags for hashing/comparison */ uint32_t curr_cflags (CPUState *cpu);
accel/tcg/cpu-exec.c +5 -4
@@ -187,13 +187,14 @@ static bool tb_lookup_cmp(const void *p, const void *d)const struct tb_desc *desc = d;if ((TARGET_TB_PCREL ||tb_pc (tb) == desc->pc) && - tb->page_addr[0 ] == desc->page_addr0 && +tb_page_addr0 (tb) == desc->page_addr0 && tb->cs_base == desc->cs_base && tb->flags == desc->flags && tb->trace_vcpu_dstate == desc->trace_vcpu_dstate &&tb_cflags (tb) == desc->cflags) {/* check next page if needed */ -if (tb->page_addr[1 ] ==-1 ) { +tb_page_addr_t tb_phys_page1 =tb_page_addr1 (tb); +if (tb_phys_page1 ==-1 ) {return true; }else {tb_page_addr_t phys_page1;
@@ -210,7 +211,7 @@ static bool tb_lookup_cmp(const void *p, const void *d)*/ virt_page1 =TARGET_PAGE_ALIGN (desc->pc); phys_page1 =get_page_addr_code (desc->env, virt_page1); -if (tb->page_addr[1 ] == phys_page1) { +if (tb_phys_page1 == phys_page1) {return true; } }
@@ -1019,7 +1020,7 @@ int cpu_exec(CPUState *cpu)* direct jump to a TB spanning two pages because the mapping * for the second page can change. */ -if (tb->page_addr[1 ] !=-1 ) { +if (tb_page_addr1 (tb) !=-1 ) { last_tb =NULL ; }#endif
accel/tcg/tb-maint.c +15 -14
@@ -44,8 +44,8 @@ static bool tb_cmp(const void *ap, const void *bp) a->flags == b->flags && (tb_cflags (a) & ~CF_INVALID ) == (tb_cflags (b) & ~CF_INVALID ) && a->trace_vcpu_dstate == b->trace_vcpu_dstate && - a->page_addr[0 ] == b->page_addr[0 ] && - a->page_addr[1] == b->page_addr[1]); +tb_page_addr0 (a) ==tb_page_addr0 (b) && + tb_page_addr1(a) == tb_page_addr1(b)); }void tb_htable_init (void )
@@ -273,7 +273,7 @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list)qemu_spin_unlock (&tb->jmp_lock);/* remove the TB from the hash list */ - phys_pc = tb->page_addr[0 ]; + phys_pc =tb_page_addr0 (tb); h =tb_hash_func (phys_pc, (TARGET_TB_PCREL ?0 :tb_pc (tb)), tb->flags, orig_cflags, tb->trace_vcpu_dstate);if (!qht_remove (&tb_ctx.htable, tb, h)) {
@@ -282,10 +282,11 @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list)/* remove the TB from the page list */ if (rm_from_page_list) { - p =page_find (tb->page_addr[0 ] >>TARGET_PAGE_BITS ); + p =page_find (phys_pc >>TARGET_PAGE_BITS );tb_page_remove (p, tb); -if (tb->page_addr[1 ] !=-1 ) { - p =page_find (tb->page_addr[1 ] >>TARGET_PAGE_BITS ); + phys_pc =tb_page_addr1 (tb); +if (phys_pc !=-1 ) { + p =page_find (phys_pc >>TARGET_PAGE_BITS );tb_page_remove (p, tb); } }
@@ -358,16 +359,16 @@ static inline void page_unlock_tb(const TranslationBlock *tb) { }/* lock the page(s) of a TB in the correct acquisition order */ static void page_lock_tb (const TranslationBlock *tb) { -page_lock_pair (NULL , tb->page_addr[0 ],NULL , tb->page_addr[1 ], false); +page_lock_pair (NULL ,tb_page_addr0 (tb),NULL ,tb_page_addr1 (tb), false); }static void page_unlock_tb (const TranslationBlock *tb) { -PageDesc *p1 =page_find (tb->page_addr[0 ] >>TARGET_PAGE_BITS ); +PageDesc *p1 =page_find (tb_page_addr0 (tb) >>TARGET_PAGE_BITS );page_unlock (p1); -if (unlikely (tb->page_addr[1 ] !=-1 )) { -PageDesc *p2 =page_find (tb->page_addr[1 ] >>TARGET_PAGE_BITS ); +if (unlikely (tb_page_addr1 (tb) !=-1 )) { +PageDesc *p2 =page_find (tb_page_addr1 (tb) >>TARGET_PAGE_BITS );if (p2 != p1) {page_unlock (p2);
@@ -382,7 +383,7 @@ static void page_unlock_tb(const TranslationBlock *tb)*/ void tb_phys_invalidate (TranslationBlock *tb,tb_page_addr_t page_addr) { -if (page_addr ==-1 && tb->page_addr[0 ] !=-1 ) { +if (page_addr ==-1 &&tb_page_addr0 (tb) !=-1 ) {page_lock_tb (tb);do_tb_phys_invalidate (tb, true);page_unlock_tb (tb);
@@ -516,11 +517,11 @@ tb_invalidate_phys_page_range__locked(struct page_collection *pages,if (n ==0 ) {/* NOTE: tb_end may be after the end of the page, but it is not a problem */ - tb_start = tb->page_addr[0 ]; + tb_start =tb_page_addr0 (tb); tb_end = tb_start + tb->size; }else { - tb_start = tb->page_addr[1 ]; - tb_end = tb_start + ((tb->page_addr[0 ] + tb->size) + tb_start =tb_page_addr1 (tb); + tb_end = tb_start + ((tb_page_addr0 (tb) + tb->size) & ~TARGET_PAGE_MASK ); }if (!(tb_end <= start || tb_start >= end)) {
accel/tcg/translate-all.c +8 -8
@@ -698,9 +698,9 @@ page_collection_lock(tb_page_addr_t start, tb_page_addr_t end) }assert_page_locked (pd); PAGE_FOR_EACH_TB(pd, tb, n) { -if (page_trylock_add (set, tb->page_addr[0 ]) || - (tb->page_addr[1 ] !=-1 && -page_trylock_add (set, tb->page_addr[1 ]))) { +if (page_trylock_add (set,tb_page_addr0 (tb)) || + (tb_page_addr1 (tb) !=-1 && +page_trylock_add (set,tb_page_addr1 (tb)))) {/* drop all locks, and reacquire in order */ g_tree_foreach (set->tree, page_entry_unlock,NULL ); goto retry;
@@ -771,8 +771,8 @@ TranslationBlock *tb_gen_code(CPUState *cpu, tb->flags = flags; tb->cflags = cflags; tb->trace_vcpu_dstate = *cpu->trace_dstate; - tb->page_addr[0 ] = phys_pc; - tb->page_addr[1 ] =-1 ; +tb_set_page_addr0 (tb, phys_pc); +tb_set_page_addr1 (tb,-1 ); tcg_ctx->tb_cflags = cflags; tb_overflow:
@@ -970,7 +970,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,* a temporary one-insn TB, and we have nothing left to do. Return early * before attempting to link to other TBs or add to the lookup table. */ -if (tb->page_addr[0 ] ==-1 ) { +if (tb_page_addr0 (tb) ==-1 ) {return tb; }
@@ -985,7 +985,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,* No explicit memory barrier is required -- tb_link_page() makes the * TB visible in a consistent state. */ - existing_tb =tb_link_page (tb, tb->page_addr[0 ], tb->page_addr[1 ]); + existing_tb =tb_link_page (tb,tb_page_addr0 (tb),tb_page_addr1 (tb));/* if the TB already exists, discard what we just translated */ if (unlikely (existing_tb != tb)) {uintptr_t orig_aligned = (uintptr_t )gen_code_buf;
@@ -1140,7 +1140,7 @@ static gboolean tb_tree_stats_iter(gpointer key, gpointer value, gpointer data)if (tb->size > tst->max_target_size) { tst->max_target_size = tb->size; } -if (tb->page_addr[1 ] !=-1 ) { +if (tb_page_addr1 (tb) !=-1 ) { tst->cross_page++; }if (tb->jmp_reset_offset[0 ] !=TB_JMP_RESET_OFFSET_INVALID ) {
accel/tcg/translator.c +5 -4
@@ -157,7 +157,7 @@ static void *translator_access(CPUArchState *env, DisasContextBase *db, tb = db->tb;/* Use slow path if first page is MMIO. */ -if (unlikely (tb->page_addr[0 ] ==-1 )) { +if (unlikely (tb_page_addr0 (tb) ==-1 )) {return NULL ; }
@@ -169,13 +169,14 @@ static void *translator_access(CPUArchState *env, DisasContextBase *db, host = db->host_addr[1 ]; base =TARGET_PAGE_ALIGN (db->pc_first);if (host ==NULL ) { - tb->page_addr[1 ] = +tb_page_addr_t phys_page =get_page_addr_code_hostp (env, base, &db->host_addr[1 ]); +/* We cannot handle MMIO as second page. */ +assert (phys_page !=-1 ); +tb_set_page_addr1 (tb, phys_page);#ifdef CONFIG_USER_ONLY page_protect (end);#endif -/* We cannot handle MMIO as second page. */ -assert (tb->page_addr[1 ] !=-1 ); host = db->host_addr[1 ]; }
Signature · 1 line
2.34.1
[PULL 24/47] accel/tcg: Simplify page_get/alloc_target_data
In reply to Richard HendersonSince the only user, Arm MTE, always requires allocation, merge the get and alloc functions to always produce a non-null result. Also assume that the user has already checked page validity.
--- include/exec/cpu-all.h | 21 ++++++--------------- accel/tcg/user-exec.c | 16 ++++------------ target/arm/mte_helper.c | 4 ---- 3 files changed, 10 insertions(+), 31 deletions(-)
include/exec/cpu-all.h +6 -15
@@ -281,27 +281,18 @@ void page_reset_target_data(target_ulong start, target_ulong end);int page_check_range (target_ulong start,target_ulong len,int flags);/** -* page_alloc_target_data(address) +* page_get_target_data(address) * @address: guest virtual address * -* Allocate TARGET_PAGE_DATA_SIZE bytes of out-of-band data to associate -* with the guest page at @address. If the page is not mapped, NULL will -* be returned. If there is existing data associated with @address, -* no new memory will be allocated. +* Return TARGET_PAGE_DATA_SIZE bytes of out-of-band data to associate +* with the guest page at @address, allocating it if necessary. The +* caller should already have verified that the address is valid. * * The memory will be freed when the guest page is deallocated, * e.g. with the munmap system call. */ -void *page_alloc_target_data (target_ulong address); - -/** -* page_get_target_data(address) -* @address: guest virtual address -* -* Return any out-of-bound memory assocated with the guest page -* at @address, as per page_alloc_target_data. -*/ -void *page_get_target_data (target_ulong address); +void *page_get_target_data (target_ulong address) + __attribute__((returns_nonnull));#endif CPUArchState *cpu_copy (CPUArchState *env);
accel/tcg/user-exec.c +4 -12
@@ -242,19 +242,11 @@ void page_reset_target_data(target_ulong start, target_ulong end)void *page_get_target_data (target_ulong address) {PageDesc *p =page_find (address >>TARGET_PAGE_BITS ); -return p ? p->target_data :NULL ; -} +void *ret = p->target_data; -void *page_alloc_target_data (target_ulong address) -{ -PageDesc *p =page_find (address >>TARGET_PAGE_BITS ); -void *ret =NULL ; - -if (p->flags &PAGE_VALID ) { - ret = p->target_data; -if (!ret) { - p->target_data = ret =g_malloc0 (TARGET_PAGE_DATA_SIZE ); - } +if (!ret) { + ret =g_malloc0 (TARGET_PAGE_DATA_SIZE ); + p->target_data = ret; }return ret; }
target/arm/mte_helper.c +0 -4
@@ -95,10 +95,6 @@ static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx, } tags =page_get_target_data (clean_ptr); -if (tags ==NULL ) { - tags =page_alloc_target_data (clean_ptr); -assert (tags !=NULL ); - } index =extract32 (ptr,LOG2_TAG_GRANULE +1 ,TARGET_PAGE_BITS -LOG2_TAG_GRANULE -1 );
Signature · 1 line
2.34.1
[PULL 19/47] accel/tcg: Use tb_invalidate_phys_page in page_set_flags
In reply to Richard HendersonWe do not require detection of overlapping TBs here, so use the more appropriate function.
--- accel/tcg/translate-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
accel/tcg/translate-all.c +1 -1
@@ -1382,7 +1382,7 @@ void page_set_flags(target_ulong start, target_ulong end, int flags)if (!(p->flags &PAGE_WRITE ) && (flags &PAGE_WRITE ) && p->first_tb) { -tb_invalidate_phys_page_unwind (addr,0 ); +tb_invalidate_phys_page (addr); }if (reset_target_data) {g_free (p->target_data);
Signature · 1 line
2.34.1
[PULL 30/47] target/hexagon: Convert to tcg_ops restore_state_to_opc
In reply to Richard Henderson--- target/hexagon/cpu.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
target/hexagon/cpu.c +7 -2
@@ -271,9 +271,13 @@ static bool hexagon_cpu_has_work(CPUState *cs)return true; } -void restore_state_to_opc (CPUHexagonState *env,TranslationBlock *tb, -target_ulong *data) +static void hexagon_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data) { +HexagonCPU *cpu =HEXAGON_CPU (cs); +CPUHexagonState *env = &cpu->env; + env->gpr[HEX_REG_PC ] = data[0 ]; }
@@ -327,6 +331,7 @@ static void hexagon_cpu_init(Object *obj)static const struct TCGCPUOps hexagon_tcg_ops = { .initialize = hexagon_translate_init, .synchronize_from_tb = hexagon_cpu_synchronize_from_tb, + .restore_state_to_opc = hexagon_restore_state_to_opc, };static void hexagon_cpu_class_init (ObjectClass *c,void *data)
Signature · 1 line
2.34.1
[PULL 31/47] target/hppa: Convert to tcg_ops restore_state_to_opc
In reply to Richard Henderson--- target/hppa/cpu.c | 19 +++++++++++++++++++ target/hppa/translate.c | 13 ------------- 2 files changed, 19 insertions(+), 13 deletions(-)
target/hppa/cpu.c +19 -0
@@ -68,6 +68,24 @@ static void hppa_cpu_synchronize_from_tb(CPUState *cs, cpu->env.psw_n = (tb->flags &PSW_N ) !=0 ; } +static void hppa_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data) +{ +HPPACPU *cpu =HPPA_CPU (cs); + + cpu->env.iaoq_f = data[0 ]; +if (data[1 ] != (target_ureg)-1 ) { + cpu->env.iaoq_b = data[1 ]; + } +/* +* Since we were executing the instruction at IAOQ_F, and took some +* sort of action that provoked the cpu_restore_state, we can infer +* that the instruction was not nullified. +*/ + cpu->env.psw_n =0 ; +} +static bool hppa_cpu_has_work (CPUState *cs) {return cs->interrupt_request & (CPU_INTERRUPT_HARD |CPU_INTERRUPT_NMI );
@@ -153,6 +171,7 @@ static const struct SysemuCPUOps hppa_sysemu_ops = {static const struct TCGCPUOps hppa_tcg_ops = { .initialize = hppa_translate_init, .synchronize_from_tb = hppa_cpu_synchronize_from_tb, + .restore_state_to_opc = hppa_restore_state_to_opc, #ifndef CONFIG_USER_ONLY .tlb_fill = hppa_cpu_tlb_fill,
target/hppa/translate.c +0 -13
@@ -4346,16 +4346,3 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns,DisasContext ctx;translator_loop (cs, tb, max_insns, pc, host_pc, &hppa_tr_ops, &ctx.base); } - -void restore_state_to_opc (CPUHPPAState *env,TranslationBlock *tb, -target_ulong *data) -{ - env->iaoq_f = data[0 ]; -if (data[1 ] != (target_ureg)-1 ) { - env->iaoq_b = data[1 ]; - } -/* Since we were executing the instruction at IAOQ_F, and took some -sort of action that provoked the cpu_restore_state, we can infer -that the instruction was not nullified. */ - env->psw_n =0 ; -}
Signature · 1 line
2.34.1
[PULL 23/47] accel/tcg: Move TARGET_PAGE_DATA_SIZE impl to user-exec.c
In reply to Richard HendersonSince "target data" is always user-only, move it out of translate-all.c to user-exec.c.
--- accel/tcg/translate-all.c | 50 --------------------------------------- accel/tcg/user-exec.c | 50 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 50 deletions(-)
accel/tcg/translate-all.c +0 -50
@@ -1399,56 +1399,6 @@ void page_set_flags(target_ulong start, target_ulong end, int flags) } } -void page_reset_target_data (target_ulong start,target_ulong end) -{ -#ifdef TARGET_PAGE_DATA_SIZE -target_ulong addr, len; - -/* -* This function should never be called with addresses outside the -* guest address space. If this assert fires, it probably indicates -* a missing call to h2g_valid. -*/ -assert (end -1 <=GUEST_ADDR_MAX ); -assert (start < end); -assert_memory_lock (); - - start = start &TARGET_PAGE_MASK ; - end =TARGET_PAGE_ALIGN (end); - -for (addr = start, len = end - start; - len !=0 ; - len -=TARGET_PAGE_SIZE , addr +=TARGET_PAGE_SIZE ) { -PageDesc *p =page_find_alloc (addr >>TARGET_PAGE_BITS ,1 ); - -g_free (p->target_data); - p->target_data =NULL ; - } -#endif -} - -#ifdef TARGET_PAGE_DATA_SIZE -void *page_get_target_data (target_ulong address) -{ -PageDesc *p =page_find (address >>TARGET_PAGE_BITS ); -return p ? p->target_data :NULL ; -} - -void *page_alloc_target_data (target_ulong address) -{ -PageDesc *p =page_find (address >>TARGET_PAGE_BITS ); -void *ret =NULL ; - -if (p->flags &PAGE_VALID ) { - ret = p->target_data; -if (!ret) { - p->target_data = ret =g_malloc0 (TARGET_PAGE_DATA_SIZE ); - } - } -return ret; -} -#endif /* TARGET_PAGE_DATA_SIZE */ -int page_check_range (target_ulong start,target_ulong len,int flags) {PageDesc *p;
accel/tcg/user-exec.c +50 -0
56 lines not on this page · raw message
Signature · 1 line
2.34.1
[PULL 29/47] target/cris: Convert to tcg_ops restore_state_to_opc
In reply to Richard Henderson--- target/cris/cpu.c | 11 +++++++++++ target/cris/translate.c | 6 ------ 2 files changed, 11 insertions(+), 6 deletions(-)
target/cris/cpu.c +11 -0
@@ -42,6 +42,15 @@ static vaddr cris_cpu_get_pc(CPUState *cs)return cpu->env.pc; } +static void cris_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data) +{ +CRISCPU *cpu =CRIS_CPU (cs); + + cpu->env.pc = data[0 ]; +} +static bool cris_cpu_has_work (CPUState *cs) {return cs->interrupt_request & (CPU_INTERRUPT_HARD |CPU_INTERRUPT_NMI );
@@ -212,6 +221,7 @@ static const struct SysemuCPUOps cris_sysemu_ops = {static const struct TCGCPUOps crisv10_tcg_ops = { .initialize = cris_initialize_crisv10_tcg, + .restore_state_to_opc = cris_restore_state_to_opc, #ifndef CONFIG_USER_ONLY .tlb_fill = cris_cpu_tlb_fill,
@@ -222,6 +232,7 @@ static const struct TCGCPUOps crisv10_tcg_ops = {static const struct TCGCPUOps crisv32_tcg_ops = { .initialize = cris_initialize_tcg, + .restore_state_to_opc = cris_restore_state_to_opc, #ifndef CONFIG_USER_ONLY .tlb_fill = cris_cpu_tlb_fill,
target/cris/translate.c +0 -6
@@ -3392,9 +3392,3 @@ void cris_initialize_tcg(void) pregnames_v32[i]); } } - -void restore_state_to_opc (CPUCRISState *env,TranslationBlock *tb, -target_ulong *data) -{ - env->pc = data[0 ]; -}
Signature · 1 line
2.34.1
[PULL 10/47] accel/tcg: Split out PageDesc to internal.h
In reply to Richard Henderson--- accel/tcg/internal.h | 31 +++++++++++++++++++++++++++++++ accel/tcg/translate-all.c | 31 +------------------------------ 2 files changed, 32 insertions(+), 30 deletions(-)
accel/tcg/internal.h +31 -0
@@ -11,6 +11,37 @@#include "exec/exec-all.h" +/* +* Access to the various translations structures need to be serialised +* via locks for consistency. In user-mode emulation access to the +* memory related structures are protected with mmap_lock. +* In !user-mode we use per-page locks. +*/ +#ifdef CONFIG_SOFTMMU +#define assert_memory_lock () +#else +#define assert_memory_lock () tcg_debug_assert(have_mmap_lock()) +#endif + +typedef struct PageDesc { +/* list of TBs intersecting this ram page */ +uintptr_t first_tb; +#ifdef CONFIG_USER_ONLY +unsigned long flags; +void *target_data; +#endif +#ifdef CONFIG_SOFTMMU +QemuSpin lock; +#endif +}PageDesc ; + +PageDesc *page_find_alloc (tb_page_addr_t index,bool alloc); + +static inline PageDesc *page_find (tb_page_addr_t index) +{ +return page_find_alloc (index, false); +} +TranslationBlock *tb_gen_code (CPUState *cpu,target_ulong pc,target_ulong cs_base,uint32_t flags,int cflags);
accel/tcg/translate-all.c +1 -30
@@ -65,30 +65,6 @@/* make various TB consistency checks */ -/* Access to the various translations structures need to be serialised via locks -* for consistency. -* In user-mode emulation access to the memory related structures are protected -* with mmap_lock. -* In !user-mode we use per-page locks. -*/ -#ifdef CONFIG_SOFTMMU -#define assert_memory_lock () -#else -#define assert_memory_lock () tcg_debug_assert(have_mmap_lock()) -#endif - -typedef struct PageDesc { -/* list of TBs intersecting this ram page */ -uintptr_t first_tb; -#ifdef CONFIG_USER_ONLY -unsigned long flags; -void *target_data; -#endif -#ifdef CONFIG_SOFTMMU -QemuSpin lock; -#endif -}PageDesc ; -/** * struct page_entry - page descriptor entry * @pd: pointer to the &struct PageDesc of the page this entry represents
@@ -445,7 +421,7 @@ void page_init(void)#endif } -static PageDesc *page_find_alloc (tb_page_addr_t index,bool alloc) +PageDesc *page_find_alloc (tb_page_addr_t index,bool alloc) {PageDesc *pd;void **lp;
@@ -511,11 +487,6 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, bool alloc)return pd + (index & (V_L2_SIZE -1 )); } -static inline PageDesc *page_find (tb_page_addr_t index) -{ -return page_find_alloc (index, false); -} -static void page_lock_pair (PageDesc **ret_p1,tb_page_addr_t phys1,PageDesc **ret_p2,tb_page_addr_t phys2,bool alloc);
Signature · 1 line
2.34.1
[PULL 37/47] target/nios2: Convert to tcg_ops restore_state_to_opc
In reply to Richard Henderson--- target/nios2/cpu.c | 11 +++++++++++ target/nios2/translate.c | 6 ------ 2 files changed, 11 insertions(+), 6 deletions(-)
target/nios2/cpu.c +11 -0
@@ -42,6 +42,16 @@ static vaddr nios2_cpu_get_pc(CPUState *cs)return env->pc; } +static void nios2_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data) +{ +Nios2CPU *cpu =NIOS2_CPU (cs); +CPUNios2State *env = &cpu->env; + + env->pc = data[0 ]; +} +static bool nios2_cpu_has_work (CPUState *cs) {return cs->interrupt_request &CPU_INTERRUPT_HARD ;
@@ -346,6 +356,7 @@ static const struct SysemuCPUOps nios2_sysemu_ops = {static const struct TCGCPUOps nios2_tcg_ops = { .initialize = nios2_tcg_init, + .restore_state_to_opc = nios2_restore_state_to_opc, #ifndef CONFIG_USER_ONLY .tlb_fill = nios2_cpu_tlb_fill,
target/nios2/translate.c +0 -6
@@ -1110,9 +1110,3 @@ void nios2_tcg_init(void) cpu_pc =tcg_global_mem_new (cpu_env, offsetof(CPUNios2State , pc),"pc" ); } - -void restore_state_to_opc (CPUNios2State *env,TranslationBlock *tb, -target_ulong *data) -{ - env->pc = data[0 ]; -}
Signature · 1 line
2.34.1
[PULL 04/47] accel/tcg: Add a quicker check for breakpoints
In reply to Richard HendersonFrom: Leandro Lupori <[email protected]>
Profiling QEMU during Fedora 35 for PPC64 boot revealed that a considerable amount of time was being spent in check_for_breakpoints() (0.61% of total time on PPC64 and 2.19% on amd64), even though it was just checking that its queue was empty and returning, when no breakpoints were set. It turns out this function is not inlined by the compiler and it's always called by helper_lookup_tb_ptr(), one of the most called functions.
By leaving only the check for empty queue in check_for_breakpoints() and moving the remaining code to check_for_breakpoints_slow(), called only when the queue is not empty, it's possible to avoid the call overhead. An improvement of about 3% in total time was measured on POWER9.
Message-Id: <[email protected]>
--- accel/tcg/cpu-exec.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
accel/tcg/cpu-exec.c +9 -6
@@ -304,16 +304,12 @@ static void log_cpu_exec(target_ulong pc, CPUState *cpu, } } -static bool check_for_breakpoints (CPUState *cpu,target_ulong pc, -uint32_t *cflags) +static bool check_for_breakpoints_slow (CPUState *cpu,target_ulong pc, +uint32_t *cflags) {CPUBreakpoint *bp;bool match_page = false; -if (likely (QTAILQ_EMPTY (&cpu->breakpoints))) { -return false; - } -/* * Singlestep overrides breakpoints. * This requirement is visible in the record-replay tests, where
@@ -374,6 +370,13 @@ static bool check_for_breakpoints(CPUState *cpu, target_ulong pc,return false; } +static inline bool check_for_breakpoints (CPUState *cpu,target_ulong pc, +uint32_t *cflags) +{ +return unlikely (!QTAILQ_EMPTY (&cpu->breakpoints)) && +check_for_breakpoints_slow (cpu, pc, cflags); +} +/** * helper_lookup_tb_ptr: quick check for next tb * @env: current cpu state
Signature · 1 line
2.34.1
[PULL 27/47] target/arm: Convert to tcg_ops restore_state_to_opc
In reply to Richard Henderson--- target/arm/cpu.c | 26 ++++++++++++++++++++++++++ target/arm/translate.c | 22 ---------------------- 2 files changed, 26 insertions(+), 22 deletions(-)
target/arm/cpu.c +26 -0
@@ -90,6 +90,31 @@ void arm_cpu_synchronize_from_tb(CPUState *cs, } } } + +static void arm_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data) +{ +CPUARMState *env = cs->env_ptr; + +if (is_a64 (env)) { +if (TARGET_TB_PCREL ) { + env->pc = (env->pc &TARGET_PAGE_MASK ) | data[0 ]; + }else { + env->pc = data[0 ]; + } + env->condexec_bits =0 ; + env->exception.syndrome = data[2 ] <<ARM_INSN_START_WORD2_SHIFT ; + }else { +if (TARGET_TB_PCREL ) { + env->regs[15 ] = (env->regs[15 ] &TARGET_PAGE_MASK ) | data[0 ]; + }else { + env->regs[15 ] = data[0 ]; + } + env->condexec_bits = data[1 ]; + env->exception.syndrome = data[2 ] <<ARM_INSN_START_WORD2_SHIFT ; + } +}#endif /* CONFIG_TCG */ static bool arm_cpu_has_work (CPUState *cs)
@@ -2152,6 +2177,7 @@ static const struct TCGCPUOps arm_tcg_ops = { .initialize = arm_translate_init, .synchronize_from_tb = arm_cpu_synchronize_from_tb, .debug_excp_handler = arm_debug_excp_handler, + .restore_state_to_opc = arm_restore_state_to_opc, #ifdef CONFIG_USER_ONLY .record_sigsegv = arm_cpu_record_sigsegv,
target/arm/translate.c +0 -22
@@ -9939,25 +9939,3 @@ void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns,translator_loop (cpu, tb, max_insns, pc, host_pc, ops, &dc.base); } - -void restore_state_to_opc (CPUARMState *env,TranslationBlock *tb, -target_ulong *data) -{ -if (is_a64 (env)) { -if (TARGET_TB_PCREL ) { - env->pc = (env->pc &TARGET_PAGE_MASK ) | data[0 ]; - }else { - env->pc = data[0 ]; - } - env->condexec_bits =0 ; - env->exception.syndrome = data[2 ] <<ARM_INSN_START_WORD2_SHIFT ; - }else { -if (TARGET_TB_PCREL ) { - env->regs[15 ] = (env->regs[15 ] &TARGET_PAGE_MASK ) | data[0 ]; - }else { - env->regs[15 ] = data[0 ]; - } - env->condexec_bits = data[1 ]; - env->exception.syndrome = data[2 ] <<ARM_INSN_START_WORD2_SHIFT ; - } -}
Signature · 1 line
2.34.1
[PULL 38/47] target/openrisc: Convert to tcg_ops restore_state_to_opc
In reply to Richard Henderson--- target/openrisc/cpu.c | 13 +++++++++++++ target/openrisc/translate.c | 10 ---------- 2 files changed, 13 insertions(+), 10 deletions(-)
target/openrisc/cpu.c +13 -0
@@ -46,6 +46,18 @@ static void openrisc_cpu_synchronize_from_tb(CPUState *cs, cpu->env.pc =tb_pc (tb); } +static void openrisc_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data) +{ +OpenRISCCPU *cpu =OPENRISC_CPU (cs); + + cpu->env.pc = data[0 ]; + cpu->env.dflag = data[1 ] &1 ; +if (data[1 ] &2 ) { + cpu->env.ppc = cpu->env.pc -4 ; + } +}static bool openrisc_cpu_has_work (CPUState *cs) {
@@ -203,6 +215,7 @@ static const struct SysemuCPUOps openrisc_sysemu_ops = {static const struct TCGCPUOps openrisc_tcg_ops = { .initialize = openrisc_translate_init, .synchronize_from_tb = openrisc_cpu_synchronize_from_tb, + .restore_state_to_opc = openrisc_restore_state_to_opc, #ifndef CONFIG_USER_ONLY .tlb_fill = openrisc_cpu_tlb_fill,
target/openrisc/translate.c +0 -10
@@ -1726,13 +1726,3 @@ void openrisc_cpu_dump_state(CPUState *cs, FILE *f, int flags) (i % 4) == 3 ? '\n' : ' '); } } - -void restore_state_to_opc (CPUOpenRISCState *env,TranslationBlock *tb, -target_ulong *data) -{ - env->pc = data[0 ]; - env->dflag = data[1 ] &1 ; -if (data[1 ] &2 ) { - env->ppc = env->pc -4 ; - } -}
Signature · 1 line
2.34.1
[PULL 11/47] accel/tcg: Split out tb-maint.c
In reply to Richard HendersonMove all of the TranslationBlock flushing and page linking code from translate-all.c to tb-maint.c.
--- accel/tcg/internal.h | 55 +++ accel/tcg/tb-maint.c | 735 ++++++++++++++++++++++++++++++++++++ accel/tcg/translate-all.c | 766 +------------------------------------- accel/tcg/meson.build | 1 + 4 files changed, 802 insertions(+), 755 deletions(-) create mode 100644 accel/tcg/tb-maint.c
accel/tcg/internal.h +55 -0
@@ -35,6 +35,27 @@ typedef struct PageDesc {#endif } PageDesc; +/* Size of the L2 (and L3, etc) page tables. */ +#define V_L2_BITS 10 +#define V_L2_SIZE (1 << V_L2_BITS) + +/* +* L1 Mapping properties +*/ +extern int v_l1_size; +extern int v_l1_shift; +extern int v_l2_levels; + +/* +* The bottom level has pointers to PageDesc, and is indexed by +* anything from 4 to (V_L2_BITS + 3) bits, depending on target page size. +*/ +#define V_L1_MIN_BITS 4 +#define V_L1_MAX_BITS (V_L2_BITS + 3) +#define V_L1_MAX_SIZE (1 << V_L1_MAX_BITS) + +extern void *l1_map[V_L1_MAX_SIZE ]; +PageDesc *page_find_alloc (tb_page_addr_t index,bool alloc);static inline PageDesc *page_find (tb_page_addr_t index)
@@ -42,12 +63,46 @@ static inline PageDesc *page_find(tb_page_addr_t index)return page_find_alloc (index, false); } +/* list iterators for lists of tagged pointers in TranslationBlock */ +#define TB_FOR_EACH_TAGGED (head, tb, n, field) \ + for (n = (head) & 1, tb = (TranslationBlock *)((head) & ~1); \ + tb; tb = (TranslationBlock *)tb->field[n], n = (uintptr_t)tb & 1, \ + tb = (TranslationBlock *)((uintptr_t)tb & ~1)) + +#define PAGE_FOR_EACH_TB (pagedesc, tb, n) \ + TB_FOR_EACH_TAGGED((pagedesc)->first_tb, tb, n, page_next) + +#define TB_FOR_EACH_JMP (head_tb, tb, n) \ + TB_FOR_EACH_TAGGED((head_tb)->jmp_list_head, tb, n, jmp_list_next) + +/* In user-mode page locks aren't used; mmap_lock is enough */ +#ifdef CONFIG_USER_ONLY +#define assert_page_locked (pd) tcg_debug_assert(have_mmap_lock()) +static inline void page_lock (PageDesc *pd) { } +static inline void page_unlock (PageDesc *pd) { } +#else +#ifdef CONFIG_DEBUG_TCG +void do_assert_page_locked (const PageDesc *pd,const char *file,int line); +#define assert_page_locked (pd) do_assert_page_locked(pd, __FILE__, __LINE__) +#else +#define assert_page_locked (pd) +#endif +void page_lock (PageDesc *pd); +void page_unlock (PageDesc *pd); +#endif +TranslationBlock *tb_gen_code (CPUState *cpu,target_ulong pc,target_ulong cs_base,uint32_t flags,int cflags); G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);void page_init (void );void tb_htable_init (void ); +void tb_reset_jump (TranslationBlock *tb,int n); +TranslationBlock *tb_link_page (TranslationBlock *tb,tb_page_addr_t phys_pc, +tb_page_addr_t phys_page2); +bool tb_invalidate_phys_page (tb_page_addr_t addr,uintptr_t pc); +int cpu_restore_state_from_tb (CPUState *cpu,TranslationBlock *tb, +uintptr_t searched_pc,bool reset_icount);/* Return the current PC from CPU, which may be cached in TB. */ static inline target_ulong log_pc (CPUState *cpu,const TranslationBlock *tb)
accel/tcg/tb-maint.c new file +735 -0
735 lines not on this page · raw message
accel/tcg/translate-all.c +11 -755
842 lines not on this page · raw message
accel/tcg/meson.build +1 -0
@@ -3,6 +3,7 @@ tcg_ss.add(files( 'tcg-all.c', 'cpu-exec-common.c', 'cpu-exec.c', + 'tb-maint.c', 'tcg-runtime-gvec.c', 'tcg-runtime.c', 'translate-all.c',
Signature · 1 line
2.34.1
[PULL 06/47] include/qemu/atomic: Use qemu_build_assert
In reply to Richard HendersonChange from QEMU_BUILD_BUG_ON, which requires ifdefs to avoid problematic code, to qemu_build_assert, which can use C ifs.
--- include/qemu/atomic.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
include/qemu/atomic.h +8 -8
@@ -133,7 +133,7 @@#define qatomic_read (ptr) \ ({ \ - QEMU_BUILD_BUG_ON(sizeof(*ptr) > ATOMIC_REG_SIZE); \ + qemu_build_assert(sizeof(*ptr) <= ATOMIC_REG_SIZE); \ qatomic_read__nocheck(ptr); \ })
@@ -141,7 +141,7 @@ __atomic_store_n(ptr, i, __ATOMIC_RELAXED)#define qatomic_set (ptr, i) do { \ - QEMU_BUILD_BUG_ON(sizeof(*ptr) > ATOMIC_REG_SIZE); \ + qemu_build_assert(sizeof(*ptr) <= ATOMIC_REG_SIZE); \ qatomic_set__nocheck(ptr, i); \ } while(0)
@@ -159,27 +159,27 @@#define qatomic_rcu_read (ptr) \ ({ \ - QEMU_BUILD_BUG_ON(sizeof(*ptr) > ATOMIC_REG_SIZE); \ + qemu_build_assert(sizeof(*ptr) <= ATOMIC_REG_SIZE); \ typeof_strip_qual(*ptr) _val; \ qatomic_rcu_read__nocheck(ptr, &_val); \ _val; \ })#define qatomic_rcu_set (ptr, i) do { \ - QEMU_BUILD_BUG_ON(sizeof(*ptr) > ATOMIC_REG_SIZE); \ + qemu_build_assert(sizeof(*ptr) <= ATOMIC_REG_SIZE); \ __atomic_store_n(ptr, i, __ATOMIC_RELEASE); \ } while(0)#define qatomic_load_acquire (ptr) \ ({ \ - QEMU_BUILD_BUG_ON(sizeof(*ptr) > ATOMIC_REG_SIZE); \ + qemu_build_assert(sizeof(*ptr) <= ATOMIC_REG_SIZE); \ typeof_strip_qual(*ptr) _val; \ __atomic_load(ptr, &_val, __ATOMIC_ACQUIRE); \ _val; \ })#define qatomic_store_release (ptr, i) do { \ - QEMU_BUILD_BUG_ON(sizeof(*ptr) > ATOMIC_REG_SIZE); \ + qemu_build_assert(sizeof(*ptr) <= ATOMIC_REG_SIZE); \ __atomic_store_n(ptr, i, __ATOMIC_RELEASE); \ } while(0)
@@ -191,7 +191,7 @@ })#define qatomic_xchg (ptr, i) ({ \ - QEMU_BUILD_BUG_ON(sizeof(*ptr) > ATOMIC_REG_SIZE); \ + qemu_build_assert(sizeof(*ptr) <= ATOMIC_REG_SIZE); \ qatomic_xchg__nocheck(ptr, i); \ })
@@ -204,7 +204,7 @@ })#define qatomic_cmpxchg (ptr, old, new) ({ \ - QEMU_BUILD_BUG_ON(sizeof(*ptr) > ATOMIC_REG_SIZE); \ + qemu_build_assert(sizeof(*ptr) <= ATOMIC_REG_SIZE); \ qatomic_cmpxchg__nocheck(ptr, old, new); \ })
Signature · 1 line
2.34.1
[PULL 17/47] accel/tcg: Rename tb_invalidate_phys_page_range and drop end parameter
In reply to Richard HendersonThis function is is never called with a real range, only for a single page. Drop the second parameter and rename to tb_invalidate_phys_page.
--- include/exec/translate-all.h | 2 +- accel/tcg/tb-maint.c | 15 ++++++++------- cpu.c | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-)
include/exec/translate-all.h +1 -1
@@ -29,7 +29,7 @@ void page_collection_unlock(struct page_collection *set);void tb_invalidate_phys_page_fast (struct page_collection *pages,tb_page_addr_t start,int len,uintptr_t retaddr); -void tb_invalidate_phys_page_range (tb_page_addr_t start,tb_page_addr_t end); +void tb_invalidate_phys_page (tb_page_addr_t addr);void tb_check_watchpoint (CPUState *cpu,uintptr_t retaddr);#ifdef CONFIG_USER_ONLY
accel/tcg/tb-maint.c +8 -7
@@ -565,25 +565,26 @@ tb_invalidate_phys_page_range__locked(struct page_collection *pages, }/* -* Invalidate all TBs which intersect with the target physical address range -* [start;end[. NOTE: start and end must refer to the *same* physical page. -* 'is_cpu_write_access' should be true if called from a real cpu write -* access: the virtual CPU will exit the current TB if code is modified inside -* this TB. +* Invalidate all TBs which intersect with the target physical +* address page @addr. * * Called with mmap_lock held for user-mode emulation */ -void tb_invalidate_phys_page_range (tb_page_addr_t start,tb_page_addr_t end) +void tb_invalidate_phys_page (tb_page_addr_t addr) {struct page_collection *pages; +tb_page_addr_t start, end;PageDesc *p;assert_memory_lock (); - p =page_find (start >>TARGET_PAGE_BITS ); + p =page_find (addr >>TARGET_PAGE_BITS );if (p ==NULL ) {return ; } + + start = addr &TARGET_PAGE_MASK ; + end = start +TARGET_PAGE_SIZE ; pages =page_collection_lock (start, end);tb_invalidate_phys_page_range__locked (pages, p, start, end,0 );page_collection_unlock (pages);
cpu.c +2 -2
@@ -277,7 +277,7 @@ void list_cpus(const char *optarg)void tb_invalidate_phys_addr (target_ulong addr) {mmap_lock (); -tb_invalidate_phys_page_range (addr, addr +1 ); +tb_invalidate_phys_page (addr);mmap_unlock (); }#else
@@ -298,7 +298,7 @@ void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr, MemTxAttrs attrs) return; } ram_addr =memory_region_get_ram_addr (mr) + addr; -tb_invalidate_phys_page_range (ram_addr, ram_addr +1 ); +tb_invalidate_phys_page (ram_addr); }#endif
Signature · 1 line
2.34.1
[PULL 46/47] target/xtensa: Convert to tcg_ops restore_state_to_opc
In reply to Richard Henderson--- target/xtensa/cpu.c | 10 ++++++++++ target/xtensa/translate.c | 6 ------ 2 files changed, 10 insertions(+), 6 deletions(-)
target/xtensa/cpu.c +10 -0
@@ -51,6 +51,15 @@ static vaddr xtensa_cpu_get_pc(CPUState *cs)return cpu->env.pc; } +static void xtensa_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data) +{ +XtensaCPU *cpu =XTENSA_CPU (cs); + + cpu->env.pc = data[0 ]; +} +static bool xtensa_cpu_has_work (CPUState *cs) {#ifndef CONFIG_USER_ONLY
@@ -215,6 +224,7 @@ static const struct SysemuCPUOps xtensa_sysemu_ops = {static const struct TCGCPUOps xtensa_tcg_ops = { .initialize = xtensa_translate_init, .debug_excp_handler = xtensa_breakpoint_handler, + .restore_state_to_opc = xtensa_restore_state_to_opc, #ifndef CONFIG_USER_ONLY .tlb_fill = xtensa_cpu_tlb_fill,
target/xtensa/translate.c +0 -6
@@ -1355,12 +1355,6 @@ void xtensa_cpu_dump_state(CPUState *cs, FILE *f, int flags) } } -void restore_state_to_opc (CPUXtensaState *env,TranslationBlock *tb, -target_ulong *data) -{ - env->pc = data[0 ]; -} -static void translate_abs (DisasContext *dc,const OpcodeArg arg[],const uint32_t par[]) {
Signature · 1 line
2.34.1
[PULL 39/47] target/ppc: Convert to tcg_ops restore_state_to_opc
In reply to Richard Henderson--- target/ppc/cpu_init.c | 10 ++++++++++ target/ppc/translate.c | 6 ------ 2 files changed, 10 insertions(+), 6 deletions(-)
target/ppc/cpu_init.c +10 -0
@@ -7221,6 +7221,15 @@ static vaddr ppc_cpu_get_pc(CPUState *cs)return cpu->env.nip; } +static void ppc_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data) +{ +PowerPCCPU *cpu =POWERPC_CPU (cs); + + cpu->env.nip = data[0 ]; +} +static bool ppc_cpu_has_work (CPUState *cs) {PowerPCCPU *cpu =POWERPC_CPU (cs);
@@ -7446,6 +7455,7 @@ static const struct SysemuCPUOps ppc_sysemu_ops = {static const struct TCGCPUOps ppc_tcg_ops = { .initialize = ppc_translate_init, + .restore_state_to_opc = ppc_restore_state_to_opc, #ifdef CONFIG_USER_ONLY .record_sigsegv = ppc_cpu_record_sigsegv,
target/ppc/translate.c +0 -6
@@ -7739,9 +7739,3 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns,translator_loop (cs, tb, max_insns, pc, host_pc, &ppc_tr_ops, &ctx.base); } - -void restore_state_to_opc (CPUPPCState *env,TranslationBlock *tb, -target_ulong *data) -{ - env->nip = data[0 ]; -}
Signature · 1 line
2.34.1
[PULL 40/47] target/riscv: Convert to tcg_ops restore_state_to_opc
In reply to Richard Henderson--- target/riscv/cpu.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
target/riscv/cpu.c +7 -2
@@ -503,10 +503,14 @@ static bool riscv_cpu_has_work(CPUState *cs)#endif } -void restore_state_to_opc (CPURISCVState *env,TranslationBlock *tb, -target_ulong *data) +static void riscv_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data) { +RISCVCPU *cpu =RISCV_CPU (cs); +CPURISCVState *env = &cpu->env;RISCVMXL xl =FIELD_EX32 (tb->flags,TB_FLAGS ,XL ); +if (xl ==MXL_RV32 ) { env->pc = (int32_t )data[0 ]; }else {
@@ -1138,6 +1142,7 @@ static const struct SysemuCPUOps riscv_sysemu_ops = {static const struct TCGCPUOps riscv_tcg_ops = { .initialize = riscv_translate_init, .synchronize_from_tb = riscv_cpu_synchronize_from_tb, + .restore_state_to_opc = riscv_restore_state_to_opc, #ifndef CONFIG_USER_ONLY .tlb_fill = riscv_cpu_tlb_fill,
Signature · 1 line
2.34.1
[PULL 14/47] accel/tcg: Remove duplicate store to tb->page_addr[]
In reply to Richard HendersonWhen we added the fast path, we initialized page_addr[] early. These stores in and around tb_page_add() are redundant; remove them.
--- accel/tcg/tb-maint.c | 3 --- 1 file changed, 3 deletions(-)
accel/tcg/tb-maint.c +0 -3
@@ -405,7 +405,6 @@ static inline void tb_page_add(PageDesc *p, TranslationBlock *tb,assert_page_locked (p); - tb->page_addr[n] = page_addr; tb->page_next[n] = p->first_tb;#ifndef CONFIG_USER_ONLY page_already_protected = p->first_tb != (uintptr_t )NULL ;
@@ -461,8 +460,6 @@ TranslationBlock *tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc,tb_page_add (p, tb,0 , phys_pc);if (p2) {tb_page_add (p2, tb,1 , phys_page2); - }else { - tb->page_addr[1 ] =-1 ; }/* add in the hash table */
Signature · 1 line
2.34.1
[PULL 20/47] accel/tcg: Call tb_invalidate_phys_page for PAGE_RESET
In reply to Richard HendersonWhen PAGE_RESET is set, we are replacing pages with new content, which means that we need to invalidate existing cached data, such as TranslationBlocks. Perform the reset invalidate while we're doing other invalidates, which allows us to remove the separate invalidates from the user-only mmap/munmap/mprotect routines.
In addition, restrict invalidation to PAGE_EXEC pages. Since cdf713085131, we have validated PAGE_EXEC is present before translation, which means we can assume that if the bit is not present, there are no translations to invalidate.
--- accel/tcg/translate-all.c | 19 +++++++++++-------- bsd-user/mmap.c | 2 -- linux-user/mmap.c | 4 ---- 3 files changed, 11 insertions(+), 14 deletions(-)
accel/tcg/translate-all.c +11 -8
@@ -1352,7 +1352,7 @@ int page_get_flags(target_ulong address)void page_set_flags (target_ulong start,target_ulong end,int flags) {target_ulong addr, len; -bool reset_target_data; +bool reset;/* This function should never be called with addresses outside the guest address space. If this assert fires, it probably indicates
@@ -1369,7 +1369,7 @@ void page_set_flags(target_ulong start, target_ulong end, int flags)if (flags &PAGE_WRITE ) { flags |=PAGE_WRITE_ORG ; } - reset_target_data = !(flags &PAGE_VALID ) || (flags &PAGE_RESET ); + reset = !(flags &PAGE_VALID ) || (flags &PAGE_RESET ); flags &= ~PAGE_RESET ; for (addr = start, len = end - start;
@@ -1377,14 +1377,17 @@ void page_set_flags(target_ulong start, target_ulong end, int flags) len -= TARGET_PAGE_SIZE, addr += TARGET_PAGE_SIZE) {PageDesc *p =page_find_alloc (addr >>TARGET_PAGE_BITS , true); -/* If the write protection bit is set, then we invalidate -the code inside. */ -if (!(p->flags &PAGE_WRITE ) && - (flags &PAGE_WRITE ) && - p->first_tb) { +/* +* If the page was executable, but is reset, or is no longer +* executable, or has become writable, then invalidate any code. +*/ +if ((p->flags &PAGE_EXEC ) + && (reset || + !(flags &PAGE_EXEC ) || + (flags & ~p->flags &PAGE_WRITE ))) {tb_invalidate_phys_page (addr); } -if (reset_target_data) { +if (reset) {g_free (p->target_data); p->target_data =NULL ; p->flags = flags;
bsd-user/mmap.c +0 -2
@@ -663,7 +663,6 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,page_dump (stdout);printf ("\n" );#endif -tb_invalidate_phys_range (start, start + len);mmap_unlock ();return start; fail:
@@ -769,7 +768,6 @@ int target_munmap(abi_ulong start, abi_ulong len)if (ret ==0 ) {page_set_flags (start, start + len,0 ); -tb_invalidate_phys_range (start, start + len); }mmap_unlock ();return ret;
linux-user/mmap.c +0 -4
@@ -182,7 +182,6 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) }page_set_flags (start, start + len, page_flags); -tb_invalidate_phys_range (start, start + len); ret =0 ; error:
@@ -662,7 +661,6 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,qemu_log_unlock (f); } } -tb_invalidate_phys_range (start, start + len);mmap_unlock ();return start; fail:
@@ -766,7 +764,6 @@ int target_munmap(abi_ulong start, abi_ulong len)if (ret ==0 ) {page_set_flags (start, start + len,0 ); -tb_invalidate_phys_range (start, start + len); }mmap_unlock ();return ret;
@@ -856,7 +853,6 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,page_set_flags (new_addr, new_addr + new_size, prot |PAGE_VALID |PAGE_RESET ); } -tb_invalidate_phys_range (new_addr, new_addr + new_size);mmap_unlock ();return new_addr; }
Signature · 1 line
2.34.1
[PULL 02/47] tcg/loongarch64: Add direct jump support
In reply to Richard HendersonFrom: Qi Hu <[email protected]>
Similar to the ARM64, LoongArch has PC-relative instructions such as PCADDU18I. These instructions can be used to support direct jump for LoongArch. Additionally, if instruction "B offset" can cover the target address(target is within ±128MB range), a single "B offset" plus a nop will be used by "tb_target_set_jump_target".
Message-Id: <[email protected]>
--- tcg/loongarch64/tcg-target.h | 9 ++++-- tcg/loongarch64/tcg-target.c.inc | 48 +++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 7 deletions(-)
tcg/loongarch64/tcg-target.h +6 -3
@@ -42,7 +42,11 @@#define TCG_TARGET_INSN_UNIT_SIZE 4#define TCG_TARGET_NB_REGS 32 -#define MAX_CODE_GEN_BUFFER_SIZE SIZE_MAX +/* +* PCADDU18I + JIRL sequence can give 20 + 16 + 2 = 38 bits +* signed offset, which is +/- 128 GiB. +*/ +#define MAX_CODE_GEN_BUFFER_SIZE (128 * GiB) typedef enum { TCG_REG_ZERO,
@@ -123,7 +127,7 @@ typedef enum {#define TCG_TARGET_HAS_clz_i32 1#define TCG_TARGET_HAS_ctz_i32 1#define TCG_TARGET_HAS_ctpop_i32 0 -#define TCG_TARGET_HAS_direct_jump 0 +#define TCG_TARGET_HAS_direct_jump 1#define TCG_TARGET_HAS_brcond2 0#define TCG_TARGET_HAS_setcond2 0#define TCG_TARGET_HAS_qemu_st8_i32 0
@@ -166,7 +170,6 @@ typedef enum {#define TCG_TARGET_HAS_muluh_i64 1#define TCG_TARGET_HAS_mulsh_i64 1 -/* not defined -- call should be eliminated at compile time */ void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t ,uintptr_t );#define TCG_TARGET_DEFAULT_MO (0)
tcg/loongarch64/tcg-target.c.inc +44 -4
60 lines not on this page · raw message
Signature · 1 line
2.34.1
[PULL 41/47] target/rx: Convert to tcg_ops restore_state_to_opc
In reply to Richard Henderson--- target/rx/cpu.c | 10 ++++++++++ target/rx/translate.c | 6 ------ 2 files changed, 10 insertions(+), 6 deletions(-)
target/rx/cpu.c +10 -0
@@ -47,6 +47,15 @@ static void rx_cpu_synchronize_from_tb(CPUState *cs, cpu->env.pc =tb_pc (tb); } +static void rx_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data) +{ +RXCPU *cpu =RX_CPU (cs); + + cpu->env.pc = data[0 ]; +} +static bool rx_cpu_has_work (CPUState *cs) { return cs->interrupt_request &
@@ -192,6 +201,7 @@ static const struct SysemuCPUOps rx_sysemu_ops = {static const struct TCGCPUOps rx_tcg_ops = { .initialize = rx_translate_init, .synchronize_from_tb = rx_cpu_synchronize_from_tb, + .restore_state_to_opc = rx_restore_state_to_opc, .tlb_fill = rx_cpu_tlb_fill, #ifndef CONFIG_USER_ONLY
target/rx/translate.c +0 -6
@@ -2371,12 +2371,6 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns,translator_loop (cs, tb, max_insns, pc, host_pc, &rx_tr_ops, &dc.base); } -void restore_state_to_opc (CPURXState *env,TranslationBlock *tb, -target_ulong *data) -{ - env->pc = data[0 ]; -} -#define ALLOC_REGISTER (sym, name) \ cpu_##sym = tcg_global_mem_new_i32(cpu_env, \ offsetof(CPURXState, sym), name)
Signature · 1 line
2.34.1
[PULL 32/47] target/i386: Convert to tcg_ops restore_state_to_opc
In reply to Richard Henderson--- target/i386/tcg/tcg-cpu.c | 19 +++++++++++++++++++ target/i386/tcg/translate.c | 15 --------------- 2 files changed, 19 insertions(+), 15 deletions(-)
target/i386/tcg/tcg-cpu.c +19 -0
@@ -56,6 +56,24 @@ static void x86_cpu_synchronize_from_tb(CPUState *cs, } } +static void x86_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data) +{ +X86CPU *cpu =X86_CPU (cs); +CPUX86State *env = &cpu->env; +int cc_op = data[1 ]; + +if (TARGET_TB_PCREL ) { + env->eip = (env->eip &TARGET_PAGE_MASK ) | data[0 ]; + }else { + env->eip = data[0 ] - tb->cs_base; + } +if (cc_op !=CC_OP_DYNAMIC ) { + env->cc_op = cc_op; + } +} +#ifndef CONFIG_USER_ONLY static bool x86_debug_check_breakpoint (CPUState *cs) {
@@ -72,6 +90,7 @@ static bool x86_debug_check_breakpoint(CPUState *cs)static const struct TCGCPUOps x86_tcg_ops = { .initialize = tcg_x86_init, .synchronize_from_tb = x86_cpu_synchronize_from_tb, + .restore_state_to_opc = x86_restore_state_to_opc, .cpu_exec_enter = x86_cpu_exec_enter, .cpu_exec_exit = x86_cpu_exec_exit, #ifdef CONFIG_USER_ONLY
target/i386/tcg/translate.c +0 -15
@@ -7023,18 +7023,3 @@ void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns,translator_loop (cpu, tb, max_insns, pc, host_pc, &i386_tr_ops, &dc.base); } - -void restore_state_to_opc (CPUX86State *env,TranslationBlock *tb, -target_ulong *data) -{ -int cc_op = data[1 ]; - -if (TARGET_TB_PCREL ) { - env->eip = (env->eip &TARGET_PAGE_MASK ) | data[0 ]; - }else { - env->eip = data[0 ] - tb->cs_base; - } -if (cc_op !=CC_OP_DYNAMIC ) { - env->cc_op = cc_op; - } -}
Signature · 1 line
2.34.1
[PULL 09/47] accel/tcg: Remove disabled debug in translate-all.c
In reply to Richard HendersonThese items printf, and could be replaced with proper tracepoints if we really cared.
--- accel/tcg/translate-all.c | 109 -------------------------------------- 1 file changed, 109 deletions(-)
accel/tcg/translate-all.c +0 -109
@@ -63,33 +63,7 @@#include "tb-context.h" #include "internal.h" -/* #define DEBUG_TB_INVALIDATE */ -/* #define DEBUG_TB_FLUSH */ /* make various TB consistency checks */ -/* #define DEBUG_TB_CHECK */ - -#ifdef DEBUG_TB_INVALIDATE -#define DEBUG_TB_INVALIDATE_GATE 1 -#else -#define DEBUG_TB_INVALIDATE_GATE 0 -#endif - -#ifdef DEBUG_TB_FLUSH -#define DEBUG_TB_FLUSH_GATE 1 -#else -#define DEBUG_TB_FLUSH_GATE 0 -#endif - -#if !defined(CONFIG_USER_ONLY ) -/* TB consistency checks only implemented for usermode emulation. */ -#undef DEBUG_TB_CHECK -#endif - -#ifdef DEBUG_TB_CHECK -#define DEBUG_TB_CHECK_GATE 1 -#else -#define DEBUG_TB_CHECK_GATE 0 -#endif /* Access to the various translations structures need to be serialised via locks * for consistency.
@@ -940,15 +914,6 @@ static void page_flush_tb(void) } } -static gboolean tb_host_size_iter (gpointer key,gpointer value,gpointer data) -{ -const TranslationBlock *tb = value; -size_t *size = data; - - *size += tb->tc.size; -return false; -} -/* flush all the translation blocks */ static void do_tb_flush (CPUState *cpu,run_on_cpu_data tb_flush_count) {
@@ -963,15 +928,6 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) } did_flush = true; -if (DEBUG_TB_FLUSH_GATE ) { -size_t nb_tbs =tcg_nb_tbs (); -size_t host_size =0 ; - -tcg_tb_foreach (tb_host_size_iter, &host_size); -printf ("qemu: flush code_size=%zu nb_tbs=%zu avg_tb_size=%zu\n" , -tcg_code_size (), nb_tbs, nb_tbs >0 ? host_size / nb_tbs :0 ); - } -CPU_FOREACH (cpu) {tcg_flush_jmp_cache (cpu); }
@@ -1005,57 +961,6 @@ void tb_flush(CPUState *cpu) } } -/* -* Formerly ifdef DEBUG_TB_CHECK. These debug functions are user-mode-only, -* so in order to prevent bit rot we compile them unconditionally in user-mode, -* and let the optimizer get rid of them by wrapping their user-only callers -* with if (DEBUG_TB_CHECK_GATE). -*/ -#ifdef CONFIG_USER_ONLY - -static void do_tb_invalidate_check (void *p,uint32_t hash,void *userp) -{ -TranslationBlock *tb = p; -target_ulong addr = *(target_ulong *)userp; - -if (!(addr +TARGET_PAGE_SIZE <=tb_pc (tb) || - addr >=tb_pc (tb) + tb->size)) { -printf ("ERROR invalidate: address=" TARGET_FMT_lx -" PC=%08lx size=%04x\n" , addr, (long )tb_pc (tb), tb->size); - } -} - -/* verify that all the pages have correct rights for code -* -* Called with mmap_lock held. -*/ -static void tb_invalidate_check (target_ulong address) -{ - address &=TARGET_PAGE_MASK ; -qht_iter (&tb_ctx.htable, do_tb_invalidate_check, &address); -} - -static void do_tb_page_check (void *p,uint32_t hash,void *userp) -{ -TranslationBlock *tb = p; -int flags1, flags2; - - flags1 =page_get_flags (tb_pc (tb)); - flags2 =page_get_flags (tb_pc (tb) + tb->size -1 ); -if ((flags1 &PAGE_WRITE ) || (flags2 &PAGE_WRITE )) { -printf ("ERROR page flags: PC=%08lx size=%04x f1=%x f2=%x\n" , - (long )tb_pc (tb), tb->size, flags1, flags2); - } -} - -/* verify that all the pages have correct rights for code */ -static void tb_page_check (void ) -{ -qht_iter (&tb_ctx.htable, do_tb_page_check,NULL ); -} - -#endif /* CONFIG_USER_ONLY */ -/* * user-mode: call with mmap_lock held * !user-mode: call with @pd->lock held
@@ -1339,12 +1244,6 @@ tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc,page_unlock (p2); }page_unlock (p); - -#ifdef CONFIG_USER_ONLY -if (DEBUG_TB_CHECK_GATE ) { -tb_page_check (); - } -#endif return tb; }
@@ -2400,9 +2299,6 @@ void page_protect(tb_page_addr_t page_addr) }mprotect (g2h_untagged (page_addr), qemu_host_page_size, (prot &PAGE_BITS ) & ~PAGE_WRITE ); -if (DEBUG_TB_INVALIDATE_GATE ) { -printf ("protecting code page: 0x" TB_PAGE_ADDR_FMT "\n" , page_addr); - } } }
@@ -2458,11 +2354,6 @@ int page_unprotect(target_ulong address, uintptr_t pc)/* and since the content will be modified, we must invalidate the corresponding translated code. */ current_tb_invalidated |=tb_invalidate_phys_page (addr, pc); -#ifdef CONFIG_USER_ONLY -if (DEBUG_TB_CHECK_GATE ) { -tb_invalidate_check (addr); - } -#endif }mprotect ((void *)g2h_untagged (host_start), qemu_host_page_size, prot &PAGE_BITS );
Signature · 1 line
2.34.1
[PULL 07/47] include/qemu/thread: Use qatomic_* functions
In reply to Richard HendersonUse qatomic_*, which expands to __atomic_* in preference to the "legacy" __sync_* functions.
--- include/qemu/thread.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
include/qemu/thread.h +4 -4
@@ -227,7 +227,7 @@ struct QemuSpin {static inline void qemu_spin_init (QemuSpin *spin) { -__sync_lock_release (&spin->value); +qatomic_set (&spin->value,0 );#ifdef CONFIG_TSAN __tsan_mutex_create (spin, __tsan_mutex_not_static);#endif
@@ -246,7 +246,7 @@ static inline void qemu_spin_lock(QemuSpin *spin)#ifdef CONFIG_TSAN __tsan_mutex_pre_lock (spin,0 );#endif -while (unlikely (__sync_lock_test_and_set (&spin->value, true))) { +while (unlikely (qatomic_xchg (&spin->value,1 ))) {while (qatomic_read (&spin->value)) {cpu_relax (); }
@@ -261,7 +261,7 @@ static inline bool qemu_spin_trylock(QemuSpin *spin)#ifdef CONFIG_TSAN __tsan_mutex_pre_lock (spin, __tsan_mutex_try_lock);#endif -bool busy =__sync_lock_test_and_set (&spin->value, true); +bool busy =qatomic_xchg (&spin->value, true);#ifdef CONFIG_TSAN unsigned flags = __tsan_mutex_try_lock; flags |= busy ? __tsan_mutex_try_lock_failed :0 ;
@@ -280,7 +280,7 @@ static inline void qemu_spin_unlock(QemuSpin *spin)#ifdef CONFIG_TSAN __tsan_mutex_pre_unlock (spin,0 );#endif -__sync_lock_release (&spin->value); +qatomic_store_release (&spin->value,0 );#ifdef CONFIG_TSAN __tsan_mutex_post_unlock (spin,0 );#endif
Signature · 1 line
2.34.1
[PULL 25/47] accel/tcg: Add restore_state_to_opc to TCGCPUOps
In reply to Richard HendersonAdd a tcg_ops hook to replace the restore_state_to_opc function call. Because these generic hooks cannot depend on target-specific types, temporarily, copy the current target_ulong data[] into uint64_t d64[].
--- include/exec/exec-all.h | 2 +- include/hw/core/tcg-cpu-ops.h | 11 +++++++++++ accel/tcg/translate-all.c | 24 ++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 3 deletions(-)
include/exec/exec-all.h +1 -1
@@ -40,7 +40,7 @@ typedef ram_addr_t tb_page_addr_t;#endif void restore_state_to_opc (CPUArchState *env,TranslationBlock *tb, -target_ulong *data); +target_ulong *data) __attribute__((weak));/** * cpu_restore_state:
include/hw/core/tcg-cpu-ops.h +11 -0
@@ -31,6 +31,17 @@ struct TCGCPUOps {* function to restore all the state, and register it here. */ void (*synchronize_from_tb)(CPUState *cpu,const TranslationBlock *tb); +/** +* @restore_state_to_opc: Synchronize state from INDEX_op_start_insn +* +* This is called when we unwind state in the middle of a TB, +* usually before raising an exception. Set all part of the CPU +* state which are tracked insn-by-insn in the target-specific +* arguments to start_insn, passed as @data. +*/ +void (*restore_state_to_opc)(CPUState *cpu,const TranslationBlock *tb, +const uint64_t *data); +/** @cpu_exec_enter: Callback for cpu_exec preparation */ void (*cpu_exec_enter)(CPUState *cpu);/** @cpu_exec_exit: Callback for cpu_exec cleanup */
accel/tcg/translate-all.c +22 -2
@@ -256,7 +256,6 @@ int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb, {target_ulong data[TARGET_INSN_START_WORDS ];uintptr_t host_pc = (uintptr_t )tb->tc.ptr; -CPUArchState *env = cpu->env_ptr;const uint8_t *p = tb->tc.ptr + tb->tc.size;int i, j, num_insns = tb->icount;#ifdef CONFIG_PROFILER
@@ -295,7 +294,20 @@ int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb,and shift if to the number of actually executed instructions */ cpu_neg (cpu)->icount_decr.u16.low += num_insns - i; } -restore_state_to_opc (env, tb, data); + + { +const struct TCGCPUOps *ops = cpu->cc->tcg_ops; + __typeof(ops->restore_state_to_opc) restore = ops->restore_state_to_opc; +if (restore) { +uint64_t d64[TARGET_INSN_START_WORDS ]; +for (i =0 ; i <TARGET_INSN_START_WORDS ; ++i) { + d64[i] = data[i]; + } +restore (cpu, tb, d64); + }else { +restore_state_to_opc (cpu->env_ptr, tb, data); + } + }#ifdef CONFIG_PROFILER qatomic_set(&prof->restore_time,
@@ -307,6 +319,14 @@ int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb,bool cpu_restore_state (CPUState *cpu,uintptr_t host_pc,bool will_exit) { +/* +* The pc update associated with restore without exit will +* break the relative pc adjustments performed by TARGET_TB_PCREL. +*/ +if (TARGET_TB_PCREL ) { +assert (will_exit); + } +/* * 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.
Signature · 1 line
2.34.1
Re: [PULL 25/47] accel/tcg: Add restore_state_to_opc to TCGCPUOps
Quoted 7 lines · Richard Henderson
Add a
tcg_opshook to replace therestore_state_to_opcfunction call. Because these generic hooks cannot depend on target-specific types, temporarily, copy the currenttarget_ulongdata[] intouint64_td64[].Reviewed-by Claudio Fontana <[email protected]>Signed-off-by Richard Henderson <[email protected]>
This has triggered a regression in x86_64 stuff:
➜ make -j30
GIT ui/keycodemapdb tests/fp/berkeley-testfloat-3 tests/fp/berkeley-softfloat-3 dtc
[1/9] Generating qemu-version.h with a custom command (wrapped by meson to capture output)
🕙11:41:11 alex.bennee@hackbox2:qemu.git/builds/bisect on HEAD (8269c01) (BISECTING) [$?]
➜ ./tests/venv/bin/avocado run tests/avocado/boot_linux.py:BootLinuxX8664.test_pc_i440fx_tcg tests/avocado/boot_linux.py:BootLinuxX8664.test_pc_q35_tcg tests/avocado/linux_ initrd.py:LinuxInitrd.test_with_2gib_file_should_work_with_linux_v4_16 tests/avocado/replay_kernel.py:ReplayKernelNormal.test_x86_64_pc
Fetching asset from tests/avocado/linux_initrd.py:LinuxInitrd.test_with_2gib_file_should_work_with_linux_v4_16
Fetching asset from tests/avocado/replay_kernel.py:ReplayKernelNormal.test_x86_64_pc
JOB ID : 1d6ae71471e46c091ed06acc59a077c10b7b1ff9
JOB LOG : /home/alex.bennee/avocado/job-results/job-2022-10-29T11.41-1d6ae71/job.log
(1/4) tests/avocado/boot_linux.py:BootLinuxX8664.test_pc_i440fx_tcg: PASS (80.15 s)
(2/4) tests/avocado/boot_linux.py:BootLinuxX8664.test_pc_q35_tcg: PASS (69.03 s)
(3/4) tests/avocado/linux_initrd.py:LinuxInitrd.test_with_2gib_file_should_work_with_linux_v4_16: PASS (14.37 s)
(4/4) tests/avocado/replay_kernel.py:ReplayKernelNormal.test_x86_64_pc: PASS (71.81 s)
RESULTS : PASS 4 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB TIME : 235.96 s
🕙11:45:10 alex.bennee@hackbox2:qemu.git/builds/bisect on HEAD (d292568) (BISECTING) [$?] took 3m56s
➜ ninja build
ninja: error: unknown target 'build'
🕙11:45:21 alex.bennee@hackbox2:qemu.git/builds/bisect on HEAD (d292568) (BISECTING) [$?] [🔴 ERROR]
✗ ninja
[56/56] Linking target qemu-system-x86_64
🕙11:45:29 alex.bennee@hackbox2:qemu.git/builds/bisect on HEAD (d292568) (BISECTING) [$?] took 4s
➜ ./tests/venv/bin/avocado run tests/avocado/boot_linux.py:BootLinuxX8664.test_pc_i440fx_tcg tests/avocado/boot_linux.py:BootLinuxX8664.test_pc_q35_tcg tests/avocado/linux_ initrd.py:LinuxInitrd.test_with_2gib_file_should_work_with_linux_v4_16 tests/avocado/replay_kernel.py:ReplayKernelNormal.test_x86_64_pc
Fetching asset from tests/avocado/linux_initrd.py:LinuxInitrd.test_with_2gib_file_should_work_with_linux_v4_16
Fetching asset from tests/avocado/replay_kernel.py:ReplayKernelNormal.test_x86_64_pc
JOB ID : a1c449facd31a2907520e6971a66a3a5529c3bd2
JOB LOG : /home/alex.bennee/avocado/job-results/job-2022-10-29T11.45-a1c449f/job.log
(1/4) tests/avocado/boot_linux.py:BootLinuxX8664.test_pc_i440fx_tcg: INTERRUPTED: Test interrupted by SIGTERM\nRunner error occurred: Timeout reached\nOriginal status: ERRO
R\n{'name': '1-tests/avocado/boot_linux.py:BootLinuxX8664.test_pc_i440fx_tcg', 'logdir': '/home/alex.bennee/avocado/job-results/job-2022-10-29T11.45-a1c449f/test-result... (120.58 s)
(2/4) tests/avocado/boot_linux.py:BootLinuxX8664.test_pc_q35_tcg: INTERRUPTED: Test interrupted by SIGTERM\nRunner error occurred: Timeout reached\nOriginal status: ERROR\n
{'name': '2-tests/avocado/boot_linux.py:BootLinuxX8664.test_pc_q35_tcg', 'logdir': '/home/alex.bennee/avocado/job-results/job-2022-10-29T11.45-a1c449f/test-results/2... (120.59 s)
(3/4) tests/avocado/linux_initrd.py:LinuxInitrd.test_with_2gib_file_should_work_with_linux_v4_16: INTERRUPTED: Test died without reporting the status.\nRunner error occurre
d: Timeout reached\nOriginal status: ERROR\n{'name': '3-tests/avocado/linux_initrd.py:LinuxInitrd.test_with_2gib_file_should_work_with_linux_v4_16', 'logdir': '/home/alex.bennee/avocado/job-results... (311.46 s)
(4/4) tests/avocado/replay_kernel.py:ReplayKernelNormal.test_x86_64_pc: INTERRUPTED: Test interrupted by SIGTERM\nRunner error occurred: Timeout reached\nOriginal status: E
RROR\n{'name': '4-tests/avocado/replay_kernel.py:ReplayKernelNormal.test_x86_64_pc', 'logdir': '/home/alex.bennee/avocado/job-results/job-2022-10-29T11.45-a1c449f/test-res... (120.58 s)
RESULTS : PASS 0 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 4 | CANCEL 0
JOB TIME : 676.41 s
🕙11:56:59 alex.bennee@hackbox2:qemu.git/builds/bisect on HEAD (d292568) (BISECTING) [$?] took 11m28s [🔴 8]
✗
Quoted 90 lines
--- include/exec/exec-all.h | 2 +- include/hw/core/tcg-cpu-ops.h | 11 +++++++++++ accel/tcg/translate-all.c | 24 ++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 3 deletions(-)include/exec/exec-all.h +1
-1@@ -40,7 +40,7 @@ typedef ram_addr_t tb_page_addr_t;#endif void restore_state_to_opc (CPUArchState *env,TranslationBlock *tb, -target_ulong *data); +target_ulong *data) __attribute__((weak));/** * cpu_restore_state: include/hw/core/tcg-cpu-ops.h +11
-0@@ -31,6 +31,17 @@ struct TCGCPUOps {* function to restore all the state, and register it here. */ void (*synchronize_from_tb)(CPUState *cpu,const TranslationBlock *tb); +/** +* @restore_state_to_opc: Synchronize state from INDEX_op_start_insn +* +* This is called when we unwind state in the middle of a TB, +* usually before raising an exception. Set all part of the CPU +* state which are tracked insn-by-insn in the target-specific +* arguments to start_insn, passed as @data. +*/ +void (*restore_state_to_opc)(CPUState *cpu,const TranslationBlock *tb, +const uint64_t *data); +/** @cpu_exec_enter: Callback for cpu_exec preparation */ void (*cpu_exec_enter)(CPUState *cpu);/** @cpu_exec_exit: Callback for cpu_exec cleanup */ accel/tcg/translate-all.c +22
-2@@ -256,7 +256,6 @@ int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb, {target_ulong data[TARGET_INSN_START_WORDS ];uintptr_t host_pc = (uintptr_t )tb->tc.ptr; -CPUArchState *env = cpu->env_ptr;const uint8_t *p = tb->tc.ptr + tb->tc.size;int i, j, num_insns = tb->icount;#ifdef CONFIG_PROFILER @@ -295,7 +294,20 @@ int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb,and shift if to the number of actually executed instructions */ cpu_neg (cpu)->icount_decr.u16.low += num_insns - i; } -restore_state_to_opc (env, tb, data); + + { +const struct TCGCPUOps *ops = cpu->cc->tcg_ops; + __typeof(ops->restore_state_to_opc) restore = ops->restore_state_to_opc; +if (restore) { +uint64_t d64[TARGET_INSN_START_WORDS ]; +for (i =0 ; i <TARGET_INSN_START_WORDS ; ++i) { + d64[i] = data[i]; + } +restore (cpu, tb, d64); + }else { +restore_state_to_opc (cpu->env_ptr, tb, data); + } + }#ifdef CONFIG_PROFILER qatomic_set(&prof->restore_time,@@ -307,6 +319,14 @@ int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb,bool cpu_restore_state (CPUState *cpu,uintptr_t host_pc,bool will_exit) { +/* +* The pc update associated with restore without exit will +* break the relative pc adjustments performed by TARGET_TB_PCREL. +*/ +if (TARGET_TB_PCREL ) { +assert (will_exit); + } +/* * 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.
Signature · 1 line
Alex Bennée
Re: [PULL 25/47] accel/tcg: Add restore_state_to_opc to TCGCPUOps
Quoted 8 lines · Alex Bennée
Quoted 5 lines · Richard Henderson
Add a
tcg_opshook to replace therestore_state_to_opcfunction call. Because these generic hooks cannot depend on target-specific types, temporarily, copy the currenttarget_ulongdata[] intouint64_td64[].
Quoted 4 lines
Quoted 2 lines
Reviewed-by Claudio Fontana <[email protected]>Signed-off-by Richard Henderson <[email protected]>This has triggered a regression in
x86_64stuff:
Patches posted: [email protected] ("[PATCH v2 0/6] tcg: Fix x86 TARGET_TB_PCREL (#1269)")
r~
Re: [PULL 25/47] accel/tcg: Add restore_state_to_opc to TCGCPUOps
In reply to Richard HendersonQuoted 8 lines · CET Richard Henderson
Add a
tcg_opshook to replace therestore_state_to_opcfunction call. Because these generic hooks cannot depend on target-specific types, temporarily, copy the currenttarget_ulongdata[] intouint64_td64[].Reviewed-by Claudio Fontana <[email protected]>Signed-off-by Richard Henderson <[email protected]>---
[...]
Quoted 4 lines
accel/tcg/translate-all.c +0
-0
[...]
accel/tcg/translate-all.c int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb, · line 332
Quoted 13 lines
bool
cpu_restore_state(CPUState *cpu, uintptr_t host_pc, bool will_exit){accel/tcg/translate-all.c +8
-0+/* +* The pc update associated with restore without exit will +* break the relative pc adjustments performed by TARGET_TB_PCREL. +*/ +if (TARGET_TB_PCREL ) { +assert (will_exit); + } +/* * 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.
This patch appears to break macOS host. This assertion always triggers on Apple Silicon. Previous patch 8269c01417 runs fine. Any ideas?
BTW Richard, could you add a message-id tag to your queued TCG patches? If you are using patchwork client then it suffices to add "msgid=on" to .pwclientrc
Best regards,
Christian Schoenebeck
Re: [PULL 25/47] accel/tcg: Add restore_state_to_opc to TCGCPUOps
Quoted 29 lines · Christian Schoenebeck
Quoted 8 lines · CET Richard Henderson
Add a
tcg_opshook to replace therestore_state_to_opcfunction call. Because these generic hooks cannot depend on target-specific types, temporarily, copy the currenttarget_ulongdata[] intouint64_td64[].Reviewed-by Claudio Fontana <[email protected]>Signed-off-by Richard Henderson <[email protected]>---
[...]
Quoted 4 lines
accel/tcg/translate-all.c +0
-0[...]
accel/tcg/translate-all.c int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb, · line 332
Quoted 13 lines
bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc, bool will_exit) {accel/tcg/translate-all.c +8
-0+/* +* The pc update associated with restore without exit will +* break the relative pc adjustments performed by TARGET_TB_PCREL. +*/ +if (TARGET_TB_PCREL ) { +assert (will_exit); + } +/* * 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.
Quoted 2 lines
This patch appears to break macOS host. This assertion always triggers on Apple Silicon. Previous patch
8269c01417runs fine. Any ideas?
It does not previously work fine. See
https://gitlab.com/qemu-project/qemu/-/issues/1269
which also contains a link to the in-flight patches.
Quoted 1 line
BTW Richard, could you add a message-id tag to your queued TCG patches?
Sometimes I remember, but I don't use the same tooling for my own work as I do for queuing other people's. I haven't found much value in it.
Quoted 2 lines
If you
are using patchwork client then it suffices to add "msgid=on" to .pwclientrc
I am not.
r~
Re: [PULL 25/47] accel/tcg: Add restore_state_to_opc to TCGCPUOps
Quoted 4 lines · Richard Henderson
Quoted 2 lines · Christian Schoenebeck
On Wednesday, October 26, 2022 4:10:54 AM CET Richard Henderson wrote:
BTW Richard, could you add a message-id tag to your queued TCG patches?
Quoted 8 lines
Sometimes I remember, but I don't use the same tooling for my own work as I do for queuing other people's. I haven't found much value in it.
Quoted 2 lines
If you
are using patchwork client then it suffices to add "msgid=on" to .pwclientrcI am not.
Tools that boil down to git-am(1) need to add the -m (--message-id) flag.
Stefan
Re: [PULL 25/47] accel/tcg: Add restore_state_to_opc to TCGCPUOps
Quoted 10 lines · Stefan Hajnoczi
Quoted 8 lines · Richard Henderson
Quoted 2 lines · Christian Schoenebeck
On Wednesday, October 26, 2022 4:10:54 AM CET Richard Henderson wrote:
BTW Richard, could you add a message-id tag to your queued TCG patches?Sometimes I remember, but I don't use the same tooling for my own work as I do for queuing other people's. I haven't found much value in it.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
If you
are using patchwork client then it suffices to add "msgid=on" to .pwclientrcI am not.
Tools that boil down to git-am(1) need to add the -m (--message-id) flag.
FWIW in my local QEMU git checkout I've run "git config am.messageid true" which alters .git/config so that the -m flag is enabled by default for "git am" commands.
ATB,
Mark.
Re: [PULL 25/47] accel/tcg: Add restore_state_to_opc to TCGCPUOps
Quoted 12 lines · Mark Cave-Ayland
Quoted 10 lines · Stefan Hajnoczi
Quoted 8 lines · Richard Henderson
Quoted 2 lines · Christian Schoenebeck
On Wednesday, October 26, 2022 4:10:54 AM CET Richard Henderson wrote:
BTW Richard, could you add a message-id tag to your queued TCG patches?Sometimes I remember, but I don't use the same tooling for my own work as I do for queuing other people's. I haven't found much value in it.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
If you
are using patchwork client then it suffices to add "msgid=on" to .pwclientrcI am not.
Tools that boil down to git-am(1) need to add the -m (--message-id) flag.
FWIW in my local QEMU git checkout I've run "git config am.messageid true" which alters .git/config so that the -m flag is enabled by default for "git am" commands.
This all supposes that one uses git am for ones own patches, which I do not.
r~
[PULL 42/47] target/s390x: Convert to tcg_ops restore_state_to_opc
In reply to Richard Henderson--- target/s390x/s390x-internal.h | 4 +++- target/s390x/cpu.c | 1 + target/s390x/tcg/translate.c | 7 +++++-- 3 files changed, 9 insertions(+), 3 deletions(-)
target/s390x/s390x-internal.h +3 -1
@@ -398,7 +398,9 @@ void handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3,/* translate.c */ void s390x_translate_init (void ); - +void s390x_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data);/* sigp.c */ int handle_sigp (CPUS390XState *env,uint8_t order,uint64_t r1,uint64_t r3);
target/s390x/cpu.c +1 -0
@@ -272,6 +272,7 @@ static void s390_cpu_reset_full(DeviceState *dev)static const struct TCGCPUOps s390_tcg_ops = { .initialize = s390x_translate_init, + .restore_state_to_opc = s390x_restore_state_to_opc, #ifdef CONFIG_USER_ONLY .record_sigsegv = s390_cpu_record_sigsegv,
target/s390x/tcg/translate.c +5 -2
@@ -6691,9 +6691,12 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns,translator_loop (cs, tb, max_insns, pc, host_pc, &s390x_tr_ops, &dc.base); } -void restore_state_to_opc (CPUS390XState *env,TranslationBlock *tb, -target_ulong *data) +void s390x_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data) { +S390CPU *cpu =S390_CPU (cs); +CPUS390XState *env = &cpu->env;int cc_op = data[1 ]; env->psw.addr = data[0 ];
Signature · 1 line
2.34.1
[PULL 16/47] accel/tcg: Rename tb_invalidate_phys_page
In reply to Richard HendersonRename to tb_invalidate_phys_page_unwind to emphasize that we also detect invalidating the current TB, and also to free up that name for other usage.
--- accel/tcg/internal.h | 2 +- accel/tcg/tb-maint.c | 2 +- accel/tcg/translate-all.c | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-)
accel/tcg/internal.h +1 -1
@@ -105,7 +105,7 @@ void tb_htable_init(void);void tb_reset_jump (TranslationBlock *tb,int n);TranslationBlock *tb_link_page (TranslationBlock *tb,tb_page_addr_t phys_pc,tb_page_addr_t phys_page2); -bool tb_invalidate_phys_page (tb_page_addr_t addr,uintptr_t pc); +bool tb_invalidate_phys_page_unwind (tb_page_addr_t addr,uintptr_t pc);int cpu_restore_state_from_tb (CPUState *cpu,TranslationBlock *tb,uintptr_t searched_pc,bool reset_icount);
accel/tcg/tb-maint.c +1 -1
@@ -657,7 +657,7 @@ void tb_invalidate_phys_page_fast(struct page_collection *pages,* TB (because it was modified by this store and the guest CPU has * precise-SMC semantics). */ -bool tb_invalidate_phys_page (tb_page_addr_t addr,uintptr_t pc) +bool tb_invalidate_phys_page_unwind (tb_page_addr_t addr,uintptr_t pc) {TranslationBlock *tb;PageDesc *p;
accel/tcg/translate-all.c +3 -2
@@ -1382,7 +1382,7 @@ void page_set_flags(target_ulong start, target_ulong end, int flags)if (!(p->flags &PAGE_WRITE ) && (flags &PAGE_WRITE ) && p->first_tb) { -tb_invalidate_phys_page (addr,0 ); +tb_invalidate_phys_page_unwind (addr,0 ); }if (reset_target_data) {g_free (p->target_data);
@@ -1580,7 +1580,8 @@ int page_unprotect(target_ulong address, uintptr_t pc)/* and since the content will be modified, we must invalidate the corresponding translated code. */ - current_tb_invalidated |=tb_invalidate_phys_page (addr, pc); + current_tb_invalidated |= +tb_invalidate_phys_page_unwind (addr, pc); }mprotect ((void *)g2h_untagged (host_start), qemu_host_page_size, prot &PAGE_BITS );
Signature · 1 line
2.34.1
[PULL 05/47] include/qemu/osdep: Add qemu_build_assert
In reply to Richard HendersonThis differs from assert, in that with optimization enabled it triggers at build-time. It differs from QEMU_BUILD_BUG_ON, aka _Static_assert, in that it is sensitive to control flow and is subject to dead-code elimination.
--- include/qemu/osdep.h | 8 ++++++++ 1 file changed, 8 insertions(+)
include/qemu/osdep.h +8 -0
@@ -186,6 +186,14 @@ void QEMU_ERROR("code path is reachable")#define qemu_build_not_reached () g_assert_not_reached()#endif +/** +* qemu_build_assert() +* +* The compiler, during optimization, is expected to prove that the +* assertion is true. +*/ +#define qemu_build_assert (test) while (!(test)) qemu_build_not_reached() +/* * According to waitpid man page: * WCOREDUMP
Signature · 1 line
2.34.1
[PULL 44/47] target/sparc: Convert to tcg_ops restore_state_to_opc
In reply to Richard Henderson--- target/sparc/cpu.h | 3 +++ target/sparc/cpu.c | 1 + target/sparc/translate.c | 7 +++++-- 3 files changed, 9 insertions(+), 2 deletions(-)
target/sparc/cpu.h +3 -0
@@ -600,6 +600,9 @@ int sparc_cpu_memory_rw_debug(CPUState *cpu, vaddr addr,/* translate.c */ void sparc_tcg_init (void ); +void sparc_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data);/* cpu-exec.c */
target/sparc/cpu.c +1 -0
@@ -872,6 +872,7 @@ static const struct SysemuCPUOps sparc_sysemu_ops = {static const struct TCGCPUOps sparc_tcg_ops = { .initialize = sparc_tcg_init, .synchronize_from_tb = sparc_cpu_synchronize_from_tb, + .restore_state_to_opc = sparc_restore_state_to_opc, #ifndef CONFIG_USER_ONLY .tlb_fill = sparc_cpu_tlb_fill,
target/sparc/translate.c +5 -2
@@ -6011,9 +6011,12 @@ void sparc_tcg_init(void) } } -void restore_state_to_opc (CPUSPARCState *env,TranslationBlock *tb, -target_ulong *data) +void sparc_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data) { +SPARCCPU *cpu =SPARC_CPU (cs); +CPUSPARCState *env = &cpu->env;target_ulong pc = data[0 ];target_ulong npc = data[1 ];
Signature · 1 line
2.34.1
[PULL 03/47] tcg/aarch64: Remove unused code in tcg_out_op
In reply to Richard HendersonFrom: Qi Hu <[email protected]>
AArch64 defines the TCG_TARGET_HAS_direct_jump. So the "else" block is useless in the case of "INDEX_op_goto_tb" in function "tcg_out_op". Add an assertion and delete these codes for clarity.
Message-Id: <[email protected]>
--- tcg/aarch64/tcg-target.c.inc | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-)
tcg/aarch64/tcg-target.c.inc +14 -17
@@ -1916,24 +1916,21 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, break; case INDEX_op_goto_tb: - if (s->tb_jmp_insn_offset != NULL) { - /* TCG_TARGET_HAS_direct_jump */ - /* Ensure that ADRP+ADD are 8-byte aligned so that an atomic - write can be used to patch the target address. */ - if ((uintptr_t)s->code_ptr & 7) { - tcg_out32(s, NOP); - } - s->tb_jmp_insn_offset[a0] = tcg_current_code_size(s); - /* actual branch destination will be patched by - tb_target_set_jmp_target later. */ - tcg_out_insn(s, 3406, ADRP, TCG_REG_TMP, 0); - tcg_out_insn(s, 3401, ADDI, TCG_TYPE_I64, TCG_REG_TMP, TCG_REG_TMP, 0); - } else { - /* !TCG_TARGET_HAS_direct_jump */ - tcg_debug_assert(s->tb_jmp_target_addr != NULL); - intptr_t offset = tcg_pcrel_diff(s, (s->tb_jmp_target_addr + a0)) >> 2; - tcg_out_insn(s, 3305, LDR, offset, TCG_REG_TMP); + tcg_debug_assert(s->tb_jmp_insn_offset != NULL); + /* + * Ensure that ADRP+ADD are 8-byte aligned so that an atomic + * write can be used to patch the target address. + */ + if ((uintptr_t)s->code_ptr & 7) { + tcg_out32(s, NOP); } + s->tb_jmp_insn_offset[a0] = tcg_current_code_size(s); + /* + * actual branch destination will be patched by + * tb_target_set_jmp_target later + */ + tcg_out_insn(s, 3406, ADRP, TCG_REG_TMP, 0); + tcg_out_insn(s, 3401, ADDI, TCG_TYPE_I64, TCG_REG_TMP, TCG_REG_TMP, 0); tcg_out_insn(s, 3207, BR, TCG_REG_TMP); set_jmp_reset_offset(s, a0); break;
Signature · 1 line
2.34.1
[PULL 43/47] target/sh4: Convert to tcg_ops restore_state_to_opc
In reply to Richard Henderson--- target/sh4/cpu.c | 16 ++++++++++++++++ target/sh4/translate.c | 10 ---------- 2 files changed, 16 insertions(+), 10 deletions(-)
target/sh4/cpu.c +16 -0
@@ -50,6 +50,21 @@ static void superh_cpu_synchronize_from_tb(CPUState *cs, cpu->env.flags = tb->flags; } +static void superh_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data) +{ +SuperHCPU *cpu =SUPERH_CPU (cs); + + cpu->env.pc = data[0 ]; + cpu->env.flags = data[1 ]; +/* +* Theoretically delayed_pc should also be restored. In practice the +* branch instruction is re-executed after exception, so the delayed +* branch target will be recomputed. +*/ +} +#ifndef CONFIG_USER_ONLY static bool superh_io_recompile_replay_branch (CPUState *cs,const TranslationBlock *tb)
@@ -243,6 +258,7 @@ static const struct SysemuCPUOps sh4_sysemu_ops = {static const struct TCGCPUOps superh_tcg_ops = { .initialize = sh4_translate_init, .synchronize_from_tb = superh_cpu_synchronize_from_tb, + .restore_state_to_opc = superh_restore_state_to_opc, #ifndef CONFIG_USER_ONLY .tlb_fill = superh_cpu_tlb_fill,
target/sh4/translate.c +0 -10
@@ -2381,13 +2381,3 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns,translator_loop (cs, tb, max_insns, pc, host_pc, &sh4_tr_ops, &ctx.base); } - -void restore_state_to_opc (CPUSH4State *env,TranslationBlock *tb, -target_ulong *data) -{ - env->pc = data[0 ]; - env->flags = data[1 ]; -/* Theoretically delayed_pc should also be restored. In practice the -branch instruction is re-executed after exception, so the delayed -branch target will be recomputed. */ -}
Signature · 1 line
2.34.1
[PULL 21/47] accel/tcg: Use page_reset_target_data in page_set_flags
In reply to Richard HendersonUse the existing function for clearing target data.
--- accel/tcg/translate-all.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
accel/tcg/translate-all.c +5 -8
@@ -1370,6 +1370,9 @@ void page_set_flags(target_ulong start, target_ulong end, int flags) flags |=PAGE_WRITE_ORG ; } reset = !(flags &PAGE_VALID ) || (flags &PAGE_RESET ); +if (reset) { +page_reset_target_data (start, end); + } flags &= ~PAGE_RESET ; for (addr = start, len = end - start;
@@ -1387,14 +1390,8 @@ void page_set_flags(target_ulong start, target_ulong end, int flags) (flags & ~p->flags & PAGE_WRITE))) {tb_invalidate_phys_page (addr); } -if (reset) { -g_free (p->target_data); - p->target_data =NULL ; - p->flags = flags; - }else { -/* Using mprotect on a page does not change sticky bits. */ - p->flags = (p->flags &PAGE_STICKY ) | flags; - } +/* Using mprotect on a page does not change sticky bits. */ + p->flags = (reset ?0 : p->flags &PAGE_STICKY ) | flags; } }
Signature · 1 line
2.34.1
[PULL 35/47] target/microblaze: Convert to tcg_ops restore_state_to_opc
In reply to Richard Henderson--- target/microblaze/cpu.c | 11 +++++++++++ target/microblaze/translate.c | 7 ------- 2 files changed, 11 insertions(+), 7 deletions(-)
target/microblaze/cpu.c +11 -0
@@ -100,6 +100,16 @@ static void mb_cpu_synchronize_from_tb(CPUState *cs, cpu->env.iflags = tb->flags &IFLAGS_TB_MASK ; } +static void mb_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data) +{ +MicroBlazeCPU *cpu =MICROBLAZE_CPU (cs); + + cpu->env.pc = data[0 ]; + cpu->env.iflags = data[1 ]; +} +static bool mb_cpu_has_work (CPUState *cs) {return cs->interrupt_request & (CPU_INTERRUPT_HARD |CPU_INTERRUPT_NMI );
@@ -373,6 +383,7 @@ static const struct SysemuCPUOps mb_sysemu_ops = {static const struct TCGCPUOps mb_tcg_ops = { .initialize = mb_tcg_init, .synchronize_from_tb = mb_cpu_synchronize_from_tb, + .restore_state_to_opc = mb_restore_state_to_opc, #ifndef CONFIG_USER_ONLY .tlb_fill = mb_cpu_tlb_fill,
target/microblaze/translate.c +0 -7
@@ -1946,10 +1946,3 @@ void mb_tcg_init(void) cpu_res_addr =tcg_global_mem_new (cpu_env, offsetof(CPUMBState , res_addr),"res_addr" ); } - -void restore_state_to_opc (CPUMBState *env,TranslationBlock *tb, -target_ulong *data) -{ - env->pc = data[0 ]; - env->iflags = data[1 ]; -}
Signature · 1 line
2.34.1
[PULL 34/47] target/m68k: Convert to tcg_ops restore_state_to_opc
In reply to Richard Henderson--- target/m68k/cpu.c | 14 ++++++++++++++ target/m68k/translate.c | 10 ---------- 2 files changed, 14 insertions(+), 10 deletions(-)
target/m68k/cpu.c +14 -0
@@ -38,6 +38,19 @@ static vaddr m68k_cpu_get_pc(CPUState *cs)return cpu->env.pc; } +static void m68k_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data) +{ +M68kCPU *cpu =M68K_CPU (cs); +int cc_op = data[1 ]; + + cpu->env.pc = data[0 ]; +if (cc_op !=CC_OP_DYNAMIC ) { + cpu->env.cc_op = cc_op; + } +} +static bool m68k_cpu_has_work (CPUState *cs) {return cs->interrupt_request &CPU_INTERRUPT_HARD ;
@@ -524,6 +537,7 @@ static const struct SysemuCPUOps m68k_sysemu_ops = {static const struct TCGCPUOps m68k_tcg_ops = { .initialize = m68k_tcg_init, + .restore_state_to_opc = m68k_restore_state_to_opc, #ifndef CONFIG_USER_ONLY .tlb_fill = m68k_cpu_tlb_fill,
target/m68k/translate.c +0 -10
@@ -6479,13 +6479,3 @@ void m68k_cpu_dump_state(CPUState *cs, FILE *f, int flags) env->mmu.mmusr, env->mmu.ar);#endif } - -void restore_state_to_opc (CPUM68KState *env,TranslationBlock *tb, -target_ulong *data) -{ -int cc_op = data[1 ]; - env->pc = data[0 ]; -if (cc_op !=CC_OP_DYNAMIC ) { - env->cc_op = cc_op; - } -}
Signature · 1 line
2.34.1
[PULL 45/47] target/tricore: Convert to tcg_ops restore_state_to_opc
In reply to Richard Henderson--- target/tricore/cpu.c | 11 +++++++++++ target/tricore/translate.c | 6 ------ 2 files changed, 11 insertions(+), 6 deletions(-)
target/tricore/cpu.c +11 -0
@@ -58,6 +58,16 @@ static void tricore_cpu_synchronize_from_tb(CPUState *cs, env->PC =tb_pc (tb); } +static void tricore_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data) +{ +TriCoreCPU *cpu =TRICORE_CPU (cs); +CPUTriCoreState *env = &cpu->env; + + env->PC = data[0 ]; +} +static void tricore_cpu_reset (DeviceState *dev) {CPUState *s =CPU (dev);
@@ -161,6 +171,7 @@ static const struct SysemuCPUOps tricore_sysemu_ops = {static const struct TCGCPUOps tricore_tcg_ops = { .initialize = tricore_tcg_init, .synchronize_from_tb = tricore_cpu_synchronize_from_tb, + .restore_state_to_opc = tricore_restore_state_to_opc, .tlb_fill = tricore_cpu_tlb_fill, };
target/tricore/translate.c +0 -6
@@ -8886,12 +8886,6 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, &tricore_tr_ops, &ctx.base); } -void -restore_state_to_opc (CPUTriCoreState *env,TranslationBlock *tb, -target_ulong *data) -{ - env->PC = data[0 ]; -}/* * * Initialization
Signature · 1 line
2.34.1
[PULL 28/47] target/avr: Convert to tcg_ops restore_state_to_opc
In reply to Richard Henderson--- target/avr/cpu.c | 11 +++++++++++ target/avr/translate.c | 6 ------ 2 files changed, 11 insertions(+), 6 deletions(-)
target/avr/cpu.c +11 -0
@@ -57,6 +57,16 @@ static void avr_cpu_synchronize_from_tb(CPUState *cs, env->pc_w =tb_pc (tb) /2 ;/* internally PC points to words */ } +static void avr_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data) +{ +AVRCPU *cpu =AVR_CPU (cs); +CPUAVRState *env = &cpu->env; + + env->pc_w = data[0 ]; +} +static void avr_cpu_reset (DeviceState *ds) {CPUState *cs =CPU (ds);
@@ -202,6 +212,7 @@ static const struct SysemuCPUOps avr_sysemu_ops = {static const struct TCGCPUOps avr_tcg_ops = { .initialize = avr_cpu_tcg_init, .synchronize_from_tb = avr_cpu_synchronize_from_tb, + .restore_state_to_opc = avr_restore_state_to_opc, .cpu_exec_interrupt = avr_cpu_exec_interrupt, .tlb_fill = avr_cpu_tlb_fill, .do_interrupt = avr_cpu_do_interrupt,
target/avr/translate.c +0 -6
@@ -3055,9 +3055,3 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns,DisasContext dc = { };translator_loop (cs, tb, max_insns, pc, host_pc, &avr_tr_ops, &dc.base); } - -void restore_state_to_opc (CPUAVRState *env,TranslationBlock *tb, -target_ulong *data) -{ - env->pc_w = data[0 ]; -}
Signature · 1 line
2.34.1
[PULL 33/47] target/loongarch: Convert to tcg_ops restore_state_to_opc
In reply to Richard Henderson--- target/loongarch/cpu.c | 11 +++++++++++ target/loongarch/translate.c | 6 ------ 2 files changed, 11 insertions(+), 6 deletions(-)
target/loongarch/cpu.c +11 -0
@@ -319,6 +319,16 @@ static void loongarch_cpu_synchronize_from_tb(CPUState *cs, env->pc = tb_pc(tb); } + +static void loongarch_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data) +{ +LoongArchCPU *cpu =LOONGARCH_CPU (cs); +CPULoongArchState *env = &cpu->env; + + env->pc = data[0 ]; +}#endif /* CONFIG_TCG */ static bool loongarch_cpu_has_work (CPUState *cs)
@@ -651,6 +661,7 @@ void loongarch_cpu_dump_state(CPUState *cs, FILE *f, int flags)static struct TCGCPUOps loongarch_tcg_ops = { .initialize = loongarch_translate_init, .synchronize_from_tb = loongarch_cpu_synchronize_from_tb, + .restore_state_to_opc = loongarch_restore_state_to_opc, #ifndef CONFIG_USER_ONLY .tlb_fill = loongarch_cpu_tlb_fill,
target/loongarch/translate.c +0 -6
@@ -272,9 +272,3 @@ void loongarch_translate_init(void) cpu_llval =tcg_global_mem_new (cpu_env, offsetof(CPULoongArchState , llval),"llval" ); } - -void restore_state_to_opc (CPULoongArchState *env,TranslationBlock *tb, -target_ulong *data) -{ - env->pc = data[0 ]; -}
Signature · 1 line
2.34.1
[PULL 13/47] accel/tcg: Drop cpu_get_tb_cpu_state from TARGET_HAS_PRECISE_SMC
In reply to Richard HendersonThe results of the calls to cpu_get_tb_cpu_state, current_{pc,cs_base,flags}, are not used.
In tb_invalidate_phys_page, use bool for current_tb_modified.
--- accel/tcg/tb-maint.c | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-)
accel/tcg/tb-maint.c +2 -23
@@ -502,23 +502,13 @@ tb_invalidate_phys_page_range__locked(struct page_collection *pages,int n;#ifdef TARGET_HAS_PRECISE_SMC CPUState *cpu = current_cpu; -CPUArchState *env =NULL ;bool current_tb_not_found = retaddr !=0 ;bool current_tb_modified = false;TranslationBlock *current_tb =NULL ; -target_ulong current_pc =0 ; -target_ulong current_cs_base =0 ; -uint32_t current_flags =0 ;#endif /* TARGET_HAS_PRECISE_SMC */ assert_page_locked (p); -#if defined(TARGET_HAS_PRECISE_SMC ) -if (cpu !=NULL ) { - env = cpu->env_ptr; - } -#endif -/* * We remove all the TBs in the range [start, end[. * XXX: see if in some cases it could be faster to invalidate all the code
@@ -554,8 +544,6 @@ tb_invalidate_phys_page_range__locked(struct page_collection *pages,*/ current_tb_modified = true; cpu_restore_state_from_tb(cpu, current_tb, retaddr, true); -cpu_get_tb_cpu_state (env, ¤t_pc, ¤t_cs_base, - ¤t_flags); }#endif /* TARGET_HAS_PRECISE_SMC */ tb_phys_invalidate__locked (tb);
@@ -679,11 +667,7 @@ bool tb_invalidate_phys_page(tb_page_addr_t addr, uintptr_t pc)#ifdef TARGET_HAS_PRECISE_SMC TranslationBlock *current_tb =NULL ;CPUState *cpu = current_cpu; -CPUArchState *env =NULL ; -int current_tb_modified =0 ; -target_ulong current_pc =0 ; -target_ulong current_cs_base =0 ; -uint32_t current_flags =0 ; +bool current_tb_modified = false;#endif assert_memory_lock ();
@@ -698,9 +682,6 @@ bool tb_invalidate_phys_page(tb_page_addr_t addr, uintptr_t pc)if (p->first_tb && pc !=0 ) { current_tb =tcg_tb_lookup (pc); } -if (cpu !=NULL ) { - env = cpu->env_ptr; - }#endif assert_page_locked (p); PAGE_FOR_EACH_TB(p, tb, n) {
@@ -713,10 +694,8 @@ bool tb_invalidate_phys_page(tb_page_addr_t addr, uintptr_t pc)* after the current PC, but it would require a specialized * function to partially restore the CPU state. */ - current_tb_modified =1 ; + current_tb_modified = true; cpu_restore_state_from_tb(cpu, current_tb, pc, true); -cpu_get_tb_cpu_state (env, ¤t_pc, ¤t_cs_base, - ¤t_flags); }#endif /* TARGET_HAS_PRECISE_SMC */ tb_phys_invalidate (tb, addr);
Signature · 1 line
2.34.1
[PULL 08/47] accel/tcg: Make page_alloc_target_data allocation constant
In reply to Richard HendersonUse a constant target data allocation size for all pages. This will be necessary to reduce overhead of page tracking. Since TARGET_PAGE_DATA_SIZE is now required, we can use this to omit data tracking for targets that don't require it.
--- include/exec/cpu-all.h | 9 ++++----- target/arm/cpu.h | 8 ++++++++ target/arm/internals.h | 4 ---- accel/tcg/translate-all.c | 8 ++++++-- target/arm/mte_helper.c | 3 +-- 5 files changed, 19 insertions(+), 13 deletions(-)
include/exec/cpu-all.h +4 -5
@@ -281,19 +281,18 @@ void page_reset_target_data(target_ulong start, target_ulong end);int page_check_range (target_ulong start,target_ulong len,int flags);/** -* page_alloc_target_data(address, size) +* page_alloc_target_data(address) * @address: guest virtual address -* @size: size of data to allocate * -* Allocate @size bytes of out-of-band data to associate with the -* guest page at @address. If the page is not mapped, NULL will +* Allocate TARGET_PAGE_DATA_SIZE bytes of out-of-band data to associate +* with the guest page at @address. If the page is not mapped, NULL will * be returned. If there is existing data associated with @address, * no new memory will be allocated. * * The memory will be freed when the guest page is deallocated, * e.g. with the munmap system call. */ -void *page_alloc_target_data (target_ulong address,size_t size); +void *page_alloc_target_data (target_ulong address);/** * page_get_target_data(address)
target/arm/cpu.h +8 -0
@@ -3410,6 +3410,14 @@ extern const uint64_t pred_esz_masks[5];#define PAGE_MTE PAGE_TARGET_2#define PAGE_TARGET_STICKY PAGE_MTE +/* We associate one allocation tag per 16 bytes, the minimum. */ +#define LOG2_TAG_GRANULE 4 +#define TAG_GRANULE (1 << LOG2_TAG_GRANULE) + +#ifdef CONFIG_USER_ONLY +#define TARGET_PAGE_DATA_SIZE (TARGET_PAGE_SIZE >> (LOG2_TAG_GRANULE + 1)) +#endif +#ifdef TARGET_TAGGED_ADDRESSES /** * cpu_untagged_addr:
target/arm/internals.h +0 -4
@@ -1164,10 +1164,6 @@ void arm_log_exception(CPUState *cs);*/ #define GMID_EL1_BS 6 -/* We associate one allocation tag per 16 bytes, the minimum. */ -#define LOG2_TAG_GRANULE 4 -#define TAG_GRANULE (1 << LOG2_TAG_GRANULE) -/* * SVE predicates are 1/8 the size of SVE vectors, and cannot use * the same simd_desc() encoding due to restrictions on size.
accel/tcg/translate-all.c +6 -2
@@ -2271,6 +2271,7 @@ void page_set_flags(target_ulong start, target_ulong end, int flags)void page_reset_target_data (target_ulong start,target_ulong end) { +#ifdef TARGET_PAGE_DATA_SIZE target_ulong addr, len;/*
@@ -2293,15 +2294,17 @@ void page_reset_target_data(target_ulong start, target_ulong end)g_free (p->target_data); p->target_data =NULL ; } +#endif } +#ifdef TARGET_PAGE_DATA_SIZE void *page_get_target_data (target_ulong address) {PageDesc *p =page_find (address >>TARGET_PAGE_BITS );return p ? p->target_data :NULL ; } -void *page_alloc_target_data (target_ulong address,size_t size) +void *page_alloc_target_data (target_ulong address) {PageDesc *p =page_find (address >>TARGET_PAGE_BITS );void *ret =NULL ;
@@ -2309,11 +2312,12 @@ void *page_alloc_target_data(target_ulong address, size_t size)if (p->flags &PAGE_VALID ) { ret = p->target_data;if (!ret) { - p->target_data = ret =g_malloc0 (size); + p->target_data = ret =g_malloc0 (TARGET_PAGE_DATA_SIZE ); } } return ret; } +#endif /* TARGET_PAGE_DATA_SIZE */ int page_check_range (target_ulong start,target_ulong len,int flags) {
target/arm/mte_helper.c +1 -2
@@ -96,8 +96,7 @@ static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx, tags =page_get_target_data (clean_ptr);if (tags ==NULL ) { -size_t alloc_size =TARGET_PAGE_SIZE >> (LOG2_TAG_GRANULE +1 ); - tags =page_alloc_target_data (clean_ptr, alloc_size); + tags =page_alloc_target_data (clean_ptr);assert (tags !=NULL ); }
Signature · 1 line
2.34.1
[PULL 36/47] target/mips: Convert to tcg_ops restore_state_to_opc
In reply to Richard Henderson--- target/mips/tcg/tcg-internal.h | 3 +++ target/mips/cpu.c | 1 + target/mips/tcg/translate.c | 8 ++++++-- 3 files changed, 10 insertions(+), 2 deletions(-)
target/mips/tcg/tcg-internal.h +3 -0
@@ -21,6 +21,9 @@ void mips_cpu_synchronize_from_tb(CPUState *cs, const TranslationBlock *tb); G_NORETURN void mips_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,MMUAccessType access_type,int mmu_idx,uintptr_t retaddr); +void mips_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data);const char *mips_exception_name (int32_t exception);
target/mips/cpu.c +1 -0
@@ -538,6 +538,7 @@ static const struct SysemuCPUOps mips_sysemu_ops = {static const struct TCGCPUOps mips_tcg_ops = { .initialize = mips_tcg_init, .synchronize_from_tb = mips_cpu_synchronize_from_tb, + .restore_state_to_opc = mips_restore_state_to_opc, #if !defined(CONFIG_USER_ONLY) .tlb_fill = mips_cpu_tlb_fill,
target/mips/tcg/translate.c +6 -2
@@ -16229,9 +16229,13 @@ void mips_tcg_init(void) } } -void restore_state_to_opc (CPUMIPSState *env,TranslationBlock *tb, -target_ulong *data) +void mips_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data) { +MIPSCPU *cpu =MIPS_CPU (cs); +CPUMIPSState *env = &cpu->env; + env->active_tc.PC = data[0 ]; env->hflags &= ~MIPS_HFLAG_BMASK ; env->hflags |= data[1 ];
Signature · 1 line
2.34.1
[PULL 47/47] accel/tcg: Remove restore_state_to_opc function
In reply to Richard HendersonAll targets have been updated. Use the tcg_ops target hook exclusively, which allows the compat code to be removed.
--- include/exec/exec-all.h | 3 --- accel/tcg/translate-all.c | 16 ++-------------- 2 files changed, 2 insertions(+), 17 deletions(-)
include/exec/exec-all.h +0 -3
@@ -39,9 +39,6 @@ typedef ram_addr_t tb_page_addr_t;#define TB_PAGE_ADDR_FMT RAM_ADDR_FMT#endif -void restore_state_to_opc (CPUArchState *env,TranslationBlock *tb, -target_ulong *data) __attribute__((weak)); -/** * cpu_restore_state: * @cpu: the vCPU state is to be restore to
accel/tcg/translate-all.c +2 -14
@@ -254,7 +254,7 @@ static int encode_search(TranslationBlock *tb, uint8_t *block)int cpu_restore_state_from_tb (CPUState *cpu,TranslationBlock *tb,uintptr_t searched_pc,bool reset_icount) { -target_ulong data[TARGET_INSN_START_WORDS ]; +uint64_t data[TARGET_INSN_START_WORDS ];uintptr_t host_pc = (uintptr_t )tb->tc.ptr;const uint8_t *p = tb->tc.ptr + tb->tc.size;int i, j, num_insns = tb->icount;
@@ -295,19 +295,7 @@ int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb,cpu_neg (cpu)->icount_decr.u16.low += num_insns - i; } - { -const struct TCGCPUOps *ops = cpu->cc->tcg_ops; - __typeof(ops->restore_state_to_opc) restore = ops->restore_state_to_opc; -if (restore) { -uint64_t d64[TARGET_INSN_START_WORDS ]; -for (i =0 ; i <TARGET_INSN_START_WORDS ; ++i) { - d64[i] = data[i]; - } -restore (cpu, tb, d64); - }else { -restore_state_to_opc (cpu->env_ptr, tb, data); - } - } + cpu->cc->tcg_ops->restore_state_to_opc (cpu, tb, data);#ifdef CONFIG_PROFILER qatomic_set(&prof->restore_time,
Signature · 1 line
2.34.1
[PULL 01/47] Revert "accel/tcg: Init TCG cflags in vCPU thread handler"
In reply to Richard HendersonFrom: Peter Maydell <[email protected]>
Commit a82fd5a4ec24d was intended to be a code cleanup, but unfortunately it has a bug. It moves the initialization of the TCG cflags from the "start a new vcpu" function to the thread handler; this is fine when each vcpu has its own thread, but when we are doing round-robin of vcpus on a single thread we end up only initializing the cflags for CPU 0, not for any of the others.
The most obvious effect of this bug is that running in icount mode with more than one CPU is broken; typically the guest hangs shortly after it brings up the secondary CPUs.
This reverts commit a82fd5a4ec24d923ff1e6da128c0fd4a74079d99.
Message-Id: <[email protected]>
--- accel/tcg/tcg-accel-ops-mttcg.c | 5 +++-- accel/tcg/tcg-accel-ops-rr.c | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-)
accel/tcg/tcg-accel-ops-mttcg.c +3 -2
@@ -70,8 +70,6 @@ static void *mttcg_cpu_thread_fn(void *arg)assert (tcg_enabled ());g_assert (!icount_enabled ()); -tcg_cpu_init_cflags (cpu, current_machine->smp.max_cpus >1 ); -rcu_register_thread (); force_rcu.notifier.notify = mttcg_force_rcu; force_rcu.cpu = cpu;
@@ -141,6 +139,9 @@ void mttcg_start_vcpu_thread(CPUState *cpu) {char thread_name[VCPU_THREAD_NAME_SIZE ]; +g_assert (tcg_enabled ()); +tcg_cpu_init_cflags (cpu, current_machine->smp.max_cpus >1 ); + cpu->thread =g_new0 (QemuThread,1 ); cpu->halt_cond =g_malloc0 (sizeof (QemuCond));qemu_cond_init (cpu->halt_cond);
accel/tcg/tcg-accel-ops-rr.c +4 -3
@@ -152,9 +152,7 @@ static void *rr_cpu_thread_fn(void *arg)Notifier force_rcu;CPUState *cpu = arg; -g_assert (tcg_enabled ()); -tcg_cpu_init_cflags (cpu, false); - +assert (tcg_enabled ());rcu_register_thread (); force_rcu.notify = rr_force_rcu;rcu_add_force_rcu_notifier (&force_rcu);
@@ -277,6 +275,9 @@ void rr_start_vcpu_thread(CPUState *cpu)static QemuCond *single_tcg_halt_cond;static QemuThread *single_tcg_cpu_thread; +g_assert (tcg_enabled ()); +tcg_cpu_init_cflags (cpu, false); +if (!single_tcg_cpu_thread) { cpu->thread =g_new0 (QemuThread,1 ); cpu->halt_cond =g_new0 (QemuCond,1 );
Signature · 1 line
2.34.1
[PULL 26/47] target/alpha: Convert to tcg_ops restore_state_to_opc
In reply to Richard Henderson--- target/alpha/cpu.c | 9 +++++++++ target/alpha/translate.c | 6 ------ 2 files changed, 9 insertions(+), 6 deletions(-)
target/alpha/cpu.c +9 -0
@@ -40,6 +40,14 @@ static vaddr alpha_cpu_get_pc(CPUState *cs)return cpu->env.pc; } +static void alpha_restore_state_to_opc (CPUState *cs, +const TranslationBlock *tb, +const uint64_t *data) +{ +AlphaCPU *cpu =ALPHA_CPU (cs); + + cpu->env.pc = data[0 ]; +}static bool alpha_cpu_has_work (CPUState *cs) {
@@ -226,6 +234,7 @@ static const struct SysemuCPUOps alpha_sysemu_ops = {static const struct TCGCPUOps alpha_tcg_ops = { .initialize = alpha_translate_init, + .restore_state_to_opc = alpha_restore_state_to_opc, #ifdef CONFIG_USER_ONLY .record_sigsegv = alpha_cpu_record_sigsegv,
target/alpha/translate.c +0 -6
@@ -3049,9 +3049,3 @@ void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns,DisasContext dc;translator_loop (cpu, tb, max_insns, pc, host_pc, &alpha_tr_ops, &dc.base); } - -void restore_state_to_opc (CPUAlphaState *env,TranslationBlock *tb, -target_ulong *data) -{ - env->pc = data[0 ]; -}
Signature · 1 line
2.34.1
[PULL 12/47] accel/tcg: Move assert_no_pages_locked to internal.h
In reply to Richard HendersonThere are no users outside of accel/tcg; this function does not need to be defined in exec-all.h.
--- accel/tcg/internal.h | 5 +++++ include/exec/exec-all.h | 8 -------- 2 files changed, 5 insertions(+), 8 deletions(-)
accel/tcg/internal.h +5 -0
@@ -90,6 +90,11 @@ void do_assert_page_locked(const PageDesc *pd, const char *file, int line);void page_lock (PageDesc *pd);void page_unlock (PageDesc *pd);#endif +#if !defined(CONFIG_USER_ONLY ) && defined(CONFIG_DEBUG_TCG ) +void assert_no_pages_locked (void ); +#else +static inline void assert_no_pages_locked (void ) { } +#endif TranslationBlock *tb_gen_code(CPUState *cpu, target_ulong pc, target_ulong cs_base, uint32_t flags,
include/exec/exec-all.h +0 -8
@@ -642,14 +642,6 @@ extern __thread uintptr_t tci_tb_ptr;smaller than 4 bytes, so we don't worry about special-casing this. */ #define GETPC_ADJ 2 -#if !defined(CONFIG_USER_ONLY ) && defined(CONFIG_DEBUG_TCG ) -void assert_no_pages_locked (void ); -#else -static inline void assert_no_pages_locked (void ) -{ -} -#endif -#if !defined(CONFIG_USER_ONLY )/**
Signature · 1 line
2.34.1
[PULL 18/47] accel/tcg: Unify declarations of tb_invalidate_phys_range
In reply to Richard HendersonWe missed this function when we introduced tb_page_addr_t.
--- include/exec/exec-all.h | 2 +- include/exec/ram_addr.h | 2 -- accel/tcg/tb-maint.c | 13 ++----------- 3 files changed, 3 insertions(+), 14 deletions(-)
include/exec/exec-all.h +1 -1
@@ -638,12 +638,12 @@ uint32_t curr_cflags(CPUState *cpu);/* TranslationBlock invalidate API */ #if defined(CONFIG_USER_ONLY )void tb_invalidate_phys_addr (target_ulong addr); -void tb_invalidate_phys_range (target_ulong start,target_ulong end);#else void tb_invalidate_phys_addr (AddressSpace *as,hwaddr addr,MemTxAttrs attrs);#endif void tb_flush (CPUState *cpu);void tb_phys_invalidate (TranslationBlock *tb,tb_page_addr_t page_addr); +void tb_invalidate_phys_range (tb_page_addr_t start,tb_page_addr_t end);void tb_set_jmp_target (TranslationBlock *tb,int n,uintptr_t addr);/* GETPC is the true target of the return instruction that we'll execute. */
include/exec/ram_addr.h +0 -2
@@ -147,8 +147,6 @@ static inline void qemu_ram_block_writeback(RAMBlock *block)#define DIRTY_CLIENTS_ALL ((1 << DIRTY_MEMORY_NUM) - 1)#define DIRTY_CLIENTS_NOCODE (DIRTY_CLIENTS_ALL & ~(1 << DIRTY_MEMORY_CODE)) -void tb_invalidate_phys_range (ram_addr_t start,ram_addr_t end); -static inline bool cpu_physical_memory_get_dirty (ram_addr_t start,ram_addr_t length,unsigned client)
accel/tcg/tb-maint.c +2 -11
@@ -20,6 +20,7 @@#include "qemu/osdep.h" #include "exec/cputlb.h" #include "exec/log.h" +#include "exec/exec-all.h" #include "exec/translate-all.h" #include "sysemu/tcg.h" #include "tcg/tcg.h"
@@ -27,12 +28,6 @@#include "tb-context.h" #include "internal.h" -/* FIXME: tb_invalidate_phys_range is declared in different places. */ -#ifdef CONFIG_USER_ONLY -#include "exec/exec-all.h" -#else -#include "exec/ram_addr.h" -#endif static bool tb_cmp (const void *ap,const void *bp) {
@@ -599,11 +594,7 @@ void tb_invalidate_phys_page(tb_page_addr_t addr)* * Called with mmap_lock held for user-mode emulation. */ -#ifdef CONFIG_SOFTMMU -void tb_invalidate_phys_range(ram_addr_t start, ram_addr_t end) -#else -void tb_invalidate_phys_range(target_ulong start, target_ulong end) -#endif +void tb_invalidate_phys_range (tb_page_addr_t start,tb_page_addr_t end) {struct page_collection *pages;tb_page_addr_t next;
Signature · 1 line
2.34.1
Stefan Hajnoczi
AppliedApplied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/7.2 for any user-visible changes.