Re: [PATCH v7] cxl/core: Create EINJ debugfs files regardless of EINJ init order

From: Yongxin Yang

Date: Tue Nov 17 2026 - 20:24:40 EST


Hi Alison, Dave,

Thanks for catching this. You are right, and v7 trades one wrong state
for another: on a host without an EINJ table the files would be created
and every access would fail with -ENODEV, which is exactly what
4ed7952b9e87 set out to avoid. Since ndctl uses the presence of those
files as the signal, the compile time check is not a fix.

Let me describe what I think the real fix has to look like and check the
direction with you before I post v8.

The root cause is ordering. cxl_core_init() is a subsys_initcall and
einj_init() is a device_initcall (module_init), so with cxl_core built
in, the EINJ state is simply not known yet at the point where the files
are created. Whatever condition is evaluated there is a guess: the
runtime check always answers "not up" (the original bug), and the
compile time check always answers "up" (the regression you found). So
the creation has to move to where the answer exists, not the condition
be rewritten.

Planned for v8:

1. Revert both IS_ENABLED() uses. The files are again created only
when einj_cxl_is_initialized() is true at creation time, so nothing
appears on a host where EINJ never comes up.

2. Move the EINJ debugfs setup out of cxl_core_init() into a callback
that runs once EINJ is actually up: cxl core registers it from
cxl_core_init(), and einj invokes it right after einj_initialized is
set. The callback is idempotent, and cxl_core_init() still creates
the files directly when EINJ is already up, which covers the module
load order (einj.ko is a dependency of cxl_core.ko, so it is always
initialised first).

I did not use a late_initcall() for this because port.c already has
subsys_initcall(cxl_core_init), and for modules every initcall macro
expands to module_init(), so a second one in the same file does not
build. A separate file would not help either, since it would need
access to cxl_debugfs and to the port list.

3. The dport directories have the same window. With the runtime check
restored they are created as before for ports registered after EINJ
comes up, and the callback above walks the ports that were already
registered and creates the directories that were skipped.

4. On your second point, I will put the check in all three helpers so
einj_cxl_inject_error() and einj_cxl_inject_rch_error() no longer
depend on their caller. One small detail: the !CONFIG stubs return
-ENXIO while this series used -ENODEV. Do you want the helpers to
follow the stubs, or the stubs to follow the helpers?

I also see that the patch was dropped from cxl/fixes, and I take the
point about threading: v8 will be posted as a thread of its own, not as
a reply to v7.

This is only a design check, no code yet. Does that direction look
right? If so I will send v8 along those lines.

Thanks!
Yongxin