[libvirt RFC PATCH 0/2] Expose synthetic host CPU topology status
When the Linux host CPU topology consistency check fails, virNodeGetInfo() returns a synthetic topology. For example, offlining one complete SMT core on each of two NUMA nodes can cause the legacy API to report one NUMA cell, one socket, and one thread per core. Applications cannot distinguish this fallback from detected topology using the existing virNodeInfo fields. We encountered this in a host management application that compared the node count from virNodeGetInfo() with the NUMA cells in capabilities XML. Capacity management had offlined host CPUs, and the synthetic node count no longer matched the detailed topology. This RFC proposes exposing whether the fallback was taken while preserving the legacy API behavior: 1. Add virNodeGetInfoWithFlags() and the VIR_NODE_INFO_TOPOLOGY_FALLBACK result bit, with QEMU driver and remote transport support, documentation, and host CPU test assertions. 2. Add virsh nodeinfo --topology-status, which appends "CPU topology: synthetic" or "CPU topology: detected". Without the option, virsh continues to use the original API and retains its existing output. The series leaves the public virNodeInfo layout and existing RPC reply unchanged. The new API uses a separate remote procedure. Unsupported drivers or older daemons return an error; lack of support is not interpreted as an absence of fallback. The indicator describes whether this particular fallback was taken. A clear bit is not a general guarantee that the legacy topology representation accurately describes every hardware arrangement. Applications needing detailed topology should continue to use virConnectGetCapabilities(). This series does not change the fallback calculation or fix topology and placement assumptions in consumers. Testing ------- Built libvirt 12.9.0 RPMs. All 65 cases in virhostcputest passed, including explicit assertions for normal and fallback topology fixtures. End-to-end testing used a 512-logical-CPU host with two NUMA nodes: NUMA node 0: CPUs 0-127,256-383 NUMA node 1: CPUs 128-255,384-511 Offlined one complete SMT core per node: NUMA node 0: SMT pair 127,383 NUMA node 1: SMT pair 255,511 With 508 CPUs online, the legacy command returned: CPU(s): 508 CPU socket(s): 1 Core(s) per socket: 512 Thread(s) per core: 1 NUMA cell(s): 1 The new virsh option appended: CPU topology: synthetic A standalone C client using virConnectOpenReadOnly("qemu:///system") and virNodeGetInfoWithFlags() returned resultFlags=0x1. After re-enabling all four CPUs, the legacy topology returned to: CPU(s): 512 CPU socket(s): 1 Core(s) per socket: 128 Thread(s) per core: 2 NUMA cell(s): 2 The new option reported "CPU topology: detected", and the C client returned resultFlags=0x0. Both states were checked with explicit qemu:///system and default virsh connections, with and without -r. Legacy nodeinfo output was retained in each state. These are targeted host CPU and integration results; they do not establish a full test-suite pass. RFC questions ------------- Is exposing the fallback state useful enough to justify a new public API, given the recommendation to use capabilities XML for detailed topology? Feedback on the API shape, result flag naming, and virsh presentation would be appreciated. The patches are based on libvirt v12.9.0 (7e809448198e). API version annotations and the new RPC procedure number reflect that base and would need adjustment to the target development branch before merge. Partha Sarathi Satapathy (2): node: Introduce virNodeGetInfoWithFlags virsh: Add --topology-status to nodeinfo docs/manpages/virsh.rst | 12 +++++++- include/libvirt/libvirt-host.h | 16 ++++++++++ src/conf/capabilities.c | 18 ++++++++++- src/conf/capabilities.h | 2 ++ src/driver-hypervisor.h | 7 +++++ src/libvirt-host.c | 57 +++++++++++++++++++++++++++++++++++ src/libvirt_private.syms | 1 + src/libvirt_public.syms | 5 ++++ src/qemu/qemu_driver.c | 16 ++++++++++ src/remote/remote_daemon_dispatch.c | 37 +++++++++++++++++++++++ src/remote/remote_driver.c | 34 +++++++++++++++++++++ src/remote/remote_protocol.x | 18 ++++++++++- src/remote_protocol-structs | 8 +++++ src/util/virhostcpu.c | 16 ++++++++-- src/util/virhostcpu.h | 3 +- src/util/virhostcpupriv.h | 3 +- tests/virhostcputest.c | 60 ++++++++++++++++++++++--------------- tools/virsh-host.c | 25 ++++++++++++++-- 18 files changed, 303 insertions(+), 35 deletions(-) -- 2.43.7
virNodeGetInfo can return a synthetic CPU topology when the Linux topology consistency check fails. Callers cannot distinguish this result from a real single-node topology. Introduce virNodeGetInfoWithFlags and the VIR_NODE_INFO_TOPOLOGY_FALLBACK result flag to expose this distinction without changing virNodeInfo or the existing RPC reply. Propagate the fallback indicator through the host CPU helpers and add QEMU driver support, a separate remote procedure, and API documentation. Extend the host CPU tests to check the indicator for normal and fallback topology results. Assisted-by: Codex:gpt-6-astra Signed-off-by: Partha Sarathi Satapathy <partha.satapathy@oracle.com> --- include/libvirt/libvirt-host.h | 16 ++++++++ src/conf/capabilities.c | 18 ++++++++- src/conf/capabilities.h | 2 + src/driver-hypervisor.h | 7 ++++ src/libvirt-host.c | 57 +++++++++++++++++++++++++++ src/libvirt_private.syms | 1 + src/libvirt_public.syms | 5 +++ src/qemu/qemu_driver.c | 16 ++++++++ src/remote/remote_daemon_dispatch.c | 37 ++++++++++++++++++ src/remote/remote_driver.c | 34 ++++++++++++++++ src/remote/remote_protocol.x | 18 ++++++++- src/remote_protocol-structs | 8 ++++ src/util/virhostcpu.c | 16 ++++++-- src/util/virhostcpu.h | 3 +- src/util/virhostcpupriv.h | 3 +- tests/virhostcputest.c | 60 +++++++++++++++++------------ 16 files changed, 270 insertions(+), 31 deletions(-) diff --git a/include/libvirt/libvirt-host.h b/include/libvirt/libvirt-host.h index 5b448e7954f9..c4c8cf0d1539 100644 --- a/include/libvirt/libvirt-host.h +++ b/include/libvirt/libvirt-host.h @@ -896,6 +896,22 @@ int virConnectGetMaxVcpus (virConnectPtr conn, const char *type); int virNodeGetInfo (virConnectPtr conn, virNodeInfoPtr info); +/** + * virNodeInfoResultFlags: + * + * Result flags returned by virNodeGetInfoWithFlags(). + * + * Since: 12.9.0 + */ +typedef enum { + VIR_NODE_INFO_TOPOLOGY_FALLBACK = (1U << 0), /* Synthetic topology reported (Since: 12.9.0) */ +} virNodeInfoResultFlags; + +int virNodeGetInfoWithFlags(virConnectPtr conn, + virNodeInfoPtr info, + unsigned int *resultFlags, + unsigned int flags); + char * virConnectGetCapabilities (virConnectPtr conn); int virNodeGetCPUStats (virConnectPtr conn, diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index e83de6d1bcfe..03fab1fa16db 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1450,10 +1450,22 @@ virCapabilitiesHostNUMAGetMaxNode(virCapsHostNUMA *caps) int virCapabilitiesGetNodeInfo(virNodeInfoPtr nodeinfo) { + unsigned int resultFlags; + + return virCapabilitiesGetNodeInfoWithFlags(nodeinfo, &resultFlags); +} + + +int +virCapabilitiesGetNodeInfoWithFlags(virNodeInfoPtr nodeinfo, + unsigned int *resultFlags) +{ + bool topologyFallback = false; virArch hostarch = virArchFromHost(); unsigned long long memorybytes; memset(nodeinfo, 0, sizeof(*nodeinfo)); + *resultFlags = 0; if (virStrcpyStatic(nodeinfo->model, virArchToString(hostarch)) < 0) return -1; @@ -1465,9 +1477,13 @@ virCapabilitiesGetNodeInfo(virNodeInfoPtr nodeinfo) if (virHostCPUGetInfo(hostarch, &nodeinfo->cpus, &nodeinfo->mhz, &nodeinfo->nodes, &nodeinfo->sockets, - &nodeinfo->cores, &nodeinfo->threads) < 0) + &nodeinfo->cores, &nodeinfo->threads, + &topologyFallback) < 0) return -1; + if (topologyFallback) + *resultFlags |= VIR_NODE_INFO_TOPOLOGY_FALLBACK; + return 0; } diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index 0482e4297a28..ccc833bba4fa 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -339,6 +339,8 @@ virBitmap *virCapabilitiesHostNUMAGetCpus(virCapsHostNUMA *caps, int virCapabilitiesHostNUMAGetMaxNode(virCapsHostNUMA *caps); int virCapabilitiesGetNodeInfo(virNodeInfoPtr nodeinfo); +int virCapabilitiesGetNodeInfoWithFlags(virNodeInfoPtr nodeinfo, + unsigned int *resultFlags); int virCapabilitiesInitPages(virCaps *caps); diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index 0add95de9671..57bcecb43945 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -75,6 +75,12 @@ typedef int (*virDrvNodeGetInfo)(virConnectPtr conn, virNodeInfoPtr info); +typedef int +(*virDrvNodeGetInfoWithFlags)(virConnectPtr conn, + virNodeInfoPtr info, + unsigned int *resultFlags, + unsigned int flags); + typedef char * (*virDrvConnectGetCapabilities)(virConnectPtr conn); @@ -1507,6 +1513,7 @@ struct _virHypervisorDriver { virDrvConnectGetSysinfo connectGetSysinfo; virDrvConnectGetMaxVcpus connectGetMaxVcpus; virDrvNodeGetInfo nodeGetInfo; + virDrvNodeGetInfoWithFlags nodeGetInfoWithFlags; virDrvConnectGetCapabilities connectGetCapabilities; virDrvConnectListDomains connectListDomains; virDrvConnectNumOfDomains connectNumOfDomains; diff --git a/src/libvirt-host.c b/src/libvirt-host.c index 6b4345b09d1f..11b2eae23f5a 100644 --- a/src/libvirt-host.c +++ b/src/libvirt-host.c @@ -421,6 +421,8 @@ virConnectGetMaxVcpus(virConnectPtr conn, * can't faithfully represent the system. In such cases a fake topology * (nodes = 1, sockets = 1, cores = number of host cpus, threads = 1) which * only correctly represents the total host CPU count is reported. + * Use virNodeGetInfoWithFlags() to determine whether the Linux topology + * consistency check selected synthetic topology. * * Applications are recommended to use the virConnectGetCapabilities() * call instead, which provides all the information except CPU frequency, @@ -456,6 +458,61 @@ virNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) } +/** + * virNodeGetInfoWithFlags: + * @conn: pointer to the hypervisor connection + * @info: pointer to a virNodeInfo structure allocated by the user + * @resultFlags: pointer to receive a bitwise OR of virNodeInfoResultFlags + * @flags: extra flags; not used yet, so callers must always pass 0 + * + * Extract hardware information about the node, as virNodeGetInfo() does, + * and report whether the Linux topology consistency check substituted + * synthetic topology via VIR_NODE_INFO_TOPOLOGY_FALLBACK in @resultFlags. + * A real single-node host does not by itself set this bit. Neither CPU + * online state nor detailed topology should be inferred from this bit; + * use virNodeGetCPUMap() and virConnectGetCapabilities() for those details. + * + * Both output pointers must be non-NULL. Outputs are valid only on success. + * Drivers or remote daemons without support return an error; callers must + * not interpret an unsupported operation as evidence of real topology. + * + * Returns 0 in case of success and -1 in case of failure. + * + * Since: 12.9.0 + */ +int +virNodeGetInfoWithFlags(virConnectPtr conn, + virNodeInfoPtr info, + unsigned int *resultFlags, + unsigned int flags) +{ + VIR_DEBUG("conn=%p, info=%p, resultFlags=%p, flags=0x%x", + conn, info, resultFlags, flags); + + virResetLastError(); + virCheckConnectReturn(conn, -1); + virCheckNonNullArgGoto(info, error); + virCheckNonNullArgGoto(resultFlags, error); + + if (flags) { + virReportInvalidArg(flags, _("unsupported flags (0x%1$x)"), flags); + goto error; + } + + *resultFlags = 0; + if (conn->driver->nodeGetInfoWithFlags) { + if (conn->driver->nodeGetInfoWithFlags(conn, info, resultFlags, flags) < 0) + goto error; + return 0; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return -1; +} + + /** * virConnectGetCapabilities: * @conn: pointer to the hypervisor connection diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 798d2d28c893..ea78251daf36 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -65,6 +65,7 @@ virCapabilitiesDomainSupported; virCapabilitiesFormatXML; virCapabilitiesFreeGuest; virCapabilitiesGetNodeInfo; +virCapabilitiesGetNodeInfoWithFlags; virCapabilitiesHostInitIOMMU; virCapabilitiesHostNUMAAddCell; virCapabilitiesHostNUMAGetCpus; diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 64ed641b7f1b..f88f7f1f24ad 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -961,4 +961,9 @@ LIBVIRT_12.5.0 { virDomainAnnounceInterface; } LIBVIRT_11.2.0; +LIBVIRT_12.9.0 { + global: + virNodeGetInfoWithFlags; +} LIBVIRT_12.5.0; + # .... define new API here using predicted next version number .... diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 59220658972e..f62fe6dabe50 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -16742,6 +16742,21 @@ qemuNodeGetInfo(virConnectPtr conn, } +static int +qemuNodeGetInfoWithFlags(virConnectPtr conn, + virNodeInfoPtr nodeinfo, + unsigned int *resultFlags, + unsigned int flags) +{ + virCheckFlags(0, -1); + + if (virNodeGetInfoWithFlagsEnsureACL(conn) < 0) + return -1; + + return virCapabilitiesGetNodeInfoWithFlags(nodeinfo, resultFlags); +} + + static int qemuNodeGetCPUStats(virConnectPtr conn, int cpuNum, @@ -21148,6 +21163,7 @@ static virHypervisorDriver qemuHypervisorDriver = { .connectGetSysinfo = qemuConnectGetSysinfo, /* 0.8.8 */ .connectGetMaxVcpus = qemuConnectGetMaxVcpus, /* 0.2.1 */ .nodeGetInfo = qemuNodeGetInfo, /* 0.2.0 */ + .nodeGetInfoWithFlags = qemuNodeGetInfoWithFlags, /* 12.9.0 */ .connectGetCapabilities = qemuConnectGetCapabilities, /* 0.2.1 */ .connectListDomains = qemuConnectListDomains, /* 0.2.0 */ .connectNumOfDomains = qemuConnectNumOfDomains, /* 0.2.0 */ diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon_dispatch.c index e54843825086..6dbd8d03a585 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -2808,6 +2808,43 @@ remoteDispatchDomainGetSecurityLabelList(virNetServer *server G_GNUC_UNUSED, return rv; } +static int +remoteDispatchNodeGetInfoWithFlags(virNetServer *server G_GNUC_UNUSED, + virNetServerClient *client, + virNetMessage *msg G_GNUC_UNUSED, + struct virNetMessageError *rerr, + remote_node_get_info_with_flags_args *args, + remote_node_get_info_with_flags_ret *ret) +{ + virNodeInfo info = {0}; + unsigned int resultFlags = 0; + virConnectPtr conn = remoteGetHypervisorConn(client); + int rv = -1; + + if (!conn) + goto cleanup; + + if (virNodeGetInfoWithFlags(conn, &info, &resultFlags, args->flags) < 0) + goto cleanup; + + memcpy(ret->info.model, info.model, sizeof(ret->info.model)); + ret->info.memory = info.memory; + ret->info.cpus = info.cpus; + ret->info.mhz = info.mhz; + ret->info.nodes = info.nodes; + ret->info.sockets = info.sockets; + ret->info.cores = info.cores; + ret->info.threads = info.threads; + ret->resultFlags = resultFlags; + rv = 0; + + cleanup: + if (rv < 0) + virNetMessageSaveError(rerr); + return rv; +} + + static int remoteDispatchNodeGetSecurityModel(virNetServer *server G_GNUC_UNUSED, virNetServerClient *client, diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 5c358d58c47e..e07d4c06c5d1 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -6305,6 +6305,39 @@ remoteDomainGetInterfaceParameters(virDomainPtr domain, } +static int +remoteNodeGetInfoWithFlags(virConnectPtr conn, + virNodeInfoPtr info, + unsigned int *resultFlags, + unsigned int flags) +{ + remote_node_get_info_with_flags_args args = {0}; + remote_node_get_info_with_flags_ret ret = {0}; + struct private_data *priv = conn->privateData; + VIR_LOCK_GUARD lock = remoteDriverLock(priv); + + args.flags = flags; + if (call(conn, priv, 0, REMOTE_PROC_NODE_GET_INFO_WITH_FLAGS, + (xdrproc_t) xdr_remote_node_get_info_with_flags_args, (char *) &args, + (xdrproc_t) xdr_remote_node_get_info_with_flags_ret, (char *) &ret) == -1) + goto cleanup; + + memcpy(info->model, ret.info.model, sizeof(info->model)); + HYPER_TO_ULONG(info->memory, ret.info.memory); + info->cpus = ret.info.cpus; + info->mhz = ret.info.mhz; + info->nodes = ret.info.nodes; + info->sockets = ret.info.sockets; + info->cores = ret.info.cores; + info->threads = ret.info.threads; + *resultFlags = ret.resultFlags; + return 0; + + cleanup: + return -1; +} + + static int remoteNodeGetMemoryParameters(virConnectPtr conn, virTypedParameterPtr params, @@ -7776,6 +7809,7 @@ static virHypervisorDriver hypervisor_driver = { .connectGetSysinfo = remoteConnectGetSysinfo, /* 0.8.8 */ .connectGetMaxVcpus = remoteConnectGetMaxVcpus, /* 0.3.0 */ .nodeGetInfo = remoteNodeGetInfo, /* 0.3.0 */ + .nodeGetInfoWithFlags = remoteNodeGetInfoWithFlags, /* 12.9.0 */ .connectGetCapabilities = remoteConnectGetCapabilities, /* 0.3.0 */ .connectListDomains = remoteConnectListDomains, /* 0.3.0 */ .connectNumOfDomains = remoteConnectNumOfDomains, /* 0.3.0 */ diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 32185fde2fab..9befc41c558d 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -556,6 +556,15 @@ struct remote_node_get_info_ret { /* insert@1 */ int threads; }; +struct remote_node_get_info_with_flags_args { + unsigned int flags; +}; + +struct remote_node_get_info_with_flags_ret { + remote_node_get_info_ret info; + unsigned int resultFlags; +}; + struct remote_connect_get_capabilities_ret { remote_nonnull_string capabilities; }; @@ -7163,5 +7172,12 @@ enum remote_procedure { * @generate: both * @acl: domain:write */ - REMOTE_PROC_DOMAIN_ANNOUNCE_INTERFACE = 456 + REMOTE_PROC_DOMAIN_ANNOUNCE_INTERFACE = 456, + + /** + * @generate: none + * @priority: high + * @acl: connect:read + */ + REMOTE_PROC_NODE_GET_INFO_WITH_FLAGS = 457 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 6093a85c9844..e2df42f1dfcb 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -148,6 +148,13 @@ struct remote_node_get_info_ret { int cores; int threads; }; +struct remote_node_get_info_with_flags_args { + u_int flags; +}; +struct remote_node_get_info_with_flags_ret { + remote_node_get_info_ret info; + u_int resultFlags; +}; struct remote_connect_get_capabilities_ret { remote_nonnull_string capabilities; }; @@ -3815,4 +3822,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_EVENT_VCPU_REMOVED = 454, REMOTE_PROC_DOMAIN_EVENT_CALLBACK_CHANNEL_LIFECYCLE = 455, REMOTE_PROC_DOMAIN_ANNOUNCE_INTERFACE = 456, + REMOTE_PROC_NODE_GET_INFO_WITH_FLAGS = 457, }; diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index a428b0d9e6ca..8ed7f4e23620 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -660,7 +660,8 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo, unsigned int *nodes, unsigned int *sockets, unsigned int *cores, - unsigned int *threads) + unsigned int *threads, + bool *topologyFallback) { g_autoptr(virBitmap) present_cpus_map = NULL; g_autoptr(virBitmap) online_cpus_map = NULL; @@ -673,6 +674,7 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo, g_autofree char *sysfs_cpudir_fallback = NULL; int direrr; + *topologyFallback = false; *mhz = 0; *cpus = *nodes = *sockets = *cores = *threads = 0; @@ -812,6 +814,7 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo, *sockets * *cores * *threads) != (*cpus + offline)) { + *topologyFallback = true; *nodes = 1; *sockets = 1; *cores = *cpus + offline; @@ -951,12 +954,15 @@ virHostCPUGetInfo(virArch hostarch G_GNUC_UNUSED, unsigned int *nodes G_GNUC_UNUSED, unsigned int *sockets G_GNUC_UNUSED, unsigned int *cores G_GNUC_UNUSED, - unsigned int *threads G_GNUC_UNUSED) + unsigned int *threads G_GNUC_UNUSED, + bool *topologyFallback) { #ifdef __linux__ int ret = -1; FILE *cpuinfo = fopen(CPUINFO_PATH, "r"); + *topologyFallback = false; + if (!cpuinfo) { virReportSystemError(errno, _("cannot open %1$s"), CPUINFO_PATH); @@ -965,7 +971,7 @@ virHostCPUGetInfo(virArch hostarch G_GNUC_UNUSED, ret = virHostCPUGetInfoPopulateLinux(cpuinfo, hostarch, cpus, mhz, nodes, - sockets, cores, threads); + sockets, cores, threads, topologyFallback); if (ret < 0) goto cleanup; @@ -976,6 +982,8 @@ virHostCPUGetInfo(virArch hostarch G_GNUC_UNUSED, unsigned long cpu_freq; size_t cpu_freq_len = sizeof(cpu_freq); + *topologyFallback = false; + *cpus = virHostCPUGetCountAppleFreeBSD(); if (*cpus == -1) return -1; @@ -1032,6 +1040,8 @@ virHostCPUGetInfo(virArch hostarch G_GNUC_UNUSED, return 0; #else + *topologyFallback = false; + /* XXX Solaris will need an impl later if they port QEMU driver */ virReportError(VIR_ERR_NO_SUPPORT, "%s", _("node info not implemented on this platform")); diff --git a/src/util/virhostcpu.h b/src/util/virhostcpu.h index 7aa02b35aa5a..9ed1d888a5ca 100644 --- a/src/util/virhostcpu.h +++ b/src/util/virhostcpu.h @@ -55,7 +55,8 @@ int virHostCPUGetInfo(virArch hostarch, unsigned int *nodes, unsigned int *sockets, unsigned int *cores, - unsigned int *threads); + unsigned int *threads, + bool *topologyFallback); int virHostCPUGetKVMMaxVCPUs(void) ATTRIBUTE_MOCKABLE; diff --git a/src/util/virhostcpupriv.h b/src/util/virhostcpupriv.h index f7b1e7c93c95..3033f6d26efa 100644 --- a/src/util/virhostcpupriv.h +++ b/src/util/virhostcpupriv.h @@ -35,7 +35,8 @@ int virHostCPUGetInfoPopulateLinux(FILE *cpuinfo, unsigned int *nodes, unsigned int *sockets, unsigned int *cores, - unsigned int *threads); + unsigned int *threads, + bool *topologyFallback); int virHostCPUGetStatsLinux(FILE *procstat, int cpuNum, diff --git a/tests/virhostcputest.c b/tests/virhostcputest.c index e362ee8d39e8..ce9c95cac961 100644 --- a/tests/virhostcputest.c +++ b/tests/virhostcputest.c @@ -27,10 +27,12 @@ main(void) static int linuxTestCompareFiles(const char *cpuinfofile, virArch arch, - const char *outputfile) + const char *outputfile, + int expectedFallback) { g_autofree char *actualData = NULL; virNodeInfo nodeinfo = { 0 }; + bool topologyFallback = true; g_autoptr(FILE) cpuinfo = NULL; cpuinfo = fopen(cpuinfofile, "r"); @@ -43,7 +45,8 @@ linuxTestCompareFiles(const char *cpuinfofile, if (virHostCPUGetInfoPopulateLinux(cpuinfo, arch, &nodeinfo.cpus, &nodeinfo.mhz, &nodeinfo.nodes, &nodeinfo.sockets, - &nodeinfo.cores, &nodeinfo.threads) < 0) { + &nodeinfo.cores, &nodeinfo.threads, + &topologyFallback) < 0) { if (virTestGetDebug()) { if (virGetLastErrorCode()) VIR_TEST_DEBUG("\n%s", virGetLastErrorMessage()); @@ -51,6 +54,13 @@ linuxTestCompareFiles(const char *cpuinfofile, return -1; } + if (expectedFallback >= 0 && + topologyFallback != !!expectedFallback) { + fprintf(stderr, "Unexpected topology fallback flag: %d (expected %d)\n", + topologyFallback, expectedFallback); + return -1; + } + actualData = g_strdup_printf("CPUs: %u/%u, MHz: %u, Nodes: %u, Sockets: %u, " "Cores: %u, Threads: %u\n", nodeinfo.cpus, VIR_NODEINFO_MAXCPUS(nodeinfo), @@ -148,6 +158,7 @@ linuxCPUStatsCompareFiles(const char *cpustatfile, struct linuxTestHostCPUData { const char *testName; virArch arch; + int expectedFallback; /* -1 skips the explicit flag assertion */ }; static int @@ -168,7 +179,8 @@ linuxTestHostCPU(const void *opaque) abs_srcdir, archStr, data->testName); virFileWrapperAddPrefix(SYSFS_SYSTEM_PATH, sysfs_prefix); - result = linuxTestCompareFiles(cpuinfo, data->arch, output); + result = linuxTestCompareFiles(cpuinfo, data->arch, output, + data->expectedFallback); virFileWrapperRemovePrefix(SYSFS_SYSTEM_PATH); return result; @@ -280,30 +292,30 @@ mymain(void) g_autofree char *datadir = g_strdup_printf("%s/virhostcpudata", abs_srcdir); g_autoptr(DIR) dir = NULL; const struct linuxTestHostCPUData nodeData[] = { - {"test1", VIR_ARCH_X86_64}, - {"test1", VIR_ARCH_PPC}, - {"test2", VIR_ARCH_X86_64}, - {"test3", VIR_ARCH_X86_64}, - {"test4", VIR_ARCH_X86_64}, - {"test5", VIR_ARCH_X86_64}, - {"test6", VIR_ARCH_X86_64}, - {"test7", VIR_ARCH_X86_64}, - {"test8", VIR_ARCH_X86_64}, - {"raspberrypi", VIR_ARCH_ARMV6L}, - {"f21-mustang", VIR_ARCH_AARCH64}, - {"rhelsa-3.19.0-mustang", VIR_ARCH_AARCH64}, - {"rhel74-moonshot", VIR_ARCH_AARCH64}, - {"high-ids", VIR_ARCH_AARCH64}, - {"deconf-cpus", VIR_ARCH_PPC64}, + {"test1", VIR_ARCH_X86_64, 0}, + {"test1", VIR_ARCH_PPC, -1}, + {"test2", VIR_ARCH_X86_64, -1}, + {"test3", VIR_ARCH_X86_64, -1}, + {"test4", VIR_ARCH_X86_64, -1}, + {"test5", VIR_ARCH_X86_64, -1}, + {"test6", VIR_ARCH_X86_64, -1}, + {"test7", VIR_ARCH_X86_64, -1}, + {"test8", VIR_ARCH_X86_64, 1}, + {"raspberrypi", VIR_ARCH_ARMV6L, -1}, + {"f21-mustang", VIR_ARCH_AARCH64, -1}, + {"rhelsa-3.19.0-mustang", VIR_ARCH_AARCH64, -1}, + {"rhel74-moonshot", VIR_ARCH_AARCH64, -1}, + {"high-ids", VIR_ARCH_AARCH64, -1}, + {"deconf-cpus", VIR_ARCH_PPC64, -1}, /* subcores, default configuration */ - {"subcores1", VIR_ARCH_PPC64}, + {"subcores1", VIR_ARCH_PPC64, -1}, /* subcores, some of the cores are offline */ - {"subcores2", VIR_ARCH_PPC64}, + {"subcores2", VIR_ARCH_PPC64, -1}, /* subcores, invalid configuration */ - {"subcores3", VIR_ARCH_PPC64}, - {"with-frequency", VIR_ARCH_S390X}, - {"with-die", VIR_ARCH_X86_64}, - {"with-clusters", VIR_ARCH_AARCH64}, + {"subcores3", VIR_ARCH_PPC64, -1}, + {"with-frequency", VIR_ARCH_S390X, -1}, + {"with-die", VIR_ARCH_X86_64, -1}, + {"with-clusters", VIR_ARCH_AARCH64, -1}, }; if (virInitialize() < 0) -- 2.43.7
On Fri, Nov 27, 2026 at 06:39:05AM +0000, Partha Sarathi Satapathy via Devel wrote:
virNodeGetInfo can return a synthetic CPU topology when the Linux topology consistency check fails. Callers cannot distinguish this result from a real single-node topology.
Introduce virNodeGetInfoWithFlags and the VIR_NODE_INFO_TOPOLOGY_FALLBACK result flag to expose this distinction without changing virNodeInfo or the existing RPC reply.
Propagate the fallback indicator through the host CPU helpers and add QEMU driver support, a separate remote procedure, and API documentation. Extend the host CPU tests to check the indicator for normal and fallback topology results.
Assisted-by: Codex:gpt-6-astra
Please see https://libvirt.org/hacking.html#use-of-ai-content-generators With regards, Daniel -- |: https://berrange.com ~~ https://hachyderm.io/@berrange :| |: https://libvirt.org ~~ https://entangle-photo.org :| |: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
Add an optional --topology-status argument that calls virNodeGetInfoWithFlags and reports CPU topology as synthetic or detected. Preserve the existing API call and output when the option is omitted. Document the option and its use with read-only connections. Assisted-by: Codex:gpt-6-astra Signed-off-by: Partha Sarathi Satapathy <partha.satapathy@oracle.com> --- docs/manpages/virsh.rst | 12 +++++++++++- tools/virsh-host.c | 25 ++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index f533a10776da..b32ce1588185 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -432,11 +432,21 @@ nodeinfo :: - nodeinfo + nodeinfo [--topology-status] Returns basic information about the node, like number and type of CPU, and size of the physical memory. +With *--topology-status*, use ``virNodeGetInfoWithFlags()`` and append +``CPU topology: synthetic`` when the Linux topology consistency check +returned synthetic topology, or ``CPU topology: detected`` otherwise. +This option also works with a read-only connection, for example +``virsh -r nodeinfo --topology-status``. +The command fails if the driver or remote daemon does not support the new +API; an unsupported operation means the topology status is unknown. +Without this option, the command continues to use ``virNodeGetInfo()`` and +its output is unchanged. + Use of this command is strongly discouraged as the information provided is not guaranteed to be accurate on all hardware platforms. diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 0c18db67c438..1f9654f39b04 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -656,13 +656,29 @@ static const vshCmdInfo info_nodeinfo = { .desc = N_("Returns basic information about the node."), }; +static const vshCmdOptDef opts_nodeinfo[] = { + {.name = "topology-status", + .type = VSH_OT_BOOL, + .help = N_("report whether synthetic CPU topology was returned") + }, + {.name = NULL} +}; + static bool -cmdNodeinfo(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) +cmdNodeinfo(vshControl *ctl, const vshCmd *cmd) { virNodeInfo info; + unsigned int resultFlags = 0; + bool topologyStatus = vshCommandOptBool(cmd, "topology-status"); virshControl *priv = ctl->privData; + int ret; + + if (topologyStatus) + ret = virNodeGetInfoWithFlags(priv->conn, &info, &resultFlags, 0); + else + ret = virNodeGetInfo(priv->conn, &info); - if (virNodeGetInfo(priv->conn, &info) < 0) { + if (ret < 0) { vshError(ctl, "%s", _("failed to get node information")); return false; } @@ -675,6 +691,9 @@ cmdNodeinfo(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) vshPrint(ctl, "%-20s %d\n", _("Thread(s) per core:"), info.threads); vshPrint(ctl, "%-20s %d\n", _("NUMA cell(s):"), info.nodes); vshPrint(ctl, "%-20s %lu KiB\n", _("Memory size:"), info.memory); + if (topologyStatus) + vshPrint(ctl, "%-20s %s\n", _("CPU topology:"), + resultFlags & VIR_NODE_INFO_TOPOLOGY_FALLBACK ? _("synthetic") : _("detected")); return true; } @@ -1970,7 +1989,7 @@ const vshCmdDef hostAndHypervisorCmds[] = { }, {.name = "nodeinfo", .handler = cmdNodeinfo, - .opts = NULL, + .opts = opts_nodeinfo, .info = &info_nodeinfo, .flags = 0 }, -- 2.43.7
On Fri, Nov 27, 2026 at 06:39:04AM +0000, Partha Sarathi Satapathy via Devel wrote:
When the Linux host CPU topology consistency check fails, virNodeGetInfo() returns a synthetic topology. For example, offlining one complete SMT core on each of two NUMA nodes can cause the legacy API to report one NUMA cell, one socket, and one thread per core.
Applications cannot distinguish this fallback from detected topology using the existing virNodeInfo fields. We encountered this in a host management application that compared the node count from virNodeGetInfo() with the NUMA cells in capabilities XML. Capacity management had offlined host CPUs, and the synthetic node count no longer matched the detailed topology.
Both the API docs and man page: https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetInfo https://libvirt.org/manpages/virsh.html#nodeinfo report that the nodeinfo topology is likely to be incorrect and that this API/command should not be used if you want accurate info, pointing users/app devs to the capabilities API/XML instead. Comparing the virNodeGetInfo data with the capabilities XML is clearly wrong and serves no purpose. The application in question should just be fixed to use the currently recommended APIs.
Is exposing the fallback state useful enough to justify a new public API, given the recommendation to use capabilities XML for detailed topology? Feedback on the API shape, result flag naming, and virsh presentation would be appreciated.
If applications can't follow the current API docs which state the current nodeinfo API should not be used, it does not seem any more likely they will do the correct thing after these patches are applied. Changing apps to use a new nodeinfoflags API which reports exactly the same broken info, along with returning a flag that says "this information is broken" is just a waste of time. With regards, Daniel -- |: https://berrange.com ~~ https://hachyderm.io/@berrange :| |: https://libvirt.org ~~ https://entangle-photo.org :| |: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
participants (3)
-
Daniel P. Berrangé -
Partha Sarathi Satapathy -
partha.satapathy@oracle.com