xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/cpuid: Expose number of vCPUs in CPUID.1.EBX
@ 2020-06-18 16:22 Hubert Jasudowicz
  2020-06-18 16:51 ` Andrew Cooper
  0 siblings, 1 reply; 5+ messages in thread
From: Hubert Jasudowicz @ 2020-06-18 16:22 UTC (permalink / raw)
  To: xen-devel; +Cc: Andrew Cooper, Wei Liu, Jan Beulich, Roger Pau Monné

When running under KVM (or presumably other hypervisors) we enable
the CPUID.1.EDX.HTT flag, thus indicating validity of CPUID.1.EBX[23:16]
- maximum number of logical processors which the guest reads as 0.

Although this method of topology detection is considered legacy,
Windows falls back to it when CPUID.0BH.EBX is 0.

CPUID.1.EBX[23:16] being equal to 0, triggers memory corruption in
ntoskrnl.exe as Windows assumes that number of logical processors would
be at least 1. Memory corruption manifests itself while mapping
framebuffer for early graphical subsystem, causing BSOD.

This patch fixes running nested Windows (tested on 7 and 10) with KVM as
L0 hypervisor, by setting the value to maximum number of vCPUs in domain.

Signed-off-by: Hubert Jasudowicz <hubert.jasudowicz@cert.pl>
---
 xen/arch/x86/cpuid.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c
index ee11087626..bf38398ef3 100644
--- a/xen/arch/x86/cpuid.c
+++ b/xen/arch/x86/cpuid.c
@@ -811,10 +811,12 @@ void guest_cpuid(const struct vcpu *v, uint32_t leaf,
 
     case 0x1:
         /* TODO: Rework topology logic. */
-        res->b &= 0x00ffffffu;
+        res->b &= 0x0000ffffu;
         if ( is_hvm_domain(d) )
             res->b |= (v->vcpu_id * 2) << 24;
 
+        res->b |= (d->max_vcpus & 0xff) << 16;
+
         /* TODO: Rework vPMU control in terms of toolstack choices. */
         if ( vpmu_available(v) &&
              vpmu_is_set(vcpu_vpmu(v), VPMU_CPU_HAS_DS) )
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-07-03 14:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-18 16:22 [PATCH] x86/cpuid: Expose number of vCPUs in CPUID.1.EBX Hubert Jasudowicz
2020-06-18 16:51 ` Andrew Cooper
2020-06-19 14:19   ` Hubert Jasudowicz
2020-06-30 20:49     ` Andrew Cooper
2020-07-03 14:36       ` Hubert Jasudowicz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).