Commit Graph
100 Commits
Author SHA1 Message Date
Peter Krempa 82b39d0580 qemu: Fix proper ordering of 'virtlockd' shutdown
In commit aa1bf13b9c I attempted to fix
the ordering of virtlockd and virtlogd during shutdown but I made a typo
in the name of 'virtlockd.service' (missing 'd').

Fixes: aa1bf13b9c
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2026-08-18 10:22:04 +02:00
Peter Krempa 7daf354747 virStorageSourceGetMetadataRecurse: Fix format probing exception for images with 'data_file'
The image metadata crawler code generally forbids qcow2 images which
have a 'backing_file' but don't specify a 'backing_file_fmt' header as
we don't want to probe the format due to security implications.

There's one notable exception for the last image in the chain which can
be format probed if it doesn't have another 'backing_file'.

As the comment in 'virStorageSourceGetMetadataRecurse' suggests we don't
want to allow the probe if anything probed would influence access to
more resources. Unfortunately that didn't involve 'data_file' header
which gives more access.

Fortunately there is no way for a guest OS having a 'raw' disk and
access to libvirt's snapshot API to abuse this as libvirt's snapshot API
does specify the header. Other cases where an arbitrary image is passed
to libvirt can 'backing_file'+'backing_file_fmt' directly to access
arbitrary file on disk so this bug is no worse in this regard.

Nevertheless it's a bug which should be fixed.

Closes: https://gitlab.com/libvirt/libvirt/-/work_items/904
Fixes: 0a3d177d9b
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-08-14 16:54:31 +02:00
Peter Krempa 61522a0bdb virstoragetest: Add example of a qcow2 image with a backing image pointing to a data_file without 'backing_format'
Add an image example which specifies a 'backing_file' without
'backing_format' and the backing file has 'data_file'. This was obtained
by running a hacked qemu-img with bypassed requirement to specify backing
file format:

 $ qemu-img create -f qcow2 -b datafile.qcow2 -u  qcow2_datafile-auto.qcow2 1024

In the test directory.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-08-14 16:54:31 +02:00
Peter Krempa 5e71ea17e2 qemucapabilitiesdata: Update 'caps_11.1.0_aarch64' after qemu release
qemu-11.1 was released, update the capability dump to the final state.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-08-12 17:22:40 +02:00
Peter Krempa 825c3055fe qemucapabilitiesdata: Update 'caps_11.1.0_x86_64' after qemu release
qemu-11.1 was released, update the capability dump to the final state.

Notable change:
 - 'win-dmp' dump format gained 'allowed-by-guest' feature flag

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-08-12 17:22:40 +02:00
Peter Krempa 5a62cbf290 remote: Fix integer overflow in RPC handler for virNodeGetFreePages (CVE-2026-18917)
CVE-2026-18917

The RPC handler 'remoteDispatchNodeGetFreePages' multiplies the 'npages'
argument with the 'cellcount' argument passed to 'virNodeGetFreePages',
both of which are declared as 'unsigned int' to both do an RPC limit
check against the 'REMOTE_NODE_MAX_CELLS' constant and then to allocate
the memory to hold the result from the actual hypervisor driver.

Since both the values are 'unsigned int' the product is also unsigned
int so big enough numbers can overflow, both passing the check and also
allocating not enough memory for the result. The hypervisor driver
assumes that the passed buffer is large enough and overwrites memory.

When this happens the the hypervisor daemon crashes.

This can be triggered e.g. by passing 1023 and 4198405 as values which
multiply to 1019 after wrapping to 32 bit unsigned value.

Use the VIR_INT_MULTIPLY_OVERFLOW macro in the check to avoid the issue
the same way as we do for other APIs doing multiplication of arguments
to determine amount of required memory.

Fixes: 34f2d0319d (v1.2.5-164-g34f2d0319d)
Closes: https://gitlab.com/libvirt/libvirt/-/work_items/903
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2026-08-12 17:21:54 +02:00
Peter Krempa a115450470 docs/securityprocess: Fix typo: removd->removed
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2026-08-12 17:13:45 +02:00
Peter Krempa 3a107ffe97 docs: securityprocess: Instruct security issue submitters to avoid archives
Archives (as witnessed by recent reports) hide useful information by
requiring the maintainer to download the archive which may be dangerous.

Recent submissions also contained a lot of fluff inside the archives.

Instruct submitters of security issues to attach files directly instead
of hiding them in an archive.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2026-08-11 17:13:43 +02:00
Peter Krempa 27905cbe57 docs: securityprocess: Convert plain 'Note' paragraph to rST admonition
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2026-08-11 17:13:43 +02:00
Peter Krempa ad91d912cd css: generic: Add support for '.. important::' RST admonition
Use the same heading color as we do for '.. warning::'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2026-08-11 17:13:43 +02:00
Peter Krempa e3da3cf552 tests: capabilityschemadata: Add a real test example
Data obtained by running:

 virsh -q capabilities > tests/capabilityschemadata/caps-qemu-real-full.xml

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-08-10 13:33:33 +02:00
Peter Krempa 5225c1cb68 conf: schemas: Allow '.' in schema for CPU flag name
Allow '.' so that CPU features such as:

 <feature name='sse4.1'/>

pass schema validation.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-08-10 13:33:33 +02:00
Peter Krempa 984d37aebf NEWS: Mention the 'preserve-running' action for '<on_crash>'
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2026-08-03 10:36:45 +02:00
Peter Krempa cdea89dd87 Add support for keeping VM running when panic notifier is used
Some guest OSes (e.g. windows) can do an internal crash dump and reboot
after a crash. They unfortunately notify the OS before doing the crash
dump though so we need a new possibility for the <on_crash> action to
keep the VM as is.

This patch introduces 'preserve-running' mode for on_crash and wires it
up into the qemu driver.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-07-27 13:38:37 +02:00
Peter Krempa ce97710da2 qemu: processGuestPanicEvent: Split individual steps under separate conditions
Separate the individual steps (setting of VM state, dumping, unlocking,
final state transition) under individual switch statements for future
extension.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-07-27 13:38:37 +02:00
Peter Krempa bf4ace1bca qemuProcessGuestPanicEventInfo: Fold into only caller
Move the code directly to the only place that calls this function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-07-27 13:38:37 +02:00
Peter Krempa 3f41645e3d qemuMonitorGuestPanicEventInfoFormatMsg: Directly return message
Remove the 'ret' variable and format the panic string on a single line.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-07-27 13:38:37 +02:00
Peter Krempa 997b9816dc conf: Use proper enum types for 'onReboot', 'onPoweroff', 'onCrash', and 'onLockFailure'
This ensures that 'switch' statements work correctly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-07-27 13:38:37 +02:00
Peter Krempa 0f18f6813c processGuestPanicEvent: Don't pass panic action via parameter
'processGuestPanicEvent' gets the full domain object; there's no point
passing it via 'struct qemuProcessEvent'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-07-27 13:38:37 +02:00
Peter Krempa 79b6d701c7 qemuDomainModifyLifecycleActionLive: Prepare to handle other actions
Rework the code so that it'll be possible to easily extend it to set
other lifecycle actions in qemu.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-07-27 13:38:37 +02:00
Peter Krempa 30a548c894 qemuProcessSetupLifecycleActions: Prepare to handle other actions
Rework the code so that it'll be possible to easily extend it to set
other lifecycle actions in qemu.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-07-27 13:38:37 +02:00
Peter Krempa 01cb769a18 qemu: capabilities: Retire QEMU_CAPS_SET_ACTION
The capability is no longer used because all qemu versions we support do
have the 'set-action' command.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-07-27 13:38:37 +02:00
Peter Krempa 94bd5174d2 qemu: Remove 'allowReboot' field
The value is no longer used. Remove it including the status XML
handling.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-07-27 13:38:37 +02:00
Peter Krempa 8365c6679f qemu: monitor: Remove support for 'watchdog-set-action'
We now use 'set-action' instead.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-07-27 13:38:37 +02:00
Peter Krempa 8effae01b9 qemu: Remove unused 'qemuProcessRebootAllowed'
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-07-27 13:38:37 +02:00
Peter Krempa 771f17c907 qemu: Always assume support for 'QEMU_CAPS_SET_ACTION'
The 'set-action' QMP command was introduced in qemu-6.0 and can't be
disabled in any way. Oldest qemu we support is qemu-7.2 so all versions
now have it.

Remove all conditional code which depends on the 'set-action' command.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-07-27 13:38:36 +02:00
Peter Krempa 2dc9670e4b libvirt-qemu: Add reference to QEMU agent protocol syntax
Add a reference to the expected format of commands used with
'virDomainQemuAgentCommand'.

Closes: https://gitlab.com/libvirt/libvirt/-/work_items/891
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-07-22 16:17:39 +02:00
Peter Krempa db06894f05 libvirt-qemu: Document that 'virDomainQemuAttach' no longer works
The qemu driver support was removed in libvirt 5.5.0 but the top level
documentation for the API didn't mention that yet.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-07-22 16:17:39 +02:00
Peter Krempa 54f5c2f949 libvirt-qemu: Add reference to QMP protocol documentation
Add link to the qemu QMP protocol reference.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-07-22 16:17:39 +02:00
Peter Krempa 3c49357d30 libvirt-domain: Use consistent flag names for APIs declaring use of 'virDomainDeviceModifyFlags'
APIs which declared that they use 'virDomainDeviceModifyFlags' enum as
flags used 'virDomainModificationImpact' flag names instead. Fix the
flag names so that it's consistent.

Closes: https://gitlab.com/libvirt/libvirt/-/work_items/897
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-07-22 16:17:39 +02:00
Peter Krempa 624f1391ef qemuxmlconftest: Add a note that the pinned CPU model tests test also old-style QMP monitor instantation
qemu-11.1 switched to the new syntax. Rather than adding a redundant
test case add a comment that we use the pinned cpu tests for the old QMP
monitor too.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2026-07-20 13:11:16 +02:00
Peter Krempa d071782577 qemu: command: Use monitor via '-object monitor-qmp,...'
Use the new 'monitor-qmp' object to instantiate the monitor instead of
the deprecated '-mon'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2026-07-20 13:11:16 +02:00
Peter Krempa 248981ff51 qemu: capabilities: Introduce QEMU_CAPS_OBJECT_MONITOR_QMP
Detect whether qemu supports monitor instantiated via '-object' instead
of the legacy '-mon'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2026-07-20 13:11:16 +02:00
Peter Krempa 13dddb5346 qemu: monitor: Standardize log format in QEMU_CHECK_MONITOR_FULL macro
Use '=' to delimit identifier and value. Since we're logging VM object
log also the name of the VM.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2026-07-20 13:11:16 +02:00
Peter Krempa 6c6716e0aa qemuMonitorJSONIOProcessLine: Log monitor object pointer in debug message
The debug message recording the string we've got to process didn't
specify which monitor object the reply comes from which makes it harder
to follow what's happening in cases when multiple VMs communicate (e.g.
when reconnecting at startup).

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2026-07-20 13:11:16 +02:00
Peter Krempa bfc42f6c0a qemucapabilitiestest: Update 'caps_11.1.0_aarch64' to 'v11.1.0-rc0'
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2026-07-20 13:11:16 +02:00
Peter Krempa 951b8ff4ca qemucapabilitiestest: Update 'caps_11.1.0_x86_64' to 'v11.1.0-rc0'
Notable changes:
 - 'wdat' machine added
 - 'mon-qmp' and 'mon-hmp' QOM objects added
 - 'virtio-rtc-pci' device added
 - 'virtio-shared-memory-mapping' QOM object added
 - 'intel-iommu' device stabilized options: 'fsts', 'pasid-bits', 'scalable-mode'
 - 'eraps' CPU feature became migratable
 - 'sp-mem' memory device added
 - 'ram-discard-manager' QOM object added
 - 'max_xattr' option added for 'virtfs' and 'fsdev' devices
 - changes in unstable commands regarding virtio backend data

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2026-07-20 13:11:16 +02:00
Peter Krempa 7e40be3ece NEWS: Mention systemd unit dependency fixes and virtio video device model selection
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2026-06-29 14:36:29 +02:00
Peter Krempa aa1bf13b9c qemu: Ensure proper shutdown ordering of virtlockd/virtlogd daemons
For socket activation to work our systemd unit files use the following
pattern:

  [virtlogd.socket]  <----(After)--- [virtlogd.service]
  [virtqemud.socket] <----(After)--- [virtqemud.service]

Now the qemu daemon also wants to use the services provided by those
daemons so we have dependency between the two too:

  [virtlogd.socket]  <----(After)--- [virtlogd.service]
         ^
         +-------------(After+Requires)-------+
                                              |
  [virtqemud.socket] <----(After)--- [virtqemud.service]

Now on startup everything is fine, because with socket activation, when
'virtqemud.service' wants to use 'virtlogd' services the socket is
already up due to the dependency+ordering and opening a connection will
cause 'virtlogd.service' to be socket-activated.

On shutdown though there's no transitive 'After' ordering between
'virtqemud.service' and 'virtlogd.service' and thus nothing explicitly
telling systemd that if virtlogd was started. In fact systemd is free to
translate it that 'virtlogd' and 'virtqemud' need to be stopped before
stopping 'virtlogd.socket'.

To illustrate what happens consider the following scenario:

A host is running a VM under virtqemud. 'virtqemud' is configured to
attempt shutdown on the VMs before killing them (daemon-based guest
shutdown, but the same reproduces also with libvirt-guests). The host
is being rebooted.

 (virtqemud attempts to shut down guests, but guest takes more than the
  configured shutdown inhibition timeout, journald output follows):

   06:44:02 fedora systemd-logind[664]: Delay lock is active (UID 0/root, PID 991/virtqemud) but inhibitor timeout is reached.
   06:44:02 fedora systemd-logind[664]: System is rebooting.
   [...]
   06:44:02 fedora virtlogd[802]: 802: debug : virSystemdNotify:667 : Notify 'STOPPING=1'
   06:44:02 fedora systemd[1]: Stopping virtlogd.service - libvirt logging daemon...
   06:44:02 fedora systemd[1]: Stopping virtqemud.service - libvirt QEMU daemon...
   06:44:02 fedora virtqemud[991]: 991: debug : virSystemdNotify:667 : Notify 'STOPPING=1'
   06:44:02 fedora systemd[1]: virtlogd.service: Deactivated successfully.
   06:44:02 fedora systemd[1]: Stopped virtlogd.service - libvirt logging daemon.

   (the shutdown times out, virtqemud kills the unresponsive vm)

   06:44:27 fedora virtqemud[991]: 1053: debug : qemuProcessStop:8916 : Shutting down vm=0x7f71ac032670 name=virt-vm1 id=1 pid=805, reason=destroyed, asyncJob=none, flags=0x0
   06:44:27 fedora virtqemud[991]: 1053: debug : qemuDomainLogAppendMessage:5757 : Append log message (vm='virt-vm1' message='2026-06-15 10:44:27.427+0000: shutting down, reason=destroyed
                                       ) stdioLogD=1
   06:44:27 fedora virtqemud[991]: 1053: error : virNetSocketReadWire:1767 : Cannot recv data: Connection reset by peer
   06:44:27 fedora virtqemud[991]: 1053: debug : qemuProcessKill:8811 : vm=0x7f71ac032670 name=virt-vm1 pid=805 flags=0x5

Now the log shows that we want to add VM log file message in
'qemuDomainLogAppendMessage' but it fails because virtlogd is dead
already.

Now the same happens also with 'virtlockd' but with much worse outcome,
especially if the configured action is to save the VMs because shutdown
of 'virtlockd' when locks are held ends up 'fencing' the VMs by killing
them.

The same also happens when libvirt-guests is used to shutdown the guests
instead.

This patch adds an explicit 'After=virtlo[ck|g]d.service' to the daemons
containing the qemu driver to ensure that the shutdown ordering makes
sense. This doesn't break socket activation (e.g. the log/lock daemons
are not started unless first invoked).

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2026-06-24 08:34:59 +02:00
Peter Krempa 4bcaba8347 virQEMUCapsLogProbeFailure: Reraise error with more information
While we don't normally try to re-wrap errors to be more descriptive,
probing of qemu capabilities is a special case as the errors can be
cryptic and don't give users enough information about what's going on.
An example is (obtained from a patched qemu which accidentally returned
a broken QMP schema):

  $ virsh start VM
  error: Failed to start domain 'VM'
  error: internal error: Duplicate hash table key 'str'

The error is unusable. On the other hand in 'virQEMUCapsLogProbeFailure'
we do special logging of the caps probing failure with a custom UUID so
that it can be easily found in the logs which reports a much better
error message. Re-raise the same as a normal error too so that the user
gets similar experience:

  $ virsh start VM
  error: Failed to start domain 'VM'
  error: internal error: Failed to probe capabilities for /home/user/git/qemu.git/build/qemu-system-x86_64: internal error: Duplicate hash table key 'str'

This does mean though that the error is logged twice, once via the
custom log entry and second via 'virReportError'. Given that this error
is extremely unlikely, having two log entries IMO doesn't warant
reworking the whole error reporting infra to allow passing extra
metadata just for this one case.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-06-24 08:34:02 +02:00
Peter Krempa 5c351c8965 qemuProcessQMPStop: Preserve error when killing qemu used for capability probing
When probing of capabilities fails 'qemuProcessQMPStop' kills the qemu
process, but also resets the error. The virResetLastError() was
originally intended to reset the error from 'virProcessKillPainfully',
it also resets any probing error resulting in the following:

  $ virsh start VM
  error: Failed to start domain 'VM'
  error: An error occurred, but the cause is unknown

Keep the error clearing as this might be called on success but preserve
the original error around it.

Fixes: db7b0b12b7
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-06-24 08:34:02 +02:00
Peter Krempa a956193164 qemu: Remove 'qemuDomainSupportsVideoVga'
The function is unused remove it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-18 11:03:36 +02:00
Peter Krempa 736c0f455a qemuDeviceVideoGetModel: Simplify by relying on checks from 'qemuValidateDomainDeviceDefVideo'
'qemuValidateDomainDeviceDefVideo' ensures that only the correct video
device models are selected as well as that only QXL and VIRTIO video
devices can be selected as secondary.

Remove unnecessary checks and simplify the code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-18 11:03:36 +02:00
Peter Krempa 659e104aff qemuDeviceVideoGetModel: Remove logic for selecting 'virtio' devices
The virtio video device frontend type is either selected by the
post-parse code based on capabilities or provided by the user/existing
XML explicitly. No need to try to come up with a model when generating
commandline based on broken logic.

The difference in test output shows:
 - honours user's config in case of the new 'device' attribute
 - shows how incorrect fallback would be used for 'virtio-vga-gl'
   (picked virtio-vga (non-gl) instead of 'virtio-gpu-gl')

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-18 11:03:36 +02:00
Peter Krempa 177ff81347 qemuValidateDomainDeviceDefVideo: Fix checks of virtio video devices
The currently existing checks are broken:
 - only QEMU_CAPS_DEVICE_VHOST_USER_GPU is checked for vhostuser
   backends (vhost-user-vga is actually separately packaged)
 - the check for the 3d accelerated (-gl) versions checks only if one
   of them exists (the commandline formatter picks a non-gl afterwards)
 - 'virtio-vga'/'virtio-gpu' is not checked at all

The code also doesn't yet check if, when the user passes the new
'device' property manually the config actually makes sense.

To fix all of the above introduce a table of supported frontend devices
as well as properties that need to be checked for them.

This requires fixing a recently-introduced test case which shows a
nonsensical situation.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-18 11:03:36 +02:00
Peter Krempa 38c970f641 qemu: postparse: Fill in selected virtio video frondend device in the XML
Historically 'virtio-vga' was always picked as the first '<video>'
(virtio) device and any sub-sequent ones were 'virtio-gpu'. When support
for aarch64 VMs was being added an exception to use 'virtio-gpu' for the
primary device was added as aarch64 doesn't have anything resembling the
"legacy" 'VGA' interface. At this point this exception was only for
aarch64. The distinction between 'virtio-vga' and 'virtio-gpu' was *not*
recorded in the VM XML as it was a new feature (for aarch64) and it
didn't make sense to pick 'virtio-vga'.

Some time later the following commit:

  commit 4c029e8cfa
  Author: Pavel Hrdina <phrdina@redhat.com>
  Date:   Fri Sep 30 14:41:37 2016 +0200

      qemu_command: properly detect which model to use for video device

      This improves commit 706b5b6277 in a way that we check qemu capabilities
      instead of what architecture we are running on to detect whether we can
      use *virtio-vga* model or not.  This is not a case only for arm/aarch64.

modified the code to do this picking by checking presence of
'virtio-vga' device instead. That approach didn't consider the fact that
the modular deployment of qemu allows for the 'virtio-vga' device to be
missing in certain cases, thus introducing a latent bug as we'll pick
'virtio-gpu' in such case but don't record it anywhere.

Now this creates a problem, if the deployments differ, because you can
have two *incompatible* (at migration stream level) setups which are
based on the same identical XML without the possibility for the
destination libvirt instance during migration to pick which is the
correct one.

To prevent this and actually fix any existing such deployment (which
allows upgrade of libvirt daemons on the source) we will record the
picked device frontend at post-parse time into the XML. This luckily
properly handles running VMs even if 'virtio-vga' were already
installed since we record the actual qemuCaps we've started the VM with.

Now 'virtio-vga' vs 'virtio-gpu' is not the only broken piece of logic.
In fact 'virtio-vga-gl' could have been downgraded to 'virtio-vga' based
on some very weird logic (see comments in code for explanation).

The logic in 'qemuDomainDeviceVideoDefPostParse' re-creates the logic
used to setup virtio-vga vs. virtio-gpu, and 'vhost-user-vga' vs.
'vhost-user-gpu' as those still make sense. For the 'gl' variants two
versions exist, one meant to recover running VMs and one for new VMs
where the broken logic makes no sense.

Now this patch just records what was selected into the XML, but doesn't
yet modify the commandline to actually use that value verbatim (e.g. if
the user specified an actual non-default value already).

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-18 11:03:36 +02:00
Peter Krempa d3bd214209 qemuDeviceVideoGetModel: Directly return picked model
There's no point in falling through to the check reporting invalid
type since if the code picks a model that one will be valid.

Reorganize the code so that we can return final decision right away.
This means that the two flags 'virtio' and 'virtioBusSuffix' need to be
set prior to the return.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-18 11:03:36 +02:00
Peter Krempa ca4bcd775c qemuxmlconftest: Add test case for specifying 'virtio-gpu' where 'virtio-vga' would be picked
Add a test case demonstrating the switch to 'virtio-gpu' on a host which
would normally pick 'virtio-vga'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-18 11:03:36 +02:00
Peter Krempa b6f7c2d3db conf: Add fields for recording actually-selected virtio video device
QEMU's commandline generator picks for virtio video between various
actual device models not only based on the XML definition but also
capabilities present. Since none of the devices is actually ABI
compatible we need to record the actually selected device in the XML.

Introduce 'device' attribute:

      <video>
        <model type='virtio' heads='1' primary='yes' device='virtio-gpu'/>

which will record the actually selected model so that we can preserve
ABI across restarts on deployment changes but more importantly across
migrations where the deployment differs.

The code specifically avoids an ABI stability check for the new field
because there are already possibly broken configurations that the users
may want to fix by picking the proper model which could be forbidden.

Users are instructed to not set the field in the XML.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-18 11:03:36 +02:00
Peter Krempa b64f4bab65 virDomainVideoDefFormat: Use 'virXMLFormatElement' instead of custom formatter
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-18 11:03:36 +02:00
Peter Krempa 7d4b510bc7 qemustatusxml2xml: Add test case capturing virtio video device
Add example of two running configs with distinct recorded capabilities
(presence of QEMU_CAPS_DEVICE_VIRTIO_VGA at startup) which will
demonstrate the recording of the picked actual device type on the
commandline.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-18 11:03:36 +02:00
Peter Krempa c10a7f2baf qemuxmlconftest: Add invocation of 'video-virtio-vga-gpu-gl' with missing caps and VIR_DOMAIN_DEF_PARSE_ABI_UPDATE
Similarly to previous patch add testing of 'virtio-gpu-gl' or
'virtio-vga-gl' with missing the respective capabilities, but this time
allowing VIR_DOMAIN_DEF_PARSE_ABI_UPDATE.

This will later on show that in case when the fallback can't be honoured
the code will not pick a device that doesn't support acceleration (the
non-gl variant).

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-18 11:03:36 +02:00
Peter Krempa a30a5a89e7 qemuxmlconftest: Add test cases for configs asking for 'virtio-gpu-gl' or 'virtio-vga-gl' without the capability
The capability check in 'qemuValidateDomainDeviceDefVideo' which
validates whether a <video> definition with acceleration enabled is
possible is only aggregate, thus validates that any '-gl' video backend
is available.

Since qemu compiles each backend into a separate module it's possible to
have an installation where 'virtio-gpu-pci-gl' exist but 'virtio-vga-gl'
doesn't and it will not be rejected at validation. The commandline
though will generate a device *without* the '-gl' which is ABI
incompatible with the counterpart which does have '-gl', but the VM
starts. If such a VM is then migrated to a deployment which does have
the '-gl' variant available, migration will fail because qemu will
generate the '-gl' device as we don't record this fact in the XML.

This test case captures this situation which will be fixed later.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-18 11:03:36 +02:00
Peter Krempa 84b05fe4e3 qemuxmlconftest: Add 'video-virtio-vga' invocation with QEMU_CAPS_DEVICE_VIRTIO_VGA disabled
The test case shows that if the 'QEMU_CAPS_DEVICE_VIRTIO_VGA' capability
is not present (e.g. if the corresponding qemu module isn't installed)
libvirt will pick:

  -device '{"driver":"virtio-gpu-pci", ...

instead of:

  -device '{"driver":"virtio-vga", ...

but without any discernable difference in the XML.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-18 11:03:36 +02:00
Peter Krempa c490360c25 qemuxmlconfdata: un-symlink 'video-virtio-vga-gpu-gl' output
Upcoming patches will add additional testing for various virtio-*-gl
devices, including filling of the default model. The output file needs
to not influnece the input for this test to work properly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-18 11:03:36 +02:00
Peter Krempa 9e43cf3e58 virQEMUCapsCacheLookupDefault: Fix error message when no emulators are installed
When querying capabilities for the default emulator with no other
arguments (e.g. 'virsh domcapabilities) fix error whithout emulator
installed an error is reported but the error would mention '(null)'
architecture:

  # virsh domcapabilities
  error: failed to get emulator capabilities
  error: unsupported configuration: unable to find any emulator to serve '(null)' architecture

This happens as the error formatting takes 'archStr' which is NULL for
the default architecture instead of using 'arch' which is populated by
the host's architecture and converting it back.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-18 11:03:36 +02:00
Peter Krempa 011ae74640 qemu: postparse: Process VM config with qemuCaps influenced by <qemu:capabilities>
The user configuration of added/removed qemu capabilities via the qemu
namespace element was applied only right before generating a
commandline, but the post parse code code didn't see these.

Apply the capability modification prior to running post parse code so
that defaults are properly picked based on the configuration.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-18 11:03:36 +02:00
Peter Krempa 5319dd6f0d qemu: validate: Validate VM config with qemuCaps influenced by <qemu:capabilities>
The user configuration of added/removed qemu capabilities via the qemu
namespace element was applied only right before generating a
commandline, but the validation code didn't see these.

Modify the validation entry points so that they apply this optionally.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-18 11:03:35 +02:00
Peter Krempa 9ec26e2c4f qemu: Allow reuse of 'qemuProcessStartUpdateCustomCaps'
Move and rename the function to 'qemuDomainUpdateCustomCapabilities' and
modify the arguments so that it will be possible to reuse it also in the
post-parse and validation code which ought to base decisions on the same
logic as VM startup would.

Since copying of the qemu capabilities object is very expensive (I've
observed an almost 4x slowdown of qemuxmlconftest)
'qemuDomainUpdateCustomCapabilities' copies the capabilities only when
necessary.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-18 11:03:35 +02:00
Peter Krempa 1bbefb6409 qemu: capabilities: Export 'virQEMUCapsNewCopy' outside of 'qemu_capspriv'
Upcoming patch will add a function which will need to optionally copy
passed capabilities for modification. Export 'virQEMUCapsNewCopy'
outside of tests.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-18 11:03:35 +02:00
Peter Krempa b8dfb9551e qemu: capabilities: Apply 'capability_filters' configration option on all capabilities
The 'capability_filters' allows admins to globally disable some qemu
capabilities via the config file.

Until now it was applied only directly when starting the VM, but that is
too late as the capability is still present when e.g. the post-parse
code is picking defaults.

Rework the code so that 'capability_filters' is applied directly after
probing qemu so all existing capabilities will lack the filtered out
ones.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-18 11:03:35 +02:00
Peter Krempa 1721249ff6 qemuxmlconftest: Fail if test case tried to pass STDIO or invalid fds to 'virCommandPassFD'
Trying to pass STDIO fds to a virCommand is very bad and test cases must
not do that.

Same way with invalid FDs.

Add code which makes qemuxmlconftest fail if any test case would attempt
that.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-10 11:23:52 +02:00
Peter Krempa 77b6c501d4 virTestDummyFDContext: Add fields to track errors and 'virTestDummyFDContextMarkError'
Add 'errors' field for tracking a list of errors and
'virTestDummyFDContextMarkError' function to add to the list.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-10 11:23:52 +02:00
Peter Krempa b23765a58f testutils: Turn 'virTestDummyFDContext' into a proper type
'virTestDummyFDContext' was a copy of GHashTable to be able to register
a cleanup function. Upcoming patches will want to track more data
together with the hash table so turn virTestDummyFDContext into a proper
struct which contains the hash table.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-10 11:23:52 +02:00
Peter Krempa 856077138a Avoid use of glib's G_REGEX_OPTIMIZE flag
glib's G_REGEX_OPTIMIZE invokes pcre's JIT optimizer which requires
writable executable memory. On hosts with SELinux this by default caused
AVC denials to be logged. The solution in Fedora's SELinux policy was
to allow execmem for e.g. virtqemud, but e.g. virtlogd or
libvirt_leaseshelper on the other hand got a 'dontaudit' rule.

Now the optimizer itself does have a substantial effect; I've measured
around 3x speedup when matching VIR_LOG_REGEX against a sample of a qemu
VM log file. On the other hand, only 3 out of 10 uses of 'g_regex_new'
used the flag and also none of the regexes which used 'G_REGEX_OPTIMIZE'
are on a hot path:

 - virDomainQemuMonitorEventStateRegisterID

    Used only when custom qemu monitor event callback is registered,
    which resides in libvirt_qemu.so so noone will actually use this
    in production.

 - virCommandRunRegex

   Used in:
    - virStorageBackendFileSystemNetFindNFSPoolSources

      Invoked only via API on output of 'showmount'. Unlikely to ever
      see lots of data.

    - virStorageBackendLogicalFindLVs
    - virStorageBackendLogicalGetPoolSources
    - virStorageBackendLogicalRefreshPool

      Invoked on output of lvs/pvs/vgs. Neither of them are likely to
      ever see lots of output to match.

    - virISCSIGetSession
    - virISCSIScanTargetsInternal

      Invoked on output of iscsiadm, unlikely to see lots of data.

 - virLogProbablyLogMessage
    - virLXCProcessIgnorableLogLine
    - domainLogContextReadFiltered

      Both of the above are used on code paths processing log output
      when failure to startup a VM process or one of the helper
      processes for devices for a qemu domain. Thus they are not invoked
      on success and the processed buffer is capped to 1k of data.

Since none of the above are on anything resembling a hot path and thus
likely to substantially benefit from the optimizer, and we do have
plenty of other uses without optimization, drop the optimizations
everywhere and add a note to sc_G_REGEX_OPTIMIZE that we're currently
avoiding the use of this flag.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-06-10 11:22:32 +02:00
Peter Krempa c081898565 syntax-check: Add warning about implications of G_REGEX_OPTIMIZE
glib's G_REGEX_OPTIMIZE flag for regex operations implies the use of
pcre's JIT optimizer for regexes which requires writable executable
memory for the optimized code.

Security frameworks such as SELinux can restrict program's access to
writable executable memory to harden the code.

glib's implementation of the regex functions handles downgrade to
interpreted evaluation of regexes gracefully if writable executable
memory is unavailable, but that is non-obvious and has a performance
penalty.

Add a syntax check which requires all uses of G_REGEX_OPTIMIZE to be
annotated so that the reader of the code can be hinted to why
G_REGEX_OPTIMIZE should perhaps be avoided.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-06-10 11:22:32 +02:00
Peter Krempa db7b3de701 qemucapabilitiestest: Add data for the qemu-11.1 dev cycle (aarch64)
The dump is based on QEMU commit 'v11.0.0-1600-g5611a9268d'

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-03 15:21:44 +02:00
Peter Krempa ace61064f0 qemucapabilitiestest: Add data for the qemu-11.1 dev cycle (x86_64)
The dump is based on QEMU commit 'v11.0.0-1600-g5611a9268d'

Notable changes:

 - machine types for the 11.1.0 release added
 - (auto) deprecated 8.1 machine type
 - 'poll-weight' property added for 'iothread' object
 - 'clipboard' property added for 'gtk' display backend
 - 'vhost-user-rtc' device added
 - new CPU models/versions
    - Cascadelake-Server-v6-x86_64-cpu
    - Cascadelake-Server-v7-x86_64-cpu
    - ClearwaterForest-v4-x86_64-cpu
    - DiamondRapids-v2-x86_64-cpu
    - EPYC-Genoa-v3-x86_64-cpu
    - EPYC-Milan-v4-x86_64-cpu
    - EPYC-Turin-v2-x86_64-cpu
    - GraniteRapids-v6-x86_64-cpu
    - GraniteRapids-v7-x86_64-cpu
    - Icelake-Server-v8-x86_64-cpu
    - Icelake-Server-v9-x86_64-cpu
    - SapphireRapids-v7-x86_64-cpu
    - SapphireRapids-v8-x86_64-cpu
    - SierraForest-v6-x86_64-cpu
    - Skylake-Server-v6-x86_64-cpu
 - 'query-kvm' command is now deprecated
 - removed 'gluster' blockdev backend
 - 'blkdebug' blockdev backend allows injecting delays
 - chardev backends support 'encoding' property
 - 'remaining' amount reported in 'query-migrate'
 - 'target-info-x86_64' QOM type added
 - 'x-rdma-chunk-size' migration parameter added

The few changed '.args' files update the machine type to the actual
version because they were frozen before we've added a newer capability
dump (latest machine type is masked to stabilize test outputs).

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-03 15:21:44 +02:00
Peter Krempa fc834144aa qemublocktest: Skip schema validation on 'gluster' backend tests
qemu-11.1 will drop support for the 'gluster' block backend driver. We
want to keep the tests around to validate that nothing in the
parser/generator has changed but there's no point in wiring up QMP
schema validation against older versions.

Skip the schema validation for gluster qemublocktests.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-03 15:21:44 +02:00
Peter Krempa 81bb33e329 ci: Regenerate with 'lcitool'
Drop the job definitions now that Cirrus CI was removed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-02 14:59:26 +02:00
Peter Krempa a1eb9698fc ci: Drop 'Cirrus CI' job defnitions
Cirrus CI no longer exists. Drop the current jobs using it from the
definitions.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-02 14:59:26 +02:00
Peter Krempa e9b5c84042 ci: README: Delete section about 'Cirrus CI'
The service no longer exists.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-06-02 14:59:26 +02:00
Peter Krempa 06a4f5721f qemuxmlconftest: Use real FD for iommufd object in tests
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:59 +02:00
Peter Krempa 8afb7fe0e7 qemuxmlconftest: Use real FDs for hostdev tests
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:59 +02:00
Peter Krempa eaecd2ca07 qemuxml2argvmock: Use real FDs for interface tests
Similarly to previous commits use real FDs so that we don't risk
collisions.

Note that for the test cases passing multiple tap and vhost FDs the
helpers which stabilize the output don't actually work, as the FDs are
concatenated. For now we'll not deal with this and simply leave them
censored by the 'XXXXXXX' string.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:59 +02:00
Peter Krempa a854a3cb84 qemuxmlconftest: Use real FDS for testing of 'vsock'
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:58 +02:00
Peter Krempa 1b13c5c791 testutilsqemu: Remove unused 'ARG_VDPA_FD' test argument
The code was refactored to allow any FD numbers so the code to map them
to specific numbers is no longer needed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:58 +02:00
Peter Krempa f7f2bf2aa0 qemuxmlconftest: Use virTestMakeDummyFD() to get VDPA disk fds
While VDPA disks did use real FDs they used convoluted infrastructure
for mapping them to specific numbers. Remove that since we can now mask
them from the output args instead.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:58 +02:00
Peter Krempa b28c8cbbb8 qemuxmlconftest: (consistently) use real FDs in tests for VDPA netdevs
Use virTestMakeDummyFD() to get a real FD for the test in
qemuxmlconftest.

Use virTestMakeDummyFD() also in qemuhotplugmock.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:58 +02:00
Peter Krempa 45d2ce9012 qemuxml2argvmock: qemuBuildTPMOpenBackendFDs: Use real FDs
Use 'virTestMakeDummyFD()' to create real FDs both for 'tpmfd' and
'cancelfd'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:58 +02:00
Peter Krempa 28ad58833e qemuxmlconftest: Setup real FDs for 'vhost-user-vga'
Initialize the chardev backends for vhost-user graphics to use real FDs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:58 +02:00
Peter Krempa 963febb511 testQemuPrepareHostBackendChardevOne: Use real FDs for all cases
Use the virTestMakeDummyFD() function to setup real FDs for all chardev
backends which are set up via testQemuPrepareHostBackendChardevOne.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:58 +02:00
Peter Krempa ddfd6db943 virDomainFDTuple: drop 'testfds' field
Thanks to real FD testing we no longer need to inject test
infrastructure into production code. Remove it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:58 +02:00
Peter Krempa 3d2d363f88 testQemuInfoSetArgs: Use real FDs with 'ARG_FD_GROUP'
Switch over to 'virTestMakeDummyFD' which allows to use real FDs in the
test and also allows to track them in the output files in a stable way.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:58 +02:00
Peter Krempa 9eb761df3f testutilsqemu: Use real FD for monitor FDs instantiated by 'testQemuPrepareHostBackendChardevOne'
Switch to 'virTestMakeDummyFD' which uses a real FD. No otuputs are
changed thanks to the code which censors 'fd' field of --add-fd.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:58 +02:00
Peter Krempa cc330bf3f9 qemuxmlconftest: Stabilize 'vfio-pci' hostdev fds
Prepare to use real FDs in tests.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:58 +02:00
Peter Krempa e1b602e8ac qemuxmlconftest: Stabilize fds in '-netdev'
Use 'testCompareXMLToArgvStabilizeOne' to provide stable test outputs
even when we'll switch to real FDs in tests.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:58 +02:00
Peter Krempa 714285084a qemuxmlconftest: Stabilize 'vsock' 'vhostfd' file descriptior in output files
Install hanlder to stabilize 'vhostfd' fds in -device so that we can
later switch tests to use real FDs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:58 +02:00
Peter Krempa c8331668af qemuxmlconftest: Stabilize FDs in iommufd objects
Install the handler to stabilize output files on '-object' with
'iommufd' qom type which references a FD directly via the 'fd' property.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:58 +02:00
Peter Krempa c2ea8b2e7c qemumonitorjsontest: Stabilize FD names in '-chardev'
Use 'testCompareXMLToArgvStabilizeOne' to censor FD values in '-chardev'
commands for stable test outputs without the need for fake FDs.

For monitor sockets this also creates a hint '@mon-fd@' to be used as
substitution to prevent any further churn on basically every .args file.
The substitution is done by temporarily using another fake FD (1764)
instead of 1729 so that it's unique.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:58 +02:00
Peter Krempa 6cf78a55f9 qemuxmlconftest: Stablilize '-add-fd' arguments
Add code which walks the generated argument list and allows to strip out
and replace by a substitution any field in either JSON or legacy qemu
argument string.

Use it to stabilize 'fd' field of '-add-fd'

This will allow us to rip out code which tries to allocate stable FD
numbers, which doesn't work reliably (e.g. if the environment passes
some FDs).

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:57 +02:00
Peter Krempa a72bbfc4ba qemuxmlconftest: Move mock'd FDs further out
Upcoming patches will introduce use of real FDs for tests. Since the
test will go through many FDs they will collide with the fake ones
allocated randomly in qemuxml2argvmock.

Move them out for now until they are replaced and masked out from the
tests.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:57 +02:00
Peter Krempa 6984ed1b4e testutils: Introduce virTestMakeDummyFD
The helper makes a dummy (file) FD to be used as FD in tests which want
to handle a FD but don't really use it. It also optionally records the
FD number along with a hint in a hash table which can be later
used to fetch the hint and stabilize test outputs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:57 +02:00
Peter Krempa 5f2c2d35c0 util: json: Introduce 'virJSONValueObjectReplaceKey'
Add a helper which replaces the value part of a JSON object key. This
will be helpful in tests where we'll want to rewrite some outputs (e.g.
fds) to stabilize output files.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:57 +02:00
Peter Krempa 1d95df0c57 util: command: Remove virCommandGetArgList
The function is now unused, remove it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:57 +02:00
Peter Krempa 1919326263 qemuxmlconftest: Use virCommandArgListAccess in testCompareXMLToArgvValidateSchema
Access the args directly rather than fetching a copy since we have a new
helper now.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:57 +02:00
Peter Krempa da7a3f4d37 util: vircommand: Add direct accessor for 'args' array for tests
Introduce virCommandArgListAccess which returns 'args' and 'nargs'

Upcoming patches will add code which censores/stabilizes FD numbers in
test outputs. This will be done by rewriting the argument of the command
before comparing it with test output. Add a test-only function to
directly access 'args' and 'nargs' of a virCommand to do this
modification.

This accessor will also be used instead of 'virCommandGetArgList' in
'testCompareXMLToArgvValidateSchema' to avoid needles copy of all
arguments.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:57 +02:00
Peter Krempa a3bedabcc4 qemuxml2argvmock: Fix behaviour of 'virCommandPass' mock
The 'virCommandPass' mock in 'qemuxml2argvmock.so' skipped passing most
FDs to the real implementation of 'virCommandPass', except for few fake
FDs that were hardcoded.

This meant that if a test case had an valid FD that it used for testing
that FD would be leaked. At the same time fake fds 1730, 1731, 1732
would be actually passed to the virCommand itself although the FD was
invalid.

Since neither of the above makes sense fix the implementation the
following way:

 - refuse to pass any STDIO fds
     They are real and they would break test program output. Some tests
     do try to use them errorneously; they will be addressed later.

 - pass real FDs to virCommand
    Real FDs can be properly handled by virCommand. Especially they will
    be closed once the virCommand object is disposed of.

 - don't pass fake FDs
    They create extra noise e.g. in valgrind. Skip those as it makes no
    sense to handle those.

This patch addresses most failures that valgrind reports with
--track-fds=all.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:57 +02:00
Peter Krempa f705379443 qemuFDPassLogFDInfo: Check if FD is valid before 'fstat'-ing it
Some test cases (qemuxmlconftest) currently use made up descriptors,
which cause e.g. valgrind to be unhappy:

 ==831186== File descriptor 1729 Invalid file descriptor
 ==831186==    at 0x531042E: fgetxattr (in /usr/lib64/libc.so.6)
 ==831186==    by 0x5AE2846: ??? (in /usr/lib64/libselinux.so.1)
 ==831186==    by 0x5AE7093: fgetfilecon_raw (in /usr/lib64/libselinux.so.1)
 ==831186==    by 0x4EB736F: qemuFDPassLogFDInfo (qemu_fd.c:92)
 ==831186==    by 0x4EB7B8E: qemuFDPassDirectTransferCommand (qemu_fd.c:443)

when tracking FDs. Since 'qemuFDPassLogFDInfo' just logs information
about the FD we can simply not query the FD if it's made up.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:57 +02:00
Peter Krempa a6d491909a util: command: Extract common parts of FD closing to virCommandMassClose
Extract the lookup of used FDs and their setup to virCommandMassClose
rather than duplicate it in the two functions we have for using
different modes of FD closing.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2026-05-25 13:28:57 +02:00