CXL Poison List Retrieval & Tracing
[email protected]
maintainerv6 cover CXL Poison List Retrieval & Tracing
From: Alison Schofield <[email protected]>
This is not targeting the 6.3 merge window.
Changes in v6:
- Remove the ABI that collected poison per region, and added the region info to the per memdev collection. (Dan)
This means Patch 4 is brand new:
cxl/region: Provide region info to the cxl_poison trace event
- Also added Patch 5: cxl/trace: Add an HPA to cxl_poison trace events to this set. It comes w a couple of Review Tags, and is unchanged, from a v2 last posted upstream.
- Dropped Jonathan's Review on Patch 3 because of changes
- Remove local var 'cxlps' (cxl_poison_state) (Dan)
- Trigger sysfs attr on boolean truisms only (Dan)
- Remove unneeded param pcidev from trace call.
- Mock: add __packed, and le64_to_cpu(() (Dan)
- Abbreviate less: s/max_mer/max_errors (Dan)
- Rename trace field 'pcidev', 'host' (Dan)
- getpoison_po/payload_out (Dan)
- Add serial no. to trace (Dan)
- s/getpoison_lock/lock (Dan)
- s/tmp/trigger
Link to v5: 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:
$ echo 1 > /sys/bus/cxl/devices/mem0/trigger_poison_list cxl_poison: memdev=mem0 serial=0 host=cxl_mem.0 region=region4 region_uuid=117b2cf4-b160-4090-9361-ba31b9649317 hpa=0xf0d0000000 dpa=0x40000000 length=0x40 source=Internal 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 | 5 ++ drivers/cxl/core/mbox.c | 74 +++++++++++++++++++ drivers/cxl/core/memdev.c | 68 ++++++++++++++++++ drivers/cxl/core/region.c | 82 +++++++++++++++++++++ drivers/cxl/core/trace.c | 94 +++++++++++++++++++++++++ drivers/cxl/core/trace.h | 92 ++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 69 +++++++++++++++++- drivers/cxl/pci.c | 4 ++ tools/testing/cxl/test/mem.c | 42 +++++++++++ 10 files changed, 543 insertions(+), 1 deletion(-)
base-commit: dbe9f7d1e155b97a42f7da81e22acc98fe0a9072
Signature · 1 line
2.37.3
[email protected]
maintainerPATCH v6 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 | 72 +++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 67 ++++++++++++++++++++++++++++++++++++++ drivers/cxl/pci.c | 4 +++ 3 files changed, 143 insertions(+)
drivers/cxl/core/mbox.c +72 -0
@@ -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>
@@ -989,6 +991,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 ) {
@@ -1012,6 +1015,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 );
@@ -1102,6 +1110,70 @@ 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_payload_out *po; +struct cxl_mbox_poison_payload_in pi; +struct cxl_mbox_cmd mbox_cmd; +int nr_records =0 ; +int rc; + + rc =mutex_lock_interruptible (&cxlds->poison.lock); +if (rc) +return rc; + + po = cxlds->poison.payload_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.payload_out =devm_kzalloc (cxlds->dev, + cxlds->payload_size, +GFP_KERNEL ); +if (!cxlds->poison.payload_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
@@ -713,6 +713,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
[email protected]
maintainerPATCH v6 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 trace event of type 'cxl_poison'.
--- drivers/cxl/core/mbox.c | 4 +- drivers/cxl/core/trace.h | 85 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-)
drivers/cxl/core/mbox.c +3 -1
@@ -1142,7 +1142,9 @@ 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);/* Protect against an uncleared _FLAG_MORE */ nr_records = nr_records +le16_to_cpu (po->count);
drivers/cxl/core/trace.h +85 -0
97 lines not on this page · raw message
Signature · 1 line
2.37.3
[email protected]
maintainerPATCH v6 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 trace events with the label 'cxl_poison'.
--- Documentation/ABI/testing/sysfs-bus-cxl | 14 +++++++ drivers/cxl/core/memdev.c | 56 +++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 2 +- 3 files changed, 71 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-bus-cxl +14 -0
@@ -403,3 +403,17 @@ Description: 1), and checks that the hardware accepts the commit request. Reading this value indicates whether the region is committed or not. + + +What: /sys/bus/cxl/devices/memX/trigger_poison_list +Date: November, 2022 +KernelVersion: v6.2 +Contact: [email protected] +Description: + (WO) When a boolean 'true' is written to this attribute the + memdev driver retrieves the poison list from the device. The + list consists of addresses that are poisoned, or would result + in poison if accessed, and the source of the poison. This + attribute is only visible for devices supporting the + capability. The retrieved errors are logged as kernel + trace events with the label 'cxl_poison'.
drivers/cxl/core/memdev.c +56 -0
74 lines not on this page · raw message
drivers/cxl/cxlmem.h +1 -1
@@ -140,7 +140,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"), \
Signature · 1 line
2.37.3
[email protected]
maintainerPATCH v6 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. The default method remains:
read the poison by memdev resource.
--- drivers/cxl/core/core.h | 5 +++ drivers/cxl/core/memdev.c | 14 ++++++- drivers/cxl/core/region.c | 82 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 1 deletion(-)
drivers/cxl/core/core.h +5 -0
@@ -22,7 +22,12 @@ void cxl_decoder_kill_region(struct cxl_endpoint_decoder *cxled);#define CXL_PMEM_REGION_TYPE (x) (&cxl_pmem_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) { }
drivers/cxl/core/memdev.c +13 -1
@@ -139,14 +139,26 @@ static ssize_t trigger_poison_list_store(struct device *dev, const char *buf, size_t len) {struct cxl_memdev *cxlmd =to_cxl_memdev (dev); +struct cxl_port *port;bool trigger;int 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 */ + rc =cxl_get_poison_by_memdev (cxlmd); +else +/* Regions mapped, collect poison by endpoint */ + rc =device_for_each_child (&port->dev, port, + cxl_get_poison_by_endpoint); +up_read (&cxl_dpa_rwsem);return rc ? rc : len;
drivers/cxl/core/region.c +82 -0
88 lines not on this page · raw message
Signature · 1 line
2.37.3
Re: [PATCH v6 4/6] cxl/region: Provide region info to the cxl_poison trace event
Quoted 9 lines · On Thu, 9 Feb 2023 15:32:57 -0800 [email protected] 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_poisontrace 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.
Quoted 8 lines
The
cxl_poisontrace event is already wired up to log the region name and uuid if it receives param 'structcxl_region'.In order to provide that
cxl_region, add another method for gathering poison - by committed endpoint decoder mappings. This method is only available withCONFIG_CXL_REGIONand is only used if a region actually maps the memdev where poison is being read. The default method remains:
read the poison by memdev resource.
Mention here that you also cover memory that isn't mapped.
A few minor comments inline.
Thanks,
Jonathan
Quoted 78 lines
Signed-off-by Alison Schofield <[email protected]>--- drivers/cxl/core/core.h | 5 +++ drivers/cxl/core/memdev.c | 14 ++++++- drivers/cxl/core/region.c | 82 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 1 deletion(-)drivers/cxl/core/core.h +5
-0@@ -22,7 +22,12 @@ void cxl_decoder_kill_region(struct cxl_endpoint_decoder *cxled);#define CXL_PMEM_REGION_TYPE (x) (&cxl_pmem_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) { }drivers/cxl/core/memdev.c +13
-1@@ -139,14 +139,26 @@ static ssize_t trigger_poison_list_store(struct device *dev, const char *buf, size_t len) {struct cxl_memdev *cxlmd =to_cxl_memdev (dev); +struct cxl_port *port;bool trigger;int 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 */ + rc =cxl_get_poison_by_memdev (cxlmd); +else +/* Regions mapped, collect poison by endpoint */ + rc =device_for_each_child (&port->dev, port, + cxl_get_poison_by_endpoint); +up_read (&cxl_dpa_rwsem);return rc ? rc : len;drivers/cxl/core/region.c +13
-0@@ -1826,6 +1826,88 @@ 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 *data) +{ +struct cxl_endpoint_decoder *cxled; +struct cxl_port *port = data; +struct cxl_dev_state *cxlds; +struct cxl_memdev *cxlmd; +u64 offset, length; +int rc =0 ; + +down_read (&cxl_dpa_rwsem); + +if (!is_endpoint_decoder (dev)) + goto out;
drivers/cxl/core/region.c struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev) · line 1851
Quoted 10 lines
drivers/cxl/core/region.c +10
-0+ + cxled =to_cxl_endpoint_decoder (dev); +if (!cxled->dpa_res || !resource_size (cxled->dpa_res)) + goto out; + +/* +* Get the poison by decoder for mapped resources. This +* separates pmem and ram poison list reads, as the spec +* requires, and provides the region for the trace event. +*/
Does the spec actually require separate decoders for PMEM and MEM? Sure, Linux only sets it up like that, but a BIOS might have set them up as a single decoder I think - even if we don't handle that form of crazy yet. If the spec requires it, then a reference would be great.
drivers/cxl/core/region.c struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev) · line 1861
Quoted 10 lines
drivers/cxl/core/region.c +10
-0+ cxlmd =cxled_to_memdev (cxled); + length = cxled->dpa_res->end - cxled->dpa_res->start +1 ; + rc =cxl_mem_get_poison (cxlmd, cxled->dpa_res->start, length, + cxled->cxld.region); +if (rc == -EFAULT && cxled->mode ==CXL_DECODER_RAM ) + rc =0 ; +if (rc) + goto out; + +/* Get poison in a skip range */
Seems odd to do it in this order. I'd do the skip first as then the records will appear in address order (subject to whatever random order the device is tracking them and the resulting ordering in each request)
Quoted 52 lines
drivers/cxl/core/region.c +49
-0+if (cxled->skip) { + rc =cxl_mem_get_poison (cxlmd,0 , cxled->skip,NULL ); +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) + goto out; + +/* +* Reach here with the last committed decoder only. +* Knowing that PMEM must always follow RAM, get poison +* for unmapped ranges based on the last decoder's mode: +* ram: scan remains of ram range, then scan for pmem +* pmem: scan remains of pmem range +*/ + cxlds = cxlmd->cxlds; + +if (cxled->mode ==CXL_DECODER_RAM ) { + offset = cxled->dpa_res->end +1 ; + length =resource_size (&cxlds->ram_res) - offset; + rc =cxl_mem_get_poison (cxlmd, offset, length,NULL ); +if (rc == -EFAULT ) + rc =0 ; +if (rc) + goto out; + } +if (cxled->mode ==CXL_DECODER_PMEM ) { + offset = cxled->dpa_res->end +1 ; + length =resource_size (&cxlds->pmem_res) - offset; + }else if (resource_size (&cxlds->pmem_res)) { + offset = cxlds->pmem_res.start; + length =resource_size (&cxlds->pmem_res); + }else { + rc =1 ; + goto out; + } +/* Final get poison call. Return rc or 1 to stop iteration. */ + rc =cxl_mem_get_poison (cxlmd, offset, length,NULL ); +if (!rc) + rc =1 ; +out: +up_read (&cxl_dpa_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)
Alison Schofield
maintainerRe: [PATCH v6 4/6] cxl/region: Provide region info to the cxl_poison trace event
Quoted 15 lines · Jonathan Cameron
Quoted 12 lines · On Thu, 9 Feb 2023 15:32:57 -0800 [email protected] 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_poisontrace 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_poisontrace event is already wired up to log the region name and uuid if it receives param 'structcxl_region'.
Quoted 7 lines
Quoted 5 lines
In order to provide that
cxl_region, add another method for gathering poison - by committed endpoint decoder mappings. This method is only available withCONFIG_CXL_REGIONand is only used if a region actually maps the memdev where poison is being read. The default method remains:
read the poison by memdev resource.Mention here that you also cover memory that isn't mapped.
Ok, will do. And will also mention that we don't cover CXL_DECODER_MIXED, as I'm noting below...
Quoted 94 lines
A few minor comments inline.
Thanks,
Jonathan
Quoted 86 lines
Signed-off-by Alison Schofield <[email protected]>--- drivers/cxl/core/core.h | 5 +++ drivers/cxl/core/memdev.c | 14 ++++++- drivers/cxl/core/region.c | 82 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 1 deletion(-)drivers/cxl/core/core.h +5
-0@@ -22,7 +22,12 @@ void cxl_decoder_kill_region(struct cxl_endpoint_decoder *cxled);#define CXL_PMEM_REGION_TYPE (x) (&cxl_pmem_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) { }drivers/cxl/core/memdev.c +13
-1@@ -139,14 +139,26 @@ static ssize_t trigger_poison_list_store(struct device *dev, const char *buf, size_t len) {struct cxl_memdev *cxlmd =to_cxl_memdev (dev); +struct cxl_port *port;bool trigger;int 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 */ + rc =cxl_get_poison_by_memdev (cxlmd); +else +/* Regions mapped, collect poison by endpoint */ + rc =device_for_each_child (&port->dev, port, + cxl_get_poison_by_endpoint); +up_read (&cxl_dpa_rwsem);return rc ? rc : len;drivers/cxl/core/region.c +21
-0@@ -1826,6 +1826,88 @@ 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 *data) +{ +struct cxl_endpoint_decoder *cxled; +struct cxl_port *port = data; +struct cxl_dev_state *cxlds; +struct cxl_memdev *cxlmd; +u64 offset, length; +int rc =0 ; + +down_read (&cxl_dpa_rwsem); + +if (!is_endpoint_decoder (dev)) + goto out; + + cxled =to_cxl_endpoint_decoder (dev); +if (!cxled->dpa_res || !resource_size (cxled->dpa_res)) + goto out; + +/* +* Get the poison by decoder for mapped resources. This +* separates pmem and ram poison list reads, as the spec
Quoted 9 lines
drivers/cxl/core/region.c struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev) · line 1851
Quoted 2 lines
drivers/cxl/core/region.c +2
-0+* requires, and provides the region for the trace event. +*/ Does the spec actually require separate decoders for PMEM and MEM? Sure, Linux only sets it up like that, but a BIOS might have set them up as a single decoder I think - even if we don't handle that form of crazy yet. If the spec requires it, then a reference would be great.
No, the spec allows mixed mode decoders. I chatted w Dan about this, and we're suggesting skipping poison reads when mode == CXL_DECODER_MIXED. That skip would be quiet, just a dev_debug(). But, add some more noise to the front end by changing adding this dev_warn() :
drivers/cxl/core/hdm.c +2 -2
@@ -268,8 +268,8 @@ static int __cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled,else if (resource_contains (&cxlds->ram_res, res)) cxled->mode =CXL_DECODER_RAM ;else { -dev_dbg (dev,"decoder%d.%d: %pr mixed\n" , port->id, - cxled->cxld.id, cxled->dpa_res); +dev_warn (dev,"decoder%d.%d: %pr mixed mode not supported\n" , + port->id, cxled->cxld.id, cxled->dpa_res); cxled->mode =CXL_DECODER_MIXED ; }
Quoted 7 lines
Quoted 7 lines
drivers/cxl/core/region.c +7
-0+ cxlmd =cxled_to_memdev (cxled); + length = cxled->dpa_res->end - cxled->dpa_res->start +1 ; + rc =cxl_mem_get_poison (cxlmd, cxled->dpa_res->start, length, + cxled->cxld.region); +if (rc == -EFAULT && cxled->mode ==CXL_DECODER_RAM ) + rc =0 ; +if (rc)
Quoted 9 lines
drivers/cxl/core/region.c struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev) · line 1861
Quoted 3 lines
drivers/cxl/core/region.c +3
-0+ goto out; + +/* Get poison in a skip range */ Seems odd to do it in this order. I'd do the skip first as then the records will appear in address order (subject to whatever random order the device is tracking them and the resulting ordering in each request)
Yes - skip should be logically first, since those addresses would be before any mapped addresses. Thanks for pointing it out.
Quoted 53 lines
Quoted 52 lines
drivers/cxl/core/region.c +49
-0+if (cxled->skip) { + rc =cxl_mem_get_poison (cxlmd,0 , cxled->skip,NULL ); +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) + goto out; + +/* +* Reach here with the last committed decoder only. +* Knowing that PMEM must always follow RAM, get poison +* for unmapped ranges based on the last decoder's mode: +* ram: scan remains of ram range, then scan for pmem +* pmem: scan remains of pmem range +*/ + cxlds = cxlmd->cxlds; + +if (cxled->mode ==CXL_DECODER_RAM ) { + offset = cxled->dpa_res->end +1 ; + length =resource_size (&cxlds->ram_res) - offset; + rc =cxl_mem_get_poison (cxlmd, offset, length,NULL ); +if (rc == -EFAULT ) + rc =0 ; +if (rc) + goto out; + } +if (cxled->mode ==CXL_DECODER_PMEM ) { + offset = cxled->dpa_res->end +1 ; + length =resource_size (&cxlds->pmem_res) - offset; + }else if (resource_size (&cxlds->pmem_res)) { + offset = cxlds->pmem_res.start; + length =resource_size (&cxlds->pmem_res); + }else { + rc =1 ; + goto out; + } +/* Final get poison call. Return rc or 1 to stop iteration. */ + rc =cxl_mem_get_poison (cxlmd, offset, length,NULL ); +if (!rc) + rc =1 ; +out: +up_read (&cxl_dpa_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)
[email protected]
maintainerPATCH v6 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 hpa event field.
--- drivers/cxl/core/trace.c | 94 ++++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/trace.h | 9 +++- 2 files changed, 102 insertions(+), 1 deletion(-)
drivers/cxl/core/trace.c +94 -0
@@ -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 +8 -1
@@ -614,6 +614,8 @@ TRACE_EVENT(cxl_memory_module,#define cxl_poison_host_name (cxlmd) \ (dev_name(cxlmd->dev.parent)) +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,
@@ -628,6 +630,7 @@ TRACE_EVENT(cxl_poison, __field(u64, serial) __string(region, region) __field(u64, overflow_t) + __field(u64, hpa) __field(u64, dpa) __field(u32, length)__array (char, uuid,16 )
@@ -647,18 +650,22 @@ TRACE_EVENT(cxl_poison,if (region) {__assign_str (region,dev_name (®ion->dev));memcpy (__entry->uuid, ®ion->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 serial=%llu host=%s region=%s region_uuid=%pU dpa=0x%llx length=0x%x source=%s flags=%s overflow_time=%llu", + TP_printk("memdev=%s serial=%llu host=%s region=%s region_uuid=%pU hpa=0x%llx dpa=0x%llx length=0x%x source=%s flags=%s overflow_time=%llu", __get_str(memdev), __entry->serial, __get_str(host), __get_str(region), __entry->uuid, + __entry->hpa, __entry->dpa, __entry->length, show_poison_source(__entry->source),
Signature · 1 line
2.37.3
[email protected]
maintainerPATCH v6 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
@@ -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_payload_in *pi = cmd->payload_in; + +/* Mock one poison record at pi.offset for 64 bytes */ +struct { +struct cxl_mbox_poison_payload_out po; +struct cxl_poison_record record; + } __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