All of lore.kernel.org
 help / color / mirror / Atom feed
* [bug report] PCI: Protect pci_reassign_bridge_resources() against addition/removal
@ 2019-09-04 10:03 Dan Carpenter
  2019-09-09  8:13 ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2019-09-04 10:03 UTC (permalink / raw)
  To: benh; +Cc: linux-pci

Hello Benjamin Herrenschmidt,

The patch 540f62d26f02: "PCI: Protect pci_reassign_bridge_resources()
against addition/removal" from Jun 24, 2019, leads to the following
static checker warning:

	drivers/pci/setup-bus.c:2158 pci_reassign_bridge_resources()
	warn: inconsistent returns 'read_sem:&pci_bus_sem'.

drivers/pci/setup-bus.c
  2066          unsigned int i;
  2067          int ret;
  2068  
  2069          down_read(&pci_bus_sem);

We added some new locking here.

  2070  
  2071          /* Walk to the root hub, releasing bridge BARs when possible */
  2072          next = bridge;
  2073          do {
  2074                  bridge = next;
  2075                  for (i = PCI_BRIDGE_RESOURCES; i < PCI_BRIDGE_RESOURCE_END;
  2076                       i++) {
  2077                          struct resource *res = &bridge->resource[i];
  2078  
  2079                          if ((res->flags ^ type) & PCI_RES_TYPE_MASK)
  2080                                  continue;
  2081  
  2082                          /* Ignore BARs which are still in use */
  2083                          if (res->child)
  2084                                  continue;
  2085  
  2086                          ret = add_to_list(&saved, bridge, res, 0, 0);
  2087                          if (ret)
  2088                                  goto cleanup;
  2089  
  2090                          pci_info(bridge, "BAR %d: releasing %pR\n",
  2091                                   i, res);
  2092  
  2093                          if (res->parent)
  2094                                  release_resource(res);
  2095                          res->start = 0;
  2096                          res->end = 0;
  2097                          break;
  2098                  }
  2099                  if (i == PCI_BRIDGE_RESOURCE_END)
  2100                          break;
  2101  
  2102                  next = bridge->bus ? bridge->bus->self : NULL;
  2103          } while (next);
  2104  
  2105          if (list_empty(&saved))
  2106                  return -ENOENT;

This needs an unlock.  It's not clear to me if any other clean up is
required, but possibly it's worth looking at.

  2107  
  2108          __pci_bus_size_bridges(bridge->subordinate, &added);
  2109          __pci_bridge_assign_resources(bridge, &added, &failed);

regards,
dan carpenter

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

* Re: [bug report] PCI: Protect pci_reassign_bridge_resources() against addition/removal
  2019-09-04 10:03 [bug report] PCI: Protect pci_reassign_bridge_resources() against addition/removal Dan Carpenter
@ 2019-09-09  8:13 ` Benjamin Herrenschmidt
  2019-09-23 21:50   ` Bjorn Helgaas
  0 siblings, 1 reply; 3+ messages in thread
From: Benjamin Herrenschmidt @ 2019-09-09  8:13 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: linux-pci

On Wed, 2019-09-04 at 13:03 +0300, Dan Carpenter wrote:
> Hello Benjamin Herrenschmidt,
> 
> The patch 540f62d26f02: "PCI: Protect pci_reassign_bridge_resources()
> against addition/removal" from Jun 24, 2019, leads to the following
> static checker warning:
> 
> 	drivers/pci/setup-bus.c:2158 pci_reassign_bridge_resources()
> 	warn: inconsistent returns 'read_sem:&pci_bus_sem'.

Thanks, I missed that. I'll try to send something but from Plumbers
might be difficult...

Cheers
Ben.

> drivers/pci/setup-bus.c
>   2066          unsigned int i;
>   2067          int ret;
>   2068  
>   2069          down_read(&pci_bus_sem);
> 
> We added some new locking here.
> 
>   2070  
>   2071          /* Walk to the root hub, releasing bridge BARs when
> possible */
>   2072          next = bridge;
>   2073          do {
>   2074                  bridge = next;
>   2075                  for (i = PCI_BRIDGE_RESOURCES; i <
> PCI_BRIDGE_RESOURCE_END;
>   2076                       i++) {
>   2077                          struct resource *res = &bridge-
> >resource[i];
>   2078  
>   2079                          if ((res->flags ^ type) &
> PCI_RES_TYPE_MASK)
>   2080                                  continue;
>   2081  
>   2082                          /* Ignore BARs which are still in use
> */
>   2083                          if (res->child)
>   2084                                  continue;
>   2085  
>   2086                          ret = add_to_list(&saved, bridge,
> res, 0, 0);
>   2087                          if (ret)
>   2088                                  goto cleanup;
>   2089  
>   2090                          pci_info(bridge, "BAR %d: releasing
> %pR\n",
>   2091                                   i, res);
>   2092  
>   2093                          if (res->parent)
>   2094                                  release_resource(res);
>   2095                          res->start = 0;
>   2096                          res->end = 0;
>   2097                          break;
>   2098                  }
>   2099                  if (i == PCI_BRIDGE_RESOURCE_END)
>   2100                          break;
>   2101  
>   2102                  next = bridge->bus ? bridge->bus->self :
> NULL;
>   2103          } while (next);
>   2104  
>   2105          if (list_empty(&saved))
>   2106                  return -ENOENT;
> 
> This needs an unlock.  It's not clear to me if any other clean up is
> required, but possibly it's worth looking at.
> 
>   2107  
>   2108          __pci_bus_size_bridges(bridge->subordinate, &added);
>   2109          __pci_bridge_assign_resources(bridge, &added,
> &failed);
> 
> regards,
> dan carpenter


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

* Re: [bug report] PCI: Protect pci_reassign_bridge_resources() against addition/removal
  2019-09-09  8:13 ` Benjamin Herrenschmidt
@ 2019-09-23 21:50   ` Bjorn Helgaas
  0 siblings, 0 replies; 3+ messages in thread
From: Bjorn Helgaas @ 2019-09-23 21:50 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: Dan Carpenter, linux-pci

On Mon, Sep 09, 2019 at 09:13:28AM +0100, Benjamin Herrenschmidt wrote:
> On Wed, 2019-09-04 at 13:03 +0300, Dan Carpenter wrote:
> > Hello Benjamin Herrenschmidt,
> > 
> > The patch 540f62d26f02: "PCI: Protect pci_reassign_bridge_resources()
> > against addition/removal" from Jun 24, 2019, leads to the following
> > static checker warning:
> > 
> > 	drivers/pci/setup-bus.c:2158 pci_reassign_bridge_resources()
> > 	warn: inconsistent returns 'read_sem:&pci_bus_sem'.
> 
> Thanks, I missed that. I'll try to send something but from Plumbers
> might be difficult...

I dropped this for now.

> > drivers/pci/setup-bus.c
> >   2066          unsigned int i;
> >   2067          int ret;
> >   2068  
> >   2069          down_read(&pci_bus_sem);
> > 
> > We added some new locking here.
> > 
> >   2070  
> >   2071          /* Walk to the root hub, releasing bridge BARs when
> > possible */
> >   2072          next = bridge;
> >   2073          do {
> >   2074                  bridge = next;
> >   2075                  for (i = PCI_BRIDGE_RESOURCES; i <
> > PCI_BRIDGE_RESOURCE_END;
> >   2076                       i++) {
> >   2077                          struct resource *res = &bridge-
> > >resource[i];
> >   2078  
> >   2079                          if ((res->flags ^ type) &
> > PCI_RES_TYPE_MASK)
> >   2080                                  continue;
> >   2081  
> >   2082                          /* Ignore BARs which are still in use
> > */
> >   2083                          if (res->child)
> >   2084                                  continue;
> >   2085  
> >   2086                          ret = add_to_list(&saved, bridge,
> > res, 0, 0);
> >   2087                          if (ret)
> >   2088                                  goto cleanup;
> >   2089  
> >   2090                          pci_info(bridge, "BAR %d: releasing
> > %pR\n",
> >   2091                                   i, res);
> >   2092  
> >   2093                          if (res->parent)
> >   2094                                  release_resource(res);
> >   2095                          res->start = 0;
> >   2096                          res->end = 0;
> >   2097                          break;
> >   2098                  }
> >   2099                  if (i == PCI_BRIDGE_RESOURCE_END)
> >   2100                          break;
> >   2101  
> >   2102                  next = bridge->bus ? bridge->bus->self :
> > NULL;
> >   2103          } while (next);
> >   2104  
> >   2105          if (list_empty(&saved))
> >   2106                  return -ENOENT;
> > 
> > This needs an unlock.  It's not clear to me if any other clean up is
> > required, but possibly it's worth looking at.
> > 
> >   2107  
> >   2108          __pci_bus_size_bridges(bridge->subordinate, &added);
> >   2109          __pci_bridge_assign_resources(bridge, &added,
> > &failed);
> > 
> > regards,
> > dan carpenter
> 

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

end of thread, other threads:[~2019-09-23 21:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-04 10:03 [bug report] PCI: Protect pci_reassign_bridge_resources() against addition/removal Dan Carpenter
2019-09-09  8:13 ` Benjamin Herrenschmidt
2019-09-23 21:50   ` Bjorn Helgaas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.