1
0

36524 Commits

Author SHA1 Message Date
Praveen K Paladugu
695a4f38b5 util: Introduce virStringFormatHex
virStringFormatHex converts an input byte array into hex string and
returns it.

Signed-off-by: Praveen K Paladugu <praveenkpaladugu@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2025-03-10 14:39:59 +01:00
Michal Privoznik
9d1e4b25ba security: Set seclabels on UEFI shim
Again, trivial. Just copy what is done for kernel and initrd.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2025-03-10 13:54:59 +01:00
Michal Privoznik
39c1784ca0 qemu_command: Generate cmd line for UEFI shim
Trivial.

Resolves: https://issues.redhat.com/browse/RHEL-68043
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2025-03-10 13:54:42 +01:00
Michal Privoznik
b136e492c5 qemu_validate: Check whether UEFI shim is supported
If UEFI shim is specified in domain XML but QEMU is too old, then
report an error.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2025-03-10 13:53:06 +01:00
Michal Privoznik
30be3b0d9d qemu_capabilities: Introduce QEMU_CAPS_MACHINE_SHIM
In its commit v9.2.0-323-ga5bd044b15 QEMU introduced another
command line option: -shim. It's used to load kernel. Track
presence of it via QEMU_CAPS_MACHINE_SHIM.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2025-03-10 13:51:42 +01:00
Michal Privoznik
6b63334233 conf: Introduce os/shim element
For secure boot environments where <loader/> is signed, it may be
unfeasible to keep the binary up to date (esp. when revoking
certificates contained within). To address that, QEMU introduced
'-shim' cmd line option which side loads another UEFI binary
which can then contain new certification authorities or list of
revocations. Expose it as <shim/> element that's nested under
<os/>, just like kernel and initrd are.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2025-03-10 13:32:46 +01:00
Peter Krempa
5cc3803d1d qemu: block: Drop 'sheepdog' protocol support
As now no supported qemu version supports the 'sheepdog' protocol drop
the code for configuring the blockdev layer.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2025-03-10 13:09:29 +01:00
Peter Krempa
8824af826d qemu: capabilities: Bump minimum qemu to qemu-6.2
Following minimum versions are needed based on our support policy:

             CentOS Stream 9: 9.1
                   Debian 12: 7.2
                   Fedora 40: 8.2
          openSUSE Leap 15.6: 8.2
                Ubuntu 22.04: 6.2
               FreeBSD ports: 9.2
              macOS homebrew: 9.2
              macOS macports: 9.2

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2025-03-10 13:09:29 +01:00
Peter Krempa
f976d1b06c conf: Drop support for 'sheepdog' disks
In upcoming patches we'll update minimum supported qemu version to
qemu-6.2 which no longer supports 'sheepdog'. This was the only
hypervisor driver that supported it.

Reject any config containing sheepdog disks when validating the XML,
remove the positive test cases in qemu and replace them by a negative
test case. This will still excercise the XML schema, but will prepare
for removal of the internal code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2025-03-10 13:09:27 +01:00
Alexander Kuznetsov
d23a516eba util: netdevvlan: Change return type of virNetDevVlanCopy to void
This function return value is invariant since 1022e0ee, so change
its type and remove all dependent checks.

Found by Linux Verification Center (linuxtesting.org) with Svace.

Reported-by: Alexander Rudyuk <a.rudyuk@fobos-nt.ru>
Signed-off-by: Alexander Kuznetsov <kuznetsovam@altlinux.org>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2025-03-07 14:48:01 +01:00
Pavel Hrdina
c4b7d29610 util: virxml: unexport virXMLFormatElementInternal
It is no longer used anywhere else.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-03-07 14:18:46 +01:00
Pavel Hrdina
e042ff6dd0 domain_conf: refactor virDomainLoaderDefFormatNvram
Use the new virXMLFormatDirect in order to remove usage of
virXMLFormatInternal.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-03-07 14:18:44 +01:00
Pavel Hrdina
aedfdaa3f6 conf: use virXMLFormatElementDirect
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-03-07 14:18:41 +01:00
Pavel Hrdina
4cc562651f util: virxml: introduce virXMLFormatElementDirect
This can be used to format XML where the element has direct value
instead of any subelement. For example:

    <maxMemory slots='16' unit='KiB'>1524288</maxMemory>

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-03-07 14:18:38 +01:00
Pavel Hrdina
798d87539d domain_conf: graphics: properly escape user provided strings when formatting XML
This was reported on virt-manager issue tracker as it was possible to
provide `listen` attribute with properly escaped characters but libvirt
would format XML without escaping it.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-03-07 14:01:27 +01:00
Pavel Hrdina
6786ae80a3 domain_conf: graphics: fix error messages when formatting XML
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-03-07 14:01:27 +01:00
Pavel Hrdina
1ef5926a80 domain_conf: graphics: move remaining VNC formatting
Now we are able to move the rest into virDomainGraphicsDefFormatVNC
without breaking order of elements in the resulting XML.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-03-07 14:01:27 +01:00
Pavel Hrdina
15599d3481 domain_conf: graphics: move remaining spice formatting
Now we are able to move the rest into virDomainGraphicsDefFormatSpice
without breaking order of elements in the resulting XML.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-03-07 14:01:27 +01:00
Pavel Hrdina
08925c0bea domain_conf: graphics: move listens formatting to relevant graphics types
Only VNC, RDP and Spice graphics types are using listen elements so call
the function only where it is needed.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-03-07 14:01:27 +01:00
Pavel Hrdina
5f97b846f0 domain_conf: graphics: extract listen formatting to separate function
This will be used in specific graphics types that are using listen
elements.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-03-07 14:01:27 +01:00
Pavel Hrdina
4c2c7720fe domain_conf: graphics: extract DBus formatting to separate function
virDomainGraphicsDefFormat function was way too long so split it into
separate functions for each graphics type.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-03-07 14:01:27 +01:00
Pavel Hrdina
e95d362ba7 domain_conf: graphics: extract EGL-Headless formatting to separate function
virDomainGraphicsDefFormat function was way too long so split it into
separate functions for each graphics type.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-03-07 14:01:27 +01:00
Pavel Hrdina
287c1a761e domain_conf: graphics: extract Spice formatting to separate function
virDomainGraphicsDefFormat function was way too long so split it into
separate functions for each graphics type.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-03-07 14:01:27 +01:00
Pavel Hrdina
a93ea4cd84 domain_conf: graphics: extract Desktop formatting to separate function
virDomainGraphicsDefFormat function was way too long so split it into
separate functions for each graphics type.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-03-07 14:01:27 +01:00
Pavel Hrdina
c2dcb47413 domain_conf: graphics: extract RDP formatting to separate function
virDomainGraphicsDefFormat function was way too long so split it into
separate functions for each graphics type.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-03-07 14:01:27 +01:00
Pavel Hrdina
7a05d981eb domain_conf: graphics: extract SDL formatting to separate function
virDomainGraphicsDefFormat function was way too long so split it into
separate functions for each graphics type.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-03-07 14:01:27 +01:00
Pavel Hrdina
9774254ce3 domain_conf: graphics: extract VNC formatting to separate function
virDomainGraphicsDefFormat function was way too long so split it into
separate functions for each graphics type.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-03-07 14:01:26 +01:00
Pavel Hrdina
227bf2c9de domain_conf: modernize graphics formatting
Use separate buffers for attributes and children elements to make the
code cleaner and to use the virXMLFormatElement() function.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-03-07 14:01:26 +01:00
Pavel Hrdina
8d055b7d61 domain_conf: graphics: use a function to format audio element
Removes code duplication.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-03-07 14:01:26 +01:00
Pavel Hrdina
320273df54 domain_conf: graphics: use a function to format gl element
Removes code duplication.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-03-07 14:01:26 +01:00
Daniel P. Berrangé
288f90feb3 qemu: support MSDM ACPI table type
The MSDM ACPI table is a replacement for the SLIC table type, now
sometimes used by Microsoft for Windows Licensing checks:

  https://learn.microsoft.com/en-us/previous-versions/windows/hardware/design/dn653305(v=vs.85)

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/748
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2025-03-07 13:00:10 +00:00
Daniel P. Berrangé
32765cd14e conf: support MSDM ACPI table type
The MSDM ACPI table is an alternative for the SLIC table type,
sometimes used by Microsoft for Windows Licensing checks:

  https://learn.microsoft.com/en-us/previous-versions/windows/hardware/design/dn653305(v=vs.85)

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2025-03-07 13:00:10 +00:00
Daniel P. Berrangé
dac6ecba6f libxl: support 'rawset' ACPI table type
This fixes representation of the 'acpi_firmware' config in the Xen
driver, which repesents a concatenation of tables of any type.

Use of 'type=slic' is accepted on input for backwards compatibility.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2025-03-07 13:00:10 +00:00
Daniel P. Berrangé
fe0cf62e0f qemu: support 'raw' ACPI table type
This allows passing a single ACPI table of any type through to QEMU with
the signture autodetected from the header.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2025-03-07 13:00:10 +00:00
Daniel P. Berrangé
513ef8f028 src: introduce 'raw' and 'rawset' ACPI table types
The QEMU driver has only accepted type=slic even though QEMU is able to
accept individual tables of any type, without needing to specify a
signature. Introduce type=raw to address this usage scenario. Contrary
to other types, this one may appear multiple times.

The Xen driver has mistakenly accepted type=slic and use it to set the
Xen acpi_firmware setting, which performs a simple passthrough of
multiple concatenated data table. Introduce type=rawset to address
this usage scenario.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2025-03-07 13:00:10 +00:00
Daniel P. Berrangé
3d94587655 src: validate permitted ACPI table types in libxl/qemu drivers
This forces us to update the drivers when defining new table types
to avoid incorrectly accepting them by default.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2025-03-07 13:00:10 +00:00
Daniel P. Berrangé
55f48d3852 conf: introduce support for multiple ACPI tables
Currently we parse

   <os>
     <acpi>
       <table type="slic">...path...</table>
     </acpi>
   </os>

into a flat 'char *slic_table' field which is rather an anti-pattern
as it has special cased a single attribute type.

This rewrites the internal design to permit multiple table types to
be parsed, should we add more in future. Each type is currently
permitted to only appear once.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2025-03-07 13:00:10 +00:00
Dion Bosschieter
92de6563c6 nwfilter: Fix deadlock between nwfilter-list and VM startup/migration
The `nwfilterBindingCreateXML` and `nwfilterConnectListAllNWFilters`
APIs can acquire locks on multiple instances of virNWFilterObj. There
is no guarantee they will acquire these locks in the same order as
each other. Thus there is a potential for deadlock if they run
concurrently acquiring locks on the same filter objects.

This flaw has always existed, but historically was rare, because
virNWFilterObjList previously used an array. This meant iteration
over filters had a fixed order, matching order of loading filters
into libvirt.  The set of filter references would have to be just
right to expose the lock ordering deadlock.

In 8.2.0, commit c4fb52dc72b312431a3a28e3a163b38441a95665 switched
to use a hash table, introducing non-determinism to the iteration
order, as hash buckets vary based on the hash seed. As such almost
any filter with references is exposed to the deadlock risk now.

It is not easy  to guarantee lock ordering on the virNWFilterObj
instances, so acquiring `driverMutex` first, will serve to serialize
all lock acquisition on virNWFilterObj instances, avoiding the
deadlock scenario.

The major cost is that concurrency of the driver is significantly
reduced, with few other APIs able to run in parallel with updating
firewall rules.

A long term solution to this problem needs significant changes

 * The mutex on virNWFilterObj would need to change to a R/W
   lock.
 * The filter instantiation/teardown process would need to split
   into two phases. The first phase would resolve all the required
   virNWFilterObj instances & acquire read locks, while holding
   the 'driverMutex'. The second phase of running iptables/ebtables
   commands would then run without driverMutex held.
 * The filter define/undefine APIs would need to acquire write
   locks, other APIs only read locks.

This would allow concurrency of filter instantiation/teardown
with everything except for filter defnie/undefine, which was
the original desire.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
[DPB: rewrite commit message & add inline comment]
Signed-off-by: Dion Bosschieter <dionbosschieter@gmail.com>
2025-03-07 12:38:57 +00:00
Alexander Kuznetsov
8acc0b76c6 qemu: snapshot: Remove dead code in qemuSnapshotDeleteBlockJobFinishing()
qemuSnapshotDeleteBlockJobFinishing() returns only 0 and 1. Convert it
to bool and remove the dead code handling -1 return in the caller.

Found by Linux Verification Center (linuxtesting.org) with Svace.

Reported-by: Reported-by: Andrey Slepykh <a.slepykh@fobos-nt.ru>
Signed-off-by: Alexander Kuznetsov <kuznetsovam@altlinux.org>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2025-03-06 15:04:06 +01:00
Peter Krempa
07d8755523 domain_caps: Don't leak 'cpu0_id' in 'virSEVCapabilitiesFree'
Freeing the 'virSEVCapability' object leaked the 'cpu0_id' field since
its introduction.

Fixes: 0236e6154c46603bc443eda2f05c8ce511c55b08
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2025-03-06 14:06:46 +01:00
Peter Krempa
107cf9992f qemu: capabilities: Parse 'cpu0Id' from capability cache XML
The 'cpu0Id' field is formatted into the caps cache XML but not parsed
back; thus restart of the daemon will make it vanish.

Fixes: 0236e6154c46603bc443eda2f05c8ce511c55b08
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2025-03-06 13:04:25 +01:00
Laine Stump
25270737d3 conf: change virDomainDefAddImplicitControllers() to return void
It can't fail.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2025-03-05 16:56:45 -05:00
Laine Stump
fd6cfeeeea conf: change virDomainDefMaybeAddSmartcardController() to return void
It can't fail.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2025-03-05 16:56:45 -05:00
Laine Stump
be9a0f4764 conf: change virDomainDefMaybeAddVirtioSerialController() to return void
It can't fail.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2025-03-05 16:56:45 -05:00
Laine Stump
74e36dfce0 conf: change virDomainDefAddDiskControllersForType() to return void
It can't fail.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2025-03-05 16:56:45 -05:00
Laine Stump
7cfcfcc403 conf: change virDomainDefMaybeAddHostdevSCSIcontroller() to return void
It can't fail.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2025-03-05 16:56:44 -05:00
Laine Stump
250d6ac2a0 conf: change virDomainDefMaybeAddController() to return true/false
This function can't fail, but it has always returned 1 if a controller
is added and 0 if not, and there is one place that checks for a 1
return, so we remove the -1 return and change it to return true/false
instead of 1/0.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2025-03-05 16:56:44 -05:00
Laine Stump
cc82b06036 hyperv: change hypervDomainDefAppendController() to return void
It can't fail. And as a result, hypervDomainDefAppendSCSIController() and
hypervDomainDefAppendIDEController() can also be changed to return void.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2025-03-05 16:56:44 -05:00
Laine Stump
e207c9c17e conf: change virDomainDefAddUSBController() to return void
It can't fail.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2025-03-05 16:56:44 -05:00
Laine Stump
b0ef70aca9 conf: stop checking for NULL return from virDomainDefAddController()
It can't fail, so the caller doesn't need to check the return.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2025-03-05 16:56:44 -05:00