Skip to content

Commit fbf5015

Browse files
bonzinigregkh
authored andcommitted
KVM: x86: Do not return host topology information from KVM_GET_SUPPORTED_CPUID
[ Upstream commit 45e966f ] Passing the host topology to the guest is almost certainly wrong and will confuse the scheduler. In addition, several fields of these CPUID leaves vary on each processor; it is simply impossible to return the right values from KVM_GET_SUPPORTED_CPUID in such a way that they can be passed to KVM_SET_CPUID2. The values that will most likely prevent confusion are all zeroes. Userspace will have to override it anyway if it wishes to present a specific topology to the guest. Cc: [email protected] Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent ee16841 commit fbf5015

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

Documentation/virt/kvm/api.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7300,6 +7300,20 @@ CPU[EAX=1]:ECX[24] (TSC_DEADLINE) is not reported by ``KVM_GET_SUPPORTED_CPUID``
73007300
It can be enabled if ``KVM_CAP_TSC_DEADLINE_TIMER`` is present and the kernel
73017301
has enabled in-kernel emulation of the local APIC.
73027302

7303+
CPU topology
7304+
~~~~~~~~~~~~
7305+
7306+
Several CPUID values include topology information for the host CPU:
7307+
0x0b and 0x1f for Intel systems, 0x8000001e for AMD systems. Different
7308+
versions of KVM return different values for this information and userspace
7309+
should not rely on it. Currently they return all zeroes.
7310+
7311+
If userspace wishes to set up a guest topology, it should be careful that
7312+
the values of these three leaves differ for each CPU. In particular,
7313+
the APIC ID is found in EDX for all subleaves of 0x0b and 0x1f, and in EAX
7314+
for 0x8000001e; the latter also encodes the core id and node id in bits
7315+
7:0 of EBX and ECX respectively.
7316+
73037317
Obsolete ioctls and capabilities
73047318
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
73057319

arch/x86/kvm/cpuid.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -567,16 +567,22 @@ struct kvm_cpuid_array {
567567
int nent;
568568
};
569569

570+
static struct kvm_cpuid_entry2 *get_next_cpuid(struct kvm_cpuid_array *array)
571+
{
572+
if (array->nent >= array->maxnent)
573+
return NULL;
574+
575+
return &array->entries[array->nent++];
576+
}
577+
570578
static struct kvm_cpuid_entry2 *do_host_cpuid(struct kvm_cpuid_array *array,
571579
u32 function, u32 index)
572580
{
573-
struct kvm_cpuid_entry2 *entry;
581+
struct kvm_cpuid_entry2 *entry = get_next_cpuid(array);
574582

575-
if (array->nent >= array->maxnent)
583+
if (!entry)
576584
return NULL;
577585

578-
entry = &array->entries[array->nent++];
579-
580586
entry->function = function;
581587
entry->index = index;
582588
entry->flags = 0;
@@ -755,22 +761,13 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
755761
entry->edx = edx.full;
756762
break;
757763
}
758-
/*
759-
* Per Intel's SDM, the 0x1f is a superset of 0xb,
760-
* thus they can be handled by common code.
761-
*/
762764
case 0x1f:
763765
case 0xb:
764766
/*
765-
* Populate entries until the level type (ECX[15:8]) of the
766-
* previous entry is zero. Note, CPUID EAX.{0x1f,0xb}.0 is
767-
* the starting entry, filled by the primary do_host_cpuid().
767+
* No topology; a valid topology is indicated by the presence
768+
* of subleaf 1.
768769
*/
769-
for (i = 1; entry->ecx & 0xff00; ++i) {
770-
entry = do_host_cpuid(array, function, i);
771-
if (!entry)
772-
goto out;
773-
}
770+
entry->eax = entry->ebx = entry->ecx = 0;
774771
break;
775772
case 0xd:
776773
entry->eax &= supported_xcr0;
@@ -962,6 +959,9 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
962959
entry->ebx = entry->ecx = entry->edx = 0;
963960
break;
964961
case 0x8000001e:
962+
/* Do not return host topology information. */
963+
entry->eax = entry->ebx = entry->ecx = 0;
964+
entry->edx = 0; /* reserved */
965965
break;
966966
case 0x8000001F:
967967
if (!kvm_cpu_cap_has(X86_FEATURE_SEV)) {

0 commit comments

Comments
 (0)