* [Qemu-devel] [PATCH 1/4] ppc: Remove broken partial PVR matching
2011-10-13 8:40 [Qemu-devel] [0/4] ppc: Implement -host CPU David Gibson
@ 2011-10-13 8:40 ` David Gibson
2011-10-13 8:40 ` [Qemu-devel] [PATCH 2/4] ppc: First cut implementation of -cpu host David Gibson
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: David Gibson @ 2011-10-13 8:40 UTC (permalink / raw)
To: agraf; +Cc: qemu-devel
The ppc target contains a ppc_find_by_pvr() function, which looks up a
CPU spec based on a PVR (that is, based on the value in the target cpu's
Processor Version Register). PVR values contain information on both the
cpu model (upper 16 bits, usually) and on the precise revision (low 16
bits, usually).
ppc_find_by_pvr, as well as making exact PVR matches, attempts to find
"close" PVR matches, when we don't have a CPU spec for the exact revision
specified. This sounds like a good idea, execpt that the current logic
is completely nonsensical.
It seems to assume CPU families are subdivided bit by bit in the PVR in a
way they just aren't. Specifically, it requires a match on all bits of the
specified pvr up to the last non-zero bit. This has the bizarre effect
that when the low bits are simply a sequential revision number (a common
though not universal pattern), then odd specified revisions must be matched
exactly, whereas even specified revisions will also match the next odd
revision, likewise for powers of 4, 8 and so forth.
To correctly do inexact matching we'd need to re-organize the table of CPU
specs to include a mask showing what PVR range the spec is compatible with
(similar to the cputable code in the Linux kernel).
For now, just remove the bogosity by only permitting exact PVR matches.
That at least makes the matching simple and consistent. If we need inexact
matching we can add the necessary per-subfamily masks later.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
target-ppc/translate_init.c | 38 +++++++-------------------------------
1 files changed, 7 insertions(+), 31 deletions(-)
diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
index ca0d852..73b49cf 100644
--- a/target-ppc/translate_init.c
+++ b/target-ppc/translate_init.c
@@ -10043,40 +10043,16 @@ int cpu_ppc_register_internal (CPUPPCState *env, const ppc_def_t *def)
static const ppc_def_t *ppc_find_by_pvr (uint32_t pvr)
{
- const ppc_def_t *ret;
- uint32_t pvr_rev;
- int i, best, match, best_match, max;
+ int i;
- ret = NULL;
- max = ARRAY_SIZE(ppc_defs);
- best = -1;
- pvr_rev = pvr & 0xFFFF;
- /* We want all specified bits to match */
- best_match = 32 - ctz32(pvr_rev);
- for (i = 0; i < max; i++) {
- /* We check that the 16 higher bits are the same to ensure the CPU
- * model will be the choosen one.
- */
- if (((pvr ^ ppc_defs[i].pvr) >> 16) == 0) {
- /* We want as much as possible of the low-level 16 bits
- * to be the same but we allow inexact matches.
- */
- match = clz32(pvr_rev ^ (ppc_defs[i].pvr & 0xFFFF));
- /* We check '>=' instead of '>' because the PPC_defs table
- * is ordered by increasing revision.
- * Then, we will match the higher revision compatible
- * with the requested PVR
- */
- if (match >= best_match) {
- best = i;
- best_match = match;
- }
+ for (i = 0; i < ARRAY_SIZE(ppc_defs); i++) {
+ /* If we have an exact match, we're done */
+ if (pvr == ppc_defs[i].pvr) {
+ return &ppc_defs[i];
}
}
- if (best != -1)
- ret = &ppc_defs[best];
- return ret;
+ return NULL;
}
#include <ctype.h>
--
1.7.6.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 2/4] ppc: First cut implementation of -cpu host
2011-10-13 8:40 [Qemu-devel] [0/4] ppc: Implement -host CPU David Gibson
2011-10-13 8:40 ` [Qemu-devel] [PATCH 1/4] ppc: Remove broken partial PVR matching David Gibson
@ 2011-10-13 8:40 ` David Gibson
2011-10-13 8:40 ` [Qemu-devel] [PATCH 3/4] ppc: Add cpu defs for POWER7 revisions 2.1 and 2.3 David Gibson
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: David Gibson @ 2011-10-13 8:40 UTC (permalink / raw)
To: agraf; +Cc: qemu-devel
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 <david@gibson.dropbear.id.au>
---
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 <kvm.h>
+#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') {
--
1.7.6.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 3/4] ppc: Add cpu defs for POWER7 revisions 2.1 and 2.3
2011-10-13 8:40 [Qemu-devel] [0/4] ppc: Implement -host CPU David Gibson
2011-10-13 8:40 ` [Qemu-devel] [PATCH 1/4] ppc: Remove broken partial PVR matching David Gibson
2011-10-13 8:40 ` [Qemu-devel] [PATCH 2/4] ppc: First cut implementation of -cpu host David Gibson
@ 2011-10-13 8:40 ` David Gibson
2011-10-13 8:40 ` [Qemu-devel] [PATCH 4/4] pseries: Under kvm use guest cpu = host cpu by default David Gibson
2011-10-13 12:01 ` [Qemu-devel] [0/4] ppc: Implement -host CPU Alexander Graf
4 siblings, 0 replies; 6+ messages in thread
From: David Gibson @ 2011-10-13 8:40 UTC (permalink / raw)
To: agraf; +Cc: qemu-devel
This patch adds cpu specs to the table for POWER7 revisions 2.1 and 2.3.
This allows -cpu host to be used on these host cpus.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
target-ppc/translate_init.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
index 62f0a6b..7de097d 100644
--- a/target-ppc/translate_init.c
+++ b/target-ppc/translate_init.c
@@ -7333,6 +7333,8 @@ enum {
CPU_POWERPC_POWER6A = 0x0F000002,
#define CPU_POWERPC_POWER7 CPU_POWERPC_POWER7_v20
CPU_POWERPC_POWER7_v20 = 0x003F0200,
+ CPU_POWERPC_POWER7_v21 = 0x003F0201,
+ CPU_POWERPC_POWER7_v23 = 0x003F0203,
CPU_POWERPC_970 = 0x00390202,
#define CPU_POWERPC_970FX CPU_POWERPC_970FX_v31
CPU_POWERPC_970FX_v10 = 0x00391100,
@@ -9139,6 +9141,8 @@ static const ppc_def_t ppc_defs[] = {
/* POWER7 */
POWERPC_DEF("POWER7", CPU_POWERPC_POWER7, POWER7),
POWERPC_DEF("POWER7_v2.0", CPU_POWERPC_POWER7_v20, POWER7),
+ POWERPC_DEF("POWER7_v2.1", CPU_POWERPC_POWER7_v21, POWER7),
+ POWERPC_DEF("POWER7_v2.3", CPU_POWERPC_POWER7_v23, POWER7),
/* PowerPC 970 */
POWERPC_DEF("970", CPU_POWERPC_970, 970),
/* PowerPC 970FX (G5) */
--
1.7.6.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 4/4] pseries: Under kvm use guest cpu = host cpu by default
2011-10-13 8:40 [Qemu-devel] [0/4] ppc: Implement -host CPU David Gibson
` (2 preceding siblings ...)
2011-10-13 8:40 ` [Qemu-devel] [PATCH 3/4] ppc: Add cpu defs for POWER7 revisions 2.1 and 2.3 David Gibson
@ 2011-10-13 8:40 ` David Gibson
2011-10-13 12:01 ` [Qemu-devel] [0/4] ppc: Implement -host CPU Alexander Graf
4 siblings, 0 replies; 6+ messages in thread
From: David Gibson @ 2011-10-13 8:40 UTC (permalink / raw)
To: agraf; +Cc: qemu-devel
Now that we've implemented -cpu host for ppc, this patch updates the
pseries machine to use the host cpu as the guest cpu by default when
running under KVM. This is important because under KVM Book3S-HV the guest
cpu _cannot_ be of a different type to the host cpu (at the moment
KVM Book3S-HV will silently virtualize the host cpu instead of whatever was
requested, but in future it is likely to simply refuse to run the VM if
a cpu model other than the host's is requested).
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
hw/spapr.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/hw/spapr.c b/hw/spapr.c
index 00b9c67..fecfa4a 100644
--- a/hw/spapr.c
+++ b/hw/spapr.c
@@ -403,7 +403,7 @@ static void ppc_spapr_init(ram_addr_t ram_size,
/* init CPUs */
if (cpu_model == NULL) {
- cpu_model = "POWER7";
+ cpu_model = kvm_enabled() ? "host" : "POWER7";
}
for (i = 0; i < smp_cpus; i++) {
env = cpu_init(cpu_model);
--
1.7.6.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [0/4] ppc: Implement -host CPU
2011-10-13 8:40 [Qemu-devel] [0/4] ppc: Implement -host CPU David Gibson
` (3 preceding siblings ...)
2011-10-13 8:40 ` [Qemu-devel] [PATCH 4/4] pseries: Under kvm use guest cpu = host cpu by default David Gibson
@ 2011-10-13 12:01 ` Alexander Graf
4 siblings, 0 replies; 6+ messages in thread
From: Alexander Graf @ 2011-10-13 12:01 UTC (permalink / raw)
To: David Gibson; +Cc: qemu-devel
On 10/13/2011 10:40 AM, David Gibson wrote:
> This series of patches implements a -cpu host option for ppc,
> analagous to the version that already exists for x86. For now, only
> the basic framework is implement. In later patches, we will need to
> improve the code to override those parts of the cpu spec that can be
> queried from the host, and use this mechanism to subsume, for example,
> the current advertisement by the pseries machine of KVM CPU
> capabilities to the guest.
Thanks, applied all to ppc-next.
Alex
^ permalink raw reply [flat|nested] 6+ messages in thread