Blame SOURCES/kvm-i386-cpu-hyperv-support-over-64-vcpus-for-windows-gu.patch

4a2fec
From b2f9f4fcaad9c64f4551ab1dbe9e474c3dc6b2b4 Mon Sep 17 00:00:00 2001
4a2fec
From: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
Date: Mon, 27 Nov 2017 12:59:13 +0100
4a2fec
Subject: [PATCH 10/15] i386/cpu/hyperv: support over 64 vcpus for windows
4a2fec
 guests
4a2fec
4a2fec
RH-Author: vrozenfe <vrozenfe@redhat.com>
4a2fec
Message-id: <1511256034-28105-1-git-send-email-vrozenfe@redhat.com>
4a2fec
Patchwork-id: 77769
4a2fec
O-Subject: [RHEL-7.5 qemu-kvm-rhev PATCH v2] i386/cpu/hyperv: support over 64 vcpus for windows guests
4a2fec
Bugzilla: 1451959
4a2fec
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
4a2fec
RH-Acked-by: Thomas Huth <thuth@redhat.com>
4a2fec
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
4a2fec
From: Gonglei <arei.gonglei@huawei.com>
4a2fec
4a2fec
Upstream-status: 6c69dfb67e84747cf071958594d939e845dfcc0c
4a2fec
4a2fec
Starting with Windows Server 2012 and Windows 8, if
4a2fec
CPUID.40000005.EAX contains a value of -1, Windows assumes specific
4a2fec
limit to the number of VPs. In this case, Windows Server 2012
4a2fec
guest VMs may use more than 64 VPs, up to the maximum supported
4a2fec
number of processors applicable to the specific Windows
4a2fec
version being used.
4a2fec
4a2fec
https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/tlfs
4a2fec
4a2fec
For compatibility, Let's introduce a new property for X86CPU,
4a2fec
named "x-hv-max-vps" as Eduardo's suggestion, and set it
4a2fec
to 0x40 before machine 2.10.
4a2fec
4a2fec
(The "x-" prefix indicates that the property is not supposed to
4a2fec
be a stable user interface.)
4a2fec
4a2fec
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
4a2fec
Message-Id: <1505143227-14324-1-git-send-email-arei.gonglei@huawei.com>
4a2fec
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
Signed-off-by: Vadim Rozenfeld <vrozenfe@redhat.com>
4a2fec
---
4a2fec
 include/hw/i386/pc.h |  5 +++++
4a2fec
 target/i386/cpu.c    | 13 +++++++++++++
4a2fec
 target/i386/cpu.h    |  2 ++
4a2fec
 target/i386/kvm.c    |  3 ++-
4a2fec
 4 files changed, 22 insertions(+), 1 deletion(-)
4a2fec
4a2fec
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
4a2fec
index 7b46121..f9b7998 100644
4a2fec
--- a/include/hw/i386/pc.h
4a2fec
+++ b/include/hw/i386/pc.h
4a2fec
@@ -1089,6 +1089,11 @@ extern void igd_passthrough_isa_bridge_create(PCIBus *bus, uint16_t gpu_dev_id);
4a2fec
             .driver = TYPE_X86_CPU,\
4a2fec
             .property = "kvm-no-smi-migration",\
4a2fec
             .value    = "on",\
4a2fec
+        },\
4a2fec
+        { /* PC_RHEL7_4_COMPAT from PC_COMPAT_2_10 */ \
4a2fec
+             .driver   = TYPE_X86_CPU,\
4a2fec
+             .property = "x-hv-max-vps",\
4a2fec
+             .value    = "0x40",\
4a2fec
         },
4a2fec
 
4a2fec
 #define PC_RHEL7_2_COMPAT \
4a2fec
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
4a2fec
index ca95336..c2dee60 100644
4a2fec
--- a/target/i386/cpu.c
4a2fec
+++ b/target/i386/cpu.c
4a2fec
@@ -4179,6 +4179,19 @@ static Property x86_cpu_properties[] = {
4a2fec
                      false),
4a2fec
     DEFINE_PROP_BOOL("vmware-cpuid-freq", X86CPU, vmware_cpuid_freq, true),
4a2fec
     DEFINE_PROP_BOOL("tcg-cpuid", X86CPU, expose_tcg, true),
4a2fec
+    /*
4a2fec
+     * From "Requirements for Implementing the Microsoft
4a2fec
+     * Hypervisor Interface":
4a2fec
+     * https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/tlfs
4a2fec
+     *
4a2fec
+     * "Starting with Windows Server 2012 and Windows 8, if
4a2fec
+     * CPUID.40000005.EAX contains a value of -1, Windows assumes that
4a2fec
+     * the hypervisor imposes no specific limit to the number of VPs.
4a2fec
+     * In this case, Windows Server 2012 guest VMs may use more than
4a2fec
+     * 64 VPs, up to the maximum supported number of processors applicable
4a2fec
+     * to the specific Windows version being used."
4a2fec
+     */
4a2fec
+    DEFINE_PROP_INT32("x-hv-max-vps", X86CPU, hv_max_vps, -1),
4a2fec
     DEFINE_PROP_END_OF_LIST()
4a2fec
 };
4a2fec
 
4a2fec
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
4a2fec
index 0518673..fd73888 100644
4a2fec
--- a/target/i386/cpu.h
4a2fec
+++ b/target/i386/cpu.h
4a2fec
@@ -1282,6 +1282,8 @@ struct X86CPU {
4a2fec
     int32_t socket_id;
4a2fec
     int32_t core_id;
4a2fec
     int32_t thread_id;
4a2fec
+
4a2fec
+    int32_t hv_max_vps;
4a2fec
 };
4a2fec
 
4a2fec
 static inline X86CPU *x86_env_get_cpu(CPUX86State *env)
4a2fec
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
4a2fec
index 739334a..ee4e91f 100644
4a2fec
--- a/target/i386/kvm.c
4a2fec
+++ b/target/i386/kvm.c
4a2fec
@@ -786,7 +786,8 @@ int kvm_arch_init_vcpu(CPUState *cs)
4a2fec
 
4a2fec
         c = &cpuid_data.entries[cpuid_i++];
4a2fec
         c->function = HYPERV_CPUID_IMPLEMENT_LIMITS;
4a2fec
-        c->eax = 0x40;
4a2fec
+
4a2fec
+        c->eax = cpu->hv_max_vps;
4a2fec
         c->ebx = 0x40;
4a2fec
 
4a2fec
         kvm_base = KVM_CPUID_SIGNATURE_NEXT;
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec