mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v5] cxl/core: Create einj_types regardless of EINJ init order
@ 2026-11-02  3:24 Yongxin Yang
  2026-11-02 21:32 ` Cheatham, Benjamin
  2026-11-03  5:36 ` [PATCH v6] cxl/core: Create EINJ debugfs files " Yongxin Yang
  0 siblings, 2 replies; 3+ messages in thread
From: Yongxin Yang @ 2026-11-02  3:24 UTC (permalink / raw)
  To: Davidlohr Bueso, Jonathan Cameron, Dave Jiang, Alison Schofield,
	Vishal Verma, Ira Weiny, Dan Williams, Rafael J . Wysocki
  Cc: Tony Luck, Borislav Petkov, Hanjun Guo, Mauro Carvalho Chehab,
	Shuai Xue, Len Brown, Li Ming, Ben Cheatham, linux-cxl,
	linux-acpi, linux-kernel, Yongxin Yang, stable

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.  With
cxl_core as a module, module dependencies make sure it is loaded after EINJ
is up and the file is created.

Create the file unconditionally instead, gated only on the CXL error
injection support being compiled in, and have
einj_cxl_available_error_type_show() return -ENODEV until EINJ is up.  This
single check in cxl_core_init() covers every combination of built-in and
modular cxl_core, cxl_acpi and EINJ, with no extra hooks.

The check in the show callback is required, not cosmetic: einj_tab is
NULL until einj_init() runs, so einj_get_available_error_type() would
dereference a NULL pointer.

This restores the discovery of the supported error types only.  On a fully
built-in RCH/RCD hierarchy the inject files below the dport directory are
still not created: cxl_debugfs_create_dport_dir() has the same early return
and the only dport there comes from cxl_acpi_probe() at
subsys_initcall_sync level, before EINJ is up.

Fixes: 8039804cfa73 ("cxl/core: Add CXL EINJ debugfs files")
Cc: <stable@vger.kernel.org>
Suggested-by: Dave Jiang <dave.jiang@intel.com>
Suggested-by: Ben Cheatham <benjamin.cheatham@amd.com>
Link: https://lore.kernel.org/all/de14c4ef-e3d8-432f-9ce8-87c468d6d2ad@amd.com/
Link: https://lore.kernel.org/all/7a22cc6a-deba-40e6-8033-97d1234420ba@amd.com/
Signed-off-by: Yongxin Yang <yangyongxin@kylinos.cn>
---
Changes in v5:
- Rework per Dave's suggestion, agreed by Ben: create einj_types from
  cxl_core_init() without looking at the runtime EINJ state, and return
  -ENODEV from einj_cxl_available_error_type_show() while EINJ is not
  initialized, instead of creating the file from three separate hooks.
  This drops the mutex, the exported helper and the cached dentry.
- Drop the cxl_acpi_probe() hook: host bridge dports, RCH included, already
  go through __devm_cxl_add_dport() -> cxl_debugfs_create_dport_dir() in the
  same probe, so the hook added nothing.
- Gate the creation on CONFIG_ACPI_APEI_EINJ_CXL rather than on the runtime
  EINJ state.
- Dropped the Reviewed-by tag as the approach changed significantly.

 drivers/acpi/apei/einj-cxl.c | 4 ++++
 drivers/cxl/core/port.c      | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/apei/einj-cxl.c b/drivers/acpi/apei/einj-cxl.c
index e70a416ec925..3090c7649ed2 100644
--- a/drivers/acpi/apei/einj-cxl.c
+++ b/drivers/acpi/apei/einj-cxl.c
@@ -30,6 +30,10 @@ int einj_cxl_available_error_type_show(struct seq_file *m, void *v)
 	int cxl_err, rc;
 	u32 available_error_type = 0;
 
+	/* einj_tab stays NULL until EINJ is initialized, don't read it. */
+	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..d4ed1cc7c480 100644
--- a/drivers/cxl/core/port.c
+++ b/drivers/cxl/core/port.c
@@ -2515,7 +2515,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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-03  5:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-02  3:24 [PATCH v5] cxl/core: Create einj_types regardless of EINJ init order Yongxin Yang
2026-11-02 21:32 ` Cheatham, Benjamin
2026-11-03  5:36 ` [PATCH v6] cxl/core: Create EINJ debugfs files " Yongxin Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®