Skip to content

kvm: honour explicit root and data disk controllers for UEFI and Windows VMs - #14844

Draft
andrijapanicsb wants to merge 1 commit into
apache:mainfrom
andrijapanicsb:kvm-honour-explicit-disk-controller
Draft

andrijapanicsb wants to merge 1 commit into
apache:mainfrom
andrijapanicsb:kvm-honour-explicit-disk-controller

Conversation

@andrijapanicsb

Copy link
Copy Markdown
Contributor

Description

This PR makes the KVM agent use the disk bus that is set for a VM with the rootDiskController and
dataDiskController details (VM details, or template details copied to the VM), whatever the guest OS, the boot
mode (BIOS, UEFI legacy, UEFI secure) and the primary storage type. When no controller is set, nothing changes.

Problem. A Windows VM with UEFI Secure Boot on a file-based primary storage (NFS, local, SharedMountPoint) always
gets its disks on SATA, even when its details say rootDiskController=virtio and dataDiskController=virtio and the
guest has the virtio storage drivers. Example: a Windows Server 2025 VM (q35, UEFI Secure Boot, NFS primary storage)
imported with UEFI=SECURE, rootDiskController=virtio, dataDiskController=virtio, nicAdapter=virtio: libvirt
gets both disks with bus='sata'. The same happens for Windows Server 2019 and 2022: there is no Windows version
specific code, the KVM agent only checks whether the OS name contains "window".

Expected. If the VM settings say the disk controller is virtio, the disks are virtio. A VM without these settings
keeps today's defaults (SATA for Windows UEFI VMs), and the CD-ROMs of UEFI VMs stay on SATA.

Root cause

The bus is forced in LibvirtComputingResource.createVbd() after the controller details have been read:

As a result, whether an explicit controller is honoured depends on the storage type:

Pool type (branch in createVbd) Root disk Data disks
File-based QCOW2 (NFS, local, SharedMountPoint, ...) Secure Boot: forced to SATA (Windows) or virtio (other OSes) Windows UEFI: forced to SATA (Secure Boot) or root disk bus
PowerFlex uses the data disk bus; Windows UEFI: forced to SATA data disk bus; Windows UEFI: forced to SATA
RBD, Gluster rootDiskController honoured (no forcing) always the root disk bus, dataDiskController ignored
CLVM, CLVM_NG, RAW format (Linstor, StorPool, ...) rootDiskController honoured Windows UEFI: root disk bus, dataDiskController ignored

So Windows UEFI Secure Boot VMs with rootDiskController=virtio already get virtio disks on RBD and CLVM pools today;
only file-based pools and PowerFlex force SATA.

The change (KVM agent only)

plugins/hypervisors/kvm/.../LibvirtComputingResource.java:

  • New getExplicitDiskBus(): returns the bus set for a disk by rootDiskController (root volume) or
    dataDiskController (data volume), or null when the detail is not set or is not virtio, scsi, sata or ide
    (for example osdefault, which the UI puts in KVM templates by default). Two rules keep it compatible:
    • The data disks of a Windows UEFI VM without dataDiskController follow the root disk, as they do today.
    • ide on a UEFI VM gives sata: UEFI VMs use q35, which has no IDE bus (libvirt refuses it), and SATA is what the
      CD-ROMs of UEFI VMs already use.
  • createVbd(): when that bus is set, it is used for the disk on every pool type (file-based, PowerFlex, RBD, Gluster,
    CLVM, RAW). When it is not set, the existing code runs unchanged, including the SATA defaults of Windows UEFI VMs and
    the PowerFlex SATA forcing.
  • defineDiskForDefaultPoolType(): new explicitDiskBus parameter. skip.force.disk.controller is still checked
    first and behaves exactly as before.

Not changed: CD-ROMs (still SATA on UEFI, IDE on BIOS), device names (vdX for virtio, sdX for SATA/SCSI, letter from
the device id), the hot-plug path (KVMStorageProcessor, which already honours the controller details since #12452),
the management server, the API, the UI and the database.

Behaviour

Only VMs with rootDiskController and/or dataDiskController set to virtio, scsi, sata or ide can change, and
only at their next start.

VM rootDiskController dataDiskController Before After
Windows, UEFI secure, file-based pool not set / osdefault not set / osdefault sata / sata sata / sata
Windows, UEFI secure, file-based pool virtio virtio sata / sata virtio / virtio
Windows, UEFI secure, file-based pool virtio not set sata / sata virtio / virtio
Windows, UEFI secure, file-based pool not set virtio sata / sata sata / virtio
Windows, UEFI secure, file-based pool ide not set sata / sata sata / sata
Windows, UEFI legacy, file-based pool virtio sata virtio / virtio virtio / sata
Windows, UEFI legacy, file-based pool ide not set ide / ide (libvirt refuses IDE on q35) sata / sata
Linux, UEFI secure, file-based pool not set not set virtio / virtio virtio / virtio
Linux, UEFI secure, file-based pool scsi not set virtio / scsi scsi / scsi
Any OS, BIOS, file-based, CLVM or RAW pool any any unchanged unchanged
Windows, UEFI, PowerFlex virtio virtio sata / sata virtio / virtio
Windows, UEFI, PowerFlex not set not set sata / sata sata / sata
Non-Windows or BIOS VM, PowerFlex scsi virtio virtio / virtio scsi / virtio
Any VM, RBD or Gluster virtio scsi virtio / virtio virtio / scsi
Any VM virtio-blk not set unchanged unchanged

Compatibility and upgrade notes

  • The agent cannot tell who set a controller detail, but on KVM the management server never writes a default one:
    the details come from the user (deploy or update details, UI settings), from the template details, or from the
    import of an unmanaged or converted VM, which copies the bus the source disk used
    (UnmanagedVMsManagerImpl). The osdefault value is not a bus and is treated as not set, as before.

  • VMs whose explicit controller was overridden get it at their next start (bold cells above). A Windows guest moved
    from SATA to virtio needs the virtio storage driver installed and enabled for boot, otherwise it stops with
    INACCESSIBLE_BOOT_DEVICE. Note that the VMware to KVM conversion stores virtio for a disk when the converted domain
    XML cannot be parsed (LibvirtBaseConvertCommandWrapper). Operators can list these VMs before upgrading the agents
    and set rootDiskController=sata / dataDiskController=sata to keep SATA:

    SELECT vm.uuid, vm.instance_name, d.name, d.value
    FROM cloud.vm_instance vm
    JOIN cloud.vm_instance_details d ON d.vm_id = vm.id
    WHERE vm.hypervisor_type = 'KVM' AND vm.removed IS NULL
      AND d.name IN ('rootDiskController', 'dataDiskController')
      AND LOWER(d.value) IN ('virtio', 'scsi', 'sata', 'ide')
      AND vm.id IN (SELECT vm_id FROM cloud.vm_instance_details WHERE name = 'UEFI');

    (4.20 uses the table user_vm_details. Add the PowerFlex, RBD and Gluster VMs listed in the table above if those
    pools are used.)

  • Running VMs are not touched. Live migration keeps the running domain definition.

  • During a rolling upgrade, a VM gets SATA or virtio depending on the agent version of the host it starts on.

  • skip.force.disk.controller keeps working. It is no longer needed to get explicit controllers honoured; it only
    changes the defaults used when no controller is set.

  • On q35, each virtio disk takes a PCIe root port and SATA disks do not. See Unable to add more than 2 volumes or networks to a vm deployed from a UEFI image #11212 about the PCIe slots left for
    hot-plugging volumes and NICs into UEFI VMs.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

How Has This Been Tested?

Unit tests in LibvirtComputingResourceTest (20 new, 5 updated for the new parameter). The createVbd tests build the
libvirt disk definitions of a User VM the way it is done at start, and check bus, target name and the <target> XML
of every disk and CD-ROM:

  • Windows UEFI Secure Boot with virtio root and data controllers, for the OS types Windows Server 2019, 2022 and 2025:
    vda/vdb virtio, CD-ROMs sdd/sde SATA.
  • Windows UEFI Secure Boot with no controller (same three OS types), and with osdefault: SATA, as before.
  • Windows UEFI legacy: explicit controllers honoured; no controller: SATA as before.
  • Windows UEFI data disks follow an explicit root controller when dataDiskController is not set.
  • Linux without controllers (UEFI Secure Boot and BIOS): unchanged; Linux UEFI Secure Boot with scsi: honoured.
  • CD-ROMs of UEFI VMs stay SATA next to virtio disks, with and without an ISO.
  • ide on UEFI gives SATA; ide on BIOS stays IDE; virtio-blk keeps the current behaviour.
  • skip.force.disk.controller=true gives the same buses as before.
  • Target names are unique for root + 3 data disks (device ids 0, 1, 2, 5) + 2 CD-ROMs, for Windows and Linux, BIOS,
    UEFI legacy and UEFI secure, and 7 controller combinations.
  • PowerFlex and RBD.

Results (JDK 17, Maven 3.8.7):

  • mvn -pl plugins/hypervisors/kvm test -Dtest=LibvirtComputingResourceTest: 350 tests, 0 failures.
  • mvn -pl plugins/hypervisors/kvm test (whole KVM plugin, checkstyle included): 1119 tests, 0 failures, 0 errors,
    1 skipped (QemuImgTest, needs a local qemu-img).
  • The 15 new createVbd tests run against main without the fix: the 8 that check explicit controllers fail
    (for example "expected virtio but was sata" for the Windows Secure Boot case) and the 7 that check unchanged
    behaviour pass.

Lab tests

These were run before this change, using skip.force.disk.controller=true. For a VM with explicit virtio controllers
that gives the same libvirt disk definitions as this change. A run with the patched agent jar itself is still to be
done; only the cloud-plugin-hypervisor-kvm jar needs to be replaced on a host for it.

Setup

  • CloudStack 24.0.0-SNAPSHOT (KVM agent 24.0.0-101), EL9 KVM hosts, NFS primary storage.
  • q35 pc-q35-rhel9.0.0, OVMF_CODE.secboot.fd with SMM.
  • Guest: Windows Server 2025 Standard with UEFI and Secure Boot, moved from VMware with virt-v2v
    (virtio-win 1.9.61, viostor 100.103.104.30200).
  • Imported with UEFI=SECURE, rootDiskController=virtio, dataDiskController=virtio, nicAdapter=virtio.
  • OS type "Windows Server 2022 (64-bit)".

Results

Run skip.force.disk.controller Disks in the libvirt XML CD-ROMs Result
1 not set (current behaviour) sdb, sdc, bus='sata' sdd, sde, SATA booted, first boot completed, guest agent running
2 true vdb, vdc, bus='virtio' sdd, sde, SATA booted, first boot completed, guest agent running
3 true (a fresh VM) vdb, vdc, bus='virtio' sdd, sde, SATA booted, first boot completed, guest agent running
  • Each VM was watched for 30 minutes after its first start and settled with no restart loop.
  • In runs 2 and 3 Windows runs both disks on viostor ("Red Hat VirtIO SCSI controller").
  • On its first boot from virtio, Windows replaced the boot-time placeholder driver with viostor and restarted once on
    its own ("Operating System: Upgrade (Planned)"); after that it settled.
  • The Secure Boot state inside the guest was read on KVM outside CloudStack, with the same guest, OVMF with the
    Microsoft keys and a virtio-blk boot disk: Confirm-SecureBootUEFI returned True on the first boot and after a
    reboot.
  • The same guest also boots and settles with SATA disks (run 1).

How did you try to break this feature and the system with this change?

Backport

4.22 and 4.20 have the same forcing code (#11554, #11750 and #12452 are on both branches), so they need the fix too.
The patch does not apply cleanly to them: one trivial conflict in createVbd (CLVM_NG does not exist on these
branches) and context differences in the test class. The createVbd tests also need the CD-ROMs passed as ISO volumes,
because the KVM agent of these branches does not define the empty CD-ROM slots itself (#13101 is not on them).
#14407 is not on these branches (#14073 is open for 4.22), so the SATA name collisions of #13484 can still happen there
for VMs whose disks are on SATA; this PR does not change that, and VMs whose disks are on virtio do not have it.

Checked locally with the conflicts resolved (JDK 17): LibvirtComputingResourceTest passes on 4.22 at 759bb81886
(289 tests) and on 4.20 at e6f193db80 (262 tests), the 20 new tests included. The resolved 4.22 change applies
cleanly to the tags 4.22.1.0 and 4.22.1.1, the 4.20 one to 4.20.3.1. On the tag 4.23.0.0 the main patch applies
with a 3-way merge and no conflict, and the test class passes (335 tests).

Documentation

The admin guide notes added by apache/cloudstack-documentation#616 and #655 should say that the rootDiskController
and dataDiskController settings are honoured for UEFI and Windows VMs, and that skip.force.disk.controller only
matters when no controller is set.

…ows VMs

When the rootDiskController or dataDiskController detail of a VM is set to
virtio, scsi, sata or ide, the KVM agent now uses that bus for the disk on
every primary storage type, whatever the guest OS and the boot mode. Until
now a Windows VM with UEFI Secure Boot on a file-based pool (and every
Windows UEFI VM on PowerFlex) always got SATA disks, whatever was set.

Without these details the existing defaults stay, including SATA for
Windows UEFI VMs. CD-ROMs are not changed (SATA on UEFI, IDE on BIOS).
ide on a UEFI VM gives sata, as the q35 machine type has no IDE bus.
skip.force.disk.controller keeps working as before.
@andrijapanicsb

Copy link
Copy Markdown
Contributor Author

On the concern raised in #10213 that virtio disks break Windows guests with UEFI Secure Boot (#10213 (comment)): I looked into this claim and tested it.

Short version: I found no evidence that virtio disks break Windows under UEFI Secure Boot, and my tests show the
opposite. Secure Boot checks signatures, not the disk bus. As far as I can find, no log, error code or reproduction
was ever posted for the original observation (#3638, #4773, #10213).

What I tested

  • Windows Server 2025 on CloudStack with Secure Boot (q35, OVMF_CODE.secboot.fd with SMM, bootmode=secure), both
    disks on bus='virtio', CD-ROMs on SATA. Two runs; both booted, finished their first boot and ran the guest agent.
  • The same guest on KVM with the Microsoft keys enrolled, boot disk on virtio-blk: Confirm-SecureBootUEFI returned
    True inside Windows, on the first boot and after a reboot.
  • Windows Server 2019 on CloudStack UEFI with virtio disks (Secure Boot off): several runs, all fine.
  • virtio-win ships the same viostor build for Server 2016, 2019, 2022 and 2025. Only 2025 was run with Secure Boot on
    virtio.

When Windows really fails

None of these cases is caused by the disk bus:

  1. No virtio storage driver in the guest, for example Windows installed from Microsoft media onto SATA or IDE.
    Booting from virtio then stops with INACCESSIBLE_BOOT_DEVICE, with or without Secure Boot. That is a fair reason
    for a SATA default when no controller is set, not for overriding an explicit setting.

  2. Test-signed or self-built drivers. Secure Boot policy prevents enabling TESTSIGNING
    (Microsoft docs),
    so a setup that relied on test signing works only with Secure Boot off. The cause is the signature, not the bus.

  3. Drivers signed in a way the Windows edition does not accept. Microsoft describes attestation signing as "for
    testing on Windows 10 client only systems"
    (Microsoft docs).
    The same applies to certificate chains the guest does not trust, such as smbus.inf from virtio-win 0.1.285 on
    Server 2025 ("terminated in a root certificate which is not trusted"), and to older Windows releases that cannot
    validate SHA-2 signatures.

  4. Firmware keys that do not match the boot manager: the CA that signed it is missing from db, or the boot
    manager is revoked through dbx. This fails in the firmware, before any disk driver loads.

  5. The first boot after moving an existing guest from SATA to virtio.

    It is a first-boot sequencing issue, not a Secure Boot one.

For this PR: forcing SATA only covers case 1, and it overrides every operator who sets virtio on purpose. This
change keeps the SATA default when no controller is set, and honours rootDiskController and dataDiskController
when they are set, as is already the case for RBD and CLVM pools.

If there is a specific Windows version or scenario to check, I can run it and post the results.

@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 20.85%. Comparing base (04fa924) to head (7576ac9).

Files with missing lines Patch % Lines
...ervisor/kvm/resource/LibvirtComputingResource.java 88.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #14844      +/-   ##
============================================
+ Coverage     20.83%   20.85%   +0.01%     
- Complexity    20973    21015      +42     
============================================
  Files          6053     6053              
  Lines        548955   548976      +21     
  Branches      73359    73364       +5     
============================================
+ Hits         114377   114481     +104     
+ Misses       421186   421115      -71     
+ Partials      13392    13380      -12     
Flag Coverage Δ
uitests 3.86% <ø> (ø)
unittests 22.29% <88.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@andrijapanicsb
andrijapanicsb marked this pull request as ready for review November 25, 2026 01:22
@andrijapanicsb

Copy link
Copy Markdown
Contributor Author

@ACSHomeBot package G

@andrijapanicsb andrijapanicsb added this to the 24.0 milestone Nov 25, 2026
@andrijapanicsb andrijapanicsb self-assigned this Nov 25, 2026
@ACSHomeBot

ACSHomeBot commented Nov 25, 2026 •

Copy link
Copy Markdown

Accepted: package kvm G for 7576ac9e81cf.

Planned: RPM + DEB, KVM SystemVM.

Status: Completed. Packaging results.

@ACSHomeBot

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants