Skip to contentSkip to conversation

CXL Poison List Retrieval & Tracing

PATCH Superseded [email protected] 3 participants 22 messages Nov 11, 2022 – Dec 8, 2022

Subsystems (2)

v3 of 13 Superseded Latest is v13 →

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

v3 cover CXL Poison List Retrieval & Tracing

From: Alison Schofield <[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

Changes in v3:
- Rebase to 6.1-rc4
- Rebase picked up cxl_dpa_resource_start() (Jonathan)
- Move poison source defines to cxlmem.h from events/cxl.h
- TRACE_printk helper macros display 'Reserved' for illegal poison sources rather than failing to parse.
- Add region uuid to the trace event.
- Always get poison, but only parse records if tracing is enabled.(Steve) There was a little foresight on not moving the calcs to the event definition itself, as Steve also suggested. The DPA->HPA translation is coming, and that work seems better kept in the driver itself.
- Remove unused hpa trace field. Add back when hpa is available.
- Remove pid from cxl_poison event. Find in common event field. (Steve)
- cxl_test: Add mock support for get poison

Changes in v2:
- Added per region poison collection
- Protect poison list w mutex
- Replace range usage w resource
- S/poison_max_mer/poison_max in cxl_dev_state kdoc (Ira)
- Renamed sysfs attribute to 'trigger_poison_list'
- _store() rm chatty dev_err() msgs (Jonathan, Dan)
- _store() use kstrtobool (Jonathan, Dan)
- _store() simplify return (Jonathan)
- cxl_memdev_visible() skip local vars on way enabled_cmds (Jonathan)
- cxl_memdev_visible() use kobj_to_dev() helper (Dan)
- Misc name shortenings and cleanups.
- Replace goto w break in cxl_mem_get_poison() do-while loop.
- Don't error out on FLAGS, record in trace event.
- Add kernel CXL_POISON__LIST_MAX (64) and guard against exceeding (Dan)
- Add current->pid to trace (Dan)
- Return the poison length as multiple of 64 per spec (Jonathan)
- Mask starting address from record->address (Jonathan)
- Move range selection to sysfs_store and make cxl_mem_get_poison() accept it.
- Get both the volatile & persistent ranges per memdev.
- Add pci device name to trace (Dan)

[1]: https://www.computeexpresslink.org/download-the-specification

Alison Schofield (6):
trace, cxl: Introduce a TRACE_EVENT for CXL poison records cxl/mbox: Add GET_POISON_LIST mailbox command cxl/memdev: Add trigger_poison_list sysfs attribute cxl/region: Add trigger_poison_list sysfs attribute tools/testing/cxl: Mock the max err records field of Identify cmd tools/testing/cxl: Mock the Get Poison List mbox command

 Documentation/ABI/testing/sysfs-bus-cxl | 28 +++++++++
 drivers/cxl/core/mbox.c                 | 81 +++++++++++++++++++++++++
 drivers/cxl/core/memdev.c               | 41 +++++++++++++
 drivers/cxl/core/region.c               | 33 ++++++++++
 drivers/cxl/cxlmem.h                    | 51 ++++++++++++++++
 include/trace/events/cxl.h              | 80 ++++++++++++++++++++++++
 tools/testing/cxl/test/mem.c            | 35 +++++++++++
 7 files changed, 349 insertions(+)
 create mode 100644 include/trace/events/cxl.h

base-commit: f0c4d9fc9cc9462659728d168387191387e903cc

Signature · 1 line
2.37.3
author maintainer
#1 lore raw

PATCH v3 1/6 trace, cxl: Introduce a TRACE_EVENT for CXL poison records

From: Alison Schofield <[email protected]>

CXL devices may support the retrieval of a device poison list. Introduce a trace event that the CXL subsystem can use to log the poison error records.

---
 drivers/cxl/cxlmem.h       | 14 +++++++
 include/trace/events/cxl.h | 80 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 94 insertions(+)
 create mode 100644 include/trace/events/cxl.h
drivers/cxl/cxlmem.h +14 -0
index 88e3a8e54b6a..669868cc1553 100644
@@ -347,6 +347,20 @@ 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 */
+
+/* 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
include/trace/events/cxl.h new file +80 -0

80 lines not on this page · raw message

Signature · 1 line
2.37.3
Reviewed-by on v3 1/6
#2 lore raw

Re: [PATCH v3 1/6] trace, cxl: Introduce a TRACE_EVENT for CXL poison records

Quoted 7 lines · On Thu, 10 Nov 2022 19:12:39 -0800 [email protected] wrote:

From: Alison Schofield <[email protected]>

CXL devices may support the retrieval of a device poison list. Introduce a trace event that the CXL subsystem can use to log the poison error records.

Only thing I wondered a bit about in here is the philosophy of whether it is useful to include the pcidev and region given they can both be established fairly easily via other paths.. Meh. Seems reasonable to me to have the in here so.

Quoted 117 lines
---
 drivers/cxl/cxlmem.h       | 14 +++++++
 include/trace/events/cxl.h | 80 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 94 insertions(+)
 create mode 100644 include/trace/events/cxl.h
drivers/cxl/cxlmem.h +14 -0
index 88e3a8e54b6a..669868cc1553 100644
@@ -347,6 +347,20 @@ 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 */
+
+/* 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
include/trace/events/cxl.h new file +80 -0
new file mode 100644
index 000000000000..03428125573f
@@ -0,0 +1,80 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM cxl
+
+#if !defined(_CXL_TRACE_H) ||  defined(TRACE_HEADER_MULTI_READ)
+#define _CXL_TRACE_H
+
+#include <linux/tracepoint.h>
+#include <cxlmem.h>
+
+#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"  })
+
+TRACE_EVENT(cxl_poison,
+
+	    TP_PROTO(const char *memdev, const char *pcidev, const char *region,
+		     const uuid_t *uuid, u64 dpa, u32 length, u8 source,
+		     u8 flags, u64 overflow_t),
+
+	    TP_ARGS(memdev, pcidev, region, uuid, dpa, length, source,
+		    flags, overflow_t),
+
+	    TP_STRUCT__entry(
+		__string(memdev, memdev)
+		__string(pcidev, pcidev)
+		__string(region, region ? region : "")
+		__array(char, uuid, 16)
+		__field(u64, dpa)
+		__field(u32, length)
+		__field(u8, source)
+		__field(u8, flags)
+		__field(u64, overflow_t)
+	    ),
+
+	    TP_fast_assign(
+		__assign_str(memdev, memdev);
+		__assign_str(pcidev, pcidev);
+		__assign_str(region, region ? region : "");
+		if (uuid)
+			memcpy(__entry->uuid, uuid, 16);
+		__entry->dpa = dpa;
+		__entry->length = length;
+		__entry->source = source;
+		__entry->flags = flags;
+		__entry->overflow_t = overflow_t;
+	    ),
+
+	    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_TRACE_H */
+
+/* This part must be outside protection */
+#undef TRACE_INCLUDE_FILE
+#define TRACE_INCLUDE_FILE cxl
+#include <trace/define_trace.h>
#3 lore raw

RE: [PATCH v3 1/6] trace, cxl: Introduce a TRACE_EVENT for CXL poison records

In reply to [email protected]
Quoted 66 lines · alison.schofield@ wrote:

From: Alison Schofield <[email protected]>

CXL devices may support the retrieval of a device poison list. Introduce a trace event that the CXL subsystem can use to log the poison error records.

---
 drivers/cxl/cxlmem.h       | 14 +++++++
 include/trace/events/cxl.h | 80 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 94 insertions(+)
 create mode 100644 include/trace/events/cxl.h
drivers/cxl/cxlmem.h +14 -0
index 88e3a8e54b6a..669868cc1553 100644
@@ -347,6 +347,20 @@ 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 */
+
+/* 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
include/trace/events/cxl.h new file +22 -0
new file mode 100644
index 000000000000..03428125573f
@@ -0,0 +1,80 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM cxl
+
+#if !defined(_CXL_TRACE_H) ||  defined(TRACE_HEADER_MULTI_READ)
+#define _CXL_TRACE_H
+
+#include <linux/tracepoint.h>
+#include <cxlmem.h>
+
+#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))

include/trace/events/cxl.h line 32

Quoted 10 lines
include/trace/events/cxl.h new file +10 -0
+
+#define show_poison_flags(flags)                             \
+	__print_flags(flags, "|",                            \
+		{ CXL_POISON_FLAG_MORE,      "More"     },   \
+		{ CXL_POISON_FLAG_OVERFLOW,  "Overflow"  },  \
+		{ CXL_POISON_FLAG_SCANNING,  "Scanning"  })
+
+TRACE_EVENT(cxl_poison,
+
+	    TP_PROTO(const char *memdev, const char *pcidev, const char *region,

Same feedback as on the Events patch, make these arguments a 'struct device *', 'struct pci_dev *', and 'struct cxl_region *' to maximize type-safety. Otherwise you could do something like pass "region0", "mem1", and "0000:64:09.0" in the wrong order and the compiler cannot help prevent that.

Quoted 51 lines
include/trace/events/cxl.h new file +48 -0
+		     const uuid_t *uuid, u64 dpa, u32 length, u8 source,
+		     u8 flags, u64 overflow_t),
+
+	    TP_ARGS(memdev, pcidev, region, uuid, dpa, length, source,
+		    flags, overflow_t),
+
+	    TP_STRUCT__entry(
+		__string(memdev, memdev)
+		__string(pcidev, pcidev)
+		__string(region, region ? region : "")
+		__array(char, uuid, 16)
+		__field(u64, dpa)
+		__field(u32, length)
+		__field(u8, source)
+		__field(u8, flags)
+		__field(u64, overflow_t)
+	    ),
+
+	    TP_fast_assign(
+		__assign_str(memdev, memdev);
+		__assign_str(pcidev, pcidev);
+		__assign_str(region, region ? region : "");
+		if (uuid)
+			memcpy(__entry->uuid, uuid, 16);
+		__entry->dpa = dpa;
+		__entry->length = length;
+		__entry->source = source;
+		__entry->flags = flags;
+		__entry->overflow_t = overflow_t;
+	    ),
+
+	    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_TRACE_H */
+
+/* This part must be outside protection */
+#undef TRACE_INCLUDE_FILE
+#define TRACE_INCLUDE_FILE cxl
+#include <trace/define_trace.h>
Signature · 1 line
2.37.3
author maintainer
#4 lore raw

PATCH v3 2/6 cxl/mbox: Add GET_POISON_LIST mailbox command

In reply to [email protected]

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 list and 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.

---
 drivers/cxl/core/mbox.c | 81 +++++++++++++++++++++++++++++++++++++++++
 drivers/cxl/cxlmem.h    | 37 +++++++++++++++++++
 2 files changed, 118 insertions(+)
drivers/cxl/core/mbox.c +81 -0
index 0c90f13870a4..88f034e97812 100644
@@ -9,6 +9,9 @@
 
 #include "core.h"
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/cxl.h>
+
 static bool cxl_raw_allow_all;
 
 /**
@@ -752,6 +755,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;
+	__le32 val = 0;
 	int rc;
 
 	rc = cxl_mbox_send_cmd(cxlds, CXL_MBOX_OP_IDENTIFY, NULL, 0, &id,
@@ -771,6 +775,9 @@ 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));
 
+	memcpy(&val, id.poison_list_max_mer, 3);
+	cxlds->poison_max = min_t(u32, le32_to_cpu(val), CXL_POISON_LIST_MAX);
+
 	return 0;
 }
 EXPORT_SYMBOL_NS_GPL(cxl_dev_state_identify, CXL);
@@ -835,6 +842,79 @@ int cxl_mem_create_range_info(struct cxl_dev_state *cxlds)
 }
 EXPORT_SYMBOL_NS_GPL(cxl_mem_create_range_info, CXL);
 
+static void cxl_trace_poison(struct cxl_mbox_poison_payload_out *po,
+			     struct cxl_region *cxlr,
+			     const char *memdev_name,
+			     const char *pcidev_name)
+{
+	const char *region_name = cxlr ? dev_name(&cxlr->dev) : NULL;
+	struct cxl_region_params *p = cxlr ? &cxlr->params : NULL;
+	uuid_t *uuid = p ? &p->uuid : NULL;
+	u64 addr, dpa, overflow_t = 0;
+	u8 source;
+	u32 len;
+
+	if (po->flags & CXL_POISON_FLAG_OVERFLOW)
+		overflow_t = le64_to_cpu(po->overflow_timestamp);
+
+	for (int i = 0; i < le16_to_cpu(po->count); i++) {
+		len = le32_to_cpu(po->record[i].length) * CXL_POISON_LEN_MULT;
+		addr = le64_to_cpu(po->record[i].address);
+		source = addr & CXL_POISON_SOURCE_MASK;
+		dpa = addr & CXL_POISON_START_MASK;
+
+		trace_cxl_poison(memdev_name, pcidev_name, region_name, uuid,
+				 dpa, len, source, po->flags, overflow_t);
+	}
+}
+
+int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
+		       struct cxl_region *cxlr)
+{
+	struct cxl_dev_state *cxlds = cxlmd->cxlds;
+	const char *memdev_name = dev_name(&cxlmd->dev);
+	const char *pcidev_name = dev_name(cxlds->dev);
+	struct cxl_mbox_poison_payload_out *po;
+	struct cxl_mbox_poison_payload_in pi;
+	int nr_records = 0;
+	int rc;
+
+	po = kvmalloc(cxlds->payload_size, GFP_KERNEL);
+	if (!po)
+		return -ENOMEM;
+
+	pi.offset = cpu_to_le64(offset);
+	pi.length = cpu_to_le64(len);
+
+	rc = mutex_lock_interruptible(&cxlds->poison_list_mutex);
+	if (rc)
+		goto out;
+
+	do {
+		rc = cxl_mbox_send_cmd(cxlds, CXL_MBOX_OP_GET_POISON, &pi,
+				       sizeof(pi), po, cxlds->payload_size);
+		if (rc)
+			break;
+
+		if (trace_cxl_poison_enabled())
+			cxl_trace_poison(po, cxlr, memdev_name, pcidev_name);
+
+		/* Protect against an uncleared _FLAG_MORE */
+		nr_records = nr_records + le16_to_cpu(po->count);
+		if (nr_records >= cxlds->poison_max) {
+			dev_dbg(&cxlmd->dev, "Max Error Records reached: %d\n",
+				nr_records);
+			break;
+		}
+	} while (po->flags & CXL_POISON_FLAG_MORE);
+
+	mutex_unlock(&cxlds->poison_list_mutex);
+out:
+	kvfree(po);
+	return rc;
+}
+EXPORT_SYMBOL_NS_GPL(cxl_mem_get_poison, CXL);
+
 struct cxl_dev_state *cxl_dev_state_create(struct device *dev)
 {
 	struct cxl_dev_state *cxlds;
@@ -846,6 +926,7 @@ struct cxl_dev_state *cxl_dev_state_create(struct device *dev)
 	}
 
 	mutex_init(&cxlds->mbox_mutex);
+	mutex_init(&cxlds->poison_list_mutex);
 	cxlds->dev = dev;
 
 	return cxlds;
drivers/cxl/cxlmem.h +37 -0
index 669868cc1553..49d891347e39 100644
@@ -192,6 +192,8 @@ struct cxl_endpoint_dvsec_info {
  *                (CXL 2.0 8.2.8.4.3 Mailbox Capabilities Register)
  * @lsa_size: Size of Label Storage Area
  *                (CXL 2.0 8.2.9.5.1.1 Identify Memory Device)
+ * @poison_max: maximum media error records held in device cache
+ * @poison_list_mutex: Mutex to synchronize poison list retrieval
  * @mbox_mutex: Mutex to synchronize mailbox access.
  * @firmware_version: Firmware version for the memory device.
  * @enabled_cmds: Hardware commands found enabled in CEL.
@@ -224,6 +226,8 @@ struct cxl_dev_state {
 
 	size_t payload_size;
 	size_t lsa_size;
+	u32 poison_max;
+	struct mutex poison_list_mutex;  /* Protect reads of poison list */
 	struct mutex mbox_mutex; /* Protects device mailbox and firmware */
 	char firmware_version[0x10];
 	DECLARE_BITMAP(enabled_cmds, CXL_MEM_COMMAND_ID_MAX);
@@ -349,6 +353,37 @@ struct cxl_mbox_set_partition_info {
 
 /* 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_timestamp;
+	__le16 count;
+	u8 rsvd2[0x14];
+	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)
@@ -395,6 +430,8 @@ 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_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);
Signature · 1 line
2.37.3
#5 lore raw

Re: [PATCH v3 2/6] cxl/mbox: Add GET_POISON_LIST mailbox command

Quoted 10 lines · On Thu, 10 Nov 2022 19:12:40 -0800 [email protected] 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.

Quoted 7 lines

Retrieve the list and 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.

Hi Alison,

I've forgotten most of previous discussions around versions of this series so I may well repeat things that were covered earlier!

A few things inline.

Thanks,

Jonathan

Quoted 28 lines
---
 drivers/cxl/core/mbox.c | 81 +++++++++++++++++++++++++++++++++++++++++
 drivers/cxl/cxlmem.h    | 37 +++++++++++++++++++
 2 files changed, 118 insertions(+)
drivers/cxl/core/mbox.c +4 -0
index 0c90f13870a4..88f034e97812 100644
@@ -9,6 +9,9 @@
 
 #include "core.h"
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/cxl.h>
+
 static bool cxl_raw_allow_all;
 
 /**
@@ -752,6 +755,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;
+	__le32 val = 0;
 	int rc;
 
 	rc = cxl_mbox_send_cmd(cxlds, CXL_MBOX_OP_IDENTIFY, NULL, 0, &id,

drivers/cxl/core/mbox.c int cxl_dev_state_identify(struct cxl_dev_state *cxlds) · line 778

Quoted 4 lines
drivers/cxl/core/mbox.c +1 -0
@@ -771,6 +775,9 @@ 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));
 
+	memcpy(&val, id.poison_list_max_mer, 3);

This is ugly. I've lost track of last discussion about get_unaligned_le24() and using it on elements of a packed structure. At very least can we do a memcpy to a u8[3] array and then use get_unaligned_le24() on that if we can't use it directly on the structure element?

Quoted 6 lines
drivers/cxl/core/mbox.c +2 -0
+	cxlds->poison_max = min_t(u32, le32_to_cpu(val), CXL_POISON_LIST_MAX);
+
 	return 0;
 }
 EXPORT_SYMBOL_NS_GPL(cxl_dev_state_identify, CXL);

drivers/cxl/core/mbox.c int cxl_mem_create_range_info(struct cxl_dev_state *cxlds) · line 849

Quoted 8 lines
drivers/cxl/core/mbox.c +5 -0
@@ -835,6 +842,79 @@ 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;
+	const char *memdev_name = dev_name(&cxlmd->dev);

Could just do this where it's used rather than here.

drivers/cxl/core/mbox.c int cxl_mem_create_range_info(struct cxl_dev_state *cxlds) · line 876

Quoted 1 line
drivers/cxl/core/mbox.c +1 -0
+	const char *pcidev_name = dev_name(cxlds->dev);

Same with this.

Quoted 57 lines
drivers/cxl/core/mbox.c +42 -0
+	struct cxl_mbox_poison_payload_out *po;
+	struct cxl_mbox_poison_payload_in pi;
+	int nr_records = 0;
+	int rc;
+
+	po = kvmalloc(cxlds->payload_size, GFP_KERNEL);
+	if (!po)
+		return -ENOMEM;
+
+	pi.offset = cpu_to_le64(offset);
+	pi.length = cpu_to_le64(len);
+
+	rc = mutex_lock_interruptible(&cxlds->poison_list_mutex);
+	if (rc)
+		goto out;
+
+	do {
+		rc = cxl_mbox_send_cmd(cxlds, CXL_MBOX_OP_GET_POISON, &pi,
+				       sizeof(pi), po, cxlds->payload_size);
+		if (rc)
+			break;
+
+		if (trace_cxl_poison_enabled())
+			cxl_trace_poison(po, cxlr, memdev_name, pcidev_name);
+
+		/* Protect against an uncleared _FLAG_MORE */
+		nr_records = nr_records + le16_to_cpu(po->count);
+		if (nr_records >= cxlds->poison_max) {
+			dev_dbg(&cxlmd->dev, "Max Error Records reached: %d\n",
+				nr_records);
+			break;
+		}
+	} while (po->flags & CXL_POISON_FLAG_MORE);
+
+	mutex_unlock(&cxlds->poison_list_mutex);
+out:
+	kvfree(po);
+	return rc;
+}
+EXPORT_SYMBOL_NS_GPL(cxl_mem_get_poison, CXL);
+
 struct cxl_dev_state *cxl_dev_state_create(struct device *dev)
 {
 	struct cxl_dev_state *cxlds;
@@ -846,6 +926,7 @@ struct cxl_dev_state *cxl_dev_state_create(struct device *dev)
 	}
 
 	mutex_init(&cxlds->mbox_mutex);
+	mutex_init(&cxlds->poison_list_mutex);
 	cxlds->dev = dev;
 
 	return cxlds;
drivers/cxl/cxlmem.h +0 -0
index 669868cc1553..49d891347e39 100644

drivers/cxl/cxlmem.h struct cxl_endpoint_dvsec_info { · line 195

Quoted 4 lines
drivers/cxl/cxlmem.h +1 -0
@@ -192,6 +192,8 @@ struct cxl_endpoint_dvsec_info {
  *                (CXL 2.0 8.2.8.4.3 Mailbox Capabilities Register)
  * @lsa_size: Size of Label Storage Area
  *                (CXL 2.0 8.2.9.5.1.1 Identify Memory Device)
+ * @poison_max: maximum media error records held in device cache

For consistency of capitalization: Maximum

Quoted 6 lines
drivers/cxl/cxlmem.h +1 -0
+ * @poison_list_mutex: Mutex to synchronize poison list retrieval
  * @mbox_mutex: Mutex to synchronize mailbox access.
  * @firmware_version: Firmware version for the memory device.
  * @enabled_cmds: Hardware commands found enabled in CEL.
@@ -224,6 +226,8 @@ struct cxl_dev_state {
 

...

author maintainer
#6 lore raw

Re: [PATCH v3 2/6] cxl/mbox: Add GET_POISON_LIST mailbox command

Quoted 22 lines · Jonathan Cameron
Quoted 10 lines · On Thu, 10 Nov 2022 19:12:40 -0800 [email protected] 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.

Quoted 7 lines

Retrieve the list and 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.

Hi Alison,

Quoted 8 lines

I've forgotten most of previous discussions around versions of this series so I may well repeat things that were covered earlier!

A few things inline.

Thanks,

Jonathan

Thanks Jonathan. Got 'em all.

Quoted 3 lines
Quoted 3 lines

---

snip

Quoted 9 lines

drivers/cxl/core/mbox.c int cxl_dev_state_identify(struct cxl_dev_state *cxlds) · line 778

Quoted 3 lines
drivers/cxl/core/mbox.c +1 -0
+	memcpy(&val, id.poison_list_max_mer, 3);

This is ugly. I've lost track of last discussion about get_unaligned_le24() and using it on elements of a packed structure. At very least can we do a memcpy to a u8[3] array and then use get_unaligned_le24() on that if we can't use it directly on the structure element?

Done, like this -
val = get_unaligned_le24(id.poison_list_max_mer);

Quoted 1 line

snip

Quoted 11 lines

drivers/cxl/core/mbox.c int cxl_mem_create_range_info(struct cxl_dev_state *cxlds) · line 875

Quoted 6 lines
drivers/cxl/core/mbox.c +6 -0
+
+int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
+		       struct cxl_region *cxlr)
+{
+	struct cxl_dev_state *cxlds = cxlmd->cxlds;
+	const char *memdev_name = dev_name(&cxlmd->dev);

Could just do this where it's used rather than here.

drivers/cxl/core/mbox.c int cxl_mem_create_range_info(struct cxl_dev_state *cxlds) · line 876

Quoted 1 line
drivers/cxl/core/mbox.c +1 -0
+	const char *pcidev_name = dev_name(cxlds->dev);

Same with this.

Done.

Quoted 1 line

snip

Quoted 3 lines

...

#7 lore raw

RE: [PATCH v3 2/6] cxl/mbox: Add GET_POISON_LIST mailbox command

In reply to [email protected]
Quoted 45 lines · 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 list and 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.

---
 drivers/cxl/core/mbox.c | 81 +++++++++++++++++++++++++++++++++++++++++
 drivers/cxl/cxlmem.h    | 37 +++++++++++++++++++
 2 files changed, 118 insertions(+)
drivers/cxl/core/mbox.c +4 -0
index 0c90f13870a4..88f034e97812 100644
@@ -9,6 +9,9 @@
 
 #include "core.h"
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/cxl.h>
+
 static bool cxl_raw_allow_all;
 
 /**
@@ -752,6 +755,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;
+	__le32 val = 0;
 	int rc;
 
 	rc = cxl_mbox_send_cmd(cxlds, CXL_MBOX_OP_IDENTIFY, NULL, 0, &id,

drivers/cxl/core/mbox.c int cxl_dev_state_identify(struct cxl_dev_state *cxlds) · line 778

Quoted 4 lines
drivers/cxl/core/mbox.c +1 -0
@@ -771,6 +775,9 @@ 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));
 
+	memcpy(&val, id.poison_list_max_mer, 3);

I see Jonathan already commented on the need for get_unaligned_le24() here, seconded.

drivers/cxl/core/mbox.c int cxl_mem_create_range_info(struct cxl_dev_state *cxlds) · line 848

Quoted 13 lines
drivers/cxl/core/mbox.c +6 -0
+	cxlds->poison_max = min_t(u32, le32_to_cpu(val), CXL_POISON_LIST_MAX);
+
 	return 0;
 }
 EXPORT_SYMBOL_NS_GPL(cxl_dev_state_identify, CXL);
@@ -835,6 +842,79 @@ int cxl_mem_create_range_info(struct cxl_dev_state *cxlds)
 }
 EXPORT_SYMBOL_NS_GPL(cxl_mem_create_range_info, CXL);
 
+static void cxl_trace_poison(struct cxl_mbox_poison_payload_out *po,
+			     struct cxl_region *cxlr,
+			     const char *memdev_name,
+			     const char *pcidev_name)

Type-safety please. Pass a 'struct cxl_memdev *' and 'struct pci_dev *'. Might need to be 'struct device *' instead of 'struct pci_dev *' depending on if this needs to be called from cxl_test, but anything is better than a non-specific string.

drivers/cxl/core/mbox.c int cxl_mem_create_range_info(struct cxl_dev_state *cxlds) · line 850

Quoted 2 lines
drivers/cxl/core/mbox.c +2 -0
+{
+	const char *region_name = cxlr ? dev_name(&cxlr->dev) : NULL;

...and push this conversion into the trace point.

Quoted 29 lines
drivers/cxl/core/mbox.c +29 -0
+	struct cxl_region_params *p = cxlr ? &cxlr->params : NULL;
+	uuid_t *uuid = p ? &p->uuid : NULL;
+	u64 addr, dpa, overflow_t = 0;
+	u8 source;
+	u32 len;
+
+	if (po->flags & CXL_POISON_FLAG_OVERFLOW)
+		overflow_t = le64_to_cpu(po->overflow_timestamp);
+
+	for (int i = 0; i < le16_to_cpu(po->count); i++) {
+		len = le32_to_cpu(po->record[i].length) * CXL_POISON_LEN_MULT;
+		addr = le64_to_cpu(po->record[i].address);
+		source = addr & CXL_POISON_SOURCE_MASK;
+		dpa = addr & CXL_POISON_START_MASK;
+
+		trace_cxl_poison(memdev_name, pcidev_name, region_name, uuid,
+				 dpa, len, source, po->flags, overflow_t);
+	}
+}
+
+int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
+		       struct cxl_region *cxlr)
+{
+	struct cxl_dev_state *cxlds = cxlmd->cxlds;
+	const char *memdev_name = dev_name(&cxlmd->dev);
+	const char *pcidev_name = dev_name(cxlds->dev);
+	struct cxl_mbox_poison_payload_out *po;
+	struct cxl_mbox_poison_payload_in pi;
+	int nr_records = 0;

drivers/cxl/core/mbox.c int cxl_mem_create_range_info(struct cxl_dev_state *cxlds) · line 889

Quoted 10 lines
drivers/cxl/core/mbox.c +10 -0
+	int rc;
+
+	po = kvmalloc(cxlds->payload_size, GFP_KERNEL);
+	if (!po)
+		return -ENOMEM;
+
+	pi.offset = cpu_to_le64(offset);
+	pi.length = cpu_to_le64(len);
+
+	rc = mutex_lock_interruptible(&cxlds->poison_list_mutex);

So I do not know what this mutex is protecting if there is an allocation per cxl_mem_get_poison() invocation. Although I suspect that's somewhat wasteful. Just allocate one buffer at the beginning of time and then use the lock to protect that buffer.

Although, I wonder if this and Event handling should share locks and one preallocated buffer? Otherwise I do think it is important for Events and Poison handling to be able to make forward progress without needing to allocate up to a megabyte of memory at runtime. The other payload_size allocations are for one-off things that run at the beginning of time, but Poison and Events run repeatedly.

Quoted 66 lines
drivers/cxl/core/mbox.c +29 -0
+	if (rc)
+		goto out;
+
+	do {
+		rc = cxl_mbox_send_cmd(cxlds, CXL_MBOX_OP_GET_POISON, &pi,
+				       sizeof(pi), po, cxlds->payload_size);
+		if (rc)
+			break;
+
+		if (trace_cxl_poison_enabled())
+			cxl_trace_poison(po, cxlr, memdev_name, pcidev_name);
+
+		/* Protect against an uncleared _FLAG_MORE */
+		nr_records = nr_records + le16_to_cpu(po->count);
+		if (nr_records >= cxlds->poison_max) {
+			dev_dbg(&cxlmd->dev, "Max Error Records reached: %d\n",
+				nr_records);
+			break;
+		}
+	} while (po->flags & CXL_POISON_FLAG_MORE);
+
+	mutex_unlock(&cxlds->poison_list_mutex);
+out:
+	kvfree(po);
+	return rc;
+}
+EXPORT_SYMBOL_NS_GPL(cxl_mem_get_poison, CXL);
+
 struct cxl_dev_state *cxl_dev_state_create(struct device *dev)
 {
 	struct cxl_dev_state *cxlds;
@@ -846,6 +926,7 @@ struct cxl_dev_state *cxl_dev_state_create(struct device *dev)
 	}
 
 	mutex_init(&cxlds->mbox_mutex);
+	mutex_init(&cxlds->poison_list_mutex);
 	cxlds->dev = dev;
 
 	return cxlds;
drivers/cxl/cxlmem.h +5 -0
index 669868cc1553..49d891347e39 100644
@@ -192,6 +192,8 @@ struct cxl_endpoint_dvsec_info {
  *                (CXL 2.0 8.2.8.4.3 Mailbox Capabilities Register)
  * @lsa_size: Size of Label Storage Area
  *                (CXL 2.0 8.2.9.5.1.1 Identify Memory Device)
+ * @poison_max: maximum media error records held in device cache
+ * @poison_list_mutex: Mutex to synchronize poison list retrieval
  * @mbox_mutex: Mutex to synchronize mailbox access.
  * @firmware_version: Firmware version for the memory device.
  * @enabled_cmds: Hardware commands found enabled in CEL.
@@ -224,6 +226,8 @@ struct cxl_dev_state {
 
 	size_t payload_size;
 	size_t lsa_size;
+	u32 poison_max;
+	struct mutex poison_list_mutex;  /* Protect reads of poison list */
 	struct mutex mbox_mutex; /* Protects device mailbox and firmware */
 	char firmware_version[0x10];
 	DECLARE_BITMAP(enabled_cmds, CXL_MEM_COMMAND_ID_MAX);
@@ -349,6 +353,37 @@ struct cxl_mbox_set_partition_info {
 
 /* Get Poison List  CXL 3.0 Spec 8.2.9.8.4.1 */
 
+struct cxl_mbox_poison_payload_in {

drivers/cxl/cxlmem.h struct cxl_mbox_set_partition_info { · line 366

Quoted 10 lines
drivers/cxl/cxlmem.h +10 -0
+	__le64 offset;
+	__le64 length;
+} __packed;
+
+struct cxl_mbox_poison_payload_out {
+	u8 flags;
+	u8 rsvd1;
+	__le64 overflow_timestamp;
+	__le16 count;
+	u8 rsvd2[0x14];

Let's use decimal values for size.

Quoted 35 lines
drivers/cxl/cxlmem.h +22 -0
+	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)
@@ -395,6 +430,8 @@ 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_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);
Signature · 1 line
2.37.3
author maintainer
#8 lore raw

Re: [PATCH v3 2/6] cxl/mbox: Add GET_POISON_LIST mailbox command

Quoted 49 lines · Dan Williams
Quoted 48 lines · 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 list and 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.

---
 drivers/cxl/core/mbox.c | 81 +++++++++++++++++++++++++++++++++++++++++
 drivers/cxl/cxlmem.h    | 37 +++++++++++++++++++
 2 files changed, 118 insertions(+)
drivers/cxl/core/mbox.c +4 -0
index 0c90f13870a4..88f034e97812 100644
@@ -9,6 +9,9 @@
 
 #include "core.h"
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/cxl.h>
+
 static bool cxl_raw_allow_all;
 
 /**
@@ -752,6 +755,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;
+	__le32 val = 0;
 	int rc;
 
 	rc = cxl_mbox_send_cmd(cxlds, CXL_MBOX_OP_IDENTIFY, NULL, 0, &id,
@@ -771,6 +775,9 @@ 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));
 
Quoted 5 lines

drivers/cxl/core/mbox.c int cxl_dev_state_identify(struct cxl_dev_state *cxlds) · line 778

Quoted 1 line
drivers/cxl/core/mbox.c +1 -0
+	memcpy(&val, id.poison_list_max_mer, 3);

I see Jonathan already commented on the need for get_unaligned_le24() here, seconded.

Got it.

Quoted 10 lines
Quoted 10 lines
drivers/cxl/core/mbox.c +2 -0
+	cxlds->poison_max = min_t(u32, le32_to_cpu(val), CXL_POISON_LIST_MAX);
+
 	return 0;
 }
 EXPORT_SYMBOL_NS_GPL(cxl_dev_state_identify, CXL);
@@ -835,6 +842,79 @@ int cxl_mem_create_range_info(struct cxl_dev_state *cxlds)
 }
 EXPORT_SYMBOL_NS_GPL(cxl_mem_create_range_info, CXL);
 
Quoted 10 lines

drivers/cxl/core/mbox.c int cxl_mem_create_range_info(struct cxl_dev_state *cxlds) · line 848

Quoted 4 lines
drivers/cxl/core/mbox.c +4 -0
+static void cxl_trace_poison(struct cxl_mbox_poison_payload_out *po,
+			     struct cxl_region *cxlr,
+			     const char *memdev_name,
+			     const char *pcidev_name)

Type-safety please. Pass a 'struct cxl_memdev *' and 'struct pci_dev *'. Might need to be 'struct device *' instead of 'struct pci_dev *' depending on if this needs to be called from cxl_test, but anything is better than a non-specific string.

Got it.

Quoted 5 lines

drivers/cxl/core/mbox.c int cxl_mem_create_range_info(struct cxl_dev_state *cxlds) · line 850

Quoted 2 lines
drivers/cxl/core/mbox.c +2 -0
+{
+	const char *region_name = cxlr ? dev_name(&cxlr->dev) : NULL;

...and push this conversion into the trace point.

Got that, and also pushed the decode of struct cxl_poison_record to the trace point like this:

TP_PROTO(const struct device *memdev, const struct pci_dev *pcidev,
const struct cxl_region *region, const struct cxl_poison_record *record, u8 flags, __le64 overflow_t),

Quoted 36 lines
Quoted 36 lines
drivers/cxl/core/mbox.c +36 -0
+	struct cxl_region_params *p = cxlr ? &cxlr->params : NULL;
+	uuid_t *uuid = p ? &p->uuid : NULL;
+	u64 addr, dpa, overflow_t = 0;
+	u8 source;
+	u32 len;
+
+	if (po->flags & CXL_POISON_FLAG_OVERFLOW)
+		overflow_t = le64_to_cpu(po->overflow_timestamp);
+
+	for (int i = 0; i < le16_to_cpu(po->count); i++) {
+		len = le32_to_cpu(po->record[i].length) * CXL_POISON_LEN_MULT;
+		addr = le64_to_cpu(po->record[i].address);
+		source = addr & CXL_POISON_SOURCE_MASK;
+		dpa = addr & CXL_POISON_START_MASK;
+
+		trace_cxl_poison(memdev_name, pcidev_name, region_name, uuid,
+				 dpa, len, source, po->flags, overflow_t);
+	}
+}
+
+int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
+		       struct cxl_region *cxlr)
+{
+	struct cxl_dev_state *cxlds = cxlmd->cxlds;
+	const char *memdev_name = dev_name(&cxlmd->dev);
+	const char *pcidev_name = dev_name(cxlds->dev);
+	struct cxl_mbox_poison_payload_out *po;
+	struct cxl_mbox_poison_payload_in pi;
+	int nr_records = 0;
+	int rc;
+
+	po = kvmalloc(cxlds->payload_size, GFP_KERNEL);
+	if (!po)
+		return -ENOMEM;
+
+	pi.offset = cpu_to_le64(offset);
Quoted 8 lines

drivers/cxl/core/mbox.c int cxl_mem_create_range_info(struct cxl_dev_state *cxlds) · line 889

Quoted 3 lines
drivers/cxl/core/mbox.c +3 -0
+	pi.length = cpu_to_le64(len);
+
+	rc = mutex_lock_interruptible(&cxlds->poison_list_mutex);

So I do not know what this mutex is protecting if there is an allocation per cxl_mem_get_poison() invocation. Although I suspect that's somewhat wasteful. Just allocate one buffer at the beginning of time and then use the lock to protect that buffer.

Intent was a single lock on the device to protect the state of the poison list retrieval - do not allow > 1 reader. With > 1 reader software may not know if it retrieved the complete list.

I'm not understanding about protecting a buffer, instead of protecting the state. Here I try to protect the state.

Quoted 9 lines

Although, I wonder if this and Event handling should share locks and one preallocated buffer? Otherwise I do think it is important for Events and Poison handling to be able to make forward progress without needing to allocate up to a megabyte of memory at runtime. The other payload_size allocations are for one-off things that run at the beginning of time, but Poison and Events run repeatedly.

Quoted 1 line

snip

#9 lore raw

Re: [PATCH v3 2/6] cxl/mbox: Add GET_POISON_LIST mailbox command

Quoted 2 lines · Alison Schofield
Quoted 1 line · Dan Williams

alison.schofield@ wrote:

[..]

Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
(quoted diff) +16 -0
+int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
+		       struct cxl_region *cxlr)
+{
+	struct cxl_dev_state *cxlds = cxlmd->cxlds;
+	const char *memdev_name = dev_name(&cxlmd->dev);
+	const char *pcidev_name = dev_name(cxlds->dev);
+	struct cxl_mbox_poison_payload_out *po;
+	struct cxl_mbox_poison_payload_in pi;
+	int nr_records = 0;
+	int rc;
+
+	po = kvmalloc(cxlds->payload_size, GFP_KERNEL);
+	if (!po)
+		return -ENOMEM;
+
+	pi.offset = cpu_to_le64(offset);
Quoted 8 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+	pi.length = cpu_to_le64(len);
+
+	rc = mutex_lock_interruptible(&cxlds->poison_list_mutex);

So I do not know what this mutex is protecting if there is an allocation per cxl_mem_get_poison() invocation. Although I suspect that's somewhat wasteful. Just allocate one buffer at the beginning of time and then use the lock to protect that buffer.

Quoted 6 lines

Intent was a single lock on the device to protect the state of the poison list retrieval - do not allow > 1 reader. With > 1 reader software may not know if it retrieved the complete list.

I'm not understanding about protecting a buffer, instead of protecting the state. Here I try to protect the state.

Ah, sorry I read cxlds->poison_list_mutex and assumed it was serializing access to the buffer, not a state machine. I do think it would be worthwhile to make this a self contained structure with its own kdoc to explain what is going on, something like:

drivers/cxl/cxlmem.h +15 -0
index ab138004f644..02697d1d951c 100644
@@ -193,6 +193,19 @@ struct cxl_endpoint_dvsec_info {
        struct range dvsec_range[2];
 };
 
+/**
+ * struct cxl_poison_state - summary
+ * @payload: ...
+ * @lock: ...
+ *
+ * A bit more description of why state needs to be held over successive
+ * mbox commands...
+ */
+struct cxl_poison_state {
+       void *payload;
+       struct mutex lock;
+};
+
 /**
  * struct cxl_dev_state - The driver device state
  *
@@ -210,6 +223,7 @@ struct cxl_endpoint_dvsec_info {
  * @lsa_size: Size of Label Storage Area
  *                (CXL 2.0 8.2.9.5.1.1 Identify Memory Device)
  * @mbox_mutex: Mutex to synchronize mailbox access.
+ * @poison: Poison list retrieval and tracing
  * @firmware_version: Firmware version for the memory device.
  * @enabled_cmds: Hardware commands found enabled in CEL.
  * @exclusive_cmds: Commands that are kernel-internal only
@@ -244,6 +258,7 @@ struct cxl_dev_state {
        size_t payload_size;
        size_t lsa_size;
        struct mutex mbox_mutex; /* Protects device mailbox and firmware */
+       struct cxl_poison_state poison;
        char firmware_version[0x10];
        DECLARE_BITMAP(enabled_cmds, CXL_MEM_COMMAND_ID_MAX);
        DECLARE_BITMAP(exclusive_cmds, CXL_MEM_COMMAND_ID_MAX);
author maintainer
#10 lore raw

Re: [PATCH v3 2/6] cxl/mbox: Add GET_POISON_LIST mailbox command

Quoted 33 lines · Dan Williams
Quoted 2 lines · Alison Schofield
Quoted 1 line · Dan Williams

alison.schofield@ wrote:

[..]

Quoted 29 lines
Quoted 16 lines
Quoted 16 lines
(quoted diff) +16 -0
+int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
+		       struct cxl_region *cxlr)
+{
+	struct cxl_dev_state *cxlds = cxlmd->cxlds;
+	const char *memdev_name = dev_name(&cxlmd->dev);
+	const char *pcidev_name = dev_name(cxlds->dev);
+	struct cxl_mbox_poison_payload_out *po;
+	struct cxl_mbox_poison_payload_in pi;
+	int nr_records = 0;
+	int rc;
+
+	po = kvmalloc(cxlds->payload_size, GFP_KERNEL);
+	if (!po)
+		return -ENOMEM;
+
+	pi.offset = cpu_to_le64(offset);
Quoted 8 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+	pi.length = cpu_to_le64(len);
+
+	rc = mutex_lock_interruptible(&cxlds->poison_list_mutex);

So I do not know what this mutex is protecting if there is an allocation per cxl_mem_get_poison() invocation. Although I suspect that's somewhat wasteful. Just allocate one buffer at the beginning of time and then use the lock to protect that buffer.

Intent was a single lock on the device to protect the state of the poison list retrieval - do not allow > 1 reader. With > 1 reader software may not know if it retrieved the complete list.

Quoted 8 lines
Quoted 2 lines

I'm not understanding about protecting a buffer, instead of protecting the state. Here I try to protect the state.

Ah, sorry I read cxlds->poison_list_mutex and assumed it was serializing access to the buffer, not a state machine. I do think it would be worthwhile to make this a self contained structure with its own kdoc to explain what is going on, something like:

OK thanks, it's getting through to me now.
Will do !

Quoted 40 lines
drivers/cxl/cxlmem.h +15 -0
index ab138004f644..02697d1d951c 100644
@@ -193,6 +193,19 @@ struct cxl_endpoint_dvsec_info {
        struct range dvsec_range[2];
 };
 
+/**
+ * struct cxl_poison_state - summary
+ * @payload: ...
+ * @lock: ...
+ *
+ * A bit more description of why state needs to be held over successive
+ * mbox commands...
+ */
+struct cxl_poison_state {
+       void *payload;
+       struct mutex lock;
+};
+
 /**
  * struct cxl_dev_state - The driver device state
  *
@@ -210,6 +223,7 @@ struct cxl_endpoint_dvsec_info {
  * @lsa_size: Size of Label Storage Area
  *                (CXL 2.0 8.2.9.5.1.1 Identify Memory Device)
  * @mbox_mutex: Mutex to synchronize mailbox access.
+ * @poison: Poison list retrieval and tracing
  * @firmware_version: Firmware version for the memory device.
  * @enabled_cmds: Hardware commands found enabled in CEL.
  * @exclusive_cmds: Commands that are kernel-internal only
@@ -244,6 +258,7 @@ struct cxl_dev_state {
        size_t payload_size;
        size_t lsa_size;
        struct mutex mbox_mutex; /* Protects device mailbox and firmware */
+       struct cxl_poison_state poison;
        char firmware_version[0x10];
        DECLARE_BITMAP(enabled_cmds, CXL_MEM_COMMAND_ID_MAX);
        DECLARE_BITMAP(exclusive_cmds, CXL_MEM_COMMAND_ID_MAX);
author maintainer
#11 lore raw

PATCH v3 3/6 cxl/memdev: Add trigger_poison_list sysfs attribute

In reply to [email protected]

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 includes 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'.

---
 Documentation/ABI/testing/sysfs-bus-cxl | 14 +++++++++
 drivers/cxl/core/memdev.c               | 41 +++++++++++++++++++++++++
 2 files changed, 55 insertions(+)
Documentation/ABI/testing/sysfs-bus-cxl +14 -0
index 8494ef27e8d2..1c5f4a853ba2 100644
@@ -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 includes 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'.
drivers/cxl/core/memdev.c +41 -0

59 lines not on this page · raw message

Signature · 1 line
2.37.3
#12 lore raw

Re: [PATCH v3 3/6] cxl/memdev: Add trigger_poison_list sysfs attribute

Quoted 10 lines · On Thu, 10 Nov 2022 19:12:41 -0800 [email protected] 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 includes 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'.

Hi Alison,

A few comments inline.

Jonathan

Quoted 14 lines
---
 Documentation/ABI/testing/sysfs-bus-cxl | 14 +++++++++
 drivers/cxl/core/memdev.c               | 41 +++++++++++++++++++++++++
 2 files changed, 55 insertions(+)
Documentation/ABI/testing/sysfs-bus-cxl +1 -0
index 8494ef27e8d2..1c5f4a853ba2 100644
@@ -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.
+

Documentation/ABI/testing/sysfs-bus-cxl Description: · line 401

Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-cxl +10 -0
+
+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 includes addresses that are poisoned or would result in
+		poison if accessed, and the source of the poison. This

Trivial, but 'includes' kind of implies it might have other things as well.

The list consists of addresses that are... perhaps?

Quoted 15 lines
Documentation/ABI/testing/sysfs-bus-cxl +3 -0
+		attribute is only visible for devices supporting the
+		capability. The retrieved errors are logged as kernel
+		trace events with the label 'cxl_poison'.
drivers/cxl/core/memdev.c +4 -0
index 20ce488a7754..06d265db5127 100644
@@ -106,12 +106,45 @@ 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)
+{

drivers/cxl/core/memdev.c static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr, · line 122

Quoted 10 lines
drivers/cxl/core/memdev.c +10 -0
+	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;
+
+	/* Per CXL Spec, separate the pmem and ram poison list reads */

Reference? I assume this is the bit about what happens if the device doesn't support poison list retrieval for volatile memory? I can't find anything more specific but maybe I'm looking in wrong place.

drivers/cxl/core/memdev.c static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr, · line 135

Quoted 13 lines
drivers/cxl/core/memdev.c +13 -0
+	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);
+		if (rc)
+			return rc;

Hmm. So should we handle the return of Invalid Physical Address as an error or not? I think not given it's optional to support the poison list for volatile memory.

Quoted 30 lines
drivers/cxl/core/memdev.c +14 -0
+	}
+	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 +163,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;
 }
 
author maintainer
#13 lore raw

Re: [PATCH v3 3/6] cxl/memdev: Add trigger_poison_list sysfs attribute

Quoted 46 lines · Jonathan Cameron
Quoted 10 lines · On Thu, 10 Nov 2022 19:12:41 -0800 [email protected] 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 includes 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'.

Hi Alison,

A few comments inline.

Jonathan

Quoted 14 lines
---
 Documentation/ABI/testing/sysfs-bus-cxl | 14 +++++++++
 drivers/cxl/core/memdev.c               | 41 +++++++++++++++++++++++++
 2 files changed, 55 insertions(+)
Documentation/ABI/testing/sysfs-bus-cxl +1 -0
index 8494ef27e8d2..1c5f4a853ba2 100644
@@ -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.
+

Documentation/ABI/testing/sysfs-bus-cxl Description: · line 401

Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-cxl +10 -0
+
+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 includes addresses that are poisoned or would result in
+		poison if accessed, and the source of the poison. This

Trivial, but 'includes' kind of implies it might have other things as well.

Quoted 2 lines

The list consists of addresses that are... perhaps?

Changed that to consists. Now, I will be on the lookout for other usages of includes with unintended implications ;)

Quoted 11 lines
Quoted 11 lines
Documentation/ABI/testing/sysfs-bus-cxl +3 -0
+		attribute is only visible for devices supporting the
+		capability. The retrieved errors are logged as kernel
+		trace events with the label 'cxl_poison'.
drivers/cxl/core/memdev.c +0 -0
index 20ce488a7754..06d265db5127 100644
@@ -106,12 +106,45 @@ static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(numa_node);
 
Quoted 14 lines
Quoted 4 lines
drivers/cxl/core/memdev.c +4 -0
+static ssize_t trigger_poison_list_store(struct device *dev,
+					 struct device_attribute *attr,
+					 const char *buf, size_t len)
+{

drivers/cxl/core/memdev.c static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr, · line 122

Quoted 10 lines
drivers/cxl/core/memdev.c +10 -0
+	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;
+
+	/* Per CXL Spec, separate the pmem and ram poison list reads */

/* Per CXL Spec 8.2.9.8.4.1 separate the pmem and ram requests */

Added this ^

Quoted 5 lines

Reference? I assume this is the bit about what happens if the device doesn't support poison list retrieval for volatile memory? I can't find anything more specific but maybe I'm looking in wrong place.

Section 8.2.9.8.4.1
Says this:
The device may reject this command if the requested range spans the device’s volatile and persistent partitions.

And this -
If the device does not support poison list for volatile ranges and any location in the requested list maps to volatile, the device shall return Invalid Physical Address.

And, the device only reports that it supports the Get Poison command, in general, not specifically for pmem or volatile.

So, we split the requests along ram and pmem boundaries.

Quoted 9 lines
Quoted 9 lines
drivers/cxl/core/memdev.c +9 -0
+	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;
Quoted 9 lines

drivers/cxl/core/memdev.c static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr, · line 135

Quoted 4 lines
drivers/cxl/core/memdev.c +4 -0
+		length = resource_size(&cxlds->ram_res);
+		rc = cxl_mem_get_poison(cxlmd, offset, length, NULL);
+		if (rc)
+			return rc;

Hmm. So should we handle the return of Invalid Physical Address as an error or not? I think not given it's optional to support the poison list for volatile memory.

Double hmmm. It wasn't obvious what to do here. Users can look for the events to see if anything was traced, regardless of the rc. But, if an 'rc' stopped a user from looking for results, that would be bad.

I'll go with no error return on ram failure.

Quoted 31 lines
Quoted 30 lines
drivers/cxl/core/memdev.c +14 -0
+	}
+	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 +163,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;
 }
 
author maintainer
#14 lore raw

PATCH v3 4/6 cxl/region: Add trigger_poison_list sysfs attribute

In reply to [email protected]

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 includes 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.

---
 Documentation/ABI/testing/sysfs-bus-cxl | 14 +++++++++++
 drivers/cxl/core/region.c               | 33 +++++++++++++++++++++++++
 2 files changed, 47 insertions(+)
Documentation/ABI/testing/sysfs-bus-cxl +14 -0
index 1c5f4a853ba2..54fad3bdcb2b 100644
@@ -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 includes
+		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'.
drivers/cxl/core/region.c +33 -0
index f9ae5ad284ff..68821238491e 100644
@@ -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,
 };
 
Signature · 1 line
2.37.3
Reviewed-by on v3 4/6
#15 lore raw

Re: [PATCH v3 4/6] cxl/region: Add trigger_poison_list sysfs attribute

Quoted 9 lines · On Thu, 10 Nov 2022 19:12:42 -0800 [email protected] wrote:

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 includes 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'.

Quoted 3 lines

Devices not supporting the poison list capability are ignored.

Trivial comment inline you might want to consider.

Quoted 13 lines
---
 Documentation/ABI/testing/sysfs-bus-cxl | 14 +++++++++++
 drivers/cxl/core/region.c               | 33 +++++++++++++++++++++++++
 2 files changed, 47 insertions(+)
Documentation/ABI/testing/sysfs-bus-cxl +0 -0
index 1c5f4a853ba2..54fad3bdcb2b 100644
@@ -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'.

Documentation/ABI/testing/sysfs-bus-cxl Description: · line 414

Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-cxl +10 -0
+
+
+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 includes

Trivial: Same as in previous patch. "includes" is too vague.

Quoted 55 lines
Documentation/ABI/testing/sysfs-bus-cxl +4 -0
+		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'.
drivers/cxl/core/region.c +33 -0
index f9ae5ad284ff..68821238491e 100644
@@ -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,
 };
 
author maintainer
#16 lore raw

Re: [PATCH v3 4/6] cxl/region: Add trigger_poison_list sysfs attribute

Quoted 12 lines · Jonathan Cameron
Quoted 9 lines · On Thu, 10 Nov 2022 19:12:42 -0800 [email protected] wrote:

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 includes 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'.

Quoted 4 lines
Quoted 3 lines

Devices not supporting the poison list capability are ignored.

Trivial comment inline you might want to consider.

Thanks, got it! I will 'include' your tag going forward.

Quoted 84 lines
Quoted 13 lines
---
 Documentation/ABI/testing/sysfs-bus-cxl | 14 +++++++++++
 drivers/cxl/core/region.c               | 33 +++++++++++++++++++++++++
 2 files changed, 47 insertions(+)
Documentation/ABI/testing/sysfs-bus-cxl +0 -0
index 1c5f4a853ba2..54fad3bdcb2b 100644
@@ -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'.

Documentation/ABI/testing/sysfs-bus-cxl Description: · line 414

Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-cxl +10 -0
+
+
+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 includes

Trivial: Same as in previous patch. "includes" is too vague.

Quoted 55 lines
Documentation/ABI/testing/sysfs-bus-cxl +4 -0
+		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'.
drivers/cxl/core/region.c +33 -0
index f9ae5ad284ff..68821238491e 100644
@@ -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,
 };
 
author maintainer
#17 lore raw

PATCH v3 5/6 tools/testing/cxl: Mock the max err records field of Identify cmd

In reply to [email protected]

From: Alison Schofield <[email protected]>

The CXL mbox command Identify reports the maximum media error records that a device will report. Mock it here for testing the GET POISON LIST mbox command.

---
 tools/testing/cxl/test/mem.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/testing/cxl/test/mem.c +4 -0
index aa2df3a15051..f0704d090073 100644
@@ -111,6 +111,10 @@ static int mock_id(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
 			cpu_to_le64(DEV_SIZE / CXL_CAPACITY_MULTIPLIER),
 	};
 
+	__le32 val = cpu_to_le32(SZ_64);
+
+	memcpy(id.poison_list_max_mer, &val, 3);
+
 	if (cmd->size_out < sizeof(id))
 		return -EINVAL;
 
Signature · 1 line
2.37.3
#18 lore raw

Re: [PATCH v3 5/6] tools/testing/cxl: Mock the max err records field of Identify cmd

Quoted 16 lines · On Thu, 10 Nov 2022 19:12:43 -0800 [email protected] wrote:

From: Alison Schofield <[email protected]>

The CXL mbox command Identify reports the maximum media error records that a device will report. Mock it here for testing the GET POISON LIST mbox command.

---
 tools/testing/cxl/test/mem.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/testing/cxl/test/mem.c +0 -0
index aa2df3a15051..f0704d090073 100644

tools/testing/cxl/test/mem.c static int mock_id(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd) · line 116

Quoted 6 lines
tools/testing/cxl/test/mem.c +3 -0
@@ -111,6 +111,10 @@ static int mock_id(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
 			cpu_to_le64(DEV_SIZE / CXL_CAPACITY_MULTIPLIER),
 	};
 
+	__le32 val = cpu_to_le32(SZ_64);
+
+	memcpy(id.poison_list_max_mer, &val, 3);

As in other direction, can we do this with a buffer of the right size if we can't do a put_unaligned_le24() directly.

Quoted 4 lines
tools/testing/cxl/test/mem.c +1 -0
+
 	if (cmd->size_out < sizeof(id))
 		return -EINVAL;
 
author maintainer
#19 lore raw

Re: [PATCH v3 5/6] tools/testing/cxl: Mock the max err records field of Identify cmd

Quoted 22 lines · Jonathan Cameron
Quoted 19 lines · On Thu, 10 Nov 2022 19:12:43 -0800 [email protected] wrote:

From: Alison Schofield <[email protected]>

The CXL mbox command Identify reports the maximum media error records that a device will report. Mock it here for testing the GET POISON LIST mbox command.

---
 tools/testing/cxl/test/mem.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/testing/cxl/test/mem.c +0 -0
index aa2df3a15051..f0704d090073 100644
@@ -111,6 +111,10 @@ static int mock_id(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
 			cpu_to_le64(DEV_SIZE / CXL_CAPACITY_MULTIPLIER),
 	};
 
Quoted 6 lines

tools/testing/cxl/test/mem.c static int mock_id(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd) · line 116

Quoted 3 lines
tools/testing/cxl/test/mem.c +3 -0
+	__le32 val = cpu_to_le32(SZ_64);
+
+	memcpy(id.poison_list_max_mer, &val, 3);

As in other direction, can we do this with a buffer of the right size if we can't do a put_unaligned_le24() directly.

Yes. Got it, thanks!

Quoted 5 lines
Quoted 4 lines
tools/testing/cxl/test/mem.c +1 -0
+
 	if (cmd->size_out < sizeof(id))
 		return -EINVAL;
 
author maintainer
#20 lore raw

PATCH v3 6/6 tools/testing/cxl: Mock the Get Poison List mbox command

In reply to [email protected]

From: Alison Schofield <[email protected]>

Return fake poison error records when the get poison list mbox command is issued. This supports testing the kernel tracing and cxl list capabilities for media errors.

---
 tools/testing/cxl/test/mem.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
tools/testing/cxl/test/mem.c +31 -0
index f0704d090073..f729e055605d 100644
@@ -38,6 +38,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 */
@@ -207,6 +211,30 @@ 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 {
+		struct cxl_mbox_poison_payload_out poison_out;
+		struct cxl_poison_record record;
+	} mock_poison_list = {
+		.poison_out = {
+			.count = cpu_to_le16(1),
+		},
+		.record = {
+			/* .address encodes DPA and poison source bits */
+			.address = cpu_to_le64(CXL_POISON_SOURCE_INTERNAL),
+			.length = cpu_to_le32(1),
+		},
+	};
+
+	if (cmd->size_out < sizeof(mock_poison_list))
+		return -EINVAL;
+
+	memcpy(cmd->payload_out, &mock_poison_list, sizeof(mock_poison_list));
+	cmd->size_out = sizeof(mock_poison_list);
+	return 0;
+}
+
 static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
 {
 	struct device *dev = cxlds->dev;
@@ -234,6 +262,9 @@ static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *
 	case CXL_MBOX_OP_GET_HEALTH_INFO:
 		rc = mock_health_info(cxlds, cmd);
 		break;
+	case CXL_MBOX_OP_GET_POISON:
+		rc = mock_get_poison(cxlds, cmd);
+		break;
 	default:
 		break;
 	}
Signature · 1 line
2.37.3
Reviewed-by on v3 6/6
#21 lore raw

Re: [PATCH v3 6/6] tools/testing/cxl: Mock the Get Poison List mbox command

Quoted 7 lines · On Thu, 10 Nov 2022 19:12:44 -0800 [email protected] wrote:

From: Alison Schofield <[email protected]>

Return fake poison error records when the get poison list mbox command is issued. This supports testing the kernel tracing and cxl list capabilities for media errors.

Quoted 60 lines
---
 tools/testing/cxl/test/mem.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
tools/testing/cxl/test/mem.c +31 -0
index f0704d090073..f729e055605d 100644
@@ -38,6 +38,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 */
@@ -207,6 +211,30 @@ 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 {
+		struct cxl_mbox_poison_payload_out poison_out;
+		struct cxl_poison_record record;
+	} mock_poison_list = {
+		.poison_out = {
+			.count = cpu_to_le16(1),
+		},
+		.record = {
+			/* .address encodes DPA and poison source bits */
+			.address = cpu_to_le64(CXL_POISON_SOURCE_INTERNAL),
+			.length = cpu_to_le32(1),
+		},
+	};
+
+	if (cmd->size_out < sizeof(mock_poison_list))
+		return -EINVAL;
+
+	memcpy(cmd->payload_out, &mock_poison_list, sizeof(mock_poison_list));
+	cmd->size_out = sizeof(mock_poison_list);
+	return 0;
+}
+
 static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
 {
 	struct device *dev = cxlds->dev;
@@ -234,6 +262,9 @@ static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *
 	case CXL_MBOX_OP_GET_HEALTH_INFO:
 		rc = mock_health_info(cxlds, cmd);
 		break;
+	case CXL_MBOX_OP_GET_POISON:
+		rc = mock_get_poison(cxlds, cmd);
+		break;
 	default:
 		break;
 	}