linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Bugfix v5] x86/PCI/ACPI: Fix regression caused by commit 63f1789ec716
  2015-04-13  4:31 [Bugfix v3] " Jiang Liu
@ 2015-04-13  6:38 ` Jiang Liu
  2015-04-13  6:56   ` Ingo Molnar
  0 siblings, 1 reply; 13+ messages in thread
From: Jiang Liu @ 2015-04-13  6:38 UTC (permalink / raw)
  To: Rafael J . Wysocki, Bjorn Helgaas, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, x86, Len Brown
  Cc: Jiang Liu, Lv Zheng, LKML, linux-pci, linux-acpi

Before commit 593669c2ac0f("Use common ACPI resource interfaces to
simplify implementation"), arch/x86/pci/acpi.c applies following
rules when parsing ACPI resources for PCI host bridge:
1) Ignore IO port resources defined by acpi_resource_io and
   acpi_resource_fixed_io, which should be used to define resource
   for PCI device instead of PCI bridge.
2) Accept IOMEM resource defined by acpi_resource_memory24,
   acpi_resource_memory32 and acpi_resource_fixed_memory32.
   These IOMEM resources are accepted to workaround some BIOS issue,
   though they should be ignored. For example, PC Engines APU.1C
   platform defines PCI host bridge IOMEM resources as:
                Memory32Fixed (ReadOnly,
                    0x000A0000,         // Address Base
                    0x00020000,         // Address Length
                    )
                Memory32Fixed (ReadOnly,
                    0x00000000,         // Address Base
                    0x00000000,         // Address Length
                    _Y00)
3) Accept all IO port and IOMEM resources defined by
   acpi_resource_address{16,32,64,extended64}, no matter it's marked as
   ACPI_CONSUMER or ACPI_PRODUCER.

Commit 593669c2ac0f("Use common ACPI resource interfaces to
simplify implementation") accept all IO port and IOMEM resources
defined by acpi_resource_io, acpi_resource_fixed_io,
acpi_resource_memory24, acpi_resource_memory32,
acpi_resource_fixed_memory32 and
acpi_resource_address{16,32,64,extended64}, which causes IO port
resources consumed by host bridge itself are listed in to host bridge
resource list.

Then commit 63f1789ec716("Ignore resources consumed by host bridge
itself") ignores resources consumed by host bridge itself by checking
IORESOURCE_WINDOW flag, which accidently removed the workaround in 2)
above for BIOS bug .

So revert to the behavior before v3.19 to fix the regression.

Sample ACPI table are archived at:
https://bugzilla.kernel.org/show_bug.cgi?id=94221

Fixes: 63f1789ec716("Ignore resources consumed by host bridge itself")
Reported-and-Tested-by: Bernhard Thaler <bernhard.thaler@wvnet.at>
Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com>
---
 arch/x86/pci/acpi.c     |   25 ++++++++++++++++++++++---
 drivers/acpi/resource.c |    6 +++++-
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
index e4695985f9de..fc2da98985c3 100644
--- a/arch/x86/pci/acpi.c
+++ b/arch/x86/pci/acpi.c
@@ -332,12 +332,32 @@ static void probe_pci_root_info(struct pci_root_info *info,
 {
 	int ret;
 	struct resource_entry *entry, *tmp;
+	unsigned long res_flags;
 
 	sprintf(info->name, "PCI Bus %04x:%02x", domain, busnum);
 	info->bridge = device;
+
+	/*
+	 * An IO or MMIO resource assigned to PCI host bridge may be consumed
+	 * by the host bridge itself or available to its child bus/devices.
+	 * On x86 and IA64 platforms, all IO and MMIO resources are assumed to
+	 * be available to child bus/devices except one special case:
+	 *	IO port [0xCF8-0xCFF] is consumed by host bridge itself to
+	 *	access PCI configuration space.
+	 *
+	 * Due to lack of specification to define resources consumed by host
+	 * bridge itself, all IO port resources defined by acpi_resource_io
+	 * and acpi_resource_fixed_io are ignored to filter out IO
+	 * port[0xCF8-0xCFF]. Seems this solution works with all BIOSes, though
+	 * it's not perfect.
+	 *
+	 * Another possible solution is to explicitly filter out IO
+	 * port[0xCF8-0xCFF].
+	 */
+	res_flags = IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_IO_FIXED;
 	ret = acpi_dev_get_resources(device, list,
 				     acpi_dev_filter_resource_type_cb,
-				     (void *)(IORESOURCE_IO | IORESOURCE_MEM));
+				     (void *)res_flags);
 	if (ret < 0)
 		dev_warn(&device->dev,
 			 "failed to parse _CRS method, error code %d\n", ret);
@@ -346,8 +366,7 @@ static void probe_pci_root_info(struct pci_root_info *info,
 			"no IO and memory resources present in _CRS\n");
 	else
 		resource_list_for_each_entry_safe(entry, tmp, list) {
-			if ((entry->res->flags & IORESOURCE_WINDOW) == 0 ||
-			    (entry->res->flags & IORESOURCE_DISABLED))
+			if (entry->res->flags & IORESOURCE_DISABLED)
 				resource_list_destroy_entry(entry);
 			else
 				entry->res->name = info->name;
diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c
index 5589a6e2a023..79b6d3b5ffd2 100644
--- a/drivers/acpi/resource.c
+++ b/drivers/acpi/resource.c
@@ -575,6 +575,9 @@ EXPORT_SYMBOL_GPL(acpi_dev_get_resources);
  *
  * This is a hepler function to support acpi_dev_get_resources(), which filters
  * ACPI resource objects according to resource types.
+ *
+ * Flag IORESOURCE_IO_FIXED is used to opt out io and fixed_io resource
+ * descriptors for ACPI host bridges on x86 and IA64 platforms.
  */
 int acpi_dev_filter_resource_type(struct acpi_resource *ares,
 				  unsigned long types)
@@ -589,7 +592,8 @@ int acpi_dev_filter_resource_type(struct acpi_resource *ares,
 		break;
 	case ACPI_RESOURCE_TYPE_IO:
 	case ACPI_RESOURCE_TYPE_FIXED_IO:
-		type = IORESOURCE_IO;
+		if ((types & IORESOURCE_IO_FIXED) == 0)
+			type = IORESOURCE_IO;
 		break;
 	case ACPI_RESOURCE_TYPE_IRQ:
 	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
-- 
1.7.10.4

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

* Re: [Bugfix v5] x86/PCI/ACPI: Fix regression caused by commit 63f1789ec716
  2015-04-13  6:38 ` [Bugfix v5] " Jiang Liu
@ 2015-04-13  6:56   ` Ingo Molnar
  2015-04-13 12:05     ` Rafael J. Wysocki
  0 siblings, 1 reply; 13+ messages in thread
From: Ingo Molnar @ 2015-04-13  6:56 UTC (permalink / raw)
  To: Jiang Liu
  Cc: Rafael J . Wysocki, Bjorn Helgaas, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, x86, Len Brown, Lv Zheng, LKML, linux-pci,
	linux-acpi


* Jiang Liu <jiang.liu@linux.intel.com> wrote:

> Before commit 593669c2ac0f("Use common ACPI resource interfaces to
> simplify implementation"), arch/x86/pci/acpi.c applies following

s/applies following
 /applied the following

> rules when parsing ACPI resources for PCI host bridge:
> 1) Ignore IO port resources defined by acpi_resource_io and
>    acpi_resource_fixed_io, which should be used to define resource
>    for PCI device instead of PCI bridge.
> 2) Accept IOMEM resource defined by acpi_resource_memory24,
>    acpi_resource_memory32 and acpi_resource_fixed_memory32.
>    These IOMEM resources are accepted to workaround some BIOS issue,

s/workaround
 /work around

It's a verb, not a noun.

>    though they should be ignored. For example, PC Engines APU.1C

Please put the platform name into quotes to make it more clearly stand 
apart from the rest of the text.

>    platform defines PCI host bridge IOMEM resources as:
>                 Memory32Fixed (ReadOnly,
>                     0x000A0000,         // Address Base
>                     0x00020000,         // Address Length
>                     )
>                 Memory32Fixed (ReadOnly,
>                     0x00000000,         // Address Base
>                     0x00000000,         // Address Length
>                     _Y00)
> 3) Accept all IO port and IOMEM resources defined by
>    acpi_resource_address{16,32,64,extended64}, no matter it's marked as
>    ACPI_CONSUMER or ACPI_PRODUCER.

s/no matter it's marked
 /regardless of whether it's marked

> Commit 593669c2ac0f("Use common ACPI resource interfaces to
> simplify implementation") accept all IO port and IOMEM resources

s/accept
 /started accepting

> defined by acpi_resource_io, acpi_resource_fixed_io,
> acpi_resource_memory24, acpi_resource_memory32,
> acpi_resource_fixed_memory32 and
> acpi_resource_address{16,32,64,extended64}, which causes IO port
> resources consumed by host bridge itself are listed in to host bridge
> resource list.

this latter part of the sentence does not parse. Did you want to 
write:

  acpi_resource_address{16,32,64,extended64}, which causes IO port
  resources consumed by the host bridge itself to be listed in the
  host bridge resource list.

?

> Then commit 63f1789ec716("Ignore resources consumed by host bridge
> itself") ignores resources consumed by host bridge itself by checking

s/ignores
 /started ignoring

s/by host bridge
 /by the host bridge

> IORESOURCE_WINDOW flag, which accidently removed the workaround in 2)
> above for BIOS bug .

s/for BIOS bug .
 /for the BIOS bug.

> So revert to the behavior before v3.19 to fix the regression.
> 
> Sample ACPI table are archived at:
> https://bugzilla.kernel.org/show_bug.cgi?id=94221
> 
> Fixes: 63f1789ec716("Ignore resources consumed by host bridge itself")
> Reported-and-Tested-by: Bernhard Thaler <bernhard.thaler@wvnet.at>
> Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com>
> ---
>  arch/x86/pci/acpi.c     |   25 ++++++++++++++++++++++---
>  drivers/acpi/resource.c |    6 +++++-
>  2 files changed, 27 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
> index e4695985f9de..fc2da98985c3 100644
> --- a/arch/x86/pci/acpi.c
> +++ b/arch/x86/pci/acpi.c
> @@ -332,12 +332,32 @@ static void probe_pci_root_info(struct pci_root_info *info,
>  {
>  	int ret;
>  	struct resource_entry *entry, *tmp;
> +	unsigned long res_flags;
>  
>  	sprintf(info->name, "PCI Bus %04x:%02x", domain, busnum);
>  	info->bridge = device;
> +
> +	/*
> +	 * An IO or MMIO resource assigned to PCI host bridge may be consumed

s/to PCI host bridge
 /to a PCI host bridge

> +	 * by the host bridge itself or available to its child bus/devices.
> +	 * On x86 and IA64 platforms, all IO and MMIO resources are assumed to
> +	 * be available to child bus/devices except one special case:
> +	 *	IO port [0xCF8-0xCFF] is consumed by host bridge itself to

s/by host bridge
 /by the host bridge

> +	 *	access PCI configuration space.
> +	 *
> +	 * Due to lack of specification to define resources consumed by host
> +	 * bridge itself, all IO port resources defined by acpi_resource_io

s/by host bridge
 /by the host bridge

> +	 * and acpi_resource_fixed_io are ignored to filter out IO
> +	 * port[0xCF8-0xCFF]. Seems this solution works with all BIOSes, though
> +	 * it's not perfect.
> +	 *
> +	 * Another possible solution is to explicitly filter out IO

s/is to
 /would be to

> +	 * port[0xCF8-0xCFF].
> +	 */
> +	res_flags = IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_IO_FIXED;
>  	ret = acpi_dev_get_resources(device, list,
>  				     acpi_dev_filter_resource_type_cb,
> -				     (void *)(IORESOURCE_IO | IORESOURCE_MEM));
> +				     (void *)res_flags);
>  	if (ret < 0)
>  		dev_warn(&device->dev,
>  			 "failed to parse _CRS method, error code %d\n", ret);
> @@ -346,8 +366,7 @@ static void probe_pci_root_info(struct pci_root_info *info,
>  			"no IO and memory resources present in _CRS\n");
>  	else
>  		resource_list_for_each_entry_safe(entry, tmp, list) {
> -			if ((entry->res->flags & IORESOURCE_WINDOW) == 0 ||
> -			    (entry->res->flags & IORESOURCE_DISABLED))
> +			if (entry->res->flags & IORESOURCE_DISABLED)
>  				resource_list_destroy_entry(entry);
>  			else
>  				entry->res->name = info->name;
> diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c
> index 5589a6e2a023..79b6d3b5ffd2 100644
> --- a/drivers/acpi/resource.c
> +++ b/drivers/acpi/resource.c
> @@ -575,6 +575,9 @@ EXPORT_SYMBOL_GPL(acpi_dev_get_resources);
>   *
>   * This is a hepler function to support acpi_dev_get_resources(), which filters
>   * ACPI resource objects according to resource types.
> + *
> + * Flag IORESOURCE_IO_FIXED is used to opt out io and fixed_io resource

s/Flag IORESOURCE_IO_FIXED is used to opt out io and fixed_io resource
  The IORESOURCE_IO_FIXED flag is used to opt out IO and FIXED_IO resource

> + * descriptors for ACPI host bridges on x86 and IA64 platforms.
>   */
>  int acpi_dev_filter_resource_type(struct acpi_resource *ares,
>  				  unsigned long types)
> @@ -589,7 +592,8 @@ int acpi_dev_filter_resource_type(struct acpi_resource *ares,
>  		break;
>  	case ACPI_RESOURCE_TYPE_IO:
>  	case ACPI_RESOURCE_TYPE_FIXED_IO:
> -		type = IORESOURCE_IO;
> +		if ((types & IORESOURCE_IO_FIXED) == 0)
> +			type = IORESOURCE_IO;
>  		break;
>  	case ACPI_RESOURCE_TYPE_IRQ:
>  	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
> -- 
> 1.7.10.4
> 

Thanks,

	Ingo

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

* Re: [Bugfix v5] x86/PCI/ACPI: Fix regression caused by commit 63f1789ec716
  2015-04-13  6:56   ` Ingo Molnar
@ 2015-04-13 12:05     ` Rafael J. Wysocki
  0 siblings, 0 replies; 13+ messages in thread
From: Rafael J. Wysocki @ 2015-04-13 12:05 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Jiang Liu, Bjorn Helgaas, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, x86, Len Brown, Lv Zheng, LKML, linux-pci,
	linux-acpi

On Monday, April 13, 2015 08:56:17 AM Ingo Molnar wrote:
> 
> * Jiang Liu <jiang.liu@linux.intel.com> wrote:
> 
> > Before commit 593669c2ac0f("Use common ACPI resource interfaces to
> > simplify implementation"), arch/x86/pci/acpi.c applies following
> 
> s/applies following
>  /applied the following
> 
> > rules when parsing ACPI resources for PCI host bridge:
> > 1) Ignore IO port resources defined by acpi_resource_io and
> >    acpi_resource_fixed_io, which should be used to define resource
> >    for PCI device instead of PCI bridge.
> > 2) Accept IOMEM resource defined by acpi_resource_memory24,
> >    acpi_resource_memory32 and acpi_resource_fixed_memory32.
> >    These IOMEM resources are accepted to workaround some BIOS issue,
> 
> s/workaround
>  /work around
> 
> It's a verb, not a noun.

Agreed on this one an all of the points below.

> >    though they should be ignored. For example, PC Engines APU.1C
> 
> Please put the platform name into quotes to make it more clearly stand 
> apart from the rest of the text.
> 
> >    platform defines PCI host bridge IOMEM resources as:
> >                 Memory32Fixed (ReadOnly,
> >                     0x000A0000,         // Address Base
> >                     0x00020000,         // Address Length
> >                     )
> >                 Memory32Fixed (ReadOnly,
> >                     0x00000000,         // Address Base
> >                     0x00000000,         // Address Length
> >                     _Y00)
> > 3) Accept all IO port and IOMEM resources defined by
> >    acpi_resource_address{16,32,64,extended64}, no matter it's marked as
> >    ACPI_CONSUMER or ACPI_PRODUCER.
> 
> s/no matter it's marked
>  /regardless of whether it's marked
> 
> > Commit 593669c2ac0f("Use common ACPI resource interfaces to
> > simplify implementation") accept all IO port and IOMEM resources
> 
> s/accept
>  /started accepting
> 
> > defined by acpi_resource_io, acpi_resource_fixed_io,
> > acpi_resource_memory24, acpi_resource_memory32,
> > acpi_resource_fixed_memory32 and
> > acpi_resource_address{16,32,64,extended64}, which causes IO port
> > resources consumed by host bridge itself are listed in to host bridge
> > resource list.
> 
> this latter part of the sentence does not parse. Did you want to 
> write:
> 
>   acpi_resource_address{16,32,64,extended64}, which causes IO port
>   resources consumed by the host bridge itself to be listed in the
>   host bridge resource list.
> 
> ?
> 
> > Then commit 63f1789ec716("Ignore resources consumed by host bridge
> > itself") ignores resources consumed by host bridge itself by checking
> 
> s/ignores
>  /started ignoring
> 
> s/by host bridge
>  /by the host bridge
> 
> > IORESOURCE_WINDOW flag, which accidently removed the workaround in 2)
> > above for BIOS bug .
> 
> s/for BIOS bug .
>  /for the BIOS bug.
> 
> > So revert to the behavior before v3.19 to fix the regression.
> > 
> > Sample ACPI table are archived at:
> > https://bugzilla.kernel.org/show_bug.cgi?id=94221
> > 
> > Fixes: 63f1789ec716("Ignore resources consumed by host bridge itself")
> > Reported-and-Tested-by: Bernhard Thaler <bernhard.thaler@wvnet.at>
> > Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com>
> > ---
> >  arch/x86/pci/acpi.c     |   25 ++++++++++++++++++++++---
> >  drivers/acpi/resource.c |    6 +++++-
> >  2 files changed, 27 insertions(+), 4 deletions(-)
> > 
> > diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
> > index e4695985f9de..fc2da98985c3 100644
> > --- a/arch/x86/pci/acpi.c
> > +++ b/arch/x86/pci/acpi.c
> > @@ -332,12 +332,32 @@ static void probe_pci_root_info(struct pci_root_info *info,
> >  {
> >  	int ret;
> >  	struct resource_entry *entry, *tmp;
> > +	unsigned long res_flags;
> >  
> >  	sprintf(info->name, "PCI Bus %04x:%02x", domain, busnum);
> >  	info->bridge = device;
> > +
> > +	/*
> > +	 * An IO or MMIO resource assigned to PCI host bridge may be consumed
> 
> s/to PCI host bridge
>  /to a PCI host bridge
> 
> > +	 * by the host bridge itself or available to its child bus/devices.
> > +	 * On x86 and IA64 platforms, all IO and MMIO resources are assumed to
> > +	 * be available to child bus/devices except one special case:
> > +	 *	IO port [0xCF8-0xCFF] is consumed by host bridge itself to
> 
> s/by host bridge
>  /by the host bridge
> 
> > +	 *	access PCI configuration space.
> > +	 *
> > +	 * Due to lack of specification to define resources consumed by host
> > +	 * bridge itself, all IO port resources defined by acpi_resource_io
> 
> s/by host bridge
>  /by the host bridge
> 
> > +	 * and acpi_resource_fixed_io are ignored to filter out IO
> > +	 * port[0xCF8-0xCFF]. Seems this solution works with all BIOSes, though
> > +	 * it's not perfect.
> > +	 *
> > +	 * Another possible solution is to explicitly filter out IO
> 
> s/is to
>  /would be to
> 
> > +	 * port[0xCF8-0xCFF].
> > +	 */
> > +	res_flags = IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_IO_FIXED;
> >  	ret = acpi_dev_get_resources(device, list,
> >  				     acpi_dev_filter_resource_type_cb,
> > -				     (void *)(IORESOURCE_IO | IORESOURCE_MEM));
> > +				     (void *)res_flags);
> >  	if (ret < 0)
> >  		dev_warn(&device->dev,
> >  			 "failed to parse _CRS method, error code %d\n", ret);
> > @@ -346,8 +366,7 @@ static void probe_pci_root_info(struct pci_root_info *info,
> >  			"no IO and memory resources present in _CRS\n");
> >  	else
> >  		resource_list_for_each_entry_safe(entry, tmp, list) {
> > -			if ((entry->res->flags & IORESOURCE_WINDOW) == 0 ||
> > -			    (entry->res->flags & IORESOURCE_DISABLED))
> > +			if (entry->res->flags & IORESOURCE_DISABLED)
> >  				resource_list_destroy_entry(entry);
> >  			else
> >  				entry->res->name = info->name;
> > diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c
> > index 5589a6e2a023..79b6d3b5ffd2 100644
> > --- a/drivers/acpi/resource.c
> > +++ b/drivers/acpi/resource.c
> > @@ -575,6 +575,9 @@ EXPORT_SYMBOL_GPL(acpi_dev_get_resources);
> >   *
> >   * This is a hepler function to support acpi_dev_get_resources(), which filters
> >   * ACPI resource objects according to resource types.
> > + *
> > + * Flag IORESOURCE_IO_FIXED is used to opt out io and fixed_io resource
> 
> s/Flag IORESOURCE_IO_FIXED is used to opt out io and fixed_io resource
>   The IORESOURCE_IO_FIXED flag is used to opt out IO and FIXED_IO resource
> 
> > + * descriptors for ACPI host bridges on x86 and IA64 platforms.
> >   */
> >  int acpi_dev_filter_resource_type(struct acpi_resource *ares,
> >  				  unsigned long types)
> > @@ -589,7 +592,8 @@ int acpi_dev_filter_resource_type(struct acpi_resource *ares,
> >  		break;
> >  	case ACPI_RESOURCE_TYPE_IO:
> >  	case ACPI_RESOURCE_TYPE_FIXED_IO:
> > -		type = IORESOURCE_IO;
> > +		if ((types & IORESOURCE_IO_FIXED) == 0)
> > +			type = IORESOURCE_IO;
> >  		break;
> >  	case ACPI_RESOURCE_TYPE_IRQ:
> >  	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:


-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

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

* [Bugfix v5] x86/PCI/ACPI: Fix regression caused by commit 63f1789ec716
@ 2015-04-20  3:08 Jiang Liu
  2015-04-29  0:40 ` Rafael J. Wysocki
  0 siblings, 1 reply; 13+ messages in thread
From: Jiang Liu @ 2015-04-20  3:08 UTC (permalink / raw)
  To: Rafael J . Wysocki, Bjorn Helgaas, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, x86, Len Brown
  Cc: Jiang Liu, Lv Zheng, LKML, linux-pci, linux-acpi

An IO port or MMIO resource assigned to a PCI host bridge may be
consumed by the host bridge itself or available to its child
bus/devices. On x86 and IA64 platforms, all IO port and MMIO
resources are assumed to be available to child bus/devices
except one special case:
    IO port [0xCF8-0xCFF] is consumed by the host bridge itself
    to access PCI configuration space.

But the ACPI and PCI Firmware specifications haven't provided a method
to tell whether a resource is consumed by the host bridge itself.
So before commit 593669c2ac0f ("x86/PCI/ACPI: Use common ACPI resource
interfaces to simplify implementation"), arch/x86/pci/acpi.c ignored
all IO port resources defined by acpi_resource_io and
acpi_resource_fixed_io to filter out IO ports consumed by the host
bridge itself.

Commit 593669c2ac0f ("x86/PCI/ACPI: Use common ACPI resource interfaces
to simplify implementation")started accepting all IO port and MMIO
resources, which caused a regression that IO port resources consumed
by the host bridge itself became available to its child devices.

Then commit 63f1789ec716 ("x86/PCI/ACPI: Ignore resources consumed by
host bridge itself") ignored resources consumed by the host bridge
itself by checking the IORESOURCE_WINDOW flag, which accidently removed
MMIO resources defined by acpi_resource_memory24, acpi_resource_memory32
and acpi_resource_fixed_memory32.

So revert to the behavior before v3.19 to fix the regression.

There is also a discussion about ignoring the Producer/Consumer flag on
IA64 platforms at:
http://patchwork.ozlabs.org/patch/461633/

Related ACPI table are archived at:
https://bugzilla.kernel.org/show_bug.cgi?id=94221

Fixes: 63f1789ec716("Ignore resources consumed by host bridge itself")
Reported-by: Bernhard Thaler <bernhard.thaler@wvnet.at>
Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com>
---
 arch/x86/pci/acpi.c     |   25 ++++++++++++++++++++++---
 drivers/acpi/resource.c |    6 +++++-
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
index e4695985f9de..fc2da98985c3 100644
--- a/arch/x86/pci/acpi.c
+++ b/arch/x86/pci/acpi.c
@@ -332,12 +332,32 @@ static void probe_pci_root_info(struct pci_root_info *info,
 {
 	int ret;
 	struct resource_entry *entry, *tmp;
+	unsigned long res_flags;
 
 	sprintf(info->name, "PCI Bus %04x:%02x", domain, busnum);
 	info->bridge = device;
+
+	/*
+	 * An IO or MMIO resource assigned to PCI host bridge may be consumed
+	 * by the host bridge itself or available to its child bus/devices.
+	 * On x86 and IA64 platforms, all IO and MMIO resources are assumed to
+	 * be available to child bus/devices except one special case:
+	 *	IO port [0xCF8-0xCFF] is consumed by host bridge itself to
+	 *	access PCI configuration space.
+	 *
+	 * Due to lack of specification to define resources consumed by host
+	 * bridge itself, all IO port resources defined by acpi_resource_io
+	 * and acpi_resource_fixed_io are ignored to filter out IO
+	 * port[0xCF8-0xCFF]. Seems this solution works with all BIOSes, though
+	 * it's not perfect.
+	 *
+	 * Another possible solution is to explicitly filter out IO
+	 * port[0xCF8-0xCFF].
+	 */
+	res_flags = IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_IO_FIXED;
 	ret = acpi_dev_get_resources(device, list,
 				     acpi_dev_filter_resource_type_cb,
-				     (void *)(IORESOURCE_IO | IORESOURCE_MEM));
+				     (void *)res_flags);
 	if (ret < 0)
 		dev_warn(&device->dev,
 			 "failed to parse _CRS method, error code %d\n", ret);
@@ -346,8 +366,7 @@ static void probe_pci_root_info(struct pci_root_info *info,
 			"no IO and memory resources present in _CRS\n");
 	else
 		resource_list_for_each_entry_safe(entry, tmp, list) {
-			if ((entry->res->flags & IORESOURCE_WINDOW) == 0 ||
-			    (entry->res->flags & IORESOURCE_DISABLED))
+			if (entry->res->flags & IORESOURCE_DISABLED)
 				resource_list_destroy_entry(entry);
 			else
 				entry->res->name = info->name;
diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c
index 5589a6e2a023..79b6d3b5ffd2 100644
--- a/drivers/acpi/resource.c
+++ b/drivers/acpi/resource.c
@@ -575,6 +575,9 @@ EXPORT_SYMBOL_GPL(acpi_dev_get_resources);
  *
  * This is a hepler function to support acpi_dev_get_resources(), which filters
  * ACPI resource objects according to resource types.
+ *
+ * Flag IORESOURCE_IO_FIXED is used to opt out io and fixed_io resource
+ * descriptors for ACPI host bridges on x86 and IA64 platforms.
  */
 int acpi_dev_filter_resource_type(struct acpi_resource *ares,
 				  unsigned long types)
@@ -589,7 +592,8 @@ int acpi_dev_filter_resource_type(struct acpi_resource *ares,
 		break;
 	case ACPI_RESOURCE_TYPE_IO:
 	case ACPI_RESOURCE_TYPE_FIXED_IO:
-		type = IORESOURCE_IO;
+		if ((types & IORESOURCE_IO_FIXED) == 0)
+			type = IORESOURCE_IO;
 		break;
 	case ACPI_RESOURCE_TYPE_IRQ:
 	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
-- 
1.7.10.4

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

* Re: [Bugfix v5] x86/PCI/ACPI: Fix regression caused by commit 63f1789ec716
  2015-04-20  3:08 [Bugfix v5] x86/PCI/ACPI: Fix regression caused by commit 63f1789ec716 Jiang Liu
@ 2015-04-29  0:40 ` Rafael J. Wysocki
  2015-04-29 13:20   ` Bjorn Helgaas
  0 siblings, 1 reply; 13+ messages in thread
From: Rafael J. Wysocki @ 2015-04-29  0:40 UTC (permalink / raw)
  To: Jiang Liu, Bjorn Helgaas, Ingo Molnar
  Cc: Thomas Gleixner, H. Peter Anvin, x86, Len Brown, Lv Zheng, LKML,
	linux-pci, linux-acpi

On Monday, April 20, 2015 11:08:58 AM Jiang Liu wrote:
> An IO port or MMIO resource assigned to a PCI host bridge may be
> consumed by the host bridge itself or available to its child
> bus/devices. On x86 and IA64 platforms, all IO port and MMIO
> resources are assumed to be available to child bus/devices
> except one special case:
>     IO port [0xCF8-0xCFF] is consumed by the host bridge itself
>     to access PCI configuration space.
> 
> But the ACPI and PCI Firmware specifications haven't provided a method
> to tell whether a resource is consumed by the host bridge itself.
> So before commit 593669c2ac0f ("x86/PCI/ACPI: Use common ACPI resource
> interfaces to simplify implementation"), arch/x86/pci/acpi.c ignored
> all IO port resources defined by acpi_resource_io and
> acpi_resource_fixed_io to filter out IO ports consumed by the host
> bridge itself.
> 
> Commit 593669c2ac0f ("x86/PCI/ACPI: Use common ACPI resource interfaces
> to simplify implementation")started accepting all IO port and MMIO
> resources, which caused a regression that IO port resources consumed
> by the host bridge itself became available to its child devices.
> 
> Then commit 63f1789ec716 ("x86/PCI/ACPI: Ignore resources consumed by
> host bridge itself") ignored resources consumed by the host bridge
> itself by checking the IORESOURCE_WINDOW flag, which accidently removed
> MMIO resources defined by acpi_resource_memory24, acpi_resource_memory32
> and acpi_resource_fixed_memory32.
> 
> So revert to the behavior before v3.19 to fix the regression.
> 
> There is also a discussion about ignoring the Producer/Consumer flag on
> IA64 platforms at:
> http://patchwork.ozlabs.org/patch/461633/
> 
> Related ACPI table are archived at:
> https://bugzilla.kernel.org/show_bug.cgi?id=94221
> 
> Fixes: 63f1789ec716("Ignore resources consumed by host bridge itself")
> Reported-by: Bernhard Thaler <bernhard.thaler@wvnet.at>
> Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com>

Bjorn, Ingo, is anyone looking at this?  We're still having a regression in
this area ...

> ---
>  arch/x86/pci/acpi.c     |   25 ++++++++++++++++++++++---
>  drivers/acpi/resource.c |    6 +++++-
>  2 files changed, 27 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
> index e4695985f9de..fc2da98985c3 100644
> --- a/arch/x86/pci/acpi.c
> +++ b/arch/x86/pci/acpi.c
> @@ -332,12 +332,32 @@ static void probe_pci_root_info(struct pci_root_info *info,
>  {
>  	int ret;
>  	struct resource_entry *entry, *tmp;
> +	unsigned long res_flags;
>  
>  	sprintf(info->name, "PCI Bus %04x:%02x", domain, busnum);
>  	info->bridge = device;
> +
> +	/*
> +	 * An IO or MMIO resource assigned to PCI host bridge may be consumed
> +	 * by the host bridge itself or available to its child bus/devices.
> +	 * On x86 and IA64 platforms, all IO and MMIO resources are assumed to
> +	 * be available to child bus/devices except one special case:
> +	 *	IO port [0xCF8-0xCFF] is consumed by host bridge itself to
> +	 *	access PCI configuration space.
> +	 *
> +	 * Due to lack of specification to define resources consumed by host
> +	 * bridge itself, all IO port resources defined by acpi_resource_io
> +	 * and acpi_resource_fixed_io are ignored to filter out IO
> +	 * port[0xCF8-0xCFF]. Seems this solution works with all BIOSes, though
> +	 * it's not perfect.
> +	 *
> +	 * Another possible solution is to explicitly filter out IO
> +	 * port[0xCF8-0xCFF].
> +	 */
> +	res_flags = IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_IO_FIXED;
>  	ret = acpi_dev_get_resources(device, list,
>  				     acpi_dev_filter_resource_type_cb,
> -				     (void *)(IORESOURCE_IO | IORESOURCE_MEM));
> +				     (void *)res_flags);
>  	if (ret < 0)
>  		dev_warn(&device->dev,
>  			 "failed to parse _CRS method, error code %d\n", ret);
> @@ -346,8 +366,7 @@ static void probe_pci_root_info(struct pci_root_info *info,
>  			"no IO and memory resources present in _CRS\n");
>  	else
>  		resource_list_for_each_entry_safe(entry, tmp, list) {
> -			if ((entry->res->flags & IORESOURCE_WINDOW) == 0 ||
> -			    (entry->res->flags & IORESOURCE_DISABLED))
> +			if (entry->res->flags & IORESOURCE_DISABLED)
>  				resource_list_destroy_entry(entry);
>  			else
>  				entry->res->name = info->name;
> diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c
> index 5589a6e2a023..79b6d3b5ffd2 100644
> --- a/drivers/acpi/resource.c
> +++ b/drivers/acpi/resource.c
> @@ -575,6 +575,9 @@ EXPORT_SYMBOL_GPL(acpi_dev_get_resources);
>   *
>   * This is a hepler function to support acpi_dev_get_resources(), which filters
>   * ACPI resource objects according to resource types.
> + *
> + * Flag IORESOURCE_IO_FIXED is used to opt out io and fixed_io resource
> + * descriptors for ACPI host bridges on x86 and IA64 platforms.
>   */
>  int acpi_dev_filter_resource_type(struct acpi_resource *ares,
>  				  unsigned long types)
> @@ -589,7 +592,8 @@ int acpi_dev_filter_resource_type(struct acpi_resource *ares,
>  		break;
>  	case ACPI_RESOURCE_TYPE_IO:
>  	case ACPI_RESOURCE_TYPE_FIXED_IO:
> -		type = IORESOURCE_IO;
> +		if ((types & IORESOURCE_IO_FIXED) == 0)
> +			type = IORESOURCE_IO;
>  		break;
>  	case ACPI_RESOURCE_TYPE_IRQ:
>  	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
> 

-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

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

* Re: [Bugfix v5] x86/PCI/ACPI: Fix regression caused by commit 63f1789ec716
  2015-04-29  0:40 ` Rafael J. Wysocki
@ 2015-04-29 13:20   ` Bjorn Helgaas
  2015-04-29 13:33     ` Jiang Liu
  0 siblings, 1 reply; 13+ messages in thread
From: Bjorn Helgaas @ 2015-04-29 13:20 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Jiang Liu, Ingo Molnar, Thomas Gleixner, H. Peter Anvin,
	x86@kernel.org, Len Brown, Lv Zheng, LKML,
	linux-pci@vger.kernel.org, linux-acpi@vger.kernel.org

On Tue, Apr 28, 2015 at 7:40 PM, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> On Monday, April 20, 2015 11:08:58 AM Jiang Liu wrote:
>> An IO port or MMIO resource assigned to a PCI host bridge may be
>> consumed by the host bridge itself or available to its child
>> bus/devices. On x86 and IA64 platforms, all IO port and MMIO
>> resources are assumed to be available to child bus/devices
>> except one special case:
>>     IO port [0xCF8-0xCFF] is consumed by the host bridge itself
>>     to access PCI configuration space.
>>
>> But the ACPI and PCI Firmware specifications haven't provided a method
>> to tell whether a resource is consumed by the host bridge itself.
>> So before commit 593669c2ac0f ("x86/PCI/ACPI: Use common ACPI resource
>> interfaces to simplify implementation"), arch/x86/pci/acpi.c ignored
>> all IO port resources defined by acpi_resource_io and
>> acpi_resource_fixed_io to filter out IO ports consumed by the host
>> bridge itself.
>>
>> Commit 593669c2ac0f ("x86/PCI/ACPI: Use common ACPI resource interfaces
>> to simplify implementation")started accepting all IO port and MMIO
>> resources, which caused a regression that IO port resources consumed
>> by the host bridge itself became available to its child devices.
>>
>> Then commit 63f1789ec716 ("x86/PCI/ACPI: Ignore resources consumed by
>> host bridge itself") ignored resources consumed by the host bridge
>> itself by checking the IORESOURCE_WINDOW flag, which accidently removed
>> MMIO resources defined by acpi_resource_memory24, acpi_resource_memory32
>> and acpi_resource_fixed_memory32.
>>
>> So revert to the behavior before v3.19 to fix the regression.
>>
>> There is also a discussion about ignoring the Producer/Consumer flag on
>> IA64 platforms at:
>> http://patchwork.ozlabs.org/patch/461633/
>>
>> Related ACPI table are archived at:
>> https://bugzilla.kernel.org/show_bug.cgi?id=94221
>>
>> Fixes: 63f1789ec716("Ignore resources consumed by host bridge itself")
>> Reported-by: Bernhard Thaler <bernhard.thaler@wvnet.at>
>> Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com>
>
> Bjorn, Ingo, is anyone looking at this?  We're still having a regression in
> this area ...

>> ---
>>  arch/x86/pci/acpi.c     |   25 ++++++++++++++++++++++---
>>  drivers/acpi/resource.c |    6 +++++-
>>  2 files changed, 27 insertions(+), 4 deletions(-)
>>
>> diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
>> index e4695985f9de..fc2da98985c3 100644
>> --- a/arch/x86/pci/acpi.c
>> +++ b/arch/x86/pci/acpi.c
>> @@ -332,12 +332,32 @@ static void probe_pci_root_info(struct pci_root_info *info,
>>  {
>>       int ret;
>>       struct resource_entry *entry, *tmp;
>> +     unsigned long res_flags;
>>
>>       sprintf(info->name, "PCI Bus %04x:%02x", domain, busnum);
>>       info->bridge = device;
>> +
>> +     /*
>> +      * An IO or MMIO resource assigned to PCI host bridge may be consumed
>> +      * by the host bridge itself or available to its child bus/devices.
>> +      * On x86 and IA64 platforms, all IO and MMIO resources are assumed to
>> +      * be available to child bus/devices except one special case:
>> +      *      IO port [0xCF8-0xCFF] is consumed by host bridge itself to
>> +      *      access PCI configuration space.
>> +      *
>> +      * Due to lack of specification to define resources consumed by host
>> +      * bridge itself, all IO port resources defined by acpi_resource_io
>> +      * and acpi_resource_fixed_io are ignored to filter out IO
>> +      * port[0xCF8-0xCFF]. Seems this solution works with all BIOSes, though
>> +      * it's not perfect.

1) I think it's misleading to say "the specs haven't provided a
method."  As far as I can tell, the Producer/Consumer bit is intended
precisely to distinguish resources consumed by a bridge from those
forwarded to downstream devices.  It would be more accurate to say
"the spec defines a bit, but firmware hasn't used that bit
consistently, so we can't rely on it."

If you want to say "it's not perfect," it would be useful to mention
the ways in which it is not perfect.  This code is still a candidate
for unification with ia64 and arm64, so we should avoid x86-specific
things here as much as possible.

>> +      *
>> +      * Another possible solution is to explicitly filter out IO
>> +      * port[0xCF8-0xCFF].
>> +      */
>> +     res_flags = IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_IO_FIXED;

2) The usage of IORESOURCE_IO_FIXED here seems like a hack.  It's not
related to other existing use of IORESOURCE_IO_FIXED, and it's not
intuitive that supplying IORESOURCE_MEM means "I want all the
memory-type resources," but supplying IORESOURCE_IO_FIXED means "I
*don't* want the fixed I/O-type resources."

A struct resource is not as expressive as a struct acpi_resource.
We're going through a lot of contortions to pass nuances of
acpi_resource through to code that only knows about struct resource.
I'm not sure that's a good long-term strategy, but I don't have a
better suggestion.

>>       ret = acpi_dev_get_resources(device, list,
>>                                    acpi_dev_filter_resource_type_cb,
>> -                                  (void *)(IORESOURCE_IO | IORESOURCE_MEM));
>> +                                  (void *)res_flags);
>>       if (ret < 0)
>>               dev_warn(&device->dev,
>>                        "failed to parse _CRS method, error code %d\n", ret);
>> @@ -346,8 +366,7 @@ static void probe_pci_root_info(struct pci_root_info *info,
>>                       "no IO and memory resources present in _CRS\n");
>>       else
>>               resource_list_for_each_entry_safe(entry, tmp, list) {
>> -                     if ((entry->res->flags & IORESOURCE_WINDOW) == 0 ||
>> -                         (entry->res->flags & IORESOURCE_DISABLED))
>> +                     if (entry->res->flags & IORESOURCE_DISABLED)
>>                               resource_list_destroy_entry(entry);
>>                       else
>>                               entry->res->name = info->name;
>> diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c
>> index 5589a6e2a023..79b6d3b5ffd2 100644
>> --- a/drivers/acpi/resource.c
>> +++ b/drivers/acpi/resource.c
>> @@ -575,6 +575,9 @@ EXPORT_SYMBOL_GPL(acpi_dev_get_resources);
>>   *
>>   * This is a hepler function to support acpi_dev_get_resources(), which filters
>>   * ACPI resource objects according to resource types.

3)  Since you're touching this comment anyway, can you fix the
"hepler" typo above, too?

>> + *
>> + * Flag IORESOURCE_IO_FIXED is used to opt out io and fixed_io resource
>> + * descriptors for ACPI host bridges on x86 and IA64 platforms.
>>   */
>>  int acpi_dev_filter_resource_type(struct acpi_resource *ares,
>>                                 unsigned long types)
>> @@ -589,7 +592,8 @@ int acpi_dev_filter_resource_type(struct acpi_resource *ares,
>>               break;
>>       case ACPI_RESOURCE_TYPE_IO:
>>       case ACPI_RESOURCE_TYPE_FIXED_IO:
>> -             type = IORESOURCE_IO;
>> +             if ((types & IORESOURCE_IO_FIXED) == 0)
>> +                     type = IORESOURCE_IO;
>>               break;
>>       case ACPI_RESOURCE_TYPE_IRQ:
>>       case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
>>
>
> --
> I speak only for myself.
> Rafael J. Wysocki, Intel Open Source Technology Center.

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

* Re: [Bugfix v5] x86/PCI/ACPI: Fix regression caused by commit 63f1789ec716
  2015-04-29 13:20   ` Bjorn Helgaas
@ 2015-04-29 13:33     ` Jiang Liu
  2015-04-29 13:37       ` Bjorn Helgaas
  2015-04-29 14:15       ` [Bugfix v5] " Rafael J. Wysocki
  0 siblings, 2 replies; 13+ messages in thread
From: Jiang Liu @ 2015-04-29 13:33 UTC (permalink / raw)
  To: Bjorn Helgaas, Rafael J. Wysocki
  Cc: Ingo Molnar, Thomas Gleixner, H. Peter Anvin, x86@kernel.org,
	Len Brown, Lv Zheng, LKML, linux-pci@vger.kernel.org,
	linux-acpi@vger.kernel.org

On 2015/4/29 21:20, Bjorn Helgaas wrote:
> On Tue, Apr 28, 2015 at 7:40 PM, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
>> On Monday, April 20, 2015 11:08:58 AM Jiang Liu wrote:
>>> An IO port or MMIO resource assigned to a PCI host bridge may be
>>> consumed by the host bridge itself or available to its child
>>> bus/devices. On x86 and IA64 platforms, all IO port and MMIO
>>> resources are assumed to be available to child bus/devices
>>> except one special case:
>>>     IO port [0xCF8-0xCFF] is consumed by the host bridge itself
>>>     to access PCI configuration space.
>>>
>>> But the ACPI and PCI Firmware specifications haven't provided a method
>>> to tell whether a resource is consumed by the host bridge itself.
>>> So before commit 593669c2ac0f ("x86/PCI/ACPI: Use common ACPI resource
>>> interfaces to simplify implementation"), arch/x86/pci/acpi.c ignored
>>> all IO port resources defined by acpi_resource_io and
>>> acpi_resource_fixed_io to filter out IO ports consumed by the host
>>> bridge itself.
>>>
>>> Commit 593669c2ac0f ("x86/PCI/ACPI: Use common ACPI resource interfaces
>>> to simplify implementation")started accepting all IO port and MMIO
>>> resources, which caused a regression that IO port resources consumed
>>> by the host bridge itself became available to its child devices.
>>>
>>> Then commit 63f1789ec716 ("x86/PCI/ACPI: Ignore resources consumed by
>>> host bridge itself") ignored resources consumed by the host bridge
>>> itself by checking the IORESOURCE_WINDOW flag, which accidently removed
>>> MMIO resources defined by acpi_resource_memory24, acpi_resource_memory32
>>> and acpi_resource_fixed_memory32.
>>>
>>> So revert to the behavior before v3.19 to fix the regression.
>>>
>>> There is also a discussion about ignoring the Producer/Consumer flag on
>>> IA64 platforms at:
>>> http://patchwork.ozlabs.org/patch/461633/
>>>
>>> Related ACPI table are archived at:
>>> https://bugzilla.kernel.org/show_bug.cgi?id=94221
>>>
>>> Fixes: 63f1789ec716("Ignore resources consumed by host bridge itself")
>>> Reported-by: Bernhard Thaler <bernhard.thaler@wvnet.at>
>>> Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com>
>>
>> Bjorn, Ingo, is anyone looking at this?  We're still having a regression in
>> this area ...
> 
>>> ---
>>>  arch/x86/pci/acpi.c     |   25 ++++++++++++++++++++++---
>>>  drivers/acpi/resource.c |    6 +++++-
>>>  2 files changed, 27 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
>>> index e4695985f9de..fc2da98985c3 100644
>>> --- a/arch/x86/pci/acpi.c
>>> +++ b/arch/x86/pci/acpi.c
>>> @@ -332,12 +332,32 @@ static void probe_pci_root_info(struct pci_root_info *info,
>>>  {
>>>       int ret;
>>>       struct resource_entry *entry, *tmp;
>>> +     unsigned long res_flags;
>>>
>>>       sprintf(info->name, "PCI Bus %04x:%02x", domain, busnum);
>>>       info->bridge = device;
>>> +
>>> +     /*
>>> +      * An IO or MMIO resource assigned to PCI host bridge may be consumed
>>> +      * by the host bridge itself or available to its child bus/devices.
>>> +      * On x86 and IA64 platforms, all IO and MMIO resources are assumed to
>>> +      * be available to child bus/devices except one special case:
>>> +      *      IO port [0xCF8-0xCFF] is consumed by host bridge itself to
>>> +      *      access PCI configuration space.
>>> +      *
>>> +      * Due to lack of specification to define resources consumed by host
>>> +      * bridge itself, all IO port resources defined by acpi_resource_io
>>> +      * and acpi_resource_fixed_io are ignored to filter out IO
>>> +      * port[0xCF8-0xCFF]. Seems this solution works with all BIOSes, though
>>> +      * it's not perfect.
> 
> 1) I think it's misleading to say "the specs haven't provided a
> method."  As far as I can tell, the Producer/Consumer bit is intended
> precisely to distinguish resources consumed by a bridge from those
> forwarded to downstream devices.  It would be more accurate to say
> "the spec defines a bit, but firmware hasn't used that bit
> consistently, so we can't rely on it."

Hi Bjorn,
	Thanks for review, I will refine the words as suggested by you.

> If you want to say "it's not perfect," it would be useful to mention
> the ways in which it is not perfect.  This code is still a candidate
> for unification with ia64 and arm64, so we should avoid x86-specific
> things here as much as possible.

Yes, I have another pending patch set to consolidate IA64 and x86 code
for ACPI PCI root.

> 
>>> +      *
>>> +      * Another possible solution is to explicitly filter out IO
>>> +      * port[0xCF8-0xCFF].
>>> +      */
>>> +     res_flags = IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_IO_FIXED;
> 
> 2) The usage of IORESOURCE_IO_FIXED here seems like a hack.  It's not
> related to other existing use of IORESOURCE_IO_FIXED, and it's not
> intuitive that supplying IORESOURCE_MEM means "I want all the
> memory-type resources," but supplying IORESOURCE_IO_FIXED means "I
> *don't* want the fixed I/O-type resources."

Yes, the IORESOURCE_IO_FIXED is a hack here. Then how about explicitly
filtering IOPORT [0xCF8-0xCFF] so we could avoid such a hack.

> 
> A struct resource is not as expressive as a struct acpi_resource.
> We're going through a lot of contortions to pass nuances of
> acpi_resource through to code that only knows about struct resource.
> I'm not sure that's a good long-term strategy, but I don't have a
> better suggestion.
> 
>>>       ret = acpi_dev_get_resources(device, list,
>>>                                    acpi_dev_filter_resource_type_cb,
>>> -                                  (void *)(IORESOURCE_IO | IORESOURCE_MEM));
>>> +                                  (void *)res_flags);
>>>       if (ret < 0)
>>>               dev_warn(&device->dev,
>>>                        "failed to parse _CRS method, error code %d\n", ret);
>>> @@ -346,8 +366,7 @@ static void probe_pci_root_info(struct pci_root_info *info,
>>>                       "no IO and memory resources present in _CRS\n");
>>>       else
>>>               resource_list_for_each_entry_safe(entry, tmp, list) {
>>> -                     if ((entry->res->flags & IORESOURCE_WINDOW) == 0 ||
>>> -                         (entry->res->flags & IORESOURCE_DISABLED))
>>> +                     if (entry->res->flags & IORESOURCE_DISABLED)
>>>                               resource_list_destroy_entry(entry);
>>>                       else
>>>                               entry->res->name = info->name;
>>> diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c
>>> index 5589a6e2a023..79b6d3b5ffd2 100644
>>> --- a/drivers/acpi/resource.c
>>> +++ b/drivers/acpi/resource.c
>>> @@ -575,6 +575,9 @@ EXPORT_SYMBOL_GPL(acpi_dev_get_resources);
>>>   *
>>>   * This is a hepler function to support acpi_dev_get_resources(), which filters
>>>   * ACPI resource objects according to resource types.
> 
> 3)  Since you're touching this comment anyway, can you fix the
> "hepler" typo above, too?

Sure.
Thanks!
Gerry

> 
>>> + *
>>> + * Flag IORESOURCE_IO_FIXED is used to opt out io and fixed_io resource
>>> + * descriptors for ACPI host bridges on x86 and IA64 platforms.
>>>   */
>>>  int acpi_dev_filter_resource_type(struct acpi_resource *ares,
>>>                                 unsigned long types)
>>> @@ -589,7 +592,8 @@ int acpi_dev_filter_resource_type(struct acpi_resource *ares,
>>>               break;
>>>       case ACPI_RESOURCE_TYPE_IO:
>>>       case ACPI_RESOURCE_TYPE_FIXED_IO:
>>> -             type = IORESOURCE_IO;
>>> +             if ((types & IORESOURCE_IO_FIXED) == 0)
>>> +                     type = IORESOURCE_IO;
>>>               break;
>>>       case ACPI_RESOURCE_TYPE_IRQ:
>>>       case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
>>>
>>
>> --
>> I speak only for myself.
>> Rafael J. Wysocki, Intel Open Source Technology Center.

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

* Re: [Bugfix v5] x86/PCI/ACPI: Fix regression caused by commit 63f1789ec716
  2015-04-29 13:33     ` Jiang Liu
@ 2015-04-29 13:37       ` Bjorn Helgaas
  2015-04-30  4:41         ` [Bugfix v6] " Jiang Liu
  2015-04-29 14:15       ` [Bugfix v5] " Rafael J. Wysocki
  1 sibling, 1 reply; 13+ messages in thread
From: Bjorn Helgaas @ 2015-04-29 13:37 UTC (permalink / raw)
  To: Jiang Liu
  Cc: Rafael J. Wysocki, Ingo Molnar, Thomas Gleixner, H. Peter Anvin,
	x86@kernel.org, Len Brown, Lv Zheng, LKML,
	linux-pci@vger.kernel.org, linux-acpi@vger.kernel.org

On Wed, Apr 29, 2015 at 8:33 AM, Jiang Liu <jiang.liu@linux.intel.com> wrote:
> On 2015/4/29 21:20, Bjorn Helgaas wrote:
>> On Tue, Apr 28, 2015 at 7:40 PM, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
>>> On Monday, April 20, 2015 11:08:58 AM Jiang Liu wrote:

>>>> +      *
>>>> +      * Another possible solution is to explicitly filter out IO
>>>> +      * port[0xCF8-0xCFF].
>>>> +      */
>>>> +     res_flags = IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_IO_FIXED;
>>
>> 2) The usage of IORESOURCE_IO_FIXED here seems like a hack.  It's not
>> related to other existing use of IORESOURCE_IO_FIXED, and it's not
>> intuitive that supplying IORESOURCE_MEM means "I want all the
>> memory-type resources," but supplying IORESOURCE_IO_FIXED means "I
>> *don't* want the fixed I/O-type resources."
>
> Yes, the IORESOURCE_IO_FIXED is a hack here. Then how about explicitly
> filtering IOPORT [0xCF8-0xCFF] so we could avoid such a hack.

I'm OK with that, although it should be in an arch-specific hook or something.

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

* Re: [Bugfix v5] x86/PCI/ACPI: Fix regression caused by commit 63f1789ec716
  2015-04-29 14:15       ` [Bugfix v5] " Rafael J. Wysocki
@ 2015-04-29 13:53         ` Jiang Liu
  0 siblings, 0 replies; 13+ messages in thread
From: Jiang Liu @ 2015-04-29 13:53 UTC (permalink / raw)
  To: Rafael J. Wysocki, Bjorn Helgaas
  Cc: Ingo Molnar, Thomas Gleixner, H. Peter Anvin, x86@kernel.org,
	Len Brown, Lv Zheng, LKML, linux-pci@vger.kernel.org,
	linux-acpi@vger.kernel.org



On 2015/4/29 22:15, Rafael J. Wysocki wrote:
> On Wednesday, April 29, 2015 09:33:16 PM Jiang Liu wrote:
>> On 2015/4/29 21:20, Bjorn Helgaas wrote:
>>> On Tue, Apr 28, 2015 at 7:40 PM, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
>>>> On Monday, April 20, 2015 11:08:58 AM Jiang Liu wrote:
>>>>> An IO port or MMIO resource assigned to a PCI host bridge may be
>>>>> consumed by the host bridge itself or available to its child
>>>>> bus/devices. On x86 and IA64 platforms, all IO port and MMIO
>>>>> resources are assumed to be available to child bus/devices
>>>>> except one special case:
>>>>>     IO port [0xCF8-0xCFF] is consumed by the host bridge itself
>>>>>     to access PCI configuration space.
>>>>>
>>>>> But the ACPI and PCI Firmware specifications haven't provided a method
>>>>> to tell whether a resource is consumed by the host bridge itself.
>>>>> So before commit 593669c2ac0f ("x86/PCI/ACPI: Use common ACPI resource
>>>>> interfaces to simplify implementation"), arch/x86/pci/acpi.c ignored
>>>>> all IO port resources defined by acpi_resource_io and
>>>>> acpi_resource_fixed_io to filter out IO ports consumed by the host
>>>>> bridge itself.
>>>>>
>>>>> Commit 593669c2ac0f ("x86/PCI/ACPI: Use common ACPI resource interfaces
>>>>> to simplify implementation")started accepting all IO port and MMIO
>>>>> resources, which caused a regression that IO port resources consumed
>>>>> by the host bridge itself became available to its child devices.
>>>>>
>>>>> Then commit 63f1789ec716 ("x86/PCI/ACPI: Ignore resources consumed by
>>>>> host bridge itself") ignored resources consumed by the host bridge
>>>>> itself by checking the IORESOURCE_WINDOW flag, which accidently removed
>>>>> MMIO resources defined by acpi_resource_memory24, acpi_resource_memory32
>>>>> and acpi_resource_fixed_memory32.
>>>>>
>>>>> So revert to the behavior before v3.19 to fix the regression.
>>>>>
>>>>> There is also a discussion about ignoring the Producer/Consumer flag on
>>>>> IA64 platforms at:
>>>>> http://patchwork.ozlabs.org/patch/461633/
>>>>>
>>>>> Related ACPI table are archived at:
>>>>> https://bugzilla.kernel.org/show_bug.cgi?id=94221
>>>>>
>>>>> Fixes: 63f1789ec716("Ignore resources consumed by host bridge itself")
>>>>> Reported-by: Bernhard Thaler <bernhard.thaler@wvnet.at>
>>>>> Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com>
>>>>
>>>> Bjorn, Ingo, is anyone looking at this?  We're still having a regression in
>>>> this area ...
>>>
>>>>> ---
>>>>>  arch/x86/pci/acpi.c     |   25 ++++++++++++++++++++++---
>>>>>  drivers/acpi/resource.c |    6 +++++-
>>>>>  2 files changed, 27 insertions(+), 4 deletions(-)
>>>>>
>>>>> diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
>>>>> index e4695985f9de..fc2da98985c3 100644
>>>>> --- a/arch/x86/pci/acpi.c
>>>>> +++ b/arch/x86/pci/acpi.c
>>>>> @@ -332,12 +332,32 @@ static void probe_pci_root_info(struct pci_root_info *info,
>>>>>  {
>>>>>       int ret;
>>>>>       struct resource_entry *entry, *tmp;
>>>>> +     unsigned long res_flags;
>>>>>
>>>>>       sprintf(info->name, "PCI Bus %04x:%02x", domain, busnum);
>>>>>       info->bridge = device;
>>>>> +
>>>>> +     /*
>>>>> +      * An IO or MMIO resource assigned to PCI host bridge may be consumed
>>>>> +      * by the host bridge itself or available to its child bus/devices.
>>>>> +      * On x86 and IA64 platforms, all IO and MMIO resources are assumed to
>>>>> +      * be available to child bus/devices except one special case:
>>>>> +      *      IO port [0xCF8-0xCFF] is consumed by host bridge itself to
>>>>> +      *      access PCI configuration space.
>>>>> +      *
>>>>> +      * Due to lack of specification to define resources consumed by host
>>>>> +      * bridge itself, all IO port resources defined by acpi_resource_io
>>>>> +      * and acpi_resource_fixed_io are ignored to filter out IO
>>>>> +      * port[0xCF8-0xCFF]. Seems this solution works with all BIOSes, though
>>>>> +      * it's not perfect.
>>>
>>> 1) I think it's misleading to say "the specs haven't provided a
>>> method."  As far as I can tell, the Producer/Consumer bit is intended
>>> precisely to distinguish resources consumed by a bridge from those
>>> forwarded to downstream devices.  It would be more accurate to say
>>> "the spec defines a bit, but firmware hasn't used that bit
>>> consistently, so we can't rely on it."
>>
>> Hi Bjorn,
>> 	Thanks for review, I will refine the words as suggested by you.
>>
>>> If you want to say "it's not perfect," it would be useful to mention
>>> the ways in which it is not perfect.  This code is still a candidate
>>> for unification with ia64 and arm64, so we should avoid x86-specific
>>> things here as much as possible.
>>
>> Yes, I have another pending patch set to consolidate IA64 and x86 code
>> for ACPI PCI root.
> 
> That's OK, but can we please fix the regression first before doing that
> unification?  Like to make life easier for the "stable" people and
> whoever wants to backport the fix?

Hi Rafael,
	Yes, I will fix the regression first before sending out the
pending patch set.
Thanks!
Gerry

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

* Re: [Bugfix v5] x86/PCI/ACPI: Fix regression caused by commit 63f1789ec716
  2015-04-29 13:33     ` Jiang Liu
  2015-04-29 13:37       ` Bjorn Helgaas
@ 2015-04-29 14:15       ` Rafael J. Wysocki
  2015-04-29 13:53         ` Jiang Liu
  1 sibling, 1 reply; 13+ messages in thread
From: Rafael J. Wysocki @ 2015-04-29 14:15 UTC (permalink / raw)
  To: Jiang Liu, Bjorn Helgaas
  Cc: Ingo Molnar, Thomas Gleixner, H. Peter Anvin, x86@kernel.org,
	Len Brown, Lv Zheng, LKML, linux-pci@vger.kernel.org,
	linux-acpi@vger.kernel.org

On Wednesday, April 29, 2015 09:33:16 PM Jiang Liu wrote:
> On 2015/4/29 21:20, Bjorn Helgaas wrote:
> > On Tue, Apr 28, 2015 at 7:40 PM, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> >> On Monday, April 20, 2015 11:08:58 AM Jiang Liu wrote:
> >>> An IO port or MMIO resource assigned to a PCI host bridge may be
> >>> consumed by the host bridge itself or available to its child
> >>> bus/devices. On x86 and IA64 platforms, all IO port and MMIO
> >>> resources are assumed to be available to child bus/devices
> >>> except one special case:
> >>>     IO port [0xCF8-0xCFF] is consumed by the host bridge itself
> >>>     to access PCI configuration space.
> >>>
> >>> But the ACPI and PCI Firmware specifications haven't provided a method
> >>> to tell whether a resource is consumed by the host bridge itself.
> >>> So before commit 593669c2ac0f ("x86/PCI/ACPI: Use common ACPI resource
> >>> interfaces to simplify implementation"), arch/x86/pci/acpi.c ignored
> >>> all IO port resources defined by acpi_resource_io and
> >>> acpi_resource_fixed_io to filter out IO ports consumed by the host
> >>> bridge itself.
> >>>
> >>> Commit 593669c2ac0f ("x86/PCI/ACPI: Use common ACPI resource interfaces
> >>> to simplify implementation")started accepting all IO port and MMIO
> >>> resources, which caused a regression that IO port resources consumed
> >>> by the host bridge itself became available to its child devices.
> >>>
> >>> Then commit 63f1789ec716 ("x86/PCI/ACPI: Ignore resources consumed by
> >>> host bridge itself") ignored resources consumed by the host bridge
> >>> itself by checking the IORESOURCE_WINDOW flag, which accidently removed
> >>> MMIO resources defined by acpi_resource_memory24, acpi_resource_memory32
> >>> and acpi_resource_fixed_memory32.
> >>>
> >>> So revert to the behavior before v3.19 to fix the regression.
> >>>
> >>> There is also a discussion about ignoring the Producer/Consumer flag on
> >>> IA64 platforms at:
> >>> http://patchwork.ozlabs.org/patch/461633/
> >>>
> >>> Related ACPI table are archived at:
> >>> https://bugzilla.kernel.org/show_bug.cgi?id=94221
> >>>
> >>> Fixes: 63f1789ec716("Ignore resources consumed by host bridge itself")
> >>> Reported-by: Bernhard Thaler <bernhard.thaler@wvnet.at>
> >>> Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com>
> >>
> >> Bjorn, Ingo, is anyone looking at this?  We're still having a regression in
> >> this area ...
> > 
> >>> ---
> >>>  arch/x86/pci/acpi.c     |   25 ++++++++++++++++++++++---
> >>>  drivers/acpi/resource.c |    6 +++++-
> >>>  2 files changed, 27 insertions(+), 4 deletions(-)
> >>>
> >>> diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
> >>> index e4695985f9de..fc2da98985c3 100644
> >>> --- a/arch/x86/pci/acpi.c
> >>> +++ b/arch/x86/pci/acpi.c
> >>> @@ -332,12 +332,32 @@ static void probe_pci_root_info(struct pci_root_info *info,
> >>>  {
> >>>       int ret;
> >>>       struct resource_entry *entry, *tmp;
> >>> +     unsigned long res_flags;
> >>>
> >>>       sprintf(info->name, "PCI Bus %04x:%02x", domain, busnum);
> >>>       info->bridge = device;
> >>> +
> >>> +     /*
> >>> +      * An IO or MMIO resource assigned to PCI host bridge may be consumed
> >>> +      * by the host bridge itself or available to its child bus/devices.
> >>> +      * On x86 and IA64 platforms, all IO and MMIO resources are assumed to
> >>> +      * be available to child bus/devices except one special case:
> >>> +      *      IO port [0xCF8-0xCFF] is consumed by host bridge itself to
> >>> +      *      access PCI configuration space.
> >>> +      *
> >>> +      * Due to lack of specification to define resources consumed by host
> >>> +      * bridge itself, all IO port resources defined by acpi_resource_io
> >>> +      * and acpi_resource_fixed_io are ignored to filter out IO
> >>> +      * port[0xCF8-0xCFF]. Seems this solution works with all BIOSes, though
> >>> +      * it's not perfect.
> > 
> > 1) I think it's misleading to say "the specs haven't provided a
> > method."  As far as I can tell, the Producer/Consumer bit is intended
> > precisely to distinguish resources consumed by a bridge from those
> > forwarded to downstream devices.  It would be more accurate to say
> > "the spec defines a bit, but firmware hasn't used that bit
> > consistently, so we can't rely on it."
> 
> Hi Bjorn,
> 	Thanks for review, I will refine the words as suggested by you.
> 
> > If you want to say "it's not perfect," it would be useful to mention
> > the ways in which it is not perfect.  This code is still a candidate
> > for unification with ia64 and arm64, so we should avoid x86-specific
> > things here as much as possible.
> 
> Yes, I have another pending patch set to consolidate IA64 and x86 code
> for ACPI PCI root.

That's OK, but can we please fix the regression first before doing that
unification?  Like to make life easier for the "stable" people and
whoever wants to backport the fix?


-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

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

* [Bugfix v6] x86/PCI/ACPI: Fix regression caused by commit 63f1789ec716
  2015-04-29 13:37       ` Bjorn Helgaas
@ 2015-04-30  4:41         ` Jiang Liu
  2015-04-30 13:28           ` Bjorn Helgaas
  0 siblings, 1 reply; 13+ messages in thread
From: Jiang Liu @ 2015-04-30  4:41 UTC (permalink / raw)
  To: Rafael J . Wysocki, Bjorn Helgaas, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, x86, Len Brown
  Cc: Jiang Liu, Lv Zheng, LKML, linux-pci, linux-acpi

An IO port or MMIO resource assigned to a PCI host bridge may be
consumed by the host bridge itself or available to its child
bus/devices. The ACPI specification defines a bit (Producer/Consumer)
to tell whether the resource is consumed by the host bridge itself,
but firmware hasn't used that bit consistently, so we can't rely on it.

Before commit 593669c2ac0f ("x86/PCI/ACPI: Use common ACPI resource
interfaces to simplify implementation"), arch/x86/pci/acpi.c ignored
all IO port resources defined by acpi_resource_io and
acpi_resource_fixed_io to filter out IO ports consumed by the host
bridge itself.

Commit 593669c2ac0f ("x86/PCI/ACPI: Use common ACPI resource interfaces
to simplify implementation") started accepting all IO port and MMIO
resources, which caused a regression that IO port resources consumed
by the host bridge itself became available to its child devices.

Then commit 63f1789ec716 ("x86/PCI/ACPI: Ignore resources consumed by
host bridge itself") ignored resources consumed by the host bridge
itself by checking the IORESOURCE_WINDOW flag, which accidently removed
MMIO resources defined by acpi_resource_memory24, acpi_resource_memory32
and acpi_resource_fixed_memory32.

On x86 and IA64 platforms, all IO port and MMIO resources are assumed
to be available to child bus/devices except one special case:
    IO port [0xCF8-0xCFF] is consumed by the host bridge itself
    to access PCI configuration space.

So explicitly filter out PCI CFG IO ports[0xCF8-0xCFF]. This solution
will also ease the way to consolidate ACPI PCI host bridge common code
from x86, ia64 and ARM64.

Related ACPI table are archived at:
https://bugzilla.kernel.org/show_bug.cgi?id=94221

Related discussions at:
http://patchwork.ozlabs.org/patch/461633/
https://lkml.org/lkml/2015/3/29/304

Fixes: 63f1789ec716("Ignore resources consumed by host bridge itself")
Reported-by: Bernhard Thaler <bernhard.thaler@wvnet.at>
Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com>
Cc: <stable@vger.kernel.org> # 4.0
---
 arch/x86/pci/acpi.c     |   24 ++++++++++++++++++++++--
 drivers/acpi/resource.c |    2 +-
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
index e4695985f9de..d93963340c3c 100644
--- a/arch/x86/pci/acpi.c
+++ b/arch/x86/pci/acpi.c
@@ -325,6 +325,26 @@ static void release_pci_root_info(struct pci_host_bridge *bridge)
 	kfree(info);
 }
 
+/*
+ * An IO port or MMIO resource assigned to a PCI host bridge may be
+ * consumed by the host bridge itself or available to its child
+ * bus/devices. The ACPI specification defines a bit (Producer/Consumer)
+ * to tell whether the resource is consumed by the host bridge itself,
+ * but firmware hasn't used that bit consistently, so we can't rely on it.
+ *
+ * On x86 and IA64 platforms, all IO port and MMIO resources are assumed
+ * to be available to child bus/devices except one special case:
+ *     IO port [0xCF8-0xCFF] is consumed by the host bridge itself
+ *     to access PCI configuration space.
+ *
+ * So explicitly filter out PCI CFG IO ports[0xCF8-0xCFF].
+ */
+static bool resource_is_pcicfg_ioport(struct resource *res)
+{
+	return (res->flags & IORESOURCE_IO) &&
+		res->start == 0xCF8 && res->end == 0xCFF;
+}
+
 static void probe_pci_root_info(struct pci_root_info *info,
 				struct acpi_device *device,
 				int busnum, int domain,
@@ -346,8 +366,8 @@ static void probe_pci_root_info(struct pci_root_info *info,
 			"no IO and memory resources present in _CRS\n");
 	else
 		resource_list_for_each_entry_safe(entry, tmp, list) {
-			if ((entry->res->flags & IORESOURCE_WINDOW) == 0 ||
-			    (entry->res->flags & IORESOURCE_DISABLED))
+			if ((entry->res->flags & IORESOURCE_DISABLED) ||
+			    resource_is_pcicfg_ioport(entry->res))
 				resource_list_destroy_entry(entry);
 			else
 				entry->res->name = info->name;
diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c
index 5589a6e2a023..8244f013f210 100644
--- a/drivers/acpi/resource.c
+++ b/drivers/acpi/resource.c
@@ -573,7 +573,7 @@ EXPORT_SYMBOL_GPL(acpi_dev_get_resources);
  * @ares: Input ACPI resource object.
  * @types: Valid resource types of IORESOURCE_XXX
  *
- * This is a hepler function to support acpi_dev_get_resources(), which filters
+ * This is a helper function to support acpi_dev_get_resources(), which filters
  * ACPI resource objects according to resource types.
  */
 int acpi_dev_filter_resource_type(struct acpi_resource *ares,
-- 
1.7.10.4

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

* Re: [Bugfix v6] x86/PCI/ACPI: Fix regression caused by commit 63f1789ec716
  2015-04-30  4:41         ` [Bugfix v6] " Jiang Liu
@ 2015-04-30 13:28           ` Bjorn Helgaas
  2015-04-30 20:16             ` Rafael J. Wysocki
  0 siblings, 1 reply; 13+ messages in thread
From: Bjorn Helgaas @ 2015-04-30 13:28 UTC (permalink / raw)
  To: Jiang Liu
  Cc: Rafael J . Wysocki, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	x86@kernel.org, Len Brown, Lv Zheng, LKML,
	linux-pci@vger.kernel.org, linux-acpi@vger.kernel.org

On Wed, Apr 29, 2015 at 11:41 PM, Jiang Liu <jiang.liu@linux.intel.com> wrote:
> An IO port or MMIO resource assigned to a PCI host bridge may be
> consumed by the host bridge itself or available to its child
> bus/devices. The ACPI specification defines a bit (Producer/Consumer)
> to tell whether the resource is consumed by the host bridge itself,
> but firmware hasn't used that bit consistently, so we can't rely on it.
>
> Before commit 593669c2ac0f ("x86/PCI/ACPI: Use common ACPI resource
> interfaces to simplify implementation"), arch/x86/pci/acpi.c ignored
> all IO port resources defined by acpi_resource_io and
> acpi_resource_fixed_io to filter out IO ports consumed by the host
> bridge itself.
>
> Commit 593669c2ac0f ("x86/PCI/ACPI: Use common ACPI resource interfaces
> to simplify implementation") started accepting all IO port and MMIO
> resources, which caused a regression that IO port resources consumed
> by the host bridge itself became available to its child devices.
>
> Then commit 63f1789ec716 ("x86/PCI/ACPI: Ignore resources consumed by
> host bridge itself") ignored resources consumed by the host bridge
> itself by checking the IORESOURCE_WINDOW flag, which accidently removed
> MMIO resources defined by acpi_resource_memory24, acpi_resource_memory32
> and acpi_resource_fixed_memory32.
>
> On x86 and IA64 platforms, all IO port and MMIO resources are assumed
> to be available to child bus/devices except one special case:
>     IO port [0xCF8-0xCFF] is consumed by the host bridge itself
>     to access PCI configuration space.
>
> So explicitly filter out PCI CFG IO ports[0xCF8-0xCFF]. This solution
> will also ease the way to consolidate ACPI PCI host bridge common code
> from x86, ia64 and ARM64.
>
> Related ACPI table are archived at:
> https://bugzilla.kernel.org/show_bug.cgi?id=94221
>
> Related discussions at:
> http://patchwork.ozlabs.org/patch/461633/
> https://lkml.org/lkml/2015/3/29/304
>
> Fixes: 63f1789ec716("Ignore resources consumed by host bridge itself")
> Reported-by: Bernhard Thaler <bernhard.thaler@wvnet.at>
> Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com>
> Cc: <stable@vger.kernel.org> # 4.0
> ---
>  arch/x86/pci/acpi.c     |   24 ++++++++++++++++++++++--
>  drivers/acpi/resource.c |    2 +-
>  2 files changed, 23 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
> index e4695985f9de..d93963340c3c 100644
> --- a/arch/x86/pci/acpi.c
> +++ b/arch/x86/pci/acpi.c
> @@ -325,6 +325,26 @@ static void release_pci_root_info(struct pci_host_bridge *bridge)
>         kfree(info);
>  }
>
> +/*
> + * An IO port or MMIO resource assigned to a PCI host bridge may be
> + * consumed by the host bridge itself or available to its child
> + * bus/devices. The ACPI specification defines a bit (Producer/Consumer)
> + * to tell whether the resource is consumed by the host bridge itself,
> + * but firmware hasn't used that bit consistently, so we can't rely on it.
> + *
> + * On x86 and IA64 platforms, all IO port and MMIO resources are assumed
> + * to be available to child bus/devices except one special case:
> + *     IO port [0xCF8-0xCFF] is consumed by the host bridge itself
> + *     to access PCI configuration space.
> + *
> + * So explicitly filter out PCI CFG IO ports[0xCF8-0xCFF].
> + */
> +static bool resource_is_pcicfg_ioport(struct resource *res)
> +{
> +       return (res->flags & IORESOURCE_IO) &&
> +               res->start == 0xCF8 && res->end == 0xCFF;
> +}
> +
>  static void probe_pci_root_info(struct pci_root_info *info,
>                                 struct acpi_device *device,
>                                 int busnum, int domain,
> @@ -346,8 +366,8 @@ static void probe_pci_root_info(struct pci_root_info *info,
>                         "no IO and memory resources present in _CRS\n");
>         else
>                 resource_list_for_each_entry_safe(entry, tmp, list) {
> -                       if ((entry->res->flags & IORESOURCE_WINDOW) == 0 ||
> -                           (entry->res->flags & IORESOURCE_DISABLED))
> +                       if ((entry->res->flags & IORESOURCE_DISABLED) ||
> +                           resource_is_pcicfg_ioport(entry->res))

Hey, I can understand this code!  This is *way* better that what you
had before.  Thanks for persevering.

My only remaining comment is that the subject line ("Fix regression
caused by commit ...") doesn't really describe the code.  It should
say something specific, like maybe "x86/PCI/ACPI: Make all resources
except [io 0xcf8-0xcff] available on PCI bus".

Reviewed-by: Bjorn Helgaas <bhelgaas@google.com>

>                                 resource_list_destroy_entry(entry);
>                         else
>                                 entry->res->name = info->name;
> diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c
> index 5589a6e2a023..8244f013f210 100644
> --- a/drivers/acpi/resource.c
> +++ b/drivers/acpi/resource.c
> @@ -573,7 +573,7 @@ EXPORT_SYMBOL_GPL(acpi_dev_get_resources);
>   * @ares: Input ACPI resource object.
>   * @types: Valid resource types of IORESOURCE_XXX
>   *
> - * This is a hepler function to support acpi_dev_get_resources(), which filters
> + * This is a helper function to support acpi_dev_get_resources(), which filters
>   * ACPI resource objects according to resource types.
>   */
>  int acpi_dev_filter_resource_type(struct acpi_resource *ares,
> --
> 1.7.10.4
>

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

* Re: [Bugfix v6] x86/PCI/ACPI: Fix regression caused by commit 63f1789ec716
  2015-04-30 13:28           ` Bjorn Helgaas
@ 2015-04-30 20:16             ` Rafael J. Wysocki
  0 siblings, 0 replies; 13+ messages in thread
From: Rafael J. Wysocki @ 2015-04-30 20:16 UTC (permalink / raw)
  To: Bjorn Helgaas, Ingo Molnar
  Cc: Jiang Liu, Thomas Gleixner, H. Peter Anvin, x86@kernel.org,
	Len Brown, Lv Zheng, LKML, linux-pci@vger.kernel.org,
	linux-acpi@vger.kernel.org

On Thursday, April 30, 2015 08:28:17 AM Bjorn Helgaas wrote:
> On Wed, Apr 29, 2015 at 11:41 PM, Jiang Liu <jiang.liu@linux.intel.com> wrote:
> > An IO port or MMIO resource assigned to a PCI host bridge may be
> > consumed by the host bridge itself or available to its child
> > bus/devices. The ACPI specification defines a bit (Producer/Consumer)
> > to tell whether the resource is consumed by the host bridge itself,
> > but firmware hasn't used that bit consistently, so we can't rely on it.
> >
> > Before commit 593669c2ac0f ("x86/PCI/ACPI: Use common ACPI resource
> > interfaces to simplify implementation"), arch/x86/pci/acpi.c ignored
> > all IO port resources defined by acpi_resource_io and
> > acpi_resource_fixed_io to filter out IO ports consumed by the host
> > bridge itself.
> >
> > Commit 593669c2ac0f ("x86/PCI/ACPI: Use common ACPI resource interfaces
> > to simplify implementation") started accepting all IO port and MMIO
> > resources, which caused a regression that IO port resources consumed
> > by the host bridge itself became available to its child devices.
> >
> > Then commit 63f1789ec716 ("x86/PCI/ACPI: Ignore resources consumed by
> > host bridge itself") ignored resources consumed by the host bridge
> > itself by checking the IORESOURCE_WINDOW flag, which accidently removed
> > MMIO resources defined by acpi_resource_memory24, acpi_resource_memory32
> > and acpi_resource_fixed_memory32.
> >
> > On x86 and IA64 platforms, all IO port and MMIO resources are assumed
> > to be available to child bus/devices except one special case:
> >     IO port [0xCF8-0xCFF] is consumed by the host bridge itself
> >     to access PCI configuration space.
> >
> > So explicitly filter out PCI CFG IO ports[0xCF8-0xCFF]. This solution
> > will also ease the way to consolidate ACPI PCI host bridge common code
> > from x86, ia64 and ARM64.
> >
> > Related ACPI table are archived at:
> > https://bugzilla.kernel.org/show_bug.cgi?id=94221
> >
> > Related discussions at:
> > http://patchwork.ozlabs.org/patch/461633/
> > https://lkml.org/lkml/2015/3/29/304
> >
> > Fixes: 63f1789ec716("Ignore resources consumed by host bridge itself")
> > Reported-by: Bernhard Thaler <bernhard.thaler@wvnet.at>
> > Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com>
> > Cc: <stable@vger.kernel.org> # 4.0
> > ---
> >  arch/x86/pci/acpi.c     |   24 ++++++++++++++++++++++--
> >  drivers/acpi/resource.c |    2 +-
> >  2 files changed, 23 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
> > index e4695985f9de..d93963340c3c 100644
> > --- a/arch/x86/pci/acpi.c
> > +++ b/arch/x86/pci/acpi.c
> > @@ -325,6 +325,26 @@ static void release_pci_root_info(struct pci_host_bridge *bridge)
> >         kfree(info);
> >  }
> >
> > +/*
> > + * An IO port or MMIO resource assigned to a PCI host bridge may be
> > + * consumed by the host bridge itself or available to its child
> > + * bus/devices. The ACPI specification defines a bit (Producer/Consumer)
> > + * to tell whether the resource is consumed by the host bridge itself,
> > + * but firmware hasn't used that bit consistently, so we can't rely on it.
> > + *
> > + * On x86 and IA64 platforms, all IO port and MMIO resources are assumed
> > + * to be available to child bus/devices except one special case:
> > + *     IO port [0xCF8-0xCFF] is consumed by the host bridge itself
> > + *     to access PCI configuration space.
> > + *
> > + * So explicitly filter out PCI CFG IO ports[0xCF8-0xCFF].
> > + */
> > +static bool resource_is_pcicfg_ioport(struct resource *res)
> > +{
> > +       return (res->flags & IORESOURCE_IO) &&
> > +               res->start == 0xCF8 && res->end == 0xCFF;
> > +}
> > +
> >  static void probe_pci_root_info(struct pci_root_info *info,
> >                                 struct acpi_device *device,
> >                                 int busnum, int domain,
> > @@ -346,8 +366,8 @@ static void probe_pci_root_info(struct pci_root_info *info,
> >                         "no IO and memory resources present in _CRS\n");
> >         else
> >                 resource_list_for_each_entry_safe(entry, tmp, list) {
> > -                       if ((entry->res->flags & IORESOURCE_WINDOW) == 0 ||
> > -                           (entry->res->flags & IORESOURCE_DISABLED))
> > +                       if ((entry->res->flags & IORESOURCE_DISABLED) ||
> > +                           resource_is_pcicfg_ioport(entry->res))
> 
> Hey, I can understand this code!  This is *way* better that what you
> had before.  Thanks for persevering.
> 
> My only remaining comment is that the subject line ("Fix regression
> caused by commit ...") doesn't really describe the code.  It should
> say something specific, like maybe "x86/PCI/ACPI: Make all resources
> except [io 0xcf8-0xcff] available on PCI bus".
> 
> Reviewed-by: Bjorn Helgaas <bhelgaas@google.com>

Awesome, thanks!

I'm sending my pull request for -rc2 shortly, so I'll queue this one up for
the next week.  I'll follow your subject suggestion.

Ingo, please let me know if there's any problem with that.

Rafael


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

end of thread, other threads:[~2015-04-30 19:51 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-20  3:08 [Bugfix v5] x86/PCI/ACPI: Fix regression caused by commit 63f1789ec716 Jiang Liu
2015-04-29  0:40 ` Rafael J. Wysocki
2015-04-29 13:20   ` Bjorn Helgaas
2015-04-29 13:33     ` Jiang Liu
2015-04-29 13:37       ` Bjorn Helgaas
2015-04-30  4:41         ` [Bugfix v6] " Jiang Liu
2015-04-30 13:28           ` Bjorn Helgaas
2015-04-30 20:16             ` Rafael J. Wysocki
2015-04-29 14:15       ` [Bugfix v5] " Rafael J. Wysocki
2015-04-29 13:53         ` Jiang Liu
  -- strict thread matches above, loose matches on Subject: below --
2015-04-13  4:31 [Bugfix v3] " Jiang Liu
2015-04-13  6:38 ` [Bugfix v5] " Jiang Liu
2015-04-13  6:56   ` Ingo Molnar
2015-04-13 12:05     ` Rafael J. Wysocki

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