Update the PXB controller busNrs to account for devices we attached in the previous commit, ensuring there are enough VM bus numbers to be assigned for each device attached downstream from each PXB controller. Signed-off-by: Nathan Chen <nathanc@xxxxxxxxxx> --- src/qemu/qemu_domain_address.c | 52 ++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index dee198a7d2..001d1ec0b9 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -2678,6 +2678,23 @@ qemuDomainAddressFindNewTargetIndex(virDomainDef *def) } +static int +qemuDomainFindAttachedDevicesBusNr(virDomainDef *def, + int lowestBusNr, + unsigned int contIdx) +{ + size_t i; + for (i = 0; i < def->ncontrollers; i++) { + virDomainControllerDef *cont = def->controllers[i]; + if (cont->info.addr.pci.bus == contIdx && cont->idx != 0) + lowestBusNr = qemuDomainFindAttachedDevicesBusNr(def, lowestBusNr - 1, cont->idx); + if (lowestBusNr <= 2) + return -1; + } + return lowestBusNr; +} + + static int qemuDomainAddressFindNewBusNr(virDomainDef *def) { @@ -2725,8 +2742,43 @@ qemuDomainAddressFindNewBusNr(virDomainDef *def) */ size_t i; + size_t lowestBusNrContIdx = 0; int lowestBusNr = 256; + if (def->iommu && def->iommu->model && + def->iommu->model == VIR_DOMAIN_IOMMU_MODEL_NESTED_SMMUV3) { + for (i = 0; i < def->ncontrollers; i++) { + virDomainControllerDef *cont = def->controllers[i]; + if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI) { + int thisBusNr = cont->opts.pciopts.busNr; + if (thisBusNr >= 0 && thisBusNr < lowestBusNr) { + lowestBusNr = thisBusNr; + lowestBusNrContIdx = i; + } + } + } + if (lowestBusNr <= 2) + return -1; + if (lowestBusNrContIdx == 0) { + for (i = 0; i < def->ncontrollers; i++) { + if (def->controllers[i]->model == VIR_DOMAIN_CONTROLLER_MODEL_PCIE_EXPANDER_BUS) { + lowestBusNrContIdx = i; + break; + } + } + } else { + for (i = lowestBusNrContIdx + 1; i < def->ncontrollers; i++) { + if (def->controllers[i]->model == VIR_DOMAIN_CONTROLLER_MODEL_PCIE_EXPANDER_BUS) { + lowestBusNrContIdx = i; + break; + } + } + } + lowestBusNr = qemuDomainFindAttachedDevicesBusNr(def, lowestBusNr, + def->controllers[lowestBusNrContIdx]->idx); + return lowestBusNr - 2; + } + for (i = 0; i < def->ncontrollers; i++) { virDomainControllerDef *cont = def->controllers[i]; -- 2.34.1