From: Ben Cheatham <Benjamin.Cheatham@amd.com>
To: <rafael@kernel.org>, <dan.j.williams@intel.com>,
<linux-cxl@vger.kernel.org>, <linux-acpi@vger.kernel.org>
Cc: <bhelgaas@google.com>, <benjamin.cheatham@amd.com>,
<yazen.ghannam@amd.com>
Subject: [PATCH v4 2/3] ACPI, APEI, EINJ: Add CXL 1.1 EINJ error type support
Date: Thu, 7 Sep 2023 14:19:55 -0500 [thread overview]
Message-ID: <20230907191956.674833-3-Benjamin.Cheatham@amd.com> (raw)
In-Reply-To: <20230907191956.674833-1-Benjamin.Cheatham@amd.com>
Add support for CXL EINJ error types for CXL 1.1 hosts added in ACPI
v6.5. Because these error types target memory-mapped CXL 1.1 compliant
downstream ports and not physical (normal/persistent) memory, these
error types are not currently allowed through the memory range
validation done by the EINJ driver.
The MMIO address of a CXL 1.1 downstream port can be found in the
cxl_rcrb_addr file in the corresponding dport directory under
/sys/bus/cxl/devices/portX. CXL 1.1 error types follow the same
procedure as a memory error type, but with param1 set to the
downstream port MMIO address.
Example usage:
$ cd /sys/kernel/debug/apei/einj
$ cat available_error_type
0x00000008 Memory Correctable
0x00000010 Memory Uncorrectable non-fatal
0x00000020 Memory Uncorrectable fatal
0x00000040 PCI Express Correctable
0x00000080 PCI Express Uncorrectable non-fatal
0x00000100 PCI Express Uncorrectable fatal
0x00008000 CXL.mem Protocol Correctable
0x00020000 CXL.mem Protocol Uncorrectable fatal
$ echo 0x8000 > error_type
$ echo 0xfffffffffffff000 > param2
$ echo 0x3 > flags
$ cat /sys/bus/cxl/devices/portX/dportY/cxl_rcrb_addr
0xb2f00000
$ echo 0xb2f00000 > param1
$ echo 1 > error_inject
Signed-off-by: Ben Cheatham <Benjamin.Cheatham@amd.com>
---
drivers/acpi/apei/Kconfig | 2 ++
drivers/acpi/apei/einj.c | 24 +++++++++++++++++++++++-
drivers/cxl/core/port.c | 19 +++++++++++++++++++
drivers/cxl/cxl.h | 1 +
include/linux/cxl.h | 18 ++++++++++++++++++
5 files changed, 63 insertions(+), 1 deletion(-)
create mode 100644 include/linux/cxl.h
diff --git a/drivers/acpi/apei/Kconfig b/drivers/acpi/apei/Kconfig
index 6b18f8bc7be3..eb9cc7157342 100644
--- a/drivers/acpi/apei/Kconfig
+++ b/drivers/acpi/apei/Kconfig
@@ -55,6 +55,8 @@ config ACPI_APEI_MEMORY_FAILURE
config ACPI_APEI_EINJ
tristate "APEI Error INJection (EINJ)"
depends on ACPI_APEI && DEBUG_FS
+ imply CXL_BUS
+ imply CXL_ACPI
help
EINJ provides a hardware error injection mechanism, it is
mainly used for debugging and testing the other parts of
diff --git a/drivers/acpi/apei/einj.c b/drivers/acpi/apei/einj.c
index 013eb621dc92..8000417a5f26 100644
--- a/drivers/acpi/apei/einj.c
+++ b/drivers/acpi/apei/einj.c
@@ -21,6 +21,7 @@
#include <linux/nmi.h>
#include <linux/delay.h>
#include <linux/mm.h>
+#include <linux/cxl.h>
#include <asm/unaligned.h>
#include "apei-internal.h"
@@ -36,6 +37,7 @@
#define MEM_ERROR_MASK (ACPI_EINJ_MEMORY_CORRECTABLE | \
ACPI_EINJ_MEMORY_UNCORRECTABLE | \
ACPI_EINJ_MEMORY_FATAL)
+#define CXL_ERROR_MASK GENMASK(17, 12)
/*
* ACPI version 5 provides a SET_ERROR_TYPE_WITH_ADDRESS action.
@@ -512,6 +514,22 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,
return rc;
}
+static int is_valid_cxl_addr(u64 addr)
+{
+ struct cxl_dport *dport;
+
+ if (IS_REACHABLE(CONFIG_CXL_ACPI))
+ dport = cxl_find_rch_dport_by_rcrb((resource_size_t) addr);
+ else
+ return 0;
+
+ if (!IS_ERR_OR_NULL(dport))
+ return 1;
+
+ pr_info("Could not find dport with rcrb 0x%llx\n", addr);
+ return 0;
+}
+
/* Inject the specified hardware error */
static int einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,
u64 param3, u64 param4)
@@ -537,8 +555,11 @@ static int einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,
if (type & ACPI5_VENDOR_BIT) {
if (vendor_flags != SETWA_FLAGS_MEM)
goto inject;
- } else if (!(type & MEM_ERROR_MASK) && !(flags & SETWA_FLAGS_MEM))
+ } else if (!(type & MEM_ERROR_MASK) && !(flags & SETWA_FLAGS_MEM)) {
goto inject;
+ } else if (type & CXL_ERROR_MASK && is_valid_cxl_addr(param1)) {
+ goto inject;
+ }
/*
* Disallow crazy address masks that give BIOS leeway to pick
@@ -807,3 +828,4 @@ module_exit(einj_exit);
MODULE_AUTHOR("Huang Ying");
MODULE_DESCRIPTION("APEI Error INJection support");
MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS(CXL);
diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c
index 001ab8742e21..f8f300496140 100644
--- a/drivers/cxl/core/port.c
+++ b/drivers/cxl/core/port.c
@@ -1122,6 +1122,25 @@ struct cxl_dport *devm_cxl_add_rch_dport(struct cxl_port *port,
}
EXPORT_SYMBOL_NS_GPL(devm_cxl_add_rch_dport, CXL);
+#if IS_ENABLED(CONFIG_CXL_ACPI)
+struct cxl_dport *cxl_find_rch_dport_by_rcrb(resource_size_t rcrb_base)
+{
+ struct cxl_dport *dport;
+ unsigned long index;
+
+ if (!cxl_root)
+ return ERR_PTR(-ENODEV);
+
+ xa_for_each(&cxl_root->dports, index, dport)
+ if ((dport->rch && dport->rcrb.base != CXL_RESOURCE_NONE)
+ && dport->rcrb.base == rcrb_base)
+ return dport;
+
+ return NULL;
+}
+EXPORT_SYMBOL_NS_GPL(cxl_find_rch_dport_by_rcrb, CXL);
+#endif
+
static int add_ep(struct cxl_ep *new)
{
struct cxl_port *port = new->dport->port;
diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
index 4d5bce4bae7e..3e6779dbcd23 100644
--- a/drivers/cxl/cxl.h
+++ b/drivers/cxl/cxl.h
@@ -8,6 +8,7 @@
#include <linux/bitfield.h>
#include <linux/bitops.h>
#include <linux/log2.h>
+#include <linux/cxl.h>
#include <linux/io.h>
/**
diff --git a/include/linux/cxl.h b/include/linux/cxl.h
new file mode 100644
index 000000000000..b57a4cc85005
--- /dev/null
+++ b/include/linux/cxl.h
@@ -0,0 +1,18 @@
+#ifndef _LINUX_CXL_H
+#define _LINUX_CXL_H
+
+#include <linux/xarray.h>
+#include <linux/errno.h>
+
+struct cxl_dport;
+
+#if IS_ENABLED(CONFIG_CXL_ACPI)
+struct cxl_dport *cxl_find_rch_dport_by_rcrb(resource_size_t rcrb_base);
+#else
+static inline struct cxl_dport *cxl_find_rch_dport_by_rcrb(resource_size_t rcrb_base)
+{
+ return NULL;
+}
+#endif
+
+#endif
--
2.34.1
next prev parent reply other threads:[~2023-09-07 19:21 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-07 19:19 [PATCH v4 0/3] CXL, ACPI, APEI, EINJ: Update EINJ for CXL 1.1 error types Ben Cheatham
2023-09-07 19:19 ` [PATCH v4 1/3] CXL, PCIE: Add cxl_rcrb_addr file to dport_dev Ben Cheatham
2023-09-12 14:11 ` Jonathan Cameron
2023-09-12 14:49 ` Ben Cheatham
2023-09-12 16:33 ` Jonathan Cameron
2023-09-07 19:19 ` Ben Cheatham [this message]
2023-09-12 14:00 ` [PATCH v4 2/3] ACPI, APEI, EINJ: Add CXL 1.1 EINJ error type support Jonathan Cameron
2023-09-12 14:49 ` Ben Cheatham
2023-09-07 19:19 ` [PATCH v4 3/3] ACPI, APEI, EINJ: Update EINJ documentation Ben Cheatham
2023-09-12 13:51 ` Jonathan Cameron
-- strict thread matches above, loose matches on Subject: below --
2023-09-22 19:39 [PATCH v4 2/3] ACPI, APEI, EINJ: Add CXL 1.1 EINJ error type support kernel test robot
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=20230907191956.674833-3-Benjamin.Cheatham@amd.com \
--to=benjamin.cheatham@amd.com \
--cc=bhelgaas@google.com \
--cc=dan.j.williams@intel.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=yazen.ghannam@amd.com \
/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.