CXL Poison List Retrieval & Tracing
[email protected]
maintainerv10 cover CXL Poison List Retrieval & Tracing
From: Alison Schofield <[email protected]>
Changes in v10:
Patch 2/6 cxl/trace: Add TRACE support for CXL media-error records
- Rename the cxl_poison trace event field 'length' to 'dpa_length' (Jonathan) The dpa_length here is the dpa length as reported by the device.
- Add a 'type' field to the cxl_poison TRACE_EVENT and define and use type 'CXL_POISON_TRACE_LIST'. This is in preparation for adding more cxl_poison_trace_type's like CXL_POISON_TRACE_(INJECT | CLEAR)
- Use continuations in TP_printk to match the file convention.
Patch 4/6 cxl/region: Provide region info to the cxl_poison trace event
- Add Jonathan Reviewed-by (for real) and Tested-by Tags (Jonathan)
- Tidy blank line at return in trigger_poison_list_store() (Jonathan)
Patches 1,3,5,6: no changes.
Cover Letter:
- Updated the example cxl_poison TRACE_EVENTs to show type=LIST
Link to v9:
https://lore.kernel.org/linux-cxl/[email protected]/
End Changelog
Add support for retrieving device poison lists and store the returned error records as kernel trace events.
The handling of the poison list is guided by the CXL 3.0 Specification Section 8.2.9.8.4.1. [1]
Example trigger:
$ echo 1 > /sys/bus/cxl/devices/mem0/trigger_poison_list
Example Trace Events:
Poison found in a PMEM Region:cxl_poison: memdev=mem0 host=cxl_mem.0 serial=0 type=LIST region=region11 region_uuid=d96e67ec-76b0-406f-8c35-5b52630dcad1 hpa=0xf100000000 dpa=0x70000000 dpa_length=0x40 source=Injected flags= overflow_time=0
Poison found in RAM Region:cxl_poison: memdev=mem0 host=cxl_mem.0 serial=0 type=LIST region=region2 region_uuid=00000000-0000-0000-0000-000000000000 hpa=0xf010000000 dpa=0x0 dpa_length=0x40 source=Injected flags= overflow_time=0
Poison found in an unmapped DPA resource:cxl_poison: memdev=mem3 host=cxl_mem.3 serial=3 type=LIST region= region_uuid=00000000-0000-0000-0000-000000000000 hpa=0xffffffffffffffff dpa=0x40000000 dpa_length=0x40 source=Injected flags= overflow_time=0
[1]: https://www.computeexpresslink.org/download-the-specification
Alison Schofield (6):
cxl/mbox: Add GET_POISON_LIST mailbox command cxl/trace: Add TRACE support for CXL media-error records cxl/memdev: Add trigger_poison_list sysfs attribute cxl/region: Provide region info to the cxl_poison trace event cxl/trace: Add an HPA to cxl_poison trace events tools/testing/cxl: Mock support for Get Poison List
Documentation/ABI/testing/sysfs-bus-cxl | 14 +++ drivers/cxl/core/core.h | 15 ++++ drivers/cxl/core/mbox.c | 75 ++++++++++++++++ drivers/cxl/core/memdev.c | 108 ++++++++++++++++++++++++ drivers/cxl/core/region.c | 63 ++++++++++++++ drivers/cxl/core/trace.c | 94 +++++++++++++++++++++ drivers/cxl/core/trace.h | 101 ++++++++++++++++++++++ drivers/cxl/cxlmem.h | 72 +++++++++++++++- drivers/cxl/mem.c | 36 ++++++++ drivers/cxl/pci.c | 4 + tools/testing/cxl/test/mem.c | 42 +++++++++ 11 files changed, 623 insertions(+), 1 deletion(-)
base-commit: e686c32590f40bffc45f105c04c836ffad3e531a
Signature · 1 line
2.37.3
[email protected]
maintainerPATCH v10 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>
@@ -994,6 +996,7 @@ int cxl_dev_state_identify(struct cxl_dev_state *cxlds)/* See CXL 2.0 Table 175 Identify Memory Device Output Payload */ struct cxl_mbox_identify id;struct cxl_mbox_cmd mbox_cmd; +u32 val;int rc; mbox_cmd = (struct cxl_mbox_cmd ) {
@@ -1017,6 +1020,11 @@ int cxl_dev_state_identify(struct cxl_dev_state *cxlds) cxlds->lsa_size =le32_to_cpu (id.lsa_size);memcpy (cxlds->firmware_version, id.fw_revision,sizeof (id.fw_revision)); +if (test_bit (CXL_MEM_COMMAND_ID_GET_POISON , cxlds->enabled_cmds)) { + val =get_unaligned_le24 (id.poison_list_max_mer); + cxlds->poison.max_errors =min_t (u32, val,CXL_POISON_LIST_MAX ); + } +return 0 ; }EXPORT_SYMBOL_NS_GPL (cxl_dev_state_identify,CXL );
@@ -1107,6 +1115,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
@@ -769,6 +769,10 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (rc)return rc; + rc =cxl_poison_state_init (cxlds); +if (rc) +return rc; + rc =cxl_dev_state_identify (cxlds);if (rc)return rc;
Signature · 1 line
2.37.3
Dave Jiang
maintainerRe: [PATCH v10 1/6] cxl/mbox: Add GET_POISON_LIST mailbox command
Quoted 6 lines · On 3/21/23 7:12 PM, [email protected] wrote:
From: Alison Schofield <[email protected]>
CXL devices maintain a list of locations that are poisoned or result in poison if the addresses are accessed by the host.
Per the spec (CXL 3.0 8.2.9.8.4.1), the device returns this Poison
Maybe you need a comma here?
Quoted 1 line
list as a set of Media Error Records that include the source of the
extra space between "of" and "Media"
Quoted 1 line
error, the starting device physical address and length. The length is
Should add a comma before "and length".
Quoted 174 lines
the number of adjacent DPAs in the record and is in units of 64 bytes.
Retrieve the poison list.
Signed-off-by Alison Schofield <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Ira Weiny <[email protected]>--- 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> @@ -994,6 +996,7 @@ int cxl_dev_state_identify(struct cxl_dev_state *cxlds)/* See CXL 2.0 Table 175 Identify Memory Device Output Payload */ struct cxl_mbox_identify id;struct cxl_mbox_cmd mbox_cmd; +u32 val;int rc; mbox_cmd = (struct cxl_mbox_cmd ) {@@ -1017,6 +1020,11 @@ int cxl_dev_state_identify(struct cxl_dev_state *cxlds) cxlds->lsa_size =le32_to_cpu (id.lsa_size);memcpy (cxlds->firmware_version, id.fw_revision,sizeof (id.fw_revision)); +if (test_bit (CXL_MEM_COMMAND_ID_GET_POISON , cxlds->enabled_cmds)) { + val =get_unaligned_le24 (id.poison_list_max_mer); + cxlds->poison.max_errors =min_t (u32, val,CXL_POISON_LIST_MAX ); + } +return 0 ; }EXPORT_SYMBOL_NS_GPL (cxl_dev_state_identify,CXL );@@ -1107,6 +1115,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 +28
-0@@ -215,6 +215,24 @@ struct cxl_event_state {struct mutex log_lock; }; +/** +* struct cxl_poison_state - Poison list retrieval +* +* @max_errors: Maximum media error records held in device cache +* @payload_out: The poison list payload returned by device +* @lock: Protect reads of the poison list +* +* Reads of the poison list are synchronized to ensure that a reader +* does not get an incomplete list because their request overlapped +* (was interrupted or preceded by) another read request of the same +* DPA range. CXL Spec 3.0 Section 8.2.9.8.4.1 +*/ +struct cxl_poison_state { +u32 max_errors; +struct cxl_mbox_poison_payload_out *payload_out; +struct mutex lock;/* Protect reads of poison list */ +}; +/** * struct cxl_dev_state - The driver device state * @@ -251,6 +269,7 @@ struct cxl_event_state {* @serial: PCIe Device Serial Number * @doe_mbs: PCI DOE mailbox array * @event: event log driver state +* @poison: poison list retrieval info * @mbox_send: @dev specific transport for transmitting mailbox commands * * See section 8.2.9.5.2 Capacity Configuration and Label Storage for @@ -290,6 +309,7 @@ struct cxl_dev_state {struct xarray doe_mbs;struct cxl_event_state event; +struct cxl_poison_state poison;int (*mbox_send)(struct cxl_dev_state *cxlds,struct cxl_mbox_cmd *cmd); };@@ -538,6 +558,50 @@ struct cxl_mbox_set_timestamp_in { } __packed; +/* Get Poison List CXL 3.0 Spec 8.2.9.8.4.1 */ +struct cxl_mbox_poison_payload_in { +__le64 offset; +__le64 length; +} __packed; + +struct cxl_mbox_poison_payload_out { +u8 flags;
drivers/cxl/cxlmem.h struct cxl_mbox_set_timestamp_in { · line 578
Quoted 10 lines
drivers/cxl/cxlmem.h +10
-0+u8 rsvd1; +__le64 overflow_t; +__le16 count; +u8 rsvd2[20 ]; +struct cxl_poison_record { +__le64 address; +__le32 length; +__le32 rsvd; + } __packed record[]; +} __packed;
Pretty long struct name. poison_mbox_in and poison_mbox_out?
Quoted 54 lines
drivers/cxl/cxlmem.h +29
-0+ +/* +* Get Poison List address field encodes the starting +* address of poison, and the source of the poison. +*/ +#define CXL_POISON_START_MASK GENMASK_ULL(63, 6) +#define CXL_POISON_SOURCE_MASK GENMASK(2, 0) + +/* Get Poison List record length is in units of 64 bytes */ +#define CXL_POISON_LEN_MULT 64 + +/* Kernel defined maximum for a list of poison errors */ +#define CXL_POISON_LIST_MAX 1024 + +/* Get Poison List: Payload out flags */ +#define CXL_POISON_FLAG_MORE BIT(0) +#define CXL_POISON_FLAG_OVERFLOW BIT(1) +#define CXL_POISON_FLAG_SCANNING BIT(2) + +/* Get Poison List: Poison Source */ +#define CXL_POISON_SOURCE_UNKNOWN 0 +#define CXL_POISON_SOURCE_EXTERNAL 1 +#define CXL_POISON_SOURCE_INTERNAL 2 +#define CXL_POISON_SOURCE_INJECTED 3 +#define CXL_POISON_SOURCE_VENDOR 7 +/** * struct cxl_mem_command - Driver representation of a memory device command * @info: Command information as it exists for the UAPI @@ -608,6 +672,9 @@ void set_exclusive_cxl_commands(struct cxl_dev_state *cxlds, unsigned long *cmdsvoid clear_exclusive_cxl_commands (struct cxl_dev_state *cxlds,unsigned long *cmds);void cxl_mem_get_event_records (struct cxl_dev_state *cxlds,u32 status);int cxl_set_timestamp (struct cxl_dev_state *cxlds); +int cxl_poison_state_init (struct cxl_dev_state *cxlds); +int cxl_mem_get_poison (struct cxl_memdev *cxlmd,u64 offset,u64 len, +struct cxl_region *cxlr);#ifdef CONFIG_CXL_SUSPEND void cxl_mem_active_inc (void );drivers/cxl/pci.c +4
-0@@ -769,6 +769,10 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (rc)return rc; + rc =cxl_poison_state_init (cxlds); +if (rc) +return rc; + rc =cxl_dev_state_identify (cxlds);if (rc)return rc;
Alison Schofield
maintainerRe: [PATCH v10 1/6] cxl/mbox: Add GET_POISON_LIST mailbox command
Quoted 12 lines · Dave Jiang
Quoted 6 lines · On 3/21/23 7:12 PM, [email protected] wrote:
From: Alison Schofield <[email protected]>
CXL devices maintain a list of locations that are poisoned or result in poison if the addresses are accessed by the host.
Per the spec (CXL 3.0 8.2.9.8.4.1), the device returns this Poison
Maybe you need a comma here?
Quoted 11 lines
Quoted 1 line
list as a set of Media Error Records that include the source of the
extra space between "of" and "Media"
Quoted 1 line
error, the starting device physical address and length. The length is
Should add a comma before "and length".
Quoted 3 lines
the number of adjacent DPAs in the record and is in units of 64 bytes.
Retrieve the poison list.
FYI - this is v10, but things you are pointing out do apply to v11. I'll update the commit msg as you suggest.
Quoted 1 line
Quoted 1 line
snip
Quoted 7 lines
Quoted 7 lines
drivers/cxl/cxlmem.h +7
-0+ +struct cxl_mbox_poison_payload_out { +u8 flags; +u8 rsvd1; +__le64 overflow_t; +__le16 count; +u8 rsvd2[20 ];
Quoted 8 lines
drivers/cxl/cxlmem.h struct cxl_mbox_set_timestamp_in { · line 578
Quoted 6 lines
drivers/cxl/cxlmem.h +6
-0+struct cxl_poison_record { +__le64 address; +__le32 length; +__le32 rsvd; + } __packed record[]; +} __packed;Pretty long struct name.
poison_mbox_inandpoison_mbox_out?
Yeah...I'll drop the _payload from each. Thanks!
Quoted 1 line
snip to end.
[email protected]
maintainerPATCH v10 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/core.h | 4 ++ drivers/cxl/core/mbox.c | 5 ++- drivers/cxl/core/trace.h | 94 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 1 deletion(-)
drivers/cxl/core/core.h +4 -0
@@ -64,4 +64,8 @@ int cxl_memdev_init(void);void cxl_memdev_exit (void );void cxl_mbox_init (void ); +enum cxl_poison_trace_type { +CXL_POISON_TRACE_LIST , +}; +#endif /* __CXL_CORE_H__ */
drivers/cxl/core/mbox.c +4 -1
@@ -1147,7 +1147,10 @@ int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,if (rc)break ; -/* TODO TRACE the media error records */ +for (int i =0 ; i <le16_to_cpu (po->count); i++) +trace_cxl_poison (cxlmd, cxlr, &po->record[i], + po->flags, po->overflow_t, +CXL_POISON_TRACE_LIST );/* Protect against an uncleared _FLAG_MORE */ nr_records = nr_records +le16_to_cpu (po->count);
drivers/cxl/core/trace.h +94 -0
110 lines not on this page · raw message
Signature · 1 line
2.37.3
kernel test robot
build botRe: [PATCH v10 2/6] cxl/trace: Add TRACE support for CXL media-error records
I love your patch! Perhaps something to improve:
Hi,
I love your patch! Perhaps something to improve:
[auto build test WARNING on e686c32590f40bffc45f105c04c836ffad3e531a]
url: https://github.com/intel-lab-lkp/linux/commits/alison-schofield-intel-com/cxl-mbox-Add-GET_POISON_LIST-mailbox-command/20230322-101449 base: e686c32590f40bffc45f105c04c836ffad3e531a patch link: https://lore.kernel.org/r/be0b6edfb0a9fdafe783c68f37972f6bc6d805c4.1679448904.git.alison.schofield%40intel.com patch subject: [PATCH v10 2/6] cxl/trace: Add TRACE support for CXL media-error records config: s390-allyesconfig (https://download.01.org/0day-ci/archive/20230322/[email protected]/config) compiler: s390-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/a687c2458d48c06353e02426ded6982be06b3a66
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review alison-schofield-intel-com/cxl-mbox-Add-GET_POISON_LIST-mailbox-command/20230322-101449 git checkout a687c2458d48c06353e02426ded6982be06b3a66
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=s390 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=s390 SHELL=/bin/bash drivers/cxl/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
In file included from include/trace/define_trace.h:102,
from drivers/cxl/core/trace.h:700,
from drivers/cxl/core/trace.c:5:
drivers/cxl/core/./trace.h: In function 'trace_raw_output_cxl_poison':
>> drivers/cxl/core/./trace.h:680:19: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 10 has type 'u32' {aka 'unsigned int'} [-Wformat=]
680 | TP_printk("memdev=%s host=%s serial=%lld type=%s region=%s " \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/trace/trace_events.h:203:34: note: in definition of macro 'DECLARE_EVENT_CLASS'
203 | trace_event_printf(iter, print); \
| ^~~~~
include/trace/trace_events.h:45:30: note: in expansion of macro 'PARAMS'
45 | PARAMS(print)); \
| ^~~~~~
drivers/cxl/core/./trace.h:639:1: note: in expansion of macro 'TRACE_EVENT'
639 | TRACE_EVENT(cxl_poison,
| ^~~~~~~~~~~
drivers/cxl/core/./trace.h:680:9: note: in expansion of macro 'TP_printk'
680 | TP_printk("memdev=%s host=%s serial=%lld type=%s region=%s " \
| ^~~~~~~~~
>> drivers/cxl/core/./trace.h:680:19: warning: format '%x' expects argument of type 'unsigned int', but argument 11 has type 'const char *' [-Wformat=]
680 | TP_printk("memdev=%s host=%s serial=%lld type=%s region=%s " \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/trace/trace_events.h:203:34: note: in definition of macro 'DECLARE_EVENT_CLASS'
203 | trace_event_printf(iter, print); \
| ^~~~~
include/trace/trace_events.h:45:30: note: in expansion of macro 'PARAMS'
45 | PARAMS(print)); \
| ^~~~~~
drivers/cxl/core/./trace.h:639:1: note: in expansion of macro 'TRACE_EVENT'
639 | TRACE_EVENT(cxl_poison,
| ^~~~~~~~~~~
drivers/cxl/core/./trace.h:680:9: note: in expansion of macro 'TP_printk'
680 | TP_printk("memdev=%s host=%s serial=%lld type=%s region=%s " \
| ^~~~~~~~~
>> drivers/cxl/core/./trace.h:680:19: warning: format '%s' expects argument of type 'char *', but argument 13 has type 'u64' {aka 'long long unsigned int'} [-Wformat=]
680 | TP_printk("memdev=%s host=%s serial=%lld type=%s region=%s " \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/trace/trace_events.h:203:34: note: in definition of macro 'DECLARE_EVENT_CLASS'
203 | trace_event_printf(iter, print); \
| ^~~~~
include/trace/trace_events.h:45:30: note: in expansion of macro 'PARAMS'
45 | PARAMS(print)); \
| ^~~~~~
drivers/cxl/core/./trace.h:639:1: note: in expansion of macro 'TRACE_EVENT'
639 | TRACE_EVENT(cxl_poison,
| ^~~~~~~~~~~
drivers/cxl/core/./trace.h:680:9: note: in expansion of macro 'TP_printk'
680 | TP_printk("memdev=%s host=%s serial=%lld type=%s region=%s " \
| ^~~~~~~~~
>> drivers/cxl/core/./trace.h:680:19: warning: format '%llu' expects a matching 'long long unsigned int' argument [-Wformat=]
680 | TP_printk("memdev=%s host=%s serial=%lld type=%s region=%s " \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/trace/trace_events.h:203:34: note: in definition of macro 'DECLARE_EVENT_CLASS'
203 | trace_event_printf(iter, print); \
| ^~~~~
include/trace/trace_events.h:45:30: note: in expansion of macro 'PARAMS'
45 | PARAMS(print)); \
| ^~~~~~
drivers/cxl/core/./trace.h:639:1: note: in expansion of macro 'TRACE_EVENT'
639 | TRACE_EVENT(cxl_poison,
| ^~~~~~~~~~~
drivers/cxl/core/./trace.h:680:9: note: in expansion of macro 'TP_printk'
680 | TP_printk("memdev=%s host=%s serial=%lld type=%s region=%s " \
| ^~~~~~~~~vim +680 drivers/cxl/core/./trace.h
604
605 #define show_poison_trace_type(type) \
606 __print_symbolic(type, \
607 { CXL_POISON_TRACE_LIST, "LIST" })
608
609 #define __show_poison_source(source) \
610 __print_symbolic(source, \
611 { CXL_POISON_SOURCE_UNKNOWN, "Unknown" }, \
612 { CXL_POISON_SOURCE_EXTERNAL, "External" }, \
613 { CXL_POISON_SOURCE_INTERNAL, "Internal" }, \
614 { CXL_POISON_SOURCE_INJECTED, "Injected" }, \
615 { CXL_POISON_SOURCE_VENDOR, "Vendor" })
616
617 #define show_poison_source(source) \
618 (((source > CXL_POISON_SOURCE_INJECTED) && \
619 (source != CXL_POISON_SOURCE_VENDOR)) ? "Reserved" \
620 : __show_poison_source(source))
621
622 #define show_poison_flags(flags) \
623 __print_flags(flags, "|", \
624 { CXL_POISON_FLAG_MORE, "More" }, \
625 { CXL_POISON_FLAG_OVERFLOW, "Overflow" }, \
626 { CXL_POISON_FLAG_SCANNING, "Scanning" })
627
628 #define __cxl_poison_addr(record) \
629 (le64_to_cpu(record->address))
630 #define cxl_poison_record_dpa(record) \
631 (__cxl_poison_addr(record) & CXL_POISON_START_MASK)
632 #define cxl_poison_record_source(record) \
633 (__cxl_poison_addr(record) & CXL_POISON_SOURCE_MASK)
634 #define cxl_poison_record_dpa_length(record) \
635 (le32_to_cpu(record->length) * CXL_POISON_LEN_MULT)
636 #define cxl_poison_overflow(flags, time) \
637 (flags & CXL_POISON_FLAG_OVERFLOW ? le64_to_cpu(time) : 0)
638
> 639 TRACE_EVENT(cxl_poison,
640
641 TP_PROTO(struct cxl_memdev *cxlmd, struct cxl_region *region,
642 const struct cxl_poison_record *record, u8 flags,
643 __le64 overflow_t, enum cxl_poison_trace_type type),
644
645 TP_ARGS(cxlmd, region, record, flags, overflow_t, type),
646
647 TP_STRUCT__entry(
648 __string(memdev, dev_name(&cxlmd->dev))
649 __string(host, dev_name(cxlmd->dev.parent))
650 __field(u64, serial)
651 __field(u8, type)
652 __string(region, region)
653 __field(u64, overflow_t)
654 __field(u64, dpa)
655 __field(u32, dpa_length)
656 __array(char, uuid, 16)
657 __field(u8, source)
658 __field(u8, flags)
659 ),
660
661 TP_fast_assign(
662 __assign_str(memdev, dev_name(&cxlmd->dev));
663 __assign_str(host, dev_name(cxlmd->dev.parent));
664 __entry->serial = cxlmd->cxlds->serial;
665 __entry->overflow_t = cxl_poison_overflow(flags, overflow_t);
666 __entry->dpa = cxl_poison_record_dpa(record);
667 __entry->dpa_length = cxl_poison_record_dpa_length(record);
668 __entry->source = cxl_poison_record_source(record);
669 __entry->type = type;
670 __entry->flags = flags;
671 if (region) {
672 __assign_str(region, dev_name(®ion->dev));
673 memcpy(__entry->uuid, ®ion->params.uuid, 16);
674 } else {
675 __assign_str(region, "");
676 memset(__entry->uuid, 0, 16);
677 }
678 ),
679
> 680 TP_printk("memdev=%s host=%s serial=%lld type=%s region=%s " \ 681 "region_uuid=%pU hpa=0x%llx dpa=0x%llx dpa_length=0x%x "\
682 "source=%s flags=%s overflow_time=%llu",
683 __get_str(memdev),
684 __get_str(host),
685 __entry->serial,
686 show_poison_trace_type(__entry->type),
687 __get_str(region),
688 __entry->uuid,
689 __entry->dpa,
690 __entry->dpa_length,
691 show_poison_source(__entry->source),
692 show_poison_flags(__entry->flags),
693 __entry->overflow_t
694 )
695 );
696
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
[email protected]
maintainerPATCH v10 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 | 48 +++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 5 ++- drivers/cxl/mem.c | 36 +++++++++++++++++++ 4 files changed, 102 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-bus-cxl +14 -0
@@ -415,3 +415,17 @@ Description: 1), and checks that the hardware accepts the commit request. Reading this value indicates whether the region is committed or not. + + +What: /sys/bus/cxl/devices/memX/trigger_poison_list +Date: March, 2023 +KernelVersion: v6.4 +Contact: [email protected] +Description: + (WO) When a boolean 'true' is written to this attribute the + memdev driver retrieves the poison list from the device. The + list consists of addresses that are poisoned, or would result + in poison if accessed, and the source of the poison. This + attribute is only visible for devices supporting the + capability. The retrieved errors are logged as kernel + trace events with the label 'cxl_poison'.
drivers/cxl/core/memdev.c +48 -0
60 lines not on this page · raw message
drivers/cxl/cxlmem.h +4 -1
@@ -145,7 +145,7 @@ struct cxl_mbox_cmd {C (FWROLLBACK , -ENXIO ,"rolled back to the previous active FW" ), \C (FWRESET , -ENXIO ,"FW failed to activate, needs cold reset" ), \C (HANDLE , -ENXIO ,"one or more Event Record Handles were invalid" ), \ -C (PADDR , -ENXIO ,"physical address specified is invalid" ), \ +C (PADDR , -EFAULT ,"physical address specified is invalid" ), \C (POISONLMT , -ENXIO ,"poison injection limit has been reached" ), \C (MEDIAFAILURE , -ENXIO ,"permanent issue with the media" ), \ C(ABORT, -ENXIO, "background cmd was aborted by device"), \
@@ -675,6 +675,9 @@ int cxl_set_timestamp(struct cxl_dev_state *cxlds);int cxl_poison_state_init (struct cxl_dev_state *cxlds);int cxl_mem_get_poison (struct cxl_memdev *cxlmd,u64 offset,u64 len,struct cxl_region *cxlr); +ssize_t cxl_trigger_poison_list (struct device *dev, +struct device_attribute *attr,const char *buf, +size_t len);#ifdef CONFIG_CXL_SUSPEND void cxl_mem_active_inc (void );
drivers/cxl/mem.c +36 -0
@@ -176,10 +176,46 @@ static int cxl_mem_probe(struct device *dev)return devm_add_action_or_reset (dev, enable_suspend,NULL ); } +static ssize_t trigger_poison_list_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t len) +{ +return cxl_trigger_poison_list (dev, attr, buf, len); +} + +static DEVICE_ATTR_WO (trigger_poison_list); + +static umode_t cxl_mem_visible (struct kobject *kobj,struct attribute *a,int n) +{ +if (a == &dev_attr_trigger_poison_list.attr) { +struct device *dev =kobj_to_dev (kobj); + +if (!test_bit (CXL_MEM_COMMAND_ID_GET_POISON , +to_cxl_memdev (dev)->cxlds->enabled_cmds)) +return 0 ; + } +return a->mode; +} + +static struct attribute *cxl_mem_attrs[] = { + &dev_attr_trigger_poison_list.attr, +NULL +}; + +static struct attribute_group cxl_mem_group = { + .attrs = cxl_mem_attrs, + .is_visible = cxl_mem_visible, +}; + +__ATTRIBUTE_GROUPS (cxl_mem); +static struct cxl_driver cxl_mem_driver = { .name ="cxl_mem" , .probe = cxl_mem_probe, .id =CXL_DEVICE_MEMORY_EXPANDER , + .drv = { + .dev_groups = cxl_mem_groups, + }, };module_cxl_driver (cxl_mem_driver);
Signature · 1 line
2.37.3
Dave Jiang
maintainerRe: [PATCH v10 3/6] cxl/memdev: Add trigger_poison_list sysfs attribute
Quoted 100 lines · On 3/21/23 7:12 PM, [email protected] wrote:
From: Alison Schofield <[email protected]>
When a boolean 'true' is written to this attribute the memdev driver retrieves the poison list from the device. The list 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'.Signed-off-by Alison Schofield <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Ira Weiny <[email protected]>--- Documentation/ABI/testing/sysfs-bus-cxl | 14 ++++++++ drivers/cxl/core/memdev.c | 48 +++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 5 ++- drivers/cxl/mem.c | 36 +++++++++++++++++++ 4 files changed, 102 insertions(+), 1 deletion(-)Documentation/ABI/testing/sysfs-bus-cxl +14
-0@@ -415,3 +415,17 @@ Description: 1), and checks that the hardware accepts the commit request. Reading this value indicates whether the region is committed or not. + + +What: /sys/bus/cxl/devices/memX/trigger_poison_list +Date: March, 2023 +KernelVersion: v6.4 +Contact: [email protected] +Description: + (WO) When a boolean 'true' is written to this attribute the + memdev driver retrieves the poison list from the device. The + list consists of addresses that are poisoned, or would result + in poison if accessed, and the source of the poison. This + attribute is only visible for devices supporting the + capability. The retrieved errors are logged as kernel + trace events with the label 'cxl_poison'.drivers/cxl/core/memdev.c +47
-0@@ -106,6 +106,53 @@ static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr, }static DEVICE_ATTR_RO (numa_node); +static int cxl_get_poison_by_memdev (struct cxl_memdev *cxlmd) +{ +struct cxl_dev_state *cxlds = cxlmd->cxlds; +u64 offset, length; +int rc =0 ; + +/* CXL 3.0 Spec 8.2.9.8.4.1 Separate pmem and ram poison requests */ +if (resource_size (&cxlds->pmem_res)) { + offset = cxlds->pmem_res.start; + length =resource_size (&cxlds->pmem_res); + rc =cxl_mem_get_poison (cxlmd, offset, length,NULL ); +if (rc) +return rc; + } +if (resource_size (&cxlds->ram_res)) { + offset = cxlds->ram_res.start; + length =resource_size (&cxlds->ram_res); + rc =cxl_mem_get_poison (cxlmd, offset, length,NULL ); +/* +* Invalid Physical Address is not an error for +* volatile addresses. Device support is optional. +*/ +if (rc == -EFAULT ) + rc =0 ; + } +return rc; +} + +ssize_t cxl_trigger_poison_list (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t len) +{ +struct cxl_memdev *cxlmd =to_cxl_memdev (dev); +bool trigger; +int rc; + +if (kstrtobool (buf, &trigger) || !trigger) +return -EINVAL ; + +down_read (&cxl_dpa_rwsem); + rc =cxl_get_poison_by_memdev (cxlmd); +up_read (&cxl_dpa_rwsem); + +return rc ? rc : len; +} +EXPORT_SYMBOL_NS_GPL (cxl_trigger_poison_list,CXL ); +static struct attribute *cxl_memdev_attributes[] = { &dev_attr_serial.attr, &dev_attr_firmware_version.attr,
drivers/cxl/core/memdev.c static umode_t cxl_memdev_visible(struct kobject *kobj, struct attribute *a, · line 180
Quoted 4 lines
drivers/cxl/core/memdev.c +1
-0@@ -130,6 +177,7 @@ static umode_t cxl_memdev_visible(struct kobject *kobj, struct attribute *a, {if (!IS_ENABLED (CONFIG_NUMA ) && a == &dev_attr_numa_node.attr)return 0 ; +
Stray blank line?
drivers/cxl/cxlmem.h struct cxl_mbox_cmd { · line 148
Quoted 13 lines
drivers/cxl/core/memdev.c +0
-0return a->mode; }drivers/cxl/cxlmem.h +1
-1@@ -145,7 +145,7 @@ struct cxl_mbox_cmd {C (FWROLLBACK , -ENXIO ,"rolled back to the previous active FW" ), \C (FWRESET , -ENXIO ,"FW failed to activate, needs cold reset" ), \C (HANDLE , -ENXIO ,"one or more Event Record Handles were invalid" ), \ - C(PADDR, -ENXIO, "physical address specified is invalid"), \ + C(PADDR, -EFAULT, "physical address specified is invalid"), \
Seems unrelated change? Does it go with previous patch?
Quoted 64 lines
drivers/cxl/cxlmem.h +3
-0C (POISONLMT , -ENXIO ,"poison injection limit has been reached" ), \C (MEDIAFAILURE , -ENXIO ,"permanent issue with the media" ), \ C(ABORT, -ENXIO, "background cmd was aborted by device"), \@@ -675,6 +675,9 @@ int cxl_set_timestamp(struct cxl_dev_state *cxlds);int cxl_poison_state_init (struct cxl_dev_state *cxlds);int cxl_mem_get_poison (struct cxl_memdev *cxlmd,u64 offset,u64 len,struct cxl_region *cxlr); +ssize_t cxl_trigger_poison_list (struct device *dev, +struct device_attribute *attr,const char *buf, +size_t len);#ifdef CONFIG_CXL_SUSPEND void cxl_mem_active_inc (void );drivers/cxl/mem.c +36
-0@@ -176,10 +176,46 @@ static int cxl_mem_probe(struct device *dev)return devm_add_action_or_reset (dev, enable_suspend,NULL ); } +static ssize_t trigger_poison_list_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t len) +{ +return cxl_trigger_poison_list (dev, attr, buf, len); +} + +static DEVICE_ATTR_WO (trigger_poison_list); + +static umode_t cxl_mem_visible (struct kobject *kobj,struct attribute *a,int n) +{ +if (a == &dev_attr_trigger_poison_list.attr) { +struct device *dev =kobj_to_dev (kobj); + +if (!test_bit (CXL_MEM_COMMAND_ID_GET_POISON , +to_cxl_memdev (dev)->cxlds->enabled_cmds)) +return 0 ; + } +return a->mode; +} + +static struct attribute *cxl_mem_attrs[] = { + &dev_attr_trigger_poison_list.attr, +NULL +}; + +static struct attribute_group cxl_mem_group = { + .attrs = cxl_mem_attrs, + .is_visible = cxl_mem_visible, +}; + +__ATTRIBUTE_GROUPS (cxl_mem); +static struct cxl_driver cxl_mem_driver = { .name ="cxl_mem" , .probe = cxl_mem_probe, .id =CXL_DEVICE_MEMORY_EXPANDER , + .drv = { + .dev_groups = cxl_mem_groups, + }, };module_cxl_driver (cxl_mem_driver);
Alison Schofield
maintainerRe: [PATCH v10 3/6] cxl/memdev: Add trigger_poison_list sysfs attribute
Quoted 22 lines · Dave Jiang
Quoted 19 lines · On 3/21/23 7:12 PM, [email protected] wrote:
From: Alison Schofield <[email protected]>
When a boolean 'true' is written to this attribute the memdev driver retrieves the poison list from the device. The list 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'.Signed-off-by Alison Schofield <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Ira Weiny <[email protected]>--- Documentation/ABI/testing/sysfs-bus-cxl | 14 ++++++++ drivers/cxl/core/memdev.c | 48 +++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 5 ++- drivers/cxl/mem.c | 36 +++++++++++++++++++ 4 files changed, 102 insertions(+), 1 deletion(-)
snip
Quoted 15 lines
Quoted 15 lines
drivers/cxl/core/memdev.c +15
-0+static int cxl_get_poison_by_memdev (struct cxl_memdev *cxlmd) +{ +struct cxl_dev_state *cxlds = cxlmd->cxlds; +u64 offset, length; +int rc =0 ; + +/* CXL 3.0 Spec 8.2.9.8.4.1 Separate pmem and ram poison requests */ +if (resource_size (&cxlds->pmem_res)) { + offset = cxlds->pmem_res.start; + length =resource_size (&cxlds->pmem_res); + rc =cxl_mem_get_poison (cxlmd, offset, length,NULL ); +if (rc) +return rc; + } +if (resource_size (&cxlds->ram_res)) {
Quoted 8 lines
drivers/cxl/core/memdev.c static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr, · line 131
Quoted 8 lines
drivers/cxl/core/memdev.c +8
-0+ offset = cxlds->ram_res.start; + length =resource_size (&cxlds->ram_res); + rc =cxl_mem_get_poison (cxlmd, offset, length,NULL ); +/* +* Invalid Physical Address is not an error for +* volatile addresses. Device support is optional. +*/ +if (rc == -EFAULT )
See this EFAULT. That is why I changed table further down to allow EFAULT to get through explicitly.
snip
Quoted 7 lines
drivers/cxl/core/memdev.c static umode_t cxl_memdev_visible(struct kobject *kobj, struct attribute *a, · line 180
Quoted 5 lines
drivers/cxl/core/memdev.c +1
-0@@ -130,6 +177,7 @@ static umode_t cxl_memdev_visible(struct kobject *kobj, struct attribute *a, {if (!IS_ENABLED (CONFIG_NUMA ) && a == &dev_attr_numa_node.attr)return 0 ; +Stray blank line?
Yes.
Quoted 15 lines
drivers/cxl/cxlmem.h struct cxl_mbox_cmd { · line 148
Quoted 13 lines
drivers/cxl/core/memdev.c +0
-0return a->mode; }drivers/cxl/cxlmem.h +1
-1@@ -145,7 +145,7 @@ struct cxl_mbox_cmd {C (FWROLLBACK , -ENXIO ,"rolled back to the previous active FW" ), \C (FWRESET , -ENXIO ,"FW failed to activate, needs cold reset" ), \C (HANDLE , -ENXIO ,"one or more Event Record Handles were invalid" ), \ - C(PADDR, -ENXIO, "physical address specified is invalid"), \ + C(PADDR, -EFAULT, "physical address specified is invalid"), \Seems unrelated change? Does it go with previous patch?
See prior note. Need this one explicitly.
Quoted 1 line
snip to end.
[email protected]
maintainerPATCH v10 4/6 cxl/region: Provide region info to the cxl_poison trace event
In reply to [email protected]From: Alison Schofield <[email protected]>
User space may need to know which region, if any, maps the poison address(es) logged in a cxl_poison trace event. Since the mapping of DPAs (device physical addresses) to a region can change, the kernel must provide this information at the time the poison list is read. The event informs user space that at event <timestamp> this <region> mapped to this <DPA>, which is poisoned.
The cxl_poison trace event is already wired up to log the region name and uuid if it receives param 'struct cxl_region'.
In order to provide that cxl_region, add another method for gathering poison - by committed endpoint decoder mappings. This method is only available with CONFIG_CXL_REGION and is only used if a region actually maps the memdev where poison is being read. After the region driver reads the poison list for all the mapped resources, control returns to the memdev driver, where poison is read for any remaining unmapped resources.
Mixed mode decoders are not currently supported in Linux. Add a debug message to the poison request path. That will serve as an alert that poison list retrieval needs to add support for mixed mode.
The default method remains: read the poison by memdev resource.
--- drivers/cxl/core/core.h | 11 +++++++ drivers/cxl/core/memdev.c | 62 +++++++++++++++++++++++++++++++++++++- drivers/cxl/core/region.c | 63 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+), 1 deletion(-)
drivers/cxl/core/core.h +11 -0
@@ -25,7 +25,12 @@ void cxl_decoder_kill_region(struct cxl_endpoint_decoder *cxled);#define CXL_DAX_REGION_TYPE (x) (&cxl_dax_region_type)int cxl_region_init (void );void cxl_region_exit (void ); +int cxl_get_poison_by_endpoint (struct device *dev,void *data);#else +static inline int cxl_get_poison_by_endpoint (struct device *dev,void *data) +{ +return 0 ; +}static inline void cxl_decoder_kill_region (struct cxl_endpoint_decoder *cxled) { }
@@ -68,4 +73,10 @@ enum cxl_poison_trace_type { CXL_POISON_TRACE_LIST, }; +struct cxl_trigger_poison_context { +struct cxl_port *port; +enum cxl_decoder_mode mode; +u64 offset; +}; +#endif /* __CXL_CORE_H__ */
drivers/cxl/core/memdev.c +61 -1
81 lines not on this page · raw message
drivers/cxl/core/region.c +63 -0
69 lines not on this page · raw message
Signature · 1 line
2.37.3
Re: [PATCH v10 4/6] cxl/region: Provide region info to the cxl_poison trace event
Quoted 24 lines · On 3/21/23 7:12 PM, [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'.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. After the region driver reads the poison list for all the mapped resources, control returns to the memdev driver, where poison is read for any remaining unmapped resources.Mixed mode decoders are not currently supported in Linux. Add a debug message to the poison request path. That will serve as an alert that poison list retrieval needs to add support for mixed mode.
Quoted 5 lines
The default method remains: read the poison by memdev resource.
Signed-off-by Alison Schofield <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Tested-by Jonathan Cameron <[email protected]>
Quoted 195 lines
--- drivers/cxl/core/core.h | 11 +++++++ drivers/cxl/core/memdev.c | 62 +++++++++++++++++++++++++++++++++++++- drivers/cxl/core/region.c | 63 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+), 1 deletion(-)drivers/cxl/core/core.h +11
-0@@ -25,7 +25,12 @@ void cxl_decoder_kill_region(struct cxl_endpoint_decoder *cxled);#define CXL_DAX_REGION_TYPE (x) (&cxl_dax_region_type)int cxl_region_init (void );void cxl_region_exit (void ); +int cxl_get_poison_by_endpoint (struct device *dev,void *data);#else +static inline int cxl_get_poison_by_endpoint (struct device *dev,void *data) +{ +return 0 ; +}static inline void cxl_decoder_kill_region (struct cxl_endpoint_decoder *cxled) { }@@ -68,4 +73,10 @@ enum cxl_poison_trace_type { CXL_POISON_TRACE_LIST, }; +struct cxl_trigger_poison_context { +struct cxl_port *port; +enum cxl_decoder_mode mode; +u64 offset; +}; +#endif /* __CXL_CORE_H__ */ drivers/cxl/core/memdev.c +61
-1@@ -106,6 +106,47 @@ static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr, }static DEVICE_ATTR_RO (numa_node); +static int cxl_get_poison_unmapped (struct cxl_memdev *cxlmd, +struct cxl_trigger_poison_context *ctx) +{ +struct cxl_dev_state *cxlds = cxlmd->cxlds; +u64 offset, length; +int rc =0 ; + +/* +* Collect poison for the remaining unmapped resources +* after poison is collected by committed endpoints. +* +* Knowing that PMEM must always follow RAM, get poison +* for unmapped resources based on the last decoder's mode: +* ram: scan remains of ram range, then any pmem range +* pmem: scan remains of pmem range +*/ + +if (ctx->mode ==CXL_DECODER_RAM ) { + offset = ctx->offset; + length =resource_size (&cxlds->ram_res) - offset; + rc =cxl_mem_get_poison (cxlmd, offset, length,NULL ); +if (rc == -EFAULT ) + rc =0 ; +if (rc) +return rc; + } +if (ctx->mode ==CXL_DECODER_PMEM ) { + offset = ctx->offset; + length =resource_size (&cxlds->dpa_res) - offset; +if (!length) +return 0 ; + }else if (resource_size (&cxlds->pmem_res)) { + offset = cxlds->pmem_res.start; + length =resource_size (&cxlds->pmem_res); + }else { +return 0 ; + } + +return cxl_mem_get_poison (cxlmd, offset, length,NULL ); +} +static int cxl_get_poison_by_memdev (struct cxl_memdev *cxlmd) {struct cxl_dev_state *cxlds = cxlmd->cxlds;@@ -139,14 +180,33 @@ ssize_t cxl_trigger_poison_list(struct device *dev, const char *buf, size_t len) {struct cxl_memdev *cxlmd =to_cxl_memdev (dev); +struct cxl_trigger_poison_context ctx; +struct cxl_port *port;bool trigger;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 */ + ctx = (struct cxl_trigger_poison_context ) { + .port = port, + }; + rc =device_for_each_child (&port->dev, &ctx, + cxl_get_poison_by_endpoint); +if (rc ==1 ) + rc =cxl_get_poison_unmapped (cxlmd, &ctx); + } +up_read (&cxl_dpa_rwsem);return rc ? rc : len;drivers/cxl/core/region.c +63
-0@@ -2213,6 +2213,69 @@ struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev) }EXPORT_SYMBOL_NS_GPL (to_cxl_pmem_region,CXL ); +int cxl_get_poison_by_endpoint (struct device *dev,void *arg) +{ +struct cxl_trigger_poison_context *ctx = arg; +struct cxl_endpoint_decoder *cxled; +struct cxl_port *port = ctx->port; +struct cxl_memdev *cxlmd; +u64 offset, length; +int rc =0 ; + +down_read (&cxl_region_rwsem); + +if (!is_endpoint_decoder (dev)) + goto out; + + cxled =to_cxl_endpoint_decoder (dev); +if (!cxled->dpa_res || !resource_size (cxled->dpa_res)) + goto out; + +/* +* Regions are only created with single mode decoders: pmem or ram. +* Linux does not currently support mixed mode decoders. This means +* that reading poison per endpoint decoder adheres to the spec +* requirement that poison reads of pmem and ram must be separated. +* CXL 3.0 Spec 8.2.9.8.4.1 +* +* Watch for future support of mixed with a dev_dbg() msg. +*/ +if (cxled->mode ==CXL_DECODER_MIXED ) { +dev_dbg (dev,"poison list read unsupported in mixed mode\n" ); + goto out; + } + + cxlmd =cxled_to_memdev (cxled); +if (cxled->skip) { + offset = cxled->dpa_res->start - cxled->skip; + length = cxled->skip; + rc =cxl_mem_get_poison (cxlmd, offset, length,NULL ); +if (rc == -EFAULT && cxled->mode ==CXL_DECODER_RAM ) + rc =0 ; +if (rc) + goto out; + } + + offset = cxled->dpa_res->start; + length = cxled->dpa_res->end - offset +1 ; + rc =cxl_mem_get_poison (cxlmd, offset, length, cxled->cxld.region); +if (rc == -EFAULT && cxled->mode ==CXL_DECODER_RAM ) + rc =0 ; +if (rc) + goto out; + +/* Iterate until commit_end is reached */ +if (cxled->cxld.id == port->commit_end) + rc =1 ; + +/* ctx informs the memdev driver of last read poison */ + ctx->mode = cxled->mode; + ctx->offset = cxled->dpa_res->end +1 ; +out: +up_read (&cxl_region_rwsem); +return rc; +} +static struct lock_class_key cxl_pmem_region_key;static struct cxl_pmem_region *cxl_pmem_region_alloc (struct cxl_region *cxlr)
[email protected]
maintainerPATCH v10 5/6 cxl/trace: Add an HPA to cxl_poison trace events
In reply to [email protected]From: Alison Schofield <[email protected]>
When a cxl_poison trace event is reported for a region, the poisoned Device Physical Address (DPA) can be translated to a Host Physical Address (HPA) for consumption by user space.
Translate and add the resulting HPA to the cxl_poison trace event. Follow the device decode logic as defined in the CXL Spec 3.0 Section 8.2.4.19.13.
If no region currently maps the poison, assign ULLONG_MAX to the cxl_poison event hpa field.
--- drivers/cxl/core/trace.c | 94 ++++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/trace.h | 7 +++ 2 files changed, 101 insertions(+)
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 +7 -0
@@ -636,6 +636,8 @@ TRACE_EVENT(cxl_memory_module,#define cxl_poison_overflow (flags, time) \ (flags & CXL_POISON_FLAG_OVERFLOW ? le64_to_cpu(time) : 0) +u64 cxl_trace_hpa (struct cxl_region *cxlr,struct cxl_memdev *memdev,u64 dpa); + TRACE_EVENT(cxl_poison, TP_PROTO(struct cxl_memdev *cxlmd, struct cxl_region *region,
@@ -651,6 +653,7 @@ TRACE_EVENT(cxl_poison, __field(u8, type) __string(region, region) __field(u64, overflow_t) + __field(u64, hpa) __field(u64, dpa) __field(u32, dpa_length)__array (char, uuid,16 )
@@ -671,9 +674,12 @@ 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 ; } ),
@@ -686,6 +692,7 @@ TRACE_EVENT(cxl_poison,show_poison_trace_type (__entry->type),__get_str (region), __entry->uuid, + __entry->hpa, __entry->dpa, __entry->dpa_length, show_poison_source(__entry->source),
Signature · 1 line
2.37.3
[email protected]
maintainerPATCH v10 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
Re: [PATCH v10 6/6] tools/testing/cxl: Mock support for Get Poison List
Quoted 6 lines · On 3/21/23 7:12 PM, [email protected] wrote:
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.
Quoted 6 lines
This supports testing the kernel tracing and cxl list capabilities for media errors.
Signed-off-by Alison Schofield <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Ira Weiny <[email protected]>
Quoted 92 lines
--- 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;