From: Konrad Rzeszutek Wilk Subject: Re: xl/SR-IOV: disposition of VFs when PF disappears? Date: Tue, 28 Oct 2014 12:56:40 -0400 Message-ID: <20141028165640.GB26801@laptop.dumpdata.com> References: <544E4A4E020000780004267D@mail.emea.novell.com> <1414414666.23883.13.camel@eu.citrix.com> <20141027133534.GC4050@laptop.dumpdata.com> <20141027180723.GD12989@laptop.dumpdata.com> <544F7D310200007800042BC2@mail.emea.novell.com> <20141028140029.GC21290@laptop.dumpdata.com> <544FC1EA0200007800042CF7@mail.emea.novell.com> <544FD17C0200007800042D5B@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XjA4o-0003dG-1G for xen-devel@lists.xenproject.org; Tue, 28 Oct 2014 16:56:58 +0000 Content-Disposition: inline In-Reply-To: <544FD17C0200007800042D5B@mail.emea.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Jan Beulich Cc: Wei Liu , Stefano Stabellini , "ian.jackson@eu.citrix.com" , Ian Campbell , xen-devel , Anirban Chakraborty List-Id: xen-devel@lists.xenproject.org On Tue, Oct 28, 2014 at 04:25:16PM +0000, Jan Beulich wrote: > >>> On 28.10.14 at 16:18, wrote: > > That flag doesn't inhibit the PF driver unloading. It only suppresses > > it freeing the VFs in that process (and afaics nothing will ever allow > > them to be released subsequently in that case). I'm about to test a > > change to pciback (it's building right now). > > Attached a raw patch for you or anyone else to comment on from > a conceptual perspective. The main thing probably is to determine > whether any further serialization needs to be added. > > Jan > > --- sle12.orig/drivers/xen/xen-pciback/pci_stub.c > +++ sle12/drivers/xen/xen-pciback/pci_stub.c > @@ -1502,6 +1502,44 @@ parse_error: > fs_initcall(pcistub_init); > #endif > > +#ifdef CONFIG_PCI_IOV > +static int pci_stub_notifier(struct notifier_block *nb, > + unsigned long action, void *data) > +{ > + struct device *dev = data; > + struct pci_dev *pdev = to_pci_dev(dev); > + > + switch (action) { > + case BUS_NOTIFY_UNBIND_DRIVER: > + for (;;) { > + struct pcistub_device *psdev; > + unsigned long flags; > + bool found = false; > + > + spin_lock_irqsave(&pcistub_devices_lock, flags); > + > + list_for_each_entry(psdev, &pcistub_devices, dev_list) > + if (!psdev->pdev && psdev->dev != pdev > + && pci_physfn(psdev->dev) == pdev) { > + found = true; > + break; > + } > + spin_unlock_irqrestore(&pcistub_devices_lock, flags); There are existing functions in the PCI back driver to find an device based on the 'struct pci_dev'. That should make this piece of code much simpler by just looking for it and if found call the 'device_release_driver'. However I am not entirely sure what ought to be done if the VF is in _use_ ? Should we still do it? > + if (!found) > + break; > + device_release_driver(&psdev->dev->dev); > + } > + break; > + } > + > + return NOTIFY_DONE; > +} > + > +static struct notifier_block pci_stub_nb = { > + .notifier_call = pci_stub_notifier, > +}; > +#endif > + > static int __init xen_pcibk_init(void) > { > int err; > @@ -1523,6 +1561,10 @@ static int __init xen_pcibk_init(void) > err = xen_pcibk_xenbus_register(); > if (err) > pcistub_exit(); > +#ifdef CONFIG_PCI_IOV > + else > + bus_register_notifier(&pci_bus_type, &pci_stub_nb); > +#endif > > return err; > }