Linux CXL
 help / color / mirror / Atom feed
From: Dave Jiang <dave.jiang@intel.com>
To: Ben Cheatham <Benjamin.Cheatham@amd.com>,
	nvdimm@lists.linux.dev, alison.schofield@intel.com
Cc: linux-cxl@vger.kernel.org
Subject: Re: [PATCH 6/7] cxl/list: Add injectable errors in output
Date: Fri, 9 Jan 2026 15:17:15 -0700	[thread overview]
Message-ID: <c9925f29-85b4-4d7a-8fab-c8c5829d6a27@intel.com> (raw)
In-Reply-To: <20260109160720.1823-7-Benjamin.Cheatham@amd.com>



On 1/9/26 9:07 AM, Ben Cheatham wrote:
> Add injectable error information for CXL memory devices and busses.
> This information is only shown when the CXL debugfs is accessible
> (normally mounted at /sys/kernel/debug/cxl).
> 
> For CXL memory devices and dports this reports whether the device
> supports poison injection. The "--media-errors"/"-L" option shows
> injected poison for memory devices.
> 
> For CXL busses this shows injectable CXL protocol error types. The
> information will be the same across busses because the error types are
> system-wide. The information is presented under the bus for easier
> filtering.
> 
> Signed-off-by: Ben Cheatham <Benjamin.Cheatham@amd.com>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>


> ---
>  cxl/json.c         | 38 ++++++++++++++++++++++++++++++++++++++
>  cxl/lib/libcxl.c   | 34 +++++++++++++++++++++++++---------
>  cxl/lib/libcxl.sym |  2 ++
>  cxl/libcxl.h       |  2 ++
>  4 files changed, 67 insertions(+), 9 deletions(-)
> 
> diff --git a/cxl/json.c b/cxl/json.c
> index e9cb88a..6cdf513 100644
> --- a/cxl/json.c
> +++ b/cxl/json.c
> @@ -663,6 +663,12 @@ struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
>  			json_object_object_add(jdev, "state", jobj);
>  	}
>  
> +	if (cxl_debugfs_exists(cxl_memdev_get_ctx(memdev))) {
> +		jobj = json_object_new_boolean(cxl_memdev_has_poison_injection(memdev));
> +		if (jobj)
> +			json_object_object_add(jdev, "poison_injectable", jobj);
> +	}
> +
>  	if (flags & UTIL_JSON_PARTITION) {
>  		jobj = util_cxl_memdev_partition_to_json(memdev, flags);
>  		if (jobj)
> @@ -691,6 +697,7 @@ void util_cxl_dports_append_json(struct json_object *jport,
>  {
>  	struct json_object *jobj, *jdports;
>  	struct cxl_dport *dport;
> +	char *einj_path;
>  	int val;
>  
>  	val = cxl_port_get_nr_dports(port);
> @@ -739,6 +746,13 @@ 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);
> +
>  		json_object_array_add(jdports, jdport);
>  		json_object_set_userdata(jdport, dport, NULL);
>  	}
> @@ -750,6 +764,8 @@ struct json_object *util_cxl_bus_to_json(struct cxl_bus *bus,
>  					 unsigned long flags)
>  {
>  	const char *devname = cxl_bus_get_devname(bus);
> +	struct cxl_ctx *ctx = cxl_bus_get_ctx(bus);
> +	struct cxl_protocol_error *perror;
>  	struct json_object *jbus, *jobj;
>  
>  	jbus = json_object_new_object();
> @@ -765,6 +781,28 @@ struct json_object *util_cxl_bus_to_json(struct cxl_bus *bus,
>  		json_object_object_add(jbus, "provider", jobj);
>  
>  	json_object_set_userdata(jbus, bus, NULL);
> +
> +	if (cxl_debugfs_exists(ctx)) {
> +		jobj = json_object_new_array();
> +		if (!jobj)
> +			return jbus;
> +
> +		cxl_protocol_error_foreach(ctx, perror)
> +		{
> +			struct json_object *jerr_str;
> +			const char *perror_str;
> +
> +			perror_str = cxl_protocol_error_get_str(perror);
> +
> +			jerr_str = json_object_new_string(perror_str);
> +			if (jerr_str)
> +				json_object_array_add(jobj, jerr_str);
> +		}
> +
> +		json_object_object_add(jbus, "injectable_protocol_errors",
> +				       jobj);
> +	}
> +
>  	return jbus;
>  }
>  
> diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
> index deebf7f..f824701 100644
> --- a/cxl/lib/libcxl.c
> +++ b/cxl/lib/libcxl.c
> @@ -285,6 +285,11 @@ static char* get_cxl_debugfs_dir(void)
>  	return debugfs_dir;
>  }
>  
> +CXL_EXPORT bool cxl_debugfs_exists(struct cxl_ctx *ctx)
> +{
> +	return ctx->cxl_debugfs != NULL;
> +}
> +
>  /**
>   * cxl_new - instantiate a new library context
>   * @ctx: context to establish
> @@ -3567,38 +3572,49 @@ cxl_protocol_error_get_str(struct cxl_protocol_error *perror)
>  	return perror->string;
>  }
>  
> -CXL_EXPORT int cxl_dport_protocol_error_inject(struct cxl_dport *dport,
> -					       unsigned int error)
> +CXL_EXPORT char *cxl_dport_get_einj_path(struct cxl_dport *dport)
>  {
>  	struct cxl_ctx *ctx = dport->port->ctx;
> -	char buf[32] = { 0 };
>  	size_t path_len, len;
>  	char *path;
>  	int rc;
>  
> -	if (!ctx->cxl_debugfs)
> -		return -ENOENT;
> -
>  	path_len = strlen(ctx->cxl_debugfs) + 100;
>  	path = calloc(path_len, sizeof(char));
>  	if (!path)
> -		return -ENOMEM;
> +		return NULL;
>  
>  	len = snprintf(path, path_len, "%s/%s/einj_inject", ctx->cxl_debugfs,
>  		      cxl_dport_get_devname(dport));
>  	if (len >= path_len) {
>  		err(ctx, "%s: buffer too small\n", cxl_dport_get_devname(dport));
>  		free(path);
> -		return -ENOMEM;
> +		return NULL;
>  	}
>  
>  	rc = access(path, F_OK);
>  	if (rc) {
>  		err(ctx, "failed to access %s: %s\n", path, strerror(errno));
>  		free(path);
> -		return -errno;
> +		return NULL;
>  	}
>  
> +	return path;
> +}
> +
> +CXL_EXPORT int cxl_dport_protocol_error_inject(struct cxl_dport *dport,
> +					       unsigned int error)
> +{
> +	struct cxl_ctx *ctx = dport->port->ctx;
> +	char buf[32] = { 0 };
> +	char *path;
> +	size_t len;
> +	int rc;
> +
> +	path = cxl_dport_get_einj_path(dport);
> +	if (!path)
> +		return -ENOENT;
> +
>  	len = snprintf(buf, sizeof(buf), "0x%x\n", error);
>  	if (len >= sizeof(buf)) {
>  		err(ctx, "%s: buffer too small\n", cxl_dport_get_devname(dport));
> diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym
> index c636edb..ebca543 100644
> --- a/cxl/lib/libcxl.sym
> +++ b/cxl/lib/libcxl.sym
> @@ -308,8 +308,10 @@ global:
>  	cxl_protocol_error_get_next;
>  	cxl_protocol_error_get_num;
>  	cxl_protocol_error_get_str;
> +	cxl_dport_get_einj_path;
>  	cxl_dport_protocol_error_inject;
>  	cxl_memdev_has_poison_injection;
>  	cxl_memdev_inject_poison;
>  	cxl_memdev_clear_poison;
> +	cxl_debugfs_exists;
>  } LIBCXL_10;
> diff --git a/cxl/libcxl.h b/cxl/libcxl.h
> index 4d035f0..e390aca 100644
> --- a/cxl/libcxl.h
> +++ b/cxl/libcxl.h
> @@ -32,6 +32,7 @@ void cxl_set_userdata(struct cxl_ctx *ctx, void *userdata);
>  void *cxl_get_userdata(struct cxl_ctx *ctx);
>  void cxl_set_private_data(struct cxl_ctx *ctx, void *data);
>  void *cxl_get_private_data(struct cxl_ctx *ctx);
> +bool cxl_debugfs_exists(struct cxl_ctx *ctx);
>  
>  enum cxl_fwl_status {
>  	CXL_FWL_STATUS_UNKNOWN,
> @@ -507,6 +508,7 @@ struct cxl_protocol_error *
>  cxl_protocol_error_get_next(struct cxl_protocol_error *perror);
>  unsigned int cxl_protocol_error_get_num(struct cxl_protocol_error *perror);
>  const char *cxl_protocol_error_get_str(struct cxl_protocol_error *perror);
> +char *cxl_dport_get_einj_path(struct cxl_dport *dport);
>  int cxl_dport_protocol_error_inject(struct cxl_dport *dport,
>  				    unsigned int error);
>  


  reply	other threads:[~2026-01-09 22:17 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-09 16:07 [ndctl PATCH v6 0/7] Add error injection support Ben Cheatham
2026-01-09 16:07 ` [PATCH 1/7] libcxl: Add debugfs path to CXL context Ben Cheatham
2026-01-09 17:43   ` Dave Jiang
2026-01-09 16:07 ` [PATCH 2/7] libcxl: Add CXL protocol errors Ben Cheatham
2026-01-09 17:54   ` Dave Jiang
2026-01-12 17:20     ` Cheatham, Benjamin
2026-01-09 16:07 ` [PATCH 3/7] libcxl: Add poison injection support Ben Cheatham
2026-01-09 18:03   ` Dave Jiang
2026-01-12 17:20     ` Cheatham, Benjamin
2026-01-09 16:07 ` [PATCH 4/7] cxl: Add inject-error command Ben Cheatham
2026-01-09 21:53   ` Dave Jiang
2026-01-12 17:20     ` Cheatham, Benjamin
2026-01-09 16:07 ` [PATCH 5/7] cxl: Add clear-error command Ben Cheatham
2026-01-09 22:12   ` Dave Jiang
2026-01-09 16:07 ` [PATCH 6/7] cxl/list: Add injectable errors in output Ben Cheatham
2026-01-09 22:17   ` Dave Jiang [this message]
2026-01-09 16:07 ` [PATCH 7/7] Documentation: Add docs for inject/clear-error commands Ben Cheatham
2026-01-09 22:25   ` Dave Jiang
  -- strict thread matches above, loose matches on Subject: below --
2026-01-22 20:37 [ndctl PATCH v7 0/7] Add error injection support Ben Cheatham
2026-01-22 20:37 ` [PATCH 6/7] cxl/list: Add injectable errors in output Ben Cheatham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c9925f29-85b4-4d7a-8fab-c8c5829d6a27@intel.com \
    --to=dave.jiang@intel.com \
    --cc=Benjamin.Cheatham@amd.com \
    --cc=alison.schofield@intel.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox