[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v4 27/43] target/i386: Add CPUID.1F generation suppor
From: |
Eduardo Habkost |
Subject: |
[Qemu-devel] [PULL v4 27/43] target/i386: Add CPUID.1F generation support for multi-dies PCMachine |
Date: |
Wed, 3 Jul 2019 15:07:10 -0300 |
From: Like Xu <address@hidden>
The CPUID.1F as Intel V2 Extended Topology Enumeration Leaf would be
exposed if guests want to emulate multiple software-visible die within
each package. Per Intel's SDM, the 0x1f is a superset of 0xb, thus they
can be generated by almost same code as 0xb except die_offset setting.
If the number of dies per package is greater than 1, the cpuid_min_level
would be adjusted to 0x1f regardless of whether the host supports CPUID.1F.
Likewise, the CPUID.1F wouldn't be exposed if env->nr_dies < 2.
Suggested-by: Eduardo Habkost <address@hidden>
Signed-off-by: Like Xu <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Eduardo Habkost <address@hidden>
---
target/i386/cpu.h | 1 +
target/i386/cpu.c | 41 +++++++++++++++++++++++++++++++++++++++++
target/i386/kvm.c | 12 ++++++++++++
3 files changed, 54 insertions(+)
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 85319f4ae1..0a96c78669 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -736,6 +736,7 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS];
#define CPUID_TOPOLOGY_LEVEL_INVALID (0U << 8)
#define CPUID_TOPOLOGY_LEVEL_SMT (1U << 8)
#define CPUID_TOPOLOGY_LEVEL_CORE (2U << 8)
+#define CPUID_TOPOLOGY_LEVEL_DIE (5U << 8)
/* MSR Feature Bits */
#define MSR_ARCH_CAP_RDCL_NO (1U << 0)
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 35ecb4113c..ea52db0600 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -4413,6 +4413,42 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,
uint32_t count,
*ecx |= CPUID_TOPOLOGY_LEVEL_INVALID;
}
+ assert(!(*eax & ~0x1f));
+ *ebx &= 0xffff; /* The count doesn't need to be reliable. */
+ break;
+ case 0x1F:
+ /* V2 Extended Topology Enumeration Leaf */
+ if (env->nr_dies < 2) {
+ *eax = *ebx = *ecx = *edx = 0;
+ break;
+ }
+
+ *ecx = count & 0xff;
+ *edx = cpu->apic_id;
+ switch (count) {
+ case 0:
+ *eax = apicid_core_offset(env->nr_dies, cs->nr_cores,
+ cs->nr_threads);
+ *ebx = cs->nr_threads;
+ *ecx |= CPUID_TOPOLOGY_LEVEL_SMT;
+ break;
+ case 1:
+ *eax = apicid_die_offset(env->nr_dies, cs->nr_cores,
+ cs->nr_threads);
+ *ebx = cs->nr_cores * cs->nr_threads;
+ *ecx |= CPUID_TOPOLOGY_LEVEL_CORE;
+ break;
+ case 2:
+ *eax = apicid_pkg_offset(env->nr_dies, cs->nr_cores,
+ cs->nr_threads);
+ *ebx = env->nr_dies * cs->nr_cores * cs->nr_threads;
+ *ecx |= CPUID_TOPOLOGY_LEVEL_DIE;
+ break;
+ default:
+ *eax = 0;
+ *ebx = 0;
+ *ecx |= CPUID_TOPOLOGY_LEVEL_INVALID;
+ }
assert(!(*eax & ~0x1f));
*ebx &= 0xffff; /* The count doesn't need to be reliable. */
break;
@@ -5094,6 +5130,11 @@ static void x86_cpu_expand_features(X86CPU *cpu, Error
**errp)
x86_cpu_adjust_level(cpu, &cpu->env.cpuid_min_level, 0x14);
}
+ /* CPU topology with multi-dies support requires CPUID[0x1F] */
+ if (env->nr_dies > 1) {
+ x86_cpu_adjust_level(cpu, &env->cpuid_min_level, 0x1F);
+ }
+
/* SVM requires CPUID[0x8000000A] */
if (env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_SVM) {
x86_cpu_adjust_level(cpu, &env->cpuid_min_xlevel, 0x8000000A);
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index e4b4f5756a..473a17e9a5 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -1451,6 +1451,10 @@ int kvm_arch_init_vcpu(CPUState *cs)
}
break;
}
+ case 0x1f:
+ if (env->nr_dies < 2) {
+ break;
+ }
case 4:
case 0xb:
case 0xd:
@@ -1458,6 +1462,11 @@ int kvm_arch_init_vcpu(CPUState *cs)
if (i == 0xd && j == 64) {
break;
}
+
+ if (i == 0x1f && j == 64) {
+ break;
+ }
+
c->function = i;
c->flags = KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
c->index = j;
@@ -1469,6 +1478,9 @@ int kvm_arch_init_vcpu(CPUState *cs)
if (i == 0xb && !(c->ecx & 0xff00)) {
break;
}
+ if (i == 0x1f && !(c->ecx & 0xff00)) {
+ break;
+ }
if (i == 0xd && c->eax == 0) {
continue;
}
--
2.18.0.rc1.1.g3f1ff2140
- [Qemu-devel] [PULL v4 22/43] i386: Don't print warning if phys-bits was set automatically, (continued)
- [Qemu-devel] [PULL v4 22/43] i386: Don't print warning if phys-bits was set automatically, Eduardo Habkost, 2019/07/03
- [Qemu-devel] [PULL v4 18/43] numa: deprecate implict memory distribution between nodes, Eduardo Habkost, 2019/07/03
- [Qemu-devel] [PULL v4 20/43] target/i386: fix feature check in hyperv-stub.c, Eduardo Habkost, 2019/07/03
- [Qemu-devel] [PULL v4 25/43] x86/cpu: use FeatureWordArray to define filtered_features, Eduardo Habkost, 2019/07/03
- [Qemu-devel] [PULL v4 24/43] i386: make 'hv-spinlocks' a regular uint32 property, Eduardo Habkost, 2019/07/03
- [Qemu-devel] [PULL v4 31/43] i386: Introduce SnowRidge CPU model, Eduardo Habkost, 2019/07/03
- [Qemu-devel] [PULL v4 23/43] i386: Fix signedness of hyperv_spinlock_attempts, Eduardo Habkost, 2019/07/03
- [Qemu-devel] [PULL v4 32/43] qmp: Add "alias-of" field to query-cpu-definitions, Eduardo Habkost, 2019/07/03
- [Qemu-devel] [PULL v4 34/43] i386: Get model-id from CPU object on "-cpu help", Eduardo Habkost, 2019/07/03
- [Qemu-devel] [PULL v4 26/43] i386: Remove unused host_cpudef variable, Eduardo Habkost, 2019/07/03
- [Qemu-devel] [PULL v4 27/43] target/i386: Add CPUID.1F generation support for multi-dies PCMachine,
Eduardo Habkost <=
- [Qemu-devel] [PULL v4 29/43] vl.c: Add -smp, dies=* command line support and update doc, Eduardo Habkost, 2019/07/03
- [Qemu-devel] [PULL v4 28/43] machine: Refactor smp_parse() in vl.c as MachineClass::smp_parse(), Eduardo Habkost, 2019/07/03
- [Qemu-devel] [PULL v4 33/43] i386: Add x-force-features option for testing, Eduardo Habkost, 2019/07/03
- [Qemu-devel] [PULL v4 30/43] qmp: Add deprecation information to query-machines, Eduardo Habkost, 2019/07/03
- [Qemu-devel] [PULL v4 35/43] i386: Register versioned CPU models, Eduardo Habkost, 2019/07/03
- [Qemu-devel] [PULL v4 36/43] i386: Define -IBRS, -noTSX, -IBRS versions of CPU models, Eduardo Habkost, 2019/07/03
- [Qemu-devel] [PULL v4 37/43] i386: Replace -noTSX, -IBRS, -IBPB CPU models with aliases, Eduardo Habkost, 2019/07/03
- [Qemu-devel] [PULL v4 38/43] i386: Make unversioned CPU models be aliases, Eduardo Habkost, 2019/07/03
- [Qemu-devel] [PULL v4 39/43] docs: Deprecate CPU model runnability guarantees, Eduardo Habkost, 2019/07/03
- [Qemu-devel] [PULL v4 40/43] i386: Add Cascadelake-Server-v2 CPU model, Eduardo Habkost, 2019/07/03