diff mbox series

[RFC/PATCH] PCI: Protect pci_reassign_bridge_resources() against concurrent addition/removal

Message ID 02ca29627597445442bb14c069678e549429dace.camel@kernel.crashing.org (mailing list archive)
State Accepted, archived
Commit 540f62d26f023a6e9c21aacb10b2f880ab2d896a
Headers show
Series [RFC/PATCH] PCI: Protect pci_reassign_bridge_resources() against concurrent addition/removal | expand

Commit Message

Benjamin Herrenschmidt June 24, 2019, 4:32 a.m. UTC
pci_reassign_bridge_resources() can be called by pci_resize_resource()
at runtime.

It will walk the PCI tree up and down, and isn't currently protected
against any changes or hotplug operation.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---

Comments

Bjorn Helgaas Aug. 21, 2019, 1:08 p.m. UTC | #1
On Mon, Jun 24, 2019 at 02:32:19PM +1000, Benjamin Herrenschmidt wrote:
> pci_reassign_bridge_resources() can be called by pci_resize_resource()
> at runtime.
> 
> It will walk the PCI tree up and down, and isn't currently protected
> against any changes or hotplug operation.
> 
> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

Applied to pci/resource for v5.4, thanks!

> ---
> 
> --- a/drivers/pci/setup-bus.c
> +++ b/drivers/pci/setup-bus.c
> @@ -2104,6 +2104,8 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
>  	unsigned int i;
>  	int ret;
>  
> +	down_read(&pci_bus_sem);
> +
>  	/* Walk to the root hub, releasing bridge BARs when possible */
>  	next = bridge;
>  	do {
> @@ -2160,6 +2162,7 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
>  	}
>  
>  	free_list(&saved);
> +	up_read(&pci_bus_sem);
>  	return 0;
>  
>  cleanup:
> @@ -2188,6 +2191,7 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
>  		pci_setup_bridge(bridge->subordinate);
>  	}
>  	free_list(&saved);
> +	up_read(&pci_bus_sem);
>  
>  	return ret;
>  }
>
Bjorn Helgaas Sept. 23, 2019, 9:50 p.m. UTC | #2
On Wed, Aug 21, 2019 at 08:08:27AM -0500, Bjorn Helgaas wrote:
> On Mon, Jun 24, 2019 at 02:32:19PM +1000, Benjamin Herrenschmidt wrote:
> > pci_reassign_bridge_resources() can be called by pci_resize_resource()
> > at runtime.
> > 
> > It will walk the PCI tree up and down, and isn't currently protected
> > against any changes or hotplug operation.
> > 
> > Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> 
> Applied to pci/resource for v5.4, thanks!

Dropped for now per Dan's bug report:
https://lore.kernel.org/r/20190904100303.GD7007@mwanda

> > ---
> > 
> > --- a/drivers/pci/setup-bus.c
> > +++ b/drivers/pci/setup-bus.c
> > @@ -2104,6 +2104,8 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
> >  	unsigned int i;
> >  	int ret;
> >  
> > +	down_read(&pci_bus_sem);
> > +
> >  	/* Walk to the root hub, releasing bridge BARs when possible */
> >  	next = bridge;
> >  	do {
> > @@ -2160,6 +2162,7 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
> >  	}
> >  
> >  	free_list(&saved);
> > +	up_read(&pci_bus_sem);
> >  	return 0;
> >  
> >  cleanup:
> > @@ -2188,6 +2191,7 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
> >  		pci_setup_bridge(bridge->subordinate);
> >  	}
> >  	free_list(&saved);
> > +	up_read(&pci_bus_sem);
> >  
> >  	return ret;
> >  }
> >
diff mbox series

Patch

--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -2104,6 +2104,8 @@  int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
 	unsigned int i;
 	int ret;
 
+	down_read(&pci_bus_sem);
+
 	/* Walk to the root hub, releasing bridge BARs when possible */
 	next = bridge;
 	do {
@@ -2160,6 +2162,7 @@  int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
 	}
 
 	free_list(&saved);
+	up_read(&pci_bus_sem);
 	return 0;
 
 cleanup:
@@ -2188,6 +2191,7 @@  int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
 		pci_setup_bridge(bridge->subordinate);
 	}
 	free_list(&saved);
+	up_read(&pci_bus_sem);
 
 	return ret;
 }