* [ndctl PATCH 0/2] add support for Set Alert Configuration mailbox command
[not found] <CGME20230711070758epcas2p4111d4413d669a8ef6dc8862a0f4835b9@epcas2p4.samsung.com>
@ 2023-07-11 7:10 ` Jehoon Park
2023-07-11 7:10 ` [ndctl PATCH 1/2] libcxl: " Jehoon Park
2023-07-11 7:10 ` [ndctl PATCH 2/2] cxl: add 'set-alert-config' command to cxl tool Jehoon Park
0 siblings, 2 replies; 5+ messages in thread
From: Jehoon Park @ 2023-07-11 7:10 UTC (permalink / raw)
To: linux-cxl
Cc: nvdimm, Alison Schofield, Vishal Verma, Ira Weiny, Ben Widawsky,
Dan Williams, Dave Jiang, Kyungsan Kim, Junhyeok Im, Jehoon Park
CXL 3.0 Spec 8.2.9.8.3.3 defines Set Alert Configuration mailbox command.
This patchset adds support for the command to configure warning alert.
Example:
# ./cxl set-alert-config mem0 -L 30 --life-used-alert=on
{
"memdev":"mem0",
"ram_size":"1024.00 MiB (1073.74 MB)",
"alert_config":{
"life_used_prog_warn_threshold_valid":true,
"dev_over_temperature_prog_warn_threshold_valid":false,
"dev_under_temperature_prog_warn_threshold_valid":false,
"corrected_volatile_mem_err_prog_warn_threshold_valid":false,
"corrected_pmem_err_prog_warn_threshold_valid":false,
"life_used_prog_warn_threshold_writable":true,
"dev_over_temperature_prog_warn_threshold_writable":true,
"dev_under_temperature_prog_warn_threshold_writable":true,
"corrected_volatile_mem_err_prog_warn_threshold_writable":true,
"corrected_pmem_err_prog_warn_threshold_writable":true,
"life_used_crit_alert_threshold":75,
"life_used_prog_warn_threshold":30,
"dev_over_temperature_crit_alert_threshold":0,
"dev_under_temperature_crit_alert_threshold":0,
"dev_over_temperature_prog_warn_threshold":0,
"dev_under_temperature_prog_warn_threshold":0,
"corrected_volatile_mem_err_prog_warn_threshold":0,
"corrected_pmem_err_prog_warn_threshold":0
},
"serial":"0",
"host":"0000:0d:00.0"
}
cxl memdev: cmd_set_alert_config: set alert configuration 1 mem
The implementation is based on the 'ndctl-inject-smart'. Variable and function
names are aligned with the implementation of 'Get Alert Configuration'.
Jehoon Park (2):
libcxl: add support for Set Alert Configuration mailbox command
cxl: add 'set-alert-config' command to cxl tool
Documentation/cxl/cxl-set-alert-config.txt | 96 +++++++++
Documentation/cxl/lib/libcxl.txt | 1 +
Documentation/cxl/meson.build | 1 +
cxl/builtin.h | 1 +
cxl/cxl.c | 1 +
cxl/lib/libcxl.c | 21 ++
cxl/lib/libcxl.sym | 12 ++
cxl/lib/private.h | 12 ++
cxl/libcxl.h | 16 ++
cxl/memdev.c | 219 ++++++++++++++++++++-
10 files changed, 379 insertions(+), 1 deletion(-)
create mode 100644 Documentation/cxl/cxl-set-alert-config.txt
base-commit: 7f75ce36ce3a0d41ed74d4e2dfcfd41a6fd7fe40
--
2.17.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ndctl PATCH 1/2] libcxl: add support for Set Alert Configuration mailbox command
2023-07-11 7:10 ` [ndctl PATCH 0/2] add support for Set Alert Configuration mailbox command Jehoon Park
@ 2023-07-11 7:10 ` Jehoon Park
2023-07-11 7:10 ` [ndctl PATCH 2/2] cxl: add 'set-alert-config' command to cxl tool Jehoon Park
1 sibling, 0 replies; 5+ messages in thread
From: Jehoon Park @ 2023-07-11 7:10 UTC (permalink / raw)
To: linux-cxl
Cc: nvdimm, Alison Schofield, Vishal Verma, Ira Weiny, Ben Widawsky,
Dan Williams, Dave Jiang, Kyungsan Kim, Junhyeok Im, Jehoon Park
CXL 3.0 Spec 8.2.9.8.3.3 defines Set Alert Configuration mailbox command which
allows a CXL host to configure programmable warning thresholds optionally.
Add methods to issue the command and set fields.
Signed-off-by: Jehoon Park <jehoon.park@samsung.com>
---
Documentation/cxl/lib/libcxl.txt | 1 +
cxl/lib/libcxl.c | 21 +++++++++++++++++++++
cxl/lib/libcxl.sym | 12 ++++++++++++
cxl/lib/private.h | 12 ++++++++++++
cxl/libcxl.h | 16 ++++++++++++++++
5 files changed, 62 insertions(+)
diff --git a/Documentation/cxl/lib/libcxl.txt b/Documentation/cxl/lib/libcxl.txt
index 31bc855..bcb8928 100644
--- a/Documentation/cxl/lib/libcxl.txt
+++ b/Documentation/cxl/lib/libcxl.txt
@@ -122,6 +122,7 @@ struct cxl_cmd *cxl_cmd_new_raw(struct cxl_memdev *memdev, int opcode);
struct cxl_cmd *cxl_cmd_new_identify(struct cxl_memdev *memdev);
struct cxl_cmd *cxl_cmd_new_get_health_info(struct cxl_memdev *memdev);
struct cxl_cmd *cxl_cmd_new_get_alert_config(struct cxl_memdev *memdev);
+struct cxl_cmd *cxl_cmd_new_set_alert_config(struct cxl_memdev *memdev);
struct cxl_cmd *cxl_cmd_new_read_label(struct cxl_memdev *memdev,
unsigned int offset, unsigned int length);
struct cxl_cmd *cxl_cmd_new_write_label(struct cxl_memdev *memdev, void *buf,
diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
index 769cd8a..a70b064 100644
--- a/cxl/lib/libcxl.c
+++ b/cxl/lib/libcxl.c
@@ -4166,3 +4166,24 @@ CXL_EXPORT int cxl_memdev_read_label(struct cxl_memdev *memdev, void *buf,
{
return lsa_op(memdev, LSA_OP_GET, buf, length, offset);
}
+
+#define cxl_alert_config_set_field(field) \
+CXL_EXPORT int cxl_cmd_alert_config_set_##field(struct cxl_cmd *cmd, int val) \
+{ \
+ struct cxl_cmd_set_alert_config *setalert = cmd->input_payload; \
+ setalert->field = val; \
+ return 0; \
+}
+
+cxl_alert_config_set_field(life_used_prog_warn_threshold)
+cxl_alert_config_set_field(dev_over_temperature_prog_warn_threshold)
+cxl_alert_config_set_field(dev_under_temperature_prog_warn_threshold)
+cxl_alert_config_set_field(corrected_volatile_mem_err_prog_warn_threshold)
+cxl_alert_config_set_field(corrected_pmem_err_prog_warn_threshold)
+cxl_alert_config_set_field(valid_alert_actions)
+cxl_alert_config_set_field(enable_alert_actions)
+
+CXL_EXPORT struct cxl_cmd *cxl_cmd_new_set_alert_config(struct cxl_memdev *memdev)
+{
+ return cxl_cmd_new_generic(memdev, CXL_MEM_COMMAND_ID_SET_ALERT_CONFIG);
+}
diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym
index c6545c7..334f01f 100644
--- a/cxl/lib/libcxl.sym
+++ b/cxl/lib/libcxl.sym
@@ -250,3 +250,15 @@ global:
cxl_region_get_daxctl_region;
cxl_port_get_parent_dport;
} LIBCXL_4;
+
+LIBCXL_6 {
+global:
+ cxl_cmd_alert_config_set_life_used_prog_warn_threshold;
+ cxl_cmd_alert_config_set_dev_over_temperature_prog_warn_threshold;
+ cxl_cmd_alert_config_set_dev_under_temperature_prog_warn_threshold;
+ cxl_cmd_alert_config_set_corrected_volatile_mem_err_prog_warn_threshold;
+ cxl_cmd_alert_config_set_corrected_pmem_err_prog_warn_threshold;
+ cxl_cmd_alert_config_set_valid_alert_actions;
+ cxl_cmd_alert_config_set_enable_alert_actions;
+ cxl_cmd_new_set_alert_config;
+} LIBCXL_5;
diff --git a/cxl/lib/private.h b/cxl/lib/private.h
index d49b560..43bf1d7 100644
--- a/cxl/lib/private.h
+++ b/cxl/lib/private.h
@@ -273,6 +273,18 @@ struct cxl_cmd_get_alert_config {
#define CXL_CMD_ALERT_CONFIG_PROG_ALERTS_CORRECTED_PMEM_ERR_PROG_WARN_THRESHOLD_MASK \
BIT(4)
+/* CXL 3.0 8.2.9.8.3.3 Set Alert Configuration */
+struct cxl_cmd_set_alert_config {
+ u8 valid_alert_actions;
+ u8 enable_alert_actions;
+ u8 life_used_prog_warn_threshold;
+ u8 rsvd;
+ le16 dev_over_temperature_prog_warn_threshold;
+ le16 dev_under_temperature_prog_warn_threshold;
+ le16 corrected_volatile_mem_err_prog_warn_threshold;
+ le16 corrected_pmem_err_prog_warn_threshold;
+} __attribute__((packed));
+
struct cxl_cmd_get_partition {
le64 active_volatile;
le64 active_persistent;
diff --git a/cxl/libcxl.h b/cxl/libcxl.h
index 0218d73..c981683 100644
--- a/cxl/libcxl.h
+++ b/cxl/libcxl.h
@@ -425,6 +425,22 @@ enum cxl_setpartition_mode {
int cxl_cmd_partition_set_mode(struct cxl_cmd *cmd,
enum cxl_setpartition_mode mode);
+int cxl_cmd_alert_config_set_life_used_prog_warn_threshold(struct cxl_cmd *cmd,
+ int threshold);
+int cxl_cmd_alert_config_set_dev_over_temperature_prog_warn_threshold(
+ struct cxl_cmd *cmd, int threshold);
+int cxl_cmd_alert_config_set_dev_under_temperature_prog_warn_threshold(
+ struct cxl_cmd *cmd, int threshold);
+int cxl_cmd_alert_config_set_corrected_volatile_mem_err_prog_warn_threshold(
+ struct cxl_cmd *cmd, int threshold);
+int cxl_cmd_alert_config_set_corrected_pmem_err_prog_warn_threshold(
+ struct cxl_cmd *cmd, int threshold);
+int cxl_cmd_alert_config_set_valid_alert_actions(struct cxl_cmd *cmd,
+ int action);
+int cxl_cmd_alert_config_set_enable_alert_actions(struct cxl_cmd *cmd,
+ int enable);
+struct cxl_cmd *cxl_cmd_new_set_alert_config(struct cxl_memdev *memdev);
+
#ifdef __cplusplus
} /* extern "C" */
#endif
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [ndctl PATCH 2/2] cxl: add 'set-alert-config' command to cxl tool
2023-07-11 7:10 ` [ndctl PATCH 0/2] add support for Set Alert Configuration mailbox command Jehoon Park
2023-07-11 7:10 ` [ndctl PATCH 1/2] libcxl: " Jehoon Park
@ 2023-07-11 7:10 ` Jehoon Park
2023-07-24 22:07 ` Verma, Vishal L
1 sibling, 1 reply; 5+ messages in thread
From: Jehoon Park @ 2023-07-11 7:10 UTC (permalink / raw)
To: linux-cxl
Cc: nvdimm, Alison Schofield, Vishal Verma, Ira Weiny, Ben Widawsky,
Dan Williams, Dave Jiang, Kyungsan Kim, Junhyeok Im, Jehoon Park
Add a new command: 'set-alert-config', which configures device's warning alert
usage: cxl set-alert-config <mem0> [<mem1>..<memN>] [<options>]
-v, --verbose turn on debug
-S, --serial use serial numbers to id memdevs
-L, --life-used-threshold <threshold>
threshold value for life used warning alert
--life-used-alert <'on' or 'off'>
enable or disable life used warning alert
-O, --over-temperature-threshold <threshold>
threshold value for device over temperature warning alert
--over-temperature-alert <'on' or 'off'>
enable or disable device over temperature warning alert
-U, --under-temperature-threshold <threshold>
threshold value for device under temperature warning alert
--under-temperature-alert <'on' or 'off'>
enable or disable device under temperature warning alert
-V, --volatile-mem-err-threshold <threshold>
threshold value for corrected volatile mem error warning alert
--volatile-mem-err-alert <'on' or 'off'>
enable or disable corrected volatile mem error warning alert
-P, --pmem-err-threshold <threshold>
threshold value for corrected pmem error warning alert
--pmem-err-alert <'on' or 'off'>
enable or disable corrected pmem error warning alert
Signed-off-by: Jehoon Park <jehoon.park@samsung.com>
---
Documentation/cxl/cxl-set-alert-config.txt | 96 +++++++++
Documentation/cxl/meson.build | 1 +
cxl/builtin.h | 1 +
cxl/cxl.c | 1 +
cxl/memdev.c | 219 ++++++++++++++++++++-
5 files changed, 317 insertions(+), 1 deletion(-)
create mode 100644 Documentation/cxl/cxl-set-alert-config.txt
diff --git a/Documentation/cxl/cxl-set-alert-config.txt b/Documentation/cxl/cxl-set-alert-config.txt
new file mode 100644
index 0000000..a291c09
--- /dev/null
+++ b/Documentation/cxl/cxl-set-alert-config.txt
@@ -0,0 +1,96 @@
+// SPDX-License-Identifier: GPL-2.0
+
+cxl-set-alert-config(1)
+=======================
+
+NAME
+----
+cxl-set-alert-config - set the warning alert threshold on a CXL memdev
+
+SYNOPSIS
+--------
+[verse]
+'cxl set-alert-config <mem0> [<mem1>..<memN>] [<options>]'
+
+DESCRIPTION
+-----------
+CXL device raises an alert when its health status is changed. Critical alert
+shall automatically be configured by the device after a device reset.
+If supported, programmable warning thresholds also be initialized to vendor
+recommended defaults, then could be configured by the host.
+
+Use this command to configure warning alert thresholds of a device.
+Having issued this command, the newly requested warning thresholds would
+override the previously programmed warning thresholds.
+
+To enable warning alert, set both 'threshold=value' and 'alert=on'. To disable
+warning alert, set only 'alert=off'. Other cases would cause errors.
+
+Use "cxl list -m <memdev> -A" to examine the programming warning threshold
+capabilities of a device.
+
+EXAMPLES
+--------
+Set warning threshold to 30 and enable alert for life used.
+[verse]
+cxl set-alert-config mem0 -L 30 --life-used-alert=on
+
+Disable warning alert for device over temperature.
+[verse]
+cxl set-alert-config mem0 --over-temperature-alert=off
+
+OPTIONS
+-------
+<memory device(s)>::
+include::memdev-option.txt[]
+
+-v::
+--verbose=::
+ Turn on verbose debug messages in the library (if libcxl was built with
+ logging and debug enabled).
+
+-L::
+--life-used-threshold=::
+ Set <value> for the life used warning alert threshold.
+
+--life-used-alert=::
+ Enable or disable the life used warning alert.
+ Options are 'on' or 'off'.
+
+-O::
+--over-temperature-threshold=::
+ Set <value> for the device over temperature warning alert threshold.
+
+--over-temperature-alert=::
+ Enable or disable the device over temperature warning alert.
+ Options are 'on' or 'off'.
+
+-U::
+--under-temperature-threshold=::
+ Set <value> for the device under temperature warning alert threshold.
+
+--under-temperature-alert=::
+ Enable or disable the device under temperature warning alert.
+ Options are 'on' or 'off'.
+
+-V::
+--volatile-mem-err-threshold=::
+ Set <value> for the corrected volatile memory error warning alert
+ threshold.
+
+--volatile-mem-err-alert=::
+ Enable or disable the corrected volatile memory error warning alert.
+ Options are 'on' or 'off'.
+
+-P::
+--pmem-err-threshold=::
+ Set <value> for the corrected persistent memory error warning alert
+ threshold.
+
+--pmem-err-alert=::
+ Enable or disable the corrected persistent memory error warning alert.
+ Options are 'on' or 'off'.
+
+SEE ALSO
+--------
+CXL-3.0 8.2.9.8.3.3
diff --git a/Documentation/cxl/meson.build b/Documentation/cxl/meson.build
index a6d77ab..3ea412d 100644
--- a/Documentation/cxl/meson.build
+++ b/Documentation/cxl/meson.build
@@ -46,6 +46,7 @@ cxl_manpages = [
'cxl-enable-region.txt',
'cxl-destroy-region.txt',
'cxl-monitor.txt',
+ 'cxl-set-alert-config.txt',
]
foreach man : cxl_manpages
diff --git a/cxl/builtin.h b/cxl/builtin.h
index 9baa43b..7b2274c 100644
--- a/cxl/builtin.h
+++ b/cxl/builtin.h
@@ -32,4 +32,5 @@ static inline int cmd_monitor(int argc, const char **argv, struct cxl_ctx *ctx)
return EXIT_FAILURE;
}
#endif
+int cmd_set_alert_config(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..15eb1e6 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 },
+ { "set-alert-config", .c_fn = cmd_set_alert_config },
};
int main(int argc, const char **argv)
diff --git a/cxl/memdev.c b/cxl/memdev.c
index 0b3ad02..2587189 100644
--- a/cxl/memdev.c
+++ b/cxl/memdev.c
@@ -34,10 +34,38 @@ static struct parameters {
const char *type;
const char *size;
const char *decoder_filter;
+ const char *life_used_threshold;
+ const char *dev_over_temperature_threshold;
+ const char *dev_under_temperature_threshold;
+ const char *corrected_volatile_mem_err_threshold;
+ const char *corrected_pmem_err_threshold;
+ const char *life_used_alert;
+ const char *dev_over_temperature_alert;
+ const char *dev_under_temperature_alert;
+ const char *corrected_volatile_mem_err_alert;
+ const char *corrected_pmem_err_alert;
} param;
static struct log_ctx ml;
+struct alert_context {
+ int valid_alert_actions;
+ int enable_alert_actions;
+ int life_used_threshold;
+ int dev_over_temperature_threshold;
+ int dev_under_temperature_threshold;
+ int corrected_volatile_mem_err_threshold;
+ int corrected_pmem_err_threshold;
+};
+
+enum cxl_setalert_event {
+ CXL_SETALERT_LIFE_USED,
+ CXL_SETALERT_OVER_TEMP,
+ CXL_SETALERT_UNDER_TEMP,
+ CXL_SETALERT_VOLATILE_MEM_ERROR,
+ CXL_SETALERT_PMEM_ERROR,
+};
+
enum cxl_setpart_type {
CXL_SETPART_PMEM,
CXL_SETPART_VOLATILE,
@@ -85,6 +113,36 @@ OPT_STRING('t', "type", ¶m.type, "type", \
OPT_BOOLEAN('f', "force", ¶m.force, \
"Attempt 'expected to fail' operations")
+#define SET_ALERT_OPTIONS() \
+OPT_STRING('L', "life-used-threshold", ¶m.life_used_threshold, \
+ "threshold", "threshold value for life used warning alert"), \
+OPT_STRING('\0', "life-used-alert", ¶m.life_used_alert, \
+ "'on' or 'off'", "enable or disable life used warning alert"), \
+OPT_STRING('O', "over-temperature-threshold", \
+ ¶m.dev_over_temperature_threshold, "threshold", \
+ "threshold value for device over temperature warning alert"), \
+OPT_STRING('\0', "over-temperature-alert", \
+ ¶m.dev_over_temperature_alert, "'on' or 'off'", \
+ "enable or disable device over temperature warning alert"), \
+OPT_STRING('U', "under-temperature-threshold", \
+ ¶m.dev_under_temperature_threshold, "threshold", \
+ "threshold value for device under temperature warning alert"), \
+OPT_STRING('\0', "under-temperature-alert", \
+ ¶m.dev_under_temperature_alert, "'on' or 'off'", \
+ "enable or disable device under temperature warning alert"), \
+OPT_STRING('V', "volatile-mem-err-threshold", \
+ ¶m.corrected_volatile_mem_err_threshold, "threshold", \
+ "threshold value for corrected volatile mem error warning alert"), \
+OPT_STRING('\0', "volatile-mem-err-alert", \
+ ¶m.corrected_volatile_mem_err_alert, "'on' or 'off'", \
+ "enable or disable corrected volatile mem error warning alert"), \
+OPT_STRING('P', "pmem-err-threshold", \
+ ¶m.corrected_pmem_err_threshold, "threshold", \
+ "threshold value for corrected pmem error warning alert"), \
+OPT_STRING('\0', "pmem-err-alert", \
+ ¶m.corrected_pmem_err_alert, "'on' or 'off'", \
+ "enable or disable corrected pmem error warning alert")
+
static const struct option read_options[] = {
BASE_OPTIONS(),
LABEL_OPTIONS(),
@@ -135,6 +193,12 @@ static const struct option free_dpa_options[] = {
OPT_END(),
};
+static const struct option set_alert_options[] = {
+ BASE_OPTIONS(),
+ SET_ALERT_OPTIONS(),
+ OPT_END(),
+};
+
enum reserve_dpa_mode {
DPA_ALLOC,
DPA_FREE,
@@ -653,6 +717,148 @@ out_err:
return rc;
}
+static int validate_alert_threshold(enum cxl_setalert_event event,
+ int threshold)
+{
+ if (event == CXL_SETALERT_LIFE_USED) {
+ if (threshold < 0 || threshold > 100) {
+ log_err(&ml, "Invalid life used threshold: %d\n",
+ threshold);
+ return -EINVAL;
+ }
+ } else if (event == CXL_SETALERT_OVER_TEMP ||
+ event == CXL_SETALERT_UNDER_TEMP) {
+ if (threshold < SHRT_MIN || threshold > SHRT_MAX) {
+ log_err(&ml,
+ "Invalid device temperature threshold: %d\n",
+ threshold);
+ return -EINVAL;
+ }
+ } else {
+ if (threshold < 0 || threshold > USHRT_MAX) {
+ log_err(&ml,
+ "Invalid corrected mem error threshold: %d\n",
+ threshold);
+ return -EINVAL;
+ }
+ }
+ return 0;
+}
+
+#define alert_param_set_threshold(arg, alert_event) \
+{ \
+ if (!param.arg##_alert) { \
+ if (param.arg##_threshold) { \
+ log_err(&ml, "Action not specified\n"); \
+ return -EINVAL; \
+ } \
+ } else if (strncmp(param.arg##_alert, "on", 2) == 0) { \
+ if (param.arg##_threshold) { \
+ char *endptr; \
+ alertctx.arg##_threshold = \
+ strtol(param.arg##_threshold, &endptr, 10); \
+ if (endptr[0] != '\0') { \
+ log_err(&ml, "Invalid threshold: %s\n", \
+ param.arg##_threshold); \
+ return -EINVAL; \
+ } \
+ rc = validate_alert_threshold( \
+ alert_event, alertctx.arg##_threshold); \
+ if (rc != 0) \
+ return rc; \
+ alertctx.valid_alert_actions |= 1 << alert_event; \
+ alertctx.enable_alert_actions |= 1 << alert_event; \
+ } else { \
+ log_err(&ml, "Threshold not specified\n"); \
+ return -EINVAL; \
+ } \
+ } else if (strncmp(param.arg##_alert, "off", 3) == 0) { \
+ if (!param.arg##_threshold) { \
+ alertctx.valid_alert_actions |= 1 << alert_event; \
+ alertctx.enable_alert_actions &= ~(1 << alert_event); \
+ } else { \
+ log_err(&ml, "Disable not require threshold\n"); \
+ return -EINVAL; \
+ } \
+ } else { \
+ log_err(&ml, "Invalid action: %s\n", param.arg##_alert); \
+ return -EINVAL; \
+ } \
+}
+
+#define setup_threshold_field(arg) \
+{ \
+ if (param.arg##_threshold) \
+ cxl_cmd_alert_config_set_##arg##_prog_warn_threshold( \
+ cmd, alertctx.arg##_threshold); \
+}
+
+static int action_set_alert_config(struct cxl_memdev *memdev,
+ struct action_context *actx)
+{
+ const char *devname = cxl_memdev_get_devname(memdev);
+ struct cxl_cmd *cmd;
+ struct alert_context alertctx = { 0 };
+ struct json_object *jmemdev;
+ unsigned long flags;
+ int rc = 0;
+
+ alert_param_set_threshold(life_used, CXL_SETALERT_LIFE_USED)
+ alert_param_set_threshold(dev_over_temperature, CXL_SETALERT_OVER_TEMP)
+ alert_param_set_threshold(dev_under_temperature,
+ CXL_SETALERT_UNDER_TEMP)
+ alert_param_set_threshold(corrected_volatile_mem_err,
+ CXL_SETALERT_VOLATILE_MEM_ERROR)
+ alert_param_set_threshold(corrected_pmem_err, CXL_SETALERT_PMEM_ERROR)
+ if (alertctx.valid_alert_actions == 0) {
+ log_err(&ml, "No action specified\n");
+ return -EINVAL;
+ }
+
+ cmd = cxl_cmd_new_set_alert_config(memdev);
+ if (!cmd) {
+ rc = -ENXIO;
+ goto out_err;
+ }
+
+ setup_threshold_field(life_used)
+ setup_threshold_field(dev_over_temperature)
+ setup_threshold_field(dev_under_temperature)
+ setup_threshold_field(corrected_volatile_mem_err)
+ setup_threshold_field(corrected_pmem_err)
+ cxl_cmd_alert_config_set_valid_alert_actions(
+ cmd, alertctx.valid_alert_actions);
+ cxl_cmd_alert_config_set_enable_alert_actions(
+ cmd, alertctx.enable_alert_actions);
+
+ rc = cxl_cmd_submit(cmd);
+ if (rc < 0) {
+ log_err(&ml, "cmd submission failed: %s\n", strerror(-rc));
+ goto out_cmd;
+ }
+
+ rc = cxl_cmd_get_mbox_status(cmd);
+ if (rc != 0) {
+ log_err(&ml, "%s: mbox status: %d\n", __func__, rc);
+ rc = -ENXIO;
+ }
+
+out_cmd:
+ cxl_cmd_unref(cmd);
+out_err:
+ if (rc)
+ log_err(&ml, "%s error: %s\n", devname, strerror(-rc));
+
+ flags = UTIL_JSON_ALERT_CONFIG;
+ if (actx->f_out == stdout && isatty(1))
+ flags |= UTIL_JSON_HUMAN;
+ jmemdev = util_cxl_memdev_to_json(memdev, flags);
+ if (actx->jdevs && jmemdev)
+ json_object_array_add(actx->jdevs, jmemdev);
+
+ return rc;
+}
+
static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
int (*action)(struct cxl_memdev *memdev,
struct action_context *actx),
@@ -696,7 +902,7 @@ static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
}
if (action == action_setpartition || action == action_reserve_dpa ||
- action == action_free_dpa)
+ action == action_free_dpa || action == action_set_alert_config)
actx.jdevs = json_object_new_array();
if (err == argc) {
@@ -893,3 +1099,14 @@ int cmd_free_dpa(int argc, const char **argv, struct cxl_ctx *ctx)
return count >= 0 ? 0 : EXIT_FAILURE;
}
+
+int cmd_set_alert_config(int argc, const char **argv, struct cxl_ctx *ctx)
+{
+ int count = memdev_action(
+ argc, argv, ctx, action_set_alert_config, set_alert_options,
+ "cxl set-alert-config <mem0> [<mem1>..<memN>] [<options>]");
+ log_info(&ml, "set alert configuration %d mem%s\n",
+ count >= 0 ? count : 0, count > 1 ? "s" : "");
+
+ return count >= 0 ? 0 : EXIT_FAILURE;
+}
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [ndctl PATCH 2/2] cxl: add 'set-alert-config' command to cxl tool
2023-07-11 7:10 ` [ndctl PATCH 2/2] cxl: add 'set-alert-config' command to cxl tool Jehoon Park
@ 2023-07-24 22:07 ` Verma, Vishal L
2023-07-31 3:23 ` Jehoon Park
0 siblings, 1 reply; 5+ messages in thread
From: Verma, Vishal L @ 2023-07-24 22:07 UTC (permalink / raw)
To: jehoon.park@samsung.com, linux-cxl@vger.kernel.org
Cc: Jiang, Dave, Schofield, Alison, im, junhyeok, Williams, Dan J,
Weiny, Ira, bwidawsk@kernel.org, nvdimm@lists.linux.dev,
ks0204.kim@samsung.com
Hi Jehoon,
Thanks for adding this. A few minor comments below, otherwise these
look good.
On Tue, 2023-07-11 at 16:10 +0900, Jehoon Park wrote:
> Add a new command: 'set-alert-config', which configures device's warning alert
>
> usage: cxl set-alert-config <mem0> [<mem1>..<memN>] [<options>]
>
> -v, --verbose turn on debug
> -S, --serial use serial numbers to id memdevs
> -L, --life-used-threshold <threshold>
> threshold value for life used warning alert
> --life-used-alert <'on' or 'off'>
> enable or disable life used warning alert
> -O, --over-temperature-threshold <threshold>
> threshold value for device over temperature warning alert
> --over-temperature-alert <'on' or 'off'>
> enable or disable device over temperature warning alert
> -U, --under-temperature-threshold <threshold>
> threshold value for device under temperature warning alert
> --under-temperature-alert <'on' or 'off'>
> enable or disable device under temperature warning alert
> -V, --volatile-mem-err-threshold <threshold>
> threshold value for corrected volatile mem error warning alert
> --volatile-mem-err-alert <'on' or 'off'>
> enable or disable corrected volatile mem error warning alert
> -P, --pmem-err-threshold <threshold>
> threshold value for corrected pmem error warning alert
> --pmem-err-alert <'on' or 'off'>
> enable or disable corrected pmem error warning alert
No need to include the full usage text in the commit message - this is
available in the man page. Just mention and describe what functionality
is being added.
>
> Signed-off-by: Jehoon Park <jehoon.park@samsung.com>
> ---
> Documentation/cxl/cxl-set-alert-config.txt | 96 +++++++++
> Documentation/cxl/meson.build | 1 +
> cxl/builtin.h | 1 +
> cxl/cxl.c | 1 +
> cxl/memdev.c | 219 ++++++++++++++++++++-
> 5 files changed, 317 insertions(+), 1 deletion(-)
> create mode 100644 Documentation/cxl/cxl-set-alert-config.txt
>
> diff --git a/Documentation/cxl/cxl-set-alert-config.txt b/Documentation/cxl/cxl-set-alert-config.txt
> new file mode 100644
> index 0000000..a291c09
> --- /dev/null
> +++ b/Documentation/cxl/cxl-set-alert-config.txt
> @@ -0,0 +1,96 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +cxl-set-alert-config(1)
> +=======================
> +
> +NAME
> +----
> +cxl-set-alert-config - set the warning alert threshold on a CXL memdev
> +
> +SYNOPSIS
> +--------
> +[verse]
> +'cxl set-alert-config <mem0> [<mem1>..<memN>] [<options>]'
> +
> +DESCRIPTION
> +-----------
> +CXL device raises an alert when its health status is changed. Critical alert
> +shall automatically be configured by the device after a device reset.
> +If supported, programmable warning thresholds also be initialized to vendor
> +recommended defaults, then could be configured by the host.
s/host/user/ ?
>
<snip>
>
> +static int validate_alert_threshold(enum cxl_setalert_event event,
> + int threshold)
> +{
> + if (event == CXL_SETALERT_LIFE_USED) {
> + if (threshold < 0 || threshold > 100) {
> + log_err(&ml, "Invalid life used threshold: %d\n",
> + threshold);
> + return -EINVAL;
> + }
> + } else if (event == CXL_SETALERT_OVER_TEMP ||
> + event == CXL_SETALERT_UNDER_TEMP) {
> + if (threshold < SHRT_MIN || threshold > SHRT_MAX) {
> + log_err(&ml,
> + "Invalid device temperature threshold: %d\n",
> + threshold);
> + return -EINVAL;
> + }
> + } else {
> + if (threshold < 0 || threshold > USHRT_MAX) {
> + log_err(&ml,
> + "Invalid corrected mem error threshold: %d\n",
> + threshold);
> + return -EINVAL;
> + }
> + }
> + return 0;
> +}
> +
> +#define alert_param_set_threshold(arg, alert_event) \
> +{ \
> + if (!param.arg##_alert) { \
> + if (param.arg##_threshold) { \
> + log_err(&ml, "Action not specified\n"); \
> + return -EINVAL; \
> + } \
> + } else if (strncmp(param.arg##_alert, "on", 2) == 0) { \
I see that ndctl-inject-smart also does strncmp, but I'm wondering if
we should be a little more strict and use strcmp instead.
The option parser won't give us strings that are not nul-terminated, so
it should be safe, and it will avoid something awkward like
"--some-alert=onward".
Ideally we probably want a helper similar to the kernel's kstrtobool(),
which would handle all of {on,true,1,t} and different capitalization as
well, but that can be a follow on patch.
> + if (param.arg##_threshold) { \
> + char *endptr; \
> + alertctx.arg##_threshold = \
> + strtol(param.arg##_threshold, &endptr, 10); \
> + if (endptr[0] != '\0') { \
> + log_err(&ml, "Invalid threshold: %s\n", \
> + param.arg##_threshold); \
> + return -EINVAL; \
> + } \
> + rc = validate_alert_threshold( \
> + alert_event, alertctx.arg##_threshold); \
> + if (rc != 0) \
> + return rc; \
> + alertctx.valid_alert_actions |= 1 << alert_event; \
> + alertctx.enable_alert_actions |= 1 << alert_event; \
> + } else { \
> + log_err(&ml, "Threshold not specified\n"); \
> + return -EINVAL; \
> + } \
> + } else if (strncmp(param.arg##_alert, "off", 3) == 0) { \
> + if (!param.arg##_threshold) { \
> + alertctx.valid_alert_actions |= 1 << alert_event; \
> + alertctx.enable_alert_actions &= ~(1 << alert_event); \
> + } else { \
> + log_err(&ml, "Disable not require threshold\n"); \
> + return -EINVAL; \
> + } \
> + } else { \
> + log_err(&ml, "Invalid action: %s\n", param.arg##_alert); \
> + return -EINVAL; \
> + } \
> +}
> +
>
<snip>
> +int cmd_set_alert_config(int argc, const char **argv, struct cxl_ctx *ctx)
> +{
> + int count = memdev_action(
> + argc, argv, ctx, action_set_alert_config, set_alert_options,
> + "cxl set-alert-config <mem0> [<mem1>..<memN>] [<options>]");
> + log_info(&ml, "set alert configuration %d mem%s\n",
Maybe "set alert configuration for %d ..."
> + count >= 0 ? count : 0, count > 1 ? "s" : "");
> +
> + return count >= 0 ? 0 : EXIT_FAILURE;
> +}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [ndctl PATCH 2/2] cxl: add 'set-alert-config' command to cxl tool
2023-07-24 22:07 ` Verma, Vishal L
@ 2023-07-31 3:23 ` Jehoon Park
0 siblings, 0 replies; 5+ messages in thread
From: Jehoon Park @ 2023-07-31 3:23 UTC (permalink / raw)
To: Verma, Vishal L
Cc: linux-cxl@vger.kernel.org, Jiang, Dave, Schofield, Alison,
im, junhyeok, Williams, Dan J, Weiny, Ira, bwidawsk@kernel.org,
nvdimm@lists.linux.dev, ks0204.kim@samsung.com
[-- Attachment #1: Type: text/plain, Size: 9250 bytes --]
On Mon, Jul 24, 2023 at 10:07:47PM +0000, Verma, Vishal L wrote:
> Hi Jehoon,
>
> Thanks for adding this. A few minor comments below, otherwise these
> look good.
>
Hi, Vishal.
Thank you for comments. I agree with all of them, especially the use of strcmp.
I missed the awkward case you mentioned.
I'll send v2 patch soon with applying those comments.
Jehoon
> On Tue, 2023-07-11 at 16:10 +0900, Jehoon Park wrote:
> > Add a new command: 'set-alert-config', which configures device's warning alert
> >
> > usage: cxl set-alert-config <mem0> [<mem1>..<memN>] [<options>]
> >
> > -v, --verbose turn on debug
> > -S, --serial use serial numbers to id memdevs
> > -L, --life-used-threshold <threshold>
> > threshold value for life used warning alert
> > --life-used-alert <'on' or 'off'>
> > enable or disable life used warning alert
> > -O, --over-temperature-threshold <threshold>
> > threshold value for device over temperature warning alert
> > --over-temperature-alert <'on' or 'off'>
> > enable or disable device over temperature warning alert
> > -U, --under-temperature-threshold <threshold>
> > threshold value for device under temperature warning alert
> > --under-temperature-alert <'on' or 'off'>
> > enable or disable device under temperature warning alert
> > -V, --volatile-mem-err-threshold <threshold>
> > threshold value for corrected volatile mem error warning alert
> > --volatile-mem-err-alert <'on' or 'off'>
> > enable or disable corrected volatile mem error warning alert
> > -P, --pmem-err-threshold <threshold>
> > threshold value for corrected pmem error warning alert
> > --pmem-err-alert <'on' or 'off'>
> > enable or disable corrected pmem error warning alert
>
> No need to include the full usage text in the commit message - this is
> available in the man page. Just mention and describe what functionality
> is being added.
>
> >
> > Signed-off-by: Jehoon Park <jehoon.park@samsung.com>
> > ---
> > Documentation/cxl/cxl-set-alert-config.txt | 96 +++++++++
> > Documentation/cxl/meson.build | 1 +
> > cxl/builtin.h | 1 +
> > cxl/cxl.c | 1 +
> > cxl/memdev.c | 219 ++++++++++++++++++++-
> > 5 files changed, 317 insertions(+), 1 deletion(-)
> > create mode 100644 Documentation/cxl/cxl-set-alert-config.txt
> >
> > diff --git a/Documentation/cxl/cxl-set-alert-config.txt b/Documentation/cxl/cxl-set-alert-config.txt
> > new file mode 100644
> > index 0000000..a291c09
> > --- /dev/null
> > +++ b/Documentation/cxl/cxl-set-alert-config.txt
> > @@ -0,0 +1,96 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +
> > +cxl-set-alert-config(1)
> > +=======================
> > +
> > +NAME
> > +----
> > +cxl-set-alert-config - set the warning alert threshold on a CXL memdev
> > +
> > +SYNOPSIS
> > +--------
> > +[verse]
> > +'cxl set-alert-config <mem0> [<mem1>..<memN>] [<options>]'
> > +
> > +DESCRIPTION
> > +-----------
> > +CXL device raises an alert when its health status is changed. Critical alert
> > +shall automatically be configured by the device after a device reset.
> > +If supported, programmable warning thresholds also be initialized to vendor
> > +recommended defaults, then could be configured by the host.
>
> s/host/user/ ?
>
> >
> <snip>
> >
> > +static int validate_alert_threshold(enum cxl_setalert_event event,
> > + int threshold)
> > +{
> > + if (event == CXL_SETALERT_LIFE_USED) {
> > + if (threshold < 0 || threshold > 100) {
> > + log_err(&ml, "Invalid life used threshold: %d\n",
> > + threshold);
> > + return -EINVAL;
> > + }
> > + } else if (event == CXL_SETALERT_OVER_TEMP ||
> > + event == CXL_SETALERT_UNDER_TEMP) {
> > + if (threshold < SHRT_MIN || threshold > SHRT_MAX) {
> > + log_err(&ml,
> > + "Invalid device temperature threshold: %d\n",
> > + threshold);
> > + return -EINVAL;
> > + }
> > + } else {
> > + if (threshold < 0 || threshold > USHRT_MAX) {
> > + log_err(&ml,
> > + "Invalid corrected mem error threshold: %d\n",
> > + threshold);
> > + return -EINVAL;
> > + }
> > + }
> > + return 0;
> > +}
> > +
> > +#define alert_param_set_threshold(arg, alert_event) \
> > +{ \
> > + if (!param.arg##_alert) { \
> > + if (param.arg##_threshold) { \
> > + log_err(&ml, "Action not specified\n"); \
> > + return -EINVAL; \
> > + } \
> > + } else if (strncmp(param.arg##_alert, "on", 2) == 0) { \
>
> I see that ndctl-inject-smart also does strncmp, but I'm wondering if
> we should be a little more strict and use strcmp instead.
>
> The option parser won't give us strings that are not nul-terminated, so
> it should be safe, and it will avoid something awkward like
> "--some-alert=onward".
>
> Ideally we probably want a helper similar to the kernel's kstrtobool(),
> which would handle all of {on,true,1,t} and different capitalization as
> well, but that can be a follow on patch.
>
> > + if (param.arg##_threshold) { \
> > + char *endptr; \
> > + alertctx.arg##_threshold = \
> > + strtol(param.arg##_threshold, &endptr, 10); \
> > + if (endptr[0] != '\0') { \
> > + log_err(&ml, "Invalid threshold: %s\n", \
> > + param.arg##_threshold); \
> > + return -EINVAL; \
> > + } \
> > + rc = validate_alert_threshold( \
> > + alert_event, alertctx.arg##_threshold); \
> > + if (rc != 0) \
> > + return rc; \
> > + alertctx.valid_alert_actions |= 1 << alert_event; \
> > + alertctx.enable_alert_actions |= 1 << alert_event; \
> > + } else { \
> > + log_err(&ml, "Threshold not specified\n"); \
> > + return -EINVAL; \
> > + } \
> > + } else if (strncmp(param.arg##_alert, "off", 3) == 0) { \
> > + if (!param.arg##_threshold) { \
> > + alertctx.valid_alert_actions |= 1 << alert_event; \
> > + alertctx.enable_alert_actions &= ~(1 << alert_event); \
> > + } else { \
> > + log_err(&ml, "Disable not require threshold\n"); \
> > + return -EINVAL; \
> > + } \
> > + } else { \
> > + log_err(&ml, "Invalid action: %s\n", param.arg##_alert); \
> > + return -EINVAL; \
> > + } \
> > +}
> > +
> >
>
> <snip>
>
> > +int cmd_set_alert_config(int argc, const char **argv, struct cxl_ctx *ctx)
> > +{
> > + int count = memdev_action(
> > + argc, argv, ctx, action_set_alert_config, set_alert_options,
> > + "cxl set-alert-config <mem0> [<mem1>..<memN>] [<options>]");
> > + log_info(&ml, "set alert configuration %d mem%s\n",
>
> Maybe "set alert configuration for %d ..."
>
> > + count >= 0 ? count : 0, count > 1 ? "s" : "");
> > +
> > + return count >= 0 ? 0 : EXIT_FAILURE;
> > +}
>
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-07-31 3:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <CGME20230711070758epcas2p4111d4413d669a8ef6dc8862a0f4835b9@epcas2p4.samsung.com>
2023-07-11 7:10 ` [ndctl PATCH 0/2] add support for Set Alert Configuration mailbox command Jehoon Park
2023-07-11 7:10 ` [ndctl PATCH 1/2] libcxl: " Jehoon Park
2023-07-11 7:10 ` [ndctl PATCH 2/2] cxl: add 'set-alert-config' command to cxl tool Jehoon Park
2023-07-24 22:07 ` Verma, Vishal L
2023-07-31 3:23 ` Jehoon Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox