Blame SOURCES/kvm-i386-Fix-up-the-Node-id-for-CPUID_8000_001E.patch

357786
From 7d5a7d6926805c069903bef845d43912cf718410 Mon Sep 17 00:00:00 2001
357786
From: Eduardo Habkost <ehabkost@redhat.com>
357786
Date: Tue, 3 Jul 2018 17:23:54 +0200
357786
Subject: [PATCH 09/89] i386: Fix up the Node id for CPUID_8000_001E
357786
357786
RH-Author: Eduardo Habkost <ehabkost@redhat.com>
357786
Message-id: <20180703172356.21038-9-ehabkost@redhat.com>
357786
Patchwork-id: 81218
357786
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH v3 08/10] i386: Fix up the Node id for CPUID_8000_001E
357786
Bugzilla: 1481253
357786
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
357786
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
357786
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
357786
From: Babu Moger <babu.moger@amd.com>
357786
357786
This is part of topoext support. To keep the compatibility, it is better
357786
we support all the combination of nr_cores and nr_threads currently
357786
supported. By allowing more nr_cores and nr_threads, we might end up with
357786
more nodes than we can actually support with the real hardware. We need to
357786
fix up the node id to make this work. We can achieve this by shifting the
357786
socket_id bits left to address more nodes.
357786
357786
Signed-off-by: Babu Moger <babu.moger@amd.com>
357786
Message-Id: <1529443919-67509-2-git-send-email-babu.moger@amd.com>
357786
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
357786
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
357786
(cherry picked from commit 631be32155dbafa1fe886f2488127956c9120ba6)
357786
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
357786
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
---
357786
 target/i386/cpu.c | 26 +++++++++++++++++++++++++-
357786
 1 file changed, 25 insertions(+), 1 deletion(-)
357786
357786
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
357786
index 643d3b1..ef43ea0 100644
357786
--- a/target/i386/cpu.c
357786
+++ b/target/i386/cpu.c
357786
@@ -19,6 +19,7 @@
357786
 
357786
 #include "qemu/osdep.h"
357786
 #include "qemu/cutils.h"
357786
+#include "qemu/bitops.h"
357786
 
357786
 #include "cpu.h"
357786
 #include "exec/exec-all.h"
357786
@@ -474,6 +475,8 @@ static void encode_topo_cpuid8000001e(CPUState *cs, X86CPU *cpu,
357786
                                        uint32_t *ecx, uint32_t *edx)
357786
 {
357786
     struct core_topology topo = {0};
357786
+    unsigned long nodes;
357786
+    int shift;
357786
 
357786
     build_core_topology(cs->nr_cores, cpu->core_id, &topo;;
357786
     *eax = cpu->apic_id;
357786
@@ -506,7 +509,28 @@ static void encode_topo_cpuid8000001e(CPUState *cs, X86CPU *cpu,
357786
      *         2  Socket id
357786
      *       1:0  Node id
357786
      */
357786
-    *ecx = ((topo.num_nodes - 1) << 8) | (cpu->socket_id << 2) | topo.node_id;
357786
+    if (topo.num_nodes <= 4) {
357786
+        *ecx = ((topo.num_nodes - 1) << 8) | (cpu->socket_id << 2) |
357786
+                topo.node_id;
357786
+    } else {
357786
+        /*
357786
+         * Node id fix up. Actual hardware supports up to 4 nodes. But with
357786
+         * more than 32 cores, we may end up with more than 4 nodes.
357786
+         * Node id is a combination of socket id and node id. Only requirement
357786
+         * here is that this number should be unique accross the system.
357786
+         * Shift the socket id to accommodate more nodes. We dont expect both
357786
+         * socket id and node id to be big number at the same time. This is not
357786
+         * an ideal config but we need to to support it. Max nodes we can have
357786
+         * is 32 (255/8) with 8 cores per node and 255 max cores. We only need
357786
+         * 5 bits for nodes. Find the left most set bit to represent the total
357786
+         * number of nodes. find_last_bit returns last set bit(0 based). Left
357786
+         * shift(+1) the socket id to represent all the nodes.
357786
+         */
357786
+        nodes = topo.num_nodes - 1;
357786
+        shift = find_last_bit(&nodes, 8);
357786
+        *ecx = ((topo.num_nodes - 1) << 8) | (cpu->socket_id << (shift + 1)) |
357786
+                topo.node_id;
357786
+    }
357786
     *edx = 0;
357786
 }
357786
 
357786
-- 
357786
1.8.3.1
357786