Skip to content

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

In review

Description

@vladimirpetrov

problem

libvirt refuses the hot-plug ("PCI controller with index='0' doesn't support hotplug"), and the API caller only gets "null job execution result".

image
2026-12-01 11:19:19,553 ERROR [c.c.a.ApiAsyncJobDispatcher] (API-Job-Executor-73:[ctx-fc8f8c9c, job-692]) (logid:62efae87) Unexpected exception while executing org.apache.cloudstack.api.command.admin.vm.AddNicToVMCmdByAdmin java.lang.RuntimeException: null job execution result
        at com.cloud.vm.VirtualMachineManagerImpl.addVmToNetwork(VirtualMachineManagerImpl.java:4577)
        at com.cloud.vm.UserVmManagerImpl.addNicToVirtualMachine(UserVmManagerImpl.java:1552)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:569)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)

Cause - seems to be regression from #12826 "KVM: assign the hot-plugged NIC the next PCI slot above existing NICs (monotonic interface naming)"

  • The wrapper now pins bus='0x00' plus a computed slot (LibvirtVMDef.java:1703, LibvirtPlugNicCommandWrapper.java:87).
  • On q35, bus 0 is pcie-root, which doesn’t support hot-plug.
  • Before this change, libvirt picked a free pcie-root-port.

Scope - any running UEFI VM (Windows 11 and Secure Boot guests included). BIOS/i440fx VMs are fine: concurrent adds got distinct device ids and slots (0x07, 0x08), and a re-added NIC got 0x09, above the existing ones.

versions

4.22.2 RC2

The steps to reproduce the bug

  1. Deploy with boottype=UEFI bootmode=LEGACY (or SECURE) then addNicToVirtualMachine.
  2. The API caller only gets null job execution result.
  3. The agent log shows:
LibvirtPlugNicCommandWrapper  Assigning PCI slot 0x03 to hot-plugged NIC
Plug Nic failed due to org.libvirt.LibvirtException: XML error: The device at PCI address 0000:00:03.0 requires
hotplug capability, but the PCI controller with index='0' doesn't support hotplug

What to do about it?

No response

Activity

  1. added this to the 4.22.2 milestone on Dec 1, 2026
  2. Alpha162 commented on Dec 2, 2026

    @Alpha162
    Contributor

    I reproduced this on a two-host lab running a build of main at 58fda71 (Ubuntu 24.04, libvirt 10.0.0, QEMU 8.2.2, OVMF 2024.02). A UEFI VM fails addNicToVirtualMachine with "null job execution result", and the agent logs the same PCI controller with index='0' doesn't support hotplug error. A BIOS VM on the same build works.

    The pinned slot is always on bus 0x00. On i440fx that's pci-root, which takes hot-plugged devices. On q35, bus 0 is pcie-root, which doesn't, so any slot we pick there fails. #12826 is on 4.20 as well, so 4.20.4 would ship this too.

    A small fix that worked for me: in findNextAvailablePciSlot, return null (let libvirt choose) when the domain's PCI controller index 0 is pcie-root. libvirt then puts the NIC on a free pcie-root-port, as it did before #12826. i440fx keeps the monotonic slot logic unchanged.

    What I tested with that change on the lab:

    Case Result
    UEFI VM, add a NIC Works. The NIC lands on a free root port (bus 0x08)
    UEFI 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 UEFI VM after a stop and start, add a NIC Works. The rebuilt domain had a free root port again
    BIOS VM, add two NICs, remove one, add it again Works. Slots 0x08, 0x09, then 0x0a, so the monotonic order from #12826 still holds
    LibvirtPlugNicCommandWrapperTest 11 pass, including 3 new ones for q35 and i440fx domain XML

    Two things worth knowing:

    • On q35 the guest's NIC order still isn't guaranteed across hot-plugs, because libvirt picks the port. Getting that would need adding a pcie-root-port per hot-plugged NIC, which seems a bigger change than a fix for a release blocker should be.
    • After the stop and start, CloudStack rebuilt the XML and the hot-plugged NIC moved from bus 0x08 to 0x03. That happens without this change too.

    @sureshanaparti I see you've picked this up. I'm happy to open a PR against 4.20 with the change and tests if that helps, or to test yours on the same lab.

  3. sureshanaparti commented on Dec 2, 2026

    @sureshanaparti
    Contributor

    thanks @Alpha162 , I created the fix here: #14948, can you review / verify it.

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

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions