From ce25d6fb8e161d45db25bdae5ffee395b3466641 Mon Sep 17 00:00:00 2001 From: Alexandr Semenikhin Date: Tue, 6 Jan 2026 10:31:29 +0000 Subject: [PATCH 1/2] util: Fix max socket calculation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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é Tested-by: Daniel P. Berrangé Signed-off-by: Alexandr Semenikhin (cherry picked from commit a64367115015df58e0d82635a40d76df56144c60 https://github.com/libvirt/libvirt/commits/) Link: https://lists.libvirt.org/archives/list/devel@lists.libvirt.org/thread/COIBU2IGVLC36Q3FLXDL3W7U7WIFVPPJ/ Signed-off-by: Nathan Chen --- 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 c3b4f87de1..cba6c956d7 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; - virBitmapSetBitExpand(sockets_map, sock); + 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); + } - if (sock > sock_max) - sock_max = sock; + virBitmapSetBitExpand(sockets_map, 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")); From 405c45e12a69313405ab6887862218a9c31ef477 Mon Sep 17 00:00:00 2001 From: Nathan Chen Date: Wed, 4 Feb 2026 05:57:42 +0000 Subject: [PATCH 2/2] 11.9.0+nvidia4-1 Signed-off-by: Nathan Chen --- debian/changelog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/debian/changelog b/debian/changelog index 50386d52ca..aefa11240a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +libvirt (11.9.0+nvidia4-1) noble; urgency=medium + + * util: Fix max socket calculation + + -- Nathan Chen Tue, 03 Feb 2026 21:57:12 -0800 + libvirt (11.9.0+nvidia3-1) noble; urgency=medium * NVIDIA: SAUCE: qemu: Use pci_bus to identify multi-smmuv3 model