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

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