Skip to contentSkip to conversation

pcie_portdriver: FIX: pcie_port_device_remove

PATCH In review Eric W. Biederman 4 participants 10 messages Feb 14, 2009 – Feb 25, 2009 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pcie_portdriver: FIX: pcie_port_device_remove

pcie_port_device_remove currently calls the remove method of port drivers twice. Ouch!

We don't get the correct interrupt mode unless there is a port device present.

We are calling device_for_each_child multiple times for no apparent reason.

So make it simple. Use pcie_port_driver_ext so we always properly know the interrupt mode the we placed the pci device in. Place put_device and device_unregister into remove_iter, and throw out the rest. Only call device_for_each_child once.

The code is simpler and actually works!

---
 drivers/pci/pcie/portdrv_core.c |   31 +++++++------------------------
 1 files changed, 7 insertions(+), 24 deletions(-)
drivers/pci/pcie/portdrv_core.c +7 -24
index 8b3f8c1..c642828 100644
@@ -326,16 +326,9 @@ int pcie_port_device_resume(struct pci_dev *dev)
 
 static int remove_iter(struct device *dev, void *data)
 {
-	struct pcie_port_service_driver *service_driver;
-
 	if (dev->bus == &pcie_port_bus_type) {
-		if (dev->driver) {
-			service_driver = to_service_driver(dev->driver);
-			if (service_driver->remove)
-				service_driver->remove(to_pcie_device(dev));
-		}
-		*(unsigned long*)data = (unsigned long)dev;
-		return 1;
+		put_device(dev);
+		device_unregister(dev);
 	}
 	return 0;
 }
@@ -349,24 +342,14 @@ static int remove_iter(struct device *dev, void *data)
  */
 void pcie_port_device_remove(struct pci_dev *dev)
 {
-	struct device *device;
-	unsigned long device_addr;
-	int interrupt_mode = PCIE_PORT_INTx_MODE;
-	int status;
+	struct pcie_port_device_ext *p_ext = pci_get_drvdata(dev);
+
+	device_for_each_child(&dev->dev, NULL, remove_iter);
 
-	do {
-		status = device_for_each_child(&dev->dev, &device_addr, remove_iter);
-		if (status) {
-			device = (struct device*)device_addr;
-			interrupt_mode = (to_pcie_device(device))->interrupt_mode;
-			put_device(device);
-			device_unregister(device);
-		}
-	} while (status);
 	/* Switch to INTx by default if MSI enabled */
-	if (interrupt_mode == PCIE_PORT_MSIX_MODE)
+	if (p_ext->interrupt_mode == PCIE_PORT_MSIX_MODE)
 		pci_disable_msix(dev);
-	else if (interrupt_mode == PCIE_PORT_MSI_MODE)
+	else if (p_ext->interrupt_mode == PCIE_PORT_MSI_MODE)
 		pci_disable_msi(dev);
 }
 
Signature · 1 line
1.6.0.6
#1 lore raw
Quoted 10 lines · On Fri, 13 Feb 2009 20:23:03 -0800 [email protected] (Eric W. Biederman)…

pcie_port_device_remove currently calls the remove method of port drivers twice. Ouch!

We don't get the correct interrupt mode unless there is a port device present.

We are calling device_for_each_child multiple times for no apparent reason.

Quoted 7 lines

So make it simple. Use pcie_port_driver_ext so we always properly know the interrupt mode the we placed the pci device in. Place put_device and device_unregister into remove_iter, and throw out the rest. Only call device_for_each_child once.

The code is simpler and actually works!

What's happening with this?

Quoted 48 lines
---
 drivers/pci/pcie/portdrv_core.c |   31 +++++++------------------------
 1 files changed, 7 insertions(+), 24 deletions(-)
drivers/pci/pcie/portdrv_core.c +5 -21
index 8b3f8c1..c642828 100644
@@ -326,16 +326,9 @@ int pcie_port_device_resume(struct pci_dev *dev)
 
 static int remove_iter(struct device *dev, void *data)
 {
-	struct pcie_port_service_driver *service_driver;
-
 	if (dev->bus == &pcie_port_bus_type) {
-		if (dev->driver) {
-			service_driver = to_service_driver(dev->driver);
-			if (service_driver->remove)
-				service_driver->remove(to_pcie_device(dev));
-		}
-		*(unsigned long*)data = (unsigned long)dev;
-		return 1;
+		put_device(dev);
+		device_unregister(dev);
 	}
 	return 0;
 }
@@ -349,24 +342,14 @@ static int remove_iter(struct device *dev, void *data)
  */
 void pcie_port_device_remove(struct pci_dev *dev)
 {
-	struct device *device;
-	unsigned long device_addr;
-	int interrupt_mode = PCIE_PORT_INTx_MODE;
-	int status;
+	struct pcie_port_device_ext *p_ext = pci_get_drvdata(dev);
+
+	device_for_each_child(&dev->dev, NULL, remove_iter);
 
-	do {
-		status = device_for_each_child(&dev->dev, &device_addr, remove_iter);
-		if (status) {
-			device = (struct device*)device_addr;
-			interrupt_mode = (to_pcie_device(device))->interrupt_mode;
-			put_device(device);
-			device_unregister(device);
-		}

drivers/pci/pcie/portdrv_core.c static int remove_iter(struct device *dev, void *data) · line 355

Quoted 10 lines
drivers/pci/pcie/portdrv_core.c +2 -3
-	} while (status);
 	/* Switch to INTx by default if MSI enabled */
-	if (interrupt_mode == PCIE_PORT_MSIX_MODE)
+	if (p_ext->interrupt_mode == PCIE_PORT_MSIX_MODE)
 		pci_disable_msix(dev);
-	else if (interrupt_mode == PCIE_PORT_MSI_MODE)
+	else if (p_ext->interrupt_mode == PCIE_PORT_MSI_MODE)
 		pci_disable_msi(dev);
 }
 

There are large-scale and conflicting changes to this file in linux-next.

If we want to jam this fix into 2.6.29 (and it looks like something we want) then this will trash the linux-next changes. It will cause me grief, and will cause Stephen grief unless the pci tree is suitably changed, which will cause Jesse grief. Either way: grief.

#2 lore raw
Quoted 7 lines · Andrew Morton

There are large-scale and conflicting changes to this file in linux-next.

If we want to jam this fix into 2.6.29 (and it looks like something we want) then this will trash the linux-next changes. It will cause me grief, and will cause Stephen grief unless the pci tree is suitably changed, which will cause Jesse grief. Either way: grief.

Ugh.

I had better have a good hard look at linux-next. I tried to ask earlier about ongoing working but I didn't hear anything.

Eric

#3 lore raw
Quoted 10 lines · Eric W. Biederman
Quoted 7 lines · Andrew Morton

There are large-scale and conflicting changes to this file in linux-next.

If we want to jam this fix into 2.6.29 (and it looks like something we want) then this will trash the linux-next changes. It will cause me grief, and will cause Stephen grief unless the pci tree is suitably changed, which will cause Jesse grief. Either way: grief.

Quoted 4 lines

Ugh.

I had better have a good hard look at linux-next. I tried to ask earlier about ongoing working but I didn't hear anything.

Yes, you did: http://marc.info/?l=linux-kernel&m=123342565225134&w=4

Thanks,
Rafael

#4 lore raw
Quoted 11 lines · Rafael J. Wysocki
Quoted 10 lines · Eric W. Biederman
Quoted 7 lines · Andrew Morton

There are large-scale and conflicting changes to this file in linux-next.

If we want to jam this fix into 2.6.29 (and it looks like something we want) then this will trash the linux-next changes. It will cause me grief, and will cause Stephen grief unless the pci tree is suitably changed, which will cause Jesse grief. Either way: grief.

Quoted 7 lines
Quoted 3 lines

Ugh.

I had better have a good hard look at linux-next. I tried to ask earlier

about

Quoted 1 line

ongoing working but I didn't hear anything.

Yes, you did: http://marc.info/?l=linux-kernel&m=123342565225134&w=4

My apologies. I should have said I did not recognize anything that was likely to conflict from what I hear from what I heard. I did hear that the pcie port driver was touched to properly handle msi-x and I foolishly thought that was already merged upstream. Especially after I glanced at Jesse's tree and I did not see any recent pci patches. Which led me to foolishly assume everything had already been merged into Linus's tree.

Andrew with respect to 2.6.29 my patch while correct and useful has no immediate utility, as the pciehp driver will crash and burn horribly if you attempt to hotplug it. So I should find the other pci port driver changes and rebase on top of them. Assuming that patch is scheduled to merge for 2.6.30.

Eric

#5 lore raw
Quoted 30 lines · On Thursday 19 February 2009 15:30:39 Eric W. Biederman wrote:
Quoted 12 lines · Rafael J. Wysocki
Quoted 11 lines · Eric W. Biederman
Quoted 7 lines · Andrew Morton

There are large-scale and conflicting changes to this file in linux-next.

If we want to jam this fix into 2.6.29 (and it looks like something we want) then this will trash the linux-next changes. It will cause me grief, and will cause Stephen grief unless the pci tree is suitably changed, which will cause Jesse grief. Either way: grief.

Ugh.

Quoted 8 lines
Quoted 2 lines

I had better have a good hard look at linux-next. I tried to ask earlier

about

Quoted 1 line

ongoing working but I didn't hear anything.

Yes, you did: http://marc.info/?l=linux-kernel&m=123342565225134&w=4

My apologies. I should have said I did not recognize anything that was likely to conflict from what I hear from what I heard. I did hear that the pcie port driver was touched to properly handle msi-x and I foolishly thought that was already merged upstream. Especially after I glanced at Jesse's tree and I did not see any recent pci patches. Which led me to foolishly assume everything had already been merged into Linus's tree.

Quoted 5 lines

Andrew with respect to 2.6.29 my patch while correct and useful has no immediate utility, as the pciehp driver will crash and burn horribly if you attempt to hotplug it. So I should find the other pci port driver changes and rebase on top of them. Assuming that patch is scheduled to merge for 2.6.30.

Yeah, if it's in my -next tree, it's scheduled for .30. I have one other hotplug related set from Kenji-san for .29 as well (to fix a regression James reported). Search for "fix wrong assumption" to check that one out.

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
#6 lore raw
In reply to Eric W. Biederman
Quoted 15 lines · Eric W. Biederman
Quoted 13 lines · Rafael J. Wysocki
Quoted 12 lines · Eric W. Biederman
Quoted 7 lines · Andrew Morton

There are large-scale and conflicting changes to this file in linux-next.

If we want to jam this fix into 2.6.29 (and it looks like something we want) then this will trash the linux-next changes. It will cause me grief, and will cause Stephen grief unless the pci tree is suitably changed, which will cause Jesse grief. Either way: grief.

Ugh.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

I had better have a good hard look at linux-next. I tried to ask earlier

about

Quoted 1 line

ongoing working but I didn't hear anything.

Yes, you did: http://marc.info/?l=linux-kernel&m=123342565225134&w=4

My apologies.

No problem. :-)

Rafael

#7 lore raw

PATCH 1/1 pcie_portdriver: FIX: pcie_port_device_remove (take 2)

pcie_port_device_remove currently calls the remove method of port drivers twice. Ouch!

We are calling device_for_each_child multiple times for no apparent reason.

So make it simple. Place put_device and device_unregister into remove_iter, and throw out the rest. Only call device_for_each_child once.

The code is simpler and actually works!

Changelog:
v2 rebase against the linux-next tree so I don't conflict with Rafael's
irq work, and remove the irq handling cleanups as Rafael's patch already made them.

---

 drivers/pci/pcie/portdrv_core.c |   23 +++--------------------
 1 files changed, 3 insertions(+), 20 deletions(-)
drivers/pci/pcie/portdrv_core.c +3 -20
index 3aea92a..569af00 100644
@@ -456,16 +456,9 @@ int pcie_port_device_resume(struct pci_dev *dev)
 
 static int remove_iter(struct device *dev, void *data)
 {
-	struct pcie_port_service_driver *service_driver;
-
 	if (dev->bus == &pcie_port_bus_type) {
-		if (dev->driver) {
-			service_driver = to_service_driver(dev->driver);
-			if (service_driver->remove)
-				service_driver->remove(to_pcie_device(dev));
-		}
-		*(unsigned long*)data = (unsigned long)dev;
-		return 1;
+		put_device(dev);
+		device_unregister(dev);
 	}
 	return 0;
 }
@@ -480,18 +473,8 @@ static int remove_iter(struct device *dev, void *data)
 void pcie_port_device_remove(struct pci_dev *dev)
 {
 	struct pcie_port_data *port_data = pci_get_drvdata(dev);
-	int status;
-
-	do {
-		unsigned long device_addr;
 
-		status = device_for_each_child(&dev->dev, &device_addr, remove_iter);
-		if (status) {
-			struct device *device = (struct device*)device_addr;
-			put_device(device);
-			device_unregister(device);
-		}
-	} while (status);
+	device_for_each_child(&dev->dev, NULL, remove_iter);
 
 	switch (port_data->port_irq_mode) {
 	case PCIE_PORT_MSIX_MODE:
Signature · 1 line
1.6.0.6
#8 lore raw

Re: [PATCH] pcie_portdriver: FIX: pcie_port_device_remove (take 2)

Quoted 10 lines · Eric W. Biederman

pcie_port_device_remove currently calls the remove method of port drivers twice. Ouch!

We are calling device_for_each_child multiple times for no apparent reason.

So make it simple. Place put_device and device_unregister into remove_iter, and throw out the rest. Only call device_for_each_child once.

Quoted 6 lines

The code is simpler and actually works!

Changelog:
v2 rebase against the linux-next tree so I don't conflict with Rafael's
irq work, and remove the irq handling cleanups as Rafael's patch already made them.

Thanks for rebasing; it's queued up in my linux-next branch now. If we really need this in the stable kernel it'll be a bit painful, since some of these structures have changed around a bit...

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
#9 lore raw

Re: [PATCH] pcie_portdriver: FIX: pcie_port_device_remove (take 2)

Quoted 13 lines · Jesse Barnes
Quoted 12 lines · Eric W. Biederman

pcie_port_device_remove currently calls the remove method of port drivers twice. Ouch!

We are calling device_for_each_child multiple times for no apparent reason.

So make it simple. Place put_device and device_unregister into remove_iter, and throw out the rest. Only call device_for_each_child once.

The code is simpler and actually works!

Quoted 8 lines
Quoted 4 lines

Changelog:
v2 rebase against the linux-next tree so I don't conflict with Rafael's
irq work, and remove the irq handling cleanups as Rafael's patch already made them.

Thanks for rebasing; it's queued up in my linux-next branch now. If we really need this in the stable kernel it'll be a bit painful, since some of these structures have changed around a bit...

I don't think it is necessary for stable. The pciehp still needs more work, and if anyone of the other port drivers was being hotplugged I expect someone would have noticed the bug and fixed it before now.

Eric