From: Junhyeok Im <junhyeok.im@samsung.com>
To: linux-cxl@vger.kernel.org
Cc: dan.j.williams@intel.com, vishal.l.verma@intel.com,
bwidawsk@kernel.org, alison.schofield@intel.com,
Junhyeok Im <junhyeok.im@samsung.com>
Subject: [ndctl 2/3] cxl: add inject-poison command to cxl tool
Date: Mon, 20 Feb 2023 13:57:08 +0900 [thread overview]
Message-ID: <20230220045709.94027-3-junhyeok.im@samsung.com> (raw)
In-Reply-To: <20230220045709.94027-1-junhyeok.im@samsung.com>
Add new command to cli tool, to inject poison into dpa(-a) on the
memory device.
DPA written in sysfs attribute(inject_poison) is converted by
kstrtou64 with 0 base by 'inject_poison_store' of CXL driver, so if
it begins with 0x the number will be parsed as a hexadecimal
(case insensitive), if it otherwise begins with 0, it will be parsed
as an octal number. Otherwise it will be parsed as a decimal.
Since the validity verification of the dpa would be done in
'cxl_validate_poison_dpa' of CXL driver, no additional logic
is added.
Also since it is expected no use case of injecting poison into the
same address for multiple devices, this command targets only one
memdev, like write-labels command.
usage: cxl inject-poison <memdev> -a <dpa> [<options>]
-v, --verbose turn on debug
-S, --serial use serial numbers to id memdevs
-a, --address <dpa> DPA to inject poison
Link to corresponding kernel patch:
https://patchwork.kernel.org/project/cxl/patch/97a0b128d0d0df56cea1a1a4ead65a40b9cf008e.1674101475.git.alison.schofield@intel.com/
Signed-off-by: Junhyeok Im <junhyeok.im@samsung.com>
---
cxl/builtin.h | 1 +
cxl/cxl.c | 1 +
cxl/memdev.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++---
3 files changed, 52 insertions(+), 3 deletions(-)
diff --git a/cxl/builtin.h b/cxl/builtin.h
index 34c5cfb..ddc4da9 100644
--- a/cxl/builtin.h
+++ b/cxl/builtin.h
@@ -23,4 +23,5 @@ int cmd_enable_region(int argc, const char **argv, struct cxl_ctx *ctx);
int cmd_disable_region(int argc, const char **argv, struct cxl_ctx *ctx);
int cmd_destroy_region(int argc, const char **argv, struct cxl_ctx *ctx);
int cmd_monitor(int argc, const char **argv, struct cxl_ctx *ctx);
+int cmd_inject_poison(int argc, const char **argv, struct cxl_ctx *ctx);
#endif /* _CXL_BUILTIN_H_ */
diff --git a/cxl/cxl.c b/cxl/cxl.c
index 3be7026..aa8d090 100644
--- a/cxl/cxl.c
+++ b/cxl/cxl.c
@@ -77,6 +77,7 @@ static struct cmd_struct commands[] = {
{ "disable-region", .c_fn = cmd_disable_region },
{ "destroy-region", .c_fn = cmd_destroy_region },
{ "monitor", .c_fn = cmd_monitor },
+ { "inject-poison", .c_fn = cmd_inject_poison },
};
int main(int argc, const char **argv)
diff --git a/cxl/memdev.c b/cxl/memdev.c
index 0b3ad02..7a10f79 100644
--- a/cxl/memdev.c
+++ b/cxl/memdev.c
@@ -34,6 +34,7 @@ static struct parameters {
const char *type;
const char *size;
const char *decoder_filter;
+ const char *poison_address;
} param;
static struct log_ctx ml;
@@ -85,6 +86,10 @@ OPT_STRING('t', "type", ¶m.type, "type", \
OPT_BOOLEAN('f', "force", ¶m.force, \
"Attempt 'expected to fail' operations")
+#define INJECT_POISON_OPTIONS() \
+OPT_STRING('a', "address", ¶m.poison_address, "dpa", \
+ "DPA to inject poison")
+
static const struct option read_options[] = {
BASE_OPTIONS(),
LABEL_OPTIONS(),
@@ -135,6 +140,12 @@ static const struct option free_dpa_options[] = {
OPT_END(),
};
+static const struct option inject_poison_options[] = {
+ BASE_OPTIONS(),
+ INJECT_POISON_OPTIONS(),
+ OPT_END(),
+};
+
enum reserve_dpa_mode {
DPA_ALLOC,
DPA_FREE,
@@ -351,6 +362,24 @@ static int action_free_dpa(struct cxl_memdev *memdev,
return __reserve_dpa(memdev, DPA_FREE, actx);
}
+static int action_inject_poison(struct cxl_memdev *memdev,
+ struct action_context *actx)
+{
+ int rc;
+
+ if (!param.poison_address) {
+ log_err(&ml, "%s: set dpa to inject poison.\n",
+ cxl_memdev_get_devname(memdev));
+ return -EINVAL;
+ }
+ rc = cxl_memdev_inject_poison(memdev, param.poison_address);
+ if (rc < 0) {
+ log_err(&ml, "%s: inject poison failed: %s\n",
+ cxl_memdev_get_devname(memdev), strerror(-rc));
+ }
+ return rc;
+}
+
static int action_disable(struct cxl_memdev *memdev, struct action_context *actx)
{
if (!cxl_memdev_is_enabled(memdev))
@@ -755,7 +784,8 @@ static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
continue;
found = true;
- if (action == action_write) {
+ if ((action == action_write) ||
+ (action == action_inject_poison)) {
single = memdev;
rc = 0;
} else
@@ -771,9 +801,15 @@ static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
}
rc = err;
- if (action == action_write) {
+ if ((action == action_write) || (action == action_inject_poison)) {
if (count > 1) {
- error("write-labels only supports writing a single memdev\n");
+ if (action == action_write) {
+ error("write-labels only supports writing "
+ "a single memdev\n");
+ } else {
+ error("inject-poison only supports injection "
+ "of poison into a single memdev\n");
+ }
usage_with_options(u, options);
return -EINVAL;
} else if (single) {
@@ -893,3 +929,14 @@ int cmd_free_dpa(int argc, const char **argv, struct cxl_ctx *ctx)
return count >= 0 ? 0 : EXIT_FAILURE;
}
+
+int cmd_inject_poison(int argc, const char **argv, struct cxl_ctx *ctx)
+{
+ int count = memdev_action(
+ argc, argv, ctx, action_inject_poison, inject_poison_options,
+ "cxl inject-poison <memdev> -a <dpa> [<options>]");
+ log_info(&ml, "inject-poison %d mem%s\n", count >= 0 ? count : 0,
+ count > 1 ? "s" : "");
+
+ return count >= 0 ? 0 : EXIT_FAILURE;
+}
--
2.34.1
next prev parent reply other threads:[~2023-02-20 4:56 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20230220045604epcas2p3bc0b1fb688c48ec0b8ae2512adba3513@epcas2p3.samsung.com>
2023-02-20 4:57 ` [ndctl 0/3] Support for inject poison Junhyeok Im
2023-02-20 4:57 ` [ndctl 1/3] libcxl: add memdev inject poison support Junhyeok Im
2023-02-27 2:43 ` Alison Schofield
2023-02-20 4:57 ` Junhyeok Im [this message]
2023-02-27 3:21 ` [ndctl 2/3] cxl: add inject-poison command to cxl tool Alison Schofield
2023-02-28 9:43 ` Junhyeok Im
2023-03-01 19:01 ` Verma, Vishal L
2023-02-27 3:25 ` Alison Schofield
2023-02-28 9:45 ` Junhyeok Im
2023-02-20 4:57 ` [ndctl 3/3] Documentation: add man page documentation for inject-poison Junhyeok Im
2023-02-27 2:38 ` [ndctl 0/3] Support for inject poison Alison Schofield
2023-02-28 9:31 ` Junhyeok Im
2023-05-08 18:39 ` Verma, Vishal L
2023-05-09 9:19 ` Junhyeok Im
[not found] <CGME20230220013613epcas2p23cee8c0fe839f12ca125e97c6f66d815@epcas2p2.samsung.com>
2023-02-20 1:37 ` [ndctl 1/3] libcxl: add memdev inject poison support junhyeok.im
2023-02-20 1:37 ` [ndctl 2/3] cxl: add inject-poison command to cxl tool junhyeok.im
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=20230220045709.94027-3-junhyeok.im@samsung.com \
--to=junhyeok.im@samsung.com \
--cc=alison.schofield@intel.com \
--cc=bwidawsk@kernel.org \
--cc=dan.j.williams@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=vishal.l.verma@intel.com \
/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