From patchwork Thu Jun 18 16:22:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hubert Jasudowicz X-Patchwork-Id: 11612837 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4320014DD for ; Thu, 18 Jun 2020 16:24:06 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 267F4208D5 for ; Thu, 18 Jun 2020 16:24:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 267F4208D5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=cert.pl Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jlxK8-0005t3-CL; Thu, 18 Jun 2020 16:23:32 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jlxK7-0005sy-7f for xen-devel@lists.xenproject.org; Thu, 18 Jun 2020 16:23:31 +0000 X-Inumbo-ID: 0b74dd34-b180-11ea-babb-12813bfff9fa Received: from bagnar.nask.net.pl (unknown [195.187.242.196]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 0b74dd34-b180-11ea-babb-12813bfff9fa; Thu, 18 Jun 2020 16:23:30 +0000 (UTC) Received: from bagnar.nask.net.pl (unknown [172.16.9.10]) by bagnar.nask.net.pl (Postfix) with ESMTP id 08509A31E1; Thu, 18 Jun 2020 18:23:29 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by bagnar.nask.net.pl (Postfix) with ESMTP id F2373A1E22; Thu, 18 Jun 2020 18:23:27 +0200 (CEST) Received: from bagnar.nask.net.pl ([127.0.0.1]) by localhost (bagnar.nask.net.pl [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id t_SUwrxZQpDC; Thu, 18 Jun 2020 18:23:27 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by bagnar.nask.net.pl (Postfix) with ESMTP id 8D2BCA31E1; Thu, 18 Jun 2020 18:23:27 +0200 (CEST) X-Virus-Scanned: amavisd-new at bagnar.nask.net.pl Received: from bagnar.nask.net.pl ([127.0.0.1]) by localhost (bagnar.nask.net.pl [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id ykPHM6-kYoqo; Thu, 18 Jun 2020 18:23:27 +0200 (CEST) Received: from belindir.nask.net.pl (belindir-ext.nask.net.pl [195.187.242.210]) by bagnar.nask.net.pl (Postfix) with ESMTP id 6BE59A1E22; Thu, 18 Jun 2020 18:23:27 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by belindir.nask.net.pl (Postfix) with ESMTP id 5BF4D20981; Thu, 18 Jun 2020 18:22:57 +0200 (CEST) Received: from belindir.nask.net.pl ([127.0.0.1]) by localhost (belindir.nask.net.pl [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id bHSnnSqrvzd7; Thu, 18 Jun 2020 18:22:52 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by belindir.nask.net.pl (Postfix) with ESMTP id EDE8821698; Thu, 18 Jun 2020 18:22:51 +0200 (CEST) X-Virus-Scanned: amavisd-new at belindir.nask.net.pl Received: from belindir.nask.net.pl ([127.0.0.1]) by localhost (belindir.nask.net.pl [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 4TBmn3T2BaKb; Thu, 18 Jun 2020 18:22:51 +0200 (CEST) Received: from arnold.localdomain (unknown [195.187.238.48]) by belindir.nask.net.pl (Postfix) with ESMTPSA id 7D5EF20981; Thu, 18 Jun 2020 18:22:51 +0200 (CEST) From: Hubert Jasudowicz To: xen-devel@lists.xenproject.org Subject: [PATCH] x86/cpuid: Expose number of vCPUs in CPUID.1.EBX Date: Thu, 18 Jun 2020 18:22:33 +0200 Message-Id: X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Wei Liu , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 --- 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) )