All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/4] CXL Poison List Retrieval & Tracing
@ 2022-10-12 21:28 alison.schofield
  2022-10-12 21:28 ` [PATCH v2 1/4] trace, cxl: Introduce a TRACE_EVENT for CXL poison records alison.schofield
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: alison.schofield @ 2022-10-12 21:28 UTC (permalink / raw)
  To: Dan Williams, Ira Weiny, Vishal Verma, Dave Jiang, Ben Widawsky,
	Steven Rostedt, Ingo Molnar
  Cc: Alison Schofield, linux-cxl, linux-kernel

From: Alison Schofield <alison.schofield@intel.com>

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
-- 
2.37.3


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 1/4] trace, cxl: Introduce a TRACE_EVENT for CXL poison records
  2022-10-12 21:28 [PATCH v2 0/4] CXL Poison List Retrieval & Tracing alison.schofield
@ 2022-10-12 21:28 ` alison.schofield
  2022-10-12 21:46   ` Steven Rostedt
  2022-10-12 21:28 ` [PATCH v2 2/4] cxl/mbox: Add GET_POISON_LIST mailbox command alison.schofield
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: alison.schofield @ 2022-10-12 21:28 UTC (permalink / raw)
  To: Dan Williams, Ira Weiny, Vishal Verma, Dave Jiang, Ben Widawsky,
	Steven Rostedt, Ingo Molnar
  Cc: Alison Schofield, linux-cxl, linux-kernel

From: Alison Schofield <alison.schofield@intel.com>

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.

Signed-off-by: Alison Schofield <alison.schofield@intel.com>
---
 include/trace/events/cxl.h | 88 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)
 create mode 100644 include/trace/events/cxl.h

diff --git a/include/trace/events/cxl.h b/include/trace/events/cxl.h
new file mode 100644
index 000000000000..9613b0f18011
--- /dev/null
+++ b/include/trace/events/cxl.h
@@ -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>
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 2/4] cxl/mbox: Add GET_POISON_LIST mailbox command
  2022-10-12 21:28 [PATCH v2 0/4] CXL Poison List Retrieval & Tracing alison.schofield
  2022-10-12 21:28 ` [PATCH v2 1/4] trace, cxl: Introduce a TRACE_EVENT for CXL poison records alison.schofield
@ 2022-10-12 21:28 ` alison.schofield
  2022-10-12 21:28 ` [PATCH v2 3/4] cxl/memdev: Add trigger_poison_list sysfs attribute alison.schofield
  2022-10-12 21:28 ` [PATCH v2 4/4] cxl/region: " alison.schofield
  3 siblings, 0 replies; 9+ messages in thread
From: alison.schofield @ 2022-10-12 21:28 UTC (permalink / raw)
  To: Dan Williams, Ira Weiny, Vishal Verma, Dave Jiang, Ben Widawsky,
	Steven Rostedt, Ingo Molnar
  Cc: Alison Schofield, linux-cxl, linux-kernel

From: Alison Schofield <alison.schofield@intel.com>

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.

Signed-off-by: Alison Schofield <alison.schofield@intel.com>
---

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(+)

diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
index 40e3ccb2bf3e..f982645e35e4 100644
--- a/drivers/cxl/core/mbox.c
+++ b/drivers/cxl/core/mbox.c
@@ -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;
diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h
index a83bb6782d23..f5c6992de236 100644
--- a/drivers/cxl/cxlmem.h
+++ b/drivers/cxl/cxlmem.h
@@ -192,6 +192,8 @@ struct cxl_endpoint_dvsec_info {
  *                (CXL 2.0 8.2.8.4.3 Mailbox Capabilities Register)
  * @lsa_size: Size of Label Storage Area
  *                (CXL 2.0 8.2.9.5.1.1 Identify Memory Device)
+ * @poison_max: maximum media error records held in device cache
+ * @poison_list_mutex: Mutex to synchronize poison list retrieval
  * @mbox_mutex: Mutex to synchronize mailbox access.
  * @firmware_version: Firmware version for the memory device.
  * @enabled_cmds: Hardware commands found enabled in CEL.
@@ -223,6 +225,8 @@ struct cxl_dev_state {
 
 	size_t payload_size;
 	size_t lsa_size;
+	u32 poison_max;
+	struct mutex poison_list_mutex;  /* Protect reads of poison list */
 	struct mutex mbox_mutex; /* Protects device mailbox and firmware */
 	char firmware_version[0x10];
 	DECLARE_BITMAP(enabled_cmds, CXL_MEM_COMMAND_ID_MAX);
@@ -344,6 +348,42 @@ struct cxl_mbox_set_partition_info {
 
 #define  CXL_SET_PARTITION_IMMEDIATE_FLAG	BIT(0)
 
+struct cxl_mbox_poison_payload_in {
+	__le64 offset;
+	__le64 length;
+} __packed;
+
+struct cxl_mbox_poison_payload_out {
+	u8 flags;
+	u8 rsvd1;
+	__le64 overflow_timestamp;
+	__le16 count;
+	u8 rsvd2[0x14];
+	struct cxl_poison_record {
+		__le64 address;
+		__le32 length;
+		__le32 rsvd;
+	} __packed record[];
+} __packed;
+
+/* 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)
+
+/*
+ * CXL 8.2.9.5.4.1 Get Poison List address field encodes both the
+ * starting address of poison, and the source of the poison.
+ */
+#define CXL_POISON_START_MASK		GENMASK_ULL(63, 6)
+#define CXL_POISON_SOURCE_MASK		GENMASK(2, 0)
+
+/* CXL 8.2.9.5.4.1 Table 188: Length is in units of 64 bytes */
+#define CXL_POISON_LEN_MULT	64
+
+/* Kernel maximum for a cache of media poison errors */
+#define CXL_POISON_LIST_MAX	1024
+
 /**
  * struct cxl_mem_command - Driver representation of a memory device command
  * @info: Command information as it exists for the UAPI
@@ -378,6 +418,8 @@ int cxl_mem_create_range_info(struct cxl_dev_state *cxlds);
 struct cxl_dev_state *cxl_dev_state_create(struct device *dev);
 void set_exclusive_cxl_commands(struct cxl_dev_state *cxlds, unsigned long *cmds);
 void clear_exclusive_cxl_commands(struct cxl_dev_state *cxlds, unsigned long *cmds);
+int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
+		       const char *region_name);
 #ifdef CONFIG_CXL_SUSPEND
 void cxl_mem_active_inc(void);
 void cxl_mem_active_dec(void);
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 3/4] cxl/memdev: Add trigger_poison_list sysfs attribute
  2022-10-12 21:28 [PATCH v2 0/4] CXL Poison List Retrieval & Tracing alison.schofield
  2022-10-12 21:28 ` [PATCH v2 1/4] trace, cxl: Introduce a TRACE_EVENT for CXL poison records alison.schofield
  2022-10-12 21:28 ` [PATCH v2 2/4] cxl/mbox: Add GET_POISON_LIST mailbox command alison.schofield
@ 2022-10-12 21:28 ` alison.schofield
  2022-10-12 21:28 ` [PATCH v2 4/4] cxl/region: " alison.schofield
  3 siblings, 0 replies; 9+ messages in thread
From: alison.schofield @ 2022-10-12 21:28 UTC (permalink / raw)
  To: Dan Williams, Ira Weiny, Vishal Verma, Dave Jiang, Ben Widawsky,
	Steven Rostedt, Ingo Molnar
  Cc: Alison Schofield, linux-cxl, linux-kernel

From: Alison Schofield <alison.schofield@intel.com>

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

Signed-off-by: Alison Schofield <alison.schofield@intel.com>
---
 Documentation/ABI/testing/sysfs-bus-cxl | 14 +++++++++
 drivers/cxl/core/memdev.c               | 41 +++++++++++++++++++++++++
 2 files changed, 55 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/testing/sysfs-bus-cxl
index 0debe2955f34..ab3665f8738e 100644
--- a/Documentation/ABI/testing/sysfs-bus-cxl
+++ b/Documentation/ABI/testing/sysfs-bus-cxl
@@ -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:	linux-cxl@vger.kernel.org
+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'.
diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
index 20ce488a7754..06d265db5127 100644
--- a/drivers/cxl/core/memdev.c
+++ b/drivers/cxl/core/memdev.c
@@ -106,12 +106,45 @@ static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(numa_node);
 
+static ssize_t trigger_poison_list_store(struct device *dev,
+					 struct device_attribute *attr,
+					 const char *buf, size_t len)
+{
+	struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
+	struct cxl_dev_state *cxlds = cxlmd->cxlds;
+	u64 offset, length;
+	bool tmp;
+	int rc;
+
+	if (kstrtobool(buf, &tmp))
+		return -EINVAL;
+
+	/* Per CXL Spec, separate the pmem and ram poison list reads */
+	if (resource_size(&cxlds->pmem_res)) {
+		offset = cxlds->pmem_res.start;
+		length = resource_size(&cxlds->pmem_res);
+		rc = cxl_mem_get_poison(cxlmd, offset, length, NULL);
+		if (rc)
+			return rc;
+	}
+	if (resource_size(&cxlds->ram_res)) {
+		offset = cxlds->ram_res.start;
+		length = resource_size(&cxlds->ram_res);
+		rc = cxl_mem_get_poison(cxlmd, offset, length, NULL);
+		if (rc)
+			return rc;
+	}
+	return len;
+}
+static DEVICE_ATTR_WO(trigger_poison_list);
+
 static struct attribute *cxl_memdev_attributes[] = {
 	&dev_attr_serial.attr,
 	&dev_attr_firmware_version.attr,
 	&dev_attr_payload_max.attr,
 	&dev_attr_label_storage_size.attr,
 	&dev_attr_numa_node.attr,
+	&dev_attr_trigger_poison_list.attr,
 	NULL,
 };
 
@@ -130,6 +163,14 @@ static umode_t cxl_memdev_visible(struct kobject *kobj, struct attribute *a,
 {
 	if (!IS_ENABLED(CONFIG_NUMA) && a == &dev_attr_numa_node.attr)
 		return 0;
+
+	if (a == &dev_attr_trigger_poison_list.attr) {
+		struct device *dev = kobj_to_dev(kobj);
+
+		if (!test_bit(CXL_MEM_COMMAND_ID_GET_POISON,
+			      to_cxl_memdev(dev)->cxlds->enabled_cmds))
+			return 0;
+	}
 	return a->mode;
 }
 
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 4/4] cxl/region: Add trigger_poison_list sysfs attribute
  2022-10-12 21:28 [PATCH v2 0/4] CXL Poison List Retrieval & Tracing alison.schofield
                   ` (2 preceding siblings ...)
  2022-10-12 21:28 ` [PATCH v2 3/4] cxl/memdev: Add trigger_poison_list sysfs attribute alison.schofield
@ 2022-10-12 21:28 ` alison.schofield
  2022-10-17 13:43   ` Jonathan Cameron
  3 siblings, 1 reply; 9+ messages in thread
From: alison.schofield @ 2022-10-12 21:28 UTC (permalink / raw)
  To: Dan Williams, Ira Weiny, Vishal Verma, Dave Jiang, Ben Widawsky,
	Steven Rostedt, Ingo Molnar
  Cc: Alison Schofield, linux-cxl, linux-kernel

From: Alison Schofield <alison.schofield@intel.com>

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.

Signed-off-by: Alison Schofield <alison.schofield@intel.com>
---
 Documentation/ABI/testing/sysfs-bus-cxl | 14 ++++++++++
 drivers/cxl/core/region.c               | 34 +++++++++++++++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/testing/sysfs-bus-cxl
index ab3665f8738e..7e33f6ee4992 100644
--- a/Documentation/ABI/testing/sysfs-bus-cxl
+++ b/Documentation/ABI/testing/sysfs-bus-cxl
@@ -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:	linux-cxl@vger.kernel.org
+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'.
diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index ad21b2aa3b0a..e20207934336 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -72,6 +72,38 @@ static int is_dup(struct device *match, void *data)
 	return 0;
 }
 
+static ssize_t trigger_poison_list_store(struct device *dev,
+					 struct device_attribute *attr,
+					 const char *buf, size_t len)
+{
+	struct cxl_region *cxlr = to_cxl_region(dev);
+	struct cxl_region_params *p = &cxlr->params;
+	struct cxl_endpoint_decoder *cxled;
+	struct cxl_memdev *cxlmd;
+	u64 offset, length;
+	int rc, i;
+	bool tmp;
+
+	if (kstrtobool(buf, &tmp))
+		return -EINVAL;
+
+	for (i = 0; i <  p->nr_targets; i++) {
+		cxled = p->targets[i];
+		cxlmd = cxled_to_memdev(cxled);
+		if (!test_bit(CXL_MEM_COMMAND_ID_GET_POISON,
+			      cxlmd->cxlds->enabled_cmds))
+			continue;
+		offset = cxl_dpa_resource(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,
 };
 
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 1/4] trace, cxl: Introduce a TRACE_EVENT for CXL poison records
  2022-10-12 21:28 ` [PATCH v2 1/4] trace, cxl: Introduce a TRACE_EVENT for CXL poison records alison.schofield
@ 2022-10-12 21:46   ` Steven Rostedt
  2022-10-14  4:39     ` Alison Schofield
  0 siblings, 1 reply; 9+ messages in thread
From: Steven Rostedt @ 2022-10-12 21:46 UTC (permalink / raw)
  To: alison.schofield
  Cc: Dan Williams, Ira Weiny, Vishal Verma, Dave Jiang, Ben Widawsky,
	Ingo Molnar, linux-cxl, linux-kernel

On Wed, 12 Oct 2022 14:28:17 -0700
alison.schofield@intel.com wrote:

> +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)

The above looks nice and compact.

> +	    ),
> +
> +	    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:

> +		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


> +	    ),
> +
> +	    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 */

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 1/4] trace, cxl: Introduce a TRACE_EVENT for CXL poison records
  2022-10-12 21:46   ` Steven Rostedt
@ 2022-10-14  4:39     ` Alison Schofield
  0 siblings, 0 replies; 9+ messages in thread
From: Alison Schofield @ 2022-10-14  4:39 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Dan Williams, Ira Weiny, Vishal Verma, Dave Jiang, Ben Widawsky,
	Ingo Molnar, linux-cxl, linux-kernel

On Wed, Oct 12, 2022 at 05:46:20PM -0400, Steven Rostedt wrote:
> On Wed, 12 Oct 2022 14:28:17 -0700
> alison.schofield@intel.com wrote:
> 
> > +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)
> 
> The above looks nice and compact.
> 
> > +	    ),
> > +
> > +	    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:
> 
> > +		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)

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

> 
> 		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 }

got it, thanks.

> 
> 		__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
> 
> 
> > +	    ),
> > +
> > +	    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 */

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 4/4] cxl/region: Add trigger_poison_list sysfs attribute
  2022-10-12 21:28 ` [PATCH v2 4/4] cxl/region: " alison.schofield
@ 2022-10-17 13:43   ` Jonathan Cameron
  2022-10-17 18:01     ` Alison Schofield
  0 siblings, 1 reply; 9+ messages in thread
From: Jonathan Cameron @ 2022-10-17 13:43 UTC (permalink / raw)
  To: alison.schofield
  Cc: Dan Williams, Ira Weiny, Vishal Verma, Dave Jiang, Ben Widawsky,
	Steven Rostedt, Ingo Molnar, linux-cxl, linux-kernel

On Wed, 12 Oct 2022 14:28:20 -0700
alison.schofield@intel.com wrote:

> From: Alison Schofield <alison.schofield@intel.com>
> 
> 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.
> 
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>

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

> +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);

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 4/4] cxl/region: Add trigger_poison_list sysfs attribute
  2022-10-17 13:43   ` Jonathan Cameron
@ 2022-10-17 18:01     ` Alison Schofield
  0 siblings, 0 replies; 9+ messages in thread
From: Alison Schofield @ 2022-10-17 18:01 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Dan Williams, Ira Weiny, Vishal Verma, Dave Jiang, Ben Widawsky,
	Steven Rostedt, Ingo Molnar, linux-cxl, linux-kernel

On Mon, Oct 17, 2022 at 02:43:02PM +0100, Jonathan Cameron wrote:
> On Wed, 12 Oct 2022 14:28:20 -0700
> alison.schofield@intel.com wrote:
> 
> > From: Alison Schofield <alison.schofield@intel.com>
> > 
> > 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.
> > 
> > Signed-off-by: Alison Schofield <alison.schofield@intel.com>
> 
> Hi Alison,
> 
> For some reason I don't have cxl_dpa_resource().
> Should that be cxl_dpa_resource_start()?

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

> 
> Jonathan
> 
> > +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);

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-10-17 18:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-12 21:28 [PATCH v2 0/4] CXL Poison List Retrieval & Tracing alison.schofield
2022-10-12 21:28 ` [PATCH v2 1/4] trace, cxl: Introduce a TRACE_EVENT for CXL poison records alison.schofield
2022-10-12 21:46   ` Steven Rostedt
2022-10-14  4:39     ` Alison Schofield
2022-10-12 21:28 ` [PATCH v2 2/4] cxl/mbox: Add GET_POISON_LIST mailbox command alison.schofield
2022-10-12 21:28 ` [PATCH v2 3/4] cxl/memdev: Add trigger_poison_list sysfs attribute alison.schofield
2022-10-12 21:28 ` [PATCH v2 4/4] cxl/region: " alison.schofield
2022-10-17 13:43   ` Jonathan Cameron
2022-10-17 18:01     ` Alison Schofield

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.