From patchwork Tue Dec 2 15:05:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Rzeszutek Wilk X-Patchwork-Id: 416893 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id EF3E91402BA for ; Wed, 3 Dec 2014 02:05:41 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932329AbaLBPFk (ORCPT ); Tue, 2 Dec 2014 10:05:40 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:48105 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932111AbaLBPFj (ORCPT ); Tue, 2 Dec 2014 10:05:39 -0500 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id sB2F5GEH032236 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 2 Dec 2014 15:05:16 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by ucsinet22.oracle.com (8.14.5+Sun/8.14.5) with ESMTP id sB2F5EVw001465 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Tue, 2 Dec 2014 15:05:15 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id sB2F5ERK017906; Tue, 2 Dec 2014 15:05:14 GMT Received: from laptop.dumpdata.com (/10.154.122.207) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 02 Dec 2014 07:05:14 -0800 Received: by laptop.dumpdata.com (Postfix, from userid 1000) id 8BE1411ADE2; Tue, 2 Dec 2014 10:05:14 -0500 (EST) Date: Tue, 2 Dec 2014 10:05:14 -0500 From: Konrad Rzeszutek Wilk To: Jan Beulich Cc: linux@eikelenboom.it, bhelgaas@google.com, xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Subject: Re: [Xen-devel] [PATCH v4] Fixes for PCI backend for 3.19 Message-ID: <20141202150514.GC27869@laptop.dumpdata.com> References: <1416608271-18931-1-git-send-email-konrad.wilk@oracle.com> <547D9E13020000780004C0B3@mail.emea.novell.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <547D9E13020000780004C0B3@mail.emea.novell.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Source-IP: ucsinet22.oracle.com [156.151.31.94] Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On Tue, Dec 02, 2014 at 10:10:11AM +0000, Jan Beulich wrote: > >>> On 21.11.14 at 23:17, wrote: > > Konrad Rzeszutek Wilk (7): > > xen/pciback: Don't deadlock when unbinding. > > driver core: Provide an wrapper around the mutex to do lockdep warnings > > xen/pciback: Include the domain id if removing the device whilst still in use > > xen/pciback: Print out the domain owning the device. > > xen/pciback: Remove tons of dereferences > > PCI: Expose pci_load_saved_state for public consumption. > > xen/pciback: Restore configuration space when detaching from a guest. > > So my "xen-pciback: drop SR-IOV VFs when PF driver unloads" isn't > among them, nor is there any alternative. What's the status of that > patch (or the problem that prompted its creation)? Oh, I've it in my queue. Um, here is what I did to it - I hadn't yet tested it - hence the reason it is not on that list. From 82ad7b4cc73f2f9a9cfd6805cff996fd5009a31f Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Thu, 6 Nov 2014 15:05:51 +0000 Subject: [PATCH 1/2] xen-pciback: drop SR-IOV VFs when PF driver unloads When a PF driver unloads, it may find it necessary to leave the VFs around simply because of pciback having marked them as assigned to a guest. Utilize a suitable notification to let go of the VFs, thus allowing the PF to go back into the state it was before its driver loaded (which in particular allows the driver to be loaded again with it being able to create the VFs anew, but which also allows to then pass through the PF instead of the VFs). Don't do this however for any VFs currently in active use by a guest. Signed-off-by: Jan Beulich [v2: Removed the switch statement, moved it about] [v3: Redid it a bit differently] Signed-off-by: Konrad Rzeszutek Wilk --- drivers/xen/xen-pciback/pci_stub.c | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/pci_stub.c index eb8b58e..ff27efa 100644 --- a/drivers/xen/xen-pciback/pci_stub.c +++ b/drivers/xen/xen-pciback/pci_stub.c @@ -1518,6 +1518,53 @@ parse_error: fs_initcall(pcistub_init); #endif +#ifdef CONFIG_PCI_IOV +static struct pcistub_device *find_vfs(const struct pci_dev *pdev) +{ + struct pcistub_device *psdev = NULL; + 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); + if (found) + return psdev; + return NULL; +} + +static int pci_stub_notifier(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct device *dev = data; + const struct pci_dev *pdev = to_pci_dev(dev); + + if (action != BUS_NOTIFY_UNBIND_DRIVER) + return NOTIFY_DONE; + + if (!pdev->is_physfn) + return NOTIFY_DONE; + + for (;;) { + struct pcistub_device *psdev = find_vfs(pdev); + if (!psdev) + break; + device_release_driver(&psdev->dev->dev); + } + 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; @@ -1539,12 +1586,19 @@ 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; } static void __exit xen_pcibk_cleanup(void) { +#ifdef CONFIG_PCI_IOV + bus_unregister_notifier(&pci_bus_type, &pci_stub_nb); +#endif xen_pcibk_xenbus_unregister(); pcistub_exit(); }