From: "Cheatham, Benjamin" <benjamin.cheatham@amd.com>
To: Dave Jiang <dave.jiang@intel.com>, <nvdimm@lists.linux.dev>,
<alison.schofield@intel.com>
Cc: <linux-cxl@vger.kernel.org>
Subject: Re: [PATCH 4/7] cxl: Add inject-error command
Date: Mon, 12 Jan 2026 11:20:23 -0600 [thread overview]
Message-ID: <fe68340f-783d-47c7-a931-d469a32f003b@amd.com> (raw)
In-Reply-To: <1160bfba-eb39-4b77-b7ed-8409009f42e1@intel.com>
On 1/9/2026 3:53 PM, Dave Jiang wrote:
>
>
> On 1/9/26 9:07 AM, Ben Cheatham wrote:
>> Add the 'cxl-inject-error' command. This command will provide CXL
>> protocol error injection for CXL VH root ports and CXL RCH downstream
>> ports, as well as poison injection for CXL memory devices.
>>
>> Add util_cxl_dport_filter() to find downstream ports by device name.
>>
>> Signed-off-by: Ben Cheatham <Benjamin.Cheatham@amd.com>
>> ---
[snip]
>> +
>> +static int poison_action(struct cxl_ctx *ctx, const char *filter,
>> + const char *addr_str)
>> +{
>> + struct cxl_memdev *memdev;
>> + unsigned long long addr;
>> + int rc;
>> +
>> + memdev = find_cxl_memdev(ctx, filter);
>> + if (!memdev)
>> + return -ENODEV;
>> +
>> + if (!cxl_memdev_has_poison_injection(memdev)) {
>> + log_err(&iel, "%s does not support error injection\n",
>> + cxl_memdev_get_devname(memdev));
>> + return -EINVAL;
>> + }
>> +
>> + if (!addr_str) {
>> + log_err(&iel, "no address provided\n");
>> + return -EINVAL;
>> + }
>> +
>> + errno = 0;
>
> Why does errno needs to be set here?
Alison suggested it last revision. It's been a while so my memory is a bit hazy,
but I think strtoull() doesn't reset errno and checking it below could cause a problem
if it was set to ERANGE by a previous function.
>
>> + addr = strtoull(addr_str, NULL, 0);
>> + if (addr == ULLONG_MAX && errno == ERANGE) {
>> + log_err(&iel, "invalid address %s", addr_str);
>> + return -EINVAL;
>> + }
>> +
>> + rc = cxl_memdev_inject_poison(memdev, addr);
>> + if (rc)
>> + log_err(&iel, "failed to inject poison at %s:%s: %s\n",
>> + cxl_memdev_get_devname(memdev), addr_str, strerror(-rc));
>
> We don't error if poison fails to inject?
It does? The return code of cxl_memdev_inject_poison() is returned below, the only
thing that this if statement does is pick which message is emitted.
Thanks,
Ben
>
> DJ
>
>> + else
>> + log_info(&iel, "poison injected at %s:%s\n",
>> + cxl_memdev_get_devname(memdev), addr_str);
>> +
>> + return rc;
>> +}
>> +
>> +static int inject_action(int argc, const char **argv, struct cxl_ctx *ctx,
>> + const struct option *options, const char *usage)
>> +{
>> + struct cxl_protocol_error *perr;
>> + const char * const u[] = {
>> + usage,
>> + NULL
>> + };
>> + int rc = -EINVAL;
>> +
>> + log_init(&iel, "cxl inject-error", "CXL_INJECT_LOG");
>> + argc = parse_options(argc, argv, options, u, 0);
>> +
>> + if (debug) {
>> + cxl_set_log_priority(ctx, LOG_DEBUG);
>> + iel.log_priority = LOG_DEBUG;
>> + } else {
>> + iel.log_priority = LOG_INFO;
>> + }
>> +
>> + if (argc != 1 || inj_param.type == NULL) {
>> + usage_with_options(u, options);
>> + return rc;
>> + }
>> +
>> + if (strcmp(inj_param.type, "poison") == 0) {
>> + rc = poison_action(ctx, argv[0], inj_param.address);
>> + return rc;
>> + }
>> +
>> + perr = find_cxl_proto_err(ctx, inj_param.type);
>> + if (perr) {
>> + rc = inject_proto_err(ctx, argv[0], perr);
>> + if (rc)
>> + log_err(&iel, "Failed to inject error: %d\n", rc);
>> + }
>> +
>> + return rc;
>> +}
>> +
>> +int cmd_inject_error(int argc, const char **argv, struct cxl_ctx *ctx)
>> +{
>> + int rc = inject_action(argc, argv, ctx, inject_options,
>> + "inject-error <device> -t <type> [<options>]");
>> +
>> + return rc ? EXIT_FAILURE : EXIT_SUCCESS;
>> +}
>> diff --git a/cxl/meson.build b/cxl/meson.build
>> index b9924ae..92031b5 100644
>> --- a/cxl/meson.build
>> +++ b/cxl/meson.build
>> @@ -7,6 +7,7 @@ cxl_src = [
>> 'memdev.c',
>> 'json.c',
>> 'filter.c',
>> + 'inject-error.c',
>> '../daxctl/json.c',
>> '../daxctl/filter.c',
>> ]
>
next prev parent reply other threads:[~2026-01-12 17:20 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 [this message]
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
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 4/7] cxl: Add inject-error command 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=fe68340f-783d-47c7-a931-d469a32f003b@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