Skip to content

KVM: let libvirt place the hot-plugged NIC on q35 guests - #14948

Open
sureshanaparti wants to merge 1 commit into
apache:4.22from
shapeblue:add-nic-to-running-uefi-vm-fix
Open

sureshanaparti wants to merge 1 commit into
apache:4.22from
shapeblue:add-nic-to-running-uefi-vm-fix

Conversation

@sureshanaparti

@sureshanaparti sureshanaparti commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR, for KVM, lets libvirt place the hot-plugged NIC on q35 guests.

Since #12826 the hot-plugged NIC is pinned to a slot on bus 0 so the guest sees a monotonic interface order. On a UEFI guest the machine type is q35, where bus 0 is the PCIe root complex and does not accept hot-plugged devices, so libvirt refuses the attach and addNicToVirtualMachine fails for every running UEFI VM.

When the domain XML carries a pcie-root controller, return no slot and let libvirt pick a free root port, as it did before #12826. i440fx guests keep the monotonic slot selection.

Fixes #14930

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

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

  • Add Nic to running UEFI VM.

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain, and the change includes targeted tests for q35 detection and fallback slot selection.

No open issues 🎉

What changed in this PR

Fixes KVM NIC hot-plugging for q35/UEFI guests by letting libvirt select a hot-pluggable PCIe root port while preserving deterministic slot assignment for i440fx guests.

Changes:

  • Detects pcie-root controllers and skips explicit slot assignment.
  • Adds unit coverage for q35 detection and fallback behavior.
File Description
plugins/​hypervisors/​kvm/​src/​test/​java/​com/​cloud/​hypervisor/​kvm/​resource/​wrapper/​LibvirtPlugNicCommandWrapperTest.java Adds tests for q35 PCIe root detection and slot-selection fallback.
plugins/​hypervisors/​kvm/​src/​main/​java/​com/​cloud/​hypervisor/​kvm/​resource/​wrapper/​LibvirtPlugNicCommandWrapper.java Detects PCIe root-complex guests and delegates NIC placement to libvirt while retaining i440fx slot assignment.

Review effort: Lite

@sureshanaparti

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 18.34%. Comparing base (069ac79) to head (818c4c5).

Files with missing lines Patch % Lines
...resource/wrapper/LibvirtPlugNicCommandWrapper.java 94.11% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               4.22   #14948   +/-   ##
=========================================
  Coverage     18.34%   18.34%           
- Complexity    16670    16675    +5     
=========================================
  Files          5939     5939           
  Lines        537814   537831   +17     
  Branches      65937    65940    +3     
=========================================
+ Hits          98637    98663   +26     
+ Misses       427953   427944    -9     
  Partials      11224    11224           
Flag Coverage Δ
uitests 4.08% <ø> (ø)
unittests 19.43% <94.11%> (+<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.

@sudo87 sudo87 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm

@sudo87

sudo87 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

one optional change we can make in "findNextAvailablePciSlot" method to parse the domxml once and pass it to both hasPcieRootComplex and getUsedPciSlots

@Alpha162 Alpha162 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sureshanaparti. I built this PR's diff and ran it on the same lab as #14930, swapping only the KVM plugin jar on one host. That lab's agent is a build of main at 58fda71 plus my NUMA change from #14921, which doesn't touch the NIC plug path.

Case Result
UEFI VM, add a NIC with the original jar (control) Fails with the same PCI controller with index='0' doesn't support hotplug error
UEFI VM, add a NIC with this PR Works. The NIC lands on a free root port (bus 0x08)
Same VM, add a second NIC with no spare root port left Fails with libvirt's "No more available PCI slots", same as before #12826
Same VM after a stop and start, add a NIC Works (bus 0x09)
BIOS VM with hot-plugged NICs on slots 0x08 and 0x09, remove the first and add it again Works, and it comes back on 0x0a, so the ordering from #12826 still holds
LibvirtPlugNicCommandWrapperTest 10 pass

The code reads well to me, and it's the same approach as the patch I tested on #14930. LGTM.

One question: #12826 is on 4.20 as well. Should this go to 4.20 too, so a later 4.20 release doesn't pick up the same regression?

@sureshanaparti

sureshanaparti commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor Author

One question: #12826 is on 4.20 as well. Should this go to 4.20 too, so a later 4.20 release doesn't pick up the same regression?

thanks @Alpha162 for testing. we can keep 4.22 for now, in case required in 4.20, we can back port as we cannot merge forward 4.20 to 4.22 in the current state as 4.22 is frozen for release. also, note that 4.20.x EOL on 1 Jan 2027 and not sure if any 4.20.x further release before that.

@sudo87

sudo87 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@sudo87 a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

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.

KVM: adding a NIC to a running UEFI VM fails.

5 participants