linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PCI: decline to resize resources if boot config must be preserved
@ 2021-01-09  9:53 Ard Biesheuvel
  2021-01-12 22:49 ` Bjorn Helgaas
  0 siblings, 1 reply; 3+ messages in thread
From: Ard Biesheuvel @ 2021-01-09  9:53 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-pci, bhelgaas, lorenzo.pieralisi, benh, Ard Biesheuvel

The _DSM #5 method in the ACPI host bridge object tells us whether the
OS is permitted to deviate from the resource assignment configured by
the firmware. If this is not the case, we should not permit drivers to
resize BARs on the fly. So make pci_resize_resource() take this into
account.

Cc: <stable@vger.kernel.org> # v5.4+
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 drivers/pci/setup-res.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index 43eda101fcf4..3b38be081e93 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -410,10 +410,16 @@ EXPORT_SYMBOL(pci_release_resource);
 int pci_resize_resource(struct pci_dev *dev, int resno, int size)
 {
 	struct resource *res = dev->resource + resno;
+	struct pci_host_bridge *host;
 	int old, ret;
 	u32 sizes;
 	u16 cmd;
 
+	/* Check if we must preserve the firmware's resource assignment */
+	host = pci_find_host_bridge(dev->bus);
+	if (host->preserve_config)
+		return -ENOTSUPP;
+
 	/* Make sure the resource isn't assigned before resizing it. */
 	if (!(res->flags & IORESOURCE_UNSET))
 		return -EBUSY;
-- 
2.17.1


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

* Re: [PATCH] PCI: decline to resize resources if boot config must be preserved
  2021-01-09  9:53 [PATCH] PCI: decline to resize resources if boot config must be preserved Ard Biesheuvel
@ 2021-01-12 22:49 ` Bjorn Helgaas
  2021-01-13  9:55   ` Ard Biesheuvel
  0 siblings, 1 reply; 3+ messages in thread
From: Bjorn Helgaas @ 2021-01-12 22:49 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: linux-kernel, linux-pci, bhelgaas, lorenzo.pieralisi, benh

On Sat, Jan 09, 2021 at 10:53:53AM +0100, Ard Biesheuvel wrote:
> The _DSM #5 method in the ACPI host bridge object tells us whether the
> OS is permitted to deviate from the resource assignment configured by
> the firmware. If this is not the case, we should not permit drivers to
> resize BARs on the fly. So make pci_resize_resource() take this into
> account.
> 
> Cc: <stable@vger.kernel.org> # v5.4+
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>

Capitalized subject to match convention and applied to pci/resource
for v5.11, thanks!

Is there an email, bug report, etc that prompted this change?

> ---
>  drivers/pci/setup-res.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
> index 43eda101fcf4..3b38be081e93 100644
> --- a/drivers/pci/setup-res.c
> +++ b/drivers/pci/setup-res.c
> @@ -410,10 +410,16 @@ EXPORT_SYMBOL(pci_release_resource);
>  int pci_resize_resource(struct pci_dev *dev, int resno, int size)
>  {
>  	struct resource *res = dev->resource + resno;
> +	struct pci_host_bridge *host;
>  	int old, ret;
>  	u32 sizes;
>  	u16 cmd;
>  
> +	/* Check if we must preserve the firmware's resource assignment */
> +	host = pci_find_host_bridge(dev->bus);
> +	if (host->preserve_config)
> +		return -ENOTSUPP;
> +
>  	/* Make sure the resource isn't assigned before resizing it. */
>  	if (!(res->flags & IORESOURCE_UNSET))
>  		return -EBUSY;
> -- 
> 2.17.1
> 

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

* Re: [PATCH] PCI: decline to resize resources if boot config must be preserved
  2021-01-12 22:49 ` Bjorn Helgaas
@ 2021-01-13  9:55   ` Ard Biesheuvel
  0 siblings, 0 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2021-01-13  9:55 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Linux Kernel Mailing List, PCI, Bjorn Helgaas, Lorenzo Pieralisi,
	Benjamin Herrenschmidt

On Tue, 12 Jan 2021 at 23:49, Bjorn Helgaas <helgaas@kernel.org> wrote:
>
> On Sat, Jan 09, 2021 at 10:53:53AM +0100, Ard Biesheuvel wrote:
> > The _DSM #5 method in the ACPI host bridge object tells us whether the
> > OS is permitted to deviate from the resource assignment configured by
> > the firmware. If this is not the case, we should not permit drivers to
> > resize BARs on the fly. So make pci_resize_resource() take this into
> > account.
> >
> > Cc: <stable@vger.kernel.org> # v5.4+
> > Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
>
> Capitalized subject to match convention and applied to pci/resource
> for v5.11, thanks!
>
> Is there an email, bug report, etc that prompted this change?
>

No, I was just reviewing the recent Tianocore changes to perform BAR
resizing before resource assignment even takes places, which is
obviously a more appropriate time to do it, as it does not require the
OS to modify the firmware configuration at all. This reminded me of
_DSM #5 and the fact that the OS may not even be permitted to make any
changes.


> > ---
> >  drivers/pci/setup-res.c | 6 ++++++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
> > index 43eda101fcf4..3b38be081e93 100644
> > --- a/drivers/pci/setup-res.c
> > +++ b/drivers/pci/setup-res.c
> > @@ -410,10 +410,16 @@ EXPORT_SYMBOL(pci_release_resource);
> >  int pci_resize_resource(struct pci_dev *dev, int resno, int size)
> >  {
> >       struct resource *res = dev->resource + resno;
> > +     struct pci_host_bridge *host;
> >       int old, ret;
> >       u32 sizes;
> >       u16 cmd;
> >
> > +     /* Check if we must preserve the firmware's resource assignment */
> > +     host = pci_find_host_bridge(dev->bus);
> > +     if (host->preserve_config)
> > +             return -ENOTSUPP;
> > +
> >       /* Make sure the resource isn't assigned before resizing it. */
> >       if (!(res->flags & IORESOURCE_UNSET))
> >               return -EBUSY;
> > --
> > 2.17.1
> >

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

end of thread, other threads:[~2021-01-13  9:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-09  9:53 [PATCH] PCI: decline to resize resources if boot config must be preserved Ard Biesheuvel
2021-01-12 22:49 ` Bjorn Helgaas
2021-01-13  9:55   ` Ard Biesheuvel

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).