* [ndctl PATCH] cxl/list: handle missing debugfs when reporting protocol injection
@ 2026-10-23 1:13 Alison Schofield
2026-10-23 13:37 ` Cheatham, Benjamin
2026-10-23 22:12 ` Alison Schofield
0 siblings, 2 replies; 3+ messages in thread
From: Alison Schofield @ 2026-10-23 1:13 UTC (permalink / raw)
To: nvdimm, Ben Cheatham; +Cc: Alison Schofield, linux-cxl
When debugfs is not mounted or CONFIG_DEBUG_FS is disabled, 'cxl list -v'
crashes while generating the protocol_injectable attribute for downstream
ports.
The crash occurs because cxl_dport_get_einj_path() passes a NULL debugfs
path to strlen().
Return NULL from cxl_dport_get_einj_path() when debugfs is unavailable,
and omit protocol_injectable from the JSON output, consistent with other
debugfs-dependent attributes. Update the documentation to match.
Thanks to Christopher Kim who reported and provided the fixup.
Originally-by: Christopher Kim
Fixes: 5d596866f8c5 ("cxl/list: add injectable errors in output")
Closes: https://github.com/pmem/ndctl/issues/300
Signed-off-by: Alison Schofield <alison.schofield@intel.com>
---
Documentation/cxl/cxl-inject-protocol-error.txt | 5 ++---
cxl/json.c | 15 +++++++++------
cxl/lib/libcxl.c | 3 +++
3 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/Documentation/cxl/cxl-inject-protocol-error.txt b/Documentation/cxl/cxl-inject-protocol-error.txt
index 196b6f6af7e3..179066ff7111 100644
--- a/Documentation/cxl/cxl-inject-protocol-error.txt
+++ b/Documentation/cxl/cxl-inject-protocol-error.txt
@@ -81,9 +81,8 @@ must be enabled. For more information, view the Linux kernel documentation on EI
This command depends on the CXL debug filesystem (normally mounted at
"/sys/kernel/debug/cxl") to inject protocol errors. If the CXL debugfs is not
-accessible the "protocol_injectable" attribute of dports will always be
-set to false, and the "injectable_protocol_errors" attribute of CXL busses
-will always be empty.
+accessible, the "protocol_injectable" attribute of dports and the
+"injectable_protocol_errors" attribute of CXL buses are omitted.
OPTIONS
-------
diff --git a/cxl/json.c b/cxl/json.c
index a92548828582..0caa3a87b61d 100644
--- a/cxl/json.c
+++ b/cxl/json.c
@@ -746,12 +746,15 @@ void util_cxl_dports_append_json(struct json_object *jport,
if (jobj)
json_object_object_add(jdport, "id", jobj);
- einj_path = cxl_dport_get_einj_path(dport);
- jobj = json_object_new_boolean(einj_path != NULL);
- if (jobj)
- json_object_object_add(jdport, "protocol_injectable",
- jobj);
- free(einj_path);
+ if (cxl_debugfs_exists(cxl_port_get_ctx(port))) {
+ einj_path = cxl_dport_get_einj_path(dport);
+ jobj = json_object_new_boolean(einj_path != NULL);
+ if (jobj)
+ json_object_object_add(jdport,
+ "protocol_injectable",
+ jobj);
+ free(einj_path);
+ }
json_object_array_add(jdports, jdport);
json_object_set_userdata(jdport, dport, NULL);
diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
index e55a7b41d77a..16348783e3de 100644
--- a/cxl/lib/libcxl.c
+++ b/cxl/lib/libcxl.c
@@ -3589,6 +3589,9 @@ CXL_EXPORT char *cxl_dport_get_einj_path(struct cxl_dport *dport)
char *path;
int rc;
+ if (!ctx->cxl_debugfs)
+ return NULL;
+
path_len = strlen(ctx->cxl_debugfs) + 100;
path = calloc(path_len, sizeof(char));
if (!path)
--
2.37.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [ndctl PATCH] cxl/list: handle missing debugfs when reporting protocol injection
2026-10-23 1:13 [ndctl PATCH] cxl/list: handle missing debugfs when reporting protocol injection Alison Schofield
@ 2026-10-23 13:37 ` Cheatham, Benjamin
2026-10-23 22:12 ` Alison Schofield
1 sibling, 0 replies; 3+ messages in thread
From: Cheatham, Benjamin @ 2026-10-23 13:37 UTC (permalink / raw)
To: Alison Schofield, nvdimm; +Cc: linux-cxl
On 10/22/2026 8:13 PM, Alison Schofield wrote:
> When debugfs is not mounted or CONFIG_DEBUG_FS is disabled, 'cxl list -v'
> crashes while generating the protocol_injectable attribute for downstream
> ports.
>
> The crash occurs because cxl_dport_get_einj_path() passes a NULL debugfs
> path to strlen().
>
> Return NULL from cxl_dport_get_einj_path() when debugfs is unavailable,
> and omit protocol_injectable from the JSON output, consistent with other
> debugfs-dependent attributes. Update the documentation to match.
>
> Thanks to Christopher Kim who reported and provided the fixup.
>
> Originally-by: Christopher Kim
> Fixes: 5d596866f8c5 ("cxl/list: add injectable errors in output")
> Closes: https://github.com/pmem/ndctl/issues/300
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>
LGTM,
Reviewed-by: Ben Cheatham <benjamin.cheatham@amd.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [ndctl PATCH] cxl/list: handle missing debugfs when reporting protocol injection
2026-10-23 1:13 [ndctl PATCH] cxl/list: handle missing debugfs when reporting protocol injection Alison Schofield
2026-10-23 13:37 ` Cheatham, Benjamin
@ 2026-10-23 22:12 ` Alison Schofield
1 sibling, 0 replies; 3+ messages in thread
From: Alison Schofield @ 2026-10-23 22:12 UTC (permalink / raw)
To: nvdimm, Ben Cheatham; +Cc: linux-cxl
On Thu, Oct 22, 2026 at 06:13:32PM -0700, Alison Schofield wrote:
> When debugfs is not mounted or CONFIG_DEBUG_FS is disabled, 'cxl list -v'
> crashes while generating the protocol_injectable attribute for downstream
> ports.
>
> The crash occurs because cxl_dport_get_einj_path() passes a NULL debugfs
> path to strlen().
>
> Return NULL from cxl_dport_get_einj_path() when debugfs is unavailable,
> and omit protocol_injectable from the JSON output, consistent with other
> debugfs-dependent attributes. Update the documentation to match.
>
> Thanks to Christopher Kim who reported and provided the fixup.
>
> Originally-by: Christopher Kim
> Fixes: 5d596866f8c5 ("cxl/list: add injectable errors in output")
> Closes: https://github.com/pmem/ndctl/issues/300
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>
Applied to pending for NDCTL v86
https://github.com/pmem/ndctl/commit/1b126bf930c5
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-23 22:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-23 1:13 [ndctl PATCH] cxl/list: handle missing debugfs when reporting protocol injection Alison Schofield
2026-10-23 13:37 ` Cheatham, Benjamin
2026-10-23 22:12 ` Alison Schofield
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox