From patchwork Thu Oct 13 08:40:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 119385 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id F2DF3B6F7B for ; Thu, 13 Oct 2011 19:41:01 +1100 (EST) Received: from localhost ([::1]:53478 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1REGqW-0000du-3x for incoming@patchwork.ozlabs.org; Thu, 13 Oct 2011 04:40:56 -0400 Received: from eggs.gnu.org ([140.186.70.92]:45882) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1REGqQ-0000dn-C7 for qemu-devel@nongnu.org; Thu, 13 Oct 2011 04:40:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1REGqM-0003Na-T2 for qemu-devel@nongnu.org; Thu, 13 Oct 2011 04:40:50 -0400 Received: from ozlabs.org ([203.10.76.45]:54880) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1REGqM-0003Mn-5g for qemu-devel@nongnu.org; Thu, 13 Oct 2011 04:40:46 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 2A380B6F83; Thu, 13 Oct 2011 19:40:42 +1100 (EST) From: David Gibson To: agraf@suse.de Date: Thu, 13 Oct 2011 19:40:32 +1100 Message-Id: <1318495234-24196-3-git-send-email-david@gibson.dropbear.id.au> X-Mailer: git-send-email 1.7.6.3 In-Reply-To: <1318495234-24196-1-git-send-email-david@gibson.dropbear.id.au> References: <1318495234-24196-1-git-send-email-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 203.10.76.45 Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 2/4] ppc: First cut implementation of -cpu host X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org For convenience with kvm, x86 allows the user to specify -cpu host on the qemu command line, which means make the guest cpu the same as the host cpu. This patch implements the same option for ppc targets. For now, this just read the host PVR (Processor Version Register) and selects one of our existing CPU specs based on it. This means that the option will not work if the host cpu is not supported by TCG, even if that wouldn't matter for use under kvm. In future, we can extend this in future to override parts of the cpu spec based on information obtained from the host (via /proc/cpuinfo, the host device tree, or explicit KVM calls). That will let us handle cases where the real kvm-virtualized CPU doesn't behave exactly like the TCG-emulated CPU. With appropriate annotation of the CPU specs we'll also then be able to use host cpus under kvm even when there isn't a matching full TCG model. Signed-off-by: David Gibson --- target-ppc/cpu.h | 1 + target-ppc/kvm.c | 19 +++++++++++++++++++ target-ppc/kvm_ppc.h | 6 ++++++ target-ppc/translate_init.c | 8 +++++++- 4 files changed, 33 insertions(+), 1 deletions(-) diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h index 3f77e30..8e5c85c 100644 --- a/target-ppc/cpu.h +++ b/target-ppc/cpu.h @@ -1107,6 +1107,7 @@ void ppc_store_msr (CPUPPCState *env, target_ulong value); void ppc_cpu_list (FILE *f, fprintf_function cpu_fprintf); +const ppc_def_t *ppc_find_by_pvr(uint32_t pvr); const ppc_def_t *cpu_ppc_find_by_name (const char *name); int cpu_ppc_register_internal (CPUPPCState *env, const ppc_def_t *def); diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c index 6a48eb4..430558b 100644 --- a/target-ppc/kvm.c +++ b/target-ppc/kvm.c @@ -878,6 +878,25 @@ int kvmppc_remove_spapr_tce(void *table, int fd, uint32_t window_size) return 0; } +static inline uint32_t mfpvr(void) +{ + uint32_t pvr; + + asm ("mfpvr %0" + : "=r"(pvr)); + return pvr; +} + +const ppc_def_t *kvmppc_host_cpu_def(void) +{ + uint32_t host_pvr = mfpvr(); + const ppc_def_t *base_spec; + + base_spec = ppc_find_by_pvr(host_pvr); + + return base_spec; +} + bool kvm_arch_stop_on_emulation_error(CPUState *env) { return true; diff --git a/target-ppc/kvm_ppc.h b/target-ppc/kvm_ppc.h index fa131bf..0062906 100644 --- a/target-ppc/kvm_ppc.h +++ b/target-ppc/kvm_ppc.h @@ -24,6 +24,7 @@ int kvmppc_smt_threads(void); off_t kvmppc_alloc_rma(const char *name); void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t window_size, int *pfd); int kvmppc_remove_spapr_tce(void *table, int pfd, uint32_t window_size); +const ppc_def_t *kvmppc_host_cpu_def(void); #else @@ -83,6 +84,11 @@ static inline int kvmppc_remove_spapr_tce(void *table, int pfd, return -1; } +static inline const ppc_def_t *kvmppc_host_cpu_def(void) +{ + return NULL; +} + #endif #ifndef CONFIG_KVM diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c index 73b49cf..62f0a6b 100644 --- a/target-ppc/translate_init.c +++ b/target-ppc/translate_init.c @@ -24,6 +24,8 @@ #include "dis-asm.h" #include "gdbstub.h" +#include +#include "kvm_ppc.h" //#define PPC_DUMP_CPU //#define PPC_DEBUG_SPR @@ -10041,7 +10043,7 @@ int cpu_ppc_register_internal (CPUPPCState *env, const ppc_def_t *def) return 0; } -static const ppc_def_t *ppc_find_by_pvr (uint32_t pvr) +const ppc_def_t *ppc_find_by_pvr(uint32_t pvr) { int i; @@ -10063,6 +10065,10 @@ const ppc_def_t *cpu_ppc_find_by_name (const char *name) const char *p; int i, max, len; + if (kvm_enabled() && (strcasecmp(name, "host") == 0)) { + return kvmppc_host_cpu_def(); + } + /* Check if the given name is a PVR */ len = strlen(name); if (len == 10 && name[0] == '0' && name[1] == 'x') {