From: Alison Schofield <[email protected]>
Subject: [PATCH v5 0/5] CXL Poison List Retrieval & Tracing
Changes in v5:
- Rebase on cxl/next
- Use struct_size() to calc mbox cmd payload .min_out
- s/INTERNAL/INJECTED mocked poison record source
- Added Jonathan Reviewed-by tag on Patch 3
Link to v4:
https://lore.kernel.org/linux-cxl/[email protected]/
Add support for retrieving device poison lists and store the returned
error records as kernel trace events.
The handling of the poison list is guided by the CXL 3.0 Specification
Section 8.2.9.8.4.1. [1]
Example, triggered by memdev:
$ echo 1 > /sys/bus/cxl/devices/mem3/trigger_poison_list
cxl_poison: memdev=mem3 pcidev=cxl_mem.3 region= region_uuid=00000000-0000-0000-0000-000000000000 dpa=0x0 length=0x40 source=Internal flags= overflow_time=0
Example, triggered by region:
$ echo 1 > /sys/bus/cxl/devices/region5/trigger_poison_list
cxl_poison: memdev=mem0 pcidev=cxl_mem.0 region=region5 region_uuid=bfcb7a29-890e-4a41-8236-fe22221fc75c dpa=0x0 length=0x40 source=Internal flags= overflow_time=0
cxl_poison: memdev=mem1 pcidev=cxl_mem.1 region=region5 region_uuid=bfcb7a29-890e-4a41-8236-fe22221fc75c dpa=0x0 length=0x40 source=Internal flags= overflow_time=0
[1]: https://www.computeexpresslink.org/download-the-specification
Alison Schofield (5):
cxl/mbox: Add GET_POISON_LIST mailbox command
cxl/trace: Add TRACE support for CXL media-error records
cxl/memdev: Add trigger_poison_list sysfs attribute
cxl/region: Add trigger_poison_list sysfs attribute
tools/testing/cxl: Mock support for Get Poison List
Documentation/ABI/testing/sysfs-bus-cxl | 28 +++++++++
drivers/cxl/core/mbox.c | 78 +++++++++++++++++++++++
drivers/cxl/core/memdev.c | 45 ++++++++++++++
drivers/cxl/core/region.c | 33 ++++++++++
drivers/cxl/core/trace.h | 83 +++++++++++++++++++++++++
drivers/cxl/cxlmem.h | 69 +++++++++++++++++++-
drivers/cxl/pci.c | 4 ++
tools/testing/cxl/test/mem.c | 42 +++++++++++++
8 files changed, 381 insertions(+), 1 deletion(-)
base-commit: 589c3357370a596ef7c99c00baca8ac799fce531
--
2.37.3
From: Alison Schofield <[email protected]>
When a boolean 'true' is written to this attribute the region driver
retrieves the poison list for the capacity each device contributes
to this region. The list consists of addresses that are poisoned,
or would result in poison if accessed, and the source of the poison.
The retrieved errors are logged as kernel trace events with the
label 'cxl_poison'.
Devices not supporting the poison list capability are ignored.
Reviewed-by: Jonathan Cameron <[email protected]>
Signed-off-by: Alison Schofield <[email protected]>
---
Documentation/ABI/testing/sysfs-bus-cxl | 14 +++++++++++
drivers/cxl/core/region.c | 33 +++++++++++++++++++++++++
2 files changed, 47 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/testing/sysfs-bus-cxl
index df40ed09ea67..b715a4609718 100644
--- a/Documentation/ABI/testing/sysfs-bus-cxl
+++ b/Documentation/ABI/testing/sysfs-bus-cxl
@@ -402,3 +402,17 @@ Description:
attribute is only visible for devices supporting the
capability. The retrieved errors are logged as kernel
trace events with the label 'cxl_poison'.
+
+
+What: /sys/bus/cxl/devices/regionZ/trigger_poison_list
+Date: November, 2022
+KernelVersion: v6.2
+Contact: [email protected]
+Description:
+ (WO) When a boolean 'true' is written to this attribute the
+ region driver retrieves the poison list for the capacity
+ each device contributes to this region. The list consists
+ of addresses that are poisoned, or would result in poison
+ if accessed, and the source of the poison. The retrieved
+ errors are logged as kernel trace events with the label
+ 'cxl_poison'.
diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index 02f28da519e3..62ba9aa6bbf8 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -72,6 +72,38 @@ static int is_dup(struct device *match, void *data)
return 0;
}
+static ssize_t trigger_poison_list_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t len)
+{
+ struct cxl_region *cxlr = to_cxl_region(dev);
+ struct cxl_region_params *p = &cxlr->params;
+ struct cxl_endpoint_decoder *cxled;
+ struct cxl_memdev *cxlmd;
+ u64 offset, length;
+ int rc, i;
+ bool tmp;
+
+ if (kstrtobool(buf, &tmp))
+ return -EINVAL;
+
+ for (i = 0; i < p->nr_targets; i++) {
+ cxled = p->targets[i];
+ cxlmd = cxled_to_memdev(cxled);
+ if (!test_bit(CXL_MEM_COMMAND_ID_GET_POISON,
+ cxlmd->cxlds->enabled_cmds))
+ continue;
+
+ offset = cxl_dpa_resource_start(cxled);
+ length = cxl_dpa_size(cxled);
+ rc = cxl_mem_get_poison(cxlmd, offset, length, cxlr);
+ if (rc)
+ return rc;
+ }
+ return len;
+}
+static DEVICE_ATTR_WO(trigger_poison_list);
+
static ssize_t uuid_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t len)
{
@@ -570,6 +602,7 @@ static struct attribute *cxl_region_attrs[] = {
&dev_attr_interleave_granularity.attr,
&dev_attr_resource.attr,
&dev_attr_size.attr,
+ &dev_attr_trigger_poison_list.attr,
NULL,
};
--
2.37.3
From: Alison Schofield <[email protected]>
Make mock memdevs support the Get Poison List mailbox command.
Return a fake poison error record when the get poison list command
is issued.
This supports testing the kernel tracing and cxl list capabilities
for media errors.
Reviewed-by: Jonathan Cameron <[email protected]>
Signed-off-by: Alison Schofield <[email protected]>
---
tools/testing/cxl/test/mem.c | 42 ++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/tools/testing/cxl/test/mem.c b/tools/testing/cxl/test/mem.c
index 5e4ecd93f1d2..09dc358bb33b 100644
--- a/tools/testing/cxl/test/mem.c
+++ b/tools/testing/cxl/test/mem.c
@@ -7,6 +7,7 @@
#include <linux/delay.h>
#include <linux/sizes.h>
#include <linux/bits.h>
+#include <asm/unaligned.h>
#include <cxlmem.h>
#define LSA_SIZE SZ_128K
@@ -38,6 +39,10 @@ static struct cxl_cel_entry mock_cel[] = {
.opcode = cpu_to_le16(CXL_MBOX_OP_GET_HEALTH_INFO),
.effect = cpu_to_le16(0),
},
+ {
+ .opcode = cpu_to_le16(CXL_MBOX_OP_GET_POISON),
+ .effect = cpu_to_le16(0),
+ },
};
/* See CXL 2.0 Table 181 Get Health Info Output Payload */
@@ -141,6 +146,8 @@ static int mock_id(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
cpu_to_le64(DEV_SIZE / CXL_CAPACITY_MULTIPLIER),
};
+ put_unaligned_le24(CXL_POISON_LIST_MAX, id.poison_list_max_mer);
+
if (cmd->size_out < sizeof(id))
return -EINVAL;
@@ -558,6 +565,34 @@ static int mock_health_info(struct cxl_dev_state *cxlds,
return 0;
}
+static int mock_get_poison(struct cxl_dev_state *cxlds,
+ struct cxl_mbox_cmd *cmd)
+{
+ struct cxl_mbox_poison_payload_in *pi = cmd->payload_in;
+
+ /* Mock one poison record at pi.offset for 64 bytes */
+ struct {
+ struct cxl_mbox_poison_payload_out po;
+ struct cxl_poison_record record;
+ } mock_plist = {
+ .po = {
+ .count = cpu_to_le16(1),
+ },
+ .record = {
+ .length = cpu_to_le32(1),
+ .address = cpu_to_le64(pi->offset +
+ CXL_POISON_SOURCE_INJECTED),
+ },
+ };
+
+ if (cmd->size_out < sizeof(mock_plist))
+ return -EINVAL;
+
+ memcpy(cmd->payload_out, &mock_plist, sizeof(mock_plist));
+ cmd->size_out = sizeof(mock_plist);
+ return 0;
+}
+
static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
{
struct device *dev = cxlds->dev;
@@ -606,6 +641,9 @@ static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *
case CXL_MBOX_OP_PASSPHRASE_SECURE_ERASE:
rc = mock_passphrase_secure_erase(cxlds, cmd);
break;
+ case CXL_MBOX_OP_GET_POISON:
+ rc = mock_get_poison(cxlds, cmd);
+ break;
default:
break;
}
@@ -664,6 +702,10 @@ static int cxl_mock_mem_probe(struct platform_device *pdev)
if (rc)
return rc;
+ rc = cxl_poison_state_init(cxlds);
+ if (rc)
+ return rc;
+
rc = cxl_dev_state_identify(cxlds);
if (rc)
return rc;
--
2.37.3
From: Alison Schofield <[email protected]>
When a boolean 'true' is written to this attribute the memdev driver
retrieves the poison list from the device. The list consists of
addresses that are poisoned, or would result in poison if accessed,
and the source of the poison. This attribute is only visible for
devices supporting the capability. The retrieved errors are logged
as kernel trace events with the label 'cxl_poison'.
Reviewed-by: Jonathan Cameron <[email protected]>
Signed-off-by: Alison Schofield <[email protected]>
---
Documentation/ABI/testing/sysfs-bus-cxl | 14 ++++++++
drivers/cxl/core/memdev.c | 45 +++++++++++++++++++++++++
drivers/cxl/cxlmem.h | 2 +-
3 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/testing/sysfs-bus-cxl
index 8494ef27e8d2..df40ed09ea67 100644
--- a/Documentation/ABI/testing/sysfs-bus-cxl
+++ b/Documentation/ABI/testing/sysfs-bus-cxl
@@ -388,3 +388,17 @@ Description:
1), and checks that the hardware accepts the commit request.
Reading this value indicates whether the region is committed or
not.
+
+
+What: /sys/bus/cxl/devices/memX/trigger_poison_list
+Date: November, 2022
+KernelVersion: v6.2
+Contact: [email protected]
+Description:
+ (WO) When a boolean 'true' is written to this attribute the
+ memdev driver retrieves the poison list from the device. The
+ list consists of addresses that are poisoned, or would result
+ in poison if accessed, and the source of the poison. This
+ attribute is only visible for devices supporting the
+ capability. The retrieved errors are logged as kernel
+ trace events with the label 'cxl_poison'.
diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
index a74a93310d26..e0af7e9c9989 100644
--- a/drivers/cxl/core/memdev.c
+++ b/drivers/cxl/core/memdev.c
@@ -106,12 +106,49 @@ static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr,
}
static DEVICE_ATTR_RO(numa_node);
+static ssize_t trigger_poison_list_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t len)
+{
+ struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
+ struct cxl_dev_state *cxlds = cxlmd->cxlds;
+ u64 offset, length;
+ bool tmp;
+ int rc;
+
+ if (kstrtobool(buf, &tmp))
+ return -EINVAL;
+
+ /* CXL 3.0 Spec 8.2.9.8.4.1 Separate pmem and ram poison requests */
+ if (resource_size(&cxlds->pmem_res)) {
+ offset = cxlds->pmem_res.start;
+ length = resource_size(&cxlds->pmem_res);
+ rc = cxl_mem_get_poison(cxlmd, offset, length, NULL);
+ if (rc)
+ return rc;
+ }
+ if (resource_size(&cxlds->ram_res)) {
+ offset = cxlds->ram_res.start;
+ length = resource_size(&cxlds->ram_res);
+ rc = cxl_mem_get_poison(cxlmd, offset, length, NULL);
+ /*
+ * Invalid Physical Address is not an error for
+ * volatile addresses. Device support is optional.
+ */
+ if (rc && rc != -EFAULT)
+ return rc;
+ }
+ return len;
+}
+static DEVICE_ATTR_WO(trigger_poison_list);
+
static struct attribute *cxl_memdev_attributes[] = {
&dev_attr_serial.attr,
&dev_attr_firmware_version.attr,
&dev_attr_payload_max.attr,
&dev_attr_label_storage_size.attr,
&dev_attr_numa_node.attr,
+ &dev_attr_trigger_poison_list.attr,
NULL,
};
@@ -130,6 +167,14 @@ static umode_t cxl_memdev_visible(struct kobject *kobj, struct attribute *a,
{
if (!IS_ENABLED(CONFIG_NUMA) && a == &dev_attr_numa_node.attr)
return 0;
+
+ if (a == &dev_attr_trigger_poison_list.attr) {
+ struct device *dev = kobj_to_dev(kobj);
+
+ if (!test_bit(CXL_MEM_COMMAND_ID_GET_POISON,
+ to_cxl_memdev(dev)->cxlds->enabled_cmds))
+ return 0;
+ }
return a->mode;
}
diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h
index f53fae20f502..28ba0cd8f2d3 100644
--- a/drivers/cxl/cxlmem.h
+++ b/drivers/cxl/cxlmem.h
@@ -139,7 +139,7 @@ struct cxl_mbox_cmd {
C(FWROLLBACK, -ENXIO, "rolled back to the previous active FW"), \
C(FWRESET, -ENXIO, "FW failed to activate, needs cold reset"), \
C(HANDLE, -ENXIO, "one or more Event Record Handles were invalid"), \
- C(PADDR, -ENXIO, "physical address specified is invalid"), \
+ C(PADDR, -EFAULT, "physical address specified is invalid"), \
C(POISONLMT, -ENXIO, "poison injection limit has been reached"), \
C(MEDIAFAILURE, -ENXIO, "permanent issue with the media"), \
C(ABORT, -ENXIO, "background cmd was aborted by device"), \
--
2.37.3
From: Alison Schofield <[email protected]>
CXL devices may support the retrieval of a device poison list.
Add a new trace event that the CXL subsystem may use to log
the media-error records returned in the poison list.
Log each media-error record as a trace event of type 'cxl_poison'.
When the poison list is requested by region, include the region name
and uuid in the trace event.
Reviewed-by: Jonathan Cameron <[email protected]>
Signed-off-by: Alison Schofield <[email protected]>
---
drivers/cxl/core/mbox.c | 6 ++-
drivers/cxl/core/trace.h | 83 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 88 insertions(+), 1 deletion(-)
diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
index a38be141e108..19b0029bbe71 100644
--- a/drivers/cxl/core/mbox.c
+++ b/drivers/cxl/core/mbox.c
@@ -10,6 +10,7 @@
#include <cxl.h>
#include "core.h"
+#include "trace.h"
static bool cxl_raw_allow_all;
@@ -898,7 +899,10 @@ int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
if (rc)
break;
- /* TODO TRACE the media error records */
+ for (int i = 0; i < le16_to_cpu(po->count); i++)
+ trace_cxl_poison(cxlmd, to_pci_dev(cxlds->dev),
+ cxlr, &po->record[i], po->flags,
+ po->overflow_t);
/* Protect against an uncleared _FLAG_MORE */
nr_records = nr_records + le16_to_cpu(po->count);
diff --git a/drivers/cxl/core/trace.h b/drivers/cxl/core/trace.h
index 20ca2fe2ca8e..c7958311ce5f 100644
--- a/drivers/cxl/core/trace.h
+++ b/drivers/cxl/core/trace.h
@@ -8,6 +8,9 @@
#include <cxl.h>
#include <linux/tracepoint.h>
+#include <linux/pci.h>
+
+#include <cxlmem.h>
#define CXL_RAS_UC_CACHE_DATA_PARITY BIT(0)
#define CXL_RAS_UC_CACHE_ADDR_PARITY BIT(1)
@@ -103,6 +106,86 @@ TRACE_EVENT(cxl_aer_correctable_error,
)
);
+#define __show_poison_source(source) \
+ __print_symbolic(source, \
+ { CXL_POISON_SOURCE_UNKNOWN, "Unknown" }, \
+ { CXL_POISON_SOURCE_EXTERNAL, "External" }, \
+ { CXL_POISON_SOURCE_INTERNAL, "Internal" }, \
+ { CXL_POISON_SOURCE_INJECTED, "Injected" }, \
+ { CXL_POISON_SOURCE_VENDOR, "Vendor" })
+
+#define show_poison_source(source) \
+ (((source > CXL_POISON_SOURCE_INJECTED) && \
+ (source != CXL_POISON_SOURCE_VENDOR)) ? "Reserved" \
+ : __show_poison_source(source))
+
+#define show_poison_flags(flags) \
+ __print_flags(flags, "|", \
+ { CXL_POISON_FLAG_MORE, "More" }, \
+ { CXL_POISON_FLAG_OVERFLOW, "Overflow" }, \
+ { CXL_POISON_FLAG_SCANNING, "Scanning" })
+
+#define __cxl_poison_addr(record) \
+ (le64_to_cpu(record->address))
+#define cxl_poison_record_dpa(record) \
+ (__cxl_poison_addr(record) & CXL_POISON_START_MASK)
+#define cxl_poison_record_source(record) \
+ (__cxl_poison_addr(record) & CXL_POISON_SOURCE_MASK)
+#define cxl_poison_record_length(record) \
+ (le32_to_cpu(record->length) * CXL_POISON_LEN_MULT)
+#define cxl_poison_overflow(flags, time) \
+ (flags & CXL_POISON_FLAG_OVERFLOW ? le64_to_cpu(time) : 0)
+
+TRACE_EVENT(cxl_poison,
+
+ TP_PROTO(struct cxl_memdev *memdev, const struct pci_dev *pcidev,
+ struct cxl_region *region,
+ const struct cxl_poison_record *record,
+ u8 flags, __le64 overflow_t),
+
+ TP_ARGS(memdev, pcidev, region, record, flags, overflow_t),
+
+ TP_STRUCT__entry(
+ __string(memdev, dev_name(&memdev->dev))
+ __string(pcidev, dev_name(&pcidev->dev))
+ __string(region, region)
+ __field(u64, overflow_t)
+ __field(u64, dpa)
+ __field(u32, length)
+ __array(char, uuid, 16)
+ __field(u8, source)
+ __field(u8, flags)
+ ),
+
+ TP_fast_assign(
+ __assign_str(memdev, dev_name(&memdev->dev));
+ __assign_str(pcidev, dev_name(&pcidev->dev));
+ __entry->overflow_t = cxl_poison_overflow(flags, overflow_t);
+ __entry->dpa = cxl_poison_record_dpa(record);
+ __entry->length = cxl_poison_record_length(record);
+ __entry->source = cxl_poison_record_source(record);
+ __entry->flags = flags;
+ if (region) {
+ __assign_str(region, dev_name(®ion->dev));
+ memcpy(__entry->uuid, ®ion->params.uuid, 16);
+ } else {
+ __assign_str(region, "");
+ memset(__entry->uuid, 0, 16);
+ }
+ ),
+
+ TP_printk("memdev=%s pcidev=%s region=%s region_uuid=%pU dpa=0x%llx length=0x%x source=%s flags=%s overflow_time=%llu",
+ __get_str(memdev),
+ __get_str(pcidev),
+ __get_str(region),
+ __entry->uuid,
+ __entry->dpa,
+ __entry->length,
+ show_poison_source(__entry->source),
+ show_poison_flags(__entry->flags),
+ __entry->overflow_t)
+);
+
#endif /* _CXL_EVENTS_H */
#define TRACE_INCLUDE_FILE trace
--
2.37.3
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.0 8.2.9.8.4.1), the device returns this Poison
list as a set of Media Error Records that include the source of the
error, the starting device physical address and length. The length is
the number of adjacent DPAs in the record and is in units of 64 bytes.
Retrieve the poison list.
Reviewed-by: Jonathan Cameron <[email protected]>
Signed-off-by: Alison Schofield <[email protected]>
---
drivers/cxl/core/mbox.c | 74 +++++++++++++++++++++++++++++++++++++++++
drivers/cxl/cxlmem.h | 67 +++++++++++++++++++++++++++++++++++++
drivers/cxl/pci.c | 4 +++
3 files changed, 145 insertions(+)
diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
index b03fba212799..a38be141e108 100644
--- a/drivers/cxl/core/mbox.c
+++ b/drivers/cxl/core/mbox.c
@@ -4,7 +4,9 @@
#include <linux/security.h>
#include <linux/debugfs.h>
#include <linux/mutex.h>
+#include <asm/unaligned.h>
#include <cxlmem.h>
+#include <cxlpci.h>
#include <cxl.h>
#include "core.h"
@@ -770,6 +772,7 @@ int cxl_dev_state_identify(struct cxl_dev_state *cxlds)
/* See CXL 2.0 Table 175 Identify Memory Device Output Payload */
struct cxl_mbox_identify id;
struct cxl_mbox_cmd mbox_cmd;
+ u32 val;
int rc;
mbox_cmd = (struct cxl_mbox_cmd) {
@@ -793,6 +796,11 @@ int cxl_dev_state_identify(struct cxl_dev_state *cxlds)
cxlds->lsa_size = le32_to_cpu(id.lsa_size);
memcpy(cxlds->firmware_version, id.fw_revision, sizeof(id.fw_revision));
+ if (test_bit(CXL_MEM_COMMAND_ID_GET_POISON, cxlds->enabled_cmds)) {
+ val = get_unaligned_le24(id.poison_list_max_mer);
+ cxlds->poison.max_mer = min_t(u32, val, CXL_POISON_LIST_MAX);
+ }
+
return 0;
}
EXPORT_SYMBOL_NS_GPL(cxl_dev_state_identify, CXL);
@@ -857,6 +865,72 @@ int cxl_mem_create_range_info(struct cxl_dev_state *cxlds)
}
EXPORT_SYMBOL_NS_GPL(cxl_mem_create_range_info, CXL);
+int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
+ struct cxl_region *cxlr)
+{
+ struct cxl_dev_state *cxlds = cxlmd->cxlds;
+ struct cxl_poison_state *cxlps = &cxlds->poison;
+ struct cxl_mbox_poison_payload_out *po;
+ struct cxl_mbox_poison_payload_in pi;
+ struct cxl_mbox_cmd mbox_cmd;
+ int nr_records = 0;
+ int rc;
+
+ rc = mutex_lock_interruptible(&cxlps->getpoison_lock);
+ if (rc)
+ return rc;
+
+ po = cxlps->getpoison_po;
+ pi.offset = cpu_to_le64(offset);
+ pi.length = cpu_to_le64(len / CXL_POISON_LEN_MULT);
+
+ mbox_cmd = (struct cxl_mbox_cmd) {
+ .opcode = CXL_MBOX_OP_GET_POISON,
+ .size_in = sizeof(pi),
+ .payload_in = &pi,
+ .size_out = cxlds->payload_size,
+ .payload_out = po,
+ .min_out = struct_size(po, record, 0),
+ };
+
+ do {
+ rc = cxl_internal_send_cmd(cxlds, &mbox_cmd);
+ if (rc)
+ break;
+
+ /* TODO TRACE the media error records */
+
+ /* Protect against an uncleared _FLAG_MORE */
+ nr_records = nr_records + le16_to_cpu(po->count);
+ if (nr_records >= cxlps->max_mer) {
+ dev_dbg(&cxlmd->dev, "Max Error Records reached: %d\n",
+ nr_records);
+ break;
+ }
+ } while (po->flags & CXL_POISON_FLAG_MORE);
+
+ mutex_unlock(&cxlps->getpoison_lock);
+ return rc;
+}
+EXPORT_SYMBOL_NS_GPL(cxl_mem_get_poison, CXL);
+
+int cxl_poison_state_init(struct cxl_dev_state *cxlds)
+{
+ struct cxl_poison_state *cxlps = &cxlds->poison;
+
+ if (!test_bit(CXL_MEM_COMMAND_ID_GET_POISON, cxlds->enabled_cmds))
+ return 0;
+
+ cxlps->getpoison_po = devm_kzalloc(cxlds->dev, cxlds->payload_size,
+ GFP_KERNEL);
+ if (!cxlps->getpoison_po)
+ return -ENOMEM;
+
+ mutex_init(&cxlps->getpoison_lock);
+ return 0;
+}
+EXPORT_SYMBOL_NS_GPL(cxl_poison_state_init, CXL);
+
struct cxl_dev_state *cxl_dev_state_create(struct device *dev)
{
struct cxl_dev_state *cxlds;
diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h
index ab138004f644..f53fae20f502 100644
--- a/drivers/cxl/cxlmem.h
+++ b/drivers/cxl/cxlmem.h
@@ -193,6 +193,24 @@ struct cxl_endpoint_dvsec_info {
struct range dvsec_range[2];
};
+/**
+ * struct cxl_poison_state - Poison list retrieval
+ *
+ * @max_mer: Maximum media error records held in device cache
+ * @getpoison_po: The poison list payload returned by device
+ * @getpoison_lock: Protect reads of the poison list
+ *
+ * Reads of the poison list are synchronized to ensure that a reader
+ * does not get an incomplete list because their request overlapped
+ * (was interrupted or preceded by) another read request of the same
+ * DPA range. CXL Spec 3.0 Section 8.2.9.8.4.1
+ */
+struct cxl_poison_state {
+ u32 max_mer;
+ void *getpoison_po;
+ struct mutex getpoison_lock; /* Protect reads of poison list */
+};
+
/**
* struct cxl_dev_state - The driver device state
*
@@ -211,6 +229,7 @@ struct cxl_endpoint_dvsec_info {
* (CXL 2.0 8.2.9.5.1.1 Identify Memory Device)
* @mbox_mutex: Mutex to synchronize mailbox access.
* @firmware_version: Firmware version for the memory device.
+ * @poison: Poison list retrieval
* @enabled_cmds: Hardware commands found enabled in CEL.
* @exclusive_cmds: Commands that are kernel-internal only
* @dpa_res: Overall DPA resource tree for the device
@@ -245,6 +264,7 @@ struct cxl_dev_state {
size_t lsa_size;
struct mutex mbox_mutex; /* Protects device mailbox and firmware */
char firmware_version[0x10];
+ struct cxl_poison_state poison;
DECLARE_BITMAP(enabled_cmds, CXL_MEM_COMMAND_ID_MAX);
DECLARE_BITMAP(exclusive_cmds, CXL_MEM_COMMAND_ID_MAX);
@@ -372,6 +392,50 @@ struct cxl_mbox_set_partition_info {
#define CXL_SET_PARTITION_IMMEDIATE_FLAG BIT(0)
+/* Get Poison List CXL 3.0 Spec 8.2.9.8.4.1 */
+struct cxl_mbox_poison_payload_in {
+ __le64 offset;
+ __le64 length;
+} __packed;
+
+struct cxl_mbox_poison_payload_out {
+ u8 flags;
+ u8 rsvd1;
+ __le64 overflow_t;
+ __le16 count;
+ u8 rsvd2[20];
+ struct cxl_poison_record {
+ __le64 address;
+ __le32 length;
+ __le32 rsvd;
+ } __packed record[];
+} __packed;
+
+/*
+ * Get Poison List address field encodes the starting
+ * address of poison, and the source of the poison.
+ */
+#define CXL_POISON_START_MASK GENMASK_ULL(63, 6)
+#define CXL_POISON_SOURCE_MASK GENMASK(2, 0)
+
+/* Get Poison List record length is in units of 64 bytes */
+#define CXL_POISON_LEN_MULT 64
+
+/* Kernel defined maximum for a list of poison errors */
+#define CXL_POISON_LIST_MAX 1024
+
+/* Get Poison List: Payload out flags */
+#define CXL_POISON_FLAG_MORE BIT(0)
+#define CXL_POISON_FLAG_OVERFLOW BIT(1)
+#define CXL_POISON_FLAG_SCANNING BIT(2)
+
+/* Get Poison List: Poison Source */
+#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
+
/**
* struct cxl_mem_command - Driver representation of a memory device command
* @info: Command information as it exists for the UAPI
@@ -441,6 +505,9 @@ int cxl_mem_create_range_info(struct cxl_dev_state *cxlds);
struct cxl_dev_state *cxl_dev_state_create(struct device *dev);
void set_exclusive_cxl_commands(struct cxl_dev_state *cxlds, unsigned long *cmds);
void clear_exclusive_cxl_commands(struct cxl_dev_state *cxlds, unsigned long *cmds);
+int cxl_poison_state_init(struct cxl_dev_state *cxlds);
+int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
+ struct cxl_region *cxlr);
#ifdef CONFIG_CXL_SUSPEND
void cxl_mem_active_inc(void);
void cxl_mem_active_dec(void);
diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c
index 3a66aadb4df0..d21357f3eca0 100644
--- a/drivers/cxl/pci.c
+++ b/drivers/cxl/pci.c
@@ -482,6 +482,10 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
if (rc)
return rc;
+ rc = cxl_poison_state_init(cxlds);
+ if (rc)
+ return rc;
+
rc = cxl_dev_state_identify(cxlds);
if (rc)
return rc;
--
2.37.3
alison.schofield@ wrote:
> 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.0 8.2.9.8.4.1), the device returns this Poison
> list as a set of Media Error Records that include the source of the
> error, the starting device physical address and length. The length is
> the number of adjacent DPAs in the record and is in units of 64 bytes.
>
> Retrieve the poison list.
>
> Reviewed-by: Jonathan Cameron <[email protected]>
> Signed-off-by: Alison Schofield <[email protected]>
> ---
> drivers/cxl/core/mbox.c | 74 +++++++++++++++++++++++++++++++++++++++++
> drivers/cxl/cxlmem.h | 67 +++++++++++++++++++++++++++++++++++++
> drivers/cxl/pci.c | 4 +++
> 3 files changed, 145 insertions(+)
>
> diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
> index b03fba212799..a38be141e108 100644
> --- a/drivers/cxl/core/mbox.c
> +++ b/drivers/cxl/core/mbox.c
> @@ -4,7 +4,9 @@
> #include <linux/security.h>
> #include <linux/debugfs.h>
> #include <linux/mutex.h>
> +#include <asm/unaligned.h>
> #include <cxlmem.h>
> +#include <cxlpci.h>
> #include <cxl.h>
>
> #include "core.h"
> @@ -770,6 +772,7 @@ int cxl_dev_state_identify(struct cxl_dev_state *cxlds)
> /* See CXL 2.0 Table 175 Identify Memory Device Output Payload */
> struct cxl_mbox_identify id;
> struct cxl_mbox_cmd mbox_cmd;
> + u32 val;
> int rc;
>
> mbox_cmd = (struct cxl_mbox_cmd) {
> @@ -793,6 +796,11 @@ int cxl_dev_state_identify(struct cxl_dev_state *cxlds)
> cxlds->lsa_size = le32_to_cpu(id.lsa_size);
> memcpy(cxlds->firmware_version, id.fw_revision, sizeof(id.fw_revision));
>
> + if (test_bit(CXL_MEM_COMMAND_ID_GET_POISON, cxlds->enabled_cmds)) {
> + val = get_unaligned_le24(id.poison_list_max_mer);
> + cxlds->poison.max_mer = min_t(u32, val, CXL_POISON_LIST_MAX);
There are not many abbreviations in the subsystem, most names are
spelled out. So, s/cxlds->poison.max_mer/cxlds->poison.max_errors/, or
something like that?
> + }
> +
> return 0;
> }
> EXPORT_SYMBOL_NS_GPL(cxl_dev_state_identify, CXL);
> @@ -857,6 +865,72 @@ int cxl_mem_create_range_info(struct cxl_dev_state *cxlds)
> }
> EXPORT_SYMBOL_NS_GPL(cxl_mem_create_range_info, CXL);
>
> +int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
> + struct cxl_region *cxlr)
> +{
> + struct cxl_dev_state *cxlds = cxlmd->cxlds;
> + struct cxl_poison_state *cxlps = &cxlds->poison;
I think similar to the cxl_nvd / cxl_nvb concern that Dave raised,
@cxlds is too close to @cxlps. Just type out cxlds->poison.lock. No need
to call it getpoison_lock when it is already in 'struct
cxl_poison_state'.
> + struct cxl_mbox_poison_payload_out *po;
> + struct cxl_mbox_poison_payload_in pi;
> + struct cxl_mbox_cmd mbox_cmd;
> + int nr_records = 0;
> + int rc;
> +
> + rc = mutex_lock_interruptible(&cxlps->getpoison_lock);
> + if (rc)
> + return rc;
> +
> + po = cxlps->getpoison_po;
> + pi.offset = cpu_to_le64(offset);
> + pi.length = cpu_to_le64(len / CXL_POISON_LEN_MULT);
> +
> + mbox_cmd = (struct cxl_mbox_cmd) {
> + .opcode = CXL_MBOX_OP_GET_POISON,
> + .size_in = sizeof(pi),
> + .payload_in = &pi,
> + .size_out = cxlds->payload_size,
> + .payload_out = po,
> + .min_out = struct_size(po, record, 0),
> + };
> +
> + do {
> + rc = cxl_internal_send_cmd(cxlds, &mbox_cmd);
> + if (rc)
> + break;
> +
> + /* TODO TRACE the media error records */
> +
> + /* Protect against an uncleared _FLAG_MORE */
> + nr_records = nr_records + le16_to_cpu(po->count);
> + if (nr_records >= cxlps->max_mer) {
> + dev_dbg(&cxlmd->dev, "Max Error Records reached: %d\n",
> + nr_records);
> + break;
> + }
> + } while (po->flags & CXL_POISON_FLAG_MORE);
> +
> + mutex_unlock(&cxlps->getpoison_lock);
> + return rc;
> +}
> +EXPORT_SYMBOL_NS_GPL(cxl_mem_get_poison, CXL);
> +
> +int cxl_poison_state_init(struct cxl_dev_state *cxlds)
> +{
> + struct cxl_poison_state *cxlps = &cxlds->poison;
> +
> + if (!test_bit(CXL_MEM_COMMAND_ID_GET_POISON, cxlds->enabled_cmds))
> + return 0;
> +
> + cxlps->getpoison_po = devm_kzalloc(cxlds->dev, cxlds->payload_size,
> + GFP_KERNEL);
> + if (!cxlps->getpoison_po)
> + return -ENOMEM;
> +
> + mutex_init(&cxlps->getpoison_lock);
> + return 0;
> +}
> +EXPORT_SYMBOL_NS_GPL(cxl_poison_state_init, CXL);
> +
> struct cxl_dev_state *cxl_dev_state_create(struct device *dev)
> {
> struct cxl_dev_state *cxlds;
> diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h
> index ab138004f644..f53fae20f502 100644
> --- a/drivers/cxl/cxlmem.h
> +++ b/drivers/cxl/cxlmem.h
> @@ -193,6 +193,24 @@ struct cxl_endpoint_dvsec_info {
> struct range dvsec_range[2];
> };
>
> +/**
> + * struct cxl_poison_state - Poison list retrieval
> + *
> + * @max_mer: Maximum media error records held in device cache
> + * @getpoison_po: The poison list payload returned by device
> + * @getpoison_lock: Protect reads of the poison list
> + *
> + * Reads of the poison list are synchronized to ensure that a reader
> + * does not get an incomplete list because their request overlapped
> + * (was interrupted or preceded by) another read request of the same
> + * DPA range. CXL Spec 3.0 Section 8.2.9.8.4.1
> + */
> +struct cxl_poison_state {
> + u32 max_mer;
Suggested rename to 'max_errors' mentioned earlier.
> + void *getpoison_po;
No need for this to be named getpoison as its already prefixed by
"cxlds->poison". This can also be a specific typed data-structure
pointer, right?
> + struct mutex getpoison_lock; /* Protect reads of poison list */
Suggested rename 'lock' mentioned earlier.
> +};
> +
> /**
> * struct cxl_dev_state - The driver device state
> *
> @@ -211,6 +229,7 @@ struct cxl_endpoint_dvsec_info {
> * (CXL 2.0 8.2.9.5.1.1 Identify Memory Device)
> * @mbox_mutex: Mutex to synchronize mailbox access.
> * @firmware_version: Firmware version for the memory device.
> + * @poison: Poison list retrieval
> * @enabled_cmds: Hardware commands found enabled in CEL.
> * @exclusive_cmds: Commands that are kernel-internal only
> * @dpa_res: Overall DPA resource tree for the device
> @@ -245,6 +264,7 @@ struct cxl_dev_state {
> size_t lsa_size;
> struct mutex mbox_mutex; /* Protects device mailbox and firmware */
> char firmware_version[0x10];
> + struct cxl_poison_state poison;
> DECLARE_BITMAP(enabled_cmds, CXL_MEM_COMMAND_ID_MAX);
> DECLARE_BITMAP(exclusive_cmds, CXL_MEM_COMMAND_ID_MAX);
>
> @@ -372,6 +392,50 @@ struct cxl_mbox_set_partition_info {
>
> #define CXL_SET_PARTITION_IMMEDIATE_FLAG BIT(0)
>
> +/* Get Poison List CXL 3.0 Spec 8.2.9.8.4.1 */
> +struct cxl_mbox_poison_payload_in {
> + __le64 offset;
> + __le64 length;
> +} __packed;
> +
> +struct cxl_mbox_poison_payload_out {
> + u8 flags;
> + u8 rsvd1;
> + __le64 overflow_t;
> + __le16 count;
> + u8 rsvd2[20];
> + struct cxl_poison_record {
> + __le64 address;
> + __le32 length;
> + __le32 rsvd;
> + } __packed record[];
> +} __packed;
> +
> +/*
> + * Get Poison List address field encodes the starting
> + * address of poison, and the source of the poison.
> + */
> +#define CXL_POISON_START_MASK GENMASK_ULL(63, 6)
> +#define CXL_POISON_SOURCE_MASK GENMASK(2, 0)
> +
> +/* Get Poison List record length is in units of 64 bytes */
> +#define CXL_POISON_LEN_MULT 64
> +
> +/* Kernel defined maximum for a list of poison errors */
> +#define CXL_POISON_LIST_MAX 1024
> +
> +/* Get Poison List: Payload out flags */
> +#define CXL_POISON_FLAG_MORE BIT(0)
> +#define CXL_POISON_FLAG_OVERFLOW BIT(1)
> +#define CXL_POISON_FLAG_SCANNING BIT(2)
> +
> +/* Get Poison List: Poison Source */
> +#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
> +
> /**
> * struct cxl_mem_command - Driver representation of a memory device command
> * @info: Command information as it exists for the UAPI
> @@ -441,6 +505,9 @@ int cxl_mem_create_range_info(struct cxl_dev_state *cxlds);
> struct cxl_dev_state *cxl_dev_state_create(struct device *dev);
> void set_exclusive_cxl_commands(struct cxl_dev_state *cxlds, unsigned long *cmds);
> void clear_exclusive_cxl_commands(struct cxl_dev_state *cxlds, unsigned long *cmds);
> +int cxl_poison_state_init(struct cxl_dev_state *cxlds);
> +int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
> + struct cxl_region *cxlr);
> #ifdef CONFIG_CXL_SUSPEND
> void cxl_mem_active_inc(void);
> void cxl_mem_active_dec(void);
> diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c
> index 3a66aadb4df0..d21357f3eca0 100644
> --- a/drivers/cxl/pci.c
> +++ b/drivers/cxl/pci.c
> @@ -482,6 +482,10 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> if (rc)
> return rc;
>
> + rc = cxl_poison_state_init(cxlds);
> + if (rc)
> + return rc;
> +
> rc = cxl_dev_state_identify(cxlds);
> if (rc)
> return rc;
> --
> 2.37.3
>
alison.schofield@ wrote:
> From: Alison Schofield <[email protected]>
>
> When a boolean 'true' is written to this attribute the memdev driver
> retrieves the poison list from the device. The list consists of
> addresses that are poisoned, or would result in poison if accessed,
> and the source of the poison. This attribute is only visible for
> devices supporting the capability. The retrieved errors are logged
> as kernel trace events with the label 'cxl_poison'.
>
> Reviewed-by: Jonathan Cameron <[email protected]>
> Signed-off-by: Alison Schofield <[email protected]>
> ---
> Documentation/ABI/testing/sysfs-bus-cxl | 14 ++++++++
> drivers/cxl/core/memdev.c | 45 +++++++++++++++++++++++++
> drivers/cxl/cxlmem.h | 2 +-
> 3 files changed, 60 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/testing/sysfs-bus-cxl
> index 8494ef27e8d2..df40ed09ea67 100644
> --- a/Documentation/ABI/testing/sysfs-bus-cxl
> +++ b/Documentation/ABI/testing/sysfs-bus-cxl
> @@ -388,3 +388,17 @@ Description:
> 1), and checks that the hardware accepts the commit request.
> Reading this value indicates whether the region is committed or
> not.
> +
> +
> +What: /sys/bus/cxl/devices/memX/trigger_poison_list
> +Date: November, 2022
> +KernelVersion: v6.2
> +Contact: [email protected]
> +Description:
> + (WO) When a boolean 'true' is written to this attribute the
> + memdev driver retrieves the poison list from the device. The
> + list consists of addresses that are poisoned, or would result
> + in poison if accessed, and the source of the poison. This
> + attribute is only visible for devices supporting the
> + capability. The retrieved errors are logged as kernel
> + trace events with the label 'cxl_poison'.
> diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
> index a74a93310d26..e0af7e9c9989 100644
> --- a/drivers/cxl/core/memdev.c
> +++ b/drivers/cxl/core/memdev.c
> @@ -106,12 +106,49 @@ static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr,
> }
> static DEVICE_ATTR_RO(numa_node);
>
> +static ssize_t trigger_poison_list_store(struct device *dev,
> + struct device_attribute *attr,
> + const char *buf, size_t len)
> +{
> + struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
> + struct cxl_dev_state *cxlds = cxlmd->cxlds;
> + u64 offset, length;
> + bool tmp;
> + int rc;
> +
> + if (kstrtobool(buf, &tmp))
> + return -EINVAL;
Wait, where's the check for "if (tmp)"? Otherwise I can do "echo N >
trigger_poison_list" and it will still run. Should probably
s/tmp/trigger/.
> +
> + /* CXL 3.0 Spec 8.2.9.8.4.1 Separate pmem and ram poison requests */
> + if (resource_size(&cxlds->pmem_res)) {
> + offset = cxlds->pmem_res.start;
> + length = resource_size(&cxlds->pmem_res);
> + rc = cxl_mem_get_poison(cxlmd, offset, length, NULL);
Ah now I see why the region information is not provided in the memdev
triggers. I think while the scan needs to be done on partition boundary
basis, like you have here, I think the region lookup needs to happen on
a per-record basis.
However, that's a significant architectural change, so I am going to
think out loud about the implications.
A site operator wants to know "is FRU (field-replaceable-unit) X bad,
and if so what's the damage?". In that report I expect they want to know
if poison impacts media that is allocated to a region (an imminent
danger) or is in free space (a problem for a later date). If the memdev
trigger does all the region lookup per record it provides that
information. Further if the memdev trigger reliably provides region
information it allows the region trigger ABI to be deleted. The region
trigger can be replaced in userspace with logic that does:
set tracepoint filter to look for region_id == $region
for endpoint decoder in $region
trigger associated memdev
...so I do think the arch change is worth it, but I am willing to hear
counter arguments.
On Fri, Jan 27, 2023 at 11:42:59AM -0800, Dan Williams wrote:
> alison.schofield@ wrote:
> > From: Alison Schofield <[email protected]>
> >
> > When a boolean 'true' is written to this attribute the memdev driver
> > retrieves the poison list from the device. The list consists of
> > addresses that are poisoned, or would result in poison if accessed,
> > and the source of the poison. This attribute is only visible for
> > devices supporting the capability. The retrieved errors are logged
> > as kernel trace events with the label 'cxl_poison'.
> >
> > Reviewed-by: Jonathan Cameron <[email protected]>
> > Signed-off-by: Alison Schofield <[email protected]>
> > ---
> > Documentation/ABI/testing/sysfs-bus-cxl | 14 ++++++++
> > drivers/cxl/core/memdev.c | 45 +++++++++++++++++++++++++
> > drivers/cxl/cxlmem.h | 2 +-
> > 3 files changed, 60 insertions(+), 1 deletion(-)
> >
> > diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/testing/sysfs-bus-cxl
> > index 8494ef27e8d2..df40ed09ea67 100644
> > --- a/Documentation/ABI/testing/sysfs-bus-cxl
> > +++ b/Documentation/ABI/testing/sysfs-bus-cxl
> > @@ -388,3 +388,17 @@ Description:
> > 1), and checks that the hardware accepts the commit request.
> > Reading this value indicates whether the region is committed or
> > not.
> > +
> > +
> > +What: /sys/bus/cxl/devices/memX/trigger_poison_list
> > +Date: November, 2022
> > +KernelVersion: v6.2
> > +Contact: [email protected]
> > +Description:
> > + (WO) When a boolean 'true' is written to this attribute the
> > + memdev driver retrieves the poison list from the device. The
> > + list consists of addresses that are poisoned, or would result
> > + in poison if accessed, and the source of the poison. This
> > + attribute is only visible for devices supporting the
> > + capability. The retrieved errors are logged as kernel
> > + trace events with the label 'cxl_poison'.
> > diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
> > index a74a93310d26..e0af7e9c9989 100644
> > --- a/drivers/cxl/core/memdev.c
> > +++ b/drivers/cxl/core/memdev.c
> > @@ -106,12 +106,49 @@ static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr,
> > }
> > static DEVICE_ATTR_RO(numa_node);
> >
> > +static ssize_t trigger_poison_list_store(struct device *dev,
> > + struct device_attribute *attr,
> > + const char *buf, size_t len)
> > +{
> > + struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
> > + struct cxl_dev_state *cxlds = cxlmd->cxlds;
> > + u64 offset, length;
> > + bool tmp;
> > + int rc;
> > +
> > + if (kstrtobool(buf, &tmp))
> > + return -EINVAL;
>
> Wait, where's the check for "if (tmp)"? Otherwise I can do "echo N >
> trigger_poison_list" and it will still run. Should probably
> s/tmp/trigger/.
Got it.
(I guess I was too loose w the trigger, thinking you write anything to
it, I'm triggering.)
>
> > +
> > + /* CXL 3.0 Spec 8.2.9.8.4.1 Separate pmem and ram poison requests */
> > + if (resource_size(&cxlds->pmem_res)) {
> > + offset = cxlds->pmem_res.start;
> > + length = resource_size(&cxlds->pmem_res);
> > + rc = cxl_mem_get_poison(cxlmd, offset, length, NULL);
>
> Ah now I see why the region information is not provided in the memdev
> triggers. I think while the scan needs to be done on partition boundary
> basis, like you have here, I think the region lookup needs to happen on
> a per-record basis.
>
> However, that's a significant architectural change, so I am going to
> think out loud about the implications.
I'm thinking that adding region info to the trace event isn't starting
here. That will be looked up when we log the event. Basically assuming
assuming find regions memdev participates in, and look for which one
maps this DPA.
>
> A site operator wants to know "is FRU (field-replaceable-unit) X bad,
> and if so what's the damage?". In that report I expect they want to know
> if poison impacts media that is allocated to a region (an imminent
> danger) or is in free space (a problem for a later date). If the memdev
> trigger does all the region lookup per record it provides that
> information. Further if the memdev trigger reliably provides region
> information it allows the region trigger ABI to be deleted. The region
> trigger can be replaced in userspace with logic that does:
>
> set tracepoint filter to look for region_id == $region
> for endpoint decoder in $region
> trigger associated memdev
>
> ...so I do think the arch change is worth it, but I am willing to hear
> counter arguments.
My only counter argument was that we could let them have it both ways,
but, simplifying and reducing code in kernel is good!
alison.schofield@ wrote:
> From: Alison Schofield <[email protected]>
>
> Make mock memdevs support the Get Poison List mailbox command.
> Return a fake poison error record when the get poison list command
> is issued.
>
> This supports testing the kernel tracing and cxl list capabilities
> for media errors.
>
> Reviewed-by: Jonathan Cameron <[email protected]>
> Signed-off-by: Alison Schofield <[email protected]>
> ---
> tools/testing/cxl/test/mem.c | 42 ++++++++++++++++++++++++++++++++++++
> 1 file changed, 42 insertions(+)
>
> diff --git a/tools/testing/cxl/test/mem.c b/tools/testing/cxl/test/mem.c
> index 5e4ecd93f1d2..09dc358bb33b 100644
> --- a/tools/testing/cxl/test/mem.c
> +++ b/tools/testing/cxl/test/mem.c
> @@ -7,6 +7,7 @@
> #include <linux/delay.h>
> #include <linux/sizes.h>
> #include <linux/bits.h>
> +#include <asm/unaligned.h>
> #include <cxlmem.h>
>
> #define LSA_SIZE SZ_128K
> @@ -38,6 +39,10 @@ static struct cxl_cel_entry mock_cel[] = {
> .opcode = cpu_to_le16(CXL_MBOX_OP_GET_HEALTH_INFO),
> .effect = cpu_to_le16(0),
> },
> + {
> + .opcode = cpu_to_le16(CXL_MBOX_OP_GET_POISON),
> + .effect = cpu_to_le16(0),
> + },
> };
>
> /* See CXL 2.0 Table 181 Get Health Info Output Payload */
> @@ -141,6 +146,8 @@ static int mock_id(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
> cpu_to_le64(DEV_SIZE / CXL_CAPACITY_MULTIPLIER),
> };
>
> + put_unaligned_le24(CXL_POISON_LIST_MAX, id.poison_list_max_mer);
> +
> if (cmd->size_out < sizeof(id))
> return -EINVAL;
>
> @@ -558,6 +565,34 @@ static int mock_health_info(struct cxl_dev_state *cxlds,
> return 0;
> }
>
> +static int mock_get_poison(struct cxl_dev_state *cxlds,
> + struct cxl_mbox_cmd *cmd)
> +{
> + struct cxl_mbox_poison_payload_in *pi = cmd->payload_in;
> +
> + /* Mock one poison record at pi.offset for 64 bytes */
> + struct {
> + struct cxl_mbox_poison_payload_out po;
> + struct cxl_poison_record record;
> + } mock_plist = {
...I think this needs to be __packed as well otherwise the compiler
could inject alignment padding between these 2 packed structures.
> + .po = {
> + .count = cpu_to_le16(1),
> + },
> + .record = {
> + .length = cpu_to_le32(1),
> + .address = cpu_to_le64(pi->offset +
sparse says there is a missing le64_to_cpu(pi->offset) here
Alison Schofield wrote:
> On Fri, Jan 27, 2023 at 11:42:59AM -0800, Dan Williams wrote:
> > alison.schofield@ wrote:
> > > From: Alison Schofield <[email protected]>
> > >
> > > When a boolean 'true' is written to this attribute the memdev driver
> > > retrieves the poison list from the device. The list consists of
> > > addresses that are poisoned, or would result in poison if accessed,
> > > and the source of the poison. This attribute is only visible for
> > > devices supporting the capability. The retrieved errors are logged
> > > as kernel trace events with the label 'cxl_poison'.
> > >
> > > Reviewed-by: Jonathan Cameron <[email protected]>
> > > Signed-off-by: Alison Schofield <[email protected]>
> > > ---
> > > Documentation/ABI/testing/sysfs-bus-cxl | 14 ++++++++
> > > drivers/cxl/core/memdev.c | 45 +++++++++++++++++++++++++
> > > drivers/cxl/cxlmem.h | 2 +-
> > > 3 files changed, 60 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/testing/sysfs-bus-cxl
> > > index 8494ef27e8d2..df40ed09ea67 100644
> > > --- a/Documentation/ABI/testing/sysfs-bus-cxl
> > > +++ b/Documentation/ABI/testing/sysfs-bus-cxl
> > > @@ -388,3 +388,17 @@ Description:
> > > 1), and checks that the hardware accepts the commit request.
> > > Reading this value indicates whether the region is committed or
> > > not.
> > > +
> > > +
> > > +What: /sys/bus/cxl/devices/memX/trigger_poison_list
> > > +Date: November, 2022
> > > +KernelVersion: v6.2
> > > +Contact: [email protected]
> > > +Description:
> > > + (WO) When a boolean 'true' is written to this attribute the
> > > + memdev driver retrieves the poison list from the device. The
> > > + list consists of addresses that are poisoned, or would result
> > > + in poison if accessed, and the source of the poison. This
> > > + attribute is only visible for devices supporting the
> > > + capability. The retrieved errors are logged as kernel
> > > + trace events with the label 'cxl_poison'.
> > > diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
> > > index a74a93310d26..e0af7e9c9989 100644
> > > --- a/drivers/cxl/core/memdev.c
> > > +++ b/drivers/cxl/core/memdev.c
> > > @@ -106,12 +106,49 @@ static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr,
> > > }
> > > static DEVICE_ATTR_RO(numa_node);
> > >
> > > +static ssize_t trigger_poison_list_store(struct device *dev,
> > > + struct device_attribute *attr,
> > > + const char *buf, size_t len)
> > > +{
> > > + struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
> > > + struct cxl_dev_state *cxlds = cxlmd->cxlds;
> > > + u64 offset, length;
> > > + bool tmp;
> > > + int rc;
> > > +
> > > + if (kstrtobool(buf, &tmp))
> > > + return -EINVAL;
> >
> > Wait, where's the check for "if (tmp)"? Otherwise I can do "echo N >
> > trigger_poison_list" and it will still run. Should probably
> > s/tmp/trigger/.
>
> Got it.
> (I guess I was too loose w the trigger, thinking you write anything to
> it, I'm triggering.)
> >
> > > +
> > > + /* CXL 3.0 Spec 8.2.9.8.4.1 Separate pmem and ram poison requests */
> > > + if (resource_size(&cxlds->pmem_res)) {
> > > + offset = cxlds->pmem_res.start;
> > > + length = resource_size(&cxlds->pmem_res);
> > > + rc = cxl_mem_get_poison(cxlmd, offset, length, NULL);
> >
> > Ah now I see why the region information is not provided in the memdev
> > triggers. I think while the scan needs to be done on partition boundary
> > basis, like you have here, I think the region lookup needs to happen on
> > a per-record basis.
> >
> > However, that's a significant architectural change, so I am going to
> > think out loud about the implications.
>
> I'm thinking that adding region info to the trace event isn't starting
> here. That will be looked up when we log the event. Basically assuming
> assuming find regions memdev participates in, and look for which one
> maps this DPA.
Yup, we're on the same page. Just compare the dpa of the error record to
the dpa ranges of the enabled decoders on the memdev then it is a
straightforward cxld->region de-reference from there.
>
> >
> > A site operator wants to know "is FRU (field-replaceable-unit) X bad,
> > and if so what's the damage?". In that report I expect they want to know
> > if poison impacts media that is allocated to a region (an imminent
> > danger) or is in free space (a problem for a later date). If the memdev
> > trigger does all the region lookup per record it provides that
> > information. Further if the memdev trigger reliably provides region
> > information it allows the region trigger ABI to be deleted. The region
> > trigger can be replaced in userspace with logic that does:
> >
> > set tracepoint filter to look for region_id == $region
> > for endpoint decoder in $region
> > trigger associated memdev
> >
> > ...so I do think the arch change is worth it, but I am willing to hear
> > counter arguments.
>
> My only counter argument was that we could let them have it both ways,
> but, simplifying and reducing code in kernel is good!
Yeah, in this case I think the memdev interface is -><- that close to
being a general purpose poison lister with all the relevant info in the
record. The only thing missing after the info is populated is the filter
logic, but event filtering is a first class feature of the trace events
subsystem.
alison.schofield@ wrote:
> From: Alison Schofield <[email protected]>
>
> Subject: [PATCH v5 0/5] CXL Poison List Retrieval & Tracing
>
> Changes in v5:
> - Rebase on cxl/next
> - Use struct_size() to calc mbox cmd payload .min_out
> - s/INTERNAL/INJECTED mocked poison record source
> - Added Jonathan Reviewed-by tag on Patch 3
>
> Link to v4:
> https://lore.kernel.org/linux-cxl/[email protected]/
>
> Add support for retrieving device poison lists and store the returned
> error records as kernel trace events.
>
> The handling of the poison list is guided by the CXL 3.0 Specification
> Section 8.2.9.8.4.1. [1]
>
> Example, triggered by memdev:
> $ echo 1 > /sys/bus/cxl/devices/mem3/trigger_poison_list
> cxl_poison: memdev=mem3 pcidev=cxl_mem.3 region= region_uuid=00000000-0000-0000-0000-000000000000 dpa=0x0 length=0x40 source=Internal flags= overflow_time=0
I think the pcidev= field wants to be called something like "host" or
"parent", because there is no strict requirement that a 'struct
cxl_memdev' is related to a 'struct pci_dev'. In fact in that example
"cxl_mem.3" is a 'struct platform_device'. Now that I think about it, I
think all CXL device events should be emitting the PCIe serial number
for the memdev.
I will look in the implementation, but do region= and region_uuid= get
populated when mem3 is a member of the region?
>
> Example, triggered by region:
> $ echo 1 > /sys/bus/cxl/devices/region5/trigger_poison_list
> cxl_poison: memdev=mem0 pcidev=cxl_mem.0 region=region5 region_uuid=bfcb7a29-890e-4a41-8236-fe22221fc75c dpa=0x0 length=0x40 source=Internal flags= overflow_time=0
> cxl_poison: memdev=mem1 pcidev=cxl_mem.1 region=region5 region_uuid=bfcb7a29-890e-4a41-8236-fe22221fc75c dpa=0x0 length=0x40 source=Internal flags= overflow_time=0
>
> [1]: https://www.computeexpresslink.org/download-the-specification
>
> Alison Schofield (5):
> cxl/mbox: Add GET_POISON_LIST mailbox command
> cxl/trace: Add TRACE support for CXL media-error records
> cxl/memdev: Add trigger_poison_list sysfs attribute
> cxl/region: Add trigger_poison_list sysfs attribute
> tools/testing/cxl: Mock support for Get Poison List
>
> Documentation/ABI/testing/sysfs-bus-cxl | 28 +++++++++
> drivers/cxl/core/mbox.c | 78 +++++++++++++++++++++++
> drivers/cxl/core/memdev.c | 45 ++++++++++++++
> drivers/cxl/core/region.c | 33 ++++++++++
> drivers/cxl/core/trace.h | 83 +++++++++++++++++++++++++
> drivers/cxl/cxlmem.h | 69 +++++++++++++++++++-
> drivers/cxl/pci.c | 4 ++
> tools/testing/cxl/test/mem.c | 42 +++++++++++++
> 8 files changed, 381 insertions(+), 1 deletion(-)
>
>
> base-commit: 589c3357370a596ef7c99c00baca8ac799fce531
> --
> 2.37.3
>