Skip to content

Commit 6f5c960

Browse files
kraxelsean-jc
authored andcommitted
KVM: x86: Don't advertise guest.MAXPHYADDR as host.MAXPHYADDR in CPUID
Drop KVM's propagation of GuestPhysBits (CPUID leaf 80000008, EAX[23:16]) to HostPhysBits (same leaf, EAX[7:0]) when advertising the address widths to userspace via KVM_GET_SUPPORTED_CPUID. Per AMD, GuestPhysBits is intended for software use, and physical CPUs do not set that field. I.e. GuestPhysBits will be non-zero if and only if KVM is running as a nested hypervisor, and in that case, GuestPhysBits is NOT guaranteed to capture the CPU's effective MAXPHYADDR when running with TDP enabled. E.g. KVM will soon use GuestPhysBits to communicate the CPU's maximum *addressable* guest physical address, which would result in KVM under- reporting PhysBits when running as an L1 on a CPU with MAXPHYADDR=52, but without 5-level paging. Signed-off-by: Gerd Hoffmann <[email protected]> Cc: [email protected] Reviewed-by: Xiaoyao Li <[email protected]> Link: https://lore.kernel.org/r/[email protected] [sean: rewrite changelog with --verbose, Cc stable@] Signed-off-by: Sean Christopherson <[email protected]>
1 parent fec50db commit 6f5c960

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

arch/x86/kvm/cpuid.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,26 +1231,25 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
12311231
entry->eax = entry->ebx = entry->ecx = 0;
12321232
break;
12331233
case 0x80000008: {
1234-
unsigned g_phys_as = (entry->eax >> 16) & 0xff;
1235-
unsigned virt_as = max((entry->eax >> 8) & 0xff, 48U);
1236-
unsigned phys_as = entry->eax & 0xff;
1234+
unsigned int virt_as = max((entry->eax >> 8) & 0xff, 48U);
1235+
unsigned int phys_as;
12371236

12381237
/*
12391238
* If TDP (NPT) is disabled use the adjusted host MAXPHYADDR as
12401239
* the guest operates in the same PA space as the host, i.e.
12411240
* reductions in MAXPHYADDR for memory encryption affect shadow
12421241
* paging, too.
12431242
*
1244-
* If TDP is enabled but an explicit guest MAXPHYADDR is not
1245-
* provided, use the raw bare metal MAXPHYADDR as reductions to
1246-
* the HPAs do not affect GPAs.
1243+
* If TDP is enabled, use the raw bare metal MAXPHYADDR as
1244+
* reductions to the HPAs do not affect GPAs.
12471245
*/
1248-
if (!tdp_enabled)
1249-
g_phys_as = boot_cpu_data.x86_phys_bits;
1250-
else if (!g_phys_as)
1251-
g_phys_as = phys_as;
1246+
if (!tdp_enabled) {
1247+
phys_as = boot_cpu_data.x86_phys_bits;
1248+
} else {
1249+
phys_as = entry->eax & 0xff;
1250+
}
12521251

1253-
entry->eax = g_phys_as | (virt_as << 8);
1252+
entry->eax = phys_as | (virt_as << 8);
12541253
entry->ecx &= ~(GENMASK(31, 16) | GENMASK(11, 8));
12551254
entry->edx = 0;
12561255
cpuid_entry_override(entry, CPUID_8000_0008_EBX);

0 commit comments

Comments
 (0)