Skip to contentSkip to conversation

CXL Poison List Retrieval & Tracing

PATCH Superseded [email protected] 3 participants 9 messages Oct 12, 2022 – Oct 17, 2022

Subsystems (2)

v2 of 13 Superseded Latest is v13 →

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

v2 cover CXL Poison List Retrieval & Tracing

From: Alison Schofield <[email protected]>

Adds 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 Spec Section 8.2.9.8.4.1. [1]

Example command line usage:

Triggered by memdev:

$ echo 1 > /sys/bus/cxl/devices/mem1/trigger_poison_list
cxl_poison:           pid:981 region: memdev:mem1 pcidev:cxl_mem.1 hpa:0x0 dpa:0xc0 length:0xc0 source:Internal flags: overflow_time:0
cxl_poison:           pid:981 region: memdev:mem1 pcidev:cxl_mem.1 hpa:0x0 dpa:0x180 length:0x100 source:Injected flags: overflow_time:0

Triggered by region: (region name is included in the trace)

$ echo 1 > /sys/bus/cxl/devices/region5/trigger_poison_list
cxl_poison:           pid:1132 region:region5 memdev:mem2 pcidev:cxl_mem.2 hpa:0x0 dpa:0x0 length:0x40 source:Unknown flags: overflow_time:0
cxl_poison:           pid:1132 region:region5 memdev:mem2 pcidev:cxl_mem.2 hpa:0x0 dpa:0x40 length:0x80 source:External flags: overflow_time:0

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

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

Alison Schofield (4):
trace, cxl: Introduce a TRACE_EVENT for CXL poison records cxl/mbox: Add GET_POISON_LIST mailbox command cxl/memdev: Add trigger_poison_list sysfs attribute cxl/region: Add trigger_poison_list sysfs attribute

 Documentation/ABI/testing/sysfs-bus-cxl | 28 ++++++++
 drivers/cxl/core/mbox.c                 | 69 +++++++++++++++++++
 drivers/cxl/core/memdev.c               | 41 ++++++++++++
 drivers/cxl/core/region.c               | 34 ++++++++++
 drivers/cxl/cxlmem.h                    | 42 ++++++++++++
 include/trace/events/cxl.h              | 88 +++++++++++++++++++++++++
 6 files changed, 302 insertions(+)
 create mode 100644 include/trace/events/cxl.h

base-commit: 1985cf58850562e4b960e19d46f0d8f19d6c7cbd

Signature · 1 line
2.37.3
author maintainer
#1 lore raw

PATCH v2 1/4 trace, cxl: Introduce a TRACE_EVENT for CXL poison records

From: Alison Schofield <[email protected]>

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

---
 include/trace/events/cxl.h | 88 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)
 create mode 100644 include/trace/events/cxl.h
include/trace/events/cxl.h new file +88 -0
new file mode 100644
index 000000000000..9613b0f18011
@@ -0,0 +1,88 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM cxl
+
+#if !defined(_CXL_TRACE_H) ||  defined(TRACE_HEADER_MULTI_READ)
+#define _CXL_TRACE_H
+
+#include <linux/tracepoint.h>
+
+/* CXL 8.2.9.5.4.1 Get Poison List: Poison Source */
+#define        CXL_POISON_SOURCE_UNKNOWN       0
+#define        CXL_POISON_SOURCE_EXTERNAL      1
+#define        CXL_POISON_SOURCE_INTERNAL      2
+#define        CXL_POISON_SOURCE_INJECTED      3
+#define        CXL_POISON_SOURCE_VENDOR        7
+
+#define show_poison_source(source)                            \
+	__print_symbolic(source,                              \
+		{ CXL_POISON_SOURCE_UNKNOWN,   "Unknown"  },  \
+		{ CXL_POISON_SOURCE_EXTERNAL,  "External" },  \
+		{ CXL_POISON_SOURCE_INTERNAL,  "Internal" },  \
+		{ CXL_POISON_SOURCE_INJECTED,  "Injected" },  \
+		{ CXL_POISON_SOURCE_VENDOR,    "Vendor"   })
+
+/* CXL 8.2.9.5.4.1 Get Poison List: Payload out flags */
+#define CXL_POISON_FLAG_MORE            BIT(0)
+#define CXL_POISON_FLAG_OVERFLOW        BIT(1)
+#define CXL_POISON_FLAG_SCANNING        BIT(2)
+
+#define show_poison_flags(flags)                             \
+	__print_flags(flags, "|",                            \
+		{ CXL_POISON_FLAG_MORE,      "More"     },   \
+		{ CXL_POISON_FLAG_OVERFLOW,  "Overflow"  },  \
+		{ CXL_POISON_FLAG_SCANNING,  "Scanning"  })
+
+TRACE_EVENT(cxl_poison,
+
+	    TP_PROTO(pid_t pid, const char *region, const char *memdev,
+		     const char *pcidev, u64 hpa, u64 dpa, u32 length,
+		     u8 source, u8 flags, u64 overflow_t),
+
+	    TP_ARGS(pid, region, memdev, pcidev, hpa, dpa,
+		    length, source, flags, overflow_t),
+
+	    TP_STRUCT__entry(
+		__field(pid_t, pid)
+		__string(region, region ? region : "")
+		__string(memdev, memdev)
+		__string(pcidev, pcidev)
+		__field(u64, hpa)
+		__field(u64, dpa)
+		__field(u32, length)
+		__field(u8, source)
+		__field(u8, flags)
+		__field(u64, overflow_t)
+	    ),
+
+	    TP_fast_assign(
+		__entry->pid = pid;
+		__assign_str(region, region ? region : "");
+		__assign_str(memdev, memdev);
+		__assign_str(pcidev, pcidev);
+		__entry->hpa = hpa;
+		__entry->dpa = dpa;
+		__entry->length = length;
+		__entry->source = source;
+		__entry->flags = flags;
+		__entry->overflow_t = overflow_t;
+	    ),
+
+	    TP_printk("pid:%d region:%s memdev:%s pcidev:%s hpa:0x%llx dpa:0x%llx length:0x%x source:%s flags:%s overflow_time:%llu",
+		__entry->pid,
+		__get_str(region),
+		__get_str(memdev),
+		__get_str(pcidev),
+		__entry->hpa,
+		__entry->dpa,
+		__entry->length,
+		show_poison_source(__entry->source),
+		show_poison_flags(__entry->flags),
+		__entry->overflow_t)
+);
+#endif /* _CXL_TRACE_H */
+
+/* This part must be outside protection */
+#undef TRACE_INCLUDE_FILE
+#define TRACE_INCLUDE_FILE cxl
+#include <trace/define_trace.h>
Signature · 1 line
2.37.3
author maintainer
#4 lore raw

PATCH v2 2/4 cxl/mbox: Add GET_POISON_LIST mailbox command

In reply to [email protected]

From: Alison Schofield <[email protected]>

CXL devices maintain a list of locations that are poisoned or result in poison if the addresses are accessed by the host.

Per the spec (CXL 3.0 8.2.9.8.4.1), the device returns this Poison list as a set of Media Error Records that include the source of the error, the starting device physical address and length. The length is the number of adjacent DPAs in the record and is in units of 64 bytes.

Retrieve the list and log each Media Error Record as a trace event of type 'cxl_poison'.

Use an optional 'region_name' parameter and include it in the trace event, to identify per region poison collection.

---

Trace field 'hpa' is always zero here. Another patch doing the address translation trails this one, and will fill it in. Happy to remove it here if the foreshadowing is unwanted.

 drivers/cxl/core/mbox.c | 69 +++++++++++++++++++++++++++++++++++++++++
 drivers/cxl/cxlmem.h    | 42 +++++++++++++++++++++++++
 2 files changed, 111 insertions(+)
drivers/cxl/core/mbox.c +69 -0
index 40e3ccb2bf3e..f982645e35e4 100644
@@ -9,6 +9,9 @@
 
 #include "core.h"
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/cxl.h>
+
 static bool cxl_raw_allow_all;
 
 /**
@@ -750,6 +753,7 @@ int cxl_dev_state_identify(struct cxl_dev_state *cxlds)
 {
 	/* See CXL 2.0 Table 175 Identify Memory Device Output Payload */
 	struct cxl_mbox_identify id;
+	__le32 val = 0;
 	int rc;
 
 	rc = cxl_mbox_send_cmd(cxlds, CXL_MBOX_OP_IDENTIFY, NULL, 0, &id,
@@ -769,6 +773,9 @@ int cxl_dev_state_identify(struct cxl_dev_state *cxlds)
 	cxlds->lsa_size = le32_to_cpu(id.lsa_size);
 	memcpy(cxlds->firmware_version, id.fw_revision, sizeof(id.fw_revision));
 
+	memcpy(&val, id.poison_list_max_mer, 3);
+	cxlds->poison_max = min_t(u32, le32_to_cpu(val), CXL_POISON_LIST_MAX);
+
 	return 0;
 }
 EXPORT_SYMBOL_NS_GPL(cxl_dev_state_identify, CXL);
@@ -833,6 +840,67 @@ int cxl_mem_create_range_info(struct cxl_dev_state *cxlds)
 }
 EXPORT_SYMBOL_NS_GPL(cxl_mem_create_range_info, CXL);
 
+int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
+		       const char *region_name)
+{
+	struct cxl_dev_state *cxlds = cxlmd->cxlds;
+	struct cxl_mbox_poison_payload_out *po;
+	struct cxl_mbox_poison_payload_in pi;
+	int nr_records = 0;
+	int rc, i;
+
+	po = kvmalloc(cxlds->payload_size, GFP_KERNEL);
+	if (!po)
+		return -ENOMEM;
+
+	pi.offset = cpu_to_le64(offset);
+	pi.length = cpu_to_le64(len);
+
+	rc = mutex_lock_interruptible(&cxlds->poison_list_mutex);
+	if (rc)
+		goto out;
+
+	do {
+		u64 overflow_t = 0;
+
+		rc = cxl_mbox_send_cmd(cxlds, CXL_MBOX_OP_GET_POISON, &pi,
+				       sizeof(pi), po, cxlds->payload_size);
+		if (rc)
+			break;
+
+		if (po->flags & CXL_POISON_FLAG_OVERFLOW)
+			overflow_t = le64_to_cpu(po->overflow_timestamp);
+
+		for (i = 0; i < le16_to_cpu(po->count); i++) {
+			u32 len = le32_to_cpu(po->record[i].length) *
+					      CXL_POISON_LEN_MULT;
+			u64 addr = le64_to_cpu(po->record[i].address);
+			u8 source = addr & CXL_POISON_SOURCE_MASK;
+			u64 dpa = addr & CXL_POISON_START_MASK;
+			u64 hpa = 0;
+
+			trace_cxl_poison(current->pid, region_name,
+					 dev_name(&cxlmd->dev),
+					 dev_name(cxlds->dev), hpa, dpa, len,
+					 source, po->flags, overflow_t);
+		}
+
+		/* Protect against an uncleared _FLAG_MORE */
+		nr_records = nr_records + le16_to_cpu(po->count);
+		if (nr_records >= cxlds->poison_max) {
+			dev_dbg(&cxlmd->dev, "Max Error Records reached: %d\n",
+				nr_records);
+			break;
+		}
+	} while (po->flags & CXL_POISON_FLAG_MORE);
+
+	mutex_unlock(&cxlds->poison_list_mutex);
+out:
+	kvfree(po);
+	return rc;
+}
+EXPORT_SYMBOL_NS_GPL(cxl_mem_get_poison, CXL);
+
 struct cxl_dev_state *cxl_dev_state_create(struct device *dev)
 {
 	struct cxl_dev_state *cxlds;
@@ -844,6 +912,7 @@ struct cxl_dev_state *cxl_dev_state_create(struct device *dev)
 	}
 
 	mutex_init(&cxlds->mbox_mutex);
+	mutex_init(&cxlds->poison_list_mutex);
 	cxlds->dev = dev;
 
 	return cxlds;
drivers/cxl/cxlmem.h +42 -0

66 lines not on this page · raw message

Signature · 1 line
2.37.3
author maintainer
#6 lore raw

PATCH v2 4/4 cxl/region: Add trigger_poison_list sysfs attribute

In reply to [email protected]

From: Alison Schofield <[email protected]>

When a boolean 'true' is written to this attribute the region driver retrieves the poison list for the capacity each device contributes to this region. The list includes addresses that are poisoned, or would result in poison if accessed, and the source of the poison. The retrieved errors are logged as kernel trace events with the label 'cxl_poison'.

Devices not supporting the poison list capability are ignored.

---
 Documentation/ABI/testing/sysfs-bus-cxl | 14 ++++++++++
 drivers/cxl/core/region.c               | 34 +++++++++++++++++++++++++
 2 files changed, 48 insertions(+)
Documentation/ABI/testing/sysfs-bus-cxl +14 -0
index ab3665f8738e..7e33f6ee4992 100644
@@ -368,3 +368,17 @@ Description:
 		attribute is only visible for devices supporting the
 		capability. The retrieved errors are logged as kernel
 		trace events with the label 'cxl_poison'.
+
+
+What:		/sys/bus/cxl/devices/regionZ/trigger_poison_list
+Date:		October, 2022
+KernelVersion:	v6.2
+Contact:	[email protected]
+Description:
+		(WO) When a boolean 'true' is written to this attribute the
+		region driver retrieves the poison list for the capacity
+		each device contributes to this region. The list includes
+		addresses that are poisoned, or would result in poison if
+		accessed, and the source of the poison. The retrieved
+		errors are logged as kernel trace events with the label
+		'cxl_poison'.
drivers/cxl/core/region.c +34 -0
index ad21b2aa3b0a..e20207934336 100644
@@ -72,6 +72,38 @@ static int is_dup(struct device *match, void *data)
 	return 0;
 }
 
+static ssize_t trigger_poison_list_store(struct device *dev,
+					 struct device_attribute *attr,
+					 const char *buf, size_t len)
+{
+	struct cxl_region *cxlr = to_cxl_region(dev);
+	struct cxl_region_params *p = &cxlr->params;
+	struct cxl_endpoint_decoder *cxled;
+	struct cxl_memdev *cxlmd;
+	u64 offset, length;
+	int rc, i;
+	bool tmp;
+
+	if (kstrtobool(buf, &tmp))
+		return -EINVAL;
+
+	for (i = 0; i <  p->nr_targets; i++) {
+		cxled = p->targets[i];
+		cxlmd = cxled_to_memdev(cxled);
+		if (!test_bit(CXL_MEM_COMMAND_ID_GET_POISON,
+			      cxlmd->cxlds->enabled_cmds))
+			continue;
+		offset = cxl_dpa_resource(cxled);
+		length = cxl_dpa_size(cxled);
+		rc = cxl_mem_get_poison(cxlmd, offset, length,
+					dev_name(&cxlr->dev));
+		if (rc)
+			return rc;
+	}
+	return len;
+}
+static DEVICE_ATTR_WO(trigger_poison_list);
+
 static ssize_t uuid_store(struct device *dev, struct device_attribute *attr,
 			  const char *buf, size_t len)
 {
@@ -282,6 +314,7 @@ static umode_t cxl_region_visible(struct kobject *kobj, struct attribute *a,
 
 	if (a == &dev_attr_uuid.attr && cxlr->mode != CXL_DECODER_PMEM)
 		return 0;
+
 	return a->mode;
 }
 
@@ -555,6 +588,7 @@ static struct attribute *cxl_region_attrs[] = {
 	&dev_attr_interleave_granularity.attr,
 	&dev_attr_resource.attr,
 	&dev_attr_size.attr,
+	&dev_attr_trigger_poison_list.attr,
 	NULL,
 };
 
Signature · 1 line
2.37.3
author maintainer
#5 lore raw

PATCH v2 3/4 cxl/memdev: Add trigger_poison_list sysfs attribute

In reply to [email protected]

From: Alison Schofield <[email protected]>

When a boolean 'true' is written to this attribute the memdev driver retrieves the poison list from the device. The list includes addresses that are poisoned, or would result in poison if accessed, and the source of the poison. This attribute is only visible for devices supporting the capability. The retrieved errors are logged as kernel trace events with the label 'cxl_poison'.

---
 Documentation/ABI/testing/sysfs-bus-cxl | 14 +++++++++
 drivers/cxl/core/memdev.c               | 41 +++++++++++++++++++++++++
 2 files changed, 55 insertions(+)
Documentation/ABI/testing/sysfs-bus-cxl +14 -0
index 0debe2955f34..ab3665f8738e 100644
@@ -354,3 +354,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:		October, 2022
+KernelVersion:	v6.2
+Contact:	[email protected]
+Description:
+		(WO) When a boolean 'true' is written to this attribute the
+		memdev driver retrieves the poison list from the device. The
+		list includes addresses that are poisoned or would result in
+		poison if accessed, and the source of the poison. This
+		attribute is only visible for devices supporting the
+		capability. The retrieved errors are logged as kernel
+		trace events with the label 'cxl_poison'.
drivers/cxl/core/memdev.c +41 -0

59 lines not on this page · raw message

Signature · 1 line
2.37.3
maintainer
#2 lore raw

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

In reply to [email protected]
Quoted 10 lines · On Wed, 12 Oct 2022 14:28:17 -0700 [email protected] wrote:
include/trace/events/cxl.h new file +10 -0
+TRACE_EVENT(cxl_poison,
+
+	    TP_PROTO(pid_t pid, const char *region, const char *memdev,
+		     const char *pcidev, u64 hpa, u64 dpa, u32 length,
+		     u8 source, u8 flags, u64 overflow_t),
+
+	    TP_ARGS(pid, region, memdev, pcidev, hpa, dpa,
+		    length, source, flags, overflow_t),
+
+	    TP_STRUCT__entry(

include/trace/events/cxl.h line 55

Quoted 10 lines
include/trace/events/cxl.h new file +10 -0
+		__field(pid_t, pid)
+		__string(region, region ? region : "")
+		__string(memdev, memdev)
+		__string(pcidev, pcidev)
+		__field(u64, hpa)
+		__field(u64, dpa)
+		__field(u32, length)
+		__field(u8, source)
+		__field(u8, flags)
+		__field(u64, overflow_t)

The above looks nice and compact.

include/trace/events/cxl.h line 68

Quoted 13 lines
include/trace/events/cxl.h new file +13 -0
+	    ),
+
+	    TP_fast_assign(
+		__entry->pid = pid;
+		__assign_str(region, region ? region : "");
+		__assign_str(memdev, memdev);
+		__assign_str(pcidev, pcidev);
+		__entry->hpa = hpa;
+		__entry->dpa = dpa;
+		__entry->length = length;
+		__entry->source = source;
+		__entry->flags = flags;
+		__entry->overflow_t = overflow_t;

But I wonder if it would be better to move the computation of patch 2 here?

That is, this:

Review

Quoted 13 lines
(quoted diff) +13 -0
+		for (i = 0; i < le16_to_cpu(po->count); i++) {
+			u32 len = le32_to_cpu(po->record[i].length) *
+					      CXL_POISON_LEN_MULT;
+			u64 addr = le64_to_cpu(po->record[i].address);
+			u8 source = addr & CXL_POISON_SOURCE_MASK;
+			u64 dpa = addr & CXL_POISON_START_MASK;
+			u64 hpa = 0;
+
+			trace_cxl_poison(current->pid, region_name,
+					 dev_name(&cxlmd->dev),
+					 dev_name(cxlds->dev), hpa, dpa, len,
+					 source, po->flags, overflow_t);
+		}

As:

// The trace_*_enabled() is a static branch which is true when the // tracepoint is enabled, and a nop when not (skipping the for block)

		for (i = 0; trace_cxl_poison_enabled() && i < le16_to_cpu(po->count); i++)
			trace_cxl_poison(region_name, cxlmd, cxlds, &po->record[i]);

And then have:

	    TP_fast_assign(
		u32 len = le32_to_cpu(record->length) *
				      CXL_POISON_LEN_MULT;
		u64 addr = le64_to_cpu(record->address);
		u8 source = addr & CXL_POISON_SOURCE_MASK;
		u64 dpa = addr & CXL_POISON_START_MASK;
		u64 hpa = 0;

		__entry->pid = current->pid;

{ the above isn't needed as the trace event will have common_pid = current->pid }

		__assign_str(region, region ? region : "");
		__assign_str(memdev, dev_name(&cxlmd->dev));
		__assign_str(pcidev, dev_name(cxlds->dev));
		__entry->hpa = hpa;
		__entry->dpa = dpa;
		__entry->length = length;
		__entry->source = source;
		__entry->flags = flags;
		__entry->overflow_t = overflow_t;

Or something similar. This will keep the work out of the code path.

-- Steve

Quoted 15 lines
include/trace/events/cxl.h new file +15 -0
+	    ),
+
+	    TP_printk("pid:%d region:%s memdev:%s pcidev:%s hpa:0x%llx dpa:0x%llx length:0x%x source:%s flags:%s overflow_time:%llu",
+		__entry->pid,
+		__get_str(region),
+		__get_str(memdev),
+		__get_str(pcidev),
+		__entry->hpa,
+		__entry->dpa,
+		__entry->length,
+		show_poison_source(__entry->source),
+		show_poison_flags(__entry->flags),
+		__entry->overflow_t)
+);
+#endif /* _CXL_TRACE_H */
author maintainer
#3 lore raw

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

Quoted 61 lines · Steven Rostedt
Quoted 10 lines · On Wed, 12 Oct 2022 14:28:17 -0700 [email protected] wrote:
include/trace/events/cxl.h new file +10 -0
+TRACE_EVENT(cxl_poison,
+
+	    TP_PROTO(pid_t pid, const char *region, const char *memdev,
+		     const char *pcidev, u64 hpa, u64 dpa, u32 length,
+		     u8 source, u8 flags, u64 overflow_t),
+
+	    TP_ARGS(pid, region, memdev, pcidev, hpa, dpa,
+		    length, source, flags, overflow_t),
+
+	    TP_STRUCT__entry(

include/trace/events/cxl.h line 55

Quoted 10 lines
include/trace/events/cxl.h new file +10 -0
+		__field(pid_t, pid)
+		__string(region, region ? region : "")
+		__string(memdev, memdev)
+		__string(pcidev, pcidev)
+		__field(u64, hpa)
+		__field(u64, dpa)
+		__field(u32, length)
+		__field(u8, source)
+		__field(u8, flags)
+		__field(u64, overflow_t)

The above looks nice and compact.

include/trace/events/cxl.h line 68

Quoted 13 lines
include/trace/events/cxl.h new file +13 -0
+	    ),
+
+	    TP_fast_assign(
+		__entry->pid = pid;
+		__assign_str(region, region ? region : "");
+		__assign_str(memdev, memdev);
+		__assign_str(pcidev, pcidev);
+		__entry->hpa = hpa;
+		__entry->dpa = dpa;
+		__entry->length = length;
+		__entry->source = source;
+		__entry->flags = flags;
+		__entry->overflow_t = overflow_t;

But I wonder if it would be better to move the computation of patch 2 here?

That is, this:

Review

Quoted 13 lines
(quoted diff) +13 -0
+		for (i = 0; i < le16_to_cpu(po->count); i++) {
+			u32 len = le32_to_cpu(po->record[i].length) *
+					      CXL_POISON_LEN_MULT;
+			u64 addr = le64_to_cpu(po->record[i].address);
+			u8 source = addr & CXL_POISON_SOURCE_MASK;
+			u64 dpa = addr & CXL_POISON_START_MASK;
+			u64 hpa = 0;
+
+			trace_cxl_poison(current->pid, region_name,
+					 dev_name(&cxlmd->dev),
+					 dev_name(cxlds->dev), hpa, dpa, len,
+					 source, po->flags, overflow_t);
+		}

As:

Quoted 2 lines

// The trace_*_enabled() is a static branch which is true when the // tracepoint is enabled, and a nop when not (skipping the for block)

Thanks for pointing it out Steve. I will take advantage of that in next version.

In this case, we'd expect, but not enforce, that the tracepoint would be enabled, because otherwise we're just reading the data from the device and throwing it away.

I appreciate your help here!
Alison

Quoted 16 lines
		for (i = 0; trace_cxl_poison_enabled() && i < le16_to_cpu(po->count); i++)
			trace_cxl_poison(region_name, cxlmd, cxlds, &po->record[i]);

And then have:

	    TP_fast_assign(
		u32 len = le32_to_cpu(record->length) *
				      CXL_POISON_LEN_MULT;
		u64 addr = le64_to_cpu(record->address);
		u8 source = addr & CXL_POISON_SOURCE_MASK;
		u64 dpa = addr & CXL_POISON_START_MASK;
		u64 hpa = 0;

		__entry->pid = current->pid;
Quoted 1 line

{ the above isn't needed as the trace event will have common_pid = current->pid }

got it, thanks.

Quoted 32 lines
		__assign_str(region, region ? region : "");
		__assign_str(memdev, dev_name(&cxlmd->dev));
		__assign_str(pcidev, dev_name(cxlds->dev));
		__entry->hpa = hpa;
		__entry->dpa = dpa;
		__entry->length = length;
		__entry->source = source;
		__entry->flags = flags;
		__entry->overflow_t = overflow_t;

Or something similar. This will keep the work out of the code path.

-- Steve

Quoted 15 lines
include/trace/events/cxl.h new file +15 -0
+	    ),
+
+	    TP_printk("pid:%d region:%s memdev:%s pcidev:%s hpa:0x%llx dpa:0x%llx length:0x%x source:%s flags:%s overflow_time:%llu",
+		__entry->pid,
+		__get_str(region),
+		__get_str(memdev),
+		__get_str(pcidev),
+		__entry->hpa,
+		__entry->dpa,
+		__entry->length,
+		show_poison_source(__entry->source),
+		show_poison_flags(__entry->flags),
+		__entry->overflow_t)
+);
+#endif /* _CXL_TRACE_H */
#7 lore raw

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

In reply to [email protected]
Quoted 9 lines · On Wed, 12 Oct 2022 14:28:20 -0700 [email protected] wrote:

From: Alison Schofield <[email protected]>

When a boolean 'true' is written to this attribute the region driver retrieves the poison list for the capacity each device contributes to this region. The list includes addresses that are poisoned, or would result in poison if accessed, and the source of the poison. The retrieved errors are logged as kernel trace events with the label 'cxl_poison'.

Quoted 3 lines

Devices not supporting the poison list capability are ignored.

Hi Alison,

For some reason I don't have cxl_dpa_resource().
Should that be cxl_dpa_resource_start()?

Looks like it got renamed in
cxl/hdm: Add support for allocating DPA to an endpoint decoder cf880423b6a0599499c1f83542cab0b75daa29ba

Jonathan

Quoted 31 lines
drivers/cxl/core/region.c +31 -0
+static ssize_t trigger_poison_list_store(struct device *dev,
+					 struct device_attribute *attr,
+					 const char *buf, size_t len)
+{
+	struct cxl_region *cxlr = to_cxl_region(dev);
+	struct cxl_region_params *p = &cxlr->params;
+	struct cxl_endpoint_decoder *cxled;
+	struct cxl_memdev *cxlmd;
+	u64 offset, length;
+	int rc, i;
+	bool tmp;
+
+	if (kstrtobool(buf, &tmp))
+		return -EINVAL;
+
+	for (i = 0; i <  p->nr_targets; i++) {
+		cxled = p->targets[i];
+		cxlmd = cxled_to_memdev(cxled);
+		if (!test_bit(CXL_MEM_COMMAND_ID_GET_POISON,
+			      cxlmd->cxlds->enabled_cmds))
+			continue;
+		offset = cxl_dpa_resource(cxled);
+		length = cxl_dpa_size(cxled);
+		rc = cxl_mem_get_poison(cxlmd, offset, length,
+					dev_name(&cxlr->dev));
+		if (rc)
+			return rc;
+	}
+	return len;
+}
+static DEVICE_ATTR_WO(trigger_poison_list);
author maintainer
#8 lore raw

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

Quoted 12 lines · Jonathan Cameron
Quoted 9 lines · On Wed, 12 Oct 2022 14:28:20 -0700 [email protected] wrote:

From: Alison Schofield <[email protected]>

When a boolean 'true' is written to this attribute the region driver retrieves the poison list for the capacity each device contributes to this region. The list includes addresses that are poisoned, or would result in poison if accessed, and the source of the poison. The retrieved errors are logged as kernel trace events with the label 'cxl_poison'.

Quoted 8 lines
Quoted 3 lines

Devices not supporting the poison list capability are ignored.

Hi Alison,

For some reason I don't have cxl_dpa_resource().
Should that be cxl_dpa_resource_start()?

Yes.

Quoted 4 lines

Looks like it got renamed in
cxl/hdm: Add support for allocating DPA to an endpoint decoder cf880423b6a0599499c1f83542cab0b75daa29ba

Looks like it got renamed during the patches review. Not worth unravelling now. I will rebase in next version.

Sorry about that and thanks!
Alison

Quoted 34 lines

Jonathan

Quoted 31 lines
drivers/cxl/core/region.c +31 -0
+static ssize_t trigger_poison_list_store(struct device *dev,
+					 struct device_attribute *attr,
+					 const char *buf, size_t len)
+{
+	struct cxl_region *cxlr = to_cxl_region(dev);
+	struct cxl_region_params *p = &cxlr->params;
+	struct cxl_endpoint_decoder *cxled;
+	struct cxl_memdev *cxlmd;
+	u64 offset, length;
+	int rc, i;
+	bool tmp;
+
+	if (kstrtobool(buf, &tmp))
+		return -EINVAL;
+
+	for (i = 0; i <  p->nr_targets; i++) {
+		cxled = p->targets[i];
+		cxlmd = cxled_to_memdev(cxled);
+		if (!test_bit(CXL_MEM_COMMAND_ID_GET_POISON,
+			      cxlmd->cxlds->enabled_cmds))
+			continue;
+		offset = cxl_dpa_resource(cxled);
+		length = cxl_dpa_size(cxled);
+		rc = cxl_mem_get_poison(cxlmd, offset, length,
+					dev_name(&cxlr->dev));
+		if (rc)
+			return rc;
+	}
+	return len;
+}
+static DEVICE_ATTR_WO(trigger_poison_list);