Skip to content

kvm: add PCIe root ports to x86 q35 guests so volumes and NICs can be hot-plugged - #14867

Open
andrijapanicsb wants to merge 1 commit into
apache:mainfrom
andrijapanicsb:kvm-q35-pcie-root-ports
Open

andrijapanicsb wants to merge 1 commit into
apache:mainfrom
andrijapanicsb:kvm-q35-pcie-root-ports

Conversation

@andrijapanicsb

@andrijapanicsb andrijapanicsb commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #11212

In short

On KVM, a UEFI (q35) guest can hot-plug only one more disk or NIC, then the next attach fails with No more available PCI slots. This gives every x86 q35 guest 28 empty PCIe root ports at start, as aarch64/s390x guests already get 32 (#5193), so disks and NICs can be hot-plugged.

Change

  1. LibvirtComputingResource: an x86 guest with a q35 machine type (q35, pc-q35-*) gets a pcie-root controller and 28 pcie-root-port controllers. The count is fixed, with no setting.
  2. LibvirtVMDef: these controllers go after all devices, without index or <address>, so libvirt places every existing device exactly where it did before. The extra ports are the empty ones after them.
  3. LibvirtPlugNicCommandWrapper: on q35, a hot-plugged NIC is no longer pinned to a bus 0 slot (since KVM: assign the hot-plugged NIC the next PCI slot above existing NICs (monotonic interface naming) #12826). libvirt refuses that on q35, because the PCIe root complex isn't hot-pluggable.

i440fx (pc), LXC, aarch64 and s390x guests get exactly the same XML as before. 28 is also the maximum OpenStack Nova allows for num_pcie_ports.

Firmware note: OVMF before May 2023

OVMF before edk2 commit 27727338b2c0 reserves I/O space for every empty hot-plug port, and only about 10 ports get resources. On such hosts, Windows Server 2019 takes the first hot-plugged disk after a start. The following ones show Device Manager code 10 until the guest is rebooted, and while it runs CloudStack can't detach them (the detach times out). Windows Server 2025 got all 10 disks on the same host, firmware and VirtIO driver. Memory size (2 or 4 GiB) makes no difference. Linux guests and NICs aren't affected. Today the second hot-plug fails outright, so this is still an improvement.

Fixed firmware: EL 9.3 and later (edk2-ovmf-20230524-3.el9 backports the fix) and Ubuntu 24.04. Affected, by package version: EL8, EL9.0-9.2, Ubuntu 22.04, Debian 12. On EL9 hosts, dnf update edk2-ovmf is enough; CloudStack's uefi.properties paths keep working.

Tests

Unit tests (JDK 17): mvn -pl plugins/hypervisors/kvm test, 1115 tests, 0 failures, 0 Checkstyle violations.

Lab 1: this commit on main. The ACSHomeBot package build of 78a1a7d (merged onto main 85ca17a), agent installed on one KVM host and compared with the stock agent from main. AlmaLinux 9.1 KVM host, libvirt 8.5.0, QEMU 7.0, NFS primary storage. Guests: Windows Server 2025 (UEFI, Secure Boot, static IP) and Ubuntu 24.04 (UEFI), each with 2 disks and 2 NICs. The management server ran a separate test build; this change is agent-only.

Test Stock agent from main With this change
Hot-plug a 2nd volume No more available PCI slots Works
Hot-plug a NIC Fails every time: ...requires hotplug capability, but the PCI controller with index='0' doesn't support hotplug Works; NICs go to free root ports after the existing ones, the guest names them in hot-plug order, ping works over them
Fill every free port with NICs and volumes - Windows: 9 NICs + 14 volumes; Linux: 8 NICs + 13 volumes; then libvirt refuses cleanly, nothing half-attached
Detach volumes and NICs, attach again, guest reboot - Same ports and names as before; everything present after the reboot
Existing guests stopped and started on the new agent, then again after dnf update edk2-ovmf - Same PCI bus/device/function for every device; same NICs, MACs and static IP; no ghost devices
Old OVMF (20220526, EL9.1), 10 volumes hot-plugged after a start, each case twice - Windows Server 2019 at 2 and 4 GiB: 1 works, 9 code 10, the 9 can't be detached until the VM is stopped. Windows Server 2025 at 2 and 4 GiB: 10 of 10 work
Current OVMF (20241117-9.el9) - Windows Server 2025: 10 of 10 work

Lab 2: an earlier build. Same host software. The agent was built from an October 24.0.0-SNAPSHOT commit (d3f0700) with the same change. That commit predates #12826, so change 3 wasn't needed there.

Test Before After
Hot-plug into a UEFI guest 2nd attach fails Windows: 19 disks + 4 NICs attached; Linux: 10 disks + 4 NICs; then libvirt refuses cleanly (all ports used)
Existing guests (Windows UEFI Secure Boot with static IP, Ubuntu UEFI, CentOS i440fx) stopped and started on the new agent - Same PCI bus/device/function for every device; same NICs, MACs and static IP; no ghost devices
Windows Server 2019, 10 disks hot-plugged after a start, on edk2-ovmf 20220526 (EL9.1) - 1 works, 9 code 10 until a reboot
Same guest and host, on edk2-ovmf 20241117-9.el9 - 10 of 10 work, back to back and with pauses; Secure Boot on
Live migration of a Linux guest, new agent to old agent and back - Works; the layout moves with the guest

Not tested yet

  • Live migration between a patched and an unpatched host on main (done only in lab 2).
  • Reverting a VM snapshot with memory taken before the upgrade.
  • q35 with SeaBIOS in a lab (checked locally with QEMU only), and guests that start with 28 or more PCIe devices.
  • Windows Server 2016 and 2022 on old OVMF, and other VirtIO driver versions.
  • aarch64 and s390x: unit tests only; their code path is unchanged.

Related: #14844 (explicit disk controllers). With it, more Windows UEFI guests use virtio-blk disks, one root port each.

… hot-plugged

x86 KVM guests with a q35 machine type (all UEFI guests, and guests with
kvm.guest.os.machine.type=q35 or a versioned pc-q35-* type) now always get a
pcie-root controller and 28 pcie-root-port controllers, appended after all
devices without index or address, as aarch64/s390x guests already get 32
(apache#5193). The count is fixed; there is no setting.

NIC hot-plug no longer pins the NIC to a bus 0 slot on q35, where libvirt
refuses it because the PCIe root complex is not hot-pluggable.

Fixes apache#11212
@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.23810% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 20.93%. Comparing base (04fa924) to head (78a1a7d).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...ervisor/kvm/resource/LibvirtComputingResource.java 91.66% 0 Missing and 1 partial ⚠️
...resource/wrapper/LibvirtPlugNicCommandWrapper.java 94.11% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #14867      +/-   ##
============================================
+ Coverage     20.83%   20.93%   +0.10%     
- Complexity    20973    21172     +199     
============================================
  Files          6053     6057       +4     
  Lines        548955   549598     +643     
  Branches      73359    73483     +124     
============================================
+ Hits         114377   115076     +699     
+ Misses       421186   421074     -112     
- Partials      13392    13448      +56     
Flag Coverage Δ
uitests 3.86% <ø> (ø)
unittests 22.38% <95.23%> (+0.10%) ⬆️

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

Copy link
Copy Markdown
Contributor Author

@ACSHomeBot package G

@ACSHomeBot

ACSHomeBot commented Nov 25, 2026 •

Copy link
Copy Markdown

Accepted: package kvm G for 78a1a7d89a0d.

Planned: RPM + DEB, KVM SystemVM.

Status: Completed. Packaging results.

@ACSHomeBot

Copy link
Copy Markdown

@andrijapanicsb
andrijapanicsb marked this pull request as ready for review November 26, 2026 02:21

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.

Unable to add more than 2 volumes or networks to a vm deployed from a UEFI image

2 participants