All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] ACPI: APEI: Filter the PCI MCFG address with an arch-agnostic method
@ 2021-10-06  2:47 ` Xuesong Chen
  0 siblings, 0 replies; 4+ messages in thread
From: Xuesong Chen @ 2021-10-06  2:47 UTC (permalink / raw)
  To: catalin.marinas, lorenzo.pieralisi, james.morse, will, rafael,
	tony.luck, bp, mingo, bhelgaas
  Cc: steve.capper, mark.rutland, linux-pci, linux-acpi,
	linux-arm-kernel, linux-kernel, xuesong.chen

The commit d91525eb8ee6 ("ACPI, EINJ: Enhance error injection tolerance
level") fixes the issue that the ACPI/APEI can not access the PCI MCFG
address on x86 platform, but this issue can also happen on other
architectures, for instance, we got below error message on arm64 platform:
...
APEI: Can not request [mem 0x50100000-0x50100003] for APEI EINJ Trigger registers
...

This patch will try to handle this case in a more common way instead of the
original 'arch' specific solution, which will be beneficial to all the
APEI-dependent platforms after that.

Signed-off-by: Xuesong Chen <xuesong.chen@linux.alibaba.com>
---
 arch/x86/pci/mmconfig-shared.c | 28 ----------------------------
 drivers/acpi/apei/apei-base.c  | 42 ++++++++++++++++++++++++++----------------
 2 files changed, 26 insertions(+), 44 deletions(-)

diff --git a/arch/x86/pci/mmconfig-shared.c b/arch/x86/pci/mmconfig-shared.c
index 0b961fe6..12f7d96 100644
--- a/arch/x86/pci/mmconfig-shared.c
+++ b/arch/x86/pci/mmconfig-shared.c
@@ -605,32 +605,6 @@ static int __init pci_parse_mcfg(struct acpi_table_header *header)
 	return 0;
 }
 
-#ifdef CONFIG_ACPI_APEI
-extern int (*arch_apei_filter_addr)(int (*func)(__u64 start, __u64 size,
-				     void *data), void *data);
-
-static int pci_mmcfg_for_each_region(int (*func)(__u64 start, __u64 size,
-				     void *data), void *data)
-{
-	struct pci_mmcfg_region *cfg;
-	int rc;
-
-	if (list_empty(&pci_mmcfg_list))
-		return 0;
-
-	list_for_each_entry(cfg, &pci_mmcfg_list, list) {
-		rc = func(cfg->res.start, resource_size(&cfg->res), data);
-		if (rc)
-			return rc;
-	}
-
-	return 0;
-}
-#define set_apei_filter() (arch_apei_filter_addr = pci_mmcfg_for_each_region)
-#else
-#define set_apei_filter()
-#endif
-
 static void __init __pci_mmcfg_init(int early)
 {
 	pci_mmcfg_reject_broken(early);
@@ -665,8 +639,6 @@ void __init pci_mmcfg_early_init(void)
 		else
 			acpi_table_parse(ACPI_SIG_MCFG, pci_parse_mcfg);
 		__pci_mmcfg_init(1);
-
-		set_apei_filter();
 	}
 }
 
diff --git a/drivers/acpi/apei/apei-base.c b/drivers/acpi/apei/apei-base.c
index c7fdb12..fa65792 100644
--- a/drivers/acpi/apei/apei-base.c
+++ b/drivers/acpi/apei/apei-base.c
@@ -21,6 +21,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/init.h>
+#include <linux/pci.h>
 #include <linux/acpi.h>
 #include <linux/slab.h>
 #include <linux/io.h>
@@ -34,6 +35,8 @@
 
 #define APEI_PFX "APEI: "
 
+extern struct list_head pci_mmcfg_list;
+
 /*
  * APEI ERST (Error Record Serialization Table) and EINJ (Error
  * INJection) interpreter framework.
@@ -448,12 +451,26 @@ static int apei_get_nvs_resources(struct apei_resources *resources)
 	return acpi_nvs_for_each_region(apei_get_res_callback, resources);
 }
 
-int (*arch_apei_filter_addr)(int (*func)(__u64 start, __u64 size,
-				     void *data), void *data);
-static int apei_get_arch_resources(struct apei_resources *resources)
-
+static int apei_filter_mcfg_addr(struct apei_resources *res,
+			struct apei_resources *mcfg_res)
 {
-	return arch_apei_filter_addr(apei_get_res_callback, resources);
+	int rc = 0;
+	struct pci_mmcfg_region *cfg;
+
+	if (list_empty(&pci_mmcfg_list))
+		return 0;
+
+	apei_resources_init(mcfg_res);
+	list_for_each_entry(cfg, &pci_mmcfg_list, list) {
+		rc = apei_res_add(&mcfg_res->iomem, cfg->res.start, resource_size(&cfg->res));
+		if (rc)
+			return rc;
+	}
+
+	/* filter the mcfg resource from current APEI's */
+	rc = apei_resources_sub(res, mcfg_res);
+
+	return rc;
 }
 
 /*
@@ -486,15 +503,9 @@ int apei_resources_request(struct apei_resources *resources,
 	if (rc)
 		goto nvs_res_fini;
 
-	if (arch_apei_filter_addr) {
-		apei_resources_init(&arch_res);
-		rc = apei_get_arch_resources(&arch_res);
-		if (rc)
-			goto arch_res_fini;
-		rc = apei_resources_sub(resources, &arch_res);
-		if (rc)
-			goto arch_res_fini;
-	}
+	rc = apei_filter_mcfg_addr(resources, &arch_res);
+	if (rc)
+		goto arch_res_fini;
 
 	rc = -EINVAL;
 	list_for_each_entry(res, &resources->iomem, list) {
@@ -544,8 +555,7 @@ int apei_resources_request(struct apei_resources *resources,
 		release_mem_region(res->start, res->end - res->start);
 	}
 arch_res_fini:
-	if (arch_apei_filter_addr)
-		apei_resources_fini(&arch_res);
+	apei_resources_fini(&arch_res);
 nvs_res_fini:
 	apei_resources_fini(&nvs_resources);
 	return rc;
-- 
1.8.3.1


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

* [PATCH 2/2] ACPI: APEI: Filter the PCI MCFG address with an arch-agnostic method
@ 2021-10-06  2:47 ` Xuesong Chen
  0 siblings, 0 replies; 4+ messages in thread
From: Xuesong Chen @ 2021-10-06  2:47 UTC (permalink / raw)
  To: catalin.marinas, lorenzo.pieralisi, james.morse, will, rafael,
	tony.luck, bp, mingo, bhelgaas
  Cc: steve.capper, mark.rutland, linux-pci, linux-acpi,
	linux-arm-kernel, linux-kernel, xuesong.chen

The commit d91525eb8ee6 ("ACPI, EINJ: Enhance error injection tolerance
level") fixes the issue that the ACPI/APEI can not access the PCI MCFG
address on x86 platform, but this issue can also happen on other
architectures, for instance, we got below error message on arm64 platform:
...
APEI: Can not request [mem 0x50100000-0x50100003] for APEI EINJ Trigger registers
...

This patch will try to handle this case in a more common way instead of the
original 'arch' specific solution, which will be beneficial to all the
APEI-dependent platforms after that.

Signed-off-by: Xuesong Chen <xuesong.chen@linux.alibaba.com>
---
 arch/x86/pci/mmconfig-shared.c | 28 ----------------------------
 drivers/acpi/apei/apei-base.c  | 42 ++++++++++++++++++++++++++----------------
 2 files changed, 26 insertions(+), 44 deletions(-)

diff --git a/arch/x86/pci/mmconfig-shared.c b/arch/x86/pci/mmconfig-shared.c
index 0b961fe6..12f7d96 100644
--- a/arch/x86/pci/mmconfig-shared.c
+++ b/arch/x86/pci/mmconfig-shared.c
@@ -605,32 +605,6 @@ static int __init pci_parse_mcfg(struct acpi_table_header *header)
 	return 0;
 }
 
-#ifdef CONFIG_ACPI_APEI
-extern int (*arch_apei_filter_addr)(int (*func)(__u64 start, __u64 size,
-				     void *data), void *data);
-
-static int pci_mmcfg_for_each_region(int (*func)(__u64 start, __u64 size,
-				     void *data), void *data)
-{
-	struct pci_mmcfg_region *cfg;
-	int rc;
-
-	if (list_empty(&pci_mmcfg_list))
-		return 0;
-
-	list_for_each_entry(cfg, &pci_mmcfg_list, list) {
-		rc = func(cfg->res.start, resource_size(&cfg->res), data);
-		if (rc)
-			return rc;
-	}
-
-	return 0;
-}
-#define set_apei_filter() (arch_apei_filter_addr = pci_mmcfg_for_each_region)
-#else
-#define set_apei_filter()
-#endif
-
 static void __init __pci_mmcfg_init(int early)
 {
 	pci_mmcfg_reject_broken(early);
@@ -665,8 +639,6 @@ void __init pci_mmcfg_early_init(void)
 		else
 			acpi_table_parse(ACPI_SIG_MCFG, pci_parse_mcfg);
 		__pci_mmcfg_init(1);
-
-		set_apei_filter();
 	}
 }
 
diff --git a/drivers/acpi/apei/apei-base.c b/drivers/acpi/apei/apei-base.c
index c7fdb12..fa65792 100644
--- a/drivers/acpi/apei/apei-base.c
+++ b/drivers/acpi/apei/apei-base.c
@@ -21,6 +21,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/init.h>
+#include <linux/pci.h>
 #include <linux/acpi.h>
 #include <linux/slab.h>
 #include <linux/io.h>
@@ -34,6 +35,8 @@
 
 #define APEI_PFX "APEI: "
 
+extern struct list_head pci_mmcfg_list;
+
 /*
  * APEI ERST (Error Record Serialization Table) and EINJ (Error
  * INJection) interpreter framework.
@@ -448,12 +451,26 @@ static int apei_get_nvs_resources(struct apei_resources *resources)
 	return acpi_nvs_for_each_region(apei_get_res_callback, resources);
 }
 
-int (*arch_apei_filter_addr)(int (*func)(__u64 start, __u64 size,
-				     void *data), void *data);
-static int apei_get_arch_resources(struct apei_resources *resources)
-
+static int apei_filter_mcfg_addr(struct apei_resources *res,
+			struct apei_resources *mcfg_res)
 {
-	return arch_apei_filter_addr(apei_get_res_callback, resources);
+	int rc = 0;
+	struct pci_mmcfg_region *cfg;
+
+	if (list_empty(&pci_mmcfg_list))
+		return 0;
+
+	apei_resources_init(mcfg_res);
+	list_for_each_entry(cfg, &pci_mmcfg_list, list) {
+		rc = apei_res_add(&mcfg_res->iomem, cfg->res.start, resource_size(&cfg->res));
+		if (rc)
+			return rc;
+	}
+
+	/* filter the mcfg resource from current APEI's */
+	rc = apei_resources_sub(res, mcfg_res);
+
+	return rc;
 }
 
 /*
@@ -486,15 +503,9 @@ int apei_resources_request(struct apei_resources *resources,
 	if (rc)
 		goto nvs_res_fini;
 
-	if (arch_apei_filter_addr) {
-		apei_resources_init(&arch_res);
-		rc = apei_get_arch_resources(&arch_res);
-		if (rc)
-			goto arch_res_fini;
-		rc = apei_resources_sub(resources, &arch_res);
-		if (rc)
-			goto arch_res_fini;
-	}
+	rc = apei_filter_mcfg_addr(resources, &arch_res);
+	if (rc)
+		goto arch_res_fini;
 
 	rc = -EINVAL;
 	list_for_each_entry(res, &resources->iomem, list) {
@@ -544,8 +555,7 @@ int apei_resources_request(struct apei_resources *resources,
 		release_mem_region(res->start, res->end - res->start);
 	}
 arch_res_fini:
-	if (arch_apei_filter_addr)
-		apei_resources_fini(&arch_res);
+	apei_resources_fini(&arch_res);
 nvs_res_fini:
 	apei_resources_fini(&nvs_resources);
 	return rc;
-- 
1.8.3.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 2/2] ACPI: APEI: Filter the PCI MCFG address with an arch-agnostic method
  2021-10-06  2:47 ` Xuesong Chen
  (?)
@ 2021-10-06  8:12 ` kernel test robot
  2021-10-08  4:36   ` Xuesong Chen
  -1 siblings, 1 reply; 4+ messages in thread
From: kernel test robot @ 2021-10-06  8:12 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 2448 bytes --]

Hi Xuesong,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on helgaas-pci/next]
[also build test ERROR on arm64/for-next/core tip/x86/core rafael-pm/linux-next v5.15-rc3 next-20210922]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Xuesong-Chen/PCI-MCFG-consolidation-and-APEI-resource-filtering/20211006-104914
base:   https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git next
config: arm64-randconfig-r016-20211004 (attached as .config)
compiler: aarch64-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/5b078b52f2babaacc9958d44f22c47f5ddc8e803
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Xuesong-Chen/PCI-MCFG-consolidation-and-APEI-resource-filtering/20211006-104914
        git checkout 5b078b52f2babaacc9958d44f22c47f5ddc8e803
        # save the attached .config to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=arm64 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   aarch64-linux-ld: drivers/acpi/apei/apei-base.o: in function `apei_resources_request.part.0':
>> apei-base.c:(.text+0x1470): undefined reference to `pci_mmcfg_list'
   aarch64-linux-ld: drivers/acpi/apei/apei-base.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `pci_mmcfg_list' which may bind externally can not be used when making a shared object; recompile with -fPIC
   apei-base.c:(.text+0x1470): dangerous relocation: unsupported relocation
>> aarch64-linux-ld: apei-base.c:(.text+0x1478): undefined reference to `pci_mmcfg_list'
   aarch64-linux-ld: apei-base.c:(.text+0x147c): undefined reference to `pci_mmcfg_list'
   aarch64-linux-ld: apei-base.c:(.text+0x1488): undefined reference to `pci_mmcfg_list'

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 46847 bytes --]

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

* Re: [PATCH 2/2] ACPI: APEI: Filter the PCI MCFG address with an arch-agnostic method
  2021-10-06  8:12 ` kernel test robot
@ 2021-10-08  4:36   ` Xuesong Chen
  0 siblings, 0 replies; 4+ messages in thread
From: Xuesong Chen @ 2021-10-08  4:36 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 3613 bytes --]

Hello All:

Refer to the below CONFIG_PCI dependency chain:

        ---> PCI_MMCONFIG(n) (x86) 
       /
PCI(n) ----> ACPI_MCFG(n) (arm64)

IOW, if CONFIG_PCI is not defined, then neither MMCONFIG nor MCFG will be defined, we only
need a static empty pci_mmcfg_list in APEI (which is independent of CONFIG_PCI) to avoid the
'undefined reference to `pci_mmcfg_list' build error, with the code logic untached.

If CONFIG_PCI is defined, then no matter PCI_MMCONFIG/ACPI_MCFG is defined or not, the original
patch can hanle it well.

So I plan to mitigate this build issue with below diff:

diff --git a/drivers/acpi/apei/apei-base.c b/drivers/acpi/apei/apei-base.c
index fa65792..7cca6ba 100644
--- a/drivers/acpi/apei/apei-base.c
+++ b/drivers/acpi/apei/apei-base.c
@@ -35,7 +35,11 @@
 
 #define APEI_PFX "APEI: "
 
+#ifdef CONFIG_PCI
 extern struct list_head pci_mmcfg_list;
+#else
+static LIST_HEAD(pci_mmcfg_list);
+#endif


I will re-send the patch set to fix this if nobody objects...

Xuesong

On 06/10/2021 16:12, kernel test robot wrote:
> Hi Xuesong,
> 
> Thank you for the patch! Yet something to improve:
> 
> [auto build test ERROR on helgaas-pci/next]
> [also build test ERROR on arm64/for-next/core tip/x86/core rafael-pm/linux-next v5.15-rc3 next-20210922]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch]
> 
> url:    https://github.com/0day-ci/linux/commits/Xuesong-Chen/PCI-MCFG-consolidation-and-APEI-resource-filtering/20211006-104914
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git next
> config: arm64-randconfig-r016-20211004 (attached as .config)
> compiler: aarch64-linux-gcc (GCC) 11.2.0
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # https://github.com/0day-ci/linux/commit/5b078b52f2babaacc9958d44f22c47f5ddc8e803
>         git remote add linux-review https://github.com/0day-ci/linux
>         git fetch --no-tags linux-review Xuesong-Chen/PCI-MCFG-consolidation-and-APEI-resource-filtering/20211006-104914
>         git checkout 5b078b52f2babaacc9958d44f22c47f5ddc8e803
>         # save the attached .config to linux build tree
>         mkdir build_dir
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=arm64 SHELL=/bin/bash
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
> 
> All errors (new ones prefixed by >>):
> 
>    aarch64-linux-ld: drivers/acpi/apei/apei-base.o: in function `apei_resources_request.part.0':
>>> apei-base.c:(.text+0x1470): undefined reference to `pci_mmcfg_list'
>    aarch64-linux-ld: drivers/acpi/apei/apei-base.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `pci_mmcfg_list' which may bind externally can not be used when making a shared object; recompile with -fPIC
>    apei-base.c:(.text+0x1470): dangerous relocation: unsupported relocation
>>> aarch64-linux-ld: apei-base.c:(.text+0x1478): undefined reference to `pci_mmcfg_list'
>    aarch64-linux-ld: apei-base.c:(.text+0x147c): undefined reference to `pci_mmcfg_list'
>    aarch64-linux-ld: apei-base.c:(.text+0x1488): undefined reference to `pci_mmcfg_list'
> 
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
> 

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

end of thread, other threads:[~2021-10-08  4:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-06  2:47 [PATCH 2/2] ACPI: APEI: Filter the PCI MCFG address with an arch-agnostic method Xuesong Chen
2021-10-06  2:47 ` Xuesong Chen
2021-10-06  8:12 ` kernel test robot
2021-10-08  4:36   ` Xuesong Chen

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.