From: Ben Cheatham <Benjamin.Cheatham@amd.com>
To: <nvdimm@lists.linux.dev>
Cc: <linux-cxl@vger.kernel.org>, <benjamin.cheatham@amd.com>,
<alison.schofield@intel.com>
Subject: [PATCH 3/6] libcxl: Add poison injection functions
Date: Thu, 24 Apr 2025 16:23:58 -0500 [thread overview]
Message-ID: <20250424212401.14789-4-Benjamin.Cheatham@amd.com> (raw)
In-Reply-To: <20250424212401.14789-1-Benjamin.Cheatham@amd.com>
Add a library API for clearing and injecting poison into a CXL memory
device through the kernel debugfs.
This API will be used by the cxl inject-error command to inject/clear
poison from a CXL memory device.
Signed-off-by: Ben Cheatham <Benjamin.Cheatham@amd.com>
---
cxl/lib/libcxl.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++
cxl/lib/libcxl.sym | 3 +++
cxl/libcxl.h | 3 +++
3 files changed, 58 insertions(+)
diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
index 408b2a3..bc4b08c 100644
--- a/cxl/lib/libcxl.c
+++ b/cxl/lib/libcxl.c
@@ -4856,3 +4856,55 @@ 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 = strlen(ctx->debugfs) + 100;
+ bool exists;
+ char *path;
+
+ 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));
+ exists = access(path, F_OK) == 0;
+
+ 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 = strlen(ctx->debugfs) + 100;
+ char addr[32];
+ char *path;
+ int rc;
+
+ 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);
+
+ rc = sysfs_write_attr(ctx, path, addr);
+ free(path);
+ return rc;
+}
+
+CXL_EXPORT int cxl_memdev_inject_poison(struct cxl_memdev *memdev, size_t addr)
+{
+ return cxl_memdev_poison_action(memdev, addr, false);
+}
+
+CXL_EXPORT int cxl_memdev_clear_poison(struct cxl_memdev *memdev, size_t addr)
+{
+ return cxl_memdev_poison_action(memdev, addr, true);
+}
diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym
index a0ab86d..783a257 100644
--- a/cxl/lib/libcxl.sym
+++ b/cxl/lib/libcxl.sym
@@ -296,4 +296,7 @@ global:
cxl_protocol_error_get_num;
cxl_protocol_error_get_str;
cxl_dport_protocol_error_inject;
+ cxl_memdev_has_poison_injection;
+ cxl_memdev_inject_poison;
+ cxl_memdev_clear_poison;
} LIBECXL_8;
diff --git a/cxl/libcxl.h b/cxl/libcxl.h
index f8b2aff..6840d2a 100644
--- a/cxl/libcxl.h
+++ b/cxl/libcxl.h
@@ -101,6 +101,9 @@ int cxl_memdev_read_label(struct cxl_memdev *memdev, void *buf, size_t length,
size_t offset);
int cxl_memdev_write_label(struct cxl_memdev *memdev, void *buf, size_t length,
size_t offset);
+bool cxl_memdev_has_poison_injection(struct cxl_memdev *memdev);
+int cxl_memdev_inject_poison(struct cxl_memdev *memdev, size_t dpa);
+int cxl_memdev_clear_poison(struct cxl_memdev *memdev, size_t dpa);
struct cxl_cmd *cxl_cmd_new_get_fw_info(struct cxl_memdev *memdev);
unsigned int cxl_cmd_fw_info_get_num_slots(struct cxl_cmd *cmd);
unsigned int cxl_cmd_fw_info_get_active_slot(struct cxl_cmd *cmd);
--
2.34.1
next prev parent reply other threads:[~2025-04-24 21:25 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-24 21:23 [ndctl PATCH 0/6] Add error injection support Ben Cheatham
2025-04-24 21:23 ` [PATCH 1/6] libcxl: Add debugfs path to CXL context Ben Cheatham
2025-04-24 21:23 ` [PATCH 2/6] libcxl: Add CXL protocol errors Ben Cheatham
2025-04-24 21:23 ` Ben Cheatham [this message]
2025-04-24 21:23 ` [PATCH 4/6] cxl/list: Add debugfs option Ben Cheatham
2025-04-24 21:24 ` [PATCH 5/6] cxl/list: Add injectable-errors option Ben Cheatham
2025-04-24 21:24 ` [PATCH 6/6] cxl: Add inject-error command Ben Cheatham
2025-04-29 2:35 ` [ndctl PATCH 0/6] Add error injection support Alison Schofield
2025-04-29 20:01 ` Ben Cheatham
2025-04-30 0:53 ` Alison Schofield
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=20250424212401.14789-4-Benjamin.Cheatham@amd.com \
--to=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