All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xuesong Chen <xuesong.chen@linux.alibaba.com>
To: linux-arm-kernel@lists.infradead.org
Cc: catalin.marinas@arm.com, will@kernel.org, steve.capper@arm.com,
	lorenzo.pieralisi@arm.com, mark.rutland@arm.com,
	xuesong.chen@linux.alibaba.com
Subject: [PATCH] arm64/apei: Filter the apei GAS address from the ECAM space
Date: Wed, 8 Sep 2021 15:02:53 +0800	[thread overview]
Message-ID: <YThgHU7eeLo9wnMW@Dennis-MBP.local> (raw)

ECAM configuration memory space is reserved during the initializaion of the
kernel, but sometimes the apei needs to access the GAS address within the
ECAM space, thus the request_mem_region(...) will be failed in this case,
the error message looks like:
...
APEI: Can not request [mem 0x50100000-0x50100003] for APEI EINJ Trigger registers
...

This patch provides an arm64 specific filter function to remove the GAS address
range from the reserved ECAM resource regions, which will make the apei's GAS
address can pass the check while not affecting the original reserved ECAM area.

Signed-off-by: Xuesong Chen <xuesong.chen@linux.alibaba.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Steve Capper <steve.capper@arm.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
---
 arch/arm64/kernel/pci.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/arch/arm64/kernel/pci.c b/arch/arm64/kernel/pci.c
index 1006ed2..6096165 100644
--- a/arch/arm64/kernel/pci.c
+++ b/arch/arm64/kernel/pci.c
@@ -19,6 +19,13 @@
 #include <linux/slab.h>
 
 #ifdef CONFIG_ACPI
+struct pci_mcfg_res_region {
+	struct list_head list;
+	struct resource res;
+};
+
+static LIST_HEAD(pci_mcfg_res_list);
+static DEFINE_MUTEX(pci_mcfg_lock);
 /*
  * Try to assign the IRQ number when probing a new device
  */
@@ -107,6 +114,58 @@ static int pci_acpi_root_prepare_resources(struct acpi_pci_root_info *ci)
 	return status;
 }
 
+#ifdef CONFIG_ACPI_APEI
+extern int (*arch_apei_filter_addr)(int (*func)(__u64 start, __u64 size,
+		void *data), void *data);
+
+static int pci_mcfg_for_each_region(int (*func)(__u64 start, __u64 size,
+		void *data), void *data)
+{
+	struct pci_mcfg_res_region *e;
+	int rc = 0;
+
+	if (list_empty(&pci_mcfg_res_list))
+		return 0;
+
+	list_for_each_entry(e, &pci_mcfg_res_list, list) {
+		rc = func(e->res.start, resource_size(&e->res), data);
+		if (rc)
+			return rc;
+	}
+
+	return 0;
+}
+
+#define set_apei_filter() \
+	do { \
+		if (!arch_apei_filter_addr) \
+			arch_apei_filter_addr = pci_mcfg_for_each_region; \
+	} while (0)
+#else
+#define set_apei_filter()
+#endif
+
+static int pci_mcfg_res_add(struct resource *res)
+{
+	struct pci_mcfg_res_region *new;
+
+	if (!res)
+		return -EINVAL;
+
+	new = kzalloc(sizeof(*new), GFP_KERNEL);
+	if (!new)
+		return -ENOMEM;
+
+	new->res.start = res->start;
+	new->res.end = res->end;
+
+	mutex_lock(&pci_mcfg_lock);
+	list_add(&new->list, &pci_mcfg_res_list);
+	mutex_unlock(&pci_mcfg_lock);
+
+	return 0;
+}
+
 /*
  * Lookup the bus range for the domain in MCFG, and set up config space
  * mapping.
@@ -144,6 +203,11 @@ static int pci_acpi_root_prepare_resources(struct acpi_pci_root_info *ci)
 		return NULL;
 	}
 
+	/* insert the mcfg resource region of current segment into the list */
+	ret = pci_mcfg_res_add(&cfgres);
+	if (ret)
+		dev_warn(dev, "add %pR into the mcfg res list failed\n", &cfgres);
+
 	return cfg;
 }
 
@@ -204,6 +268,8 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
 	list_for_each_entry(child, &bus->children, node)
 		pcie_bus_configure_settings(child);
 
+	set_apei_filter();
+
 	return bus;
 }
 
-- 
1.8.3.1


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

             reply	other threads:[~2021-09-08  7:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-08  7:02 Xuesong Chen [this message]
2021-09-29  1:32 ` [PATCH] arm64/apei: Filter the apei GAS address from the ECAM space Xuesong Chen
2021-09-29 12:59 ` Lorenzo Pieralisi
2021-09-29 12:59   ` Lorenzo Pieralisi
2021-09-30  5:56   ` Xuesong Chen
2021-09-30  5:56     ` Xuesong Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YThgHU7eeLo9wnMW@Dennis-MBP.local \
    --to=xuesong.chen@linux.alibaba.com \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=mark.rutland@arm.com \
    --cc=steve.capper@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.