libvirt-11.10.0-10.6.el10nv

- util: Fix max socket calculation (VOYAGER-338)

Resolves: VOYAGER-338
This commit is contained in:
Pavel Hrdina 2026-03-28 13:05:39 +01:00
parent 0909e35830
commit f61b15baa2
2 changed files with 109 additions and 1 deletions

View File

@ -0,0 +1,104 @@
From 8e511697576aec1fc1baad499f64348fd169e093 Mon Sep 17 00:00:00 2001
Message-ID: <8e511697576aec1fc1baad499f64348fd169e093.1774699457.git.phrdina@redhat.com>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Tue, 6 Jan 2026 10:31:29 +0000
Subject: [PATCH] util: Fix max socket calculation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
From: Alexandr Semenikhin <alexandr2e78@gmail.com>
This patch changes how the maximum socket count is calculated.
On some systems (e.g. GB200), physical_package_id values are not
contiguous or zero-based. Instead of 0..N, they may contain large
arbitrary identifiers (e.g. 256123234). The previous implementation
assumed a 0..N range and used the maximum ID value directly.
This caused:
excessive memory allocation
extremely large loop bounds
OOM / DoS scenarios
unnecessary CPU time consumption
The new implementation computes the socket count as the number of unique
package IDs present on the node, rather than relying on the maximum numeric
value.
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Tested-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Alexandr Semenikhin <alexandr2e78@gmail.com>
(cherry picked from commit a64367115015df58e0d82635a40d76df56144c60)
Resolves: https://redhat.atlassian.net/browse/VOYAGER-338
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
src/util/virhostcpu.c | 32 +++++++++++++++++++++++++++++---
1 file changed, 29 insertions(+), 3 deletions(-)
diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
index 09395ddb04..113aa6881e 100644
--- a/src/util/virhostcpu.c
+++ b/src/util/virhostcpu.c
@@ -331,6 +331,8 @@ virHostCPUParseNode(const char *node,
int siblings;
unsigned int cpu;
int direrr;
+ g_autoptr(GHashTable) st = g_hash_table_new(g_direct_hash, g_direct_equal);
+ gpointer sock_resolved;
*threads = 0;
*cores = 0;
@@ -356,15 +358,29 @@ virHostCPUParseNode(const char *node,
if (virHostCPUGetSocket(cpu, &sock) < 0)
goto cleanup;
+ if (!g_hash_table_lookup_extended(st,
+ GUINT_TO_POINTER(sock),
+ NULL,
+ &sock_resolved)) {
+ g_hash_table_insert(st,
+ GUINT_TO_POINTER(sock),
+ GUINT_TO_POINTER(sock_max));
+ sock = sock_max;
+ sock_max++;
+ } else {
+ sock = GPOINTER_TO_UINT(sock_resolved);
+ }
+
virBitmapSetBitExpand(sockets_map, sock);
-
- if (sock > sock_max)
- sock_max = sock;
}
if (direrr < 0)
goto cleanup;
+ if (sock_max == 0) {
+ g_hash_table_insert(st, GUINT_TO_POINTER(0), GUINT_TO_POINTER(sock_max));
+ }
+
sock_max++;
/* allocate cores maps for each socket */
@@ -400,6 +416,16 @@ virHostCPUParseNode(const char *node,
if (virHostCPUGetSocket(cpu, &sock) < 0)
goto cleanup;
+
+ if (!g_hash_table_lookup_extended(st,
+ GUINT_TO_POINTER(sock),
+ NULL,
+ &sock_resolved)) {
+ goto cleanup;
+ }
+
+ sock = GPOINTER_TO_UINT(sock_resolved);
+
if (!virBitmapIsBitSet(sockets_map, sock)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("CPU socket topology has changed"));
--
2.53.0

View File

@ -294,7 +294,7 @@
Summary: Library providing a simple virtualization API
Name: libvirt
Version: 11.10.0
Release: 10.5%{?dist}%{?extra_release}
Release: 10.6%{?dist}%{?extra_release}
License: GPL-2.0-or-later AND LGPL-2.1-only AND LGPL-2.1-or-later AND OFL-1.1
URL: https://libvirt.org/
@ -405,6 +405,7 @@ Patch100: libvirt-conf-Add-iommufd-fdgroup-support.patch
Patch101: libvirt-qemu-Implement-iommufd-fdgroup.patch
Patch102: libvirt-tests-Add-iommufd-fdgroup-test.patch
Patch103: libvirt-hypervisor-Call-virWaitForDevices-after-detaching-host-devices.patch
Patch104: libvirt-util-Fix-max-socket-calculation.patch
Requires: libvirt-daemon = %{version}-%{release}
@ -2796,6 +2797,9 @@ exit 0
%endif
%changelog
* Sat Mar 28 2026 Pavel Hrdina <phrdina@redhat.com> - 11.10.0-10.6
- util: Fix max socket calculation (VOYAGER-338)
* Fri Mar 27 2026 Pavel Hrdina <phrdina@redhat.com> - 11.10.0-10.5
- hypervisor: Call virWaitForDevices() after detaching host devices (VOYAGER-309)