[PATCH v7] cxl/core: Create EINJ debugfs files regardless of EINJ init order
From: Yongxin Yang
Date: Wed Nov 04 2026 - 01:18:11 EST
The einj_types file under the CXL debugfs directory is never created when
cxl_core is built in. cxl_core_init() runs at subsys_initcall level, while
einj_init() registers EINJ at device_initcall level, so the
einj_cxl_is_initialized() check in cxl_core_init() always sees EINJ as not
up yet and the debugfs_create_file() below it is never reached.
Change the file creation condition from EINJ being initialized to a compile
time check for ACPI_APEI_EINJ_CXL and return -ENODEV until EINJ is up.
The same check also guards the inject files under every downstream port
directory. Gate that directory creation on CONFIG_ACPI_APEI_EINJ_CXL as
well, and check einj_cxl_is_initialized() in cxl_einj_inject() to reject
writes until EINJ is up.
Fixes: 8039804cfa73 ("cxl/core: Add CXL EINJ debugfs files")
Reviewed-by: Ben Cheatham <benjamin.cheatham@xxxxxxx>
Signed-off-by: Yongxin Yang <yangyongxin@xxxxxxxxxx>
---
Link: https://lore.kernel.org/all/de14c4ef-e3d8-432f-9ce8-87c468d6d2ad@xxxxxxx/
Link: https://lore.kernel.org/all/7a22cc6a-deba-40e6-8033-97d1234420ba@xxxxxxx/
Link: https://lore.kernel.org/all/63e782a6-e33a-46ce-a455-5d207a60661f@xxxxxxx/
Link: https://lore.kernel.org/all/1a5ceda1-f039-4946-b8d7-2bc97ed48c00@xxxxxxx/
Changes in v7:
- Drop the RCH mention from the third paragraph, as suggested by Ben.
drivers/acpi/apei/einj-cxl.c | 3 +++
drivers/cxl/core/port.c | 7 +++++--
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/acpi/apei/einj-cxl.c b/drivers/acpi/apei/einj-cxl.c
index e70a416ec925..22a7eb4dc75e 100644
--- a/drivers/acpi/apei/einj-cxl.c
+++ b/drivers/acpi/apei/einj-cxl.c
@@ -30,6 +30,9 @@ int einj_cxl_available_error_type_show(struct seq_file *m, void *v)
int cxl_err, rc;
u32 available_error_type = 0;
+ if (!einj_cxl_is_initialized())
+ return -ENODEV;
+
rc = einj_get_available_error_type(&available_error_type, ACPI_EINJ_GET_ERROR_TYPE);
if (rc)
return rc;
diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c
index 625e4aa427db..a949228de936 100644
--- a/drivers/cxl/core/port.c
+++ b/drivers/cxl/core/port.c
@@ -806,6 +806,9 @@ static int cxl_einj_inject(void *data, u64 type)
{
struct cxl_dport *dport = data;
+ if (!einj_cxl_is_initialized())
+ return -ENODEV;
+
if (dport->rch)
return einj_cxl_inject_rch_error(dport->rcrb.base, type);
@@ -819,7 +822,7 @@ static void cxl_debugfs_create_dport_dir(struct cxl_dport *dport)
struct cxl_port *parent = parent_port_of(dport->port);
struct dentry *dir;
- if (!einj_cxl_is_initialized())
+ if (!IS_ENABLED(CONFIG_ACPI_APEI_EINJ_CXL))
return;
/*
@@ -2515,7 +2518,7 @@ static __init int cxl_core_init(void)
cxl_debugfs = debugfs_create_dir("cxl", NULL);
- if (einj_cxl_is_initialized())
+ if (IS_ENABLED(CONFIG_ACPI_APEI_EINJ_CXL))
debugfs_create_file("einj_types", 0400, cxl_debugfs, NULL,
&einj_cxl_available_error_type_fops);
--
2.25.1