From: Laine Stump Date: Sat, 19 Oct 2019 05:58:07 +0000 (-0400) Subject: qemu: avoid double reservation of PCI address for interface type='hostdev' X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=47a7b8a96b6343d4af18ef80330f805ef031fe9b;p=libvirt.git qemu: avoid double reservation of PCI address for interface type='hostdev' Commit 01ca4010d86 (libvirt v5.1.0) moved address reservation for hotplugged interface devices up to an earlier point in qemuDomainAttachNetDevice(), because that function calls qemuDomainSupportsNicdev() (in the case of VIR_DOMAIN_NET_TYPE_VHOSTUSER), and qemuDomainSupportsNicdev() needs to know the address type (for ARM machinetypes) and returns incorrect results when the address type is "none". This bugfix unfortunately caused a regression, because it also made PCI address reservation happen before we noticed that the device was a *hostdev* interface. Those interfaces are hotplugged by just calling out to qemuDomainAttachHostdevDevice() - that function would then also attempt to reserve the *same PCI address* that had just been reserved in qemuDomainAttachNetDevice(). The solution is to move the bit of code that short-circuits out to virDomainHostdevAttach() up *even earlier* so that no PCI address has been allocated by the time it's called. https://bugzilla.redhat.com/show_bug.cgi?id=1744523 Signed-off-by: Laine Stump Reviewed-by: Andrea Bolognani --- diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index fd4bafef0c..77744ed96a 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1181,6 +1181,17 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, if (qemuAssignDeviceNetAlias(vm->def, net, -1) < 0) goto cleanup; + if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) { + /* This is really a "smart hostdev", so it should be attached + * as a hostdev (the hostdev code will reach over into the + * netdev-specific code as appropriate), then also added to + * the nets list (see cleanup:) if successful. + */ + ret = qemuDomainAttachHostDevice(driver, vm, + virDomainNetGetActualHostdev(net)); + goto cleanup; + } + if (qemuDomainIsS390CCW(vm->def) && net->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI && virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_CCW)) { @@ -1260,17 +1271,6 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, goto cleanup; break; - case VIR_DOMAIN_NET_TYPE_HOSTDEV: - /* This is really a "smart hostdev", so it should be attached - * as a hostdev (the hostdev code will reach over into the - * netdev-specific code as appropriate), then also added to - * the nets list (see cleanup:) if successful. - */ - ret = qemuDomainAttachHostDevice(driver, vm, - virDomainNetGetActualHostdev(net)); - goto cleanup; - break; - case VIR_DOMAIN_NET_TYPE_VHOSTUSER: queueSize = net->driver.virtio.queues; if (!queueSize) @@ -1313,6 +1313,10 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, } break; + case VIR_DOMAIN_NET_TYPE_HOSTDEV: + /* hostdev interfaces were handled earlier in this function */ + break; + case VIR_DOMAIN_NET_TYPE_SERVER: case VIR_DOMAIN_NET_TYPE_CLIENT: case VIR_DOMAIN_NET_TYPE_MCAST: