Skip to contentSkip to conversation

CXL Poison List Retrieval & Tracing

PATCH Superseded [email protected] 2 participants 23 messages Apr 10, 2023 – Apr 17, 2023 CXL

v12 of 13 Superseded Latest is v13 →

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

v12 cover CXL Poison List Retrieval & Tracing

From: Alison Schofield <[email protected]>

Changes in v12:
- Pick up Reviewed-by Tags:
2/6 cxl/trace: Add TRACE support for CXL media-error records (Ira) 4/6 cxl/region: Provide region info to the cxl_poison trace event (Ira, DaveJ) 6/6 tools/testing/cxl: Mock support for Get Poison List (DaveJ)
- Update sysfs doc to say logging happens when cxl_poison events are enabled.
- Remove errant blank line in cxl_memdev_visible() (Jonathan, DaveJ)
- Rename cxlds->poison.payload_out, poison.list_out
- Update commit message syntax (DaveJ)
- Shorten mailbox struct names (DaveJ)

Link to v11:
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 trigger:

$ echo 1 > /sys/bus/cxl/devices/mem0/trigger_poison_list

Example Trace Events:

Poison found in a PMEM Region:
cxl_poison: memdev=mem0 host=cxl_mem.0 serial=0 trace_type=List region=region11 region_uuid=d96e67ec-76b0-406f-8c35-5b52630dcad1 hpa=0xf100000000 dpa=0x70000000 dpa_length=0x40 source=Injected flags= overflow_time=0

Poison found in RAM Region:
cxl_poison: memdev=mem0 host=cxl_mem.0 serial=0 trace_type=List region=region2 region_uuid=00000000-0000-0000-0000-000000000000 hpa=0xf010000000 dpa=0x0 dpa_length=0x40 source=Injected flags= overflow_time=0

Poison found in an unmapped DPA resource:
cxl_poison: memdev=mem3 host=cxl_mem.3 serial=3 trace_type=List region= region_uuid=00000000-0000-0000-0000-000000000000 hpa=0xffffffffffffffff dpa=0x40000000 dpa_length=0x40 source=Injected flags= overflow_time=0

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

Alison Schofield (6):
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: Provide region info to the cxl_poison trace event cxl/trace: Add an HPA to cxl_poison trace events tools/testing/cxl: Mock support for Get Poison List

 Documentation/ABI/testing/sysfs-bus-cxl |  14 +++
 drivers/cxl/core/core.h                 |  15 ++++
 drivers/cxl/core/mbox.c                 |  74 ++++++++++++++++
 drivers/cxl/core/memdev.c               | 108 ++++++++++++++++++++++++
 drivers/cxl/core/region.c               |  63 ++++++++++++++
 drivers/cxl/core/trace.c                |  94 +++++++++++++++++++++
 drivers/cxl/core/trace.h                | 101 ++++++++++++++++++++++
 drivers/cxl/cxlmem.h                    |  72 +++++++++++++++-
 drivers/cxl/mem.c                       |  36 ++++++++
 drivers/cxl/pci.c                       |   4 +
 tools/testing/cxl/test/mem.c            |  42 +++++++++
 11 files changed, 622 insertions(+), 1 deletion(-)

base-commit: e686c32590f40bffc45f105c04c836ffad3e531a

Signature · 1 line
2.37.3
author maintainer
#1 lore raw

PATCH v12 1/6 cxl/mbox: Add GET_POISON_LIST mailbox command

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.

---
 drivers/cxl/core/mbox.c | 71 +++++++++++++++++++++++++++++++++++++++++
 drivers/cxl/cxlmem.h    | 67 ++++++++++++++++++++++++++++++++++++++
 drivers/cxl/pci.c       |  4 +++
 3 files changed, 142 insertions(+)
drivers/cxl/core/mbox.c +71 -0
index f2addb457172..69a5d69dd53b 100644
@@ -5,6 +5,8 @@
 #include <linux/debugfs.h>
 #include <linux/ktime.h>
 #include <linux/mutex.h>
+#include <asm/unaligned.h>
+#include <cxlpci.h>
 #include <cxlmem.h>
 #include <cxl.h>
 
@@ -994,6 +996,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) {
@@ -1017,6 +1020,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_errors = min_t(u32, val, CXL_POISON_LIST_MAX);
+	}
+
 	return 0;
 }
 EXPORT_SYMBOL_NS_GPL(cxl_dev_state_identify, CXL);
@@ -1107,6 +1115,69 @@ int cxl_set_timestamp(struct cxl_dev_state *cxlds)
 }
 EXPORT_SYMBOL_NS_GPL(cxl_set_timestamp, 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_mbox_poison_out *po;
+	struct cxl_mbox_poison_in pi;
+	struct cxl_mbox_cmd mbox_cmd;
+	int nr_records = 0;
+	int rc;
+
+	rc = mutex_lock_interruptible(&cxlds->poison.lock);
+	if (rc)
+		return rc;
+
+	po = cxlds->poison.list_out;
+	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 >= cxlds->poison.max_errors) {
+			dev_dbg(&cxlmd->dev, "Max Error Records reached: %d\n",
+				nr_records);
+			break;
+		}
+	} while (po->flags & CXL_POISON_FLAG_MORE);
+
+	mutex_unlock(&cxlds->poison.lock);
+	return rc;
+}
+EXPORT_SYMBOL_NS_GPL(cxl_mem_get_poison, CXL);
+
+int cxl_poison_state_init(struct cxl_dev_state *cxlds)
+{
+	if (!test_bit(CXL_MEM_COMMAND_ID_GET_POISON, cxlds->enabled_cmds))
+		return 0;
+
+	cxlds->poison.list_out = devm_kzalloc(cxlds->dev, cxlds->payload_size,
+					      GFP_KERNEL);
+	if (!cxlds->poison.list_out)
+		return -ENOMEM;
+
+	mutex_init(&cxlds->poison.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;
drivers/cxl/cxlmem.h +67 -0

97 lines not on this page · raw message

drivers/cxl/pci.c +4 -0
index 60b23624d167..827ea0895778 100644
@@ -769,6 +769,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;
Signature · 1 line
2.37.3
author maintainer
#12 lore raw

PATCH v12 2/6 cxl/trace: Add TRACE support for CXL media-error records

In reply to [email protected]

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 cxl_poison trace event of type 'List'.

---
 drivers/cxl/core/core.h  |  4 ++
 drivers/cxl/core/mbox.c  |  5 ++-
 drivers/cxl/core/trace.h | 94 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 102 insertions(+), 1 deletion(-)
drivers/cxl/core/core.h +4 -0
index cde475e13216..e888e293943e 100644
@@ -64,4 +64,8 @@ int cxl_memdev_init(void);
 void cxl_memdev_exit(void);
 void cxl_mbox_init(void);
 
+enum cxl_poison_trace_type {
+	CXL_POISON_TRACE_LIST,
+};
+
 #endif /* __CXL_CORE_H__ */
drivers/cxl/core/mbox.c +4 -1
index 69a5d69dd53b..cc69ee33f208 100644
@@ -1147,7 +1147,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, cxlr, &po->record[i],
+					 po->flags, po->overflow_t,
+					 CXL_POISON_TRACE_LIST);
 
 		/* Protect against an uncleared _FLAG_MORE */
 		nr_records = nr_records + le16_to_cpu(po->count);
drivers/cxl/core/trace.h +94 -0

110 lines not on this page · raw message

Signature · 1 line
2.37.3
author maintainer
#13 lore raw

PATCH v12 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 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 events when cxl_poison event tracing is enabled.

---
 Documentation/ABI/testing/sysfs-bus-cxl | 14 ++++++++
 drivers/cxl/core/memdev.c               | 48 +++++++++++++++++++++++++
 drivers/cxl/cxlmem.h                    |  5 ++-
 drivers/cxl/mem.c                       | 36 +++++++++++++++++++
 4 files changed, 102 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-bus-cxl +14 -0
index 3acf2f17a73f..48ac0d911801 100644
@@ -415,3 +415,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:		April, 2023
+KernelVersion:	v6.4
+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
+		events when cxl_poison event tracing is enabled.
drivers/cxl/core/memdev.c +48 -0

60 lines not on this page · raw message

drivers/cxl/cxlmem.h +4 -1
index a3033c8dd8e2..aa9ba74e03a0 100644
@@ -145,7 +145,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"),               \
@@ -675,6 +675,9 @@ int cxl_set_timestamp(struct cxl_dev_state *cxlds);
 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);
+ssize_t cxl_trigger_poison_list(struct device *dev,
+				struct device_attribute *attr, const char *buf,
+				size_t len);
 
 #ifdef CONFIG_CXL_SUSPEND
 void cxl_mem_active_inc(void);
drivers/cxl/mem.c +36 -0
index 39c4b54f0715..576f5b691589 100644
@@ -176,10 +176,46 @@ static int cxl_mem_probe(struct device *dev)
 	return devm_add_action_or_reset(dev, enable_suspend, NULL);
 }
 
+static ssize_t trigger_poison_list_store(struct device *dev,
+					 struct device_attribute *attr,
+					 const char *buf, size_t len)
+{
+	return cxl_trigger_poison_list(dev, attr, buf, len);
+}
+
+static DEVICE_ATTR_WO(trigger_poison_list);
+
+static umode_t cxl_mem_visible(struct kobject *kobj, struct attribute *a, int n)
+{
+	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;
+}
+
+static struct attribute *cxl_mem_attrs[] = {
+	&dev_attr_trigger_poison_list.attr,
+	NULL
+};
+
+static struct attribute_group cxl_mem_group = {
+	.attrs = cxl_mem_attrs,
+	.is_visible = cxl_mem_visible,
+};
+
+__ATTRIBUTE_GROUPS(cxl_mem);
+
 static struct cxl_driver cxl_mem_driver = {
 	.name = "cxl_mem",
 	.probe = cxl_mem_probe,
 	.id = CXL_DEVICE_MEMORY_EXPANDER,
+	.drv = {
+		.dev_groups = cxl_mem_groups,
+	},
 };
 
 module_cxl_driver(cxl_mem_driver);
Signature · 1 line
2.37.3
author maintainer
#17 lore raw

PATCH v12 4/6 cxl/region: Provide region info to the cxl_poison trace event

In reply to [email protected]

From: Alison Schofield <[email protected]>

User space may need to know which region, if any, maps the poison address(es) logged in a cxl_poison trace event. Since the mapping of DPAs (device physical addresses) to a region can change, the kernel must provide this information at the time the poison list is read. The event informs user space that at event <timestamp> this <region> mapped to this <DPA>, which is poisoned.

The cxl_poison trace event is already wired up to log the region name and uuid if it receives param 'struct cxl_region'.

In order to provide that cxl_region, add another method for gathering poison - by committed endpoint decoder mappings. This method is only available with CONFIG_CXL_REGION and is only used if a region actually maps the memdev where poison is being read. After the region driver reads the poison list for all the mapped resources, control returns to the memdev driver, where poison is read for any remaining unmapped resources.

Mixed mode decoders are not currently supported in Linux. Add a debug message to the poison request path. That will serve as an alert that poison list retrieval needs to add support for mixed mode.

The default method remains: read the poison by memdev resource.

---
 drivers/cxl/core/core.h   | 11 +++++++
 drivers/cxl/core/memdev.c | 62 +++++++++++++++++++++++++++++++++++++-
 drivers/cxl/core/region.c | 63 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 135 insertions(+), 1 deletion(-)
drivers/cxl/core/core.h +11 -0
index e888e293943e..57bd22e01a0b 100644
@@ -25,7 +25,12 @@ void cxl_decoder_kill_region(struct cxl_endpoint_decoder *cxled);
 #define CXL_DAX_REGION_TYPE(x) (&cxl_dax_region_type)
 int cxl_region_init(void);
 void cxl_region_exit(void);
+int cxl_get_poison_by_endpoint(struct device *dev, void *data);
 #else
+static inline int cxl_get_poison_by_endpoint(struct device *dev, void *data)
+{
+	return 0;
+}
 static inline void cxl_decoder_kill_region(struct cxl_endpoint_decoder *cxled)
 {
 }
@@ -68,4 +73,10 @@ enum cxl_poison_trace_type {
 	CXL_POISON_TRACE_LIST,
 };
 
+struct cxl_trigger_poison_context {
+	struct cxl_port *port;
+	enum cxl_decoder_mode mode;
+	u64 offset;
+};
+
 #endif /* __CXL_CORE_H__ */
drivers/cxl/core/memdev.c +61 -1

81 lines not on this page · raw message

drivers/cxl/core/region.c +63 -0

69 lines not on this page · raw message

Signature · 1 line
2.37.3
author maintainer
#21 lore raw

PATCH v12 5/6 cxl/trace: Add an HPA to cxl_poison trace events

In reply to [email protected]

From: Alison Schofield <[email protected]>

When a cxl_poison trace event is reported for a region, the poisoned Device Physical Address (DPA) can be translated to a Host Physical Address (HPA) for consumption by user space.

Translate and add the resulting HPA to the cxl_poison trace event. Follow the device decode logic as defined in the CXL Spec 3.0 Section 8.2.4.19.13.

If no region currently maps the poison, assign ULLONG_MAX to the cxl_poison event hpa field.

---
 drivers/cxl/core/trace.c | 94 ++++++++++++++++++++++++++++++++++++++++
 drivers/cxl/core/trace.h | 11 ++++-
 2 files changed, 103 insertions(+), 2 deletions(-)
drivers/cxl/core/trace.c +94 -0
index 29ae7ce81dc5..d0403dc3c8ab 100644
@@ -1,5 +1,99 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /* Copyright(c) 2022 Intel Corporation. All rights reserved. */
 
+#include <cxl.h>
+#include "core.h"
+
 #define CREATE_TRACE_POINTS
 #include "trace.h"
+
+static bool cxl_is_hpa_in_range(u64 hpa, struct cxl_region *cxlr, int pos)
+{
+	struct cxl_region_params *p = &cxlr->params;
+	int gran = p->interleave_granularity;
+	int ways = p->interleave_ways;
+	u64 offset;
+
+	/* Is the hpa within this region at all */
+	if (hpa < p->res->start || hpa > p->res->end) {
+		dev_dbg(&cxlr->dev,
+			"Addr trans fail: hpa 0x%llx not in region\n", hpa);
+		return false;
+	}
+
+	/* Is the hpa in an expected chunk for its pos(-ition) */
+	offset = hpa - p->res->start;
+	offset = do_div(offset, gran * ways);
+	if ((offset >= pos * gran) && (offset < (pos + 1) * gran))
+		return true;
+
+	dev_dbg(&cxlr->dev,
+		"Addr trans fail: hpa 0x%llx not in expected chunk\n", hpa);
+
+	return false;
+}
+
+static u64 cxl_dpa_to_hpa(u64 dpa,  struct cxl_region *cxlr,
+			  struct cxl_endpoint_decoder *cxled)
+{
+	u64 dpa_offset, hpa_offset, bits_upper, mask_upper, hpa;
+	struct cxl_region_params *p = &cxlr->params;
+	int pos = cxled->pos;
+	u16 eig = 0;
+	u8 eiw = 0;
+
+	ways_to_eiw(p->interleave_ways, &eiw);
+	granularity_to_eig(p->interleave_granularity, &eig);
+
+	/*
+	 * The device position in the region interleave set was removed
+	 * from the offset at HPA->DPA translation. To reconstruct the
+	 * HPA, place the 'pos' in the offset.
+	 *
+	 * The placement of 'pos' in the HPA is determined by interleave
+	 * ways and granularity and is defined in the CXL Spec 3.0 Section
+	 * 8.2.4.19.13 Implementation Note: Device Decode Logic
+	 */
+
+	/* Remove the dpa base */
+	dpa_offset = dpa - cxl_dpa_resource_start(cxled);
+
+	mask_upper = GENMASK_ULL(51, eig + 8);
+
+	if (eiw < 8) {
+		hpa_offset = (dpa_offset & mask_upper) << eiw;
+		hpa_offset |= pos << (eig + 8);
+	} else {
+		bits_upper = (dpa_offset & mask_upper) >> (eig + 8);
+		bits_upper = bits_upper * 3;
+		hpa_offset = ((bits_upper << (eiw - 8)) + pos) << (eig + 8);
+	}
+
+	/* The lower bits remain unchanged */
+	hpa_offset |= dpa_offset & GENMASK_ULL(eig + 7, 0);
+
+	/* Apply the hpa_offset to the region base address */
+	hpa = hpa_offset + p->res->start;
+
+	if (!cxl_is_hpa_in_range(hpa, cxlr, cxled->pos))
+		return ULLONG_MAX;
+
+	return hpa;
+}
+
+u64 cxl_trace_hpa(struct cxl_region *cxlr, struct cxl_memdev *cxlmd,
+		  u64 dpa)
+{
+	struct cxl_region_params *p = &cxlr->params;
+	struct cxl_endpoint_decoder *cxled = NULL;
+
+	for (int i = 0; i <  p->nr_targets; i++) {
+		cxled = p->targets[i];
+		if (cxlmd == cxled_to_memdev(cxled))
+			break;
+	}
+	if (!cxled || cxlmd != cxled_to_memdev(cxled))
+		return ULLONG_MAX;
+
+	return cxl_dpa_to_hpa(dpa, cxlr, cxled);
+}
drivers/cxl/core/trace.h +9 -2
index 2687a2c6fbfa..65d81d27cb85 100644
@@ -636,6 +636,8 @@ TRACE_EVENT(cxl_memory_module,
 #define cxl_poison_overflow(flags, time)				\
 	(flags & CXL_POISON_FLAG_OVERFLOW ? le64_to_cpu(time) : 0)
 
+u64 cxl_trace_hpa(struct cxl_region *cxlr, struct cxl_memdev *memdev, u64 dpa);
+
 TRACE_EVENT(cxl_poison,
 
 	TP_PROTO(struct cxl_memdev *cxlmd, struct cxl_region *region,
@@ -651,6 +653,7 @@ TRACE_EVENT(cxl_poison,
 		__field(u8, trace_type)
 		__string(region, region)
 		__field(u64, overflow_t)
+		__field(u64, hpa)
 		__field(u64, dpa)
 		__field(u32, dpa_length)
 		__array(char, uuid, 16)
@@ -671,21 +674,25 @@ TRACE_EVENT(cxl_poison,
 		if (region) {
 			__assign_str(region, dev_name(&region->dev));
 			memcpy(__entry->uuid, &region->params.uuid, 16);
+			__entry->hpa = cxl_trace_hpa(region, cxlmd,
+						     __entry->dpa);
 		} else {
 			__assign_str(region, "");
 			memset(__entry->uuid, 0, 16);
+			__entry->hpa = ULLONG_MAX;
 		}
 	    ),
 
 	TP_printk("memdev=%s host=%s serial=%lld trace_type=%s region=%s "  \
-		"region_uuid=%pU dpa=0x%llx dpa_length=0x%x source=%s "     \
-		"flags=%s overflow_time=%llu",
+		"region_uuid=%pU hpa=0x%llx dpa=0x%llx dpa_length=0x%x "    \
+		"source=%s flags=%s overflow_time=%llu",
 		__get_str(memdev),
 		__get_str(host),
 		__entry->serial,
 		show_poison_trace_type(__entry->trace_type),
 		__get_str(region),
 		__entry->uuid,
+		__entry->hpa,
 		__entry->dpa,
 		__entry->dpa_length,
 		show_poison_source(__entry->source),
Signature · 1 line
2.37.3
author maintainer
#22 lore raw

PATCH v12 6/6 tools/testing/cxl: Mock support for Get Poison List

In reply to [email protected]

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.

---
 tools/testing/cxl/test/mem.c | 42 ++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
tools/testing/cxl/test/mem.c +42 -0
index 9263b04d35f7..cf7975db05ed 100644
@@ -7,6 +7,7 @@
 #include <linux/delay.h>
 #include <linux/sizes.h>
 #include <linux/bits.h>
+#include <asm/unaligned.h>
 #include <cxlmem.h>
 
 #include "trace.h"
@@ -40,6 +41,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 */
@@ -471,6 +476,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;
 
@@ -888,6 +895,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_in *pi = cmd->payload_in;
+
+	/* Mock one poison record at pi.offset for 64 bytes */
+	struct {
+		struct cxl_mbox_poison_out po;
+		struct cxl_poison_record record;
+	} __packed mock_plist = {
+		.po = {
+			.count = cpu_to_le16(1),
+		},
+		.record = {
+			.length = cpu_to_le32(1),
+			.address = cpu_to_le64(le64_to_cpu(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;
@@ -942,6 +977,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;
 	}
@@ -1010,6 +1048,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;
Signature · 1 line
2.37.3
#2 lore raw

RE: [PATCH v12 1/6] cxl/mbox: Add GET_POISON_LIST mailbox command

In reply to [email protected]
Quoted 43 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 poison list.

---
 drivers/cxl/core/mbox.c | 71 +++++++++++++++++++++++++++++++++++++++++
 drivers/cxl/cxlmem.h    | 67 ++++++++++++++++++++++++++++++++++++++
 drivers/cxl/pci.c       |  4 +++
 3 files changed, 142 insertions(+)
drivers/cxl/core/mbox.c +3 -0
index f2addb457172..69a5d69dd53b 100644
@@ -5,6 +5,8 @@
 #include <linux/debugfs.h>
 #include <linux/ktime.h>
 #include <linux/mutex.h>
+#include <asm/unaligned.h>
+#include <cxlpci.h>
 #include <cxlmem.h>
 #include <cxl.h>
 
@@ -994,6 +996,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) {

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

Quoted 8 lines
drivers/cxl/core/mbox.c +5 -0
@@ -1017,6 +1020,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_errors = min_t(u32, val, CXL_POISON_LIST_MAX);
+	}
+

With this new interface I do not expect we want to support user tooling that wants to retrieve the list via ioctl. So I think this wants a lead-in patch that deprecates the poison command support so that the linux-cxl community only has one mechanism to maintain going forward.

Something like the below as a lead-in, and then you would add code to cxl_walk_cel() to set a flag for the "get poison" machinery.

-- >8 --
From f2cd1d1e09fe6f36255f3b8cd831b2b4903045d4 Mon Sep 17 00:00:00 2001
From: Dan Williams <[email protected]>
Date: Tue, 11 Apr 2023 17:48:45 -0700
Subject: [PATCH] cxl/mbox: Deprecate poison commands

The CXL subsystem is adding a formal mechanism for retrieving the poison list. Minimize the maintenance burden going forward, and maximize the investment in common tooling by deprecating direct user access to issue this command outside of CXL_MEM_RAW_COMMANDS debug scenarios.

A new cxl_deprecated_commands[] list is created for querying which command ids defined in previous kernels are now deprecated.

Effectively all of the commands defined in:

87815ee9d006 ("cxl/pci: Add media provisioning required commands")

...were defined prematurely and should have waited until the kernel implementation was decided. To my knowledge there are no shipping devices with poison listing support and no known tools that would regress with this change.

---
 drivers/cxl/core/mbox.c      |  3 ---
 include/uapi/linux/cxl_mem.h | 31 ++++++++++++++++++++++++++++---
 2 files changed, 28 insertions(+), 6 deletions(-)
drivers/cxl/core/mbox.c +0 -3
index f2addb457172..8e24038b8769 100644
@@ -61,9 +61,6 @@ static struct cxl_mem_command cxl_mem_commands[CXL_MEM_COMMAND_ID_MAX] = {
 	CXL_CMD(SET_ALERT_CONFIG, 0xc, 0, 0),
 	CXL_CMD(GET_SHUTDOWN_STATE, 0, 0x1, 0),
 	CXL_CMD(SET_SHUTDOWN_STATE, 0x1, 0, 0),
-	CXL_CMD(GET_POISON, 0x10, CXL_VARIABLE_PAYLOAD, 0),
-	CXL_CMD(INJECT_POISON, 0x8, 0, 0),
-	CXL_CMD(CLEAR_POISON, 0x48, 0, 0),
 	CXL_CMD(GET_SCAN_MEDIA_CAPS, 0x10, 0x4, 0),
 	CXL_CMD(SCAN_MEDIA, 0x11, 0, 0),
 	CXL_CMD(GET_SCAN_MEDIA, 0, CXL_VARIABLE_PAYLOAD, 0),
include/uapi/linux/cxl_mem.h +28 -3
index 86bbacf2a315..90f17343f1ba 100644
@@ -40,19 +40,22 @@
 	___C(SET_ALERT_CONFIG, "Set Alert Configuration"),                \
 	___C(GET_SHUTDOWN_STATE, "Get Shutdown State"),                   \
 	___C(SET_SHUTDOWN_STATE, "Set Shutdown State"),                   \
-	___C(GET_POISON, "Get Poison List"),                              \
-	___C(INJECT_POISON, "Inject Poison"),                             \
-	___C(CLEAR_POISON, "Clear Poison"),                               \
+	___DEPRECATED(GET_POISON, "Get Poison List"),                     \
+	___DEPRECATED(INJECT_POISON, "Inject Poison"),                    \
+	___DEPRECATED(CLEAR_POISON, "Clear Poison"),                      \
 	___C(GET_SCAN_MEDIA_CAPS, "Get Scan Media Capabilities"),         \
 	___C(SCAN_MEDIA, "Scan Media"),                                   \
 	___C(GET_SCAN_MEDIA, "Get Scan Media Results"),                   \
 	___C(MAX, "invalid / last command")
 
 #define ___C(a, b) CXL_MEM_COMMAND_ID_##a
+#define ___DEPRECATED(a, b) CXL_MEM_DEPRECATED_ID_##a
 enum { CXL_CMDS };
 
 #undef ___C
+#undef ___DEPRECATED
 #define ___C(a, b) { b }
+#define ___DEPRECATED(a, b) { "Deprecated " b }
 static const struct {
 	const char *name;
 } cxl_command_names[] __attribute__((__unused__)) = { CXL_CMDS };
@@ -68,6 +71,28 @@ static const struct {
  */
 
 #undef ___C
+#undef ___DEPRECATED
+#define ___C(a, b) (0)
+#define ___DEPRECATED(a, b) (1)
+
+static const u8 cxl_deprecated_commands[]
+	__attribute__((__unused__)) = { CXL_CMDS };
+
+/*
+ * Here's how this actually breaks out:
+ * cxl_deprecated_commands[] = {
+ *	[CXL_MEM_COMMAND_ID_INVALID] = 0,
+ *	[CXL_MEM_COMMAND_ID_IDENTIFY] = 0,
+ *	...
+ *	[CXL_MEM_DEPRECATED_ID_GET_POISON] = 1,
+ *	[CXL_MEM_DEPRECATED_ID_INJECT_POISON] = 1,
+ *	[CXL_MEM_DEPRECATED_ID_CLEAR_POISON] = 1,
+ *	...
+ * };
+ */
+
+#undef ___C
+#undef ___DEPRECATED
 
 /**
  * struct cxl_command_info - Command information returned from a query.
Signature · 2 lines
2.39.2
-- 8< --
Quoted 52 lines
drivers/cxl/core/mbox.c +45 -0
 	return 0;
 }
 EXPORT_SYMBOL_NS_GPL(cxl_dev_state_identify, CXL);
@@ -1107,6 +1115,69 @@ int cxl_set_timestamp(struct cxl_dev_state *cxlds)
 }
 EXPORT_SYMBOL_NS_GPL(cxl_set_timestamp, 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_mbox_poison_out *po;
+	struct cxl_mbox_poison_in pi;
+	struct cxl_mbox_cmd mbox_cmd;
+	int nr_records = 0;
+	int rc;
+
+	rc = mutex_lock_interruptible(&cxlds->poison.lock);
+	if (rc)
+		return rc;
+
+	po = cxlds->poison.list_out;
+	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 >= cxlds->poison.max_errors) {
+			dev_dbg(&cxlmd->dev, "Max Error Records reached: %d\n",
+				nr_records);
+			break;
+		}
+	} while (po->flags & CXL_POISON_FLAG_MORE);
+
+	mutex_unlock(&cxlds->poison.lock);
+	return rc;

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

Quoted 10 lines
drivers/cxl/core/mbox.c +10 -0
+}
+EXPORT_SYMBOL_NS_GPL(cxl_mem_get_poison, CXL);
+
+int cxl_poison_state_init(struct cxl_dev_state *cxlds)
+{
+	if (!test_bit(CXL_MEM_COMMAND_ID_GET_POISON, cxlds->enabled_cmds))
+		return 0;
+
+	cxlds->poison.list_out = devm_kzalloc(cxlds->dev, cxlds->payload_size,
+					      GFP_KERNEL);

Given the payload can be multiple pages in size use kvmalloc() like cxl_mem_alloc_event_buf().

Quoted 60 lines
drivers/cxl/core/mbox.c +8 -0
+	if (!cxlds->poison.list_out)
+		return -ENOMEM;
+
+	mutex_init(&cxlds->poison.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;
drivers/cxl/cxlmem.h +20 -0
index ccbafc05a636..a3033c8dd8e2 100644
@@ -215,6 +215,24 @@ struct cxl_event_state {
 	struct mutex log_lock;
 };
 
+/**
+ * struct cxl_poison_state - Driver poison state info
+ *
+ * @max_errors: Maximum media error records held in device cache
+ * @list_out: The poison list payload returned by device
+ * @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_errors;
+	struct cxl_mbox_poison_out *list_out;
+	struct mutex lock;  /* Protect reads of poison list */
+};
+
 /**
  * struct cxl_dev_state - The driver device state
  *
@@ -251,6 +269,7 @@ struct cxl_event_state {
  * @serial: PCIe Device Serial Number
  * @doe_mbs: PCI DOE mailbox array
  * @event: event log driver state
+ * @poison: poison driver state info
  * @mbox_send: @dev specific transport for transmitting mailbox commands
  *
  * See section 8.2.9.5.2 Capacity Configuration and Label Storage for
@@ -290,6 +309,7 @@ struct cxl_dev_state {
 	struct xarray doe_mbs;
 
 	struct cxl_event_state event;
+	struct cxl_poison_state poison;
 
 	int (*mbox_send)(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd);
 };
@@ -538,6 +558,50 @@ struct cxl_mbox_set_timestamp_in {
 
 } __packed;
 

drivers/cxl/cxlmem.h struct cxl_mbox_set_timestamp_in { · line 570

Quoted 10 lines
drivers/cxl/cxlmem.h +10 -0
+/* Get Poison List  CXL 3.0 Spec 8.2.9.8.4.1 */
+struct cxl_mbox_poison_in {
+	__le64 offset;
+	__le64 length;
+} __packed;
+
+struct cxl_mbox_poison_out {
+	u8 flags;
+	u8 rsvd1;
+	__le64 overflow_t;

I was wondering what the "_t" meant, I always read that as "type". Perhaps "_ts" or even just spell out "_timestamp".

Aside from the minor fixups and reworking the enumeration mechanism per above, this looks good to me.

author maintainer
#3 lore raw

Re: [PATCH v12 1/6] cxl/mbox: Add GET_POISON_LIST mailbox command

Quoted 58 lines · Dan Williams
Quoted 43 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 poison list.

---
 drivers/cxl/core/mbox.c | 71 +++++++++++++++++++++++++++++++++++++++++
 drivers/cxl/cxlmem.h    | 67 ++++++++++++++++++++++++++++++++++++++
 drivers/cxl/pci.c       |  4 +++
 3 files changed, 142 insertions(+)
drivers/cxl/core/mbox.c +3 -0
index f2addb457172..69a5d69dd53b 100644
@@ -5,6 +5,8 @@
 #include <linux/debugfs.h>
 #include <linux/ktime.h>
 #include <linux/mutex.h>
+#include <asm/unaligned.h>
+#include <cxlpci.h>
 #include <cxlmem.h>
 #include <cxl.h>
 
@@ -994,6 +996,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) {

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

Quoted 8 lines
drivers/cxl/core/mbox.c +5 -0
@@ -1017,6 +1020,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_errors = min_t(u32, val, CXL_POISON_LIST_MAX);
+	}
+

With this new interface I do not expect we want to support user tooling that wants to retrieve the list via ioctl. So I think this wants a lead-in patch that deprecates the poison command support so that the linux-cxl community only has one mechanism to maintain going forward.

Quoted 2 lines

Something like the below as a lead-in, and then you would add code to cxl_walk_cel() to set a flag for the "get poison" machinery.

In the inject & clear series, I made the commands kernel exclusive (and also blocked their usage in raw mode).

https://lore.kernel.org/linux-cxl/[email protected]/T/#m5b86f3e88ee7ad5b92843babdb9fd41b7f03cf36

Is that not enough or not the right protection?

Alison

Quoted 249 lines

-- >8 --
From f2cd1d1e09fe6f36255f3b8cd831b2b4903045d4 Mon Sep 17 00:00:00 2001
From: Dan Williams <[email protected]>
Date: Tue, 11 Apr 2023 17:48:45 -0700
Subject: [PATCH] cxl/mbox: Deprecate poison commands

The CXL subsystem is adding a formal mechanism for retrieving the poison list. Minimize the maintenance burden going forward, and maximize the investment in common tooling by deprecating direct user access to issue this command outside of CXL_MEM_RAW_COMMANDS debug scenarios.

A new cxl_deprecated_commands[] list is created for querying which command ids defined in previous kernels are now deprecated.

Effectively all of the commands defined in:

87815ee9d006 ("cxl/pci: Add media provisioning required commands")

...were defined prematurely and should have waited until the kernel implementation was decided. To my knowledge there are no shipping devices with poison listing support and no known tools that would regress with this change.

---
 drivers/cxl/core/mbox.c      |  3 ---
 include/uapi/linux/cxl_mem.h | 31 ++++++++++++++++++++++++++++---
 2 files changed, 28 insertions(+), 6 deletions(-)
drivers/cxl/core/mbox.c +0 -3
index f2addb457172..8e24038b8769 100644
@@ -61,9 +61,6 @@ static struct cxl_mem_command cxl_mem_commands[CXL_MEM_COMMAND_ID_MAX] = {
 	CXL_CMD(SET_ALERT_CONFIG, 0xc, 0, 0),
 	CXL_CMD(GET_SHUTDOWN_STATE, 0, 0x1, 0),
 	CXL_CMD(SET_SHUTDOWN_STATE, 0x1, 0, 0),
-	CXL_CMD(GET_POISON, 0x10, CXL_VARIABLE_PAYLOAD, 0),
-	CXL_CMD(INJECT_POISON, 0x8, 0, 0),
-	CXL_CMD(CLEAR_POISON, 0x48, 0, 0),
 	CXL_CMD(GET_SCAN_MEDIA_CAPS, 0x10, 0x4, 0),
 	CXL_CMD(SCAN_MEDIA, 0x11, 0, 0),
 	CXL_CMD(GET_SCAN_MEDIA, 0, CXL_VARIABLE_PAYLOAD, 0),
include/uapi/linux/cxl_mem.h +28 -3
index 86bbacf2a315..90f17343f1ba 100644
@@ -40,19 +40,22 @@
 	___C(SET_ALERT_CONFIG, "Set Alert Configuration"),                \
 	___C(GET_SHUTDOWN_STATE, "Get Shutdown State"),                   \
 	___C(SET_SHUTDOWN_STATE, "Set Shutdown State"),                   \
-	___C(GET_POISON, "Get Poison List"),                              \
-	___C(INJECT_POISON, "Inject Poison"),                             \
-	___C(CLEAR_POISON, "Clear Poison"),                               \
+	___DEPRECATED(GET_POISON, "Get Poison List"),                     \
+	___DEPRECATED(INJECT_POISON, "Inject Poison"),                    \
+	___DEPRECATED(CLEAR_POISON, "Clear Poison"),                      \
 	___C(GET_SCAN_MEDIA_CAPS, "Get Scan Media Capabilities"),         \
 	___C(SCAN_MEDIA, "Scan Media"),                                   \
 	___C(GET_SCAN_MEDIA, "Get Scan Media Results"),                   \
 	___C(MAX, "invalid / last command")
 
 #define ___C(a, b) CXL_MEM_COMMAND_ID_##a
+#define ___DEPRECATED(a, b) CXL_MEM_DEPRECATED_ID_##a
 enum { CXL_CMDS };
 
 #undef ___C
+#undef ___DEPRECATED
 #define ___C(a, b) { b }
+#define ___DEPRECATED(a, b) { "Deprecated " b }
 static const struct {
 	const char *name;
 } cxl_command_names[] __attribute__((__unused__)) = { CXL_CMDS };
@@ -68,6 +71,28 @@ static const struct {
  */
 
 #undef ___C
+#undef ___DEPRECATED
+#define ___C(a, b) (0)
+#define ___DEPRECATED(a, b) (1)
+
+static const u8 cxl_deprecated_commands[]
+	__attribute__((__unused__)) = { CXL_CMDS };
+
+/*
+ * Here's how this actually breaks out:
+ * cxl_deprecated_commands[] = {
+ *	[CXL_MEM_COMMAND_ID_INVALID] = 0,
+ *	[CXL_MEM_COMMAND_ID_IDENTIFY] = 0,
+ *	...
+ *	[CXL_MEM_DEPRECATED_ID_GET_POISON] = 1,
+ *	[CXL_MEM_DEPRECATED_ID_INJECT_POISON] = 1,
+ *	[CXL_MEM_DEPRECATED_ID_CLEAR_POISON] = 1,
+ *	...
+ * };
+ */
+
+#undef ___C
+#undef ___DEPRECATED
 
 /**
  * struct cxl_command_info - Command information returned from a query.
Signature · 2 lines
2.39.2
-- 8< --
Quoted 52 lines
drivers/cxl/core/mbox.c +45 -0
 	return 0;
 }
 EXPORT_SYMBOL_NS_GPL(cxl_dev_state_identify, CXL);
@@ -1107,6 +1115,69 @@ int cxl_set_timestamp(struct cxl_dev_state *cxlds)
 }
 EXPORT_SYMBOL_NS_GPL(cxl_set_timestamp, 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_mbox_poison_out *po;
+	struct cxl_mbox_poison_in pi;
+	struct cxl_mbox_cmd mbox_cmd;
+	int nr_records = 0;
+	int rc;
+
+	rc = mutex_lock_interruptible(&cxlds->poison.lock);
+	if (rc)
+		return rc;
+
+	po = cxlds->poison.list_out;
+	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 >= cxlds->poison.max_errors) {
+			dev_dbg(&cxlmd->dev, "Max Error Records reached: %d\n",
+				nr_records);
+			break;
+		}
+	} while (po->flags & CXL_POISON_FLAG_MORE);
+
+	mutex_unlock(&cxlds->poison.lock);
+	return rc;

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

Quoted 10 lines
drivers/cxl/core/mbox.c +10 -0
+}
+EXPORT_SYMBOL_NS_GPL(cxl_mem_get_poison, CXL);
+
+int cxl_poison_state_init(struct cxl_dev_state *cxlds)
+{
+	if (!test_bit(CXL_MEM_COMMAND_ID_GET_POISON, cxlds->enabled_cmds))
+		return 0;
+
+	cxlds->poison.list_out = devm_kzalloc(cxlds->dev, cxlds->payload_size,
+					      GFP_KERNEL);

Given the payload can be multiple pages in size use kvmalloc() like cxl_mem_alloc_event_buf().

Quoted 60 lines
drivers/cxl/core/mbox.c +8 -0
+	if (!cxlds->poison.list_out)
+		return -ENOMEM;
+
+	mutex_init(&cxlds->poison.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;
drivers/cxl/cxlmem.h +20 -0
index ccbafc05a636..a3033c8dd8e2 100644
@@ -215,6 +215,24 @@ struct cxl_event_state {
 	struct mutex log_lock;
 };
 
+/**
+ * struct cxl_poison_state - Driver poison state info
+ *
+ * @max_errors: Maximum media error records held in device cache
+ * @list_out: The poison list payload returned by device
+ * @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_errors;
+	struct cxl_mbox_poison_out *list_out;
+	struct mutex lock;  /* Protect reads of poison list */
+};
+
 /**
  * struct cxl_dev_state - The driver device state
  *
@@ -251,6 +269,7 @@ struct cxl_event_state {
  * @serial: PCIe Device Serial Number
  * @doe_mbs: PCI DOE mailbox array
  * @event: event log driver state
+ * @poison: poison driver state info
  * @mbox_send: @dev specific transport for transmitting mailbox commands
  *
  * See section 8.2.9.5.2 Capacity Configuration and Label Storage for
@@ -290,6 +309,7 @@ struct cxl_dev_state {
 	struct xarray doe_mbs;
 
 	struct cxl_event_state event;
+	struct cxl_poison_state poison;
 
 	int (*mbox_send)(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd);
 };
@@ -538,6 +558,50 @@ struct cxl_mbox_set_timestamp_in {
 
 } __packed;
 

drivers/cxl/cxlmem.h struct cxl_mbox_set_timestamp_in { · line 570

Quoted 10 lines
drivers/cxl/cxlmem.h +10 -0
+/* Get Poison List  CXL 3.0 Spec 8.2.9.8.4.1 */
+struct cxl_mbox_poison_in {
+	__le64 offset;
+	__le64 length;
+} __packed;
+
+struct cxl_mbox_poison_out {
+	u8 flags;
+	u8 rsvd1;
+	__le64 overflow_t;

I was wondering what the "_t" meant, I always read that as "type". Perhaps "_ts" or even just spell out "_timestamp".

Aside from the minor fixups and reworking the enumeration mechanism per above, this looks good to me.

#4 lore raw

Re: [PATCH v12 1/6] cxl/mbox: Add GET_POISON_LIST mailbox command

Quoted 62 lines · Alison Schofield
Quoted 58 lines · Dan Williams
Quoted 43 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 poison list.

---
 drivers/cxl/core/mbox.c | 71 +++++++++++++++++++++++++++++++++++++++++
 drivers/cxl/cxlmem.h    | 67 ++++++++++++++++++++++++++++++++++++++
 drivers/cxl/pci.c       |  4 +++
 3 files changed, 142 insertions(+)
drivers/cxl/core/mbox.c +3 -0
index f2addb457172..69a5d69dd53b 100644
@@ -5,6 +5,8 @@
 #include <linux/debugfs.h>
 #include <linux/ktime.h>
 #include <linux/mutex.h>
+#include <asm/unaligned.h>
+#include <cxlpci.h>
 #include <cxlmem.h>
 #include <cxl.h>
 
@@ -994,6 +996,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) {

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

Quoted 8 lines
drivers/cxl/core/mbox.c +5 -0
@@ -1017,6 +1020,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_errors = min_t(u32, val, CXL_POISON_LIST_MAX);
+	}
+

With this new interface I do not expect we want to support user tooling that wants to retrieve the list via ioctl. So I think this wants a lead-in patch that deprecates the poison command support so that the linux-cxl community only has one mechanism to maintain going forward.

Quoted 2 lines

Something like the below as a lead-in, and then you would add code to cxl_walk_cel() to set a flag for the "get poison" machinery.

Quoted 6 lines

In the inject & clear series, I made the commands kernel exclusive (and also blocked their usage in raw mode).

https://lore.kernel.org/linux-cxl/[email protected]/T/#m5b86f3e88ee7ad5b92843babdb9fd41b7f03cf36

Is that not enough or not the right protection?

I think I'm having deja vu and maybe we talked about this already and I forgot the outcome?

The concern is having a consistent approach across the commands that are valid from userspace all the time, those that are valid sometimes (temporarily marked exclusive), and those that are unsupported from userspace (unsupported via raw command being a special case of that).

For recent new mailbox functionality like CXL_MBOX_OP_GET_EVENT_RECORD and the DCD commands, that are only expected to be executed from the kernel, those are kept out of the CXL_CMDS list, not marked exclusive.

The commands marked exclusive like the label commands return EBUSY, but only while libnvdimm owns the label area. If libnvdimm is disconnected (echo pmemX > /sys/bus/cxl/drivers/cxl_pmem/unbind), then those commands stop being exclusive.

So, I think I want to keep "exclusive" as a set of commands that are suitable to build into a user tool just that the tool needs to know the rules about when those commands might be busy.

For poison the user tool is expected to use sysfs + trace-events, so including it in the list of available commands returned by CXL_MEM_QUERY_COMMANDS only to never be able to execute it seems wrong.

Marking it deprecated as a "whoops" feels more honest and brings it in line with the other commands that are permanently kernel exclusive.

#14 lore raw

RE: [PATCH v12 3/6] cxl/memdev: Add trigger_poison_list sysfs attribute

In reply to [email protected]
Quoted 70 lines · 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 events when cxl_poison event tracing is enabled.

---
 Documentation/ABI/testing/sysfs-bus-cxl | 14 ++++++++
 drivers/cxl/core/memdev.c               | 48 +++++++++++++++++++++++++
 drivers/cxl/cxlmem.h                    |  5 ++-
 drivers/cxl/mem.c                       | 36 +++++++++++++++++++
 4 files changed, 102 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-bus-cxl +14 -0
index 3acf2f17a73f..48ac0d911801 100644
@@ -415,3 +415,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:		April, 2023
+KernelVersion:	v6.4
+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
+		events when cxl_poison event tracing is enabled.
drivers/cxl/core/memdev.c +21 -0
index 0af8856936dc..297d87ebaca6 100644
@@ -106,6 +106,53 @@ static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(numa_node);
 
+static int cxl_get_poison_by_memdev(struct cxl_memdev *cxlmd)
+{
+	struct cxl_dev_state *cxlds = cxlmd->cxlds;
+	u64 offset, length;
+	int rc = 0;
+
+	/* 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.

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

Quoted 10 lines
drivers/cxl/core/memdev.c +10 -0
+		 */
+		if (rc == -EFAULT)
+			rc = 0;
+	}
+	return rc;
+}
+
+ssize_t cxl_trigger_poison_list(struct device *dev,
+				struct device_attribute *attr,
+				const char *buf, size_t len)

The @attr argument is unused, it can be dropped.

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

Quoted 2 lines
drivers/cxl/core/memdev.c +2 -0
+{
+	struct cxl_memdev *cxlmd = to_cxl_memdev(dev);

The caller can do this conversion.

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

Quoted 5 lines
drivers/cxl/core/memdev.c +5 -0
+	bool trigger;
+	ssize_t rc;
+
+	if (kstrtobool(buf, &trigger) || !trigger)
+		return -EINVAL;

Hmm, the caller could to this too...

...the below seems to be the bit that the cxl_core cares about handling.

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

Quoted 2 lines
drivers/cxl/core/memdev.c +2 -0
+
+	down_read(&cxl_dpa_rwsem);

down_read_interruptible() since this is coming from userspace.

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

Quoted 4 lines
drivers/cxl/core/memdev.c +4 -0
+	rc = cxl_get_poison_by_memdev(cxlmd);
+	up_read(&cxl_dpa_rwsem);
+
+	return rc ? rc : len;

The caller can do this conversion.

drivers/cxl/core/memdev.c static umode_t cxl_memdev_visible(struct kobject *kobj, struct attribute *a, · line 180

Quoted 11 lines
drivers/cxl/core/memdev.c +4 -0
+}
+EXPORT_SYMBOL_NS_GPL(cxl_trigger_poison_list, CXL);
+
 static struct attribute *cxl_memdev_attributes[] = {
 	&dev_attr_serial.attr,
 	&dev_attr_firmware_version.attr,
@@ -130,6 +177,7 @@ 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;
+

I am surprised that Jonathan let this slide :).

Quoted 3 lines
drivers/cxl/core/memdev.c +0 -0
 	return a->mode;
 }
 
#18 lore raw

RE: [PATCH v12 4/6] cxl/region: Provide region info to the cxl_poison trace event

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

From: Alison Schofield <[email protected]>

User space may need to know which region, if any, maps the poison address(es) logged in a cxl_poison trace event. Since the mapping of DPAs (device physical addresses) to a region can change, the kernel must provide this information at the time the poison list is read. The event informs user space that at event <timestamp> this <region> mapped to this <DPA>, which is poisoned.

The cxl_poison trace event is already wired up to log the region name and uuid if it receives param 'struct cxl_region'.

In order to provide that cxl_region, add another method for gathering poison - by committed endpoint decoder mappings. This method is only available with CONFIG_CXL_REGION and is only used if a region actually maps the memdev where poison is being read. After the region driver reads the poison list for all the mapped resources, control returns to the memdev driver, where poison is read for any remaining unmapped resources.

Mixed mode decoders are not currently supported in Linux. Add a debug message to the poison request path. That will serve as an alert that poison list retrieval needs to add support for mixed mode.

The default method remains: read the poison by memdev resource.

---
 drivers/cxl/core/core.h   | 11 +++++++
 drivers/cxl/core/memdev.c | 62 +++++++++++++++++++++++++++++++++++++-
 drivers/cxl/core/region.c | 63 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 135 insertions(+), 1 deletion(-)
drivers/cxl/core/core.h +0 -0
index e888e293943e..57bd22e01a0b 100644

drivers/cxl/core/core.h void cxl_decoder_kill_region(struct cxl_endpoint_decoder *cxled); · line 33

Quoted 9 lines
drivers/cxl/core/core.h +5 -0
@@ -25,7 +25,12 @@ void cxl_decoder_kill_region(struct cxl_endpoint_decoder *cxled);
 #define CXL_DAX_REGION_TYPE(x) (&cxl_dax_region_type)
 int cxl_region_init(void);
 void cxl_region_exit(void);
+int cxl_get_poison_by_endpoint(struct device *dev, void *data);
 #else
+static inline int cxl_get_poison_by_endpoint(struct device *dev, void *data)
+{
+	return 0;
+}

For a public function the lack of type safety jumps out at me... more below:

Quoted 86 lines
drivers/cxl/core/core.h +6 -0
 static inline void cxl_decoder_kill_region(struct cxl_endpoint_decoder *cxled)
 {
 }
@@ -68,4 +73,10 @@ enum cxl_poison_trace_type {
 	CXL_POISON_TRACE_LIST,
 };
 
+struct cxl_trigger_poison_context {
+	struct cxl_port *port;
+	enum cxl_decoder_mode mode;
+	u64 offset;
+};
+
 #endif /* __CXL_CORE_H__ */
drivers/cxl/core/memdev.c +49 -1
index 297d87ebaca6..f26b5b6cda10 100644
@@ -106,6 +106,47 @@ static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(numa_node);
 
+static int cxl_get_poison_unmapped(struct cxl_memdev *cxlmd,
+				   struct cxl_trigger_poison_context *ctx)
+{
+	struct cxl_dev_state *cxlds = cxlmd->cxlds;
+	u64 offset, length;
+	int rc = 0;
+
+	/*
+	 * Collect poison for the remaining unmapped resources
+	 * after poison is collected by committed endpoints.
+	 *
+	 * Knowing that PMEM must always follow RAM, get poison
+	 * for unmapped resources based on the last decoder's mode:
+	 *	ram: scan remains of ram range, then any pmem range
+	 *	pmem: scan remains of pmem range
+	 */
+
+	if (ctx->mode == CXL_DECODER_RAM) {
+		offset = ctx->offset;
+		length = resource_size(&cxlds->ram_res) - offset;
+		rc = cxl_mem_get_poison(cxlmd, offset, length, NULL);
+		if (rc == -EFAULT)
+			rc = 0;
+		if (rc)
+			return rc;
+	}
+	if (ctx->mode == CXL_DECODER_PMEM) {
+		offset = ctx->offset;
+		length = resource_size(&cxlds->dpa_res) - offset;
+		if (!length)
+			return 0;
+	} else if (resource_size(&cxlds->pmem_res)) {
+		offset = cxlds->pmem_res.start;
+		length = resource_size(&cxlds->pmem_res);
+	} else {
+		return 0;
+	}
+
+	return cxl_mem_get_poison(cxlmd, offset, length, NULL);
+}
+
 static int cxl_get_poison_by_memdev(struct cxl_memdev *cxlmd)
 {
 	struct cxl_dev_state *cxlds = cxlmd->cxlds;
@@ -139,14 +180,33 @@ ssize_t cxl_trigger_poison_list(struct device *dev,
 				const char *buf, size_t len)
 {
 	struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
+	struct cxl_trigger_poison_context ctx;
+	struct cxl_port *port;
 	bool trigger;
 	ssize_t rc;
 
 	if (kstrtobool(buf, &trigger) || !trigger)
 		return -EINVAL;
 
+	port = dev_get_drvdata(&cxlmd->dev);
+	if (!port || !is_cxl_endpoint(port))
+		return -EINVAL;
+
 	down_read(&cxl_dpa_rwsem);
-	rc = cxl_get_poison_by_memdev(cxlmd);
+	if (port->commit_end == -1) {
+		/* No regions mapped to this memdev */

drivers/cxl/core/memdev.c ssize_t cxl_trigger_poison_list(struct device *dev, · line 207

Quoted 10 lines
drivers/cxl/core/memdev.c +10 -0
+		rc = cxl_get_poison_by_memdev(cxlmd);
+	} else {
+		/* Regions mapped, collect poison by endpoint */
+		ctx = (struct cxl_trigger_poison_context) {
+			.port = port,
+		};
+		rc = device_for_each_child(&port->dev, &ctx,
+					   cxl_get_poison_by_endpoint);
+		if (rc == 1)
+			rc = cxl_get_poison_unmapped(cxlmd, &ctx);

Ah, cxl_get_poison_by_endpoint() is a function pointer to device_for_each_child(), that really feels like a detail that's private to the implementation.

I would reorganize this to something like:

     if (port->commit_end == -1) {
             /* No regions mapped to this memdev */
             rc = cxl_get_poison_by_memdev(cxlmd);
     } else {
             /* Regions mapped, collect poison by endpoint */
             rc = cxl_get_poison_by_endpoint(endpoint);
     }

...and then internal to cxl_get_poison_by_endpoint() do:

             ctx = (struct cxl_trigger_poison_context) {
                     .port = endpoint,
             };
             rc = device_for_each_child(&port->dev, &ctx,
                                        poison_by_decoder);
             if (rc == 1)
                     rc = cxl_get_poison_unmapped(cxlmd, &ctx);

...then the header file reads more calmly with the added type-safety.

Quoted 29 lines
drivers/cxl/core/memdev.c +2 -0
+	}
+
 	up_read(&cxl_dpa_rwsem);
 
 	return rc ? rc : len;
drivers/cxl/core/region.c +16 -0
index f29028148806..4c4d3a6d631d 100644
@@ -2213,6 +2213,69 @@ struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev)
 }
 EXPORT_SYMBOL_NS_GPL(to_cxl_pmem_region, CXL);
 
+int cxl_get_poison_by_endpoint(struct device *dev, void *arg)
+{
+	struct cxl_trigger_poison_context *ctx = arg;
+	struct cxl_endpoint_decoder *cxled;
+	struct cxl_port *port = ctx->port;
+	struct cxl_memdev *cxlmd;
+	u64 offset, length;
+	int rc = 0;
+
+	down_read(&cxl_region_rwsem);
+
+	if (!is_endpoint_decoder(dev))
+		goto out;
+
+	cxled = to_cxl_endpoint_decoder(dev);
+	if (!cxled->dpa_res || !resource_size(cxled->dpa_res))

drivers/cxl/core/region.c struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev) · line 2241

Quoted 10 lines
drivers/cxl/core/region.c +10 -0
+		goto out;
+
+	/*
+	 * Regions are only created with single mode decoders: pmem or ram.
+	 * Linux does not currently support mixed mode decoders. This means
+	 * that reading poison per endpoint decoder adheres to the spec
+	 * requirement that poison reads of pmem and ram must be separated.
+	 * CXL 3.0 Spec 8.2.9.8.4.1
+	 *
+	 * Watch for future support of mixed with a dev_dbg() msg.

This sentence can go, mixed will never* be supported.

* at least until the vendor that manages to ship such a thing comes and explains why the kernel needs to work around that awkwardness.

Quoted 43 lines
drivers/cxl/core/region.c +37 -0
+	 */
+	if (cxled->mode == CXL_DECODER_MIXED) {
+		dev_dbg(dev, "poison list read unsupported in mixed mode\n");
+		goto out;
+	}
+
+	cxlmd = cxled_to_memdev(cxled);
+	if (cxled->skip) {
+		offset = cxled->dpa_res->start - cxled->skip;
+		length = cxled->skip;
+		rc = cxl_mem_get_poison(cxlmd, offset, length, NULL);
+		if (rc == -EFAULT && cxled->mode == CXL_DECODER_RAM)
+			rc = 0;
+		if (rc)
+			goto out;
+	}
+
+	offset = cxled->dpa_res->start;
+	length = cxled->dpa_res->end - offset + 1;
+	rc = cxl_mem_get_poison(cxlmd, offset, length, cxled->cxld.region);
+	if (rc == -EFAULT && cxled->mode == CXL_DECODER_RAM)
+		rc = 0;
+	if (rc)
+		goto out;
+
+	/* Iterate until commit_end is reached */
+	if (cxled->cxld.id == port->commit_end)
+		rc = 1;
+
+	/* ctx informs the memdev driver of last read poison */
+	ctx->mode = cxled->mode;
+	ctx->offset = cxled->dpa_res->end + 1;
+out:
+	up_read(&cxl_region_rwsem);
+	return rc;
+}
+
 static struct lock_class_key cxl_pmem_region_key;
 
 static struct cxl_pmem_region *cxl_pmem_region_alloc(struct cxl_region *cxlr)
Signature · 1 line
2.37.3
author maintainer
#5 lore raw

Re: [PATCH v12 1/6] cxl/mbox: Add GET_POISON_LIST mailbox command

In reply to Dan Williams
Quoted 5 lines · Dan Williams
Quoted 4 lines · Alison Schofield
Quoted 3 lines · Dan Williams
Quoted 2 lines · alison.schofield@ wrote:

From: Alison Schofield <[email protected]>

snip

Quoted 37 lines
Quoted 9 lines
Quoted 8 lines

With this new interface I do not expect we want to support user tooling that wants to retrieve the list via ioctl. So I think this wants a lead-in patch that deprecates the poison command support so that the linux-cxl community only has one mechanism to maintain going forward.

Something like the below as a lead-in, and then you would add code to cxl_walk_cel() to set a flag for the "get poison" machinery.

Quoted 6 lines

In the inject & clear series, I made the commands kernel exclusive (and also blocked their usage in raw mode).

https://lore.kernel.org/linux-cxl/[email protected]/T/#m5b86f3e88ee7ad5b92843babdb9fd41b7f03cf36

Is that not enough or not the right protection?

I think I'm having deja vu and maybe we talked about this already and I forgot the outcome?

The concern is having a consistent approach across the commands that are valid from userspace all the time, those that are valid sometimes (temporarily marked exclusive), and those that are unsupported from userspace (unsupported via raw command being a special case of that).

For recent new mailbox functionality like CXL_MBOX_OP_GET_EVENT_RECORD and the DCD commands, that are only expected to be executed from the kernel, those are kept out of the CXL_CMDS list, not marked exclusive.

The commands marked exclusive like the label commands return EBUSY, but only while libnvdimm owns the label area. If libnvdimm is disconnected (echo pmemX > /sys/bus/cxl/drivers/cxl_pmem/unbind), then those commands stop being exclusive.

So, I think I want to keep "exclusive" as a set of commands that are suitable to build into a user tool just that the tool needs to know the rules about when those commands might be busy.

Quoted 6 lines

For poison the user tool is expected to use sysfs + trace-events, so including it in the list of available commands returned by CXL_MEM_QUERY_COMMANDS only to never be able to execute it seems wrong.

Marking it deprecated as a "whoops" feels more honest and brings it in line with the other commands that are permanently kernel exclusive.

Yes, we were here previously w Inject & Clear series, and didn't close on it. My last words were were in a inject/clear changelog:

Quoted 4 lines
Quoted 4 lines

I didn't deprecate the ioctls as Dan suggested. Instead, I followed on Ira's recent clean up wrt enabled and exclusive commands, deciding that the honest response to a cxl_query() would be 'Enabled' (if hardware supports) and kernel 'Exclusive' (always). Please take a look.

Once we deprecate, is there a way for users to determine what commands a device supports?

Can you post that deprecate patch preemptively? I'll update the affected series to follow it.

Please include SCAN_MEDIA & GET_SCAN_MEDIA in your patch for the same reason. SCAN_MEDIA_CAPS is harmless.

 	___C(GET_SCAN_MEDIA_CAPS, "Get Scan Media Capabilities"),         \
-	___C(SCAN_MEDIA, "Scan Media"),                                   \
-	___C(GET_SCAN_MEDIA, "Get Scan Media Results"),                   \
+	___DEPRECATED(SCAN_MEDIA, "Scan Media"),                          \
+	___DEPRECATED(GET_SCAN_MEDIA, "Get Scan Media Results"),          \

___C(MAX, "invalid / last command")

Alison

author maintainer
#7 lore raw

Re: [PATCH v12 1/6] cxl/mbox: Add GET_POISON_LIST mailbox command

In reply to Dan Williams

On Tue, Apr 11, 2023 at 06:47:56PM -0700, Dan Williams wrote:

responding to the non-deprecate-related feedback...

Quoted 3 lines
Quoted 2 lines · alison.schofield@ wrote:

From: Alison Schofield <[email protected]>

snip

Quoted 11 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+
+int cxl_poison_state_init(struct cxl_dev_state *cxlds)
+{
+	if (!test_bit(CXL_MEM_COMMAND_ID_GET_POISON, cxlds->enabled_cmds))
+		return 0;
+
+	cxlds->poison.list_out = devm_kzalloc(cxlds->dev, cxlds->payload_size,
+					      GFP_KERNEL);

Given the payload can be multiple pages in size use kvmalloc() like cxl_mem_alloc_event_buf().

Got it, thanks.

Quoted 8 lines
Quoted 7 lines
(quoted diff) +6 -0
+	if (!cxlds->poison.list_out)
+		return -ENOMEM;
+
+	mutex_init(&cxlds->poison.lock);
+	return 0;
+}
Quoted 13 lines

Review

Quoted 9 lines
(quoted diff) +9 -0
+struct cxl_mbox_poison_in {
+	__le64 offset;
+	__le64 length;
+} __packed;
+
+struct cxl_mbox_poison_out {
+	u8 flags;
+	u8 rsvd1;
+	__le64 overflow_t;

I was wondering what the "_t" meant, I always read that as "type". Perhaps "_ts" or even just spell out "_timestamp".

Sure, picking overflow_ts

Quoted 2 lines

Aside from the minor fixups and reworking the enumeration mechanism per above, this looks good to me.

author maintainer
#15 lore raw

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

In reply to Dan Williams
Quoted 75 lines · Dan Williams
Quoted 74 lines · 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 events when cxl_poison event tracing is enabled.

---
 Documentation/ABI/testing/sysfs-bus-cxl | 14 ++++++++
 drivers/cxl/core/memdev.c               | 48 +++++++++++++++++++++++++
 drivers/cxl/cxlmem.h                    |  5 ++-
 drivers/cxl/mem.c                       | 36 +++++++++++++++++++
 4 files changed, 102 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-bus-cxl +14 -0
index 3acf2f17a73f..48ac0d911801 100644
@@ -415,3 +415,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:		April, 2023
+KernelVersion:	v6.4
+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
+		events when cxl_poison event tracing is enabled.
drivers/cxl/core/memdev.c +25 -0
index 0af8856936dc..297d87ebaca6 100644
@@ -106,6 +106,53 @@ static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(numa_node);
 
+static int cxl_get_poison_by_memdev(struct cxl_memdev *cxlmd)
+{
+	struct cxl_dev_state *cxlds = cxlmd->cxlds;
+	u64 offset, length;
+	int rc = 0;
+
+	/* 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 == -EFAULT)
+			rc = 0;
+	}
Quoted 8 lines

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

Quoted 6 lines
drivers/cxl/core/memdev.c +6 -0
+	return rc;
+}
+
+ssize_t cxl_trigger_poison_list(struct device *dev,
+				struct device_attribute *attr,
+				const char *buf, size_t len)

The @attr argument is unused, it can be dropped.

Agree, will do.

Quoted 6 lines

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

Quoted 3 lines
drivers/cxl/core/memdev.c +2 -0
+{
+	struct cxl_memdev *cxlmd = to_cxl_memdev(dev);

The caller can do this conversion.

Quoted 7 lines

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

Quoted 5 lines
drivers/cxl/core/memdev.c +5 -0
+	bool trigger;
+	ssize_t rc;
+
+	if (kstrtobool(buf, &trigger) || !trigger)
+		return -EINVAL;

Hmm, the caller could to this too...

Why split the work?

It seems having the caller do a little bit of work, and then pass it on, hurts readability. ATM, the caller does nothing, and here we do all the usual sysfs handling. The division of power is crisp. If it's not an efficiency concern, why make it less readable?

Alison

Quoted 7 lines

...the below seems to be the bit that the cxl_core cares about handling.

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

Quoted 2 lines
drivers/cxl/core/memdev.c +2 -0
+
+	down_read(&cxl_dpa_rwsem);

down_read_interruptible() since this is coming from userspace.

Thanks, got it!

Quoted 8 lines

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

Quoted 5 lines
drivers/cxl/core/memdev.c +4 -0
+	rc = cxl_get_poison_by_memdev(cxlmd);
+	up_read(&cxl_dpa_rwsem);
+
+	return rc ? rc : len;

The caller can do this conversion.

Quoted 13 lines

drivers/cxl/core/memdev.c static umode_t cxl_memdev_visible(struct kobject *kobj, struct attribute *a, · line 180

Quoted 11 lines
drivers/cxl/core/memdev.c +4 -0
+}
+EXPORT_SYMBOL_NS_GPL(cxl_trigger_poison_list, CXL);
+
 static struct attribute *cxl_memdev_attributes[] = {
 	&dev_attr_serial.attr,
 	&dev_attr_firmware_version.attr,
@@ -130,6 +177,7 @@ 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;
+

I am surprised that Jonathan let this slide :).

He caught it, so did DaveJ. It just won't go away.

Quoted 4 lines
Quoted 4 lines
drivers/cxl/core/memdev.c +0 -0
 	return a->mode;
 }
 
author maintainer
#19 lore raw

Re: [PATCH v12 4/6] cxl/region: Provide region info to the cxl_poison trace event

In reply to Dan Williams
Quoted 177 lines · Dan Williams
Quoted 42 lines · alison.schofield@ wrote:

From: Alison Schofield <[email protected]>

User space may need to know which region, if any, maps the poison address(es) logged in a cxl_poison trace event. Since the mapping of DPAs (device physical addresses) to a region can change, the kernel must provide this information at the time the poison list is read. The event informs user space that at event <timestamp> this <region> mapped to this <DPA>, which is poisoned.

The cxl_poison trace event is already wired up to log the region name and uuid if it receives param 'struct cxl_region'.

In order to provide that cxl_region, add another method for gathering poison - by committed endpoint decoder mappings. This method is only available with CONFIG_CXL_REGION and is only used if a region actually maps the memdev where poison is being read. After the region driver reads the poison list for all the mapped resources, control returns to the memdev driver, where poison is read for any remaining unmapped resources.

Mixed mode decoders are not currently supported in Linux. Add a debug message to the poison request path. That will serve as an alert that poison list retrieval needs to add support for mixed mode.

The default method remains: read the poison by memdev resource.

---
 drivers/cxl/core/core.h   | 11 +++++++
 drivers/cxl/core/memdev.c | 62 +++++++++++++++++++++++++++++++++++++-
 drivers/cxl/core/region.c | 63 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 135 insertions(+), 1 deletion(-)
drivers/cxl/core/core.h +0 -0
index e888e293943e..57bd22e01a0b 100644

drivers/cxl/core/core.h void cxl_decoder_kill_region(struct cxl_endpoint_decoder *cxled); · line 33

Quoted 9 lines
drivers/cxl/core/core.h +5 -0
@@ -25,7 +25,12 @@ void cxl_decoder_kill_region(struct cxl_endpoint_decoder *cxled);
 #define CXL_DAX_REGION_TYPE(x) (&cxl_dax_region_type)
 int cxl_region_init(void);
 void cxl_region_exit(void);
+int cxl_get_poison_by_endpoint(struct device *dev, void *data);
 #else
+static inline int cxl_get_poison_by_endpoint(struct device *dev, void *data)
+{
+	return 0;
+}

For a public function the lack of type safety jumps out at me... more below:

Quoted 86 lines
drivers/cxl/core/core.h +6 -0
 static inline void cxl_decoder_kill_region(struct cxl_endpoint_decoder *cxled)
 {
 }
@@ -68,4 +73,10 @@ enum cxl_poison_trace_type {
 	CXL_POISON_TRACE_LIST,
 };
 
+struct cxl_trigger_poison_context {
+	struct cxl_port *port;
+	enum cxl_decoder_mode mode;
+	u64 offset;
+};
+
 #endif /* __CXL_CORE_H__ */
drivers/cxl/core/memdev.c +49 -1
index 297d87ebaca6..f26b5b6cda10 100644
@@ -106,6 +106,47 @@ static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(numa_node);
 
+static int cxl_get_poison_unmapped(struct cxl_memdev *cxlmd,
+				   struct cxl_trigger_poison_context *ctx)
+{
+	struct cxl_dev_state *cxlds = cxlmd->cxlds;
+	u64 offset, length;
+	int rc = 0;
+
+	/*
+	 * Collect poison for the remaining unmapped resources
+	 * after poison is collected by committed endpoints.
+	 *
+	 * Knowing that PMEM must always follow RAM, get poison
+	 * for unmapped resources based on the last decoder's mode:
+	 *	ram: scan remains of ram range, then any pmem range
+	 *	pmem: scan remains of pmem range
+	 */
+
+	if (ctx->mode == CXL_DECODER_RAM) {
+		offset = ctx->offset;
+		length = resource_size(&cxlds->ram_res) - offset;
+		rc = cxl_mem_get_poison(cxlmd, offset, length, NULL);
+		if (rc == -EFAULT)
+			rc = 0;
+		if (rc)
+			return rc;
+	}
+	if (ctx->mode == CXL_DECODER_PMEM) {
+		offset = ctx->offset;
+		length = resource_size(&cxlds->dpa_res) - offset;
+		if (!length)
+			return 0;
+	} else if (resource_size(&cxlds->pmem_res)) {
+		offset = cxlds->pmem_res.start;
+		length = resource_size(&cxlds->pmem_res);
+	} else {
+		return 0;
+	}
+
+	return cxl_mem_get_poison(cxlmd, offset, length, NULL);
+}
+
 static int cxl_get_poison_by_memdev(struct cxl_memdev *cxlmd)
 {
 	struct cxl_dev_state *cxlds = cxlmd->cxlds;
@@ -139,14 +180,33 @@ ssize_t cxl_trigger_poison_list(struct device *dev,
 				const char *buf, size_t len)
 {
 	struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
+	struct cxl_trigger_poison_context ctx;
+	struct cxl_port *port;
 	bool trigger;
 	ssize_t rc;
 
 	if (kstrtobool(buf, &trigger) || !trigger)
 		return -EINVAL;
 
+	port = dev_get_drvdata(&cxlmd->dev);
+	if (!port || !is_cxl_endpoint(port))
+		return -EINVAL;
+
 	down_read(&cxl_dpa_rwsem);
-	rc = cxl_get_poison_by_memdev(cxlmd);
+	if (port->commit_end == -1) {
+		/* No regions mapped to this memdev */

drivers/cxl/core/memdev.c ssize_t cxl_trigger_poison_list(struct device *dev, · line 207

Quoted 10 lines
drivers/cxl/core/memdev.c +10 -0
+		rc = cxl_get_poison_by_memdev(cxlmd);
+	} else {
+		/* Regions mapped, collect poison by endpoint */
+		ctx = (struct cxl_trigger_poison_context) {
+			.port = port,
+		};
+		rc = device_for_each_child(&port->dev, &ctx,
+					   cxl_get_poison_by_endpoint);
+		if (rc == 1)
+			rc = cxl_get_poison_unmapped(cxlmd, &ctx);

Ah, cxl_get_poison_by_endpoint() is a function pointer to device_for_each_child(), that really feels like a detail that's private to the implementation.

I would reorganize this to something like:

     if (port->commit_end == -1) {
             /* No regions mapped to this memdev */
             rc = cxl_get_poison_by_memdev(cxlmd);
     } else {
             /* Regions mapped, collect poison by endpoint */
             rc = cxl_get_poison_by_endpoint(endpoint);
     }

...and then internal to cxl_get_poison_by_endpoint() do:

             ctx = (struct cxl_trigger_poison_context) {
                     .port = endpoint,
             };
             rc = device_for_each_child(&port->dev, &ctx,
                                        poison_by_decoder);
             if (rc == 1)
                     rc = cxl_get_poison_unmapped(cxlmd, &ctx);
Quoted 1 line

...then the header file reads more calmly with the added type-safety.

I'll take another stab at this.

A couple of versions back, I pulled cxl_get_poison_unmapped() out of cxl_get_poison_by_endpoint() since it was not really work of the region driver. (Ira called that out in a review)

Thanks,
Alison

Quoted 43 lines
Quoted 30 lines
drivers/cxl/core/memdev.c +2 -0
+	}
+
 	up_read(&cxl_dpa_rwsem);
 
 	return rc ? rc : len;
drivers/cxl/core/region.c +16 -0
index f29028148806..4c4d3a6d631d 100644
@@ -2213,6 +2213,69 @@ struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev)
 }
 EXPORT_SYMBOL_NS_GPL(to_cxl_pmem_region, CXL);
 
+int cxl_get_poison_by_endpoint(struct device *dev, void *arg)
+{
+	struct cxl_trigger_poison_context *ctx = arg;
+	struct cxl_endpoint_decoder *cxled;
+	struct cxl_port *port = ctx->port;
+	struct cxl_memdev *cxlmd;
+	u64 offset, length;
+	int rc = 0;
+
+	down_read(&cxl_region_rwsem);
+
+	if (!is_endpoint_decoder(dev))
+		goto out;
+
+	cxled = to_cxl_endpoint_decoder(dev);
+	if (!cxled->dpa_res || !resource_size(cxled->dpa_res))

drivers/cxl/core/region.c struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev) · line 2241

Quoted 10 lines
drivers/cxl/core/region.c +10 -0
+		goto out;
+
+	/*
+	 * Regions are only created with single mode decoders: pmem or ram.
+	 * Linux does not currently support mixed mode decoders. This means
+	 * that reading poison per endpoint decoder adheres to the spec
+	 * requirement that poison reads of pmem and ram must be separated.
+	 * CXL 3.0 Spec 8.2.9.8.4.1
+	 *
+	 * Watch for future support of mixed with a dev_dbg() msg.

This sentence can go, mixed will never* be supported.

Quoted 3 lines

* at least until the vendor that manages to ship such a thing comes and explains why the kernel needs to work around that awkwardness.

Got it!

Quoted 1 line
Quoted 1 line
drivers/cxl/core/region.c +1 -0
+	 */

snip

Quoted 1 line
#6 lore raw

Re: [PATCH v12 1/6] cxl/mbox: Add GET_POISON_LIST mailbox command

In reply to Alison Schofield

Alison Schofield wrote:
[..]

Quoted 2 lines

Once we deprecate, is there a way for users to determine what commands a device supports?

I think this discussion needs to be careful about the word "command" there's the Linux CXL command ids and there are the device mailbox command opcodes. The Linux commands ids are usually, but not always, a 1:1 match with the mailbox commands, but the functionality that the mailbox command implements need not be wrapped by a Linux command id.

For poison retrieval the user will know that the device supports it because the poison sysfs entries will pop up. For DCD the user will know that the device supports the commands because the DCD region info will show up in sysfs. So, CXL_MEM_QUERY_COMMANDS is only a mechanism to enumerate the Linux command ids, the way to query device functionality is via a combination of CXL_MEM_QUERY_COMMANDS and sysfs.

Quoted 6 lines

Can you post that deprecate patch preemptively? I'll update the affected series to follow it.

Please include SCAN_MEDIA & GET_SCAN_MEDIA in your patch for the same reason. SCAN_MEDIA_CAPS is harmless.

I was going to say wait until the scan media kernel implementation shows up, but you're right the sooner we deprecate the better.

Review

Quoted 6 lines
(quoted diff) +2 -2
 	___C(GET_SCAN_MEDIA_CAPS, "Get Scan Media Capabilities"),         \
-	___C(SCAN_MEDIA, "Scan Media"),                                   \
-	___C(GET_SCAN_MEDIA, "Get Scan Media Results"),                   \
+	___DEPRECATED(SCAN_MEDIA, "Scan Media"),                          \
+	___DEPRECATED(GET_SCAN_MEDIA, "Get Scan Media Results"),          \
 	___C(MAX, "invalid / last command")

I was thinking you would pick up that patch in your next posting, so go ahead and pull in that update.

#16 lore raw

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

In reply to Alison Schofield

Alison Schofield wrote:
[..]

Quoted 8 lines
Quoted 7 lines

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

Quoted 5 lines
drivers/cxl/core/memdev.c +5 -0
+	bool trigger;
+	ssize_t rc;
+
+	if (kstrtobool(buf, &trigger) || !trigger)
+		return -EINVAL;

Hmm, the caller could to this too...

Quoted 6 lines

Why split the work?

It seems having the caller do a little bit of work, and then pass it on, hurts readability. ATM, the caller does nothing, and here we do all the usual sysfs handling. The division of power is crisp. If it's not an efficiency concern, why make it less readable?

Ah interesting, I am coming at it from a Separation of Concerns perspective.

The core functionality being exported is a method to retrieve poison records and emit them as trace-events. Whether that is in response to sysfs stimulus or some other stimulus is not something the core needs to care about. An export of cxl_get_poison_by_memdev() is an API that can have multiple users, cxl_trigger_poison_list() is an API that is purpose-built for one user. The motivation is to have the core API be potentially useful for multiple contexts.

One thought experiement is write a kernel-doc comment for cxl_trigger_poison_list(). It would need to say something like "this API is only for the cxl_mem driver to use for its sysfs attribute", while the kernel-doc for cxl_get_poison_by_memdev() can remain generic.

So the general ask here is create new CXL core exports that can be read and understood independent of their callers.

Quoted 31 lines
Quoted 6 lines

...the below seems to be the bit that the cxl_core cares about handling.

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	down_read(&cxl_dpa_rwsem);

down_read_interruptible() since this is coming from userspace.

Thanks, got it!

Quoted 8 lines

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

Quoted 5 lines
drivers/cxl/core/memdev.c +4 -0
+	rc = cxl_get_poison_by_memdev(cxlmd);
+	up_read(&cxl_dpa_rwsem);
+
+	return rc ? rc : len;

The caller can do this conversion.

Quoted 13 lines

drivers/cxl/core/memdev.c static umode_t cxl_memdev_visible(struct kobject *kobj, struct attribute *a, · line 180

Quoted 11 lines
drivers/cxl/core/memdev.c +4 -0
+}
+EXPORT_SYMBOL_NS_GPL(cxl_trigger_poison_list, CXL);
+
 static struct attribute *cxl_memdev_attributes[] = {
 	&dev_attr_serial.attr,
 	&dev_attr_firmware_version.attr,
@@ -130,6 +177,7 @@ 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;
+

I am surprised that Jonathan let this slide :).

Quoted 1 line

He caught it, so did DaveJ. It just won't go away.

I feel your pain, these things are sneaky.

#20 lore raw

Re: [PATCH v12 4/6] cxl/region: Provide region info to the cxl_poison trace event

In reply to Alison Schofield

Alison Schofield wrote:
[..]

Quoted 24 lines
Quoted 24 lines

Ah, cxl_get_poison_by_endpoint() is a function pointer to device_for_each_child(), that really feels like a detail that's private to the implementation.

I would reorganize this to something like:

     if (port->commit_end == -1) {
             /* No regions mapped to this memdev */
             rc = cxl_get_poison_by_memdev(cxlmd);
     } else {
             /* Regions mapped, collect poison by endpoint */
             rc = cxl_get_poison_by_endpoint(endpoint);
     }

...and then internal to cxl_get_poison_by_endpoint() do:

             ctx = (struct cxl_trigger_poison_context) {
                     .port = endpoint,
             };
             rc = device_for_each_child(&port->dev, &ctx,
                                        poison_by_decoder);
             if (rc == 1)
                     rc = cxl_get_poison_unmapped(cxlmd, &ctx);
Quoted 7 lines
Quoted 1 line

...then the header file reads more calmly with the added type-safety.

I'll take another stab at this.

A couple of versions back, I pulled cxl_get_poison_unmapped() out of cxl_get_poison_by_endpoint() since it was not really work of the region driver. (Ira called that out in a review)

I think it's ok to have poison_by_decoder() and cxl_get_poison_unmapped() within cxl_get_poison_by_endpoint() because decoder-mapped and unmapped-capacity are both a part of the endpoint. Given that the region core and the region driver are both glommed into drivers/cxl/core/region.c I would not worry too much about the unmapped scanning being in that file if it keeps all the poison code better colocated.

author maintainer
#8 lore raw

Re: [PATCH v12 1/6] cxl/mbox: Add GET_POISON_LIST mailbox command

In reply to Dan Williams
Quoted 3 lines · Dan Williams
Quoted 2 lines · alison.schofield@ wrote:

From: Alison Schofield <[email protected]>

follow up on the deprecate patch...

snip

Quoted 15 lines

With this new interface I do not expect we want to support user tooling that wants to retrieve the list via ioctl. So I think this wants a lead-in patch that deprecates the poison command support so that the linux-cxl community only has one mechanism to maintain going forward.

Something like the below as a lead-in, and then you would add code to cxl_walk_cel() to set a flag for the "get poison" machinery.

-- >8 --
From f2cd1d1e09fe6f36255f3b8cd831b2b4903045d4 Mon Sep 17 00:00:00 2001
From: Dan Williams <[email protected]>
Date: Tue, 11 Apr 2023 17:48:45 -0700
Subject: [PATCH] cxl/mbox: Deprecate poison commands

Quoted 4 lines

The CXL subsystem is adding a formal mechanism for retrieving the poison list. Minimize the maintenance burden going forward, and maximize the investment in common tooling by deprecating direct user access to issue this command outside of CXL_MEM_RAW_COMMANDS debug scenarios.

I'm expanding the scope of this deprecate patch to include Scan commands, and want to make above statement correct, wrt what is allowed in raw mode.

Today, Scan Media (& Results) are not allowed in raw.
It seems like in the spirit of raw, we should allow the scans. That would be same as the raw allowed commands Get Poison, Inject & Clear.

Thoughts?

Alison

Quoted 94 lines

A new cxl_deprecated_commands[] list is created for querying which command ids defined in previous kernels are now deprecated.

Effectively all of the commands defined in:

87815ee9d006 ("cxl/pci: Add media provisioning required commands")

...were defined prematurely and should have waited until the kernel implementation was decided. To my knowledge there are no shipping devices with poison listing support and no known tools that would regress with this change.

---
 drivers/cxl/core/mbox.c      |  3 ---
 include/uapi/linux/cxl_mem.h | 31 ++++++++++++++++++++++++++++---
 2 files changed, 28 insertions(+), 6 deletions(-)
drivers/cxl/core/mbox.c +0 -3
index f2addb457172..8e24038b8769 100644
@@ -61,9 +61,6 @@ static struct cxl_mem_command cxl_mem_commands[CXL_MEM_COMMAND_ID_MAX] = {
 	CXL_CMD(SET_ALERT_CONFIG, 0xc, 0, 0),
 	CXL_CMD(GET_SHUTDOWN_STATE, 0, 0x1, 0),
 	CXL_CMD(SET_SHUTDOWN_STATE, 0x1, 0, 0),
-	CXL_CMD(GET_POISON, 0x10, CXL_VARIABLE_PAYLOAD, 0),
-	CXL_CMD(INJECT_POISON, 0x8, 0, 0),
-	CXL_CMD(CLEAR_POISON, 0x48, 0, 0),
 	CXL_CMD(GET_SCAN_MEDIA_CAPS, 0x10, 0x4, 0),
 	CXL_CMD(SCAN_MEDIA, 0x11, 0, 0),
 	CXL_CMD(GET_SCAN_MEDIA, 0, CXL_VARIABLE_PAYLOAD, 0),
include/uapi/linux/cxl_mem.h +28 -3
index 86bbacf2a315..90f17343f1ba 100644
@@ -40,19 +40,22 @@
 	___C(SET_ALERT_CONFIG, "Set Alert Configuration"),                \
 	___C(GET_SHUTDOWN_STATE, "Get Shutdown State"),                   \
 	___C(SET_SHUTDOWN_STATE, "Set Shutdown State"),                   \
-	___C(GET_POISON, "Get Poison List"),                              \
-	___C(INJECT_POISON, "Inject Poison"),                             \
-	___C(CLEAR_POISON, "Clear Poison"),                               \
+	___DEPRECATED(GET_POISON, "Get Poison List"),                     \
+	___DEPRECATED(INJECT_POISON, "Inject Poison"),                    \
+	___DEPRECATED(CLEAR_POISON, "Clear Poison"),                      \
 	___C(GET_SCAN_MEDIA_CAPS, "Get Scan Media Capabilities"),         \
 	___C(SCAN_MEDIA, "Scan Media"),                                   \
 	___C(GET_SCAN_MEDIA, "Get Scan Media Results"),                   \
 	___C(MAX, "invalid / last command")
 
 #define ___C(a, b) CXL_MEM_COMMAND_ID_##a
+#define ___DEPRECATED(a, b) CXL_MEM_DEPRECATED_ID_##a
 enum { CXL_CMDS };
 
 #undef ___C
+#undef ___DEPRECATED
 #define ___C(a, b) { b }
+#define ___DEPRECATED(a, b) { "Deprecated " b }
 static const struct {
 	const char *name;
 } cxl_command_names[] __attribute__((__unused__)) = { CXL_CMDS };
@@ -68,6 +71,28 @@ static const struct {
  */
 
 #undef ___C
+#undef ___DEPRECATED
+#define ___C(a, b) (0)
+#define ___DEPRECATED(a, b) (1)
+
+static const u8 cxl_deprecated_commands[]
+	__attribute__((__unused__)) = { CXL_CMDS };
+
+/*
+ * Here's how this actually breaks out:
+ * cxl_deprecated_commands[] = {
+ *	[CXL_MEM_COMMAND_ID_INVALID] = 0,
+ *	[CXL_MEM_COMMAND_ID_IDENTIFY] = 0,
+ *	...
+ *	[CXL_MEM_DEPRECATED_ID_GET_POISON] = 1,
+ *	[CXL_MEM_DEPRECATED_ID_INJECT_POISON] = 1,
+ *	[CXL_MEM_DEPRECATED_ID_CLEAR_POISON] = 1,
+ *	...
+ * };
+ */
+
+#undef ___C
+#undef ___DEPRECATED
 
 /**
  * struct cxl_command_info - Command information returned from a query.
Signature · 1 line
2.39.2
#9 lore raw

Re: [PATCH v12 1/6] cxl/mbox: Add GET_POISON_LIST mailbox command

Quoted 33 lines · Alison Schofield
Quoted 3 lines · Dan Williams
Quoted 2 lines · alison.schofield@ wrote:

From: Alison Schofield <[email protected]>

follow up on the deprecate patch...

snip

Quoted 15 lines

With this new interface I do not expect we want to support user tooling that wants to retrieve the list via ioctl. So I think this wants a lead-in patch that deprecates the poison command support so that the linux-cxl community only has one mechanism to maintain going forward.

Something like the below as a lead-in, and then you would add code to cxl_walk_cel() to set a flag for the "get poison" machinery.

-- >8 --
From f2cd1d1e09fe6f36255f3b8cd831b2b4903045d4 Mon Sep 17 00:00:00 2001
From: Dan Williams <[email protected]>
Date: Tue, 11 Apr 2023 17:48:45 -0700
Subject: [PATCH] cxl/mbox: Deprecate poison commands

Quoted 4 lines

The CXL subsystem is adding a formal mechanism for retrieving the poison list. Minimize the maintenance burden going forward, and maximize the investment in common tooling by deprecating direct user access to issue this command outside of CXL_MEM_RAW_COMMANDS debug scenarios.

I'm expanding the scope of this deprecate patch to include Scan commands, and want to make above statement correct, wrt what is allowed in raw mode.

Quoted 5 lines

Today, Scan Media (& Results) are not allowed in raw.
It seems like in the spirit of raw, we should allow the scans. That would be same as the raw allowed commands Get Poison, Inject & Clear.

Thoughts?

The goal of blocking commands even for raw access is for the kernel to say "hey, there's a formal interface for this, use that instead". At the same time there is the "raw_allow_all" mechanism for those debug scenarios to opt-in and say "I really know what I am doing". I think the raw_allow_all hurdle is high enough to prevent splintering of user tooling and encourage collaboration on the commons.

So I would say feel free to continue to list commands in cxl_disabled_raw_commands as a way to document the commands that we, linux-cxl@ community, believe need to be kernel managed. Rely on raw_allow_all as the release valve for expert debugging.

author maintainer
#10 lore raw

Re: [PATCH v12 1/6] cxl/mbox: Add GET_POISON_LIST mailbox command

In reply to Dan Williams

Dan, Vishal,

Following up on using the new deprecated list ...

Quoted 67 lines · Dan Williams
Quoted 43 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 poison list.

---
 drivers/cxl/core/mbox.c | 71 +++++++++++++++++++++++++++++++++++++++++
 drivers/cxl/cxlmem.h    | 67 ++++++++++++++++++++++++++++++++++++++
 drivers/cxl/pci.c       |  4 +++
 3 files changed, 142 insertions(+)
drivers/cxl/core/mbox.c +3 -0
index f2addb457172..69a5d69dd53b 100644
@@ -5,6 +5,8 @@
 #include <linux/debugfs.h>
 #include <linux/ktime.h>
 #include <linux/mutex.h>
+#include <asm/unaligned.h>
+#include <cxlpci.h>
 #include <cxlmem.h>
 #include <cxl.h>
 
@@ -994,6 +996,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) {

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

Quoted 8 lines
drivers/cxl/core/mbox.c +5 -0
@@ -1017,6 +1020,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_errors = min_t(u32, val, CXL_POISON_LIST_MAX);
+	}
+

With this new interface I do not expect we want to support user tooling that wants to retrieve the list via ioctl. So I think this wants a lead-in patch that deprecates the poison command support so that the linux-cxl community only has one mechanism to maintain going forward.

Something like the below as a lead-in, and then you would add code to cxl_walk_cel() to set a flag for the "get poison" machinery.

-- >8 --
From f2cd1d1e09fe6f36255f3b8cd831b2b4903045d4 Mon Sep 17 00:00:00 2001
From: Dan Williams <[email protected]>
Date: Tue, 11 Apr 2023 17:48:45 -0700
Subject: [PATCH] cxl/mbox: Deprecate poison commands

Quoted 7 lines

The CXL subsystem is adding a formal mechanism for retrieving the poison list. Minimize the maintenance burden going forward, and maximize the investment in common tooling by deprecating direct user access to issue this command outside of CXL_MEM_RAW_COMMANDS debug scenarios.

A new cxl_deprecated_commands[] list is created for querying which command ids defined in previous kernels are now deprecated.

Dan, Vishal,

With the driver no longer returning these commands in the cxl_mem_commands[] list, they will appear as -EOPNOTSUPP in the ndctl:libcxl cxl_query().

Is there something else we need to do to actually show these cmds as deprecated? Something like query the deprecated list and add a new status to cxl_query().

At the moment, my goal is to do what is needed in the driver now, and pick up any accompanying libcxl changes after the driver changes are merged. A bit worried I'm leaving something undone in driver today.

Thanks,
Alison

Quoted 92 lines

Effectively all of the commands defined in:

87815ee9d006 ("cxl/pci: Add media provisioning required commands")

...were defined prematurely and should have waited until the kernel implementation was decided. To my knowledge there are no shipping devices with poison listing support and no known tools that would regress with this change.

---
 drivers/cxl/core/mbox.c      |  3 ---
 include/uapi/linux/cxl_mem.h | 31 ++++++++++++++++++++++++++++---
 2 files changed, 28 insertions(+), 6 deletions(-)
drivers/cxl/core/mbox.c +0 -3
index f2addb457172..8e24038b8769 100644
@@ -61,9 +61,6 @@ static struct cxl_mem_command cxl_mem_commands[CXL_MEM_COMMAND_ID_MAX] = {
 	CXL_CMD(SET_ALERT_CONFIG, 0xc, 0, 0),
 	CXL_CMD(GET_SHUTDOWN_STATE, 0, 0x1, 0),
 	CXL_CMD(SET_SHUTDOWN_STATE, 0x1, 0, 0),
-	CXL_CMD(GET_POISON, 0x10, CXL_VARIABLE_PAYLOAD, 0),
-	CXL_CMD(INJECT_POISON, 0x8, 0, 0),
-	CXL_CMD(CLEAR_POISON, 0x48, 0, 0),
 	CXL_CMD(GET_SCAN_MEDIA_CAPS, 0x10, 0x4, 0),
 	CXL_CMD(SCAN_MEDIA, 0x11, 0, 0),
 	CXL_CMD(GET_SCAN_MEDIA, 0, CXL_VARIABLE_PAYLOAD, 0),
include/uapi/linux/cxl_mem.h +28 -3
index 86bbacf2a315..90f17343f1ba 100644
@@ -40,19 +40,22 @@
 	___C(SET_ALERT_CONFIG, "Set Alert Configuration"),                \
 	___C(GET_SHUTDOWN_STATE, "Get Shutdown State"),                   \
 	___C(SET_SHUTDOWN_STATE, "Set Shutdown State"),                   \
-	___C(GET_POISON, "Get Poison List"),                              \
-	___C(INJECT_POISON, "Inject Poison"),                             \
-	___C(CLEAR_POISON, "Clear Poison"),                               \
+	___DEPRECATED(GET_POISON, "Get Poison List"),                     \
+	___DEPRECATED(INJECT_POISON, "Inject Poison"),                    \
+	___DEPRECATED(CLEAR_POISON, "Clear Poison"),                      \
 	___C(GET_SCAN_MEDIA_CAPS, "Get Scan Media Capabilities"),         \
 	___C(SCAN_MEDIA, "Scan Media"),                                   \
 	___C(GET_SCAN_MEDIA, "Get Scan Media Results"),                   \
 	___C(MAX, "invalid / last command")
 
 #define ___C(a, b) CXL_MEM_COMMAND_ID_##a
+#define ___DEPRECATED(a, b) CXL_MEM_DEPRECATED_ID_##a
 enum { CXL_CMDS };
 
 #undef ___C
+#undef ___DEPRECATED
 #define ___C(a, b) { b }
+#define ___DEPRECATED(a, b) { "Deprecated " b }
 static const struct {
 	const char *name;
 } cxl_command_names[] __attribute__((__unused__)) = { CXL_CMDS };
@@ -68,6 +71,28 @@ static const struct {
  */
 
 #undef ___C
+#undef ___DEPRECATED
+#define ___C(a, b) (0)
+#define ___DEPRECATED(a, b) (1)
+
+static const u8 cxl_deprecated_commands[]
+	__attribute__((__unused__)) = { CXL_CMDS };
+
+/*
+ * Here's how this actually breaks out:
+ * cxl_deprecated_commands[] = {
+ *	[CXL_MEM_COMMAND_ID_INVALID] = 0,
+ *	[CXL_MEM_COMMAND_ID_IDENTIFY] = 0,
+ *	...
+ *	[CXL_MEM_DEPRECATED_ID_GET_POISON] = 1,
+ *	[CXL_MEM_DEPRECATED_ID_INJECT_POISON] = 1,
+ *	[CXL_MEM_DEPRECATED_ID_CLEAR_POISON] = 1,
+ *	...
+ * };
+ */
+
+#undef ___C
+#undef ___DEPRECATED
 
 /**
  * struct cxl_command_info - Command information returned from a query.
Signature · 2 lines
2.39.2
-- 8< --

snip

#11 lore raw

Re: [PATCH v12 1/6] cxl/mbox: Add GET_POISON_LIST mailbox command

Quoted 83 lines · Alison Schofield

Dan, Vishal,

Following up on using the new deprecated list ...

Quoted 67 lines · Dan Williams
Quoted 43 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 poison list.

---
 drivers/cxl/core/mbox.c | 71 +++++++++++++++++++++++++++++++++++++++++
 drivers/cxl/cxlmem.h    | 67 ++++++++++++++++++++++++++++++++++++++
 drivers/cxl/pci.c       |  4 +++
 3 files changed, 142 insertions(+)
drivers/cxl/core/mbox.c +3 -0
index f2addb457172..69a5d69dd53b 100644
@@ -5,6 +5,8 @@
 #include <linux/debugfs.h>
 #include <linux/ktime.h>
 #include <linux/mutex.h>
+#include <asm/unaligned.h>
+#include <cxlpci.h>
 #include <cxlmem.h>
 #include <cxl.h>
 
@@ -994,6 +996,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) {

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

Quoted 8 lines
drivers/cxl/core/mbox.c +5 -0
@@ -1017,6 +1020,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_errors = min_t(u32, val, CXL_POISON_LIST_MAX);
+	}
+

With this new interface I do not expect we want to support user tooling that wants to retrieve the list via ioctl. So I think this wants a lead-in patch that deprecates the poison command support so that the linux-cxl community only has one mechanism to maintain going forward.

Something like the below as a lead-in, and then you would add code to cxl_walk_cel() to set a flag for the "get poison" machinery.

-- >8 --
From f2cd1d1e09fe6f36255f3b8cd831b2b4903045d4 Mon Sep 17 00:00:00 2001
From: Dan Williams <[email protected]>
Date: Tue, 11 Apr 2023 17:48:45 -0700
Subject: [PATCH] cxl/mbox: Deprecate poison commands

Quoted 7 lines

The CXL subsystem is adding a formal mechanism for retrieving the poison list. Minimize the maintenance burden going forward, and maximize the investment in common tooling by deprecating direct user access to issue this command outside of CXL_MEM_RAW_COMMANDS debug scenarios.

A new cxl_deprecated_commands[] list is created for querying which command ids defined in previous kernels are now deprecated.

Dan, Vishal,

Quoted 7 lines

With the driver no longer returning these commands in the cxl_mem_commands[] list, they will appear as -EOPNOTSUPP in the ndctl:libcxl cxl_query().

Is there something else we need to do to actually show these cmds as deprecated? Something like query the deprecated list and add a new status to cxl_query().

No, because any software written before the deprecation does not know to look to see if they are deprecated, and software written afterwards can read the latest header file. So an EOPNOTSUPP return is all that is needed.

Quoted 4 lines

At the moment, my goal is to do what is needed in the driver now, and pick up any accompanying libcxl changes after the driver changes are merged. A bit worried I'm leaving something undone in driver today.

As long as there are users with new needs the driver will always have undone corner cases. I think this series is in good shape.