[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 09/13] cpuid: propagate further CPUID leafs when -cp
From: |
Andre Przywara |
Subject: |
[Qemu-devel] [PATCH 09/13] cpuid: propagate further CPUID leafs when -cpu host |
Date: |
Tue, 2 Feb 2010 11:08:17 +0100 |
-cpu host currently only propagates the CPU's family/model/stepping,
the brand name and the feature bits.
Add a whitelist of safe CPUID leafs to let the guest see the actual
CPU's cache details and other things.
Signed-off-by: Andre Przywara <address@hidden>
---
target-i386/cpu.h | 5 ++++-
target-i386/cpuid.c | 28 ++++++++++++++++++++++------
2 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index f826d3d..982f815 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -581,6 +581,9 @@ typedef struct {
#define NB_MMU_MODES 2
+#define CPUID_FLAGS_VENDOR_OVERRIDE 1
+#define CPUID_FLAGS_HOST 2
+
typedef struct CPUX86State {
/* standard registers */
target_ulong regs[CPU_NB_REGS];
@@ -685,7 +688,7 @@ typedef struct CPUX86State {
uint32_t cpuid_ext2_features;
uint32_t cpuid_ext3_features;
uint32_t cpuid_apic_id;
- int cpuid_vendor_override;
+ uint32_t cpuid_flags;
/* MTRRs */
uint64_t mtrr_fixed[11];
diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c
index 635c2f4..6aa1f3f 100644
--- a/target-i386/cpuid.c
+++ b/target-i386/cpuid.c
@@ -122,7 +122,7 @@ typedef struct x86_def_t {
uint32_t features, ext_features, ext2_features, ext3_features,
kvm_features;
uint32_t xlevel;
char model_id[48];
- int vendor_override;
+ uint32_t flags;
} x86_def_t;
#define I486_FEATURES (CPUID_FP87 | CPUID_VME | CPUID_PSE)
@@ -419,7 +419,7 @@ static int cpu_x86_fill_host(x86_def_t *x86_cpu_def)
x86_cpu_def->ext2_features = edx;
x86_cpu_def->ext3_features = ecx;
cpu_x86_fill_model_id(x86_cpu_def->model_id);
- x86_cpu_def->vendor_override = 0;
+ x86_cpu_def->flags = CPUID_FLAGS_HOST;
return 0;
}
@@ -529,7 +529,7 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def,
const char *cpu_model)
x86_cpu_def->vendor2 |= ((uint8_t)val[i + 4]) << (8 * i);
x86_cpu_def->vendor3 |= ((uint8_t)val[i + 8]) << (8 * i);
}
- x86_cpu_def->vendor_override = 1;
+ x86_cpu_def->flags |= CPUID_FLAGS_VENDOR_OVERRIDE;
} else if (!strcmp(featurestr, "model_id")) {
pstrcpy(x86_cpu_def->model_id, sizeof(x86_cpu_def->model_id),
val);
@@ -602,7 +602,7 @@ int cpu_x86_register (CPUX86State *env, const char
*cpu_model)
env->cpuid_vendor2 = CPUID_VENDOR_INTEL_2;
env->cpuid_vendor3 = CPUID_VENDOR_INTEL_3;
}
- env->cpuid_vendor_override = def->vendor_override;
+ env->cpuid_flags = def->flags;
env->cpuid_level = def->level;
if (def->family > 0x0f)
env->cpuid_version = 0xf00 | ((def->family - 0x0f) << 20);
@@ -647,22 +647,38 @@ static void get_cpuid_vendor(CPUX86State *env, uint32_t
*ebx,
* this if you want to use KVM's sysenter/syscall emulation
* in compatibility mode and when doing cross vendor migration
*/
- if (kvm_enabled() && env->cpuid_vendor_override) {
+ if (kvm_enabled() &&
+ (env->cpuid_flags & CPUID_FLAGS_VENDOR_OVERRIDE) == 0) {
host_cpuid(0, 0, NULL, ebx, ecx, edx);
}
}
+#define CPUID_LEAF_PROPAGATE ((1 << 0x02) | (1 << 0x04) | (1 << 0x05) |\
+ (1 << 0x0D))
+#define CPUID_LEAF_PROPAGATE_EXTENDED ((1 << 0x05) | (1 << 0x06) |\
+ (1 << 0x08) | (1 << 0x19) | (1 << 0x1A))
+
void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
uint32_t *eax, uint32_t *ebx,
uint32_t *ecx, uint32_t *edx)
{
- /* test if maximum index reached */
if (index & 0x80000000) {
+ /* test if maximum index reached */
if (index > env->cpuid_xlevel)
index = env->cpuid_level;
+ if ((env->cpuid_flags & CPUID_FLAGS_HOST) &&
+ ((1 << (index - 0x80000000)) & CPUID_LEAF_PROPAGATE_EXTENDED)) {
+ host_cpuid(index, count, eax, ebx, ecx, edx);
+ return;
+ }
} else {
if (index > env->cpuid_level)
index = env->cpuid_level;
+ if ((env->cpuid_flags & CPUID_FLAGS_HOST) &&
+ ((1 << index) & CPUID_LEAF_PROPAGATE)) {
+ host_cpuid(index, count, eax, ebx, ecx, edx);
+ return;
+ }
}
switch(index) {
--
1.6.4
- [Qemu-devel] [PATCH 00/13] i386 cpuid: cleanup and fixes, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 02/13] cpuid: replace magic number with named constant, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 05/13] cpuid: add missing CPUID feature flag names, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 08/13] cpuid: simplify CPUID flag search function, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 11/13] cpuid: Always expose 32 and 64-bit CPUs, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 10/13] cpuid: add TCG feature bit trimming, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 03/13] cpuid: moved host_cpuid function and remove prototype, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 09/13] cpuid: propagate further CPUID leafs when -cpu host,
Andre Przywara <=
- [Qemu-devel] [PATCH 04/13] cpuid: Replace strtok with get_opt_name, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 01/13] cpuid: move CPUID functions into separate file, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 07/13] cpuid: remove unnecessary kvm_trim function, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 06/13] cpuid: list all known x86 CPUID feature flags, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 12/13] cpuid: Add kvm32 CPU model, Andre Przywara, 2010/02/02
- [Qemu-devel] [PATCH 13/13] cpuid: fix CPUID levels, Andre Przywara, 2010/02/02