Skip to contentSkip to conversation

cxl/list: handle missing debugfs when reporting protocol injection

PATCH Applied Alison Schofield 2 participants 3 messages Oct 23

Subsystems (2)
lore
Share & tools
lore

Alison Schofield

author maintainer
#0 lore raw

PATCH 1/1 cxl/list: handle missing debugfs when reporting protocol injection

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")
---
 Documentation/cxl/cxl-inject-protocol-error.txt |  5 ++---
 cxl/json.c                                      | 15 +++++++++------
 cxl/lib/libcxl.c                                |  3 +++
 3 files changed, 14 insertions(+), 9 deletions(-)
Documentation/cxl/cxl-inject-protocol-error.txt +2 -3
index 196b6f6af7e3..179066ff7111 100644
@@ -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
 -------
cxl/json.c +9 -6
index a92548828582..0caa3a87b61d 100644
@@ -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);
cxl/lib/libcxl.c +3 -0
index e55a7b41d77a..16348783e3de 100644
@@ -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)
Signature · 1 line
2.37.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Alison Schofield

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.

Quoted 6 lines

Thanks to Christopher Kim who reported and provided the fixup.

Originally-by Christopher Kim
Fixes 5d596866f8c5 ("cxl/list: add injectable errors in output")

LGTM,

author maintainer Applied
#2 lore raw
In reply to Alison Schofield
Quoted 11 lines · Alison Schofield

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.

Quoted 6 lines

Thanks to Christopher Kim who reported and provided the fixup.

Originally-by Christopher Kim
Fixes 5d596866f8c5 ("cxl/list: add injectable errors in output")

Applied to pending for NDCTL v86
https://github.com/pmem/ndctl/commit/1b126bf930c5