<div dir="ltr"><div dir="ltr"><div>Thanks Laine,</div><div><br></div><div>Mea Culpa, <br></div><div><br></div><div>Couldn't reproduce, or found the multiple duplicate entries in the guest pci domain/bus/slot/function space which got resolved easily.<br></div><div><br></div><div><br></div><div><br></div><div><br></div><div>[root@grit tmp]# virsh list<br> Id   Name   State<br>--------------------<br><br>[root@grit tmp]# virsh list --all<br> Id   Name          State<br>------------------------------<br> -    openbsd6.7    shut off<br> -    openindiana   shut off<br> -    proxmox6.2    shut off<br> -    ubuntu20.04   shut off<br> -    win2k19       shut off<br><br>[root@grit tmp]# virsh version<br>Compiled against library: libvirt 6.1.0<br>Using library: libvirt 6.1.0<br>Using API: QEMU 6.1.0<br>Running hypervisor: QEMU 4.2.1<br><br>[root@grit tmp]# virsh dumpxml ubuntu20.04 | gzip -c >  ubunt2004.xml.gz <br>[root@grit tmp]# chown dan: ubunt2004.xml.gz<br>[root@grit tmp]# virsh edit win2k19 <br></div><div><br></div><div>(paste the 4 <hostdev mode='subsystem' type='pci' managed='yes'> devices from ubuntu2004 to the devices section)</div><div>save and exit.<br></div><div><br></div><div>error: XML error: Attempted double use of PCI Address 0000:08:00.0<br>Failed. Try again? [y,n,i,f,?]: <br><br></div><div>[root@grit tmp]# virsh dumpxml win2k19  | gzip -c >  win2k19.xml.gz</div><div><br></div><br></div><div>Looking closer it seemed the 0000:08:00.0 was the guest address that already had a device defined on it.</div><div><br></div><div><br></div><div>Removing those in virt-manager and readding them generated a warning that they were in another definition, however</div><div>it did accept them.</div><div><br></div><div>This, for 4 pci devices, confused libvrtd in the meantime however it was still functional.</div><div><br></div><div>Aug 18 10:31:27 grit libvirtd[106082]: internal error: failed to get number of host interfaces: unspecified error - errors in loading some config files<br>Aug 18 10:31:55 grit libvirtd[106082]: internal error: failed to get number of host interfaces: unspecified error - errors in loading some config files<br>Aug 18 10:32:17 grit libvirtd[106082]: internal error: failed to get number of host interfaces: unspecified error - errors in loading some config files<br>Aug 18 10:32:32 grit libvirtd[106082]: internal error: failed to get number of host interfaces: unspecified error - errors in loading some config files<br></div><div><br></div><div dir="ltr"><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Aug 18, 2020 at 1:00 AM Laine Stump <<a href="mailto:laine@redhat.com">laine@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 8/8/20 11:53 PM, Daniel Black wrote:<br>
> <br>
> In attempting to isolate vfio-pci problems between two different guest <br>
> instances, the creation of a second guest (with existing guest shutdown) <br>
> resulted in:.<br>
> <br>
> Aug 09 12:43:23 grit libvirtd[6716]: internal error: Device 0000:01:00.3 <br>
> is already in use<br>
> Aug 09 12:43:23 grit libvirtd[6716]: internal error: Device 0000:01:00.3 <br>
> is already in use<br>
> Aug 09 12:43:23 grit libvirtd[6716]: Failed to allocate PCI device list: <br>
> internal error: Device 0000:01:00.3 is already in use<br>
<br>
Hmm. Normally the error that would be logged if a device is already in <br>
use would say something like this:<br>
<br>
error: Failed to start domain Win10-GPU<br>
error: Requested operation is not valid: PCI device 0000:05:00.0 is in<br>
        use by driver QEMU, domain F30<br>
<br>
So you're encountering this in an unexpected place.<br>
<br>
> <br>
> Compiled against library: libvirt 6.1.0<br>
> Using library: libvirt 6.1.0<br>
> Using API: QEMU 6.1.0<br>
> Running hypervisor: QEMU 4.2.1<br>
> (fc32 default install)<br>
> <br>
> The upstream code seems  also to test definitions rather than active <br>
> uses of the PCI device.<br>
<br>
<br>
That isn't the case. You're misunderstanding what devices are on the <br>
list. (see below for details)<br>
<br>
> <br>
> My potentially naive patch to correct this (but not the failing test <br>
> cases) would be:<br>
> <br>
> diff --git a/src/util/virpci.c b/src/util/virpci.c<br>
> index 47c671daa0..a00c5e6f44 100644<br>
> --- a/src/util/virpci.c<br>
> +++ b/src/util/virpci.c<br>
> @@ -1597,7 +1597,7 @@ int<br>
>   virPCIDeviceListAdd(virPCIDeviceListPtr list,<br>
>                       virPCIDevicePtr dev)<br>
>   {<br>
> -    if (virPCIDeviceListFind(list, dev)) {<br>
> +    if (virPCIDeviceBusContainsActiveDevices(dev, list)) {<br>
>           virReportError(VIR_ERR_INTERNAL_ERROR,<br>
>                          _("Device %s is already in use"), dev->name);<br>
>           return -1;<br>
> <br>
> Is this too simplistic or undesirable a feature request/implementation?<br>
<br>
Only devices that are currently in use by a guest (activePCIHostdevs), <br>
or that libvirt is in the process of detaching from the guest + vfio and <br>
rebinding to the device's host driver (inactivePCIHostdevs) are on <br>
either list of PCI devices maintained by libvirt. Once a device is <br>
completely detached from the guest and (if "managed='yes'" was set in <br>
the XML config) re-binded to the natural host driver for the device, it <br>
is removed from the list and can be used elsewhere.<br>
<br>
I just tested this with an assigned GPU + soundcard on two guests to <br>
verify that it works properly. (I'm running the latest upstream master <br>
though, so it's not an exact replication of your test)<br>
<br>
<br>
> <br>
> I'd be more than grateful if someone carries this through as I'm unsure <br>
> when I may get time for this.<br>
<br>
<br>
Can you provide the XML for your <hostdev> in the two guests, and the <br>
exact sequence of commands that lead to this error? There is definitely <br>
either a bug in the code, or a bug in what you're doing. By seeing the <br>
sequence of events, we can either attempt to replicate it, or let you <br>
know what change you need to make to your workflow to eliminate the error.<br>
<br>
</blockquote></div></div>