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

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