Received: from eggs.gnu.org ([208.118.235.92]:60247) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1FtU-0006xm-VE for qemu-devel@nongnu.org; Fri, 01 Feb 2013 07:39:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U1FtR-00029D-Fw for qemu-devel@nongnu.org; Fri, 01 Feb 2013 07:39:00 -0500 Received: from cantor2.suse.de ([195.135.220.15]:56678 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1FtQ-00028v-Kp for qemu-devel@nongnu.org; Fri, 01 Feb 2013 07:38:57 -0500 Received: from relay1.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id B4686A3DDF for ; Fri, 1 Feb 2013 13:38:55 +0100 (CET) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Fri, 1 Feb 2013 13:38:30 +0100 Message-Id: <1359722312-2391-5-git-send-email-afaerber@suse.de> In-Reply-To: <1359722312-2391-1-git-send-email-afaerber@suse.de> References: <1359722312-2391-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH qom-cpu-next 4/6] cpu: Move current_tb field to CPUState List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= Explictly NULL it on CPU reset since it was located before breakpoints. Change vapic_report_tpr_access() argument to CPUState. This also resolves the use of void* for cpu.h independence. Change vAPIC patch_instruction() argument to X86CPU. Signed-off-by: Andreas F=C3=A4rber --- cpu-exec.c | 13 ++++++++----- cputlb.c | 6 ++++-- hw/apic_common.c | 2 +- hw/apic_internal.h | 2 +- hw/kvmvapic.c | 13 ++++++++----- include/exec/cpu-defs.h | 1 - include/exec/exec-all.h | 4 +++- include/qom/cpu.h | 3 +++ qom/cpu.c | 1 + translate-all.c | 29 +++++++++++++++++++---------- 10 Dateien ge=C3=A4ndert, 48 Zeilen hinzugef=C3=BCgt(+), 26 Zeilen entfe= rnt(-) diff --git a/cpu-exec.c b/cpu-exec.c index 32f3559..83ddea4 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -34,7 +34,9 @@ bool qemu_cpu_has_work(CPUState *cpu) =20 void cpu_loop_exit(CPUArchState *env) { - env->current_tb =3D NULL; + CPUState *cpu =3D ENV_GET_CPU(env); + + cpu->current_tb =3D NULL; longjmp(env->jmp_env, 1); } =20 @@ -56,6 +58,7 @@ void cpu_resume_from_signal(CPUArchState *env, void *pu= c) static void cpu_exec_nocache(CPUArchState *env, int max_cycles, TranslationBlock *orig_tb) { + CPUState *cpu =3D ENV_GET_CPU(env); tcg_target_ulong next_tb; TranslationBlock *tb; =20 @@ -66,10 +69,10 @@ static void cpu_exec_nocache(CPUArchState *env, int m= ax_cycles, =20 tb =3D tb_gen_code(env, orig_tb->pc, orig_tb->cs_base, orig_tb->flag= s, max_cycles); - env->current_tb =3D tb; + cpu->current_tb =3D tb; /* execute the generated code */ next_tb =3D tcg_qemu_tb_exec(env, tb->tc_ptr); - env->current_tb =3D NULL; + cpu->current_tb =3D NULL; =20 if ((next_tb & 3) =3D=3D 2) { /* Restore PC. This may happen if async event occurs before @@ -591,7 +594,7 @@ int cpu_exec(CPUArchState *env) TB, but before it is linked into a potentially infinite loop and becomes env->current_tb. Avoid starting execution if there is a pending interrupt. *= / - env->current_tb =3D tb; + cpu->current_tb =3D tb; barrier(); if (likely(!cpu->exit_request)) { tc_ptr =3D tb->tc_ptr; @@ -625,7 +628,7 @@ int cpu_exec(CPUArchState *env) } } } - env->current_tb =3D NULL; + cpu->current_tb =3D NULL; /* reset soft MMU for next block (it can currently only be set by a memory fault) */ } /* for(;;) */ diff --git a/cputlb.c b/cputlb.c index 88239c4..aba7e44 100644 --- a/cputlb.c +++ b/cputlb.c @@ -54,6 +54,7 @@ static const CPUTLBEntry s_cputlb_empty_entry =3D { */ void tlb_flush(CPUArchState *env, int flush_global) { + CPUState *cpu =3D ENV_GET_CPU(env); int i; =20 #if defined(DEBUG_TLB) @@ -61,7 +62,7 @@ void tlb_flush(CPUArchState *env, int flush_global) #endif /* must reset current TB so that interrupts cannot modify the links while we are modifying them */ - env->current_tb =3D NULL; + cpu->current_tb =3D NULL; =20 for (i =3D 0; i < CPU_TLB_SIZE; i++) { int mmu_idx; @@ -92,6 +93,7 @@ static inline void tlb_flush_entry(CPUTLBEntry *tlb_ent= ry, target_ulong addr) =20 void tlb_flush_page(CPUArchState *env, target_ulong addr) { + CPUState *cpu =3D ENV_GET_CPU(env); int i; int mmu_idx; =20 @@ -110,7 +112,7 @@ void tlb_flush_page(CPUArchState *env, target_ulong a= ddr) } /* must reset current TB so that interrupts cannot modify the links while we are modifying them */ - env->current_tb =3D NULL; + cpu->current_tb =3D NULL; =20 addr &=3D TARGET_PAGE_MASK; i =3D (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); diff --git a/hw/apic_common.c b/hw/apic_common.c index 6e1b1e0..d8c9810 100644 --- a/hw/apic_common.c +++ b/hw/apic_common.c @@ -103,7 +103,7 @@ void apic_handle_tpr_access_report(DeviceState *d, ta= rget_ulong ip, { APICCommonState *s =3D DO_UPCAST(APICCommonState, busdev.qdev, d); =20 - vapic_report_tpr_access(s->vapic, &s->cpu->env, ip, access); + vapic_report_tpr_access(s->vapic, CPU(s->cpu), ip, access); } =20 void apic_report_irq_delivered(int delivered) diff --git a/hw/apic_internal.h b/hw/apic_internal.h index dcbbfd4..9265e52 100644 --- a/hw/apic_internal.h +++ b/hw/apic_internal.h @@ -143,7 +143,7 @@ bool apic_next_timer(APICCommonState *s, int64_t curr= ent_time); void apic_enable_tpr_access_reporting(DeviceState *d, bool enable); void apic_enable_vapic(DeviceState *d, hwaddr paddr); =20 -void vapic_report_tpr_access(DeviceState *dev, void *cpu, target_ulong i= p, +void vapic_report_tpr_access(DeviceState *dev, CPUState *cpu, target_ulo= ng ip, TPRAccess access); =20 #endif /* !QEMU_APIC_INTERNAL_H */ diff --git a/hw/kvmvapic.c b/hw/kvmvapic.c index 1b5f416..9265baf 100644 --- a/hw/kvmvapic.c +++ b/hw/kvmvapic.c @@ -382,8 +382,10 @@ static void patch_call(VAPICROMState *s, CPUX86State= *env, target_ulong ip, cpu_memory_rw_debug(env, ip + 1, (void *)&offset, sizeof(offset), 1)= ; } =20 -static void patch_instruction(VAPICROMState *s, CPUX86State *env, target= _ulong ip) +static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulon= g ip) { + CPUState *cs =3D CPU(cpu); + CPUX86State *env =3D &cpu->env; VAPICHandlers *handlers; uint8_t opcode[2]; uint32_t imm32; @@ -439,17 +441,18 @@ static void patch_instruction(VAPICROMState *s, CPU= X86State *env, target_ulong i resume_all_vcpus(); =20 if (!kvm_enabled()) { - env->current_tb =3D NULL; + cs->current_tb =3D NULL; tb_gen_code(env, current_pc, current_cs_base, current_flags, 1); cpu_resume_from_signal(env, NULL); } } =20 -void vapic_report_tpr_access(DeviceState *dev, void *cpu, target_ulong i= p, +void vapic_report_tpr_access(DeviceState *dev, CPUState *cs, target_ulon= g ip, TPRAccess access) { VAPICROMState *s =3D DO_UPCAST(VAPICROMState, busdev.qdev, dev); - CPUX86State *env =3D cpu; + X86CPU *cpu =3D X86_CPU(cs); + CPUX86State *env =3D &cpu->env; =20 cpu_synchronize_state(env); =20 @@ -465,7 +468,7 @@ void vapic_report_tpr_access(DeviceState *dev, void *= cpu, target_ulong ip, if (vapic_enable(s, env) < 0) { return; } - patch_instruction(s, env, ip); + patch_instruction(s, cpu, ip); } =20 typedef struct VAPICEnableTPRReporting { diff --git a/include/exec/cpu-defs.h b/include/exec/cpu-defs.h index ca39f05..ae64590 100644 --- a/include/exec/cpu-defs.h +++ b/include/exec/cpu-defs.h @@ -148,7 +148,6 @@ typedef struct CPUWatchpoint { =20 #define CPU_TEMP_BUF_NLONGS 128 #define CPU_COMMON = \ - struct TranslationBlock *current_tb; /* currently executing TB */ = \ /* soft mmu support */ = \ /* in order to avoid passing too many arguments to the MMIO = \ helpers, we store some rarely used information in the CPU = \ diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index d235ef8..ddd989d 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -393,11 +393,13 @@ extern volatile sig_atomic_t exit_request; instruction of a TB so that interrupts take effect immediately. */ static inline int can_do_io(CPUArchState *env) { + CPUState *cpu =3D ENV_GET_CPU(env); + if (!use_icount) { return 1; } /* If not executing code then assume we are ok. */ - if (!env->current_tb) { + if (cpu->current_tb =3D=3D NULL) { return 1; } return env->can_do_io !=3D 0; diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 42f3f34..c25a997 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -71,6 +71,7 @@ struct kvm_run; * @created: Indicates whether the CPU thread has been successfully crea= ted. * @stop: Indicates a pending stop request. * @stopped: Indicates the CPU has been artificially stopped. + * @current_tb: Currently executing TB. * @kvm_fd: vCPU file descriptor for KVM. * * State of one CPU core or thread. @@ -99,6 +100,8 @@ struct CPUState { bool stopped; volatile sig_atomic_t exit_request; =20 + struct TranslationBlock *current_tb; + int kvm_fd; bool kvm_vcpu_dirty; struct KVMState *kvm_state; diff --git a/qom/cpu.c b/qom/cpu.c index 7d8c675..0a2194d 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -33,6 +33,7 @@ void cpu_reset(CPUState *cpu) static void cpu_common_reset(CPUState *cpu) { cpu->exit_request =3D 0; + cpu->current_tb =3D NULL; } =20 ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_mod= el) diff --git a/translate-all.c b/translate-all.c index d367fc4..0122fc5 100644 --- a/translate-all.c +++ b/translate-all.c @@ -1008,6 +1008,7 @@ void tb_invalidate_phys_page_range(tb_page_addr_t s= tart, tb_page_addr_t end, { TranslationBlock *tb, *tb_next, *saved_tb; CPUArchState *env =3D cpu_single_env; + CPUState *cpu =3D NULL; tb_page_addr_t tb_start, tb_end; PageDesc *p; int n; @@ -1030,6 +1031,9 @@ void tb_invalidate_phys_page_range(tb_page_addr_t s= tart, tb_page_addr_t end, /* build code bitmap */ build_page_bitmap(p); } + if (env !=3D NULL) { + cpu =3D ENV_GET_CPU(env); + } =20 /* we remove all the TBs in the range [start, end[ */ /* XXX: see if in some cases it could be faster to invalidate all @@ -1076,14 +1080,14 @@ void tb_invalidate_phys_page_range(tb_page_addr_t= start, tb_page_addr_t end, /* we need to do that to handle the case where a signal occurs while doing tb_phys_invalidate() */ saved_tb =3D NULL; - if (env) { - saved_tb =3D env->current_tb; - env->current_tb =3D NULL; + if (cpu !=3D NULL) { + saved_tb =3D cpu->current_tb; + cpu->current_tb =3D NULL; } tb_phys_invalidate(tb, -1); - if (env) { - env->current_tb =3D saved_tb; - if (env->interrupt_request && env->current_tb) { + if (cpu !=3D NULL) { + cpu->current_tb =3D saved_tb; + if (env && env->interrupt_request && cpu->current_tb) { cpu_interrupt(env, env->interrupt_request); } } @@ -1104,7 +1108,7 @@ void tb_invalidate_phys_page_range(tb_page_addr_t s= tart, tb_page_addr_t end, /* we generate a block containing just the instruction modifying the memory. It will ensure that it cannot modify itself */ - env->current_tb =3D NULL; + cpu->current_tb =3D NULL; tb_gen_code(env, current_pc, current_cs_base, current_flags, 1); cpu_resume_from_signal(env, NULL); } @@ -1152,6 +1156,7 @@ static void tb_invalidate_phys_page(tb_page_addr_t = addr, #ifdef TARGET_HAS_PRECISE_SMC TranslationBlock *current_tb =3D NULL; CPUArchState *env =3D cpu_single_env; + CPUState *cpu =3D NULL; int current_tb_modified =3D 0; target_ulong current_pc =3D 0; target_ulong current_cs_base =3D 0; @@ -1168,6 +1173,9 @@ static void tb_invalidate_phys_page(tb_page_addr_t = addr, if (tb && pc !=3D 0) { current_tb =3D tb_find_pc(pc); } + if (env !=3D NULL) { + cpu =3D ENV_GET_CPU(env); + } #endif while (tb !=3D NULL) { n =3D (uintptr_t)tb & 3; @@ -1196,7 +1204,7 @@ static void tb_invalidate_phys_page(tb_page_addr_t = addr, /* we generate a block containing just the instruction modifying the memory. It will ensure that it cannot modify itself */ - env->current_tb =3D NULL; + cpu->current_tb =3D NULL; tb_gen_code(env, current_pc, current_cs_base, current_flags, 1); cpu_resume_from_signal(env, puc); } @@ -1423,15 +1431,16 @@ void cpu_unlink_tb(CPUArchState *env) problem and hope the cpu will stop of its own accord. For usersp= ace emulation this often isn't actually as bad as it sounds. Often signals are used primarily to interrupt blocking syscalls. */ + CPUState *cpu =3D ENV_GET_CPU(env); TranslationBlock *tb; static spinlock_t interrupt_lock =3D SPIN_LOCK_UNLOCKED; =20 spin_lock(&interrupt_lock); - tb =3D env->current_tb; + tb =3D cpu->current_tb; /* if the cpu is currently executing code, we must unlink it and all the potentially executing TB */ if (tb) { - env->current_tb =3D NULL; + cpu->current_tb =3D NULL; tb_reset_jump_recursive(tb); } spin_unlock(&interrupt_lock); --=20 1.7.10.4