Support poison list retrieval
[email protected]
maintainerv5 cover Support poison list retrieval
From: Alison Schofield <[email protected]>
Changes since v4:
- Unit test style changes based on a chatroom review with Vishal.
- Link to v4:
https://lore.kernel.org/linux-cxl/[email protected]/
Changes since v3:
- Exclude poison record where address belongs to a different region
- Add unit test case for above scenario
- Refactor unit test handling of poison record checks (Vishal)
- Address shellcheck complaints in the unit test (Vishal)
- Remove empty json fields from cxl-list man page
- Omit json "flags" field when no flags exist
- Minor flow updates in the unit test
- Link to v3:
https://lore.kernel.org/linux-cxl/[email protected]/
Begin cover letter:
Add the option to include a memory device poison list in cxl list json output. Examples appended below: by memdev, by region, by memdev and coincidentally in a region, and no poison found.
Example: By memdev
cxl list -m mem1 --poison -u
{
"memdev":"mem1",
"pmem_size":"1024.00 MiB (1073.74 MB)",
"ram_size":"1024.00 MiB (1073.74 MB)",
"serial":"0x1",
"numa_node":1,
"host":"cxl_mem.1",
"poison":{
"nr_records":4,
"records":[
{
"dpa":"0x40000000",
"dpa_length":64,
"source":"Injected",
},
{
"dpa":"0x40001000",
"dpa_length":64,
"source":"Injected",
},
{
"dpa":"0",
"dpa_length":64,
"source":"Injected",
},
{
"dpa":"0x600",
"dpa_length":64,
"source":"Injected",
}
] }
}
Example: By region
cxl list -r region5 --poison -u
{
"region":"region5",
"resource":"0xf110000000",
"size":"2.00 GiB (2.15 GB)",
"type":"pmem",
"interleave_ways":2,
"interleave_granularity":4096,
"decode_state":"commit",
"poison":{
"nr_records":2,
"records":[
{
"memdev":"mem1",
"region":"region5",
"hpa":"0xf110001000",
"dpa":"0x40000000",
"dpa_length":64,
"source":"Injected",
},
{
"memdev":"mem0",
"region":"region5",
"hpa":"0xf110000000",
"dpa":"0x40000000",
"dpa_length":64,
"source":"Injected",
}
] }
}
Example: By memdev and coincidentally in a region
# cxl list -m mem0 --poison -u
{
"memdev":"mem0",
"pmem_size":"1024.00 MiB (1073.74 MB)",
"ram_size":"1024.00 MiB (1073.74 MB)",
"serial":"0",
"numa_node":0,
"host":"cxl_mem.0",
"poison":{
"nr_records":1,
"records":[
{
"region":"region5",
"hpa":"0xf110000000",
"dpa":"0x40000000",
"dpa_length":64,
"source":"Injected",
}
]
}
}Example: No poison found
cxl list -m mem9 --poison -u
{
"memdev":"mem9",
"pmem_size":"1024.00 MiB (1073.74 MB)",
"ram_size":"1024.00 MiB (1073.74 MB)",
"serial":"0x9",
"numa_node":1,
"host":"cxl_mem.9",
"poison":{
"nr_records":0 }
}
Alison Schofield (5):
libcxl: add interfaces for GET_POISON_LIST mailbox commands
cxl: add an optional pid check to event parsing cxl/list: collect and parse the poison list records cxl/list: add --poison option to cxl list cxl/test: add cxl-poison.sh unit test
Documentation/cxl/cxl-list.txt | 58 +++++++++ cxl/event_trace.c | 5 + cxl/event_trace.h | 1 + cxl/filter.h | 3 + cxl/json.c | 211 +++++++++++++++++++++++++++++++++ cxl/lib/libcxl.c | 47 ++++++++ cxl/lib/libcxl.sym | 6 + cxl/libcxl.h | 2 + cxl/list.c | 2 + test/cxl-poison.sh | 158 ++++++++++++++++++++++++ test/meson.build | 2 + 11 files changed, 495 insertions(+) create mode 100644 test/cxl-poison.sh
base-commit: a871e6153b11fe63780b37cdcb1eb347b296095c
Signature · 1 line
2.37.3
[email protected]
maintainerPATCH v5 1/5 libcxl: add interfaces for GET_POISON_LIST mailbox commands
From: Alison Schofield <[email protected]>
CXL devices maintain a list of locations that are poisoned or result in poison if the addresses are accessed by the host.
Per the spec (CXL 3.1 8.2.9.9.4.1), the device returns the Poison List as a set of Media Error Records that include the source of the error, the starting device physical address and length.
Trigger the retrieval of the poison list by writing to the memory device sysfs attribute: trigger_poison_list. The CXL driver only offers triggering per memdev, so the trigger by region interface offered here is a convenience API that triggers a poison list retrieval for each memdev contributing to a region.
int cxl_memdev_trigger_poison_list(struct cxl_memdev *memdev); int cxl_region_trigger_poison_list(struct cxl_region *region);
The resulting poison records are logged as kernel trace events named 'cxl_poison'.
--- cxl/lib/libcxl.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ cxl/lib/libcxl.sym | 6 ++++++ cxl/libcxl.h | 2 ++ 3 files changed, 55 insertions(+)
cxl/lib/libcxl.c +47 -0
@@ -1647,6 +1647,53 @@ CXL_EXPORT int cxl_memdev_disable_invalidate(struct cxl_memdev *memdev)return 0 ; } +CXL_EXPORT int cxl_memdev_trigger_poison_list(struct cxl_memdev *memdev) +{ +struct cxl_ctx *ctx =cxl_memdev_get_ctx (memdev); +char *path = memdev->dev_buf; +int len = memdev->buf_len, rc; + +if (snprintf (path, len,"%s/trigger_poison_list" , + memdev->dev_path) >= len) { +err (ctx,"%s: buffer too small\n" , +cxl_memdev_get_devname (memdev)); +return -ENXIO ; + } + rc =sysfs_write_attr (ctx, path,"1\n" ); +if (rc <0 ) { +fprintf (stderr, +"%s: Failed write sysfs attr trigger_poison_list\n" , +cxl_memdev_get_devname (memdev)); +return rc; + } +return 0 ; +} + +CXL_EXPORT int cxl_region_trigger_poison_list(struct cxl_region *region) +{ +struct cxl_memdev_mapping *mapping; +int rc; + + cxl_mapping_foreach(region, mapping) { +struct cxl_decoder *decoder; +struct cxl_memdev *memdev; + + decoder =cxl_mapping_get_decoder (mapping); +if (!decoder) +continue ; + + memdev =cxl_decoder_get_memdev (decoder); +if (!memdev) +continue ; + + rc =cxl_memdev_trigger_poison_list (memdev); +if (rc) +return rc; + } + +return 0 ; +} + CXL_EXPORT int cxl_memdev_enable(struct cxl_memdev *memdev) {struct cxl_ctx *ctx =cxl_memdev_get_ctx (memdev);
cxl/lib/libcxl.sym +6 -0
@@ -264,3 +264,9 @@ global: cxl_memdev_update_fw; cxl_memdev_cancel_fw_update; } LIBCXL_5; + +LIBCXL_7 { +global: + cxl_memdev_trigger_poison_list; + cxl_region_trigger_poison_list; +} LIBCXL_6;
cxl/libcxl.h +2 -0
@@ -460,6 +460,8 @@ enum cxl_setpartition_mode {int cxl_cmd_partition_set_mode (struct cxl_cmd *cmd,enum cxl_setpartition_mode mode); +int cxl_memdev_trigger_poison_list (struct cxl_memdev *memdev); +int cxl_region_trigger_poison_list (struct cxl_region *region); #ifdef __cplusplus }/* extern "C" */
Signature · 1 line
2.37.3
[email protected]
maintainerPATCH v5 2/5 cxl: add an optional pid check to event parsing
In reply to [email protected]From: Alison Schofield <[email protected]>
When parsing CXL events, callers may only be interested in events that originate from the current process. Introduce an optional argument to the event trace context: event_pid. When event_pid is present, only include events with a matching pid in the returned JSON list. It is not a failure to see other, non matching results. Simply skip those.
The initial use case for this is device poison listings where only the poison error records requested by this process are wanted.
--- cxl/event_trace.c | 5 +++++ cxl/event_trace.h | 1 + 2 files changed, 6 insertions(+)
cxl/event_trace.c +5 -0
@@ -208,6 +208,11 @@ static int cxl_event_parse(struct tep_event *event, struct tep_record *record,return 0 ; } +if (event_ctx->event_pid) { +if (event_ctx->event_pid !=tep_data_pid (event->tep, record)) +return 0 ; + } +if (event_ctx->parse_event)return event_ctx->parse_event (event, record, &event_ctx->jlist_head);
cxl/event_trace.h +1 -0
@@ -15,6 +15,7 @@ struct event_ctx {const char *system;struct list_head jlist_head;const char *event_name;/* optional */ +int event_pid;/* optional */ int (*parse_event)(struct tep_event *event,struct tep_record *record,struct list_head *jlist_head);/* optional */ };
Signature · 1 line
2.37.3
[email protected]
maintainerPATCH v5 3/5 cxl/list: collect and parse the poison list records
In reply to [email protected]From: Alison Schofield <[email protected]>
Poison list records are logged as events in the kernel tracing subsystem. To prepare the poison list for cxl list, enable tracing, trigger the poison list read, and parse the generated cxl_poison events into a json representation.
--- cxl/json.c | 211 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+)
cxl/json.c +211 -0
@@ -2,15 +2,19 @@// Copyright (C) 2015-2021 Intel Corporation. All rights reserved. #include <limits.h> #include <util/json.h> +#include <util/bitmap.h> #include <uuid/uuid.h> #include <cxl/libcxl.h> #include <json-c/json.h> #include <json-c/printbuf.h> #include <ccan/short_types/short_types.h> +#include <traceevent/event-parse.h> +#include <tracefs/tracefs.h> #include "filter.h" #include "json.h" #include "../daxctl/json.h" +#include "event_trace.h" #define CXL_FW_VERSION_STR_LEN 16#define CXL_FW_MAX_SLOTS 4
@@ -571,6 +575,201 @@ err_jobj:return NULL ; } +/* CXL Spec 3.1 Table 8-140 Media Error Record */ +#define CXL_POISON_SOURCE_UNKNOWN 0 +#define CXL_POISON_SOURCE_EXTERNAL 1 +#define CXL_POISON_SOURCE_INTERNAL 2 +#define CXL_POISON_SOURCE_INJECTED 3 +#define CXL_POISON_SOURCE_VENDOR 7 + +/* CXL Spec 3.1 Table 8-139 Get Poison List Output Payload */ +#define CXL_POISON_FLAG_MORE BIT(0) +#define CXL_POISON_FLAG_OVERFLOW BIT(1) +#define CXL_POISON_FLAG_SCANNING BIT(2) + +static struct json_object * +util_cxl_poison_events_to_json (struct tracefs_instance *inst, +const char *region_name,unsigned long flags) +{ +struct json_object *jerrors, *jpoison, *jobj =NULL ; +struct jlist_node *jnode, *next; +struct event_ctx ectx = { + .event_name ="cxl_poison" , + .event_pid =getpid (), + .system ="cxl" , + }; +int rc, count =0 ; + +list_head_init (&ectx.jlist_head); + rc =cxl_parse_events (inst, &ectx); +if (rc <0 ) { +fprintf (stderr,"Failed to parse events: %d\n" , rc); +return NULL ; + } +/* Add nr_records:0 to json */ +if (list_empty (&ectx.jlist_head)) + goto out; + + jerrors =json_object_new_array (); +if (!jerrors) +return NULL ; + +list_for_each_safe (&ectx.jlist_head, jnode, next, list) { +struct json_object *jp, *jval; +int source, pflags =0 ; +u64 addr, len; + + jp =json_object_new_object (); +if (!jp) +return NULL ; + +/* Skip records not in this region when listing by region */ +if (json_object_object_get_ex (jnode->jobj,"region" , &jval)) { +const char *name; + + name =json_object_get_string (jval); +if ((region_name) && (strcmp (region_name, name) !=0 )) +continue ; + +if (strlen (name)) +json_object_object_add (jp,"region" , jval); + } + +/* Memdev name is only needed when listing by region */ +if (region_name) { +if (json_object_object_get_ex (jnode->jobj,"memdev" , + &jval)) +json_object_object_add (jp,"memdev" , jval); + } + +/* +* When listing by memdev, region names and valid HPAs +* will appear if the poisoned address is part of a region. +* Pick up those valid region names and HPAs and ignore +* any empties and invalids. +*/ + +if (json_object_object_get_ex (jnode->jobj,"hpa" , &jval)) { + addr =json_object_get_uint64 (jval); +if (addr !=ULLONG_MAX ) { + jobj =util_json_object_hex (addr, flags); +json_object_object_add (jp,"hpa" , jobj); + } + } +if (json_object_object_get_ex (jnode->jobj,"dpa" , &jval)) { + addr =json_object_get_int64 (jval); + jobj =util_json_object_hex (addr, flags); +json_object_object_add (jp,"dpa" , jobj); + } +if (json_object_object_get_ex (jnode->jobj,"dpa_length" , &jval)) { + len =json_object_get_int64 (jval); + jobj =util_json_object_size (len, flags); +json_object_object_add (jp,"dpa_length" , jobj); + } +if (json_object_object_get_ex (jnode->jobj,"source" , &jval)) { + source =json_object_get_int (jval); +switch (source) { +case CXL_POISON_SOURCE_UNKNOWN : + jobj =json_object_new_string ("Unknown" ); +break ; +case CXL_POISON_SOURCE_EXTERNAL : + jobj =json_object_new_string ("External" ); +break ; +case CXL_POISON_SOURCE_INTERNAL : + jobj =json_object_new_string ("Internal" ); +break ; +case CXL_POISON_SOURCE_INJECTED : + jobj =json_object_new_string ("Injected" ); +break ; +case CXL_POISON_SOURCE_VENDOR : + jobj =json_object_new_string ("Vendor" ); +break ; +default : + jobj =json_object_new_string ("Reserved" ); + } +json_object_object_add (jp,"source" , jobj); + } +if (json_object_object_get_ex (jnode->jobj,"flags" , &jval)) + pflags =json_object_get_int (jval); + +if (pflags) { +char flag_str[32 ] = {'\0' }; + +if (pflags &CXL_POISON_FLAG_MORE ) +strcat (flag_str,"More," ); +if (pflags &CXL_POISON_FLAG_OVERFLOW ) +strcat (flag_str,"Overflow," ); +if (pflags &CXL_POISON_FLAG_SCANNING ) +strcat (flag_str,"Scanning," ); + jobj =json_object_new_string (flag_str); +if (jobj) +json_object_object_add (jp,"flags" , jobj); + } +if (json_object_object_get_ex (jnode->jobj,"overflow_t" , &jval)) +json_object_object_add (jp,"overflow_time" , jval); + +json_object_array_add (jerrors, jp); + count++; + }/* list_for_each_safe */ + +out: + jpoison =json_object_new_object (); +if (!jpoison) +return NULL ; + +/* Always include the count. If count is zero, no records follow. */ + jobj =json_object_new_int (count); +if (jobj) +json_object_object_add (jpoison,"nr_records" , jobj); +if (count) +json_object_object_add (jpoison,"records" , jerrors); + +return jpoison; +} + +static struct json_object * +util_cxl_poison_list_to_json (struct cxl_region *region, +struct cxl_memdev *memdev, +unsigned long flags) +{ +struct json_object *jpoison =NULL ; +struct tracefs_instance *inst; +const char *region_name; +int rc; + + inst =tracefs_instance_create ("cxl list" ); +if (!inst) { +fprintf (stderr,"tracefs_instance_create() failed\n" ); +return NULL ; + } + + rc =cxl_event_tracing_enable (inst,"cxl" ,"cxl_poison" ); +if (rc <0 ) { +fprintf (stderr,"Failed to enable trace: %d\n" , rc); + goto err_free; + } + +if (region) + rc =cxl_region_trigger_poison_list (region); +else + rc =cxl_memdev_trigger_poison_list (memdev); +if (rc) + goto err_free; + + rc =cxl_event_tracing_disable (inst); +if (rc <0 ) { +fprintf (stderr,"Failed to disable trace: %d\n" , rc); + goto err_free; + } + + region_name = region ?cxl_region_get_devname (region) :NULL ; + jpoison =util_cxl_poison_events_to_json (inst, region_name, flags); + +err_free: +tracefs_instance_free (inst); +return jpoison; +} +struct json_object *util_cxl_memdev_to_json (struct cxl_memdev *memdev,unsigned long flags) {
@@ -649,6 +848,12 @@ struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,json_object_object_add (jdev,"firmware" , jobj); } +if (flags &UTIL_JSON_MEDIA_ERRORS ) { + jobj =util_cxl_poison_list_to_json (NULL , memdev, flags); +if (jobj) +json_object_object_add (jdev,"poison" , jobj); + } +json_object_set_userdata (jdev, memdev,NULL );return jdev; }
@@ -987,6 +1192,12 @@ struct json_object *util_cxl_region_to_json(struct cxl_region *region,json_object_object_add (jregion,"state" , jobj); } +if (flags &UTIL_JSON_MEDIA_ERRORS ) { + jobj =util_cxl_poison_list_to_json (region,NULL , flags); +if (jobj) +json_object_object_add (jregion,"poison" , jobj); + } +util_cxl_mappings_append_json (jregion, region, flags);if (flags &UTIL_JSON_DAX ) {
Signature · 1 line
2.37.3
[email protected]
maintainerPATCH v5 4/5 cxl/list: add --poison option to cxl list
In reply to [email protected]From: Alison Schofield <[email protected]>
The --poison option to 'cxl list' retrieves poison lists from memory devices supporting the capability and displays the returned poison records in the cxl list json. This option can apply to memdevs or regions.
Example usage in the Documentation/cxl/cxl-list.txt update.
--- Documentation/cxl/cxl-list.txt | 58 ++++++++++++++++++++++++++++++++++ cxl/filter.h | 3 ++ cxl/list.c | 2 ++ 3 files changed, 63 insertions(+)
Documentation/cxl/cxl-list.txt +58 -0
@@ -415,6 +415,64 @@ OPTIONS --region:: Specify CXL region device name(s), or device id(s), to filter the listing. +-L:: +--poison:: + Include poison information. The poison list is retrieved from the + device(s) and poison records are added to the listing. Apply this + option to memdevs and regions where devices support the poison + list capability. + +---- +# cxl list -m mem11 --poison +[ + { + "memdev":"mem11", + "pmem_size":268435456, + "ram_size":0, + "serial":0, + "host":"0000:37:00.0", + "poison":{ + "nr_records":1, + "records":[ + { + "dpa":0, + "dpa_length":64, + "source":"Internal", + } + ] + } + } +] +# cxl list -r region5 --poison +[ + { + "region":"region5", + "resource":1035623989248, + "size":2147483648, + "interleave_ways":2, + "interleave_granularity":4096, + "decode_state":"commit", + "poison":{ + "nr_records":2, + "records":[ + { + "memdev":"mem2", + "dpa":0, + "dpa_length":64, + "source":"Internal", + }, + { + "memdev":"mem5", + "dpa":0, + "length":512, + "source":"Vendor", + } + ] + } + } +] +---- + -v:: --verbose:: Increase verbosity of the output. This can be specified
cxl/filter.h +3 -0
@@ -30,6 +30,7 @@ struct cxl_filter_params {bool fw;bool alert_config;bool dax; +bool poison;int verbose;struct log_ctx ctx; };
@@ -88,6 +89,8 @@ static inline unsigned long cxl_filter_to_flags(struct cxl_filter_params *param) flags |=UTIL_JSON_ALERT_CONFIG ;if (param->dax) flags |=UTIL_JSON_DAX |UTIL_JSON_DAX_DEVS ; +if (param->poison) + flags |=UTIL_JSON_MEDIA_ERRORS ;return flags; }
cxl/list.c +2 -0
@@ -57,6 +57,8 @@ static const struct option options[] = { "include memory device firmware information"),OPT_BOOLEAN ('A' ,"alert-config" , ¶m.alert_config,"include alert configuration information" ), +OPT_BOOLEAN ('L' ,"poison" , ¶m.poison, +"include poison information " ),OPT_INCR ('v' ,"verbose" , ¶m.verbose,"increase output detail" ), #ifdef ENABLE_DEBUG OPT_BOOLEAN(0, "debug", &debug, "debug list walk"),
Signature · 1 line
2.37.3
[email protected]
maintainerPATCH v5 5/5 cxl/test: add cxl-poison.sh unit test
In reply to [email protected]From: Alison Schofield <[email protected]>
Exercise cxl list, libcxl, and driver pieces of the get poison list pathway. Inject and clear poison using debugfs and use cxl-cli to read the poison list by memdev and by region.
--- test/cxl-poison.sh | 158 +++++++++++++++++++++++++++++++++++++++++++++ test/meson.build | 2 + 2 files changed, 160 insertions(+) create mode 100644 test/cxl-poison.sh
test/cxl-poison.sh new file +158 -0
@@ -0,0 +1,158 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2023 Intel Corporation. All rights reserved. + +. "$(dirname "$0")"/common + +rc=77 + +set -ex + +trap 'err $LINENO' ERR + +check_prereq "jq" + +modprobe -r cxl_test +modprobe cxl_test + +rc=1 + +# THEORY OF OPERATION: Exercise cxl-cli and cxl driver ability to +# inject, clear, and get the poison list. Do it by memdev and by region. +# Based on current cxl-test topology. + +find_memdev() +{ + readarray -t capable_mems < <("$CXL" list -b "$CXL_TEST_BUS" -M | + jq -r ".[] | select(.pmem_size != null) | + select(.ram_size != null) | .memdev") + + if [ ${#capable_mems[@]} == 0 ]; then + echo "no memdevs found for test" + err "$LINENO" + fi + + memdev=${capable_mems[0]} +} + +create_x2_region() +{ + # Find an x2 decoder + decoder="$($CXL list -b "$CXL_TEST_BUS" -D -d root | jq -r ".[] | + select(.pmem_capable == true) | + select(.nr_targets == 2) | + .decoder")" + + # Find a memdev for each host-bridge interleave position + port_dev0="$($CXL list -T -d "$decoder" | jq -r ".[] | + .targets | .[] | select(.position == 0) | .target")" + port_dev1="$($CXL list -T -d "$decoder" | jq -r ".[] | + .targets | .[] | select(.position == 1) | .target")" + mem0="$($CXL list -M -p "$port_dev0" | jq -r ".[0].memdev")" + mem1="$($CXL list -M -p "$port_dev1" | jq -r ".[0].memdev")" + + region="$($CXL create-region -d "$decoder" -m "$mem0" "$mem1" | + jq -r ".region")" + if [[ ! $region ]]; then + echo "create-region failed for $decoder" + err "$LINENO" + fi + echo "$region" +} + +# When cxl-cli support for inject and clear arrives, replace +# the writes to /sys/kernel/debug with the new cxl commands. + +inject_poison_sysfs() +{ + memdev="$1" + addr="$2" + + echo "$addr" > /sys/kernel/debug/cxl/"$memdev"/inject_poison +} + +clear_poison_sysfs() +{ + memdev="$1" + addr="$2" + + echo "$addr" > /sys/kernel/debug/cxl/"$memdev"/clear_poison +} + +validate_region_poison() +{ + region="$1" + nr_expect="$2" + + poison_list="$($CXL list -r "$region" --poison | jq -r '.[].poison')" + + nr_found="$(jq -r ".nr_records" <<< "$poison_list")" + if [ "$nr_found" -ne "$nr_expect" ]; then + echo "$nr_expect poison records expected, $nr_found found" + err "$LINENO" + fi + + if [[ "$nr_expect" == 0 ]]; then + return + fi + + # Make sure region name format stays sane + region_found="$(jq -r ".records | .[0] | .region" <<< "$poison_list")" + if [[ "$region_found" != "$region" ]]; then + echo "$region expected, $region_found found" + err "$LINENO" + fi +} + +validate_memdev_poison() +{ + memdev="$1" + nr_expect="$2" + + nr_found="$("$CXL" list -m "$memdev" --poison | + jq -r '.[].poison.nr_records')" + if [ "$nr_found" -ne "$nr_expect" ]; then + echo "$nr_expect poison records expected, $nr_found found" + err "$LINENO" + fi +} + +test_poison_by_memdev() +{ + find_memdev + inject_poison_sysfs "$memdev" "0x40000000" + inject_poison_sysfs "$memdev" "0x40001000" + inject_poison_sysfs "$memdev" "0x600" + inject_poison_sysfs "$memdev" "0x0" + validate_memdev_poison "$memdev" 4 + + clear_poison_sysfs "$memdev" "0x40000000" + clear_poison_sysfs "$memdev" "0x40001000" + clear_poison_sysfs "$memdev" "0x600" + clear_poison_sysfs "$memdev" "0x0" + validate_memdev_poison "$memdev" 0 +} + +test_poison_by_region() +{ + create_x2_region + inject_poison_sysfs "$mem0" "0x40000000" + inject_poison_sysfs "$mem1" "0x40000000" + validate_region_poison "$region" 2 + + clear_poison_sysfs "$mem0" "0x40000000" + clear_poison_sysfs "$mem1" "0x40000000" + validate_region_poison "$region" 0 +} + +# Turn tracing on. Note that 'cxl list --poison' does toggle the tracing. +# Turning it on here allows the test user to also view inject and clear +# trace events. +echo 1 > /sys/kernel/tracing/events/cxl/cxl_poison/enable + +test_poison_by_memdev +test_poison_by_region + +check_dmesg "$LINENO" + +modprobe -r cxl-test
test/meson.build +2 -0
@@ -157,6 +157,7 @@ cxl_create_region = find_program('cxl-create-region.sh') cxl_xor_region = find_program('cxl-xor-region.sh') cxl_update_firmware = find_program('cxl-update-firmware.sh') cxl_events = find_program('cxl-events.sh') +cxl_poison = find_program('cxl-poison.sh') tests = [ [ 'libndctl', libndctl, 'ndctl' ],
@@ -186,6 +187,7 @@ tests = [ [ 'cxl-create-region.sh', cxl_create_region, 'cxl' ], [ 'cxl-xor-region.sh', cxl_xor_region, 'cxl' ], [ 'cxl-events.sh', cxl_events, 'cxl' ], + [ 'cxl-poison.sh', cxl_poison, 'cxl' ], ] if get_option('destructive').enabled()
Signature · 1 line
2.37.3
Re: [ndctl PATCH v5 4/5] cxl/list: add --poison option to cxl list
In reply to [email protected]Quoted 21 lines · alison.schofield@ wrote:
From: Alison Schofield <[email protected]>
The --poison option to 'cxl list' retrieves poison lists from memory devices supporting the capability and displays the returned poison records in the cxl list json. This option can apply to memdevs or regions.
Example usage in the
Documentation/cxl/cxl-list.txtupdate.Signed-off-by Alison Schofield <[email protected]>--- Documentation/cxl/cxl-list.txt | 58 ++++++++++++++++++++++++++++++++++ cxl/filter.h | 3 ++ cxl/list.c | 2 ++ 3 files changed, 63 insertions(+)Documentation/cxl/cxl-list.txt +0
-0
Documentation/cxl/cxl-list.txt OPTIONS · line 423
Quoted 9 lines
Documentation/cxl/cxl-list.txt +6
-0@@ -415,6 +415,64 @@ OPTIONS --region:: Specify CXL region device name(s), or device id(s), to filter the listing. +-L:: +--poison:: + Include poison information. The poison list is retrieved from the + device(s) and poison records are added to the listing. Apply this + option to memdevs and regions where devices support the poison + list capability.
While CXL calls it "poison" I am not convinced that's the term that end users can universally use for this. This is why "ndctl list" uses -M, but yeah, -M and -P are already taken. Even -E is taken for "errors".
Documentation/cxl/cxl-list.txt OPTIONS · line 436
Quoted 13 lines
Documentation/cxl/cxl-list.txt +13
-0+ +---- +# cxl list -m mem11 --poison +[ + { + "memdev":"mem11", + "pmem_size":268435456, + "ram_size":0, + "serial":0, + "host":"0000:37:00.0", + "poison":{ + "nr_records":1, + "records":[
One cleanup I want to see before this goes live... drop nr_records and just make "poison" an array object directly. The number of records is trivially determined by the jq "len" operator.
Also, per above rename "poison" to "media_errors". I believe "poison" is an x86'ism where "media_error" is a more generic term.
Quoted 15 lines
Documentation/cxl/cxl-list.txt +15
-0+ { + "dpa":0, + "dpa_length":64, + "source":"Internal", + } + ] + } + } +] +# cxl list -r region5 --poison +[ + { + "region":"region5", + "resource":1035623989248, + "size":2147483648,
Documentation/cxl/cxl-list.txt OPTIONS · line 461
Quoted 10 lines
Documentation/cxl/cxl-list.txt +10
-0+ "interleave_ways":2, + "interleave_granularity":4096, + "decode_state":"commit", + "poison":{ + "nr_records":2, + "records":[ + { + "memdev":"mem2", + "dpa":0, + "dpa_length":64,
Does length need to be prefixed with "dpa_"?
Documentation/cxl/cxl-list.txt OPTIONS · line 462
Quoted 1 line
Documentation/cxl/cxl-list.txt +1
-0+ "source":"Internal",
I am not sure what the end user can do with "source"? I have tended to not emit things if I can't think of a use case for the field to be there.
Re: [ndctl PATCH v5 3/5] cxl/list: collect and parse the poison list records
In reply to [email protected]Quoted 57 lines · alison.schofield@ wrote:
From: Alison Schofield <[email protected]>
Poison list records are logged as events in the kernel tracing subsystem. To prepare the poison list for cxl list, enable tracing, trigger the poison list read, and parse the generated
cxl_poisonevents into a json representation.Signed-off-by Alison Schofield <[email protected]>--- cxl/json.c | 211 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+)cxl/json.c +21
-0@@ -2,15 +2,19 @@// Copyright (C) 2015-2021 Intel Corporation. All rights reserved. #include <limits.h> #include <util/json.h> +#include <util/bitmap.h> #include <uuid/uuid.h> #include <cxl/libcxl.h> #include <json-c/json.h> #include <json-c/printbuf.h> #include <ccan/short_types/short_types.h> +#include <traceevent/event-parse.h> +#include <tracefs/tracefs.h> #include "filter.h" #include "json.h" #include "../daxctl/json.h" +#include "event_trace.h" #define CXL_FW_VERSION_STR_LEN 16#define CXL_FW_MAX_SLOTS 4@@ -571,6 +575,201 @@ err_jobj:return NULL ; } +/* CXL Spec 3.1 Table 8-140 Media Error Record */ +#define CXL_POISON_SOURCE_UNKNOWN 0 +#define CXL_POISON_SOURCE_EXTERNAL 1 +#define CXL_POISON_SOURCE_INTERNAL 2 +#define CXL_POISON_SOURCE_INJECTED 3 +#define CXL_POISON_SOURCE_VENDOR 7 + +/* CXL Spec 3.1 Table 8-139 Get Poison List Output Payload */ +#define CXL_POISON_FLAG_MORE BIT(0) +#define CXL_POISON_FLAG_OVERFLOW BIT(1) +#define CXL_POISON_FLAG_SCANNING BIT(2) + +static struct json_object * +util_cxl_poison_events_to_json (struct tracefs_instance *inst, +const char *region_name,unsigned long flags) +{ +struct json_object *jerrors, *jpoison, *jobj =NULL ;
cxl/json.c err_jobj: · line 604
Quoted 10 lines
cxl/json.c +10
-0+struct jlist_node *jnode, *next; +struct event_ctx ectx = { + .event_name ="cxl_poison" , + .event_pid =getpid (), + .system ="cxl" , + }; +int rc, count =0 ; + +list_head_init (&ectx.jlist_head); + rc =cxl_parse_events (inst, &ectx);
This pattern really feels like it wants a cxl_for_each_event() -style helper rather than require the end caller to open code list usage. Basically cxl_parse_events() is a helper that should stay local to cxl/monitor.c. This new cxl_for_each_event() would become used internally by cxl_parse_events() and let util_cxl_poison_events_to_json() do its own per-event iteration.
Quoted 14 lines
cxl/json.c +14
-0+if (rc <0 ) { +fprintf (stderr,"Failed to parse events: %d\n" , rc); +return NULL ; + } +/* Add nr_records:0 to json */ +if (list_empty (&ectx.jlist_head)) + goto out; + + jerrors =json_object_new_array (); +if (!jerrors) +return NULL ; + +list_for_each_safe (&ectx.jlist_head, jnode, next, list) { +struct json_object *jp, *jval;
cxl/json.c err_jobj: · line 628
Quoted 10 lines
cxl/json.c +10
-0+int source, pflags =0 ; +u64 addr, len; + + jp =json_object_new_object (); +if (!jp) +return NULL ; + +/* Skip records not in this region when listing by region */ +if (json_object_object_get_ex (jnode->jobj,"region" , &jval)) { +const char *name;
So we're building a json_object internal to cxl_parse_events() only to turn around and extract details out of that object that tell us this event was not of interest, or to create yet another json object?
I think this implementation has a chance to be significantly less complicated if the event list can be iterated directly without this temporary json_object parsing.
RE: [ndctl PATCH v5 4/5] cxl/list: add --poison option to cxl list
In reply to Dan WilliamsSome comments inline
-----Original Message-----
From: Dan Williams <[email protected]>
Sent: Wednesday, December 6, 2023 8:23 PM
To: Schofield, Alison <[email protected]>; Verma, Vishal L <[email protected]>
Cc: Schofield, Alison <[email protected]>; [email protected]; [email protected]
Subject: Re: [ndctl PATCH v5 4/5] cxl/list: add --poison option to cxl list
Quoted 22 lines · alison.schofield@ wrote:
From: Alison Schofield <[email protected]>
The --poison option to 'cxl list' retrieves poison lists from memory devices supporting the capability and displays the returned poison records in the cxl list json. This option can apply to memdevs or regions.
Example usage in the
Documentation/cxl/cxl-list.txtupdate.Signed-off-by Alison Schofield <[email protected]>--- Documentation/cxl/cxl-list.txt | 58 ++++++++++++++++++++++++++++++++++ cxl/filter.h | 3 ++ cxl/list.c | 2 ++ 3 files changed, 63 insertions(+)(quoted diff) +0
-0
b/Documentation/cxl/cxl-list.txtindex838de4086678..ee2f1b2d9fae100644
Documentation/cxl/cxl-list.txt OPTIONS · line 423
Quoted 9 lines
Documentation/cxl/cxl-list.txt +6
-0@@ -415,6 +415,64 @@ OPTIONS --region:: Specify CXL region device name(s), or device id(s), to filter the listing. +-L:: +--poison:: + Include poison information. The poison list is retrieved from the + device(s) and poison records are added to the listing. Apply this + option to memdevs and regions where devices support the poison + list capability.
While CXL calls it "poison" I am not convinced that's the term that end users can universally use for this. This is why "ndctl list" uses -M, but yeah, -M and -P are already taken. Even -E is taken for "errors".
Documentation/cxl/cxl-list.txt OPTIONS · line 436
Quoted 13 lines
Documentation/cxl/cxl-list.txt +13
-0+ +---- +# cxl list -m mem11 --poison +[ + { + "memdev":"mem11", + "pmem_size":268435456, + "ram_size":0, + "serial":0, + "host":"0000:37:00.0", + "poison":{ + "nr_records":1, + "records":[
One cleanup I want to see before this goes live... drop nr_records and just make "poison" an array object directly. The number of records is trivially determined by the jq "len" operator.
Also, per above rename "poison" to "media_errors". I believe "poison" is an x86'ism where "media_error" is a more generic term.
[ETT] The problem is that a poison can be written into CXL and is NOT a media error. Generally... the only way a customer should interpret that a DPA is "poisoned" is that if you consume that address, you'll end up in a MCA-Recovery path. It does not indicate media health. But see discussion later about "source"
Quoted 15 lines
Documentation/cxl/cxl-list.txt +15
-0+ { + "dpa":0, + "dpa_length":64, + "source":"Internal", + } + ] + } + } +] +# cxl list -r region5 --poison +[ + { + "region":"region5", + "resource":1035623989248, + "size":2147483648,
Documentation/cxl/cxl-list.txt OPTIONS · line 461
Quoted 10 lines
Documentation/cxl/cxl-list.txt +10
-0+ "interleave_ways":2, + "interleave_granularity":4096, + "decode_state":"commit", + "poison":{ + "nr_records":2, + "records":[ + { + "memdev":"mem2", + "dpa":0, + "dpa_length":64,
Does length need to be prefixed with "dpa_"?
Documentation/cxl/cxl-list.txt OPTIONS · line 462
Quoted 1 line
Documentation/cxl/cxl-list.txt +1
-0+ "source":"Internal",
I am not sure what the end user can do with "source"? I have tended to not emit things if I can't think of a use case for the field to be there. [ETT] The sources are "external" (poison written into CXL), "internal" (the device generated the poison), "injected" (ie via poison inject) and "vendor specific". This is how I would use source.
"external" = don't expect to see a cxl media error, look elsewhere like a UCNA or a mem_data error in the RP's CXL.CM RAS.
"internal" = expect to see a media error for more information.
"injected" = somebody injected the error, no service action needed except to maybe tighten up your security.
"vendor" = see vendor
How about a HPA? :D
Alison Schofield
maintainerRe: [ndctl PATCH v5 4/5] cxl/list: add --poison option to cxl list
In reply to Dan WilliamsQuoted 45 lines · Dan Williams
Quoted 21 lines · alison.schofield@ wrote:
From: Alison Schofield <[email protected]>
The --poison option to 'cxl list' retrieves poison lists from memory devices supporting the capability and displays the returned poison records in the cxl list json. This option can apply to memdevs or regions.
Example usage in the
Documentation/cxl/cxl-list.txtupdate.Signed-off-by Alison Schofield <[email protected]>--- Documentation/cxl/cxl-list.txt | 58 ++++++++++++++++++++++++++++++++++ cxl/filter.h | 3 ++ cxl/list.c | 2 ++ 3 files changed, 63 insertions(+)Documentation/cxl/cxl-list.txt +0
-0Documentation/cxl/cxl-list.txt OPTIONS · line 423
Quoted 9 lines
Documentation/cxl/cxl-list.txt +6
-0@@ -415,6 +415,64 @@ OPTIONS --region:: Specify CXL region device name(s), or device id(s), to filter the listing. +-L:: +--poison:: + Include poison information. The poison list is retrieved from the + device(s) and poison records are added to the listing. Apply this + option to memdevs and regions where devices support the poison + list capability.While CXL calls it "poison" I am not convinced that's the term that end users can universally use for this. This is why "ndctl list" uses -M, but yeah, -M and -P are already taken. Even -E is taken for "errors".
Quoted 9 lines
Documentation/cxl/cxl-list.txt +9
-0+ +---- +# cxl list -m mem11 --poison +[ + { + "memdev":"mem11", + "pmem_size":268435456, + "ram_size":0, + "serial":0,
Quoted 8 lines
Documentation/cxl/cxl-list.txt OPTIONS · line 436
Quoted 4 lines
Documentation/cxl/cxl-list.txt +4
-0+ "host":"0000:37:00.0", + "poison":{ + "nr_records":1, + "records":[One cleanup I want to see before this goes live... drop
nr_recordsand just make "poison" an array object directly. The number of records is trivially determined by the jq "len" operator.
The poison nr_records count is a convenience for the cmdline user, not for the user doing their own jq parsing. It also intends to explicitly show nr_records:0 when no poison is found.
Say NAK again and I'll rm it all.
Quoted 3 lines
Also, per above rename "poison" to "
media_errors". I believe "poison" is an x86'ism where "media_error" is a more generic term.
OK
Quoted 27 lines
Quoted 16 lines
Documentation/cxl/cxl-list.txt +15
-0+ { + "dpa":0, + "dpa_length":64, + "source":"Internal", + } + ] + } + } +] +# cxl list -r region5 --poison +[ + { + "region":"region5", + "resource":1035623989248, + "size":2147483648,Documentation/cxl/cxl-list.txt OPTIONS · line 461
Quoted 10 lines
Documentation/cxl/cxl-list.txt +10
-0+ "interleave_ways":2, + "interleave_granularity":4096, + "decode_state":"commit", + "poison":{ + "nr_records":2, + "records":[ + { + "memdev":"mem2", + "dpa":0, + "dpa_length":64,
Quoted 2 lines
Does length need to be prefixed with "
dpa_"?
Nope. Will remove.
Quoted 5 lines
Documentation/cxl/cxl-list.txt OPTIONS · line 462
Quoted 1 line
Documentation/cxl/cxl-list.txt +1
-0+ "source":"Internal",I am not sure what the end user can do with "source"? I have tended to not emit things if I can't think of a use case for the field to be there.
Erwin followed w a comment on this one. Yeah, I think folks want to know if error was injected at least.
Alison
Alison Schofield
maintainerRe: [ndctl PATCH v5 3/5] cxl/list: collect and parse the poison list records
In reply to Dan WilliamsQuoted 3 lines · Dan Williams
Quoted 2 lines · alison.schofield@ wrote:
From: Alison Schofield <[email protected]>
snip
Quoted 10 lines
Quoted 10 lines
cxl/json.c +10
-0+struct json_object *jerrors, *jpoison, *jobj =NULL ; +struct jlist_node *jnode, *next; +struct event_ctx ectx = { + .event_name ="cxl_poison" , + .event_pid =getpid (), + .system ="cxl" , + }; +int rc, count =0 ; + +list_head_init (&ectx.jlist_head);
Quoted 9 lines
cxl/json.c err_jobj: · line 604
Quoted 1 line
cxl/json.c +1
-0+ rc =cxl_parse_events (inst, &ectx);This pattern really feels like it wants a
cxl_for_each_event()-style helper rather than require the end caller to open code list usage. Basicallycxl_parse_events()is a helper that should stay local tocxl/monitor.c. This newcxl_for_each_event()would become used internally bycxl_parse_events()and letutil_cxl_poison_events_to_json()do its own per-event iteration.
snip & concat'ing your next comment:
Quoted 7 lines
So we're building a
json_objectinternal tocxl_parse_events()only to turn around and extract details out of that object that tell us this event was not of interest, or to create yet another json object?I think this implementation has a chance to be significantly less complicated if the event list can be iterated directly without this temporary
json_objectparsing.
DaveJ actually already implemented a method to include a 'private' parsing function in the event_ctx structure. I didn't use it, but but rather used the generic cxl_event_to_json helper, and then parsed that all over again to refine for poison list output.
I think reorganizing w a private event_ctx->parse_event will streamline as you suggest.
Alison