[PATCH 0/4] Add support for expanding CPU features in domain capabilities
Consistently with all other CPU definitions, domain capabilities report host-model CPU as a base model and additional list of features. Getting all features supported on a host is possible by passing the host-model CPU definition to hypervisor-cpu-baseline with --features option. But while this is very easy in virsh (domain capabilities can by directly piped to hypervisor-cpu-baseline), doing this via API is more complicated. The relevant part of the domain XML needs to be copied into a new XML document, formatted and passed to virConnectBaselineHypervisorCPU. This series adds the ability to expand CPU features directly in the domain capabilities XML without having to call another API. Jiri Denemark (4): Introduce EXPAND_CPU_FEATURES flag for domain capabilities qemu: Implement VIR_CONNECT_GET_DOMAIN_CAPABILITIES_EXPAND_CPU_FEATURES virsh: Add --expand-cpu-features option for domcapabilities docs: Clarify host-model description in domain capabilities docs/formatdomaincaps.rst | 4 ++++ docs/manpages/virsh.rst | 5 +++++ include/libvirt/libvirt-domain.h | 2 ++ src/libvirt-domain.c | 5 +++++ src/qemu/qemu_driver.c | 9 ++++++++- tools/virsh-host.c | 7 +++++++ 6 files changed, 31 insertions(+), 1 deletion(-) -- 2.53.0
From: Jiri Denemark <jdenemar@redhat.com> The new VIR_CONNECT_GET_DOMAIN_CAPABILITIES_EXPAND_CPU_FEATURES flag for virConnectGetDomainCapabilities can be used to request the host-model CPU definition to include all supported features (normally only extra features relative to the selected CPU model are listed). Signed-off-by: Jiri Denemark <jdenemar@redhat.com> --- include/libvirt/libvirt-domain.h | 2 ++ src/libvirt-domain.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h index d82406fe05..ccc2c87ea8 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -1517,6 +1517,8 @@ int virDomainMigrateStartPostCopy(virDomainPtr domain, typedef enum { /* Report host model with deprecated features disabled. (Since: 11.0.0) */ VIR_CONNECT_GET_DOMAIN_CAPABILITIES_DISABLE_DEPRECATED_FEATURES = (1 << 0), + /* Report all host model CPU features. (Since: 12.2.0) */ + VIR_CONNECT_GET_DOMAIN_CAPABILITIES_EXPAND_CPU_FEATURES = (1 << 1), } virConnectGetDomainCapabilitiesFlags; char * virConnectGetDomainCapabilities(virConnectPtr conn, diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index a1f6efde20..6b8783d57f 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -12330,6 +12330,11 @@ virDomainSetUserPassword(virDomainPtr dom, * instance, if host, libvirt and qemu is capable of VFIO * passthrough and so on. * + * If @flags includes VIR_CONNECT_GET_DOMAIN_CAPABILITIES_EXPAND_CPU_FEATURES, + * libvirt will explicitly list all CPU features (in host-model CPU definition) + * that are supported on the host. Without this flag features that are part of + * the CPU model itself will not be listed. + * * Returns NULL in case of error or an XML string * defining the capabilities. * -- 2.53.0
From: Jiri Denemark <jdenemar@redhat.com> Signed-off-by: Jiri Denemark <jdenemar@redhat.com> --- src/qemu/qemu_driver.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 7d33477636..8b148b33b4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -16748,7 +16748,8 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn, virDomainVirtType virttype; g_autoptr(virDomainCaps) domCaps = NULL; - virCheckFlags(VIR_CONNECT_GET_DOMAIN_CAPABILITIES_DISABLE_DEPRECATED_FEATURES, + virCheckFlags(VIR_CONNECT_GET_DOMAIN_CAPABILITIES_DISABLE_DEPRECATED_FEATURES | + VIR_CONNECT_GET_DOMAIN_CAPABILITIES_EXPAND_CPU_FEATURES, NULL); if (virConnectGetDomainCapabilitiesEnsureACL(conn) < 0) @@ -16774,6 +16775,12 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn, VIR_CPU_FEATURE_DISABLE); } + if (flags & VIR_CONNECT_GET_DOMAIN_CAPABILITIES_EXPAND_CPU_FEATURES) { + virCPUDef *cpu = domCaps->cpu.hostModel; + if (cpu && virCPUExpandFeatures(arch, cpu) < 0) + return NULL; + } + return virDomainCapsFormat(domCaps); } -- 2.53.0
From: Jiri Denemark <jdenemar@redhat.com> Signed-off-by: Jiri Denemark <jdenemar@redhat.com> --- docs/manpages/virsh.rst | 5 +++++ tools/virsh-host.c | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index b3e9289894..591c47a7ce 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -592,6 +592,7 @@ domcapabilities domcapabilities [virttype] [emulatorbin] [arch] [machine] [--xpath EXPRESSION] [--wrap] [--disable-deprecated-features] + [--expand-cpu-features] Print an XML document describing the domain capabilities for the @@ -638,6 +639,10 @@ of host-model CPU XML, updating the features list with any features flagged as deprecated for the CPU model by the hypervisor. These features will be paired with the "disable" policy. +The **--expand-cpu-features** option will cause the host-model CPU definition +to contain all CPU features supported on the host including those implicitly +enabled by the selected CPU model. + pool-capabilities ----------------- diff --git a/tools/virsh-host.c b/tools/virsh-host.c index e918cfa4ca..dd98917fa8 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -118,6 +118,10 @@ static const vshCmdOptDef opts_domcapabilities[] = { .type = VSH_OT_BOOL, .help = N_("report host CPU model with deprecated features disabled"), }, + {.name = "expand-cpu-features", + .type = VSH_OT_BOOL, + .help = N_("show all features in host CPU model"), + }, {.name = NULL} }; @@ -137,6 +141,9 @@ cmdDomCapabilities(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "disable-deprecated-features")) flags |= VIR_CONNECT_GET_DOMAIN_CAPABILITIES_DISABLE_DEPRECATED_FEATURES; + if (vshCommandOptBool(cmd, "expand-cpu-features")) + flags |= VIR_CONNECT_GET_DOMAIN_CAPABILITIES_EXPAND_CPU_FEATURES; + if (vshCommandOptString(ctl, cmd, "virttype", &virttype) < 0 || vshCommandOptString(ctl, cmd, "emulatorbin", &emulatorbin) < 0 || vshCommandOptString(ctl, cmd, "arch", &arch) < 0 || -- 2.53.0
From: Jiri Denemark <jdenemar@redhat.com> Signed-off-by: Jiri Denemark <jdenemar@redhat.com> --- docs/formatdomaincaps.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/formatdomaincaps.rst b/docs/formatdomaincaps.rst index 5a1d3f2670..ed935c704d 100644 --- a/docs/formatdomaincaps.rst +++ b/docs/formatdomaincaps.rst @@ -316,6 +316,10 @@ more details about it: reports physical address size of the host CPU if this value is available and applicable for the requested domain type. This is useful for computing baseline CPU definition which should be compatible with several hosts. + Consistently with all other CPU definitions used by libvirt, features + implicitly enabled by the selected CPU model (in ``model`` sub element) are + not listed. Use ``--expand-cpu-features`` virsh option or the equivalent API + flag to request all supported features to be listed in the CPU definition. ``custom`` The ``mode`` element contains a list of supported CPU models, each described by a dedicated ``model`` element. The ``usable`` attribute specifies whether -- 2.53.0
On Wed, Mar 11, 2026 at 12:39:17 +0100, Jiri Denemark via Devel wrote:
Consistently with all other CPU definitions, domain capabilities report host-model CPU as a base model and additional list of features. Getting all features supported on a host is possible by passing the host-model CPU definition to hypervisor-cpu-baseline with --features option. But while this is very easy in virsh (domain capabilities can by directly piped to hypervisor-cpu-baseline), doing this via API is more complicated. The relevant part of the domain XML needs to be copied into a new XML document, formatted and passed to virConnectBaselineHypervisorCPU.
This series adds the ability to expand CPU features directly in the domain capabilities XML without having to call another API.
Jiri Denemark (4): Introduce EXPAND_CPU_FEATURES flag for domain capabilities qemu: Implement VIR_CONNECT_GET_DOMAIN_CAPABILITIES_EXPAND_CPU_FEATURES virsh: Add --expand-cpu-features option for domcapabilities docs: Clarify host-model description in domain capabilities
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
participants (2)
-
Jiri Denemark -
Peter Krempa