cxl, EINJ: Update EINJ for CXL error types
v14 cover cxl, EINJ: Update EINJ for CXL error types
v14 Changes:
- Remove einj-cxl module and instead compile as part of EINJ module (Dan)
- Change CONFIG_ACPI_APEI_EINJ_CXL from tristate to bool (Dan)
- Fix CONFIG_ACPI_APEI_EINJ_CXL/CONFIG_CXL_BUS dependencies
- Remove EINJ function exports (Dan)
- Organizational changes for CXL content in EINJ kernel documentation (Dan)
- Demote "EINJ table not found." print to pr_debug() from pr_info() (Dan)
v13 Changes:
- Create new einj-cxl module for EINJ CXL error type functionality
- Rename CONFIG_CXL_EINJ to CONFIG_ACPI_APEI_EINJ_CXL
- Move CONFIG_ACPI_APEI_CXL to be under CONFIG_ACPI_APEI_EINJ (due to new CONFIG_CXL_BUS dependency)
- Add an optional dependency to CONFIG_CXL_BUS on CONFIG_ACPI_APEI_EINJ_CXL
- Change pr_warn("EINJ table not found.") to a pr_info() for when/if EINJ probe fails (Tony)
- Add a clarification that a CXL port needs to be present for CXL EINJ error types to einj.rst (Davidlohr)
The new CXL error types will use the Memory Address field in the SET_ERROR_TYPE_WITH_ADDRESS structure in order to target a CXL 1.1 compliant memory-mapped downstream port. The value of the memory address will be in the port's MMIO range, and it will not represent physical (normal or persistent) memory.
Add the functionality for injecting CXL 1.1 errors to the EINJ module, but not through the EINJ legacy interface under /sys/kernel/debug/apei/einj. Instead, make the error types available under /sys/kernel/debug/cxl. This allows for validating the MMIO address for a CXL 1.1 error type while also not making the user responsible for finding it.
Ben Cheatham (4):
EINJ: Migrate to a platform driver
EINJ: Add CXL error type support
cxl/core: Add CXL EINJ debugfs files
EINJ, Documentation: Update EINJ kernel doc
Documentation/ABI/testing/debugfs-cxl | 30 +++++
.../firmware-guide/acpi/apei/einj.rst | 34 +++++
MAINTAINERS | 1 +
drivers/acpi/apei/Kconfig | 12 ++
drivers/acpi/apei/Makefile | 2 +
drivers/acpi/apei/apei-internal.h | 16 +++
drivers/acpi/apei/{einj.c => einj-core.c} | 124 ++++++++++++++----
drivers/acpi/apei/einj-cxl.c | 120 +++++++++++++++++
drivers/cxl/core/port.c | 41 ++++++
include/linux/einj-cxl.h | 40 ++++++
10 files changed, 392 insertions(+), 28 deletions(-)
rename drivers/acpi/apei/{einj.c => einj-core.c} (91%)
create mode 100644 drivers/acpi/apei/einj-cxl.c
create mode 100644 include/linux/einj-cxl.hSignature · 1 line
2.34.1
PATCH v14 1/4 EINJ: Migrate to a platform driver
Change the EINJ module to install a platform device/driver on module init and move the module init() and exit() functions to driver probe and remove. This change allows the EINJ module to load regardless of whether setting up EINJ succeeds, which allows dependent modules to still load (i.e. the CXL core).
Since EINJ may no longer be initialized when the module loads, any functions that are called from dependent/external modules should check the einj_initialized variable before calling any EINJ functions.
--- drivers/acpi/apei/einj.c | 48 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-)
drivers/acpi/apei/einj.c +44 -4
@@ -21,6 +21,7 @@#include <linux/nmi.h> #include <linux/delay.h> #include <linux/mm.h> +#include <linux/platform_device.h> #include <asm/unaligned.h> #include "apei-internal.h"
@@ -137,6 +138,11 @@ static struct apei_exec_ins_type einj_ins_type[] = {*/ static DEFINE_MUTEX (einj_mutex); +/* +* Exported APIs use this flag to exit early if einj_probe() failed. +*/ +static bool einj_initialized__ro_after_init ; +static void *einj_param;static void einj_exec_ctx_init (struct apei_exec_context *ctx)
@@ -703,21 +709,21 @@ static int einj_check_table(struct acpi_table_einj *einj_tab)return 0 ; } -static int __init einj_init (void ) +static int __init einj_probe (struct platform_device *pdev) {int rc;acpi_status status;struct apei_exec_context ctx;if (acpi_disabled) { -pr_info ("ACPI disabled.\n" ); +pr_debug ("ACPI disabled.\n" );return -ENODEV ; } status =acpi_get_table (ACPI_SIG_EINJ ,0 , (struct acpi_table_header **)&einj_tab);if (status ==AE_NOT_FOUND ) { -pr_warn ("EINJ table not found.\n" ); +pr_debug ("EINJ table not found.\n" );return -ENODEV ; }else if (ACPI_FAILURE (status)) { pr_err("Failed to get EINJ table: %s\n",
@@ -805,7 +811,7 @@ static int __init einj_init(void)return rc; } -static void __exit einj_exit(void) +static void __exit einj_remove(struct platform_device *pdev) {struct apei_exec_context ctx;
@@ -826,6 +832,40 @@ static void __exit einj_exit(void)acpi_put_table ((struct acpi_table_header *)einj_tab); } +static struct platform_device *einj_dev; +static struct platform_driver einj_driver = { + .remove_new = einj_remove, + .driver = { + .name ="acpi-einj" , + }, +}; + +static int __init einj_init (void ) +{ +struct platform_device_info einj_dev_info = { + .name ="acpi-einj" , + .id =-1 , + }; +int rc; + + einj_dev =platform_device_register_full (&einj_dev_info); +if (IS_ERR (einj_dev)) +return PTR_ERR (einj_dev); + + rc =platform_driver_probe (&einj_driver, einj_probe); + einj_initialized = rc ==0 ; + +return 0 ; +} + +static void __exit einj_exit(void) +{ +if (einj_initialized) +platform_driver_unregister (&einj_driver); + +platform_device_del (einj_dev); +} +module_init (einj_init);module_exit (einj_exit);
Signature · 1 line
2.34.1
Re: [PATCH v14 1/4] EINJ: Migrate to a platform driver
Quoted 9 lines · Ben Cheatham
Change the EINJ module to install a platform device/driver on module init and move the module
init()andexit()functions to driver probe and remove. This change allows the EINJ module to load regardless of whether setting up EINJ succeeds, which allows dependent modules to still load (i.e. the CXL core).Since EINJ may no longer be initialized when the module loads, any functions that are called from dependent/external modules should check the
einj_initializedvariable before calling any EINJ functions.
Is this statement true given that no debugfs files are registered when einj_initialized() is false?
It would be nice to remove that from the functions and just rely on debugfs files not being published for safety.
With that fixed up you can add:
Re: [PATCH v14 1/4] EINJ: Migrate to a platform driver
Quoted 7 lines · Dan Williams
Quoted 6 lines · Ben Cheatham
Change the EINJ module to install a platform device/driver on module init and move the module
init()andexit()functions to driver probe and remove. This change allows the EINJ module to load regardless of whether setting up EINJ succeeds, which allows dependent modules to still load (i.e. the CXL core).
Quoted 7 lines
Quoted 3 lines
Since EINJ may no longer be initialized when the module loads, any functions that are called from dependent/external modules should check the
einj_initializedvariable before calling any EINJ functions.Is this statement true given that no debugfs files are registered when
einj_initialized()is false?
That's true, I guess this would just be for redundancy/extra safety.
Quoted 3 lines
It would be nice to remove that from the functions and just rely on debugfs files not being published for safety.
I'll go ahead and remove those checks.
Quoted 3 lines
With that fixed up you can add:
Reviewed-by Dan Williams <[email protected]>
Re: [PATCH v14 1/4] EINJ: Migrate to a platform driver
In reply to Ben CheathamQuoted 11 lines · On Mon, 26 Feb 2024 16:27:01 -0600 Ben Cheatham <[email protected]>…
Change the EINJ module to install a platform device/driver on module init and move the module
init()andexit()functions to driver probe and remove. This change allows the EINJ module to load regardless of whether setting up EINJ succeeds, which allows dependent modules to still load (i.e. the CXL core).Since EINJ may no longer be initialized when the module loads, any functions that are called from dependent/external modules should check the
einj_initializedvariable before calling any EINJ functions.Signed-off-by Ben Cheatham <[email protected]>
Looks good to me.
I did wonder if a debug message was needed on no acpi support given that should be really really obvious on a system, but I guess with late probing of this from a module, maybe that is still useful.
Jonathan
PATCH v14 2/4 EINJ: Add CXL error type support
In reply to Ben CheathamRemove CXL protocol error types from the EINJ module and move them to a new einj_cxl module. The einj_cxl module implements the necessary handling for CXL protocol error injection and exposes an API for the CXL core to use said functionality. Because the CXL error types require special handling, only allow them to be injected through the einj_cxl module and return an error when attempting to inject through "regular" EINJ.
---
MAINTAINERS | 1 +
drivers/acpi/apei/Kconfig | 12 +++
drivers/acpi/apei/Makefile | 2 +
drivers/acpi/apei/apei-internal.h | 16 +++
drivers/acpi/apei/{einj.c => einj-core.c} | 78 +++++++++-----
drivers/acpi/apei/einj-cxl.c | 120 ++++++++++++++++++++++
include/linux/einj-cxl.h | 40 ++++++++
7 files changed, 244 insertions(+), 25 deletions(-)
rename drivers/acpi/apei/{einj.c => einj-core.c} (94%)
create mode 100644 drivers/acpi/apei/einj-cxl.c
create mode 100644 include/linux/einj-cxl.hMAINTAINERS +1 -0
@@ -5289,6 +5289,7 @@ M: Dan Williams <[email protected]> L: [email protected] S: Maintained F: drivers/cxl/ +F: include/linux/cxl-einj.h F: include/linux/cxl-event.h F: include/uapi/linux/cxl_mem.h F: tools/testing/cxl/
drivers/acpi/apei/Kconfig +12 -0
@@ -60,6 +60,18 @@ config ACPI_APEI_EINJ mainly used for debugging and testing the other parts of APEI and some other RAS features. +config ACPI_APEI_EINJ_CXL + bool "CXL Error INJection Support" + default ACPI_APEI_EINJ + depends on ACPI_APEI_EINJ && CXL_BUS <= ACPI_APEI_EINJ + help + Support for CXL protocol Error INJection through debugfs/cxl. + Availability and which errors are supported is dependent on + the host platform. Look to ACPI v6.5 section 18.6.4 and kernel + EINJ documentation for more information. + + If unsure say 'n' + config ACPI_APEI_ERST_DEBUG tristate "APEI Error Record Serialization Table (ERST) Debug Support" depends on ACPI_APEI
drivers/acpi/apei/Makefile +2 -0
@@ -2,6 +2,8 @@ obj-$(CONFIG_ACPI_APEI) += apei.o obj-$(CONFIG_ACPI_APEI_GHES) += ghes.o obj-$(CONFIG_ACPI_APEI_EINJ) += einj.o +einj-y := einj-core.o +einj-$(CONFIG_ACPI_APEI_EINJ_CXL) += einj-cxl.o obj-$(CONFIG_ACPI_APEI_ERST_DEBUG) += erst-dbg.o apei-y := apei-base.o hest.o erst.o bert.o
drivers/acpi/apei/apei-internal.h +16 -0
@@ -130,4 +130,20 @@ static inline u32 cper_estatus_len(struct acpi_hest_generic_status *estatus) }int apei_osc_setup (void ); + +int einj_get_available_error_type (u32 *type); +int einj_error_inject (u32 type,u32 flags,u64 param1,u64 param2,u64 param3, +u64 param4); +bool einj_is_cxl_error_type (u64 type); +int einj_validate_error_type (u64 type); + +#ifndef ACPI_EINJ_CXL_CACHE_CORRECTABLE +#define ACPI_EINJ_CXL_CACHE_CORRECTABLE BIT(12) +#define ACPI_EINJ_CXL_CACHE_UNCORRECTABLE BIT(13) +#define ACPI_EINJ_CXL_CACHE_FATAL BIT(14) +#define ACPI_EINJ_CXL_MEM_CORRECTABLE BIT(15) +#define ACPI_EINJ_CXL_MEM_UNCORRECTABLE BIT(16) +#define ACPI_EINJ_CXL_MEM_FATAL BIT(17) +#endif +#endif
drivers/acpi/apei/einj-core.c renamed from drivers/acpi/apei/einj.c +53 -25
139 lines not on this page · raw message
drivers/acpi/apei/einj-cxl.c new file +120 -0
120 lines not on this page · raw message
include/linux/einj-cxl.h new file +40 -0
@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* CXL protocol Error INJection support. +* +* Copyright (c) 2023 Advanced Micro Devices, Inc. +* All Rights Reserved. +* +* Author: Ben Cheatham <[email protected]> +*/ +#ifndef EINJ_CXL_H +#define EINJ_CXL_H + +#include <linux/pci.h> + +#if IS_ENABLED (CONFIG_ACPI_APEI_EINJ_CXL ) +int einj_cxl_available_error_type_show (struct seq_file *m,void *v); +int einj_cxl_inject_error (struct pci_dev *dport_dev,u64 type); +int einj_cxl_inject_rch_error (u64 rcrb,u64 type); +bool einj_cxl_is_initialized (void ); +#else /* !IS_ENABLED(CONFIG_ACPI_APEI_EINJ_CXL) */ +static inline int einj_cxl_available_error_type_show (struct seq_file *m, +void *v) +{ +return -ENXIO ; +} + +static inline int einj_cxl_inject_error (struct pci_dev *dport_dev,u64 type) +{ +return -ENXIO ; +} + +static inline int einj_cxl_inject_rch_error (u64 rcrb,u64 type) +{ +return -ENXIO ; +} + +static inline bool einj_cxl_is_initialized (void ) {return false; } +#endif /* CONFIG_ACPI_APEI_EINJ_CXL */ + +#endif /* EINJ_CXL_H */
Signature · 1 line
2.34.1
Luck, Tony
reviewerRE: [PATCH v14 2/4] EINJ: Add CXL error type support
drivers/acpi/apei/Kconfig config ACPI_APEI_EINJ · line 64
Quoted 5 lines
Remove CXL protocol error types from the EINJ module and move them to a new
einj_cxlmodule. Theeinj_cxlmodule implements the necessarydrivers/acpi/apei/Kconfig +2
-0+config ACPI_APEI_EINJ_CXL + bool "CXL Error INJection Support"
It's not really a module anymore. Need to update commit messages.
-Tony
Re: [PATCH v14 2/4] EINJ: Add CXL error type support
Quoted 9 lines · Tony
drivers/acpi/apei/Kconfig config ACPI_APEI_EINJ · line 64
Quoted 5 lines
Remove CXL protocol error types from the EINJ module and move them to a new
einj_cxlmodule. Theeinj_cxlmodule implements the necessarydrivers/acpi/apei/Kconfig +2
-0+config ACPI_APEI_EINJ_CXL + bool "CXL Error INJection Support"It's not really a module anymore. Need to update commit messages.
-Tony
You're 100% correct. I was in a bit of a rush getting these out yesterday and forgot this message (and the next one) need to be updated. I'll send out replies to those patches with the updated messages.
Thanks,
Ben
Re: [PATCH v14 2/4] EINJ: Add CXL error type support
In reply to Ben CheathamThis patch had an outdated commit message, so here's the patch with an updated description.
I also realized that I was wrong about letting CXL 2.0+ error types (discussed a revision or two ago) and I wasn't actually letting them through. I've went ahead and added the ability to inject CXL 2.0+ error through the legacy interface. This pretty much amounts to returning an error for CXL 1.0/1.1 injection types in einj_error_inject() and instead routing them through a new einj_cxl_rch_error_inject() function called in einj-cxl.c
If this change is too big I can send in another revision, I just wanted to avoid spamming the list(s).
From eea1cf991dc2a551f6db2e3bb9510ed43c86762d Mon Sep 17 00:00:00 2001
From: Ben Cheatham <[email protected]>
Date: Fri, 16 Feb 2024 11:12:51 -0600
Subject: [PATCH v14 2/4] EINJ: Add CXL error type support
Move CXL protocol error types from einj.c (now einj-core.c) to einj-cxl.c. einj-cxl.c implements the necessary handling for CXL protocol error injection and exposes an API for the CXL core to use said functionality, while also allowing the EINJ module to be built without CXL support. Because CXL error types targeting CXL 1.0/1.1 ports require special handling, only allow them to be injected through the new cxl debugfs interface (next commit) and return an error when attempting to inject through the legacy interface.
---
MAINTAINERS | 1 +
drivers/acpi/apei/Kconfig | 12 +++
drivers/acpi/apei/Makefile | 2 +
drivers/acpi/apei/apei-internal.h | 18 ++++
drivers/acpi/apei/{einj.c => einj-core.c} | 85 +++++++++++----
drivers/acpi/apei/einj-cxl.c | 121 ++++++++++++++++++++++
include/linux/einj-cxl.h | 40 +++++++
7 files changed, 257 insertions(+), 22 deletions(-)
rename drivers/acpi/apei/{einj.c => einj-core.c} (94%)
create mode 100644 drivers/acpi/apei/einj-cxl.c
create mode 100644 include/linux/einj-cxl.hMAINTAINERS +1 -0
@@ -5289,6 +5289,7 @@ M: Dan Williams <[email protected]> L: [email protected] S: Maintained F: drivers/cxl/ +F: include/linux/cxl-einj.h F: include/linux/cxl-event.h F: include/uapi/linux/cxl_mem.h F: tools/testing/cxl/
drivers/acpi/apei/Kconfig +12 -0
@@ -60,6 +60,18 @@ config ACPI_APEI_EINJ mainly used for debugging and testing the other parts of APEI and some other RAS features. +config ACPI_APEI_EINJ_CXL + bool "CXL Error INJection Support" + default ACPI_APEI_EINJ + depends on ACPI_APEI_EINJ && CXL_BUS <= ACPI_APEI_EINJ + help + Support for CXL protocol Error INJection through debugfs/cxl. + Availability and which errors are supported is dependent on + the host platform. Look to ACPI v6.5 section 18.6.4 and kernel + EINJ documentation for more information. + + If unsure say 'n' + config ACPI_APEI_ERST_DEBUG tristate "APEI Error Record Serialization Table (ERST) Debug Support" depends on ACPI_APEI
drivers/acpi/apei/Makefile +2 -0
@@ -2,6 +2,8 @@ obj-$(CONFIG_ACPI_APEI) += apei.o obj-$(CONFIG_ACPI_APEI_GHES) += ghes.o obj-$(CONFIG_ACPI_APEI_EINJ) += einj.o +einj-y := einj-core.o +einj-$(CONFIG_ACPI_APEI_EINJ_CXL) += einj-cxl.o obj-$(CONFIG_ACPI_APEI_ERST_DEBUG) += erst-dbg.o apei-y := apei-base.o hest.o erst.o bert.o
drivers/acpi/apei/apei-internal.h +18 -0
@@ -130,4 +130,22 @@ static inline u32 cper_estatus_len(struct acpi_hest_generic_status *estatus) }int apei_osc_setup (void ); + +int einj_get_available_error_type (u32 *type); +int einj_error_inject (u32 type,u32 flags,u64 param1,u64 param2,u64 param3, +u64 param4); +int einj_cxl_rch_error_inject (u32 type,u32 flags,u64 param1,u64 param2, +u64 param3,u64 param4); +bool einj_is_cxl_error_type (u64 type); +int einj_validate_error_type (u64 type); + +#ifndef ACPI_EINJ_CXL_CACHE_CORRECTABLE +#define ACPI_EINJ_CXL_CACHE_CORRECTABLE BIT(12) +#define ACPI_EINJ_CXL_CACHE_UNCORRECTABLE BIT(13) +#define ACPI_EINJ_CXL_CACHE_FATAL BIT(14) +#define ACPI_EINJ_CXL_MEM_CORRECTABLE BIT(15) +#define ACPI_EINJ_CXL_MEM_UNCORRECTABLE BIT(16) +#define ACPI_EINJ_CXL_MEM_FATAL BIT(17) +#endif +#endif
drivers/acpi/apei/einj-core.c renamed from drivers/acpi/apei/einj.c +63 -22
155 lines not on this page · raw message
drivers/acpi/apei/einj-cxl.c new file +121 -0
121 lines not on this page · raw message
include/linux/einj-cxl.h new file +40 -0
@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* CXL protocol Error INJection support. +* +* Copyright (c) 2023 Advanced Micro Devices, Inc. +* All Rights Reserved. +* +* Author: Ben Cheatham <[email protected]> +*/ +#ifndef EINJ_CXL_H +#define EINJ_CXL_H + +#include <linux/pci.h> + +#if IS_ENABLED (CONFIG_ACPI_APEI_EINJ_CXL ) +int einj_cxl_available_error_type_show (struct seq_file *m,void *v); +int einj_cxl_inject_error (struct pci_dev *dport_dev,u64 type); +int einj_cxl_inject_rch_error (u64 rcrb,u64 type); +bool einj_cxl_is_initialized (void ); +#else /* !IS_ENABLED(CONFIG_ACPI_APEI_EINJ_CXL) */ +static inline int einj_cxl_available_error_type_show (struct seq_file *m, +void *v) +{ +return -ENXIO ; +} + +static inline int einj_cxl_inject_error (struct pci_dev *dport_dev,u64 type) +{ +return -ENXIO ; +} + +static inline int einj_cxl_inject_rch_error (u64 rcrb,u64 type) +{ +return -ENXIO ; +} + +static inline bool einj_cxl_is_initialized (void ) {return false; } +#endif /* CONFIG_ACPI_APEI_EINJ_CXL */ + +#endif /* EINJ_CXL_H */
Signature · 1 line
2.34.1
Re: [PATCH v14 2/4] EINJ: Add CXL error type support
Quoted 168 lines · Ben Cheatham
This patch had an outdated commit message, so here's the patch with an updated description.
I also realized that I was wrong about letting CXL 2.0+ error types (discussed a revision or two ago) and I wasn't actually letting them through. I've went ahead and added the ability to inject CXL 2.0+ error through the legacy interface. This pretty much amounts to returning an error for CXL 1.0/1.1 injection types in
einj_error_inject()and instead routing them through a neweinj_cxl_rch_error_inject()function called ineinj-cxl.cIf this change is too big I can send in another revision, I just wanted to avoid spamming the list(s).
From
eea1cf991dc2a551f6db2e3bb9510ed43c86762dMon Sep 17 00:00:00 2001
From: Ben Cheatham <[email protected]>
Date: Fri, 16 Feb 2024 11:12:51 -0600
Subject: [PATCH v14 2/4] EINJ: Add CXL error type supportMove CXL protocol error types from
einj.c(noweinj-core.c) toeinj-cxl.c.einj-cxl.cimplements the necessary handling for CXL protocol error injection and exposes an API for the CXL core to use said functionality, while also allowing the EINJ module to be built without CXL support. Because CXL error types targeting CXL 1.0/1.1 ports require special handling, only allow them to be injected through the new cxl debugfs interface (next commit) and return an error when attempting to inject through the legacy interface.Signed-off-by Ben Cheatham <[email protected]>--- MAINTAINERS | 1 + drivers/acpi/apei/Kconfig | 12 +++ drivers/acpi/apei/Makefile | 2 + drivers/acpi/apei/apei-internal.h | 18 ++++ drivers/acpi/apei/{einj.c => einj-core.c} | 85 +++++++++++---- drivers/acpi/apei/einj-cxl.c | 121 ++++++++++++++++++++++ include/linux/einj-cxl.h | 40 +++++++ 7 files changed, 257 insertions(+), 22 deletions(-) rename drivers/acpi/apei/{einj.c => einj-core.c} (94%) create mode 100644 drivers/acpi/apei/einj-cxl.c create mode 100644 include/linux/einj-cxl.hMAINTAINERS +1
-0@@ -5289,6 +5289,7 @@ M: Dan Williams <[email protected]> L: [email protected] S: Maintained F: drivers/cxl/ +F: include/linux/cxl-einj.h F: include/linux/cxl-event.h F: include/uapi/linux/cxl_mem.h F: tools/testing/cxl/drivers/acpi/apei/Kconfig +12
-0@@ -60,6 +60,18 @@ config ACPI_APEI_EINJ mainly used for debugging and testing the other parts of APEI and some other RAS features. +config ACPI_APEI_EINJ_CXL + bool "CXL Error INJection Support" + default ACPI_APEI_EINJ + depends on ACPI_APEI_EINJ && CXL_BUS <= ACPI_APEI_EINJ + help + Support for CXL protocol Error INJection through debugfs/cxl. + Availability and which errors are supported is dependent on + the host platform. Look to ACPI v6.5 section 18.6.4 and kernel + EINJ documentation for more information. + + If unsure say 'n' + config ACPI_APEI_ERST_DEBUG tristate "APEI Error Record Serialization Table (ERST) Debug Support" depends on ACPI_APEIdrivers/acpi/apei/Makefile +2
-0@@ -2,6 +2,8 @@ obj-$(CONFIG_ACPI_APEI) += apei.o obj-$(CONFIG_ACPI_APEI_GHES) += ghes.o obj-$(CONFIG_ACPI_APEI_EINJ) += einj.o +einj-y := einj-core.o +einj-$(CONFIG_ACPI_APEI_EINJ_CXL) += einj-cxl.o obj-$(CONFIG_ACPI_APEI_ERST_DEBUG) += erst-dbg.o apei-y := apei-base.o hest.o erst.o bert.odrivers/acpi/apei/apei-internal.h +18
-0@@ -130,4 +130,22 @@ static inline u32 cper_estatus_len(struct acpi_hest_generic_status *estatus) }int apei_osc_setup (void ); + +int einj_get_available_error_type (u32 *type); +int einj_error_inject (u32 type,u32 flags,u64 param1,u64 param2,u64 param3, +u64 param4); +int einj_cxl_rch_error_inject (u32 type,u32 flags,u64 param1,u64 param2, +u64 param3,u64 param4); +bool einj_is_cxl_error_type (u64 type); +int einj_validate_error_type (u64 type); + +#ifndef ACPI_EINJ_CXL_CACHE_CORRECTABLE +#define ACPI_EINJ_CXL_CACHE_CORRECTABLE BIT(12) +#define ACPI_EINJ_CXL_CACHE_UNCORRECTABLE BIT(13) +#define ACPI_EINJ_CXL_CACHE_FATAL BIT(14) +#define ACPI_EINJ_CXL_MEM_CORRECTABLE BIT(15) +#define ACPI_EINJ_CXL_MEM_UNCORRECTABLE BIT(16) +#define ACPI_EINJ_CXL_MEM_FATAL BIT(17) +#endif +#endif drivers/acpi/apei/einj-core.c renamed from drivers/acpi/apei/einj.c +10
-4@@ -37,6 +37,12 @@#define MEM_ERROR_MASK (ACPI_EINJ_MEMORY_CORRECTABLE | \ ACPI_EINJ_MEMORY_UNCORRECTABLE | \ ACPI_EINJ_MEMORY_FATAL) +#define CXL_ERROR_MASK (ACPI_EINJ_CXL_CACHE_CORRECTABLE | \ + ACPI_EINJ_CXL_CACHE_UNCORRECTABLE | \ + ACPI_EINJ_CXL_CACHE_FATAL | \ + ACPI_EINJ_CXL_MEM_CORRECTABLE | \ + ACPI_EINJ_CXL_MEM_UNCORRECTABLE | \ + ACPI_EINJ_CXL_MEM_FATAL)/* * ACPI version 5 provides a SET_ERROR_TYPE_WITH_ADDRESS action. @@ -141,7 +147,7 @@ static DEFINE_MUTEX(einj_mutex);/* * Exported APIs use this flag to exit early if einj_probe() failed. */ -static bool einj_initialized__ro_after_init ; +bool einj_initialized__ro_after_init ;static void *einj_param;@@ -166,7 +172,7 @@ static int __einj_get_available_error_type(u32 *type) }/* Get error injection capabilities of the platform */ -static int einj_get_available_error_type (u32 *type) +int einj_get_available_error_type (u32 *type) {int rc;@@ -536,8 +542,8 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, }/* Inject the specified hardware error */ -static int einj_error_inject (u32 type,u32 flags,u64 param1,u64 param2, -u64 param3,u64 param4) +int einj_error_inject (u32 type,u32 flags,u64 param1,u64 param2,u64 param3, +u64 param4) {int rc;u64 base_addr, size;@@ -560,8 +566,18 @@ 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;
drivers/acpi/apei/einj-core.c static int einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, · line 577
Quoted 10 lines
drivers/acpi/apei/einj-core.c renamed from drivers/acpi/apei/einj.c +8
-1- }else if (!(type &MEM_ERROR_MASK ) && !(flags &SETWA_FLAGS_MEM )) + }else if (!(type &MEM_ERROR_MASK ) && !(flags &SETWA_FLAGS_MEM )) { goto inject; + } + +/* +* Injections targeting a CXL 1.0/1.1 port have to be injected +* from the CXL debugfs interface so that we can guarantee a +* correct MMIO address. +*/
Given that the CXL debugfs is not present in this file I would update this comment to give a hints using local references. Something like:
/*
* Injections targeting a CXL 1.0/1.1 port have to be injected
* via the einj_cxl_rch_error_inject() path as that does proper
* input validation that passed address is an RCRB base address. */
...that said, how does this work for the CXL 2.0 path? Does not einj_cxl_inject_error() need to use __einj_error_inject() rather than einj_error_inject() to get by this check?
Re: [PATCH v14 2/4] EINJ: Add CXL error type support
Quoted 183 lines · Dan Williams
Quoted 168 lines · Ben Cheatham
This patch had an outdated commit message, so here's the patch with an updated description.
I also realized that I was wrong about letting CXL 2.0+ error types (discussed a revision or two ago) and I wasn't actually letting them through. I've went ahead and added the ability to inject CXL 2.0+ error through the legacy interface. This pretty much amounts to returning an error for CXL 1.0/1.1 injection types in
einj_error_inject()and instead routing them through a neweinj_cxl_rch_error_inject()function called ineinj-cxl.cIf this change is too big I can send in another revision, I just wanted to avoid spamming the list(s).
From
eea1cf991dc2a551f6db2e3bb9510ed43c86762dMon Sep 17 00:00:00 2001
From: Ben Cheatham <[email protected]>
Date: Fri, 16 Feb 2024 11:12:51 -0600
Subject: [PATCH v14 2/4] EINJ: Add CXL error type supportMove CXL protocol error types from
einj.c(noweinj-core.c) toeinj-cxl.c.einj-cxl.cimplements the necessary handling for CXL protocol error injection and exposes an API for the CXL core to use said functionality, while also allowing the EINJ module to be built without CXL support. Because CXL error types targeting CXL 1.0/1.1 ports require special handling, only allow them to be injected through the new cxl debugfs interface (next commit) and return an error when attempting to inject through the legacy interface.Signed-off-by Ben Cheatham <[email protected]>--- MAINTAINERS | 1 + drivers/acpi/apei/Kconfig | 12 +++ drivers/acpi/apei/Makefile | 2 + drivers/acpi/apei/apei-internal.h | 18 ++++ drivers/acpi/apei/{einj.c => einj-core.c} | 85 +++++++++++---- drivers/acpi/apei/einj-cxl.c | 121 ++++++++++++++++++++++ include/linux/einj-cxl.h | 40 +++++++ 7 files changed, 257 insertions(+), 22 deletions(-) rename drivers/acpi/apei/{einj.c => einj-core.c} (94%) create mode 100644 drivers/acpi/apei/einj-cxl.c create mode 100644 include/linux/einj-cxl.hMAINTAINERS +1
-0@@ -5289,6 +5289,7 @@ M: Dan Williams <[email protected]> L: [email protected] S: Maintained F: drivers/cxl/ +F: include/linux/cxl-einj.h F: include/linux/cxl-event.h F: include/uapi/linux/cxl_mem.h F: tools/testing/cxl/drivers/acpi/apei/Kconfig +12
-0@@ -60,6 +60,18 @@ config ACPI_APEI_EINJ mainly used for debugging and testing the other parts of APEI and some other RAS features. +config ACPI_APEI_EINJ_CXL + bool "CXL Error INJection Support" + default ACPI_APEI_EINJ + depends on ACPI_APEI_EINJ && CXL_BUS <= ACPI_APEI_EINJ + help + Support for CXL protocol Error INJection through debugfs/cxl. + Availability and which errors are supported is dependent on + the host platform. Look to ACPI v6.5 section 18.6.4 and kernel + EINJ documentation for more information. + + If unsure say 'n' + config ACPI_APEI_ERST_DEBUG tristate "APEI Error Record Serialization Table (ERST) Debug Support" depends on ACPI_APEIdrivers/acpi/apei/Makefile +2
-0@@ -2,6 +2,8 @@ obj-$(CONFIG_ACPI_APEI) += apei.o obj-$(CONFIG_ACPI_APEI_GHES) += ghes.o obj-$(CONFIG_ACPI_APEI_EINJ) += einj.o +einj-y := einj-core.o +einj-$(CONFIG_ACPI_APEI_EINJ_CXL) += einj-cxl.o obj-$(CONFIG_ACPI_APEI_ERST_DEBUG) += erst-dbg.o apei-y := apei-base.o hest.o erst.o bert.odrivers/acpi/apei/apei-internal.h +18
-0@@ -130,4 +130,22 @@ static inline u32 cper_estatus_len(struct acpi_hest_generic_status *estatus) }int apei_osc_setup (void ); + +int einj_get_available_error_type (u32 *type); +int einj_error_inject (u32 type,u32 flags,u64 param1,u64 param2,u64 param3, +u64 param4); +int einj_cxl_rch_error_inject (u32 type,u32 flags,u64 param1,u64 param2, +u64 param3,u64 param4); +bool einj_is_cxl_error_type (u64 type); +int einj_validate_error_type (u64 type); + +#ifndef ACPI_EINJ_CXL_CACHE_CORRECTABLE +#define ACPI_EINJ_CXL_CACHE_CORRECTABLE BIT(12) +#define ACPI_EINJ_CXL_CACHE_UNCORRECTABLE BIT(13) +#define ACPI_EINJ_CXL_CACHE_FATAL BIT(14) +#define ACPI_EINJ_CXL_MEM_CORRECTABLE BIT(15) +#define ACPI_EINJ_CXL_MEM_UNCORRECTABLE BIT(16) +#define ACPI_EINJ_CXL_MEM_FATAL BIT(17) +#endif +#endif drivers/acpi/apei/einj-core.c renamed from drivers/acpi/apei/einj.c +10
-4@@ -37,6 +37,12 @@#define MEM_ERROR_MASK (ACPI_EINJ_MEMORY_CORRECTABLE | \ ACPI_EINJ_MEMORY_UNCORRECTABLE | \ ACPI_EINJ_MEMORY_FATAL) +#define CXL_ERROR_MASK (ACPI_EINJ_CXL_CACHE_CORRECTABLE | \ + ACPI_EINJ_CXL_CACHE_UNCORRECTABLE | \ + ACPI_EINJ_CXL_CACHE_FATAL | \ + ACPI_EINJ_CXL_MEM_CORRECTABLE | \ + ACPI_EINJ_CXL_MEM_UNCORRECTABLE | \ + ACPI_EINJ_CXL_MEM_FATAL)/* * ACPI version 5 provides a SET_ERROR_TYPE_WITH_ADDRESS action. @@ -141,7 +147,7 @@ static DEFINE_MUTEX(einj_mutex);/* * Exported APIs use this flag to exit early if einj_probe() failed. */ -static bool einj_initialized__ro_after_init ; +bool einj_initialized__ro_after_init ;static void *einj_param;@@ -166,7 +172,7 @@ static int __einj_get_available_error_type(u32 *type) }/* Get error injection capabilities of the platform */ -static int einj_get_available_error_type (u32 *type) +int einj_get_available_error_type (u32 *type) {int rc;@@ -536,8 +542,8 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, }/* Inject the specified hardware error */ -static int einj_error_inject (u32 type,u32 flags,u64 param1,u64 param2, -u64 param3,u64 param4) +int einj_error_inject (u32 type,u32 flags,u64 param1,u64 param2,u64 param3, +u64 param4) {int rc;u64 base_addr, size;@@ -560,8 +566,18 @@ 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;drivers/acpi/apei/einj-core.c static int einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, · line 577
Quoted 10 lines
drivers/acpi/apei/einj-core.c renamed from drivers/acpi/apei/einj.c +8
-1- }else if (!(type &MEM_ERROR_MASK ) && !(flags &SETWA_FLAGS_MEM )) + }else if (!(type &MEM_ERROR_MASK ) && !(flags &SETWA_FLAGS_MEM )) { goto inject; + } + +/* +* Injections targeting a CXL 1.0/1.1 port have to be injected +* from the CXL debugfs interface so that we can guarantee a +* correct MMIO address. +*/ Given that the CXL debugfs is not present in this file I would update this comment to give a hints using local references. Something like:
Quoted 6 lines
/*
* Injections targeting a CXL 1.0/1.1 port have to be injected
* via theeinj_cxl_rch_error_inject()path as that does proper
* input validation that passed address is an RCRB base address. */
I agree, I'll change it to something along those lines.
Quoted 4 lines
...that said, how does this work for the CXL 2.0 path? Does not
einj_cxl_inject_error()need to use__einj_error_inject()rather thaneinj_error_inject()to get by this check?
The way that the target port type (1.0 vs. 2.0+) is differentiated is whether we are targeting a memory address, which is what SETWA_FLAGS_MEM indicates. So for the CXL 2.0+ path, the check will pass. Although the error type is a CXL error type, the flags variable will be set to SETWA_FLAGS_SBDF (I'm 90% sure that's what it's called, but it's something along those lines). Let me know if that doesn't answer your question!
Re: [PATCH v14 2/4] EINJ: Add CXL error type support
In reply to Ben CheathamQuoted 11 lines · Ben Cheatham
This patch had an outdated commit message, so here's the patch with an updated description.
I also realized that I was wrong about letting CXL 2.0+ error types (discussed a revision or two ago) and I wasn't actually letting them through. I've went ahead and added the ability to inject CXL 2.0+ error through the legacy interface. This pretty much amounts to returning an error for CXL 1.0/1.1 injection types in
einj_error_inject()and instead routing them through a neweinj_cxl_rch_error_inject()function called ineinj-cxl.cIf this change is too big I can send in another revision, I just wanted to avoid spamming the list(s).
The thing to avoid is sending too many versions too quickly, and making sure that upstream can reassemble the set with minimal effort. In this case now that I have a few review comments and the fact that b4 likely has no chance at assembling this correctly I would go ahead and fixup those comments for a v15.
Re: [PATCH v14 2/4] EINJ: Add CXL error type support
Quoted 10 lines · Dan Williams
Quoted 9 lines · Ben Cheatham
This patch had an outdated commit message, so here's the patch with an updated description.
I also realized that I was wrong about letting CXL 2.0+ error types (discussed a revision or two ago) and I wasn't actually letting them through. I've went ahead and added the ability to inject CXL 2.0+ error through the legacy interface. This pretty much amounts to returning an error for CXL 1.0/1.1 injection types in
einj_error_inject()and instead routing them through a neweinj_cxl_rch_error_inject()function called ineinj-cxl.c
Quoted 8 lines
Quoted 2 lines
If this change is too big I can send in another revision, I just wanted to avoid spamming the list(s).
The thing to avoid is sending too many versions too quickly, and making sure that upstream can reassemble the set with minimal effort. In this case now that I have a few review comments and the fact that b4 likely has no chance at assembling this correctly I would go ahead and fixup those comments for a v15.
Alright that makes sense. I'll put together a v15 and send it out later this week/early next week.
Thanks,
Ben
Re: [PATCH v14 2/4] EINJ: Add CXL error type support
In reply to Ben CheathamQuoted 9 lines · On Mon, 26 Feb 2024 16:27:02 -0600 Ben Cheatham <[email protected]>…
Remove CXL protocol error types from the EINJ module and move them to a new
einj_cxlmodule. Theeinj_cxlmodule implements the necessary handling for CXL protocol error injection and exposes an API for the CXL core to use said functionality. Because the CXL error types require special handling, only allow them to be injected through theeinj_cxlmodule and return an error when attempting to inject through "regular" EINJ.Signed-off-by Ben Cheatham <[email protected]>
Hi Ben,
Some minor comments inline given you are doing a v15 (yikes!)
Jonathan
Quoted 7 lines
drivers/acpi/apei/einj-core.c renamed from drivers/acpi/apei/einj.c +0
-0
...
Quoted 43 lines
drivers/acpi/apei/einj-core.c renamed from drivers/acpi/apei/einj.c +6
-14@@ -640,29 +648,21 @@ static int available_error_type_show(struct seq_file *m, void *v)DEFINE_SHOW_ATTRIBUTE (available_error_type); -static int error_type_get (void *data,u64 *val) -{ - *val = error_type; - -return 0 ; -} - -static int error_type_set (void *data,u64 val) +int einj_validate_error_type (u64 type) { +u32 tval, vendor, available_error_type =0 ;int rc; -u32 available_error_type =0 ; -u32 tval, vendor;/* Only low 32 bits for error type are valid */ -if (val &GENMASK_ULL (63 ,32 )) +if (type &GENMASK_ULL (63 ,32 ))return -EINVAL ;/* * Vendor defined types have 0x80000000 bit set, and * are not enumerated by ACPI_EINJ_GET_ERROR_TYPE */ - vendor = val &ACPI5_VENDOR_BIT ; - tval = val &0x7fffffff ; + vendor = type &ACPI5_VENDOR_BIT ; + tval = type &GENMASK (30 ,0 );/* Only one error type can be specified */ if (tval & (tval -1 ))@@ -671,9 +671,37 @@ static int error_type_set(void *data, u64 val) rc =einj_get_available_error_type (&available_error_type);if (rc)return rc; -if (!(val & available_error_type)) +if (!(type & available_error_type))return -EINVAL ; }
drivers/acpi/apei/einj-core.c static int error_type_set(void *data, u64 val) · line 686
Quoted 10 lines
drivers/acpi/apei/einj-core.c renamed from drivers/acpi/apei/einj.c +10
-0+ +return 0 ; +} + +bool einj_is_cxl_error_type (u64 type) +{ +return (type &CXL_ERROR_MASK ) && (!(type &ACPI5_VENDOR_BIT )); +} + +static int error_type_get (void *data,u64 *val)
This is reordered, but fairly sure no need to do so and it will make patch cleaner to leave it above the validation code.
Quoted 5 lines
drivers/acpi/apei/einj-core.c renamed from drivers/acpi/apei/einj.c +5
-0+{ + *val = error_type; + +return 0 ; +}
drivers/acpi/apei/einj-core.c static int error_type_set(void *data, u64 val) · line 701
Quoted 10 lines
drivers/acpi/apei/einj-core.c renamed from drivers/acpi/apei/einj.c +10
-0+ +static int error_type_set (void *data,u64 val) +{ +int rc; + +/* CXL error types have to be injected from cxl debugfs */ +if (einj_is_cxl_error_type (val)) +return -EINVAL ; + + rc =einj_validate_error_type (val);
Trivial but I'd have preferred this factoring out in a precursor patch just to make reviewing this a tiny bit easier.
Quoted 13 lines
drivers/acpi/apei/einj-core.c renamed from drivers/acpi/apei/einj.c +3
-0+if (rc) +return rc; + error_type = val;return 0 ;drivers/acpi/apei/einj-cxl.c new file +1
-0@@ -0,0 +1,120 @@ +// SPDX-License-Identifier: GPL-2.0-only
drivers/acpi/apei/einj-cxl.c line 11
Quoted 10 lines
drivers/acpi/apei/einj-cxl.c new file +10
-0+/* +* CXL Error INJection support. Used by CXL core to inject +* protocol errors into CXL ports. +* +* Copyright (C) 2023 Advanced Micro Devices, Inc. +* +* Author: Ben Cheatham <[email protected]> +*/ +#include <linux/einj-cxl.h> +#include <linux/debugfs.h>
Follow include what you use principles a little closer (there are always exceptions in kernel world...). The following seems resonable to me.
#include <linux/array_size.h>
#include <linux/seq_file.h>
drivers/acpi/apei/einj-cxl.c line 19
Quoted 8 lines
drivers/acpi/apei/einj-cxl.c new file +8
-0+ +#include "apei-internal.h" + +/* Defined in einj-core.c */ +extern bool einj_initialized; + +static struct {u32 mask;const char *str; }const einj_cxl_error_type_string[] = { + {BIT (12 ),"CXL.cache Protocol Correctable" },
Use the defines for the bits? Not sure why the original code didn't do so other than maybe long line lengths?
Quoted 11 lines
drivers/acpi/apei/einj-cxl.c new file +11
-0+ { BIT(13), "CXL.cache Protocol Uncorrectable non-fatal" }, + { BIT(14), "CXL.cache Protocol Uncorrectable fatal" }, + { BIT(15), "CXL.mem Protocol Correctable" }, + { BIT(16), "CXL.mem Protocol Uncorrectable non-fatal" }, + { BIT(17), "CXL.mem Protocol Uncorrectable fatal" }, +}; + +int einj_cxl_available_error_type_show (struct seq_file *m,void *v) +{ +int cxl_err, rc; +u32 available_error_type =0 ;
drivers/acpi/apei/einj-cxl.c line 40
Quoted 10 lines
drivers/acpi/apei/einj-cxl.c new file +10
-0+ +if (!einj_initialized) +return -ENXIO ; + + rc =einj_get_available_error_type (&available_error_type); +if (rc) +return rc; + +for (int pos =0 ; pos <ARRAY_SIZE (einj_cxl_error_type_string); pos++) { + cxl_err =ACPI_EINJ_CXL_CACHE_CORRECTABLE << pos;
Hmm. This is a little ugly.
Could do something like the following bit it's of similar level of ugly so up to you.
int bit_pos = ACPI_EINJ_CXL_CACHE_CORRECTABLE;
for_each_bit_set_bit_from(bit_pos, &available_error_type,
ARRAY_SIZE(einj_cxl_error_type_string)) {
int pos = bit_pos - ACPI_EINJ_CXL_CACHE_CORRECTABLE;Quoted 21 lines
drivers/acpi/apei/einj-cxl.c new file +10
-0+ +if (available_error_type & cxl_err) +seq_printf (m,"0x%08x\t%s\n" , + einj_cxl_error_type_string[pos].mask, + einj_cxl_error_type_string[pos].str); + } + +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (einj_cxl_available_error_type_show,CXL );include/linux/einj-cxl.h new file +3
-0@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* CXL protocol Error INJection support.
include/linux/einj-cxl.h line 13
Quoted 10 lines
include/linux/einj-cxl.h new file +10
-0+* +* Copyright (c) 2023 Advanced Micro Devices, Inc. +* All Rights Reserved. +* +* Author: Ben Cheatham <[email protected]> +*/ +#ifndef EINJ_CXL_H +#define EINJ_CXL_H + +#include <linux/pci.h>
Use a forwards def
struct pci_dev;
and drop the include. Also need
struct seq_file;
Quoted 27 lines
include/linux/einj-cxl.h new file +27
-0+ +#if IS_ENABLED (CONFIG_ACPI_APEI_EINJ_CXL ) +int einj_cxl_available_error_type_show (struct seq_file *m,void *v); +int einj_cxl_inject_error (struct pci_dev *dport_dev,u64 type); +int einj_cxl_inject_rch_error (u64 rcrb,u64 type); +bool einj_cxl_is_initialized (void ); +#else /* !IS_ENABLED(CONFIG_ACPI_APEI_EINJ_CXL) */ +static inline int einj_cxl_available_error_type_show (struct seq_file *m, +void *v) +{ +return -ENXIO ; +} + +static inline int einj_cxl_inject_error (struct pci_dev *dport_dev,u64 type) +{ +return -ENXIO ; +} + +static inline int einj_cxl_inject_rch_error (u64 rcrb,u64 type) +{ +return -ENXIO ; +} + +static inline bool einj_cxl_is_initialized (void ) {return false; } +#endif /* CONFIG_ACPI_APEI_EINJ_CXL */ + +#endif /* EINJ_CXL_H */
Re: [PATCH v14 2/4] EINJ: Add CXL error type support
Hey Jonathan, thanks for taking a look!
Quoted 11 lines · Jonathan Cameron
Quoted 8 lines · On Mon, 26 Feb 2024 16:27:02 -0600 Ben Cheatham <[email protected]>…
Remove CXL protocol error types from the EINJ module and move them to a new
einj_cxlmodule. Theeinj_cxlmodule implements the necessary handling for CXL protocol error injection and exposes an API for the CXL core to use said functionality. Because the CXL error types require special handling, only allow them to be injected through theeinj_cxlmodule and return an error when attempting to inject through "regular" EINJ.
Quoted 5 lines
Quoted 1 line
Signed-off-by Ben Cheatham <[email protected]>Hi Ben,
Some minor comments inline given you are doing a v15 (yikes!)
Yeah I know :(.
Quoted 59 lines
Jonathan
Quoted 7 lines
drivers/acpi/apei/einj-core.c renamed from drivers/acpi/apei/einj.c +0
-0...
Quoted 47 lines
drivers/acpi/apei/einj-core.c renamed from drivers/acpi/apei/einj.c +10
-14@@ -640,29 +648,21 @@ static int available_error_type_show(struct seq_file *m, void *v)DEFINE_SHOW_ATTRIBUTE (available_error_type); -static int error_type_get (void *data,u64 *val) -{ - *val = error_type; - -return 0 ; -} - -static int error_type_set (void *data,u64 val) +int einj_validate_error_type (u64 type) { +u32 tval, vendor, available_error_type =0 ;int rc; -u32 available_error_type =0 ; -u32 tval, vendor;/* Only low 32 bits for error type are valid */ -if (val &GENMASK_ULL (63 ,32 )) +if (type &GENMASK_ULL (63 ,32 ))return -EINVAL ;/* * Vendor defined types have 0x80000000 bit set, and * are not enumerated by ACPI_EINJ_GET_ERROR_TYPE */ - vendor = val &ACPI5_VENDOR_BIT ; - tval = val &0x7fffffff ; + vendor = type &ACPI5_VENDOR_BIT ; + tval = type &GENMASK (30 ,0 );/* Only one error type can be specified */ if (tval & (tval -1 ))@@ -671,9 +671,37 @@ static int error_type_set(void *data, u64 val) rc =einj_get_available_error_type (&available_error_type);if (rc)return rc; -if (!(val & available_error_type)) +if (!(type & available_error_type))return -EINVAL ; } + +return 0 ; +} +
Quoted 9 lines
drivers/acpi/apei/einj-core.c static int error_type_set(void *data, u64 val) · line 686
Quoted 6 lines
drivers/acpi/apei/einj-core.c renamed from drivers/acpi/apei/einj.c +6
-0+bool einj_is_cxl_error_type (u64 type) +{ +return (type &CXL_ERROR_MASK ) && (!(type &ACPI5_VENDOR_BIT )); +} + +static int error_type_get (void *data,u64 *val)This is reordered, but fairly sure no need to do so and it will make patch cleaner to leave it above the validation code.
Sorry it's been a bit, but I think I moved it to go with the other error_type functions. I don't mind leaving it where it was though.
Quoted 10 lines
Quoted 10 lines
drivers/acpi/apei/einj-core.c renamed from drivers/acpi/apei/einj.c +10
-0+{ + *val = error_type; + +return 0 ; +} + +static int error_type_set (void *data,u64 val) +{ +int rc; +
Quoted 9 lines
drivers/acpi/apei/einj-core.c static int error_type_set(void *data, u64 val) · line 701
Quoted 5 lines
drivers/acpi/apei/einj-core.c renamed from drivers/acpi/apei/einj.c +5
-0+/* CXL error types have to be injected from cxl debugfs */ +if (einj_is_cxl_error_type (val)) +return -EINVAL ; + + rc =einj_validate_error_type (val);Trivial but I'd have preferred this factoring out in a precursor patch just to make reviewing this a tiny bit easier.
It would probably make sense, but at this point I just want to get this across the finish line :).
Quoted 28 lines
Quoted 14 lines
drivers/acpi/apei/einj-core.c renamed from drivers/acpi/apei/einj.c +3
-0+if (rc) +return rc; + error_type = val;return 0 ;drivers/acpi/apei/einj-cxl.c new file +1
-0@@ -0,0 +1,120 @@ +// SPDX-License-Identifier: GPL-2.0-only drivers/acpi/apei/einj-cxl.c line 11
Quoted 10 lines
drivers/acpi/apei/einj-cxl.c new file +10
-0+/* +* CXL Error INJection support. Used by CXL core to inject +* protocol errors into CXL ports. +* +* Copyright (C) 2023 Advanced Micro Devices, Inc. +* +* Author: Ben Cheatham <[email protected]> +*/ +#include <linux/einj-cxl.h> +#include <linux/debugfs.h> Follow include what you use principles a little closer (there are always exceptions in kernel world...). The following seems resonable to me.
Quoted 3 lines
#include <
linux/array_size.h>
#include <linux/seq_file.h>
Will do!
Quoted 13 lines
drivers/acpi/apei/einj-cxl.c line 19
Quoted 9 lines
drivers/acpi/apei/einj-cxl.c new file +8
-0+ +#include "apei-internal.h" + +/* Defined in einj-core.c */ +extern bool einj_initialized; + +static struct {u32 mask;const char *str; }const einj_cxl_error_type_string[] = { + {BIT (12 ),"CXL.cache Protocol Correctable" },Use the defines for the bits? Not sure why the original code didn't do so other than maybe long line lengths?
I agree, this was merged from some ACPI tree changes in rc4 and I don't think they have the defines in that tree yet.
Quoted 27 lines
Quoted 13 lines
drivers/acpi/apei/einj-cxl.c new file +11
-0+ { BIT(13), "CXL.cache Protocol Uncorrectable non-fatal" }, + { BIT(14), "CXL.cache Protocol Uncorrectable fatal" }, + { BIT(15), "CXL.mem Protocol Correctable" }, + { BIT(16), "CXL.mem Protocol Uncorrectable non-fatal" }, + { BIT(17), "CXL.mem Protocol Uncorrectable fatal" }, +}; + +int einj_cxl_available_error_type_show (struct seq_file *m,void *v) +{ +int cxl_err, rc; +u32 available_error_type =0 ;drivers/acpi/apei/einj-cxl.c line 40
Quoted 10 lines
drivers/acpi/apei/einj-cxl.c new file +10
-0+ +if (!einj_initialized) +return -ENXIO ; + + rc =einj_get_available_error_type (&available_error_type); +if (rc) +return rc; + +for (int pos =0 ; pos <ARRAY_SIZE (einj_cxl_error_type_string); pos++) { + cxl_err =ACPI_EINJ_CXL_CACHE_CORRECTABLE << pos;Hmm. This is a little ugly.
Could do something like the following bit it's of similar level of ugly so up to you.
Quoted 5 lines
int bit_pos = ACPI_EINJ_CXL_CACHE_CORRECTABLE;
for_each_bit_set_bit_from(bit_pos, &available_error_type,
ARRAY_SIZE(einj_cxl_error_type_string)) {
int pos = bit_pos - ACPI_EINJ_CXL_CACHE_CORRECTABLE;I agree it's ugly. I think this version has the added benfit of parity with einj_available_error_type_show() in einj-core.c, so I think it's better to keep it this way if it's the same to you.
Quoted 35 lines
Quoted 23 lines
drivers/acpi/apei/einj-cxl.c new file +10
-0+ +if (available_error_type & cxl_err) +seq_printf (m,"0x%08x\t%s\n" , + einj_cxl_error_type_string[pos].mask, + einj_cxl_error_type_string[pos].str); + } + +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (einj_cxl_available_error_type_show,CXL );include/linux/einj-cxl.h new file +3
-0@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* CXL protocol Error INJection support. include/linux/einj-cxl.h line 13
Quoted 10 lines
include/linux/einj-cxl.h new file +10
-0+* +* Copyright (c) 2023 Advanced Micro Devices, Inc. +* All Rights Reserved. +* +* Author: Ben Cheatham <[email protected]> +*/ +#ifndef EINJ_CXL_H +#define EINJ_CXL_H + +#include <linux/pci.h> Use a forwards def
Quoted 6 lines
struct
pci_dev;and drop the include. Also need
struct
seq_file;
Will do.
Quoted 29 lines
Quoted 28 lines
include/linux/einj-cxl.h new file +27
-0+ +#if IS_ENABLED (CONFIG_ACPI_APEI_EINJ_CXL ) +int einj_cxl_available_error_type_show (struct seq_file *m,void *v); +int einj_cxl_inject_error (struct pci_dev *dport_dev,u64 type); +int einj_cxl_inject_rch_error (u64 rcrb,u64 type); +bool einj_cxl_is_initialized (void ); +#else /* !IS_ENABLED(CONFIG_ACPI_APEI_EINJ_CXL) */ +static inline int einj_cxl_available_error_type_show (struct seq_file *m, +void *v) +{ +return -ENXIO ; +} + +static inline int einj_cxl_inject_error (struct pci_dev *dport_dev,u64 type) +{ +return -ENXIO ; +} + +static inline int einj_cxl_inject_rch_error (u64 rcrb,u64 type) +{ +return -ENXIO ; +} + +static inline bool einj_cxl_is_initialized (void ) {return false; } +#endif /* CONFIG_ACPI_APEI_EINJ_CXL */ + +#endif /* EINJ_CXL_H */
Jonathan Cameron
Reviewed-byRe: [PATCH v14 2/4] EINJ: Add CXL error type support
Quoted 14 lines · On Thu, 7 Mar 2024 08:46:49 -0600 Ben Cheatham <[email protected]>…
Hey Jonathan, thanks for taking a look!
Quoted 11 lines · Jonathan Cameron
Quoted 8 lines · On Mon, 26 Feb 2024 16:27:02 -0600 Ben Cheatham <[email protected]>…
Remove CXL protocol error types from the EINJ module and move them to a new
einj_cxlmodule. Theeinj_cxlmodule implements the necessary handling for CXL protocol error injection and exposes an API for the CXL core to use said functionality. Because the CXL error types require special handling, only allow them to be injected through theeinj_cxlmodule and return an error when attempting to inject through "regular" EINJ.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Ben Cheatham <[email protected]>Hi Ben,
Some minor comments inline given you are doing a v15 (yikes!)
Yeah I know :(.
With headers tidied up.
Quoted 33 lines
Quoted 27 lines
Quoted 13 lines
drivers/acpi/apei/einj-cxl.c new file +11
-0+ { BIT(13), "CXL.cache Protocol Uncorrectable non-fatal" }, + { BIT(14), "CXL.cache Protocol Uncorrectable fatal" }, + { BIT(15), "CXL.mem Protocol Correctable" }, + { BIT(16), "CXL.mem Protocol Uncorrectable non-fatal" }, + { BIT(17), "CXL.mem Protocol Uncorrectable fatal" }, +}; + +int einj_cxl_available_error_type_show (struct seq_file *m,void *v) +{ +int cxl_err, rc; +u32 available_error_type =0 ;drivers/acpi/apei/einj-cxl.c line 40
Quoted 10 lines
drivers/acpi/apei/einj-cxl.c new file +10
-0+ +if (!einj_initialized) +return -ENXIO ; + + rc =einj_get_available_error_type (&available_error_type); +if (rc) +return rc; + +for (int pos =0 ; pos <ARRAY_SIZE (einj_cxl_error_type_string); pos++) { + cxl_err =ACPI_EINJ_CXL_CACHE_CORRECTABLE << pos;Hmm. This is a little ugly.
Could do something like the following bit it's of similar level of ugly so up to you.Quoted 5 lines
int bit_pos = ACPI_EINJ_CXL_CACHE_CORRECTABLE; for_each_bit_set_bit_from(bit_pos, &available_error_type, ARRAY_SIZE(einj_cxl_error_type_string)) { int pos = bit_pos - ACPI_EINJ_CXL_CACHE_CORRECTABLE;
Quoted 4 lines
I agree it's ugly. I think this version has the added benfit of parity with
einj_available_error_type_show()ineinj-core.c, so I think it's better to keep it this way if it's the same to you.
Sure. We can always (maybe) tidy them both up later :)
J
PATCH v14 3/4 cxl/core: Add CXL EINJ debugfs files
In reply to Ben CheathamExport CXL helper functions in the einj_cxl module for getting/injecting available CXL protocol error types to sysfs under kernel/debug/cxl.
The kernel/debug/cxl/einj_types file will print the available CXL protocol errors in the same format as the available_error_types file provided by the einj_cxl module. The kernel/debug/cxl/$dport_dev/einj_inject is functionally the same as the error_type and error_inject files provided by the EINJ module, i.e.:
writing an error type into $dport_dev/einj_inject will inject said error type into the CXL dport represented by $dport_dev.
--- Documentation/ABI/testing/debugfs-cxl | 30 ++++++++++++++++++++ drivers/cxl/core/port.c | 41 +++++++++++++++++++++++++++ 2 files changed, 71 insertions(+)
Documentation/ABI/testing/debugfs-cxl +30 -0
@@ -33,3 +33,33 @@ Description: device cannot clear poison from the address, -ENXIO is returned. The clear_poison attribute is only visible for devices supporting the capability. + +What: /sys/kernel/debug/cxl/einj_types +Date: January, 2024 +KernelVersion: v6.9 +Contact: [email protected] +Description: + (RO) Prints the CXL protocol error types made available by + the platform in the format "0x<error number> <error type>". + The possible error types are (as of ACPI v6.5): + 0x1000 CXL.cache Protocol Correctable + 0x2000 CXL.cache Protocol Uncorrectable non-fatal + 0x4000 CXL.cache Protocol Uncorrectable fatal + 0x8000 CXL.mem Protocol Correctable + 0x10000 CXL.mem Protocol Uncorrectable non-fatal + 0x20000 CXL.mem Protocol Uncorrectable fatal + + The <error number> can be written to einj_inject to inject + <error type> into a chosen dport. + +What: /sys/kernel/debug/cxl/$dport_dev/einj_inject +Date: January, 2024 +KernelVersion: v6.9 +Contact: [email protected] +Description: + (WO) Writing an integer to this file injects the corresponding + CXL protocol error into $dport_dev ($dport_dev will be a device + name from /sys/bus/pci/devices). The integer to type mapping for + injection can be found by reading from einj_types. If the dport + was enumerated in RCH mode, a CXL 1.1 error is injected, otherwise + a CXL 2.0 error is injected.
drivers/cxl/core/port.c +41 -0
65 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v14 3/4] cxl/core: Add CXL EINJ debugfs files
This patch also had an outdated commit message (still referenced the einj-cxl module). The patch with the updated commit message is below. I also made a tiny change to the format specifier of the einj_inject file to "0x%llx\n" from "%llx\n".
Thanks,
Ben
From 321129893da9129473c447772a461c1a4e9e0e9d Mon Sep 17 00:00:00 2001
From: Ben Cheatham <[email protected]>
Date: Fri, 16 Feb 2024 11:17:01 -0600
Subject: [PATCH v14 3/4] cxl/core: Add CXL EINJ debugfs files
Export CXL helper functions in einj-cxl.c for getting/injecting available CXL protocol error types to sysfs under kernel/debug/cxl.
The kernel/debug/cxl/einj_types file will print the available CXL protocol errors in the same format as the available_error_types file provided by the einj module. The kernel/debug/cxl/$dport_dev/einj_inject file is functionally the same as the error_type and error_inject files provided by the EINJ module, i.e.: writing an error type into $dport_dev/einj_inject will inject said error type into the CXL dport represented by $dport_dev.
--- Documentation/ABI/testing/debugfs-cxl | 30 +++++++++++++++++++ drivers/cxl/core/port.c | 42 +++++++++++++++++++++++++++ 2 files changed, 72 insertions(+)
Documentation/ABI/testing/debugfs-cxl +30 -0
@@ -33,3 +33,33 @@ Description: device cannot clear poison from the address, -ENXIO is returned. The clear_poison attribute is only visible for devices supporting the capability. + +What: /sys/kernel/debug/cxl/einj_types +Date: January, 2024 +KernelVersion: v6.9 +Contact: [email protected] +Description: + (RO) Prints the CXL protocol error types made available by + the platform in the format "0x<error number> <error type>". + The possible error types are (as of ACPI v6.5): + 0x1000 CXL.cache Protocol Correctable + 0x2000 CXL.cache Protocol Uncorrectable non-fatal + 0x4000 CXL.cache Protocol Uncorrectable fatal + 0x8000 CXL.mem Protocol Correctable + 0x10000 CXL.mem Protocol Uncorrectable non-fatal + 0x20000 CXL.mem Protocol Uncorrectable fatal + + The <error number> can be written to einj_inject to inject + <error type> into a chosen dport. + +What: /sys/kernel/debug/cxl/$dport_dev/einj_inject +Date: January, 2024 +KernelVersion: v6.9 +Contact: [email protected] +Description: + (WO) Writing an integer to this file injects the corresponding + CXL protocol error into $dport_dev ($dport_dev will be a device + name from /sys/bus/pci/devices). The integer to type mapping for + injection can be found by reading from einj_types. If the dport + was enumerated in RCH mode, a CXL 1.1 error is injected, otherwise + a CXL 2.0 error is injected.
drivers/cxl/core/port.c +42 -0
66 lines not on this page · raw message
Signature · 1 line
2.34.1
Jonathan Cameron
Reviewed-byRe: [PATCH v14 3/4] cxl/core: Add CXL EINJ debugfs files
Quoted 23 lines · On Tue, 27 Feb 2024 14:14:35 -0600 Ben Cheatham <[email protected]>…
This patch also had an outdated commit message (still referenced the einj-cxl module). The patch with the updated commit message is below. I also made a tiny change to the format specifier of the
einj_injectfile to "0x%llx\n" from "%llx\n".Thanks,
BenFrom
321129893da9129473c447772a461c1a4e9e0e9dMon Sep 17 00:00:00 2001
From: Ben Cheatham <[email protected]>
Date: Fri, 16 Feb 2024 11:17:01 -0600
Subject: [PATCH v14 3/4] cxl/core: Add CXL EINJ debugfs filesExport CXL helper functions in
einj-cxl.cfor getting/injecting available CXL protocol error types to sysfs underkernel/debug/cxl.The
kernel/debug/cxl/einj_typesfile will print the available CXL protocol errors in the same format as theavailable_error_typesfile provided by the einj module. Thekernel/debug/cxl/$dport_dev/einj_injectfile is functionally the same as theerror_typeanderror_injectfiles provided by the EINJ module, i.e.: writing an error type into $dport_dev/einj_inject will inject said error type into the CXL dport represented by $dport_dev.
Quoted 1 line
Signed-off-by Ben Cheatham <[email protected]>
LGTM other than not sending patches like this as tooling won't pick them up!
Re: [PATCH v14 3/4] cxl/core: Add CXL EINJ debugfs files
Quoted 26 lines · Jonathan Cameron
Quoted 23 lines · On Tue, 27 Feb 2024 14:14:35 -0600 Ben Cheatham <[email protected]>…
This patch also had an outdated commit message (still referenced the einj-cxl module). The patch with the updated commit message is below. I also made a tiny change to the format specifier of the
einj_injectfile to "0x%llx\n" from "%llx\n".Thanks,
BenFrom
321129893da9129473c447772a461c1a4e9e0e9dMon Sep 17 00:00:00 2001
From: Ben Cheatham <[email protected]>
Date: Fri, 16 Feb 2024 11:17:01 -0600
Subject: [PATCH v14 3/4] cxl/core: Add CXL EINJ debugfs filesExport CXL helper functions in
einj-cxl.cfor getting/injecting available CXL protocol error types to sysfs underkernel/debug/cxl.The
kernel/debug/cxl/einj_typesfile will print the available CXL protocol errors in the same format as theavailable_error_typesfile provided by the einj module. Thekernel/debug/cxl/$dport_dev/einj_injectfile is functionally the same as theerror_typeanderror_injectfiles provided by the EINJ module, i.e.: writing an error type into $dport_dev/einj_inject will inject said error type into the CXL dport represented by $dport_dev.
Quoted 4 lines
Quoted 1 line
Signed-off-by Ben Cheatham <[email protected]>LGTM other than not sending patches like this as tooling won't pick them up!
Reviewed-by Jonathan Cameron <[email protected]>
Yeah I normally wouldn't send it in this way, but I caught what needed changes before most people started to review and didn't want to make a whole new version for them (especially since the version number is quite high already). I probably should've just waited a day or two and double checked before sending it out in hindsight.
Thanks,
Ben
PATCH v14 4/4 EINJ, Documentation: Update EINJ kernel doc
In reply to Ben CheathamUpdate EINJ kernel document to include how to inject CXL protocol error types, build the kernel to include CXL error types, and give an example injection.
--- .../firmware-guide/acpi/apei/einj.rst | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+)
Documentation/firmware-guide/acpi/apei/einj.rst +34 -0
@@ -32,6 +32,10 @@ configuration:: CONFIG_ACPI_APEI CONFIG_ACPI_APEI_EINJ +...and to (optionally) enable CXL protocol error injection set:: + + CONFIG_ACPI_APEI_EINJ_CXL + The EINJ user interface is in <debugfs mount point>/apei/einj. The following files belong to it:
@@ -118,6 +122,24 @@ The following files belong to it: this actually works depends on what operations the BIOS actually includes in the trigger phase. +CXL error types are supported from ACPI 6.5 onwards (given a CXL port +is present). The EINJ user interface for CXL error types is at +<debugfs mount point>/cxl. The following files belong to it: + +- einj_types: + + Provides the same functionality as available_error_types above, but + for CXL error types + +- $dport_dev/einj_inject: + + Injects a CXL error type into the CXL port represented by $dport_dev, + where $dport_dev is the name of the CXL port (usually a PCIe device name). + Error injections targeting a CXL 2.0+ port can use the legacy interface + under <debugfs mount point>/apei/einj, while CXL 1.1/1.0 port injections + must use this file. + + BIOS versions based on the ACPI 4.0 specification have limited options in controlling where the errors are injected. Your BIOS may support an extension (enabled with the param_extension=1 module parameter, or boot
@@ -181,6 +203,18 @@ You should see something like this in dmesg:: [22715.834759] EDAC sbridge MC3: PROCESSOR 0:306e7 TIME 1422553404 SOCKET 0 APIC 0 [22716.616173] EDAC MC3: 1 CE memory read error on CPU_SrcID#0_Channel#0_DIMM#0 (channel:0 slot:0 page:0x12345 offset:0x0 grain:32 syndrome:0x0 - area:DRAM err_code:0001:0090 socket:0 channel_mask:1 rank:0) +A CXL error injection example with $dport_dev=0000:e0:01.1:: + + # cd /sys/kernel/debug/cxl/ + # ls + 0000:e0:01.1 0000:0c:00.0 + # cat einj_types # See which errors can be injected + 0x00008000 CXL.mem Protocol Correctable + 0x00010000 CXL.mem Protocol Uncorrectable non-fatal + 0x00020000 CXL.mem Protocol Uncorrectable fatal + # cd 0000:e0:01.1 # Navigate to dport to inject into + # echo 0x8000 > einj_inject # Inject error + Special notes for injection into SGX enclaves: There may be a separate BIOS setup option to enable SGX injection.
Signature · 1 line
2.34.1
Re: [PATCH v14 4/4] EINJ, Documentation: Update EINJ kernel doc
Quoted 5 lines · On Mon, 26 Feb 2024 16:27:04 -0600 Ben Cheatham <[email protected]>…
Update EINJ kernel document to include how to inject CXL protocol error types, build the kernel to include CXL error types, and give an example injection.
Signed-off-by Ben Cheatham <[email protected]>