From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:44603) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tf1WY-0006U0-33 for qemu-devel@nongnu.org; Sat, 01 Dec 2012 23:51:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tf1WT-0006CG-Qr for qemu-devel@nongnu.org; Sat, 01 Dec 2012 23:51:25 -0500 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 2 Dec 2012 05:50:50 +0100 Message-Id: <1354423851-24818-11-git-send-email-afaerber@suse.de> In-Reply-To: <1354423851-24818-1-git-send-email-afaerber@suse.de> References: <1354423851-24818-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 10/11] cpu: Move kvm_state field into CPUState List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, mtosatti@redhat.com, Alexander Graf , "open list:PowerPC" , Avi Kivity , anthony@codemonkey.ws, =?UTF-8?q?Andreas=20F=C3=A4rber?= Adapt some functions to take CPUState / {PowerPC,S390}CPU argument. Signed-off-by: Andreas F=C3=A4rber --- cpu-defs.h | 2 -- include/qemu/cpu.h | 3 +++ kvm-all.c | 28 ++++++++++++++-------------- kvm.h | 4 ++-- target-i386/cpu.c | 7 +++++-- target-i386/kvm.c | 22 +++++++++++----------- target-ppc/kvm.c | 30 +++++++++++++++++------------- target-s390x/kvm.c | 5 ++--- 8 Dateien ge=C3=A4ndert, 54 Zeilen hinzugef=C3=BCgt(+), 47 Zeilen entfer= nt(-) diff --git a/cpu-defs.h b/cpu-defs.h index a382e35..9ed54cf 100644 --- a/cpu-defs.h +++ b/cpu-defs.h @@ -135,7 +135,6 @@ typedef struct icount_decr_u16 { #endif =20 struct kvm_run; -struct KVMState; struct qemu_work_item; =20 typedef struct CPUBreakpoint { @@ -205,7 +204,6 @@ typedef struct CPUWatchpoint { void *opaque; = \ = \ const char *cpu_model_str; = \ - struct KVMState *kvm_state; = \ struct kvm_run *kvm_run; =20 #endif diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h index cdc45ff..32deacb 100644 --- a/include/qemu/cpu.h +++ b/include/qemu/cpu.h @@ -52,6 +52,8 @@ typedef struct CPUClass { void (*reset)(CPUState *cpu); } CPUClass; =20 +struct KVMState; + /** * CPUState: * @created: Indicates whether the CPU thread has been successfully crea= ted. @@ -81,6 +83,7 @@ struct CPUState { int kvm_fd; int kvm_vcpu_dirty; #endif + struct KVMState *kvm_state; =20 /* TODO Move common fields from CPUArchState here. */ }; diff --git a/kvm-all.c b/kvm-all.c index 5f1d1fe..ba139ab 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -230,7 +230,7 @@ int kvm_init_vcpu(CPUArchState *env) } =20 cpu->kvm_fd =3D ret; - env->kvm_state =3D s; + cpu->kvm_state =3D s; cpu->kvm_vcpu_dirty =3D true; =20 mmap_size =3D kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0); @@ -1763,12 +1763,12 @@ void kvm_setup_guest_memory(void *start, size_t s= ize) } =20 #ifdef KVM_CAP_SET_GUEST_DEBUG -struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUArchState *env, +struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUState *cpu, target_ulong pc) { struct kvm_sw_breakpoint *bp; =20 - QTAILQ_FOREACH(bp, &env->kvm_state->kvm_sw_breakpoints, entry) { + QTAILQ_FOREACH(bp, &cpu->kvm_state->kvm_sw_breakpoints, entry) { if (bp->pc =3D=3D pc) { return bp; } @@ -1776,23 +1776,23 @@ struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(= CPUArchState *env, return NULL; } =20 -int kvm_sw_breakpoints_active(CPUArchState *env) +int kvm_sw_breakpoints_active(CPUState *cpu) { - return !QTAILQ_EMPTY(&env->kvm_state->kvm_sw_breakpoints); + return !QTAILQ_EMPTY(&cpu->kvm_state->kvm_sw_breakpoints); } =20 struct kvm_set_guest_debug_data { struct kvm_guest_debug dbg; - CPUArchState *env; + CPUState *cpu; int err; }; =20 static void kvm_invoke_set_guest_debug(void *data) { struct kvm_set_guest_debug_data *dbg_data =3D data; - CPUState *cpu =3D ENV_GET_CPU(dbg_data->env); =20 - dbg_data->err =3D kvm_vcpu_ioctl(cpu, KVM_SET_GUEST_DEBUG, &dbg_data= ->dbg); + dbg_data->err =3D kvm_vcpu_ioctl(dbg_data->cpu, KVM_SET_GUEST_DEBUG, + &dbg_data->dbg); } =20 int kvm_update_guest_debug(CPUArchState *env, unsigned long reinject_tra= p) @@ -1806,7 +1806,7 @@ int kvm_update_guest_debug(CPUArchState *env, unsig= ned long reinject_trap) data.dbg.control |=3D KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_SINGLES= TEP; } kvm_arch_update_guest_debug(cpu, &data.dbg); - data.env =3D env; + data.cpu =3D cpu; =20 run_on_cpu(cpu, kvm_invoke_set_guest_debug, &data); return data.err; @@ -1821,7 +1821,7 @@ int kvm_insert_breakpoint(CPUArchState *current_env= , target_ulong addr, int err; =20 if (type =3D=3D GDB_BREAKPOINT_SW) { - bp =3D kvm_find_sw_breakpoint(current_env, addr); + bp =3D kvm_find_sw_breakpoint(current_cpu, addr); if (bp) { bp->use_count++; return 0; @@ -1840,7 +1840,7 @@ int kvm_insert_breakpoint(CPUArchState *current_env= , target_ulong addr, return err; } =20 - QTAILQ_INSERT_HEAD(¤t_env->kvm_state->kvm_sw_breakpoints, + QTAILQ_INSERT_HEAD(¤t_cpu->kvm_state->kvm_sw_breakpoints, bp, entry); } else { err =3D kvm_arch_insert_hw_breakpoint(addr, len, type); @@ -1867,7 +1867,7 @@ int kvm_remove_breakpoint(CPUArchState *current_env= , target_ulong addr, int err; =20 if (type =3D=3D GDB_BREAKPOINT_SW) { - bp =3D kvm_find_sw_breakpoint(current_env, addr); + bp =3D kvm_find_sw_breakpoint(current_cpu, addr); if (!bp) { return -ENOENT; } @@ -1882,7 +1882,7 @@ int kvm_remove_breakpoint(CPUArchState *current_env= , target_ulong addr, return err; } =20 - QTAILQ_REMOVE(¤t_env->kvm_state->kvm_sw_breakpoints, bp, e= ntry); + QTAILQ_REMOVE(¤t_cpu->kvm_state->kvm_sw_breakpoints, bp, e= ntry); g_free(bp); } else { err =3D kvm_arch_remove_hw_breakpoint(addr, len, type); @@ -1904,7 +1904,7 @@ void kvm_remove_all_breakpoints(CPUArchState *curre= nt_env) { CPUState *current_cpu =3D ENV_GET_CPU(current_env); struct kvm_sw_breakpoint *bp, *next; - KVMState *s =3D current_env->kvm_state; + KVMState *s =3D current_cpu->kvm_state; CPUArchState *env; CPUState *cpu; =20 diff --git a/kvm.h b/kvm.h index a2375ff..6ddcdc5 100644 --- a/kvm.h +++ b/kvm.h @@ -207,10 +207,10 @@ struct kvm_sw_breakpoint { =20 QTAILQ_HEAD(kvm_sw_breakpoint_head, kvm_sw_breakpoint); =20 -struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUArchState *env, +struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUState *cpu, target_ulong pc); =20 -int kvm_sw_breakpoints_active(CPUArchState *env); +int kvm_sw_breakpoints_active(CPUState *cpu); =20 int kvm_arch_insert_sw_breakpoint(CPUState *current_cpu, struct kvm_sw_breakpoint *bp); diff --git a/target-i386/cpu.c b/target-i386/cpu.c index c6c2ca0..a014fa8 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1614,6 +1614,9 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) { + X86CPU *cpu =3D x86_env_get_cpu(env); + CPUState *cs =3D CPU(cpu); + /* test if maximum index reached */ if (index & 0x80000000) { if (index > env->cpuid_xlevel) { @@ -1730,7 +1733,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, case 0xA: /* Architectural Performance Monitoring Leaf */ if (kvm_enabled()) { - KVMState *s =3D env->kvm_state; + KVMState *s =3D cs->kvm_state; =20 *eax =3D kvm_arch_get_supported_cpuid(s, 0xA, count, R_EAX); *ebx =3D kvm_arch_get_supported_cpuid(s, 0xA, count, R_EBX); @@ -1753,7 +1756,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, break; } if (kvm_enabled()) { - KVMState *s =3D env->kvm_state; + KVMState *s =3D cs->kvm_state; =20 *eax =3D kvm_arch_get_supported_cpuid(s, 0xd, count, R_EAX); *ebx =3D kvm_arch_get_supported_cpuid(s, 0xd, count, R_EBX); diff --git a/target-i386/kvm.c b/target-i386/kvm.c index b2efa1e..ff5c9cd 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -316,7 +316,7 @@ int kvm_arch_on_sigbus_vcpu(CPUState *c, int code, vo= id *addr) if ((env->mcg_cap & MCG_SER_P) && addr && (code =3D=3D BUS_MCEERR_AR || code =3D=3D BUS_MCEERR_AO)) { if (qemu_ram_addr_from_host(addr, &ram_addr) || - !kvm_physical_memory_addr_from_host(env->kvm_state, addr, &p= addr)) { + !kvm_physical_memory_addr_from_host(c->kvm_state, addr, &pad= dr)) { fprintf(stderr, "Hardware memory error for memory used by " "QEMU itself instead of guest system!\n"); /* Hope we are lucky for AO MCE */ @@ -348,8 +348,8 @@ int kvm_arch_on_sigbus(int code, void *addr) =20 /* Hope we are lucky for AO MCE */ if (qemu_ram_addr_from_host(addr, &ram_addr) || - !kvm_physical_memory_addr_from_host(first_cpu->kvm_state, ad= dr, - &paddr)) { + !kvm_physical_memory_addr_from_host(CPU(first_cpu)->kvm_stat= e, + addr, &paddr)) { fprintf(stderr, "Hardware memory error for memory used by " "QEMU itself instead of guest system!: %p\n", addr); return 0; @@ -579,12 +579,12 @@ int kvm_arch_init_vcpu(CPUState *cs) =20 if (((env->cpuid_version >> 8)&0xF) >=3D 6 && (env->cpuid_features&(CPUID_MCE|CPUID_MCA)) =3D=3D (CPUID_MCE= |CPUID_MCA) - && kvm_check_extension(env->kvm_state, KVM_CAP_MCE) > 0) { + && kvm_check_extension(cs->kvm_state, KVM_CAP_MCE) > 0) { uint64_t mcg_cap; int banks; int ret; =20 - ret =3D kvm_get_mce_cap_supported(env->kvm_state, &mcg_cap, &ban= ks); + ret =3D kvm_get_mce_cap_supported(cs->kvm_state, &mcg_cap, &bank= s); if (ret < 0) { fprintf(stderr, "kvm_get_mce_cap_supported: %s", strerror(-r= et)); return ret; @@ -612,7 +612,7 @@ int kvm_arch_init_vcpu(CPUState *cs) return r; } =20 - r =3D kvm_check_extension(env->kvm_state, KVM_CAP_TSC_CONTROL); + r =3D kvm_check_extension(cs->kvm_state, KVM_CAP_TSC_CONTROL); if (r && env->tsc_khz) { r =3D kvm_vcpu_ioctl(cs, KVM_SET_TSC_KHZ, env->tsc_khz); if (r < 0) { @@ -1977,9 +1977,10 @@ void kvm_arch_remove_all_hw_breakpoints(void) =20 static CPUWatchpoint hw_watchpoint; =20 -static int kvm_handle_debug(CPUX86State *env, +static int kvm_handle_debug(X86CPU *cpu, struct kvm_debug_exit_arch *arch_info) { + CPUX86State *env =3D &cpu->env; int ret =3D 0; int n; =20 @@ -2011,7 +2012,7 @@ static int kvm_handle_debug(CPUX86State *env, } } } - } else if (kvm_find_sw_breakpoint(env, arch_info->pc)) { + } else if (kvm_find_sw_breakpoint(CPU(cpu), arch_info->pc)) { ret =3D EXCP_DEBUG; } if (ret =3D=3D 0) { @@ -2028,7 +2029,6 @@ static int kvm_handle_debug(CPUX86State *env, =20 void kvm_arch_update_guest_debug(CPUState *cpu, struct kvm_guest_debug *= dbg) { - CPUX86State *env =3D &X86_CPU(cpu)->env; const uint8_t type_code[] =3D { [GDB_BREAKPOINT_HW] =3D 0x0, [GDB_WATCHPOINT_WRITE] =3D 0x1, @@ -2039,7 +2039,7 @@ void kvm_arch_update_guest_debug(CPUState *cpu, str= uct kvm_guest_debug *dbg) }; int n; =20 - if (kvm_sw_breakpoints_active(env)) { + if (kvm_sw_breakpoints_active(cpu)) { dbg->control |=3D KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_USE_SW_BP; } if (nb_hw_breakpoint > 0) { @@ -2106,7 +2106,7 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_r= un *run) break; case KVM_EXIT_DEBUG: DPRINTF("kvm_exit_debug\n"); - ret =3D kvm_handle_debug(env, &run->debug.arch); + ret =3D kvm_handle_debug(cpu, &run->debug.arch); break; default: fprintf(stderr, "KVM: unknown exit reason %d\n", run->exit_reaso= n); diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c index ad5bc66..7f21540 100644 --- a/target-ppc/kvm.c +++ b/target-ppc/kvm.c @@ -140,7 +140,7 @@ static int kvm_booke206_tlb_init(PowerPCCPU *cpu) int ret, i; =20 if (!kvm_enabled() || - !kvm_check_extension(env->kvm_state, KVM_CAP_SW_TLB)) { + !kvm_check_extension(cs->kvm_state, KVM_CAP_SW_TLB)) { return 0; } =20 @@ -178,7 +178,7 @@ static int kvm_booke206_tlb_init(PowerPCCPU *cpu) =20 =20 #if defined(TARGET_PPC64) -static void kvm_get_fallback_smmu_info(CPUPPCState *env, +static void kvm_get_fallback_smmu_info(CPUState *cs, struct kvm_ppc_smmu_info *info) { memset(info, 0, sizeof(*info)); @@ -206,7 +206,7 @@ static void kvm_get_fallback_smmu_info(CPUPPCState *e= nv, * implements KVM_CAP_PPC_GET_SMMU_INFO and thus doesn't hit * this fallback. */ - if (kvm_check_extension(env->kvm_state, KVM_CAP_PPC_GET_PVINFO)) { + if (kvm_check_extension(cs->kvm_state, KVM_CAP_PPC_GET_PVINFO)) { /* No flags */ info->flags =3D 0; info->slb_size =3D 64; @@ -262,18 +262,19 @@ static void kvm_get_fallback_smmu_info(CPUPPCState = *env, } } =20 -static void kvm_get_smmu_info(CPUPPCState *env, struct kvm_ppc_smmu_info= *info) +static void kvm_get_smmu_info(PowerPCCPU *cpu, struct kvm_ppc_smmu_info = *info) { + CPUState *cs =3D CPU(cpu); int ret; =20 - if (kvm_check_extension(env->kvm_state, KVM_CAP_PPC_GET_SMMU_INFO)) = { - ret =3D kvm_vm_ioctl(env->kvm_state, KVM_PPC_GET_SMMU_INFO, info= ); + if (kvm_check_extension(cs->kvm_state, KVM_CAP_PPC_GET_SMMU_INFO)) { + ret =3D kvm_vm_ioctl(cs->kvm_state, KVM_PPC_GET_SMMU_INFO, info)= ; if (ret =3D=3D 0) { return; } } =20 - kvm_get_fallback_smmu_info(env, info); + kvm_get_fallback_smmu_info(cs, info); } =20 static long getrampagesize(void) @@ -316,10 +317,11 @@ static bool kvm_valid_page_size(uint32_t flags, lon= g rampgsize, uint32_t shift) return (1ul << shift) <=3D rampgsize; } =20 -static void kvm_fixup_page_sizes(CPUPPCState *env) +static void kvm_fixup_page_sizes(PowerPCCPU *cpu) { static struct kvm_ppc_smmu_info smmu_info; static bool has_smmu_info; + CPUPPCState *env =3D &cpu->env; long rampagesize; int iq, ik, jq, jk; =20 @@ -330,7 +332,7 @@ static void kvm_fixup_page_sizes(CPUPPCState *env) =20 /* Collect MMU info from kernel if not already */ if (!has_smmu_info) { - kvm_get_smmu_info(env, &smmu_info); + kvm_get_smmu_info(cpu, &smmu_info); has_smmu_info =3D true; } =20 @@ -373,7 +375,7 @@ static void kvm_fixup_page_sizes(CPUPPCState *env) } #else /* defined (TARGET_PPC64) */ =20 -static inline void kvm_fixup_page_sizes(CPUPPCState *env) +static inline void kvm_fixup_page_sizes(PowerPCCPU *cpu) { } =20 @@ -386,7 +388,7 @@ int kvm_arch_init_vcpu(CPUState *cs) int ret; =20 /* Gather server mmu info from KVM and update the CPU state */ - kvm_fixup_page_sizes(cenv); + kvm_fixup_page_sizes(cpu); =20 /* Synchronize sregs with kvm */ ret =3D kvm_arch_sync_sregs(cpu); @@ -986,12 +988,14 @@ uint32_t kvmppc_get_dfp(void) =20 int kvmppc_get_hypercall(CPUPPCState *env, uint8_t *buf, int buf_len) { + PowerPCCPU *cpu =3D ppc_env_get_cpu(env); + CPUState *cs =3D CPU(cpu); uint32_t *hc =3D (uint32_t*)buf; =20 struct kvm_ppc_pvinfo pvinfo; =20 - if (kvm_check_extension(env->kvm_state, KVM_CAP_PPC_GET_PVINFO) && - !kvm_vm_ioctl(env->kvm_state, KVM_PPC_GET_PVINFO, &pvinfo)) { + if (kvm_check_extension(cs->kvm_state, KVM_CAP_PPC_GET_PVINFO) && + !kvm_vm_ioctl(cs->kvm_state, KVM_PPC_GET_PVINFO, &pvinfo)) { memcpy(buf, pvinfo.hcall, buf_len); =20 return 0; diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c index 5422678..4e34304 100644 --- a/target-s390x/kvm.c +++ b/target-s390x/kvm.c @@ -291,12 +291,11 @@ int kvm_arch_process_async_events(CPUState *cs) void kvm_s390_interrupt_internal(S390CPU *cpu, int type, uint32_t parm, uint64_t parm64, int vm) { - CPUS390XState *env =3D &cpu->env; CPUState *cs =3D CPU(cpu); struct kvm_s390_interrupt kvmint; int r; =20 - if (!env->kvm_state) { + if (!cs->kvm_state) { return; } =20 @@ -305,7 +304,7 @@ void kvm_s390_interrupt_internal(S390CPU *cpu, int ty= pe, uint32_t parm, kvmint.parm64 =3D parm64; =20 if (vm) { - r =3D kvm_vm_ioctl(env->kvm_state, KVM_S390_INTERRUPT, &kvmint); + r =3D kvm_vm_ioctl(cs->kvm_state, KVM_S390_INTERRUPT, &kvmint); } else { r =3D kvm_vcpu_ioctl(cs, KVM_S390_INTERRUPT, &kvmint); } --=20 1.7.10.4