public inbox for nvdimm@lists.linux.dev
 help / color / mirror / Atom feed
From: "Cheatham, Benjamin" <benjamin.cheatham@amd.com>
To: Dave Jiang <dave.jiang@intel.com>, <nvdimm@lists.linux.dev>
Cc: <linux-cxl@vger.kernel.org>, <alison.schofield@intel.com>
Subject: Re: [ndctl PATCH v3 3/7] libcxl: Add poison injection support
Date: Thu, 23 Oct 2025 15:15:22 -0500	[thread overview]
Message-ID: <997cb265-bb16-4aa8-91d5-ac245f85fe29@amd.com> (raw)
In-Reply-To: <4c452ff5-bcd3-4a3e-9fc1-04fb741f9e14@intel.com>

On 10/21/2025 6:44 PM, Dave Jiang wrote:
> 
> 
> On 10/21/25 11:31 AM, Ben Cheatham wrote:
>> Add a library API for clearing and injecting poison into a CXL memory
>> device through the CXL debugfs.
>>
>> This API will be used by the 'cxl-inject-error' and 'cxl-clear-error'
>> commands in later commits.
>>
>> Signed-off-by: Ben Cheatham <Benjamin.Cheatham@amd.com>
>> ---
>>  cxl/lib/libcxl.c   | 60 ++++++++++++++++++++++++++++++++++++++++++++++
>>  cxl/lib/libcxl.sym |  3 +++
>>  cxl/libcxl.h       |  3 +++
>>  3 files changed, 66 insertions(+)
>>
>> diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
>> index 9486b0f..9d4bd80 100644
>> --- a/cxl/lib/libcxl.c
>> +++ b/cxl/lib/libcxl.c
>> @@ -5019,3 +5019,63 @@ CXL_EXPORT struct cxl_cmd *cxl_cmd_new_set_alert_config(struct cxl_memdev *memde
>>  {
>>  	return cxl_cmd_new_generic(memdev, CXL_MEM_COMMAND_ID_SET_ALERT_CONFIG);
>>  }
>> +
>> +CXL_EXPORT bool cxl_memdev_has_poison_injection(struct cxl_memdev *memdev)
>> +{
>> +	struct cxl_ctx *ctx = memdev->ctx;
>> +	size_t path_len;
>> +	bool exists;
>> +	char *path;
>> +
>> +	if (!ctx->debugfs)
>> +		return false;
>> +
>> +	path_len = strlen(ctx->debugfs) + 100;
>> +	path = calloc(path_len, sizeof(char));
>> +	if (!path)
>> +		return false;
>> +
>> +	snprintf(path, path_len, "%s/cxl/%s/inject_poison", ctx->debugfs,
>> +		 cxl_memdev_get_devname(memdev));
> 
> check return value
> 
>> +	exists = access(path, F_OK) == 0;
> 
> While this works, it is more readable this way:
> 
> 	exists = true;
> 	...
> 	rc = access(path, F_OK);
> 	if (rc)
> 		exists = false;> +

Ok, I'll change it.

>> +	free(path);
>> +	return exists;
>> +}
>> +
>> +static int cxl_memdev_poison_action(struct cxl_memdev *memdev, size_t dpa,
>> +				    bool clear)
>> +{
>> +	struct cxl_ctx *ctx = memdev->ctx;
>> +	size_t path_len;
>> +	char addr[32];
>> +	char *path;
>> +	int rc;
>> +
>> +	if (!ctx->debugfs)
>> +		return -ENOENT;
>> +
>> +	path_len = strlen(ctx->debugfs) + 100;
>> +	path = calloc(path_len, sizeof(char));
>> +	if (!path)
>> +		return -ENOMEM;
>> +
>> +	snprintf(path, path_len, "%s/cxl/%s/%s", ctx->debugfs,
>> +		 cxl_memdev_get_devname(memdev),
>> +		 clear ? "clear_poison" : "inject_poison");
>> +	snprintf(addr, 32, "0x%lx\n", dpa);
> 
> check return values for both snprintf()
> 

Will do!

  reply	other threads:[~2025-10-23 20:15 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-21 18:31 [ndctl PATCH v3 0/7] Add error injection support Ben Cheatham
2025-10-21 18:31 ` [ndctl PATCH v3 1/7] libcxl: Add debugfs path to CXL context Ben Cheatham
2025-10-21 22:55   ` Dave Jiang
2025-10-23 20:15     ` Cheatham, Benjamin
2025-10-21 18:31 ` [ndctl PATCH v3 2/7] libcxl: Add CXL protocol errors Ben Cheatham
2025-10-21 23:15   ` Dave Jiang
2025-10-23 20:15     ` Cheatham, Benjamin
2025-10-23 22:50       ` Dave Jiang
2025-10-21 18:31 ` [ndctl PATCH v3 3/7] libcxl: Add poison injection support Ben Cheatham
2025-10-21 23:44   ` Dave Jiang
2025-10-23 20:15     ` Cheatham, Benjamin [this message]
2025-10-21 18:31 ` [ndctl PATCH v3 4/7] cxl: Add inject-error command Ben Cheatham
2025-10-22 17:06   ` Dave Jiang
2025-10-23 20:15     ` Cheatham, Benjamin
2025-10-23 22:51       ` Dave Jiang
2025-10-21 18:31 ` [ndctl PATCH v3 5/7] cxl: Add clear-error command Ben Cheatham
2025-10-21 18:31 ` [ndctl PATCH v3 6/7] cxl/list: Add injectable errors in output Ben Cheatham
2025-10-22 17:18   ` Dave Jiang
2025-10-21 18:31 ` [ndctl PATCH v3 7/7] Documentation: Add docs for inject/clear-error commands Ben Cheatham
2025-10-22 17:22   ` Dave Jiang

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=997cb265-bb16-4aa8-91d5-ac245f85fe29@amd.com \
    --to=benjamin.cheatham@amd.com \
    --cc=alison.schofield@intel.com \
    --cc=dave.jiang@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