yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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