cxl: Device protocol AER injection
Subsystems (4)
RFC 1/1 cxl: Device protocol AER injection
This patch is intended to provide a method of testing the recently submitted cxl series "cxl: Enable CXL PCIe Port Protocol Error handling and logging" found here:
https://lore.kernel.org/linux-cxl/[email protected]/T/#md90ec1fdd1b374bf1e32e7736e2b3e34b328c701
The changes in this patch will allow CXL RAS protocol testing by injecting AER errors using AER EINJ. The RAS register block status is updated using a central function to augment RAS register block returned by to_ras_base(). This supports all CXL devices including Root Ports, Upstream Switch Ports, Downstream Switch Ports, Endpoints, and RCH Downstream Ports.
Add debugfs-based CXL protocol error injection for testing CXL RAS error handling paths. Injects CXL RAS protocol errors using AER internal error inject interface via /sys/kernel/debug/cxl/aer_einj_inject.
RAS CXL status is set using to_ras_base() function override when kernel config CONFIG_CXL_PROTO_AER_EINJ is enabled.
Usage:
echo "DDDD:BB:DD.F [UCE|CE] AER_STATUS RAS_STATUS [RCH]" > \
/sys/kernel/debug/cxl/aer_einj_inject
Move struct aer_error_inj and aer_inject() to linux/aer.h so CXL can invoke AER injection directly. Export aer_inject() with EXPORT_SYMBOL_GPL.
Make cxl_debugfs non-static in port.c and declare it extern in core.h so the debugfs file can be created under the existing CXL debugfs root.
--- drivers/cxl/Kconfig | 13 +++ drivers/cxl/core/core.h | 21 ++++ drivers/cxl/core/port.c | 2 +- drivers/cxl/core/ras.c | 208 ++++++++++++++++++++++++++++++++++ drivers/cxl/core/ras_rch.c | 12 ++ drivers/pci/pcie/aer_inject.c | 29 ++--- include/linux/aer.h | 15 +++ 7 files changed, 281 insertions(+), 19 deletions(-)
drivers/cxl/Kconfig +13 -0
@@ -238,6 +238,19 @@ config CXL_RAS def_bool y depends on ACPI_APEI_GHES && PCIEAER && CXL_BUS +config CXL_PROTO_AER_EINJ + bool "CXL: RAS Protocol Error Injection using AER EINJ" + depends on CXL_RAS + depends on PCIEAER_INJECT + help + Enable debugfs-based CXL protocol error injection. Writes to + /sys/kernel/debug/cxl/aer_einj_inject inject CXL RAS protocol + errors using the AER internal error inject interface. + + This is a debug/test facility. Say N for production kernels. + + If unsure say N. + config CXL_ATL def_bool y depends on CXL_REGION
drivers/cxl/core/core.h +21 -0
@@ -182,6 +182,9 @@ static inline struct device *dport_to_host(struct cxl_dport *dport)return port->uport_dev;return &port->dev; } + +extern struct dentry *cxl_debugfs; +#ifdef CONFIG_CXL_RAS void cxl_ras_init (void );void cxl_ras_exit (void );
@@ -244,4 +247,22 @@ int cxl_set_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid,resource_size_t cxl_rcd_component_reg_phys (struct device *dev,struct cxl_dport *dport); + +#ifdef CONFIG_CXL_PROTO_AER_EINJ + +#define AER_REGISTER_SIZE 5 +#define RAS_REGISTER_SIZE (CXL_RAS_CAPABILITY_LENGTH / sizeof(u32)) + +struct cxl_aer_einj { +int correctable; +bool is_rch; +struct mutex *lock; +struct device *dev; +u32 aer_registers[AER_REGISTER_SIZE ]; +u32 ras_registers[RAS_REGISTER_SIZE ]; +}; + +extern struct cxl_aer_einj cxl_aer_einj; +#endif +#endif /* __CXL_CORE_H__ */
drivers/cxl/core/port.c +1 -1
@@ -2501,7 +2501,7 @@ const struct bus_type cxl_bus_type = { };EXPORT_SYMBOL_NS_GPL (cxl_bus_type,"CXL" ); -static struct dentry *cxl_debugfs; +struct dentry *cxl_debugfs;struct dentry *cxl_debugfs_create_dir (const char *dir) {
drivers/cxl/core/ras.c +208 -0
236 lines not on this page · raw message
drivers/cxl/core/ras_rch.c +12 -0
@@ -110,6 +110,14 @@ void cxl_handle_rdport_errors(struct pci_dev *pdev)if (!dport)return ; +#if IS_ENABLED (CONFIG_CXL_PROTO_AER_EINJ ) +if (cxl_aer_einj.is_rch && cxl_aer_einj.dev) { + severity = cxl_aer_einj.correctable ? +AER_CORRECTABLE :AER_FATAL ; + goto handle_ras; + } +#endif +if (!cxl_rch_get_aer_info (dport->regs.dport_aer, &aer_regs))return ;
@@ -117,6 +125,10 @@ void cxl_handle_rdport_errors(struct pci_dev *pdev)return ;pci_print_aer (pdev, severity, &aer_regs); + +#if IS_ENABLED (CONFIG_CXL_PROTO_AER_EINJ ) +handle_ras: +#endif if (severity ==AER_CORRECTABLE )cxl_handle_cor_ras (dport->port, dport,to_ras_base (port, dport), pdev->dsn);
drivers/pci/pcie/aer_inject.c +11 -18
@@ -14,6 +14,7 @@#define dev_fmt (fmt) "aer_inject: " fmt +#include <linux/aer.h> #include <linux/module.h> #include <linux/init.h> #include <linux/interrupt.h>
@@ -31,19 +32,6 @@static bool aer_mask_override;module_param (aer_mask_override, bool,0 ); -struct aer_error_inj { -u8 bus; -u8 dev; -u8 fn; -u32 uncor_status; -u32 cor_status; -u32 header_log0; -u32 header_log1; -u32 header_log2; -u32 header_log3; -u32 domain; -}; -struct aer_error {struct list_head list;u32 domain;
@@ -316,7 +304,7 @@ static int pci_bus_set_aer_ops(struct pci_bus *bus)return 0 ; } -static int aer_inject (struct aer_error_inj *einj) +int aer_inject (struct aer_error_inj *einj) {struct aer_error *err, *rperr;struct aer_error *err_alloc =NULL , *rperr_alloc =NULL ;
@@ -332,10 +320,14 @@ static int aer_inject(struct aer_error_inj *einj) dev =pci_get_domain_bus_and_slot (einj->domain, einj->bus, devfn);if (!dev)return -ENODEV ; - rpdev =pcie_find_root_port (dev); -/* If Root Port not found, try to find an RCEC */ -if (!rpdev) - rpdev = dev->rcec; +if (pci_pcie_type (dev) ==PCI_EXP_TYPE_RC_EC ) + rpdev = dev; +else { + rpdev =pcie_find_root_port (dev); +/* If Root Port not found, try to find an RCEC */ +if (!rpdev) + rpdev = dev->rcec; + }if (!rpdev) {pci_err (dev,"Neither Root Port nor RCEC found\n" ); ret = -ENODEV ;
@@ -482,6 +474,7 @@ static int aer_inject(struct aer_error_inj *einj)pci_dev_put (dev);return ret; } +EXPORT_SYMBOL_GPL (aer_inject);static ssize_t aer_inject_write (struct file *filp,const char __user *ubuf,size_t usize,loff_t *off)
include/linux/aer.h +15 -0
@@ -27,6 +27,21 @@struct pci_dev ;struct work_struct ; +struct aer_error_inj { +u8 bus; +u8 dev; +u8 fn; +u32 uncor_status; +u32 cor_status; +u32 header_log0; +u32 header_log1; +u32 header_log2; +u32 header_log3; +u32 domain; +}; + +int aer_inject (struct aer_error_inj *einj); +struct pcie_tlp_log {union {u32 dw[PCIE_STD_MAX_TLP_HEADERLOG ];
Signature · 1 line
2.34.1
Dave Jiang
maintainerQuoted 132 lines · Terry Bowman
This patch is intended to provide a method of testing the recently submitted cxl series "cxl: Enable CXL PCIe Port Protocol Error handling and logging" found here:
https://lore.kernel.org/linux-cxl/[email protected]/T/#md90ec1fdd1b374bf1e32e7736e2b3e34b328c701
The changes in this patch will allow CXL RAS protocol testing by injecting AER errors using AER EINJ. The RAS register block status is updated using a central function to augment RAS register block returned by
to_ras_base(). This supports all CXL devices including Root Ports, Upstream Switch Ports, Downstream Switch Ports, Endpoints, and RCH Downstream Ports.Add debugfs-based CXL protocol error injection for testing CXL RAS error handling paths. Injects CXL RAS protocol errors using AER internal error inject interface via
/sys/kernel/debug/cxl/aer_einj_inject.RAS CXL status is set using
to_ras_base()function override when kernel configCONFIG_CXL_PROTO_AER_EINJis enabled.Usage:
echo "DDDD:BB:DD.F [UCE|CE]AER_STATUSRAS_STATUS[RCH]" > \
/sys/kernel/debug/cxl/aer_einj_injectMove struct
aer_error_injandaer_inject()tolinux/aer.hso CXL can invoke AER injection directly. Exportaer_inject()withEXPORT_SYMBOL_GPL.Make
cxl_debugfsnon-static inport.cand declare it extern incore.hso the debugfs file can be created under the existing CXL debugfs root.Co-developed-by Ben Cheatham <[email protected]>Signed-off-by Ben Cheatham <[email protected]>Signed-off-by Terry Bowman <[email protected]>--- drivers/cxl/Kconfig | 13 +++ drivers/cxl/core/core.h | 21 ++++ drivers/cxl/core/port.c | 2 +- drivers/cxl/core/ras.c | 208 ++++++++++++++++++++++++++++++++++ drivers/cxl/core/ras_rch.c | 12 ++ drivers/pci/pcie/aer_inject.c | 29 ++--- include/linux/aer.h | 15 +++ 7 files changed, 281 insertions(+), 19 deletions(-)drivers/cxl/Kconfig +13
-0@@ -238,6 +238,19 @@ config CXL_RAS def_bool y depends on ACPI_APEI_GHES && PCIEAER && CXL_BUS +config CXL_PROTO_AER_EINJ + bool "CXL: RAS Protocol Error Injection using AER EINJ" + depends on CXL_RAS + depends on PCIEAER_INJECT + help + Enable debugfs-based CXL protocol error injection. Writes to + /sys/kernel/debug/cxl/aer_einj_inject inject CXL RAS protocol + errors using the AER internal error inject interface. + + This is a debug/test facility. Say N for production kernels. + + If unsure say N. + config CXL_ATL def_bool y depends on CXL_REGIONdrivers/cxl/core/core.h +21
-0@@ -182,6 +182,9 @@ static inline struct device *dport_to_host(struct cxl_dport *dport)return port->uport_dev;return &port->dev; } + +extern struct dentry *cxl_debugfs; +#ifdef CONFIG_CXL_RAS void cxl_ras_init (void );void cxl_ras_exit (void );@@ -244,4 +247,22 @@ int cxl_set_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid,resource_size_t cxl_rcd_component_reg_phys (struct device *dev,struct cxl_dport *dport); + +#ifdef CONFIG_CXL_PROTO_AER_EINJ + +#define AER_REGISTER_SIZE 5 +#define RAS_REGISTER_SIZE (CXL_RAS_CAPABILITY_LENGTH / sizeof(u32)) + +struct cxl_aer_einj { +int correctable; +bool is_rch; +struct mutex *lock; +struct device *dev; +u32 aer_registers[AER_REGISTER_SIZE ]; +u32 ras_registers[RAS_REGISTER_SIZE ]; +}; + +extern struct cxl_aer_einj cxl_aer_einj; +#endif +#endif /* __CXL_CORE_H__ */ drivers/cxl/core/port.c +1
-1@@ -2501,7 +2501,7 @@ const struct bus_type cxl_bus_type = { };EXPORT_SYMBOL_NS_GPL (cxl_bus_type,"CXL" ); -static struct dentry *cxl_debugfs; +struct dentry *cxl_debugfs;struct dentry *cxl_debugfs_create_dir (const char *dir) {drivers/cxl/core/ras.c +1
-0@@ -3,6 +3,7 @@#include <linux/pci.h> #include <linux/aer.h> +#include <linux/debugfs.h> #include <cxl/event.h> #include <cxlmem.h> #include <cxlpci.h>
drivers/cxl/core/ras.c static void cxl_cper_prot_err_work_fn(struct work_struct *work) · line 121
Quoted 4 lines
drivers/cxl/core/ras.c +1
-0@@ -117,6 +118,195 @@ static void cxl_cper_prot_err_work_fn(struct work_struct *work) } static DECLARE_WORK(cxl_cper_prot_err_work, cxl_cper_prot_err_work_fn); +#if IS_ENABLED (CONFIG_CXL_PROTO_AER_EINJ )
Can this be moved to a header file? Prefer to not introduce #ifdef in the C source.
Quoted 192 lines
drivers/cxl/core/ras.c +188
-0+ +static DEFINE_MUTEX (cxl_aer_einj_mutex); + +struct cxl_aer_einj cxl_aer_einj = { + .lock = &cxl_aer_einj_mutex, +}; + +static const char cxl_aer_einj_usage[] = +"ssss:bb:dd.f [UCE|CE] AER_STATUS RAS_STATUS [RCH]\n" ; + +static int cxl_aer_inject_error (struct pci_dev *pdev,bool correctable, +u32 aer_status,u32 ras_status) +{ +/* RCD errors are signaled as internal errors on the associated RCEC */ +if (pci_pcie_type (pdev) ==PCI_EXP_TYPE_RC_END ) { +if (!pdev->rcec) +return -ENODEV ; + pdev = pdev->rcec; + } + +struct aer_error_inj einj = { + .bus = pdev->bus->number, + .dev =PCI_SLOT (pdev->devfn), + .fn =PCI_FUNC (pdev->devfn), + .domain =pci_domain_nr (pdev->bus), + }; +int ret; +int aer_offset; +int ras_offset; + +if (correctable) { + einj.cor_status = aer_status |PCI_ERR_COR_INTERNAL ; + aer_offset =PCI_ERR_COR_STATUS /sizeof (u32); + ras_offset =CXL_RAS_CORRECTABLE_STATUS_OFFSET /sizeof (u32); + }else { + einj.uncor_status = aer_status |PCI_ERR_UNC_INTN ; + aer_offset =PCI_ERR_UNCOR_STATUS /sizeof (u32); + ras_offset =CXL_RAS_UNCORRECTABLE_STATUS_OFFSET /sizeof (u32); + } + + cxl_aer_einj.correctable = correctable; + cxl_aer_einj.aer_registers[aer_offset] = aer_status; + cxl_aer_einj.ras_registers[ras_offset] = ras_status; + + ret =aer_inject (&einj); +if (ret) { +pr_err ("cxl-einj: aer_inject failed: %d\n" , ret); +return ret; + } + +return 0 ; +} + +static ssize_t cxl_aer_einj_write (struct file *file, +const char __user *ubuf, +size_t count,loff_t *ppos) +{ +char sbdf[16 ], severity[4 ], topology[4 ] ="" ; +unsigned int domain, bus, dev, fn; +u32 aer_status, ras_status; +struct cxl_dport *dport; +char buf[128 ]; +int nargs; +int ret; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + +if (count >=sizeof (buf)) { +pr_err ("cxl-einj: input too long (%zu bytes, max %zu)\n" , count,sizeof (buf) -1 ); +return -EINVAL ; + } + +if (copy_from_user (buf, ubuf, count)) { +pr_err ("cxl-einj: copy_from_user failed\n" ); +return -EFAULT ; + } + buf[count] ='\0' ; + + nargs =sscanf (buf,"%15s %3s %x %x %3s" , sbdf, severity, + &aer_status, &ras_status, topology); +if (nargs <4 ) { +pr_err ("cxl-einj: expected format: <SBDF> <UCE|CE> <aer_status> <ras_status>\n" ); +return -EINVAL ; + } + +if (nargs ==5 &&strcmp (topology,"RCH" ) !=0 ) +return -EINVAL ; + +if (strcmp (severity,"UCE" ) !=0 &&strcmp (severity,"CE" ) !=0 ) { +pr_err ("cxl-einj: expected 'UCE' or 'CE', got '%s'\n" , severity); +return -EINVAL ; + } + +if (sscanf (sbdf,"%x:%x:%x.%x" , &domain, &bus, &dev, &fn) !=4 ) { +pr_err ("cxl-einj: invalid SBDF format '%s', expected DDDD:BB:DD.F\n" , sbdf); +return -EINVAL ; + } + + struct pci_dev *pdev __free(pci_dev_put) = +pci_get_domain_bus_and_slot (domain, bus,PCI_DEVFN (dev, fn)); +if (!pdev) { +pr_err ("cxl-einj: device %s not found\n" , sbdf); +return -ENODEV ; + } + +guard (mutex)(cxl_aer_einj.lock); + cxl_aer_einj.dev =NULL ; + + struct cxl_port *port __free(put_cxl_port) = find_cxl_port_by_dev(&pdev->dev, &dport); +if (!port) { +dev_err (&pdev->dev,"cxl-einj: Failed to find CXL Port.\n" ); +return -ENODEV ; + } + +if (!to_ras_base (port, dport)) { +dev_err (&pdev->dev,"cxl-einj: RAS not initialized.\n" ); +return -ENODEV ; + } + + cxl_aer_einj.is_rch = (nargs ==5 &&strcmp (topology,"RCH" ) ==0 ); +if (!cxl_aer_einj.is_rch) +pci_dev_get (pdev); + cxl_aer_einj.dev = cxl_aer_einj.is_rch ? pdev->dev.parent : &pdev->dev; + ret =cxl_aer_inject_error (pdev,strcmp (severity,"CE" ) ==0 , + aer_status, ras_status); +if (ret) { +if (!cxl_aer_einj.is_rch) +pci_dev_put (pdev); + cxl_aer_einj.dev =NULL ; +pr_err ("cxl-einj: injection failed for %s: %d\n" , sbdf, ret); +return ret; + } + +return count; +} + +static ssize_t cxl_aer_einj_read (struct file *file,char __user *ubuf, +size_t count,loff_t *ppos) +{ +return simple_read_from_buffer (ubuf, count, ppos, + cxl_aer_einj_usage, +sizeof (cxl_aer_einj_usage) -1 ); +} + +static const struct file_operations cxl_ras_error_fops = { + .owner =THIS_MODULE , + .read = cxl_aer_einj_read, + .write = cxl_aer_einj_write, + .llseek = default_llseek, +}; + +static void cxl_ras_create_debugfs (struct dentry *dir) +{ +debugfs_create_file ("aer_einj_inject" ,0600 , dir,NULL , + &cxl_ras_error_fops); +} + +static void __iomem *to_einj_ras_base (struct cxl_port *port,struct cxl_dport *dport) +{ +if (dport) { +if (cxl_aer_einj.is_rch) { +if (cxl_aer_einj.dev == dport->dport_dev) { + cxl_aer_einj.dev =NULL ; +return (__force void __iomem *)cxl_aer_einj.ras_registers; + } + }else { +if (cxl_aer_einj.dev == dport->dport_dev) { +pci_dev_put (to_pci_dev (cxl_aer_einj.dev)); + cxl_aer_einj.dev =NULL ; +return (__force void __iomem *)cxl_aer_einj.ras_registers; + } + } + }else if (!cxl_aer_einj.is_rch) { +struct device *dev =is_cxl_endpoint (port) ? + port->uport_dev->parent : port->uport_dev; + +if (dev_is_pci (dev) && cxl_aer_einj.dev == dev) { +pci_dev_put (to_pci_dev (cxl_aer_einj.dev)); + cxl_aer_einj.dev =NULL ; +return (__force void __iomem *)cxl_aer_einj.ras_registers; + } + } + +return NULL ; +} +#endif +static void cxl_unmask_proto_interrupts (struct device *dev) {struct pci_dev *pdev;
drivers/cxl/core/ras.c void __iomem *to_ras_base(struct cxl_port *port, struct cxl_dport *dport) · line 431
Quoted 4 lines
drivers/cxl/core/ras.c +1
-0@@ -238,6 +428,14 @@ void __iomem *to_ras_base(struct cxl_port *port, struct cxl_dport *dport)if (!port)return NULL ; +#if IS_ENABLED (CONFIG_CXL_PROTO_AER_EINJ )
I think you can do something like below instead:
if (IS_ENABLED(CONFIG_CXL_PROTO_AER_EINJ))
DJ
Quoted 155 lines
drivers/cxl/core/ras.c +17
-0+if (cxl_aer_einj.dev) { +void __iomem *einj =to_einj_ras_base (port, dport); +if (einj) +return einj; + } +#endif +if (dport)return dport->regs.ras;@@ -458,10 +656,20 @@ void cxl_ras_init(void)cxl_cper_register_prot_err_work (&cxl_cper_prot_err_work);cxl_register_proto_err_work (&cxl_proto_err_work, cxl_proto_err_do_flush); +#if IS_ENABLED (CONFIG_CXL_PROTO_AER_EINJ ) +cxl_ras_create_debugfs (cxl_debugfs); +#endif }void cxl_ras_exit (void ) {cxl_unregister_proto_err_work ();cxl_cper_unregister_prot_err_work (); +#if IS_ENABLED (CONFIG_CXL_PROTO_AER_EINJ ) +if (cxl_aer_einj.dev) { +if (!cxl_aer_einj.is_rch) +pci_dev_put (to_pci_dev (cxl_aer_einj.dev)); + cxl_aer_einj.dev =NULL ; + } +#endif }drivers/cxl/core/ras_rch.c +12
-0@@ -110,6 +110,14 @@ void cxl_handle_rdport_errors(struct pci_dev *pdev)if (!dport)return ; +#if IS_ENABLED (CONFIG_CXL_PROTO_AER_EINJ ) +if (cxl_aer_einj.is_rch && cxl_aer_einj.dev) { + severity = cxl_aer_einj.correctable ? +AER_CORRECTABLE :AER_FATAL ; + goto handle_ras; + } +#endif +if (!cxl_rch_get_aer_info (dport->regs.dport_aer, &aer_regs))return ;@@ -117,6 +125,10 @@ void cxl_handle_rdport_errors(struct pci_dev *pdev)return ;pci_print_aer (pdev, severity, &aer_regs); + +#if IS_ENABLED (CONFIG_CXL_PROTO_AER_EINJ ) +handle_ras: +#endif if (severity ==AER_CORRECTABLE )cxl_handle_cor_ras (dport->port, dport,to_ras_base (port, dport), pdev->dsn);drivers/pci/pcie/aer_inject.c +11
-18@@ -14,6 +14,7 @@#define dev_fmt (fmt) "aer_inject: " fmt +#include <linux/aer.h> #include <linux/module.h> #include <linux/init.h> #include <linux/interrupt.h> @@ -31,19 +32,6 @@static bool aer_mask_override;module_param (aer_mask_override, bool,0 ); -struct aer_error_inj { -u8 bus; -u8 dev; -u8 fn; -u32 uncor_status; -u32 cor_status; -u32 header_log0; -u32 header_log1; -u32 header_log2; -u32 header_log3; -u32 domain; -}; -struct aer_error {struct list_head list;u32 domain;@@ -316,7 +304,7 @@ static int pci_bus_set_aer_ops(struct pci_bus *bus)return 0 ; } -static int aer_inject (struct aer_error_inj *einj) +int aer_inject (struct aer_error_inj *einj) {struct aer_error *err, *rperr;struct aer_error *err_alloc =NULL , *rperr_alloc =NULL ;@@ -332,10 +320,14 @@ static int aer_inject(struct aer_error_inj *einj) dev =pci_get_domain_bus_and_slot (einj->domain, einj->bus, devfn);if (!dev)return -ENODEV ; - rpdev =pcie_find_root_port (dev); -/* If Root Port not found, try to find an RCEC */ -if (!rpdev) - rpdev = dev->rcec; +if (pci_pcie_type (dev) ==PCI_EXP_TYPE_RC_EC ) + rpdev = dev; +else { + rpdev =pcie_find_root_port (dev); +/* If Root Port not found, try to find an RCEC */ +if (!rpdev) + rpdev = dev->rcec; + }if (!rpdev) {pci_err (dev,"Neither Root Port nor RCEC found\n" ); ret = -ENODEV ;@@ -482,6 +474,7 @@ static int aer_inject(struct aer_error_inj *einj)pci_dev_put (dev);return ret; } +EXPORT_SYMBOL_GPL (aer_inject);static ssize_t aer_inject_write (struct file *filp,const char __user *ubuf,size_t usize,loff_t *off)include/linux/aer.h +15
-0@@ -27,6 +27,21 @@struct pci_dev ;struct work_struct ; +struct aer_error_inj { +u8 bus; +u8 dev; +u8 fn; +u32 uncor_status; +u32 cor_status; +u32 header_log0; +u32 header_log1; +u32 header_log2; +u32 header_log3; +u32 domain; +}; + +int aer_inject (struct aer_error_inj *einj); +struct pcie_tlp_log {union {u32 dw[PCIE_STD_MAX_TLP_HEADERLOG ];
Quoted 138 lines · Dave Jiang
Quoted 135 lines · Terry Bowman
This patch is intended to provide a method of testing the recently submitted cxl series "cxl: Enable CXL PCIe Port Protocol Error handling and logging" found here:
https://lore.kernel.org/linux-cxl/[email protected]/T/#md90ec1fdd1b374bf1e32e7736e2b3e34b328c701
The changes in this patch will allow CXL RAS protocol testing by injecting AER errors using AER EINJ. The RAS register block status is updated using a central function to augment RAS register block returned by
to_ras_base(). This supports all CXL devices including Root Ports, Upstream Switch Ports, Downstream Switch Ports, Endpoints, and RCH Downstream Ports.Add debugfs-based CXL protocol error injection for testing CXL RAS error handling paths. Injects CXL RAS protocol errors using AER internal error inject interface via
/sys/kernel/debug/cxl/aer_einj_inject.RAS CXL status is set using
to_ras_base()function override when kernel configCONFIG_CXL_PROTO_AER_EINJis enabled.Usage:
echo "DDDD:BB:DD.F [UCE|CE]AER_STATUSRAS_STATUS[RCH]" > \
/sys/kernel/debug/cxl/aer_einj_injectMove struct
aer_error_injandaer_inject()tolinux/aer.hso CXL can invoke AER injection directly. Exportaer_inject()withEXPORT_SYMBOL_GPL.Make
cxl_debugfsnon-static inport.cand declare it extern incore.hso the debugfs file can be created under the existing CXL debugfs root.Co-developed-by Ben Cheatham <[email protected]>Signed-off-by Ben Cheatham <[email protected]>Signed-off-by Terry Bowman <[email protected]>--- drivers/cxl/Kconfig | 13 +++ drivers/cxl/core/core.h | 21 ++++ drivers/cxl/core/port.c | 2 +- drivers/cxl/core/ras.c | 208 ++++++++++++++++++++++++++++++++++ drivers/cxl/core/ras_rch.c | 12 ++ drivers/pci/pcie/aer_inject.c | 29 ++--- include/linux/aer.h | 15 +++ 7 files changed, 281 insertions(+), 19 deletions(-)drivers/cxl/Kconfig +13
-0@@ -238,6 +238,19 @@ config CXL_RAS def_bool y depends on ACPI_APEI_GHES && PCIEAER && CXL_BUS +config CXL_PROTO_AER_EINJ + bool "CXL: RAS Protocol Error Injection using AER EINJ" + depends on CXL_RAS + depends on PCIEAER_INJECT + help + Enable debugfs-based CXL protocol error injection. Writes to + /sys/kernel/debug/cxl/aer_einj_inject inject CXL RAS protocol + errors using the AER internal error inject interface. + + This is a debug/test facility. Say N for production kernels. + + If unsure say N. + config CXL_ATL def_bool y depends on CXL_REGIONdrivers/cxl/core/core.h +21
-0@@ -182,6 +182,9 @@ static inline struct device *dport_to_host(struct cxl_dport *dport)return port->uport_dev;return &port->dev; } + +extern struct dentry *cxl_debugfs; +#ifdef CONFIG_CXL_RAS void cxl_ras_init (void );void cxl_ras_exit (void );@@ -244,4 +247,22 @@ int cxl_set_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid,resource_size_t cxl_rcd_component_reg_phys (struct device *dev,struct cxl_dport *dport); + +#ifdef CONFIG_CXL_PROTO_AER_EINJ + +#define AER_REGISTER_SIZE 5 +#define RAS_REGISTER_SIZE (CXL_RAS_CAPABILITY_LENGTH / sizeof(u32)) + +struct cxl_aer_einj { +int correctable; +bool is_rch; +struct mutex *lock; +struct device *dev; +u32 aer_registers[AER_REGISTER_SIZE ]; +u32 ras_registers[RAS_REGISTER_SIZE ]; +}; + +extern struct cxl_aer_einj cxl_aer_einj; +#endif +#endif /* __CXL_CORE_H__ */ drivers/cxl/core/port.c +1
-1@@ -2501,7 +2501,7 @@ const struct bus_type cxl_bus_type = { };EXPORT_SYMBOL_NS_GPL (cxl_bus_type,"CXL" ); -static struct dentry *cxl_debugfs; +struct dentry *cxl_debugfs;struct dentry *cxl_debugfs_create_dir (const char *dir) {drivers/cxl/core/ras.c +1
-0@@ -3,6 +3,7 @@#include <linux/pci.h> #include <linux/aer.h> +#include <linux/debugfs.h> #include <cxl/event.h> #include <cxlmem.h> #include <cxlpci.h> @@ -117,6 +118,195 @@ static void cxl_cper_prot_err_work_fn(struct work_struct *work) } static DECLARE_WORK(cxl_cper_prot_err_work, cxl_cper_prot_err_work_fn);
Quoted 4 lines
drivers/cxl/core/ras.c static void cxl_cper_prot_err_work_fn(struct work_struct *work) · line 121
Quoted 1 line
drivers/cxl/core/ras.c +1
-0+#if IS_ENABLED (CONFIG_CXL_PROTO_AER_EINJ )Can this be moved to a header file? Prefer to not introduce #ifdef in the C source.
Yes, I will move to core.h.
Quoted 195 lines
Quoted 195 lines
drivers/cxl/core/ras.c +188
-0+ +static DEFINE_MUTEX (cxl_aer_einj_mutex); + +struct cxl_aer_einj cxl_aer_einj = { + .lock = &cxl_aer_einj_mutex, +}; + +static const char cxl_aer_einj_usage[] = +"ssss:bb:dd.f [UCE|CE] AER_STATUS RAS_STATUS [RCH]\n" ; + +static int cxl_aer_inject_error (struct pci_dev *pdev,bool correctable, +u32 aer_status,u32 ras_status) +{ +/* RCD errors are signaled as internal errors on the associated RCEC */ +if (pci_pcie_type (pdev) ==PCI_EXP_TYPE_RC_END ) { +if (!pdev->rcec) +return -ENODEV ; + pdev = pdev->rcec; + } + +struct aer_error_inj einj = { + .bus = pdev->bus->number, + .dev =PCI_SLOT (pdev->devfn), + .fn =PCI_FUNC (pdev->devfn), + .domain =pci_domain_nr (pdev->bus), + }; +int ret; +int aer_offset; +int ras_offset; + +if (correctable) { + einj.cor_status = aer_status |PCI_ERR_COR_INTERNAL ; + aer_offset =PCI_ERR_COR_STATUS /sizeof (u32); + ras_offset =CXL_RAS_CORRECTABLE_STATUS_OFFSET /sizeof (u32); + }else { + einj.uncor_status = aer_status |PCI_ERR_UNC_INTN ; + aer_offset =PCI_ERR_UNCOR_STATUS /sizeof (u32); + ras_offset =CXL_RAS_UNCORRECTABLE_STATUS_OFFSET /sizeof (u32); + } + + cxl_aer_einj.correctable = correctable; + cxl_aer_einj.aer_registers[aer_offset] = aer_status; + cxl_aer_einj.ras_registers[ras_offset] = ras_status; + + ret =aer_inject (&einj); +if (ret) { +pr_err ("cxl-einj: aer_inject failed: %d\n" , ret); +return ret; + } + +return 0 ; +} + +static ssize_t cxl_aer_einj_write (struct file *file, +const char __user *ubuf, +size_t count,loff_t *ppos) +{ +char sbdf[16 ], severity[4 ], topology[4 ] ="" ; +unsigned int domain, bus, dev, fn; +u32 aer_status, ras_status; +struct cxl_dport *dport; +char buf[128 ]; +int nargs; +int ret; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + +if (count >=sizeof (buf)) { +pr_err ("cxl-einj: input too long (%zu bytes, max %zu)\n" , count,sizeof (buf) -1 ); +return -EINVAL ; + } + +if (copy_from_user (buf, ubuf, count)) { +pr_err ("cxl-einj: copy_from_user failed\n" ); +return -EFAULT ; + } + buf[count] ='\0' ; + + nargs =sscanf (buf,"%15s %3s %x %x %3s" , sbdf, severity, + &aer_status, &ras_status, topology); +if (nargs <4 ) { +pr_err ("cxl-einj: expected format: <SBDF> <UCE|CE> <aer_status> <ras_status>\n" ); +return -EINVAL ; + } + +if (nargs ==5 &&strcmp (topology,"RCH" ) !=0 ) +return -EINVAL ; + +if (strcmp (severity,"UCE" ) !=0 &&strcmp (severity,"CE" ) !=0 ) { +pr_err ("cxl-einj: expected 'UCE' or 'CE', got '%s'\n" , severity); +return -EINVAL ; + } + +if (sscanf (sbdf,"%x:%x:%x.%x" , &domain, &bus, &dev, &fn) !=4 ) { +pr_err ("cxl-einj: invalid SBDF format '%s', expected DDDD:BB:DD.F\n" , sbdf); +return -EINVAL ; + } + + struct pci_dev *pdev __free(pci_dev_put) = +pci_get_domain_bus_and_slot (domain, bus,PCI_DEVFN (dev, fn)); +if (!pdev) { +pr_err ("cxl-einj: device %s not found\n" , sbdf); +return -ENODEV ; + } + +guard (mutex)(cxl_aer_einj.lock); + cxl_aer_einj.dev =NULL ; + + struct cxl_port *port __free(put_cxl_port) = find_cxl_port_by_dev(&pdev->dev, &dport); +if (!port) { +dev_err (&pdev->dev,"cxl-einj: Failed to find CXL Port.\n" ); +return -ENODEV ; + } + +if (!to_ras_base (port, dport)) { +dev_err (&pdev->dev,"cxl-einj: RAS not initialized.\n" ); +return -ENODEV ; + } + + cxl_aer_einj.is_rch = (nargs ==5 &&strcmp (topology,"RCH" ) ==0 ); +if (!cxl_aer_einj.is_rch) +pci_dev_get (pdev); + cxl_aer_einj.dev = cxl_aer_einj.is_rch ? pdev->dev.parent : &pdev->dev; + ret =cxl_aer_inject_error (pdev,strcmp (severity,"CE" ) ==0 , + aer_status, ras_status); +if (ret) { +if (!cxl_aer_einj.is_rch) +pci_dev_put (pdev); + cxl_aer_einj.dev =NULL ; +pr_err ("cxl-einj: injection failed for %s: %d\n" , sbdf, ret); +return ret; + } + +return count; +} + +static ssize_t cxl_aer_einj_read (struct file *file,char __user *ubuf, +size_t count,loff_t *ppos) +{ +return simple_read_from_buffer (ubuf, count, ppos, + cxl_aer_einj_usage, +sizeof (cxl_aer_einj_usage) -1 ); +} + +static const struct file_operations cxl_ras_error_fops = { + .owner =THIS_MODULE , + .read = cxl_aer_einj_read, + .write = cxl_aer_einj_write, + .llseek = default_llseek, +}; + +static void cxl_ras_create_debugfs (struct dentry *dir) +{ +debugfs_create_file ("aer_einj_inject" ,0600 , dir,NULL , + &cxl_ras_error_fops); +} + +static void __iomem *to_einj_ras_base (struct cxl_port *port,struct cxl_dport *dport) +{ +if (dport) { +if (cxl_aer_einj.is_rch) { +if (cxl_aer_einj.dev == dport->dport_dev) { + cxl_aer_einj.dev =NULL ; +return (__force void __iomem *)cxl_aer_einj.ras_registers; + } + }else { +if (cxl_aer_einj.dev == dport->dport_dev) { +pci_dev_put (to_pci_dev (cxl_aer_einj.dev)); + cxl_aer_einj.dev =NULL ; +return (__force void __iomem *)cxl_aer_einj.ras_registers; + } + } + }else if (!cxl_aer_einj.is_rch) { +struct device *dev =is_cxl_endpoint (port) ? + port->uport_dev->parent : port->uport_dev; + +if (dev_is_pci (dev) && cxl_aer_einj.dev == dev) { +pci_dev_put (to_pci_dev (cxl_aer_einj.dev)); + cxl_aer_einj.dev =NULL ; +return (__force void __iomem *)cxl_aer_einj.ras_registers; + } + } + +return NULL ; +} +#endif +static void cxl_unmask_proto_interrupts (struct device *dev) {struct pci_dev *pdev;@@ -238,6 +428,14 @@ void __iomem *to_ras_base(struct cxl_port *port, struct cxl_dport *dport)if (!port)return NULL ;
Quoted 8 lines
drivers/cxl/core/ras.c void __iomem *to_ras_base(struct cxl_port *port, struct cxl_dport *dport) · line 431
Quoted 1 line
drivers/cxl/core/ras.c +1
-0+#if IS_ENABLED (CONFIG_CXL_PROTO_AER_EINJ )I think you can do something like below instead:
if (
IS_ENABLED(CONFIG_CXL_PROTO_AER_EINJ))DJ
Good idea. Thanks for pointing this out.
Terry
[snip]
Jonathan Cameron
maintainerQuoted 5 lines · On Fri, 17 Jul 2026 17:57:00 -0500 Terry Bowman <[email protected]> wrote:
This patch is intended to provide a method of testing the recently submitted cxl series "cxl: Enable CXL PCIe Port Protocol Error handling and logging" found here:
https://lore.kernel.org/linux-cxl/[email protected]/T/#md90ec1fdd1b374bf1e32e7736e2b3e34b328c701
Hi Terry,
https://lore.kernel.org/linux-cxl/[email protected]
Works fine. Generally you can crop that end bit off the links.
Quoted 7 lines
The changes in this patch will allow CXL RAS protocol testing by injecting AER errors using AER EINJ. The RAS register block status is updated using a central function to augment RAS register block returned by
to_ras_base(). This supports all CXL devices including Root Ports, Upstream Switch Ports, Downstream Switch Ports, Endpoints, and RCH Downstream Ports.
Why is this an RFC rather than a final proposal? There should always be something to give the reviewer that info in the patch description. I'd actually be tempted to throw a cover letter in to have somewhere out of the way to put that information.
Is it simply because it only makes sense once the other seris lands.
Quoted 16 lines
Add debugfs-based CXL protocol error injection for testing CXL RAS error handling paths. Injects CXL RAS protocol errors using AER internal error inject interface via
/sys/kernel/debug/cxl/aer_einj_inject.RAS CXL status is set using
to_ras_base()function override when kernel configCONFIG_CXL_PROTO_AER_EINJis enabled.Usage:
echo "DDDD:BB:DD.F [UCE|CE]AER_STATUSRAS_STATUS[RCH]" > \
/sys/kernel/debug/cxl/aer_einj_injectMove struct
aer_error_injandaer_inject()tolinux/aer.hso CXL can invoke AER injection directly. Exportaer_inject()withEXPORT_SYMBOL_GPL.
Quoted 7 lines
Make
cxl_debugfsnon-static inport.cand declare it extern incore.hso the debugfs file can be created under the existing CXL debugfs root.Co-developed-by Ben Cheatham <[email protected]>Signed-off-by Ben Cheatham <[email protected]>Signed-off-by Terry Bowman <[email protected]>
+CC Ashok,
Various thing inline. Mostly this review is a bit superficial as I'd like ideally to see a cleaner separation of this at level of files etc.
Thanks,
Jonathan
Quoted 15 lines
--- drivers/cxl/Kconfig | 13 +++ drivers/cxl/core/core.h | 21 ++++ drivers/cxl/core/port.c | 2 +- drivers/cxl/core/ras.c | 208 ++++++++++++++++++++++++++++++++++ drivers/cxl/core/ras_rch.c | 12 ++ drivers/pci/pcie/aer_inject.c | 29 ++--- include/linux/aer.h | 15 +++ 7 files changed, 281 insertions(+), 19 deletions(-)drivers/cxl/Kconfig +0
-0
drivers/cxl/Kconfig config CXL_RAS · line 244
Quoted 7 lines
drivers/cxl/Kconfig +4
-0@@ -238,6 +238,19 @@ config CXL_RAS def_bool y depends on ACPI_APEI_GHES && PCIEAER && CXL_BUS +config CXL_PROTO_AER_EINJ + bool "CXL: RAS Protocol Error Injection using AER EINJ" + depends on CXL_RAS + depends on PCIEAER_INJECT
Do we think anyone who has CXL and PCIEAER_INJECT support will want to carefully not build this? I'm just wondering if we can avoid asking the question and base the built or not on the combination of those.
Quoted 13 lines
drivers/cxl/Kconfig +8
-0+ help + Enable debugfs-based CXL protocol error injection. Writes to + /sys/kernel/debug/cxl/aer_einj_inject inject CXL RAS protocol + errors using the AER internal error inject interface. + + This is a debug/test facility. Say N for production kernels. + + If unsure say N.drivers/cxl/core/core.h +0
-0
...
drivers/cxl/core/core.h int cxl_set_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid, · line 251
Quoted 6 lines
drivers/cxl/core/core.h +2
-0@@ -244,4 +247,22 @@ int cxl_set_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid,resource_size_t cxl_rcd_component_reg_phys (struct device *dev,struct cxl_dport *dport); + +#ifdef CONFIG_CXL_PROTO_AER_EINJ
Do we need the ifdefs? If the option isn't built none of this should get used. So small benefit.
Quoted 29 lines
drivers/cxl/core/core.h +15
-0+ +#define AER_REGISTER_SIZE 5 +#define RAS_REGISTER_SIZE (CXL_RAS_CAPABILITY_LENGTH / sizeof(u32)) + +struct cxl_aer_einj { +int correctable; +bool is_rch; +struct mutex *lock; +struct device *dev; +u32 aer_registers[AER_REGISTER_SIZE ]; +u32 ras_registers[RAS_REGISTER_SIZE ]; +}; + +extern struct cxl_aer_einj cxl_aer_einj; +#endif drivers/cxl/core/ras.c +1
-0@@ -3,6 +3,7 @@#include <linux/pci.h> #include <linux/aer.h> +#include <linux/debugfs.h> #include <cxl/event.h> #include <cxlmem.h> #include <cxlpci.h>
drivers/cxl/core/ras.c static void cxl_cper_prot_err_work_fn(struct work_struct *work) · line 122
Quoted 5 lines
drivers/cxl/core/ras.c +2
-0@@ -117,6 +118,195 @@ static void cxl_cper_prot_err_work_fn(struct work_struct *work) } static DECLARE_WORK(cxl_cper_prot_err_work, cxl_cper_prot_err_work_fn); +#if IS_ENABLED (CONFIG_CXL_PROTO_AER_EINJ ) +
Unless very strong reasons for it, generally don't do #if stuff in c files. Just have a separate c file for this. Otherwise it hurts readability and we tend to loose the clean separation over time. A file makes that less likely.
drivers/cxl/core/ras.c static void cxl_cper_prot_err_work_fn(struct work_struct *work) · line 123
Quoted 1 line
drivers/cxl/core/ras.c +1
-0+static DEFINE_MUTEX (cxl_aer_einj_mutex);
Needs a comment for what data it is protecting.
Quoted 22 lines
drivers/cxl/core/ras.c +22
-0+ +struct cxl_aer_einj cxl_aer_einj = { + .lock = &cxl_aer_einj_mutex, +}; + +static const char cxl_aer_einj_usage[] = +"ssss:bb:dd.f [UCE|CE] AER_STATUS RAS_STATUS [RCH]\n" ; + +static int cxl_aer_inject_error (struct pci_dev *pdev,bool correctable, +u32 aer_status,u32 ras_status) +{ +/* RCD errors are signaled as internal errors on the associated RCEC */ +if (pci_pcie_type (pdev) ==PCI_EXP_TYPE_RC_END ) { +if (!pdev->rcec) +return -ENODEV ; + pdev = pdev->rcec; + } + +struct aer_error_inj einj = { + .bus = pdev->bus->number, + .dev =PCI_SLOT (pdev->devfn), + .fn =PCI_FUNC (pdev->devfn),
drivers/cxl/core/ras.c static void cxl_cper_prot_err_work_fn(struct work_struct *work) · line 155
Quoted 10 lines
drivers/cxl/core/ras.c +10
-0+ .domain = pci_domain_nr(pdev->bus), + }; +int ret; +int aer_offset; +int ras_offset; + +if (correctable) { + einj.cor_status = aer_status |PCI_ERR_COR_INTERNAL ; + aer_offset =PCI_ERR_COR_STATUS /sizeof (u32); + ras_offset =CXL_RAS_CORRECTABLE_STATUS_OFFSET /sizeof (u32);
Given these are offsets into cxl_aer_einj.aer_registers / ras_registers can we use sizeof(*cxl_aer_einj.aer_registers) etc
Quoted 12 lines
drivers/cxl/core/ras.c +12
-0+ }else { + einj.uncor_status = aer_status |PCI_ERR_UNC_INTN ; + aer_offset =PCI_ERR_UNCOR_STATUS /sizeof (u32); + ras_offset =CXL_RAS_UNCORRECTABLE_STATUS_OFFSET /sizeof (u32); + } + + cxl_aer_einj.correctable = correctable; + cxl_aer_einj.aer_registers[aer_offset] = aer_status; + cxl_aer_einj.ras_registers[ras_offset] = ras_status; + + ret =aer_inject (&einj); +if (ret) {
drivers/cxl/core/ras.c static void cxl_cper_prot_err_work_fn(struct work_struct *work) · line 177
Quoted 10 lines
drivers/cxl/core/ras.c +10
-0+pr_err ("cxl-einj: aer_inject failed: %d\n" , ret); +return ret; + } + +return 0 ; +} + +static ssize_t cxl_aer_einj_write (struct file *file, +const char __user *ubuf, +size_t count,loff_t *ppos)
Might as well wrap to 80 chars and save a line.
Quoted 1 line
drivers/cxl/core/ras.c +1
-0+{
...
Quoted 6 lines
drivers/cxl/core/ras.c +6
-0+ + struct cxl_port *port __free(put_cxl_port) = find_cxl_port_by_dev(&pdev->dev, &dport); +if (!port) { +dev_err (&pdev->dev,"cxl-einj: Failed to find CXL Port.\n" ); +return -ENODEV ; + }
drivers/cxl/core/ras.c static void cxl_cper_prot_err_work_fn(struct work_struct *work) · line 245
Quoted 10 lines
drivers/cxl/core/ras.c +10
-0+ +if (!to_ras_base (port, dport)) { +dev_err (&pdev->dev,"cxl-einj: RAS not initialized.\n" ); +return -ENODEV ; + } + + cxl_aer_einj.is_rch = (nargs ==5 &&strcmp (topology,"RCH" ) ==0 ); +if (!cxl_aer_einj.is_rch) +pci_dev_get (pdev); + cxl_aer_einj.dev = cxl_aer_einj.is_rch ? pdev->dev.parent : &pdev->dev;
cxl_aer_einj.dev = cxl_aer_einj.is_rch ? pdev->dev.parent : pci_dev_get(&pdev->dev);
Or use an if else for both is_rch based choices.
Lazy me wonders.... Can we just grab a reference to the dev.parent for is_rch and simplify the code? We don't really need it I think but it is harmless.
Quoted 8 lines
drivers/cxl/core/ras.c +8
-0+ ret =cxl_aer_inject_error (pdev,strcmp (severity,"CE" ) ==0 , + aer_status, ras_status); +if (ret) { +if (!cxl_aer_einj.is_rch) +pci_dev_put (pdev); + cxl_aer_einj.dev =NULL ; +pr_err ("cxl-einj: injection failed for %s: %d\n" , sbdf, ret); +return ret;
drivers/cxl/core/ras.c static void cxl_cper_prot_err_work_fn(struct work_struct *work) · line 263
Quoted 10 lines
drivers/cxl/core/ras.c +10
-0+ } + +return count; +} + +static ssize_t cxl_aer_einj_read (struct file *file,char __user *ubuf, +size_t count,loff_t *ppos) +{ + return simple_read_from_buffer(ubuf, count, ppos, + cxl_aer_einj_usage,
Probably wrap this to push that up a line.
drivers/cxl/core/ras.c static void cxl_cper_prot_err_work_fn(struct work_struct *work) · line 286
Quoted 11 lines
drivers/cxl/core/ras.c +10
-0+ sizeof(cxl_aer_einj_usage) - 1); +} + +static void __iomem *to_einj_ras_base (struct cxl_port *port,struct cxl_dport *dport) +{ +if (dport) { +if (cxl_aer_einj.is_rch) { +if (cxl_aer_einj.dev == dport->dport_dev) { + cxl_aer_einj.dev =NULL ; +return (__force void __iomem *)cxl_aer_einj.ras_registers;
Given the output of this is always force cast, maybe move that force up to the caller?
drivers/cxl/core/ras.c static void cxl_cper_prot_err_work_fn(struct work_struct *work) · line 290
Quoted 4 lines
drivers/cxl/core/ras.c +4
-0+ } + }else { +if (cxl_aer_einj.dev == dport->dport_dev) { +pci_dev_put (to_pci_dev (cxl_aer_einj.dev));
Not locally obvious why a thing called to_einj_ras_base should put anything it didn't get. I think this needs a restructure to more obviously be tidying up references that were held over the queue. At very leads needs a comment.
/* Reference held from X no longer needed so drop */
Quoted 23 lines
drivers/cxl/core/ras.c +19
-0+ cxl_aer_einj.dev =NULL ; + return (__force void __iomem *)cxl_aer_einj.ras_registers; + } + } + }else if (!cxl_aer_einj.is_rch) { +struct device *dev =is_cxl_endpoint (port) ? + port->uport_dev->parent : port->uport_dev; + +if (dev_is_pci (dev) && cxl_aer_einj.dev == dev) { +pci_dev_put (to_pci_dev (cxl_aer_einj.dev)); + cxl_aer_einj.dev =NULL ; +return (__force void __iomem *)cxl_aer_einj.ras_registers; + } + } + +return NULL ; +} +#endif +static void cxl_unmask_proto_interrupts (struct device *dev) {struct pci_dev *pdev;
drivers/cxl/core/ras.c void __iomem *to_ras_base(struct cxl_port *port, struct cxl_dport *dport) · line 431
Quoted 4 lines
drivers/cxl/core/ras.c +1
-0@@ -238,6 +428,14 @@ void __iomem *to_ras_base(struct cxl_port *port, struct cxl_dport *dport)if (!port)return NULL ; +#if IS_ENABLED (CONFIG_CXL_PROTO_AER_EINJ )
Wrap with
if (IS_ENABLED()) to keep it visible to the compiler.
Quoted 11 lines
drivers/cxl/core/ras.c +7
-0+if (cxl_aer_einj.dev) { +void __iomem *einj =to_einj_ras_base (port, dport); +if (einj) +return einj; + } +#endif +if (dport)return dport->regs.ras;
drivers/cxl/core/ras.c void cxl_ras_init(void) · line 660
Quoted 5 lines
drivers/cxl/core/ras.c +2
-0@@ -458,10 +656,20 @@ void cxl_ras_init(void)cxl_cper_register_prot_err_work (&cxl_cper_prot_err_work);cxl_register_proto_err_work (&cxl_proto_err_work, cxl_proto_err_do_flush); +#if IS_ENABLED (CONFIG_CXL_PROTO_AER_EINJ ) +cxl_ras_create_debugfs (cxl_debugfs);
stub that in a header.
drivers/cxl/core/ras.c void cxl_ras_init(void) · line 668
Quoted 8 lines
drivers/cxl/core/ras.c +2
-0+#endif }void cxl_ras_exit (void ) {cxl_unregister_proto_err_work ();cxl_cper_unregister_prot_err_work (); +#if IS_ENABLED (CONFIG_CXL_PROTO_AER_EINJ )
As below. Use
if (IS_ENABLED())
and keep everything visible.
Quoted 12 lines
drivers/cxl/core/ras.c +6
-0+if (cxl_aer_einj.dev) { +if (!cxl_aer_einj.is_rch) +pci_dev_put (to_pci_dev (cxl_aer_einj.dev)); + cxl_aer_einj.dev =NULL ; + } +#endif }drivers/cxl/core/ras_rch.c +0
-0
drivers/cxl/core/ras_rch.c void cxl_handle_rdport_errors(struct pci_dev *pdev) · line 118
Quoted 9 lines
drivers/cxl/core/ras_rch.c +6
-0@@ -110,6 +110,14 @@ void cxl_handle_rdport_errors(struct pci_dev *pdev)if (!dport)return ; +#if IS_ENABLED (CONFIG_CXL_PROTO_AER_EINJ ) +if (cxl_aer_einj.is_rch && cxl_aer_einj.dev) { + severity = cxl_aer_einj.correctable ? +AER_CORRECTABLE :AER_FATAL ; + goto handle_ras; + }
Use instead
if (IS_ENABLED(CONFIG_CXL_PROTO_AR_EINJ))
then compiler can see the code (but remove it) which means you don't need the dance around the label below.
In general follow this pattern anyway rather than #if when you can.
Quoted 58 lines
drivers/cxl/core/ras_rch.c +6
-0+#endif +if (!cxl_rch_get_aer_info (dport->regs.dport_aer, &aer_regs))return ;@@ -117,6 +125,10 @@ void cxl_handle_rdport_errors(struct pci_dev *pdev)return ;pci_print_aer (pdev, severity, &aer_regs); + +#if IS_ENABLED (CONFIG_CXL_PROTO_AER_EINJ ) +handle_ras: +#endif if (severity ==AER_CORRECTABLE )cxl_handle_cor_ras (dport->port, dport,to_ras_base (port, dport), pdev->dsn);drivers/pci/pcie/aer_inject.c +2
-14@@ -14,6 +14,7 @@#define dev_fmt (fmt) "aer_inject: " fmt +#include <linux/aer.h> #include <linux/module.h> #include <linux/init.h> #include <linux/interrupt.h> @@ -31,19 +32,6 @@static bool aer_mask_override;module_param (aer_mask_override, bool,0 ); -struct aer_error_inj { -u8 bus; -u8 dev; -u8 fn; -u32 uncor_status; -u32 cor_status; -u32 header_log0; -u32 header_log1; -u32 header_log2; -u32 header_log3; -u32 domain; -}; -struct aer_error {struct list_head list;u32 domain;@@ -316,7 +304,7 @@ static int pci_bus_set_aer_ops(struct pci_bus *bus)return 0 ; } -static int aer_inject (struct aer_error_inj *einj) +int aer_inject (struct aer_error_inj *einj) {struct aer_error *err, *rperr;struct aer_error *err_alloc =NULL , *rperr_alloc =NULL ;
drivers/pci/pcie/aer_inject.c static int aer_inject(struct aer_error_inj *einj) · line 323
Quoted 8 lines
drivers/pci/pcie/aer_inject.c +1
-4@@ -332,10 +320,14 @@ static int aer_inject(struct aer_error_inj *einj) dev =pci_get_domain_bus_and_slot (einj->domain, einj->bus, devfn);if (!dev)return -ENODEV ; - rpdev =pcie_find_root_port (dev); -/* If Root Port not found, try to find an RCEC */ -if (!rpdev) - rpdev = dev->rcec; +if (pci_pcie_type (dev) ==PCI_EXP_TYPE_RC_EC )
{ }
as the else is multiline (see coding standard)
Maybe need a comment for why it might be an RCEC for injection. Is this an RCH specific path where there is nothing else to target?
Quoted 11 lines
drivers/pci/pcie/aer_inject.c +7
-0+ rpdev = dev; + else { + rpdev =pcie_find_root_port (dev); +/* If Root Port not found, try to find an RCEC */ +if (!rpdev) + rpdev = dev->rcec; + }if (!rpdev) {pci_err (dev,"Neither Root Port nor RCEC found\n" ); ret = -ENODEV ;
drivers/pci/pcie/aer_inject.c static int aer_inject(struct aer_error_inj *einj) · line 477
Quoted 4 lines
drivers/pci/pcie/aer_inject.c +1
-0@@ -482,6 +474,7 @@ static int aer_inject(struct aer_error_inj *einj)pci_dev_put (dev);return ret; } +EXPORT_SYMBOL_GPL (aer_inject);
I wonder if we want to restrict this to specific modules?
One for Bjorn probably.
Quoted 29 lines
drivers/pci/pcie/aer_inject.c +0
-0static ssize_t aer_inject_write (struct file *filp,const char __user *ubuf,size_t usize,loff_t *off)include/linux/aer.h +15
-0@@ -27,6 +27,21 @@struct pci_dev ;struct work_struct ; +struct aer_error_inj { +u8 bus; +u8 dev; +u8 fn; +u32 uncor_status; +u32 cor_status; +u32 header_log0; +u32 header_log1; +u32 header_log2; +u32 header_log3; +u32 domain; +}; + +int aer_inject (struct aer_error_inj *einj); +struct pcie_tlp_log {union {u32 dw[PCIE_STD_MAX_TLP_HEADERLOG ];
Quoted 7 lines · Jonathan Cameron
Quoted 4 lines · On Fri, 17 Jul 2026 17:57:00 -0500 Terry Bowman <[email protected]> wrote:
This patch is intended to provide a method of testing the recently submitted cxl series "cxl: Enable CXL PCIe Port Protocol Error handling and logging" found here:
Quoted 8 lines
Quoted 1 line
https://lore.kernel.org/linux-cxl/[email protected]/T/#md90ec1fdd1b374bf1e32e7736e2b3e34b328c701
Hi Terry,
https://lore.kernel.org/linux-cxl/[email protected]
Works fine. Generally you can crop that end bit off the links.
Good to know. I'll use that going forward.
Quoted 8 lines
Quoted 7 lines
The changes in this patch will allow CXL RAS protocol testing by injecting AER errors using AER EINJ. The RAS register block status is updated using a central function to augment RAS register block returned by
to_ras_base(). This supports all CXL devices including Root Ports, Upstream Switch Ports, Downstream Switch Ports, Endpoints, and RCH Downstream Ports.
Quoted 7 lines
Why is this an RFC rather than a final proposal? There should always be something to give the reviewer that info in the patch description. I'd actually be tempted to throw a cover letter in to have somewhere out of the way to put that information.
Is it simply because it only makes sense once the other seris lands.
The immediate priority was providing a testing procedure for the v18 series. I wasn't sure how the design would be received. For instance, the to_einj_ras_base() could be moved into cxl-test as a to_ras_base() mock implemented function or it could remain in ras.c (or maybe even ras_einj.c) outside of cxl-mock. I'm looking forward to Alison's review and comments.
My preference is to introduce core/ras_einj,c and add these changes. This would be to isolate all the changes except for: cxl_ras_einj_init(), cxl_ras_einj_exit(), and to_einj_ras_base(). I've started moving forward with making these changes knowing the direction could change once this receives more reviews.
Also worth discussing is the commandline takes multiple parameters for a single sysfs file which I know isn't acceptable by everyone. I personally like the interface as-is because its simpler to use in comparison to multiple files that must be set individually.
Quoted 49 lines
Quoted 16 lines
Add debugfs-based CXL protocol error injection for testing CXL RAS error handling paths. Injects CXL RAS protocol errors using AER internal error inject interface via
/sys/kernel/debug/cxl/aer_einj_inject.RAS CXL status is set using
to_ras_base()function override when kernel configCONFIG_CXL_PROTO_AER_EINJis enabled.Usage:
echo "DDDD:BB:DD.F [UCE|CE]AER_STATUSRAS_STATUS[RCH]" > \
/sys/kernel/debug/cxl/aer_einj_injectMove struct
aer_error_injandaer_inject()tolinux/aer.hso CXL can invoke AER injection directly. Exportaer_inject()withEXPORT_SYMBOL_GPL.Quoted 7 lines
Make
cxl_debugfsnon-static inport.cand declare it extern incore.hso the debugfs file can be created under the existing CXL debugfs root.Co-developed-by Ben Cheatham <[email protected]>Signed-off-by Ben Cheatham <[email protected]>Signed-off-by Terry Bowman <[email protected]>+CC Ashok,
Various thing inline. Mostly this review is a bit superficial as I'd like ideally to see a cleaner separation of this at level of files etc.
Thanks,
Jonathan
Quoted 18 lines
--- drivers/cxl/Kconfig | 13 +++ drivers/cxl/core/core.h | 21 ++++ drivers/cxl/core/port.c | 2 +- drivers/cxl/core/ras.c | 208 ++++++++++++++++++++++++++++++++++ drivers/cxl/core/ras_rch.c | 12 ++ drivers/pci/pcie/aer_inject.c | 29 ++--- include/linux/aer.h | 15 +++ 7 files changed, 281 insertions(+), 19 deletions(-)drivers/cxl/Kconfig +0
-0@@ -238,6 +238,19 @@ config CXL_RAS def_bool y depends on ACPI_APEI_GHES && PCIEAER && CXL_BUS
Quoted 9 lines
drivers/cxl/Kconfig config CXL_RAS · line 244
Quoted 4 lines
drivers/cxl/Kconfig +4
-0+config CXL_PROTO_AER_EINJ + bool "CXL: RAS Protocol Error Injection using AER EINJ" + depends on CXL_RAS + depends on PCIEAER_INJECTDo we think anyone who has CXL and
PCIEAER_INJECTsupport will want to carefully not build this? I'm just wondering if we can avoid asking the question and base the built or not on the combination of those.
Good question: How do we incorporate this with the existing CXL EINJ functionality making them complementary and consistant? The existing EINJ is true ACPI injection but only supports RPs. The ACPI EINJ callouts are currrently in core/port.c. We should consider moving it into a common file such as core/ras_einj.c. With that move it will help force us merge the interfaces where/if possible and at least give central location for error RAS injection. I think folding the AER injection into PCIEAER_INJECT kernel config is reasonable but looking for others feedback.
Quoted 17 lines
Quoted 13 lines
drivers/cxl/Kconfig +8
-0+ help + Enable debugfs-based CXL protocol error injection. Writes to + /sys/kernel/debug/cxl/aer_einj_inject inject CXL RAS protocol + errors using the AER internal error inject interface. + + This is a debug/test facility. Say N for production kernels. + + If unsure say N.drivers/cxl/core/core.h +0
-0...
Quoted 2 lines
drivers/cxl/core/core.h +0
-0@@ -244,4 +247,22 @@ int cxl_set_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid,
Quoted 8 lines
drivers/cxl/core/core.h int cxl_set_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid, · line 251
Quoted 4 lines
drivers/cxl/core/core.h +2
-0resource_size_t cxl_rcd_component_reg_phys (struct device *dev,struct cxl_dport *dport); + +#ifdef CONFIG_CXL_PROTO_AER_EINJ Do we need the ifdefs? If the option isn't built none of this should get used. So small benefit.
Youre right. You pointed that trick/pattern out before and results in less unneeded code. I'll make that change.
Quoted 32 lines
Quoted 32 lines
drivers/cxl/core/core.h +15
-0+ +#define AER_REGISTER_SIZE 5 +#define RAS_REGISTER_SIZE (CXL_RAS_CAPABILITY_LENGTH / sizeof(u32)) + +struct cxl_aer_einj { +int correctable; +bool is_rch; +struct mutex *lock; +struct device *dev; +u32 aer_registers[AER_REGISTER_SIZE ]; +u32 ras_registers[RAS_REGISTER_SIZE ]; +}; + +extern struct cxl_aer_einj cxl_aer_einj; +#endif drivers/cxl/core/ras.c +1
-0@@ -3,6 +3,7 @@#include <linux/pci.h> #include <linux/aer.h> +#include <linux/debugfs.h> #include <cxl/event.h> #include <cxlmem.h> #include <cxlpci.h> @@ -117,6 +118,195 @@ static void cxl_cper_prot_err_work_fn(struct work_struct *work) } static DECLARE_WORK(cxl_cper_prot_err_work, cxl_cper_prot_err_work_fn);
Quoted 8 lines
drivers/cxl/core/ras.c static void cxl_cper_prot_err_work_fn(struct work_struct *work) · line 122
Quoted 2 lines
drivers/cxl/core/ras.c +2
-0+#if IS_ENABLED (CONFIG_CXL_PROTO_AER_EINJ ) +Unless very strong reasons for it, generally don't do #if stuff in c files. Just have a separate c file for this. Otherwise it hurts readability and we tend to loose the clean separation over time. A file makes that less likely.
Ok.
Quoted 32 lines
drivers/cxl/core/ras.c static void cxl_cper_prot_err_work_fn(struct work_struct *work) · line 123
Quoted 2 lines
drivers/cxl/core/ras.c +1
-0+static DEFINE_MUTEX (cxl_aer_einj_mutex);Needs a comment for what data it is protecting.
Quoted 27 lines
drivers/cxl/core/ras.c +27
-0+ +struct cxl_aer_einj cxl_aer_einj = { + .lock = &cxl_aer_einj_mutex, +}; + +static const char cxl_aer_einj_usage[] = +"ssss:bb:dd.f [UCE|CE] AER_STATUS RAS_STATUS [RCH]\n" ; + +static int cxl_aer_inject_error (struct pci_dev *pdev,bool correctable, +u32 aer_status,u32 ras_status) +{ +/* RCD errors are signaled as internal errors on the associated RCEC */ +if (pci_pcie_type (pdev) ==PCI_EXP_TYPE_RC_END ) { +if (!pdev->rcec) +return -ENODEV ; + pdev = pdev->rcec; + } + +struct aer_error_inj einj = { + .bus = pdev->bus->number, + .dev =PCI_SLOT (pdev->devfn), + .fn =PCI_FUNC (pdev->devfn), + .domain =pci_domain_nr (pdev->bus), + }; +int ret; +int aer_offset; +int ras_offset;
Quoted 9 lines
drivers/cxl/core/ras.c static void cxl_cper_prot_err_work_fn(struct work_struct *work) · line 155
Quoted 5 lines
drivers/cxl/core/ras.c +5
-0+ +if (correctable) { + einj.cor_status = aer_status |PCI_ERR_COR_INTERNAL ; + aer_offset =PCI_ERR_COR_STATUS /sizeof (u32); + ras_offset =CXL_RAS_CORRECTABLE_STATUS_OFFSET /sizeof (u32);Given these are offsets into cxl_aer_einj.aer_registers /
ras_registerscan we usesizeof(*cxl_aer_einj.aer_registers)etc
We could but that assumes the CEs are book ending the register blocks. And this would be inconsistent with UCE case below, right? Tell me if I misunderstaood the question.
Quoted 16 lines
Quoted 16 lines
drivers/cxl/core/ras.c +16
-0+ }else { + einj.uncor_status = aer_status |PCI_ERR_UNC_INTN ; + aer_offset =PCI_ERR_UNCOR_STATUS /sizeof (u32); + ras_offset =CXL_RAS_UNCORRECTABLE_STATUS_OFFSET /sizeof (u32); + } + + cxl_aer_einj.correctable = correctable; + cxl_aer_einj.aer_registers[aer_offset] = aer_status; + cxl_aer_einj.ras_registers[ras_offset] = ras_status; + + ret =aer_inject (&einj); +if (ret) { +pr_err ("cxl-einj: aer_inject failed: %d\n" , ret); +return ret; + } +
Quoted 9 lines
drivers/cxl/core/ras.c static void cxl_cper_prot_err_work_fn(struct work_struct *work) · line 177
Quoted 6 lines
drivers/cxl/core/ras.c +6
-0+return 0 ; +} + +static ssize_t cxl_aer_einj_write (struct file *file, +const char __user *ubuf, +size_t count,loff_t *ppos)Might as well wrap to 80 chars and save a line.
Ok
Quoted 23 lines
Quoted 1 line
drivers/cxl/core/ras.c +1
-0+{...
Quoted 6 lines
drivers/cxl/core/ras.c +6
-0+ + struct cxl_port *port __free(put_cxl_port) = find_cxl_port_by_dev(&pdev->dev, &dport); +if (!port) { +dev_err (&pdev->dev,"cxl-einj: Failed to find CXL Port.\n" ); +return -ENODEV ; + }drivers/cxl/core/ras.c static void cxl_cper_prot_err_work_fn(struct work_struct *work) · line 245
Quoted 10 lines
drivers/cxl/core/ras.c +10
-0+ +if (!to_ras_base (port, dport)) { +dev_err (&pdev->dev,"cxl-einj: RAS not initialized.\n" ); +return -ENODEV ; + } + + cxl_aer_einj.is_rch = (nargs ==5 &&strcmp (topology,"RCH" ) ==0 ); +if (!cxl_aer_einj.is_rch) +pci_dev_get (pdev); + cxl_aer_einj.dev = cxl_aer_einj.is_rch ? pdev->dev.parent : &pdev->dev;cxl_aer_einj.dev = cxl_aer_einj.is_rch ? pdev->dev.parent : pci_dev_get(&pdev->dev);
Quoted 5 lines
Or use an if else for both
is_rchbased choices.
Lazy me wonders.... Can we just grab a reference to the dev.parent foris_rchand simplify the code? We don't really need it I think but it is harmless.
Your change is cleaner and the parent ref increment doesnt hurt as you mentioned.
Quoted 12 lines
Quoted 12 lines
drivers/cxl/core/ras.c +12
-0+ ret =cxl_aer_inject_error (pdev,strcmp (severity,"CE" ) ==0 , + aer_status, ras_status); +if (ret) { +if (!cxl_aer_einj.is_rch) +pci_dev_put (pdev); + cxl_aer_einj.dev =NULL ; +pr_err ("cxl-einj: injection failed for %s: %d\n" , sbdf, ret); +return ret; + } + +return count; +}
Quoted 9 lines
drivers/cxl/core/ras.c static void cxl_cper_prot_err_work_fn(struct work_struct *work) · line 263
Quoted 6 lines
drivers/cxl/core/ras.c +6
-0+ +static ssize_t cxl_aer_einj_read (struct file *file,char __user *ubuf, +size_t count,loff_t *ppos) +{ + return simple_read_from_buffer(ubuf, count, ppos, + cxl_aer_einj_usage,Probably wrap this to push that up a line.
Ok
Quoted 14 lines
drivers/cxl/core/ras.c static void cxl_cper_prot_err_work_fn(struct work_struct *work) · line 286
Quoted 11 lines
drivers/cxl/core/ras.c +10
-0+ sizeof(cxl_aer_einj_usage) - 1); +} + +static void __iomem *to_einj_ras_base (struct cxl_port *port,struct cxl_dport *dport) +{ +if (dport) { +if (cxl_aer_einj.is_rch) { +if (cxl_aer_einj.dev == dport->dport_dev) { + cxl_aer_einj.dev =NULL ; +return (__force void __iomem *)cxl_aer_einj.ras_registers;Given the output of this is always force cast, maybe move that force up to the caller?
I think that works if it remains an internal helper and isn't made a mock function to to_ras_base(). If to_einj_ras_base() is used as a mock than it would require changing the to_ras_base() as well.
Quoted 10 lines
drivers/cxl/core/ras.c static void cxl_cper_prot_err_work_fn(struct work_struct *work) · line 290
Quoted 4 lines
drivers/cxl/core/ras.c +4
-0+ } + }else { +if (cxl_aer_einj.dev == dport->dport_dev) { +pci_dev_put (to_pci_dev (cxl_aer_einj.dev));Not locally obvious why a thing called
to_einj_ras_baseshould put anything it didn't get. I think this needs a restructure to more obviously be tidying up references that were held over the queue. At very leads needs a comment.
/* Reference held from X no longer needed so drop */
The ref was incremented in cxl_aer_einj_write() on invoking injection. The ref is decremented here after its usage. RCHs are excluded because they dont have a SBDF.
Quoted 26 lines
Quoted 26 lines
drivers/cxl/core/ras.c +19
-0+ cxl_aer_einj.dev =NULL ; + return (__force void __iomem *)cxl_aer_einj.ras_registers; + } + } + }else if (!cxl_aer_einj.is_rch) { +struct device *dev =is_cxl_endpoint (port) ? + port->uport_dev->parent : port->uport_dev; + +if (dev_is_pci (dev) && cxl_aer_einj.dev == dev) { +pci_dev_put (to_pci_dev (cxl_aer_einj.dev)); + cxl_aer_einj.dev =NULL ; +return (__force void __iomem *)cxl_aer_einj.ras_registers; + } + } + +return NULL ; +} +#endif +static void cxl_unmask_proto_interrupts (struct device *dev) {struct pci_dev *pdev;@@ -238,6 +428,14 @@ void __iomem *to_ras_base(struct cxl_port *port, struct cxl_dport *dport)if (!port)return NULL ;
Quoted 5 lines
drivers/cxl/core/ras.c void __iomem *to_ras_base(struct cxl_port *port, struct cxl_dport *dport) · line 431
Quoted 1 line
drivers/cxl/core/ras.c +1
-0+#if IS_ENABLED (CONFIG_CXL_PROTO_AER_EINJ )Wrap with
if (IS_ENABLED()) to keep it visible to the compiler.
Ok
Quoted 10 lines
Quoted 10 lines
drivers/cxl/core/ras.c +7
-0+if (cxl_aer_einj.dev) { +void __iomem *einj =to_einj_ras_base (port, dport); +if (einj) +return einj; + } +#endif +if (dport)return dport->regs.ras;
Quoted 8 lines
drivers/cxl/core/ras.c void cxl_ras_init(void) · line 660
Quoted 6 lines
drivers/cxl/core/ras.c +2
-0@@ -458,10 +656,20 @@ void cxl_ras_init(void)cxl_cper_register_prot_err_work (&cxl_cper_prot_err_work);cxl_register_proto_err_work (&cxl_proto_err_work, cxl_proto_err_do_flush); +#if IS_ENABLED (CONFIG_CXL_PROTO_AER_EINJ ) +cxl_ras_create_debugfs (cxl_debugfs);stub that in a header.
Actually, during rework today I moved it to cxl_ras_einj_init(), a new function. Thoughts?
Quoted 10 lines
drivers/cxl/core/ras.c void cxl_ras_init(void) · line 668
Quoted 8 lines
drivers/cxl/core/ras.c +2
-0+#endif }void cxl_ras_exit (void ) {cxl_unregister_proto_err_work ();cxl_cper_unregister_prot_err_work (); +#if IS_ENABLED (CONFIG_CXL_PROTO_AER_EINJ )As below. Use
Quoted 4 lines
if (IS_ENABLED())and keep everything visible.
Ok
Quoted 25 lines
Quoted 12 lines
drivers/cxl/core/ras.c +6
-0+if (cxl_aer_einj.dev) { +if (!cxl_aer_einj.is_rch) +pci_dev_put (to_pci_dev (cxl_aer_einj.dev)); + cxl_aer_einj.dev =NULL ; + } +#endif }drivers/cxl/core/ras_rch.c +0
-0drivers/cxl/core/ras_rch.c void cxl_handle_rdport_errors(struct pci_dev *pdev) · line 118
Quoted 9 lines
drivers/cxl/core/ras_rch.c +6
-0@@ -110,6 +110,14 @@ void cxl_handle_rdport_errors(struct pci_dev *pdev)if (!dport)return ; +#if IS_ENABLED (CONFIG_CXL_PROTO_AER_EINJ ) +if (cxl_aer_einj.is_rch && cxl_aer_einj.dev) { + severity = cxl_aer_einj.correctable ? +AER_CORRECTABLE :AER_FATAL ; + goto handle_ras; + }Use instead
if (IS_ENABLED(CONFIG_CXL_PROTO_AR_EINJ))
Quoted 6 lines
then compiler can see the code (but remove it) which means you don't need the dance around the label below.
In general follow this pattern anyway rather than #if when you can.
Got it.
Quoted 61 lines
Quoted 61 lines
drivers/cxl/core/ras_rch.c +6
-0+#endif +if (!cxl_rch_get_aer_info (dport->regs.dport_aer, &aer_regs))return ;@@ -117,6 +125,10 @@ void cxl_handle_rdport_errors(struct pci_dev *pdev)return ;pci_print_aer (pdev, severity, &aer_regs); + +#if IS_ENABLED (CONFIG_CXL_PROTO_AER_EINJ ) +handle_ras: +#endif if (severity ==AER_CORRECTABLE )cxl_handle_cor_ras (dport->port, dport,to_ras_base (port, dport), pdev->dsn);drivers/pci/pcie/aer_inject.c +2
-14@@ -14,6 +14,7 @@#define dev_fmt (fmt) "aer_inject: " fmt +#include <linux/aer.h> #include <linux/module.h> #include <linux/init.h> #include <linux/interrupt.h> @@ -31,19 +32,6 @@static bool aer_mask_override;module_param (aer_mask_override, bool,0 ); -struct aer_error_inj { -u8 bus; -u8 dev; -u8 fn; -u32 uncor_status; -u32 cor_status; -u32 header_log0; -u32 header_log1; -u32 header_log2; -u32 header_log3; -u32 domain; -}; -struct aer_error {struct list_head list;u32 domain;@@ -316,7 +304,7 @@ static int pci_bus_set_aer_ops(struct pci_bus *bus)return 0 ; } -static int aer_inject (struct aer_error_inj *einj) +int aer_inject (struct aer_error_inj *einj) {struct aer_error *err, *rperr;struct aer_error *err_alloc =NULL , *rperr_alloc =NULL ;@@ -332,10 +320,14 @@ static int aer_inject(struct aer_error_inj *einj) dev =pci_get_domain_bus_and_slot (einj->domain, einj->bus, devfn);if (!dev)return -ENODEV ;
Quoted 9 lines
drivers/pci/pcie/aer_inject.c static int aer_inject(struct aer_error_inj *einj) · line 323
Quoted 5 lines
drivers/pci/pcie/aer_inject.c +1
-4- rpdev =pcie_find_root_port (dev); -/* If Root Port not found, try to find an RCEC */ -if (!rpdev) - rpdev = dev->rcec; +if (pci_pcie_type (dev) ==PCI_EXP_TYPE_RC_EC ){ }
as the else is multiline (see coding standard)
Ok
Quoted 20 lines
Maybe need a comment for why it might be an RCEC for injection. Is this an RCH specific path where there is nothing else to target?
Quoted 11 lines
drivers/pci/pcie/aer_inject.c +7
-0+ rpdev = dev; + else { + rpdev =pcie_find_root_port (dev); +/* If Root Port not found, try to find an RCEC */ +if (!rpdev) + rpdev = dev->rcec; + }if (!rpdev) {pci_err (dev,"Neither Root Port nor RCEC found\n" ); ret = -ENODEV ;drivers/pci/pcie/aer_inject.c static int aer_inject(struct aer_error_inj *einj) · line 477
Quoted 4 lines
drivers/pci/pcie/aer_inject.c +1
-0@@ -482,6 +474,7 @@ static int aer_inject(struct aer_error_inj *einj)pci_dev_put (dev);return ret; } +EXPORT_SYMBOL_GPL (aer_inject);I wonder if we want to restrict this to specific modules?
Quoted 2 lines
One for Bjorn probably.
Because right now it injects AER to any PCI device.
Also, worth discussing is the commandline currently uses multiple parameters for a single sysfs file. I mentioned this at the top.
Thanks for reviewing Jonathan.
-Terry
Quoted 30 lines
Quoted 29 lines
drivers/pci/pcie/aer_inject.c +0
-0static ssize_t aer_inject_write (struct file *filp,const char __user *ubuf,size_t usize,loff_t *off)include/linux/aer.h +15
-0@@ -27,6 +27,21 @@struct pci_dev ;struct work_struct ; +struct aer_error_inj { +u8 bus; +u8 dev; +u8 fn; +u32 uncor_status; +u32 cor_status; +u32 header_log0; +u32 header_log1; +u32 header_log2; +u32 header_log3; +u32 domain; +}; + +int aer_inject (struct aer_error_inj *einj); +struct pcie_tlp_log {union {u32 dw[PCIE_STD_MAX_TLP_HEADERLOG ];
Jonathan Cameron
maintainerQuoted 21 lines
Quoted 9 lines
Why is this an RFC rather than a final proposal? There should always be something to give the reviewer that info in the patch description. I'd actually be tempted to throw a cover letter in to have somewhere out of the way to put that information.
Is it simply because it only makes sense once the other seris lands.
The immediate priority was providing a testing procedure for the v18 series. I wasn't sure how the design would be received. For instance, the
to_einj_ras_base()could be moved into cxl-test as ato_ras_base()mock implemented function or it could remain inras.c(or maybe evenras_einj.c) outside of cxl-mock. I'm looking forward to Alison's review and comments.My preference is to introduce core/ras_einj,c and add these changes. This would be to isolate all the changes except for:
cxl_ras_einj_init(),cxl_ras_einj_exit(), andto_einj_ras_base(). I've started moving forward with making these changes knowing the direction could change once this receives more reviews.
Quoted 4 lines
Also worth discussing is the commandline takes multiple parameters for a single sysfs file which I know isn't acceptable by everyone. I personally like the interface as-is because its simpler to use in comparison to multiple files that must be set individually.
It is debugfs so rules are much more flexible than sysfs.
Quoted 28 lines
Quoted 18 lines
Quoted 18 lines
--- drivers/cxl/Kconfig | 13 +++ drivers/cxl/core/core.h | 21 ++++ drivers/cxl/core/port.c | 2 +- drivers/cxl/core/ras.c | 208 ++++++++++++++++++++++++++++++++++ drivers/cxl/core/ras_rch.c | 12 ++ drivers/pci/pcie/aer_inject.c | 29 ++--- include/linux/aer.h | 15 +++ 7 files changed, 281 insertions(+), 19 deletions(-)drivers/cxl/Kconfig +0
-0@@ -238,6 +238,19 @@ config CXL_RAS def_bool y depends on ACPI_APEI_GHES && PCIEAER && CXL_BUSQuoted 9 lines
drivers/cxl/Kconfig config CXL_RAS · line 244
Quoted 4 lines
drivers/cxl/Kconfig +4
-0+config CXL_PROTO_AER_EINJ + bool "CXL: RAS Protocol Error Injection using AER EINJ" + depends on CXL_RAS + depends on PCIEAER_INJECTDo we think anyone who has CXL and
PCIEAER_INJECTsupport will want to carefully not build this? I'm just wondering if we can avoid asking the question and base the built or not on the combination of those.
Quoted 9 lines
Good question: How do we incorporate this with the existing CXL EINJ functionality making them complementary and consistant? The existing EINJ is true ACPI injection but only supports RPs. The ACPI EINJ callouts are currrently in
core/port.c. We should consider moving it into a common file such ascore/ras_einj.c. With that move it will help force us merge the interfaces where/if possible and at least give central location for error RAS injection. I think folding the AER injection intoPCIEAER_INJECTkernel config is reasonable but looking for others feedback.
I hadn't really thought about the injection method. Indeed raises interesting questions of how it should be done. Add an ABI doc in Documentation/ABI for next version.
Quoted 41 lines
Quoted 32 lines
drivers/cxl/Kconfig config CXL_RAS · line 245
Quoted 2 lines
drivers/cxl/Kconfig +1
-0+static DEFINE_MUTEX(cxl_aer_einj_mutex);Needs a comment for what data it is protecting.
Quoted 27 lines
drivers/cxl/Kconfig +27
-0+ +struct cxl_aer_einj cxl_aer_einj = { + .lock = &cxl_aer_einj_mutex, +}; + +static const char cxl_aer_einj_usage[] = + "ssss:bb:dd.f [UCE|CE] AER_STATUS RAS_STATUS [RCH]\n"; + +static int cxl_aer_inject_error(struct pci_dev *pdev, bool correctable, + u32 aer_status, u32 ras_status) +{ + /* RCD errors are signaled as internal errors on the associated RCEC */ + if (pci_pcie_type(pdev) == PCI_EXP_TYPE_RC_END) { + if (!pdev->rcec) + return -ENODEV; + pdev = pdev->rcec; + } + + struct aer_error_inj einj = { + .bus = pdev->bus->number, + .dev = PCI_SLOT(pdev->devfn), + .fn = PCI_FUNC(pdev->devfn), + .domain = pci_domain_nr(pdev->bus), + }; + int ret; + int aer_offset; + int ras_offset;Quoted 9 lines
drivers/cxl/Kconfig
Quoted 5 lines
drivers/cxl/Kconfig +5
-0+ + if (correctable) { + einj.cor_status = aer_status | PCI_ERR_COR_INTERNAL; + aer_offset = PCI_ERR_COR_STATUS / sizeof(u32); + ras_offset = CXL_RAS_CORRECTABLE_STATUS_OFFSET / sizeof(u32);Given these are offsets into cxl_aer_einj.aer_registers /
ras_registerscan we usesizeof(*cxl_aer_einj.aer_registers)etc
Quoted 2 lines
We could but that assumes the CEs are book ending the register blocks. And this would be inconsistent with UCE case below, right? Tell me if I misunderstaood the question.
I just meant to replace those sizeof(u32) with something that indicates where the size is coming from. Applies equally below.
Quoted 28 lines
Quoted 12 lines
drivers/cxl/Kconfig
Quoted 9 lines
drivers/cxl/Kconfig +8
-0+ +static void __iomem *to_einj_ras_base(struct cxl_port *port, struct cxl_dport *dport) +{ + if (dport) { + if (cxl_aer_einj.is_rch) { + if (cxl_aer_einj.dev == dport->dport_dev) { + cxl_aer_einj.dev = NULL; + return (__force void __iomem *)cxl_aer_einj.ras_registers;Given the output of this is always force cast, maybe move that force up to the caller?
I think that works if it remains an internal helper and isn't made a mock function to
to_ras_base(). Ifto_einj_ras_base()is used as a mock than it would require changing theto_ras_base()as well.Quoted 10 lines
drivers/cxl/Kconfig
Quoted 4 lines
drivers/cxl/Kconfig +4
-0+ } + } else { + if (cxl_aer_einj.dev == dport->dport_dev) { + pci_dev_put(to_pci_dev(cxl_aer_einj.dev));Not locally obvious why a thing called
to_einj_ras_baseshould put anything it didn't get. I think this needs a restructure to more obviously be tidying up references that were held over the queue. At very leads needs a comment.
/* Reference held from X no longer needed so drop */
Quoted 2 lines
The ref was incremented in
cxl_aer_einj_write()on invoking injection. The ref is decremented here after its usage. RCHs are excluded because they dont have a SBDF.
Just add minimal reference for that.
Quoted 24 lines
Quoted 15 lines
Quoted 15 lines
drivers/cxl/Kconfig +10
-0+ cxl_aer_einj.dev = NULL; + return (__force void __iomem *)cxl_aer_einj.ras_registers; + } + if (cxl_aer_einj.dev) { + void __iomem *einj = to_einj_ras_base(port, dport); + if (einj) + return einj; + } +#endif + if (dport) return dport->regs.ras;Quoted 8 lines
drivers/cxl/Kconfig void cxl_ras_init(void) · line 660
Quoted 6 lines
drivers/cxl/Kconfig +2
-0@@ -458,10 +656,20 @@ void cxl_ras_init(void) cxl_cper_register_prot_err_work(&cxl_cper_prot_err_work); cxl_register_proto_err_work(&cxl_proto_err_work, cxl_proto_err_do_flush); +#if IS_ENABLED(CONFIG_CXL_PROTO_AER_EINJ) + cxl_ras_create_debugfs(cxl_debugfs);stub that in a header.
Quoted 2 lines
Actually, during rework today I moved it to
cxl_ras_einj_init(), a new function. Thoughts?
Sounds good.
Quoted 90 lines
Quoted 45 lines
Quoted 45 lines
drivers/pci/pcie/aer_inject.c +2
-14@@ -14,6 +14,7 @@#define dev_fmt (fmt) "aer_inject: " fmt +#include <linux/aer.h> #include <linux/module.h> #include <linux/init.h> #include <linux/interrupt.h> @@ -31,19 +32,6 @@static bool aer_mask_override;module_param (aer_mask_override, bool,0 ); -struct aer_error_inj { -u8 bus; -u8 dev; -u8 fn; -u32 uncor_status; -u32 cor_status; -u32 header_log0; -u32 header_log1; -u32 header_log2; -u32 header_log3; -u32 domain; -}; -struct aer_error {struct list_head list;u32 domain;@@ -316,7 +304,7 @@ static int pci_bus_set_aer_ops(struct pci_bus *bus)return 0 ; } -static int aer_inject (struct aer_error_inj *einj) +int aer_inject (struct aer_error_inj *einj) {struct aer_error *err, *rperr;struct aer_error *err_alloc =NULL , *rperr_alloc =NULL ;@@ -332,10 +320,14 @@ static int aer_inject(struct aer_error_inj *einj) dev =pci_get_domain_bus_and_slot (einj->domain, einj->bus, devfn);if (!dev)return -ENODEV ;Quoted 9 lines
drivers/pci/pcie/aer_inject.c static int aer_inject(struct aer_error_inj *einj) · line 323
Quoted 5 lines
drivers/pci/pcie/aer_inject.c +1
-4- rpdev =pcie_find_root_port (dev); -/* If Root Port not found, try to find an RCEC */ -if (!rpdev) - rpdev = dev->rcec; +if (pci_pcie_type (dev) ==PCI_EXP_TYPE_RC_EC ){ }
as the else is multiline (see coding standard)Ok
Quoted 20 lines
Maybe need a comment for why it might be an RCEC for injection. Is this an RCH specific path where there is nothing else to target?
Quoted 11 lines
drivers/pci/pcie/aer_inject.c +7
-0+ rpdev = dev; + else { + rpdev =pcie_find_root_port (dev); +/* If Root Port not found, try to find an RCEC */ +if (!rpdev) + rpdev = dev->rcec; + }if (!rpdev) {pci_err (dev,"Neither Root Port nor RCEC found\n" ); ret = -ENODEV ;drivers/pci/pcie/aer_inject.c static int aer_inject(struct aer_error_inj *einj) · line 477
Quoted 4 lines
drivers/pci/pcie/aer_inject.c +1
-0@@ -482,6 +474,7 @@ static int aer_inject(struct aer_error_inj *einj)pci_dev_put (dev);return ret; } +EXPORT_SYMBOL_GPL (aer_inject);I wonder if we want to restrict this to specific modules?
Quoted 2 lines
One for Bjorn probably.
Because right now it injects AER to any PCI device.
Also, worth discussing is the commandline currently uses multiple parameters for a single sysfs file. I mentioned this at the top.
Thanks for reviewing Jonathan.
-Terry
Hi Terry,
Quoted 3 lines · Terry Bowman
This patch is intended to provide a method of testing the recently submitted cxl series "cxl: Enable CXL PCIe Port Protocol Error handling and logging"
Ran this on 7.2-rc3 with v18, under QEMU with a switch topology so all four port classes are present. v19 wasn't out yet when I ran it; the findings below are in the RFC's own code and don't move with the delta. It works -- one CE per class with a different RAS status bit each time, attribution correct in all four:
RP ras=0x1 port=port1 dport=0000:0c:00.0 'Cache Data ECC Error' USP ras=0x2 port=port2 dport= 'Memory Data ECC Error' DSP ras=0x4 port=port2 dport=0000:0e:00.0 'CRC Threshold Hit' EP ras=0x8 memdev=mem1 port=endpoint4 'Retry Threshold'
A UCE panics via cxl_pci_error_detected() as the series intends, and six malformed inputs are rejected. Only VH here, so I can't say anything about whether the RCH branch is right.
drivers/cxl/Kconfig config CXL_RAS · line 244
Quoted 1 line
drivers/cxl/Kconfig +1
-0+ depends on PCIEAER_INJECT
Beyond Jonathan's question about asking at all -- a bool depending on a tristate means kconfig will give you PCIEAER_INJECT=m with CXL_BUS=y and this =y. olddefconfig produces that from a defconfig and it doesn't link:
ld: ras.c: undefined reference to `aer_inject'
Deriving it from the combination rather than asking would take the broken config with the question.
drivers/cxl/core/ras.c static void cxl_cper_prot_err_work_fn(struct work_struct *work) · line 163
Quoted 1 line
drivers/cxl/core/ras.c +1
-0+ cxl_aer_einj.aer_registers[aer_offset] = aer_status;
Only reference to aer_registers[] in the tree. aer_inject() builds its own AER config space and the RCH path skips cxl_rch_get_aer_info(), so nothing reads it. Is it still needed, or can it go with the core/ras_einj.c move?
Review
Quoted 1 line
(quoted diff) +1
-0+ cxl_aer_einj.dev = NULL;
Clears the pointer but not the reference. Every non-RCH arm takes a pci_dev_get() below; to_einj_ras_base() on a match and cxl_ras_exit() drop it. Both need .dev to still point there. So an arm not consumed before the next write is orphaned.
Thirty back-to-back injections gave 26 trace events, with aer_inject run 30 times and the kfifo-add-failed, port-not-found, port-unbound, dport-not-found and RAS-not-mapped counts all zero (kfifo is 128 deep, so no overflow). Four arms were never disarmed. I can't tell whether the AER core folded them into one pass or the next write replaced .dev first, and either way the reference goes. I couldn't make it fire on demand -- unbinding cxl_port fails the arm-time lookup instead -- so it's a race, but it's the one a test loop hits.
Behind it the handshake has no single owner: the mutex is writer-only, while to_einj_ras_base() mutates the same fields and drops a reference without it. Both consumers are live: the CE runs consume arms from the kfifo work, and the UCE backtrace has cxl_pci_error_detected() doing it from the AER IRQ thread. A disarm helper
owning the reference would cover this and the asymmetry Jonathan raised about putting a reference it didn't get.
drivers/cxl/core/ras.c static void cxl_cper_prot_err_work_fn(struct work_struct *work) · line 242
Quoted 1 line
drivers/cxl/core/ras.c +1
-0+ cxl_aer_einj.is_rch = (nargs ==5 &&strcmp (topology,"RCH" ) ==0 );
RCH on a VH device is accepted:
# echo "0000:0c:00.0 CE 0 0x80 RCH" > .../aer_einj_inject -> 0
aer_inject() fires and AER logs it, but no CXL trace event appears -- the RCH branch can't match a VH dport. Reproduces every time. So a typo gets you a real AER error with the CXL path silently skipped, which reads as "the handler didn't fire". is_cxl_restricted(pdev), already used further down the file, would make it -EINVAL.
Quoted 2 lines
Also worth discussing is the commandline takes multiple parameters for a single sysfs file
One file also suits the state handling above better. Several files spread one request over several writes with no commit point.
Quoted 1 line
How do we incorporate this with the existing CXL EINJ functionality
core/ras_einj.c sounds right, and the Kconfig above is another reason for both in one place. Worth a line in the ABI doc that ACPI EINJ is a real injection but Root Port only while this covers every class with software registers -- that's what decides which one a test wants.
Last thing, off this patch: with the registers a kernel-side array this can't exercise the MMIO readback, the offsets against a real capability block, or the header log. QEMU has RAS on root and switch ports but injects only on endpoints, so it can't cover the classes today either. I'm looking at adding port-level injection there as a second path through the real reads.
Many thanks,
Junjie