linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 2/3] PCI: Separate stop and remove devices in pciehp
@ 2013-07-27 15:11 Yinghai Lu
  2013-07-27 15:11 ` [PATCH v2 3/3] PCI: Stop sriov after stop PF if PF's driver skip that Yinghai Lu
                   ` (2 more replies)
  0 siblings, 3 replies; 25+ messages in thread
From: Yinghai Lu @ 2013-07-27 15:11 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci, Yinghai Lu, Yijing Wang, Jiang Liu

commit dc087f2f6a2925e81831f3016b9cbb6e470e7423
(PCI: Simplify IOV implementation and fix reference count races)
broke the pcie native hotplug with SRIOV enabled: PF is not freed
during hot-remove, and later hot-add do not work as old pci_dev
is still around, and can not create new pci_dev.

That commit need VFs to be removed via pci_disable_sriov/virtfn_remove
to make sure ref to PF is put back.

So we can not call stop_and_remove for VF before PF, that will
make VF get removed directly before PF's driver try to use
pci_disable_sriov/virtfn_remove to do it.

Solution is separating stop and remove in two iterations.

In first iteration, we stop VF driver at first with iterating devices
reversely, and later during stop PF driver, disable_sriov will use
virtfn_remove to remove VFs.

Also some driver (like mlx4_core) need VF's driver get stopped before PF's.

Need this one for v3.11.

-v2: separate VGA checking to another patch according to Bjorn.
     and after patches that make pciehp to be built-in

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Yijing Wang <wangyijing@huawei.com>
Cc: Jiang Liu <liuj97@gmail.com>

---
 drivers/pci/hotplug/pciehp_pci.c |   15 +++++++++++++--
 drivers/pci/pci.h                |    3 +++
 drivers/pci/remove.c             |    4 ++--
 3 files changed, 18 insertions(+), 4 deletions(-)

Index: linux-2.6/drivers/pci/hotplug/pciehp_pci.c
===================================================================
--- linux-2.6.orig/drivers/pci/hotplug/pciehp_pci.c
+++ linux-2.6/drivers/pci/hotplug/pciehp_pci.c
@@ -109,6 +109,13 @@ int pciehp_unconfigure_device(struct slo
 	}
 
 	/*
+	 * Now VF need to be removed via virtfn_remove to make
+	 * sure ref to PF is put back. Some driver (mlx4_core) need
+	 * VF's driver get stopped before PF.
+	 * So we need to stop VF driver at first, that means
+	 * loop reversely, and later during stop PF driver,
+	 * disable_sriov will use virtfn_remove to remove VFs.
+	 *
 	 * Stopping an SR-IOV PF device removes all the associated VFs,
 	 * which will update the bus->devices list and confuse the
 	 * iterator.  Therefore, iterate in reverse so we remove the VFs
@@ -116,8 +123,7 @@ int pciehp_unconfigure_device(struct slo
 	 */
 	list_for_each_entry_safe_reverse(dev, temp, &parent->devices,
 					 bus_list) {
-		pci_dev_get(dev);
-		pci_stop_and_remove_bus_device(dev);
+		pci_stop_bus_device(dev);
 		/*
 		 * Ensure that no new Requests will be generated from
 		 * the device.
@@ -128,6 +134,11 @@ int pciehp_unconfigure_device(struct slo
 			command |= PCI_COMMAND_INTX_DISABLE;
 			pci_write_config_word(dev, PCI_COMMAND, command);
 		}
+	}
+
+	list_for_each_entry_safe(dev, temp, &parent->devices, bus_list) {
+		pci_dev_get(dev);
+		pci_remove_bus_device(dev);
 		pci_dev_put(dev);
 	}
 
Index: linux-2.6/drivers/pci/remove.c
===================================================================
--- linux-2.6.orig/drivers/pci/remove.c
+++ linux-2.6/drivers/pci/remove.c
@@ -56,7 +56,7 @@ void pci_remove_bus(struct pci_bus *bus)
 }
 EXPORT_SYMBOL(pci_remove_bus);
 
-static void pci_stop_bus_device(struct pci_dev *dev)
+void pci_stop_bus_device(struct pci_dev *dev)
 {
 	struct pci_bus *bus = dev->subordinate;
 	struct pci_dev *child, *tmp;
@@ -76,7 +76,7 @@ static void pci_stop_bus_device(struct p
 	pci_stop_dev(dev);
 }
 
-static void pci_remove_bus_device(struct pci_dev *dev)
+void pci_remove_bus_device(struct pci_dev *dev)
 {
 	struct pci_bus *bus = dev->subordinate;
 	struct pci_dev *child, *tmp;
Index: linux-2.6/drivers/pci/pci.h
===================================================================
--- linux-2.6.orig/drivers/pci/pci.h
+++ linux-2.6/drivers/pci/pci.h
@@ -317,4 +317,7 @@ static inline int pci_dev_specific_reset
 }
 #endif
 
+void pci_stop_bus_device(struct pci_dev *dev);
+void pci_remove_bus_device(struct pci_dev *dev);
+
 #endif /* DRIVERS_PCI_H */

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2013-08-14 20:58 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-27 15:11 [PATCH v2 2/3] PCI: Separate stop and remove devices in pciehp Yinghai Lu
2013-07-27 15:11 ` [PATCH v2 3/3] PCI: Stop sriov after stop PF if PF's driver skip that Yinghai Lu
2013-07-29 19:58   ` Bjorn Helgaas
2013-07-29 20:32     ` Don Dutile
2013-07-29 21:07       ` Alexander Duyck
2013-07-29 21:31         ` Don Dutile
2013-07-29 21:52           ` Jeff Kirsher
2013-07-29 23:14             ` Yinghai Lu
2013-07-29 23:23               ` Jeff Kirsher
2013-07-30 15:04                 ` Don Dutile
2013-08-01 20:16       ` Bjorn Helgaas
2013-08-01 21:21         ` Don Dutile
2013-08-01 21:41           ` Bjorn Helgaas
2013-08-01 21:55           ` Alexander Duyck
2013-07-27 15:11 ` [PATCH v2 1/3] PCI/pciehp: Separate VGA checking out from loop Yinghai Lu
2013-08-07  4:01 ` [PATCH v2 2/3] PCI: Separate stop and remove devices in pciehp Bjorn Helgaas
2013-08-07  6:34   ` Yinghai Lu
2013-08-08  1:49     ` Yinghai Lu
2013-08-08  1:54       ` Yinghai Lu
2013-08-09 17:04       ` Bjorn Helgaas
2013-08-09 23:44         ` Yinghai Lu
2013-08-14 19:44           ` Bjorn Helgaas
2013-08-14 20:15             ` Yinghai Lu
2013-08-14 20:36               ` Bjorn Helgaas
2013-08-14 20:58                 ` Yinghai Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).